lumix-js 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli/init.js +66 -43
  2. package/package.json +4 -4
package/dist/cli/init.js CHANGED
@@ -4,26 +4,31 @@ import fs from "fs-extra";
4
4
  import path from "path";
5
5
  import { __dirname } from "./utils.js";
6
6
  import { spawnSync } from "child_process";
7
- function hasCommand(cmd) {
8
- const which = process.platform === "win32" ? "where" : "which";
9
- const res = spawnSync(which, [cmd], { stdio: "ignore" });
10
- return res.status === 0;
7
+ function isPackageManagerAvailable(pm) {
8
+ try {
9
+ let res = spawnSync(pm, ["--version"], { stdio: "ignore" });
10
+ if (res.error) {
11
+ const err = res.error;
12
+ if (process.platform === "win32" && err.code === "ENOENT" && (pm === "npm" || pm === "pnpm")) {
13
+ res = spawnSync("cmd", ["/c", pm, "--version"], { stdio: "ignore" });
14
+ }
15
+ }
16
+ return res.status === 0;
17
+ }
18
+ catch {
19
+ return false;
20
+ }
11
21
  }
12
22
  function detectPackageManager() {
13
- if (hasCommand("bun"))
23
+ if (isPackageManagerAvailable("bun"))
14
24
  return "bun";
15
- if (hasCommand("pnpm"))
25
+ if (isPackageManagerAvailable("pnpm"))
16
26
  return "pnpm";
17
27
  return "npm";
18
28
  }
19
29
  function getInstalledPackageManagers() {
20
- const out = [];
21
- if (hasCommand("bun"))
22
- out.push("bun");
23
- if (hasCommand("pnpm"))
24
- out.push("pnpm");
25
- out.push("npm");
26
- return Array.from(new Set(out));
30
+ // Always show the main options; availability will be handled at install time.
31
+ return ["bun", "pnpm", "npm"];
27
32
  }
28
33
  function runDevCommand(pm) {
29
34
  if (pm === "npm")
@@ -38,16 +43,34 @@ function installCommand(pm) {
38
43
  function runInstall(pm, cwd) {
39
44
  const cmd = pm;
40
45
  const args = ["install"];
41
- const res = spawnSync(cmd, args, { cwd, stdio: "inherit" });
42
- if (res.error)
43
- throw res.error;
46
+ let res = spawnSync(cmd, args, { cwd, encoding: "utf8" });
47
+ if (res.error) {
48
+ // On Windows, npm/pnpm may be available through cmd resolution even if not directly spawnable.
49
+ const err = res.error;
50
+ if (process.platform === "win32" && err.code === "ENOENT" && (pm === "npm" || pm === "pnpm")) {
51
+ res = spawnSync("cmd", ["/c", pm, ...args], { cwd, encoding: "utf8" });
52
+ }
53
+ else {
54
+ throw res.error;
55
+ }
56
+ }
44
57
  if (res.signal === "SIGINT") {
45
58
  const err = new Error("install interrupted");
46
59
  err.code = "SIGINT";
47
60
  throw err;
48
61
  }
49
62
  if (typeof res.status === "number" && res.status !== 0) {
50
- throw new Error(`${cmd} install failed with exit code ${res.status}`);
63
+ const failure = {
64
+ pm,
65
+ status: res.status ?? null,
66
+ signal: res.signal ?? null,
67
+ stdout: String(res.stdout || ""),
68
+ stderr: String(res.stderr || ""),
69
+ };
70
+ const err = new Error(`${cmd} install failed`);
71
+ err.code = "INSTALL_FAILED";
72
+ err.failure = failure;
73
+ throw err;
51
74
  }
52
75
  }
53
76
  function isEnoentSpawnError(e) {
@@ -56,6 +79,11 @@ function isEnoentSpawnError(e) {
56
79
  function isSigintError(e) {
57
80
  return Boolean(e && typeof e === "object" && "code" in e && e.code === "SIGINT");
58
81
  }
82
+ function getInstallFailure(e) {
83
+ return Boolean(e && typeof e === "object" && e.code === "INSTALL_FAILED" && e.failure)
84
+ ? e.failure
85
+ : null;
86
+ }
59
87
  export async function init(name, options) {
60
88
  console.log("");
61
89
  console.log(` ${pc.bold(pc.cyan("⚡ LumixJS"))} ${pc.dim("v0.1.0")}`);
@@ -154,35 +182,30 @@ export async function init(name, options) {
154
182
  process.exit(0);
155
183
  }
156
184
  if (isEnoentSpawnError(e)) {
157
- const fallback = detectedPm;
158
- if (fallback !== packageManager && hasCommand(fallback)) {
159
- console.log(pc.yellow(`\n ${packageManager} not found. Retrying with ${fallback}...`));
160
- try {
161
- packageManager = fallback;
162
- runInstall(packageManager, targetDir);
163
- console.log(pc.green(pc.bold("\n Dependencies installed.")));
164
- }
165
- catch (e2) {
166
- if (isSigintError(e2)) {
167
- console.log(pc.red("\n Aborted.\n"));
168
- process.exit(0);
169
- }
170
- console.log(pc.red(`\n Failed to install dependencies: ${e2?.message || e2}`));
171
- console.log(pc.dim(" Project created at:"));
172
- console.log(` ${targetDir}\n`);
173
- }
174
- }
175
- else {
176
- console.log(pc.red(`\n Failed to install dependencies: ${e?.message || e}`));
177
- console.log(pc.dim(" Project created at:"));
178
- console.log(` ${targetDir}\n`);
179
- }
185
+ console.log(pc.red(`\n Failed to install dependencies: ${packageManager} not found`));
180
186
  }
181
187
  else {
182
- console.log(pc.red(`\n Failed to install dependencies: ${e?.message || e}`));
183
- console.log(pc.dim(" Project created at:"));
184
- console.log(` ${targetDir}\n`);
188
+ console.log(pc.red(`\n Failed to install dependencies using ${packageManager}.`));
189
+ }
190
+ const failure = getInstallFailure(e);
191
+ if (failure) {
192
+ const out = `${failure.stdout}${failure.stderr}`.trim();
193
+ if (out) {
194
+ console.log(pc.dim("\n Output:"));
195
+ console.log(out);
196
+ }
197
+ }
198
+ else if (e?.message) {
199
+ console.log(pc.dim("\n Output:"));
200
+ console.log(String(e.message));
185
201
  }
202
+ console.log(pc.dim("\n Project created at:"));
203
+ console.log(` ${targetDir}\n`);
204
+ console.log(pc.dim(" You can try installing with a different package manager:"));
205
+ console.log(` cd ${projectName}`);
206
+ console.log(" npm install");
207
+ console.log(" pnpm install");
208
+ console.log(" bun install\n");
186
209
  }
187
210
  }
188
211
  console.log(pc.dim("\n Next steps:"));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lumix-js",
3
- "version": "0.1.0",
4
- "description": "The modular runtime for LuminJS",
3
+ "version": "0.1.1",
4
+ "description": "The modular runtime for LumixJS",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -37,11 +37,11 @@
37
37
  "dependencies": {
38
38
  "@types/bun": "^1.3.9",
39
39
  "vite": "^7.3.1",
40
- "commander": "^12.0.0",
40
+ "commander": "^14.0.3",
41
41
  "prompts": "^2.4.2",
42
42
  "picocolors": "^1.0.0",
43
43
  "bundle-require": "^5.0.0",
44
- "vite-plugin-lumix": "workspace:*",
44
+ "vite-plugin-lumix": "latest",
45
45
  "fs-extra": "^11.2.0"
46
46
  }
47
47
  }