insta 0.0.48 → 0.0.49
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.
- package/dist/commands/build.js +34 -9
- package/dist/commands/compute.js +446 -46
- package/dist/commands/deploy.js +20 -1
- package/dist/commands/setup.js +4 -79
- package/dist/commands/upgrade.js +282 -54
- package/dist/index.js +15 -10
- package/dist/spawn.js +77 -0
- package/dist/util.js +17 -2
- package/package.json +1 -1
package/dist/spawn.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { existsSync, statSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, win32 } from 'node:path';
|
|
3
|
+
export const isRunnableFile = (path, win) => {
|
|
4
|
+
try {
|
|
5
|
+
const stat = statSync(path);
|
|
6
|
+
if (!stat.isFile())
|
|
7
|
+
return false;
|
|
8
|
+
return win || (stat.mode & 0o111) !== 0;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/** Read an environment variable the way Windows itself does: case-insensitively.
|
|
15
|
+
* `process.env` is already case-insensitive on win32, but a COPY of it (`{ ...process.env }`,
|
|
16
|
+
* which every caller that adds a variable makes) is an ordinary object that keeps whatever
|
|
17
|
+
* casing Windows used — and Windows overwhelmingly spells it `Path`, not `PATH`. Reading
|
|
18
|
+
* `env.PATH` off such a copy yields undefined, nothing resolves, and the caller falls back to
|
|
19
|
+
* spawning the bare `.cmd` shim this module exists to avoid. */
|
|
20
|
+
export function envVar(env, name, win) {
|
|
21
|
+
const direct = env[name];
|
|
22
|
+
if (direct !== undefined || !win)
|
|
23
|
+
return direct;
|
|
24
|
+
const wanted = name.toLowerCase();
|
|
25
|
+
for (const [key, value] of Object.entries(env))
|
|
26
|
+
if (key.toLowerCase() === wanted)
|
|
27
|
+
return value;
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
/** Resolve a bare command name to its absolute PATH location (PATHEXT-aware on Windows).
|
|
31
|
+
* cmd.exe searches the CURRENT DIRECTORY before PATH for bare names, so callers must pass
|
|
32
|
+
* the absolute shim path to the cmd.exe wrapper below. */
|
|
33
|
+
export function whichOnPath(bin, env = process.env, platform = process.platform) {
|
|
34
|
+
const win = platform === 'win32';
|
|
35
|
+
const exts = win ? [...(envVar(env, 'PATHEXT', win) ?? '.COM;.EXE;.BAT;.CMD').split(';'), ''] : [''];
|
|
36
|
+
for (const dir of (envVar(env, 'PATH', win) ?? '').split(win ? ';' : ':')) {
|
|
37
|
+
if (!dir)
|
|
38
|
+
continue;
|
|
39
|
+
for (const ext of exts) {
|
|
40
|
+
const path = join(dir, bin + ext);
|
|
41
|
+
if (isRunnableFile(path, win))
|
|
42
|
+
return path;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
// On Windows `npm`/`npx` and most npm-installed CLIs are .cmd shims, which spawn() without a
|
|
48
|
+
// shell refuses. Prefer re-entering npm/npx through node; otherwise resolve a safe absolute shim
|
|
49
|
+
// path and invoke it through cmd.exe. Kept shared so every child-process call uses the same rules.
|
|
50
|
+
export function resolveSpawnable(cmd, args, npmExecpath = process.env.npm_execpath, execPath = process.execPath, platform = process.platform, env = process.env, systemRoot = process.env.SYSTEMROOT ?? process.env.windir ?? 'C:\\Windows') {
|
|
51
|
+
const execIsNode = /(^|[\\/])node(\.exe)?$/i.test(execPath);
|
|
52
|
+
if ((cmd === 'npm' || cmd === 'npx') && execIsNode) {
|
|
53
|
+
if (npmExecpath && /(^|[\\/])np[mx](-cli)?\.[cm]?js$/.test(npmExecpath)) {
|
|
54
|
+
const cli = npmExecpath.replace(/np[mx](-cli)?(\.[cm]?js)$/, `${cmd}$1$2`);
|
|
55
|
+
if (existsSync(cli))
|
|
56
|
+
return { cmd: execPath, args: [cli, ...args] };
|
|
57
|
+
}
|
|
58
|
+
const nodeDir = dirname(execPath);
|
|
59
|
+
const besideNode = platform === 'win32'
|
|
60
|
+
? join(nodeDir, 'node_modules', 'npm', 'bin', `${cmd}-cli.js`)
|
|
61
|
+
: join(nodeDir, '..', 'lib', 'node_modules', 'npm', 'bin', `${cmd}-cli.js`);
|
|
62
|
+
if (existsSync(besideNode))
|
|
63
|
+
return { cmd: execPath, args: [besideNode, ...args] };
|
|
64
|
+
}
|
|
65
|
+
const bareShim = !/[\\/]/.test(cmd) && !/\.exe$/i.test(cmd);
|
|
66
|
+
if (platform === 'win32' && bareShim && !args.some((arg) => /[&|<>^%"]/.test(arg))) {
|
|
67
|
+
const absolute = whichOnPath(cmd, env, platform);
|
|
68
|
+
// The resolved path itself also becomes cmd.exe input. If a PATH directory contains a shell
|
|
69
|
+
// metacharacter, fail via the caller's normal bare-spawn fallback rather than interpret it.
|
|
70
|
+
// Pin cmd.exe to System32 too: CreateProcess-style lookup checks cwd before PATH.
|
|
71
|
+
if (absolute && !/[&|<>^%"]/.test(absolute)) {
|
|
72
|
+
return { cmd: win32.join(systemRoot, 'System32', 'cmd.exe'), args: ['/d', '/s', '/c', absolute, ...args] };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { cmd, args };
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=spawn.js.map
|
package/dist/util.js
CHANGED
|
@@ -48,9 +48,24 @@ export function openUrl(url) {
|
|
|
48
48
|
return false;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
export
|
|
51
|
+
export class CliExit extends Error {
|
|
52
|
+
constructor() {
|
|
53
|
+
// Preserve the observable error used by direct command-unit tests that previously mocked
|
|
54
|
+
// process.exit(1) by throwing `Error('exit 1')`.
|
|
55
|
+
super('exit 1');
|
|
56
|
+
this.name = 'CliExit';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export function fail(msg) {
|
|
52
60
|
process.stderr.write(`error: ${msg}\n`);
|
|
53
|
-
process.
|
|
61
|
+
process.exitCode = 1;
|
|
62
|
+
}
|
|
63
|
+
// Stop the current command without forcing Node to tear down active libuv handles. On Windows,
|
|
64
|
+
// process.exit() can race the detached update-check child and abort in src\win\async.c with
|
|
65
|
+
// UV_HANDLE_CLOSING. The guard absorbs CliExit after fail() records the intended exit status.
|
|
66
|
+
export function die(msg) {
|
|
67
|
+
fail(msg);
|
|
68
|
+
throw new CliExit();
|
|
54
69
|
}
|
|
55
70
|
export function printJson(v) {
|
|
56
71
|
process.stdout.write(JSON.stringify(v, null, 2) + '\n');
|