@galaxy-stack/blackhole-cli 3.0.6 → 3.0.8

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.
@@ -0,0 +1,174 @@
1
+ /** The oldest npm this CLI supports: `--omit=dev` and the lockfile it reads arrived in npm 7. */
2
+ export declare const MIN_NPM_MAJOR = 7;
3
+ /** The command a person can paste when this CLI cannot find npm itself. */
4
+ export declare const NPM_MANUAL_HINT = "npm i -g @galaxy-stack/blackhole-cli@latest";
5
+ /** How an npm candidate is started: straight, through node's JS entry, or through `cmd.exe`. */
6
+ export type NpmKind = "direct" | "node" | "cmd";
7
+ /** One way to run npm, resolved but not started. */
8
+ export interface NpmInvocation {
9
+ /** Binary to spawn: npm itself, `node`, or `cmd.exe`. */
10
+ readonly command: string;
11
+ /** Whether the child is npm, node running npm's entry, or cmd running the `.cmd` shim. */
12
+ readonly kind: NpmKind;
13
+ /** npm's JS entry (kind `node`) or the shim (kind `cmd`). */
14
+ readonly entry?: string;
15
+ /** Where the candidate came from, printed by `harness status` and by every failure. */
16
+ readonly source: string;
17
+ }
18
+ /** Every process fact the ladder reads, so a test can drive it without npm installed. */
19
+ export interface NpmLookup {
20
+ readonly platform: NodeJS.Platform;
21
+ readonly env: NodeJS.ProcessEnv;
22
+ /** The running node: the interpreter behind every `npm-cli.js` candidate. */
23
+ readonly node: string;
24
+ readonly exists: (path: string) => boolean;
25
+ /** First match of a bare name on PATH (or `where`/`which`), when the caller has one. */
26
+ readonly which: (name: string) => string | undefined;
27
+ }
28
+ /** One rung of the ladder, kept so a failure can say what it tried. */
29
+ export interface NpmAttempt {
30
+ /** The rung, as the user reads it. */
31
+ readonly label: string;
32
+ /** The path(s) that rung looked at, or why it had nothing to look at. */
33
+ readonly detail: string;
34
+ /** Whether this rung answered. */
35
+ readonly found: boolean;
36
+ }
37
+ /** What one npm run produced. */
38
+ export interface NpmRunResult {
39
+ /** Exit code 0 and no timeout. */
40
+ readonly ok: boolean;
41
+ /** Exit code, or null when npm could not be started at all. */
42
+ readonly code: number | null;
43
+ /** Everything the child wrote (stdout and stderr), or the guidance when it never started. */
44
+ readonly output: string;
45
+ /** Whether the run was killed by {@link NpmRunOptions.timeoutMs}. */
46
+ readonly timedOut: boolean;
47
+ /** The invocation that ran; absent when npm was not found. */
48
+ readonly invocation?: NpmInvocation;
49
+ }
50
+ /** What one npm run takes. */
51
+ export interface NpmRunOptions {
52
+ /** Process facts; this machine by default. */
53
+ readonly lookup?: NpmLookup;
54
+ /** Working directory for npm. */
55
+ readonly cwd?: string;
56
+ /** Kill npm after this long. */
57
+ readonly timeoutMs?: number;
58
+ /** Called with every complete output line, so a long install still shows progress. */
59
+ readonly onLine?: (line: string) => void;
60
+ /** Extra environment for the child, on top of this process's own. */
61
+ readonly env?: NodeJS.ProcessEnv;
62
+ }
63
+ /**
64
+ * A PATH lookup done here rather than through `which`/`where`, so it works in the same
65
+ * environments where spawning a helper would fail (a stripped `env -i` shell, a service).
66
+ * @param name - bare executable name, without an extension.
67
+ * @param env - the environment holding PATH (and PATHEXT on Windows).
68
+ * @param platform - target platform; Windows reads PATHEXT and splits PATH on ";".
69
+ * @param exists - filesystem probe.
70
+ * @returns the first match, or undefined.
71
+ */
72
+ export declare function whichOnPath(name: string, env: NodeJS.ProcessEnv, platform: NodeJS.Platform, exists: (path: string) => boolean): string | undefined;
73
+ /** The real filesystem, PATH and environment. */
74
+ export declare function systemNpmLookup(): NpmLookup;
75
+ /**
76
+ * The `npm-cli.js` files an official node distribution keeps beside its binary.
77
+ *
78
+ * The MSI installer (and nvm-windows) put npm in `<nodeDir>/node_modules`, while nvm on
79
+ * macOS/Linux, Homebrew and the official pkg keep it in `<nodeDir>/../lib/node_modules`. Both
80
+ * layouts are one node install apart, so they cost nothing to list.
81
+ * @param nodeDir - `dirname(process.execPath)`.
82
+ * @returns candidate paths, most likely first.
83
+ */
84
+ export declare function npmJSEntries(nodeDir: string): string[];
85
+ /**
86
+ * Every way to run npm on this machine, in the order the ladder tries them: `GBH_NPM`, PATH, the
87
+ * `npm.cmd` beside node (Windows), node running npm's own JS entry, then the macOS system paths.
88
+ * @param lookup - process facts.
89
+ * @returns invocations in preference order, de-duplicated.
90
+ */
91
+ export declare function npmCandidates(lookup?: NpmLookup): NpmInvocation[];
92
+ /**
93
+ * The npm this machine should use, or undefined when it has none.
94
+ * @param lookup - process facts.
95
+ * @returns the first acceptable invocation.
96
+ */
97
+ export declare function resolveNpm(lookup?: NpmLookup): NpmInvocation | undefined;
98
+ /**
99
+ * The ladder as the user reads it, one entry per rung, for a failure message.
100
+ * @param lookup - process facts.
101
+ * @returns every rung, with the path it looked at.
102
+ */
103
+ export declare function npmAttempts(lookup?: NpmLookup): NpmAttempt[];
104
+ /**
105
+ * The sentence a machine without npm gets: what was tried, what to install, and the manual command.
106
+ *
107
+ * It deliberately says nothing about `spawn` or `ENOENT`: neither is something a person can act on.
108
+ * @param lookup - process facts.
109
+ * @returns several lines, safe to print as-is.
110
+ */
111
+ export declare function npmMissingMessage(lookup?: NpmLookup): string;
112
+ /**
113
+ * Quote one argument for `cmd.exe`. Only what cmd would split on or read as syntax is quoted, and
114
+ * an inner quote is escaped the way cmd expects, so paths with spaces survive intact.
115
+ * @param arg - one argv entry.
116
+ * @returns the argument as cmd should receive it.
117
+ */
118
+ export declare function quoteForCmd(arg: string): string;
119
+ /**
120
+ * Build the one string cmd.exe receives after `/d /s /c`.
121
+ * @param args - argv to run.
122
+ * @returns the command line, quoted per argument.
123
+ */
124
+ export declare function windowsCommandLine(args: readonly string[]): string;
125
+ /**
126
+ * The argv that starts npm for one invocation.
127
+ * @param invocation - resolved npm.
128
+ * @param args - npm's own arguments.
129
+ * @returns argv for {@link NpmInvocation.command}.
130
+ */
131
+ export declare function npmArgv(invocation: NpmInvocation, args: readonly string[]): string[];
132
+ /**
133
+ * A spawn that failed even though npm was found — a broken shim, a deleted prefix, a permission
134
+ * wall. Still actionable, and still never a bare ENOENT.
135
+ * @param invocation - what was spawned.
136
+ * @param error - the spawn failure.
137
+ * @returns the message the caller prints.
138
+ */
139
+ export declare function npmSpawnFailure(invocation: NpmInvocation, error: Error): string;
140
+ /**
141
+ * Run npm with the first invocation that exists.
142
+ *
143
+ * Output is captured (stdout and stderr together) and every complete line is handed to
144
+ * {@link NpmRunOptions.onLine}, so a caller can stream progress and still print the tail when the
145
+ * run fails. When no npm exists the result is a failure whose output is
146
+ * {@link npmMissingMessage} — the caller prints guidance, never a spawn error.
147
+ * @param args - npm's own arguments.
148
+ * @param options - lookup, cwd, timeout, line sink, extra environment.
149
+ * @returns exit code, captured output, and which npm ran.
150
+ */
151
+ export declare function runNpm(args: readonly string[], options?: NpmRunOptions): Promise<NpmRunResult>;
152
+ /**
153
+ * Parse what `npm --version` printed.
154
+ * @param text - the child's output.
155
+ * @returns major/minor and the version, or undefined when nothing looked like a version.
156
+ */
157
+ export declare function parseNpmVersion(text: string): {
158
+ major: number;
159
+ minor: number;
160
+ version: string;
161
+ } | undefined;
162
+ /**
163
+ * Ask the npm this CLI would use which version it is.
164
+ * @param options - lookup and timeout.
165
+ * @returns the version (for instance `10.9.2`), or undefined when npm could not answer.
166
+ */
167
+ export declare function readNpmVersion(options?: NpmRunOptions): Promise<string | undefined>;
168
+ /**
169
+ * Warn about an npm too old for the flags this CLI passes.
170
+ * @param version - what {@link readNpmVersion} returned.
171
+ * @returns one actionable line, or undefined when npm is new enough (or unknown).
172
+ */
173
+ export declare function npmVersionWarning(version: string | undefined): string | undefined;
174
+ //# sourceMappingURL=npm-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm-cli.d.ts","sourceRoot":"","sources":["../src/npm-cli.ts"],"names":[],"mappings":"AAkBA,iGAAiG;AACjG,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,2EAA2E;AAC3E,eAAO,MAAM,eAAe,gDAAgD,CAAC;AAE7E,gGAAgG;AAChG,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,C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;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAElE;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAIpF;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAM/E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAkClG;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAI3G;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAI7F;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKjF"}
@@ -0,0 +1,332 @@
1
+ /**
2
+ * Finding npm on a machine where `npm` is not simply on PATH, and running it.
3
+ *
4
+ * Two real failures on Windows drove this module. (1) The code spawned `npm` directly: Windows
5
+ * only has `npm.cmd`, which `spawn` refuses without a shell, and a PATH inherited from a GUI or a
6
+ * node installed by the MSI can miss the shim entirely — the user read "spawn npm ENOENT".
7
+ * (2) `harness install` called npm the same way, so the host runtime never installed and the
8
+ * failure only surfaced later, when `blackhole web` tried to boot.
9
+ *
10
+ * The ladder below never needs PATH for npm to exist: a node install ships npm as JavaScript, so
11
+ * `node <...>/npm-cli.js` is a way to run npm on every official distribution, Windows included.
12
+ * Every candidate is tried in order, without a shell, and a machine that has no npm at all gets a
13
+ * sentence naming what was tried and what to do instead of a raw ENOENT.
14
+ */
15
+ import { spawn } from "node:child_process";
16
+ import { existsSync } from "node:fs";
17
+ import { delimiter, dirname, join } from "node:path";
18
+ /** The oldest npm this CLI supports: `--omit=dev` and the lockfile it reads arrived in npm 7. */
19
+ export const MIN_NPM_MAJOR = 7;
20
+ /** The command a person can paste when this CLI cannot find npm itself. */
21
+ export const NPM_MANUAL_HINT = "npm i -g @galaxy-stack/blackhole-cli@latest";
22
+ /**
23
+ * A PATH lookup done here rather than through `which`/`where`, so it works in the same
24
+ * environments where spawning a helper would fail (a stripped `env -i` shell, a service).
25
+ * @param name - bare executable name, without an extension.
26
+ * @param env - the environment holding PATH (and PATHEXT on Windows).
27
+ * @param platform - target platform; Windows reads PATHEXT and splits PATH on ";".
28
+ * @param exists - filesystem probe.
29
+ * @returns the first match, or undefined.
30
+ */
31
+ export function whichOnPath(name, env, platform, exists) {
32
+ const extensions = platform === "win32"
33
+ ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").map(extension => extension.trim().toLowerCase()).filter(extension => extension.length > 0)
34
+ : [""];
35
+ const separator = platform === "win32" ? ";" : delimiter;
36
+ for (const raw of (env.PATH ?? "").split(separator)) {
37
+ const dir = raw.trim().replace(/^"(.*)"$/u, "$1");
38
+ if (dir.length === 0)
39
+ continue;
40
+ for (const extension of extensions) {
41
+ const candidate = join(dir, name + extension);
42
+ if (exists(candidate))
43
+ return candidate;
44
+ }
45
+ }
46
+ return undefined;
47
+ }
48
+ /** The real filesystem, PATH and environment. */
49
+ export function systemNpmLookup() {
50
+ return {
51
+ platform: process.platform,
52
+ env: process.env,
53
+ node: process.execPath,
54
+ exists: existsSync,
55
+ which: name => whichOnPath(name, process.env, process.platform, existsSync),
56
+ };
57
+ }
58
+ /**
59
+ * The `npm-cli.js` files an official node distribution keeps beside its binary.
60
+ *
61
+ * The MSI installer (and nvm-windows) put npm in `<nodeDir>/node_modules`, while nvm on
62
+ * macOS/Linux, Homebrew and the official pkg keep it in `<nodeDir>/../lib/node_modules`. Both
63
+ * layouts are one node install apart, so they cost nothing to list.
64
+ * @param nodeDir - `dirname(process.execPath)`.
65
+ * @returns candidate paths, most likely first.
66
+ */
67
+ export function npmJSEntries(nodeDir) {
68
+ return [
69
+ join(nodeDir, "node_modules", "npm", "bin", "npm-cli.js"),
70
+ join(nodeDir, "..", "lib", "node_modules", "npm", "bin", "npm-cli.js"),
71
+ join(nodeDir, "..", "node_modules", "npm", "bin", "npm-cli.js"),
72
+ ];
73
+ }
74
+ /** A path that ends in JavaScript runs on node: npm itself is such a program. */
75
+ function isJsEntry(path) {
76
+ return /\.(js|mjs|cjs)$/iu.test(path);
77
+ }
78
+ /** A `.cmd`/`.bat` shim: spawn refuses it without a shell, so it is unwrapped or wrapped. */
79
+ function isWindowsShim(path) {
80
+ return /\.(cmd|bat)$/iu.test(path);
81
+ }
82
+ /**
83
+ * Turn a found npm path into an invocation.
84
+ *
85
+ * The npm-cli.js behind a shim is preferred over the shim: it starts through node with no shell,
86
+ * so a prefix containing spaces never depends on how cmd strips quotes. A shim whose package is
87
+ * gone still works through `cmd.exe /d /s /c`, which is Node's own `shell: true` shape.
88
+ * @param found - path that answered the lookup.
89
+ * @param source - how that path was found, for messages.
90
+ * @param lookup - process facts.
91
+ * @returns the invocation to spawn.
92
+ */
93
+ function invocationFor(found, source, lookup) {
94
+ if (isJsEntry(found))
95
+ return { command: lookup.node, kind: "node", entry: found, source };
96
+ if (isWindowsShim(found)) {
97
+ const cli = join(dirname(found), "node_modules", "npm", "bin", "npm-cli.js");
98
+ if (lookup.exists(cli))
99
+ return { command: lookup.node, kind: "node", entry: cli, source: source + " → " + cli };
100
+ return { command: lookup.env.ComSpec ?? "cmd.exe", kind: "cmd", entry: found, source };
101
+ }
102
+ return { command: found, kind: "direct", source };
103
+ }
104
+ /**
105
+ * Every way to run npm on this machine, in the order the ladder tries them: `GBH_NPM`, PATH, the
106
+ * `npm.cmd` beside node (Windows), node running npm's own JS entry, then the macOS system paths.
107
+ * @param lookup - process facts.
108
+ * @returns invocations in preference order, de-duplicated.
109
+ */
110
+ export function npmCandidates(lookup = systemNpmLookup()) {
111
+ const found = [];
112
+ const override = (lookup.env.GBH_NPM ?? "").trim();
113
+ if (override.length > 0)
114
+ found.push(invocationFor(override, "GBH_NPM", lookup));
115
+ const onPath = lookup.which("npm");
116
+ if (onPath !== undefined)
117
+ found.push(invocationFor(onPath, "PATH (" + onPath + ")", lookup));
118
+ const nodeDir = dirname(lookup.node);
119
+ if (lookup.platform === "win32") {
120
+ const shim = join(nodeDir, "npm.cmd");
121
+ if (lookup.exists(shim))
122
+ found.push(invocationFor(shim, "npm.cmd cạnh node (" + shim + ")", lookup));
123
+ }
124
+ for (const entry of npmJSEntries(nodeDir)) {
125
+ if (lookup.exists(entry))
126
+ found.push({ command: lookup.node, kind: "node", entry, source: "node + npm-cli.js (" + entry + ")" });
127
+ }
128
+ if (lookup.platform !== "win32") {
129
+ for (const bin of ["/opt/homebrew/bin/npm", "/usr/local/bin/npm"]) {
130
+ if (lookup.exists(bin))
131
+ found.push(invocationFor(bin, "đường dẫn hệ thống (" + bin + ")", lookup));
132
+ }
133
+ }
134
+ const seen = new Set();
135
+ return found.filter(candidate => {
136
+ const key = candidate.kind + " " + candidate.command + " " + (candidate.entry ?? "");
137
+ if (seen.has(key))
138
+ return false;
139
+ seen.add(key);
140
+ return true;
141
+ });
142
+ }
143
+ /**
144
+ * The npm this machine should use, or undefined when it has none.
145
+ * @param lookup - process facts.
146
+ * @returns the first acceptable invocation.
147
+ */
148
+ export function resolveNpm(lookup = systemNpmLookup()) {
149
+ return npmCandidates(lookup)[0];
150
+ }
151
+ /**
152
+ * The ladder as the user reads it, one entry per rung, for a failure message.
153
+ * @param lookup - process facts.
154
+ * @returns every rung, with the path it looked at.
155
+ */
156
+ export function npmAttempts(lookup = systemNpmLookup()) {
157
+ const attempts = [];
158
+ const override = (lookup.env.GBH_NPM ?? "").trim();
159
+ attempts.push({ label: "GBH_NPM", detail: override.length === 0 ? "chưa đặt" : override, found: override.length > 0 });
160
+ const onPath = lookup.which("npm");
161
+ attempts.push({ label: "PATH (npm)", detail: onPath ?? "không có npm trên PATH", found: onPath !== undefined });
162
+ const nodeDir = dirname(lookup.node);
163
+ if (lookup.platform === "win32") {
164
+ const shim = join(nodeDir, "npm.cmd");
165
+ attempts.push({ label: "npm.cmd cạnh node", detail: shim + (lookup.exists(shim) ? "" : " (không có)"), found: lookup.exists(shim) });
166
+ }
167
+ const entries = npmJSEntries(nodeDir);
168
+ const foundEntry = entries.find(entry => lookup.exists(entry));
169
+ attempts.push({ label: "node + npm-cli.js", detail: foundEntry ?? entries.join(" · "), found: foundEntry !== undefined });
170
+ if (lookup.platform !== "win32") {
171
+ const systemPaths = ["/opt/homebrew/bin/npm", "/usr/local/bin/npm"];
172
+ const foundSystem = systemPaths.find(bin => lookup.exists(bin));
173
+ attempts.push({
174
+ label: "đường dẫn hệ thống",
175
+ detail: foundSystem ?? systemPaths.map(bin => bin + " (không có)").join(" · "),
176
+ found: foundSystem !== undefined,
177
+ });
178
+ }
179
+ return attempts;
180
+ }
181
+ /**
182
+ * The sentence a machine without npm gets: what was tried, what to install, and the manual command.
183
+ *
184
+ * It deliberately says nothing about `spawn` or `ENOENT`: neither is something a person can act on.
185
+ * @param lookup - process facts.
186
+ * @returns several lines, safe to print as-is.
187
+ */
188
+ export function npmMissingMessage(lookup = systemNpmLookup()) {
189
+ const tried = npmAttempts(lookup).map(attempt => " " + attempt.label + ": " + attempt.detail).join("\n");
190
+ return [
191
+ "Không tìm thấy npm trên máy này — blackhole cần npm để cài gói.",
192
+ " đã thử:",
193
+ tried,
194
+ " cách sửa:",
195
+ " - cài Node.js kèm npm (https://nodejs.org — bộ cài chính thức có sẵn npm) rồi chạy lại;",
196
+ " - hoặc đặt GBH_NPM tới npm có trên máy, ví dụ GBH_NPM=/opt/homebrew/bin/npm.",
197
+ " cài tay: " + NPM_MANUAL_HINT,
198
+ ].join("\n");
199
+ }
200
+ /**
201
+ * Quote one argument for `cmd.exe`. Only what cmd would split on or read as syntax is quoted, and
202
+ * an inner quote is escaped the way cmd expects, so paths with spaces survive intact.
203
+ * @param arg - one argv entry.
204
+ * @returns the argument as cmd should receive it.
205
+ */
206
+ export function quoteForCmd(arg) {
207
+ if (arg.length === 0)
208
+ return '""';
209
+ if (!/[\s"&|<>^]/u.test(arg))
210
+ return arg;
211
+ return '"' + arg.replaceAll('"', '\\"') + '"';
212
+ }
213
+ /**
214
+ * Build the one string cmd.exe receives after `/d /s /c`.
215
+ * @param args - argv to run.
216
+ * @returns the command line, quoted per argument.
217
+ */
218
+ export function windowsCommandLine(args) {
219
+ return args.map(quoteForCmd).join(" ");
220
+ }
221
+ /**
222
+ * The argv that starts npm for one invocation.
223
+ * @param invocation - resolved npm.
224
+ * @param args - npm's own arguments.
225
+ * @returns argv for {@link NpmInvocation.command}.
226
+ */
227
+ export function npmArgv(invocation, args) {
228
+ if (invocation.kind === "node")
229
+ return invocation.entry === undefined ? [...args] : [invocation.entry, ...args];
230
+ if (invocation.kind === "cmd")
231
+ return ["/d", "/s", "/c", windowsCommandLine([invocation.entry ?? "npm", ...args])];
232
+ return [...args];
233
+ }
234
+ /**
235
+ * A spawn that failed even though npm was found — a broken shim, a deleted prefix, a permission
236
+ * wall. Still actionable, and still never a bare ENOENT.
237
+ * @param invocation - what was spawned.
238
+ * @param error - the spawn failure.
239
+ * @returns the message the caller prints.
240
+ */
241
+ export function npmSpawnFailure(invocation, error) {
242
+ return [
243
+ "Không chạy được npm qua " + invocation.source + ": " + (error.message.length === 0 ? "lỗi không rõ" : error.message),
244
+ " cách sửa: cài Node.js kèm npm (https://nodejs.org), hoặc đặt GBH_NPM tới npm có trên máy.",
245
+ " cài tay: " + NPM_MANUAL_HINT,
246
+ ].join("\n");
247
+ }
248
+ /**
249
+ * Run npm with the first invocation that exists.
250
+ *
251
+ * Output is captured (stdout and stderr together) and every complete line is handed to
252
+ * {@link NpmRunOptions.onLine}, so a caller can stream progress and still print the tail when the
253
+ * run fails. When no npm exists the result is a failure whose output is
254
+ * {@link npmMissingMessage} — the caller prints guidance, never a spawn error.
255
+ * @param args - npm's own arguments.
256
+ * @param options - lookup, cwd, timeout, line sink, extra environment.
257
+ * @returns exit code, captured output, and which npm ran.
258
+ */
259
+ export function runNpm(args, options = {}) {
260
+ const lookup = options.lookup ?? systemNpmLookup();
261
+ const invocation = resolveNpm(lookup);
262
+ if (invocation === undefined) {
263
+ return Promise.resolve({ ok: false, code: null, output: npmMissingMessage(lookup), timedOut: false });
264
+ }
265
+ return new Promise(resolvePromise => {
266
+ const child = spawn(invocation.command, npmArgv(invocation, args), {
267
+ // Never a shell: a JS entry runs on node, and a Windows shim is wrapped explicitly above.
268
+ shell: false,
269
+ ...(options.cwd === undefined ? {} : { cwd: options.cwd }),
270
+ env: { ...process.env, NO_COLOR: "1", ...(options.env ?? {}) },
271
+ stdio: ["ignore", "pipe", "pipe"],
272
+ });
273
+ let output = "";
274
+ let timedOut = false;
275
+ const absorb = (chunk) => {
276
+ const text = chunk.toString("utf8");
277
+ output = (output + text).slice(-65_536);
278
+ if (options.onLine === undefined)
279
+ return;
280
+ for (const line of text.split("\n"))
281
+ if (line.trim().length > 0)
282
+ options.onLine(line.trimEnd());
283
+ };
284
+ child.stdout?.on("data", absorb);
285
+ child.stderr?.on("data", absorb);
286
+ const timer = options.timeoutMs === undefined
287
+ ? undefined
288
+ : setTimeout(() => { timedOut = true; child.kill("SIGTERM"); }, options.timeoutMs);
289
+ const finish = (code, text) => {
290
+ if (timer !== undefined)
291
+ clearTimeout(timer);
292
+ resolvePromise({ ok: code === 0 && !timedOut, code, output: text, timedOut, invocation });
293
+ };
294
+ child.once("error", (error) => finish(null, npmSpawnFailure(invocation, error)));
295
+ child.once("close", code => finish(code, output));
296
+ });
297
+ }
298
+ /**
299
+ * Parse what `npm --version` printed.
300
+ * @param text - the child's output.
301
+ * @returns major/minor and the version, or undefined when nothing looked like a version.
302
+ */
303
+ export function parseNpmVersion(text) {
304
+ const match = /(\d+)\.(\d+)\.(\d+)/u.exec(text);
305
+ if (match === null)
306
+ return undefined;
307
+ return { major: Number(match[1]), minor: Number(match[2]), version: match[1] + "." + match[2] + "." + match[3] };
308
+ }
309
+ /**
310
+ * Ask the npm this CLI would use which version it is.
311
+ * @param options - lookup and timeout.
312
+ * @returns the version (for instance `10.9.2`), or undefined when npm could not answer.
313
+ */
314
+ export async function readNpmVersion(options = {}) {
315
+ const result = await runNpm(["--version"], { timeoutMs: 20_000, ...options });
316
+ const lines = result.output.trim().split(/\r?\n/u).map(line => line.trim()).filter(line => line.length > 0);
317
+ return parseNpmVersion(lines[lines.length - 1] ?? "")?.version;
318
+ }
319
+ /**
320
+ * Warn about an npm too old for the flags this CLI passes.
321
+ * @param version - what {@link readNpmVersion} returned.
322
+ * @returns one actionable line, or undefined when npm is new enough (or unknown).
323
+ */
324
+ export function npmVersionWarning(version) {
325
+ if (version === undefined)
326
+ return undefined;
327
+ const parsed = parseNpmVersion(version);
328
+ if (parsed === undefined || parsed.major >= MIN_NPM_MAJOR)
329
+ return undefined;
330
+ return "npm v" + parsed.version + " quá cũ: blackhole cần npm >= " + String(MIN_NPM_MAJOR) + " (cờ --omit=dev). Chạy \"npm i -g npm@latest\" rồi thử lại.";
331
+ }
332
+ //# sourceMappingURL=npm-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm-cli.js","sourceRoot":"","sources":["../src/npm-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAErD,iGAAiG;AACjG,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,C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B,QAAQ,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBpE"}
1
+ {"version":3,"file":"tui.d.ts","sourceRoot":"","sources":["../src/tui.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAkE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChI,OAAO,KAAK,EAAuB,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAe5E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,2FAA2F;AAC3F,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,aAAa,GAAG,eAAe,GAAG,eAAe,GAAG,qBAAqB,CAAC,CAAC,CAAC;AAE3K,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAE,OAAO,GAAE,MAAM,IAAe,EAAE,QAAQ,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe,GAAG,gBAAgB,CA2CvO;AAoBD,wBAAgB,OAAO,gCAGtB;AAmaD,wBAAgB,SAAS,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,iBAAiB,CAAA;CAAE,+BA6D5D;AACD,wBAAsB,QAAQ,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBpE"}
package/dist/tui.js CHANGED
@@ -371,7 +371,11 @@ function Screen({ app, plan, planMode, status, jobs = [], agents = [], pending,
371
371
  onNotice("Không kiểm tra được bản mới (" + state.error + ")");
372
372
  return;
373
373
  }
374
- const result = await runSelfUpdate({ onProgress: ({ pct, line }) => onNotice(String(pct).padStart(3) + "% " + line.slice(0, 80)) });
374
+ const result = await runSelfUpdate({
375
+ onProgress: ({ pct, line }) => onNotice(String(pct).padStart(3) + "% " + line.slice(0, 80)),
376
+ // npm older than 7 cannot honour --omit=dev: say it before the install, not after.
377
+ onWarning: line => onNotice(line),
378
+ });
375
379
  setVersion(await checkForUpdate({ stateDir: app.stateDir, force: true }));
376
380
  onNotice(result.ok ? "Đã cập nhật lên v" + state.latest + " — thoát và mở lại blackhole để dùng bản mới" : "Cập nhật thất bại: " + result.output.slice(-200));
377
381
  })();