@shell-shock/core 0.15.2 → 0.16.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.
- package/dist/api.cjs +10 -7
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts +1 -1
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts +1 -1
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +11 -8
- package/dist/api.mjs.map +1 -1
- package/dist/components/helpers.cjs +1 -1
- package/dist/components/helpers.cjs.map +1 -1
- package/dist/components/helpers.mjs +1 -1
- package/dist/components/helpers.mjs.map +1 -1
- package/dist/components/index.cjs +8 -4
- package/dist/components/index.d.cts +4 -2
- package/dist/components/index.d.mts +4 -2
- package/dist/components/index.mjs +4 -2
- package/dist/components/options-parser-logic.cjs +68 -48
- package/dist/components/options-parser-logic.cjs.map +1 -1
- package/dist/components/options-parser-logic.d.cts.map +1 -1
- package/dist/components/options-parser-logic.d.mts.map +1 -1
- package/dist/components/options-parser-logic.mjs +68 -48
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/spawn-builtin.cjs +656 -0
- package/dist/components/spawn-builtin.cjs.map +1 -0
- package/dist/components/spawn-builtin.d.cts +12 -0
- package/dist/components/spawn-builtin.d.cts.map +1 -0
- package/dist/components/spawn-builtin.d.mts +12 -0
- package/dist/components/spawn-builtin.d.mts.map +1 -0
- package/dist/components/spawn-builtin.mjs +653 -0
- package/dist/components/spawn-builtin.mjs.map +1 -0
- package/dist/components/state-builtin.cjs +553 -0
- package/dist/components/state-builtin.cjs.map +1 -0
- package/dist/components/state-builtin.d.cts +18 -0
- package/dist/components/state-builtin.d.cts.map +1 -0
- package/dist/components/state-builtin.d.mts +18 -0
- package/dist/components/state-builtin.d.mts.map +1 -0
- package/dist/components/state-builtin.mjs +547 -0
- package/dist/components/state-builtin.mjs.map +1 -0
- package/dist/components/utils-builtin.cjs +3 -499
- package/dist/components/utils-builtin.cjs.map +1 -1
- package/dist/components/utils-builtin.d.cts +1 -10
- package/dist/components/utils-builtin.d.cts.map +1 -1
- package/dist/components/utils-builtin.d.mts +1 -10
- package/dist/components/utils-builtin.d.mts.map +1 -1
- package/dist/components/utils-builtin.mjs +5 -498
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.mjs.map +1 -1
- package/dist/contexts/options.cjs +9 -9
- package/dist/contexts/options.cjs.map +1 -1
- package/dist/contexts/options.d.cts +2 -2
- package/dist/contexts/options.d.cts.map +1 -1
- package/dist/contexts/options.d.mts +2 -2
- package/dist/contexts/options.d.mts.map +1 -1
- package/dist/contexts/options.mjs +9 -9
- package/dist/contexts/options.mjs.map +1 -1
- package/dist/index.cjs +2 -10
- package/dist/index.d.cts +1 -2
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +1 -7
- package/dist/plugin.cjs +11 -26
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +1 -1
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +10 -24
- package/dist/plugin.mjs.map +1 -1
- package/dist/types/config.cjs +3 -1
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.cts +1 -1
- package/dist/types/config.d.cts.map +1 -1
- package/dist/types/config.d.mts +1 -1
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/config.mjs +3 -1
- package/dist/types/config.mjs.map +1 -1
- package/dist/types/env.cjs +2 -1
- package/dist/types/env.cjs.map +1 -1
- package/dist/types/env.d.cts +15 -0
- package/dist/types/env.d.cts.map +1 -1
- package/dist/types/env.d.mts +15 -0
- package/dist/types/env.d.mts.map +1 -1
- package/dist/types/env.mjs +2 -1
- package/dist/types/env.mjs.map +1 -1
- package/dist/types/index.cjs +0 -2
- package/dist/types/index.d.cts +1 -2
- package/dist/types/index.d.mts +1 -2
- package/dist/types/index.mjs +1 -2
- package/package.json +50 -36
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/types/runtime.cjs +0 -13
- package/dist/types/runtime.cjs.map +0 -1
- package/dist/types/runtime.d.cts +0 -14
- package/dist/types/runtime.d.cts.map +0 -1
- package/dist/types/runtime.d.mts +0 -14
- package/dist/types/runtime.d.mts.map +0 -1
- package/dist/types/runtime.mjs +0 -11
- package/dist/types/runtime.mjs.map +0 -1
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
4
|
+
let defu = require("defu");
|
|
5
|
+
defu = require_runtime.__toESM(defu);
|
|
6
|
+
let _alloy_js_core = require("@alloy-js/core");
|
|
7
|
+
let _powerlines_plugin_alloy_core_components_spacing = require("@powerlines/plugin-alloy/core/components/spacing");
|
|
8
|
+
let _alloy_js_typescript = require("@alloy-js/typescript");
|
|
9
|
+
let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
10
|
+
let _powerlines_plugin_alloy_typescript_components_builtin_file = require("@powerlines/plugin-alloy/typescript/components/builtin-file");
|
|
11
|
+
let _powerlines_plugin_alloy_typescript_components_tsdoc = require("@powerlines/plugin-alloy/typescript/components/tsdoc");
|
|
12
|
+
|
|
13
|
+
//#region src/components/spawn-builtin.tsx
|
|
14
|
+
/**
|
|
15
|
+
* A built-in module for handling child process spawning in Shell Shock.
|
|
16
|
+
*/
|
|
17
|
+
function SpawnBuiltin(props) {
|
|
18
|
+
const [{ children }, rest] = (0, _alloy_js_core.splitProps)(props, ["children"]);
|
|
19
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_builtin_file.BuiltinFile, (0, _alloy_js_core_jsx_runtime.mergeProps)({
|
|
20
|
+
id: "spawn",
|
|
21
|
+
description: "A module to handle spawning child processes."
|
|
22
|
+
}, rest, {
|
|
23
|
+
get imports() {
|
|
24
|
+
return (0, defu.default)(rest.imports ?? {}, {
|
|
25
|
+
"node:path": [
|
|
26
|
+
"basename",
|
|
27
|
+
"extname",
|
|
28
|
+
"dirname",
|
|
29
|
+
"join"
|
|
30
|
+
],
|
|
31
|
+
"node:fs": ["existsSync"],
|
|
32
|
+
"node:child_process": [{
|
|
33
|
+
name: "spawn",
|
|
34
|
+
alias: "_spawn"
|
|
35
|
+
}],
|
|
36
|
+
"node:stream": [{
|
|
37
|
+
name: "Stream",
|
|
38
|
+
default: true,
|
|
39
|
+
type: true
|
|
40
|
+
}]
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
get builtinImports() {
|
|
44
|
+
return (0, defu.default)(rest.builtinImports ?? {}, { env: ["isWindows"] });
|
|
45
|
+
},
|
|
46
|
+
get children() {
|
|
47
|
+
return [
|
|
48
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
49
|
+
name: "resolveCommandEnv",
|
|
50
|
+
parameters: [{
|
|
51
|
+
name: "params",
|
|
52
|
+
type: "{ argv: string[]; env?: NodeJS.ProcessEnv; baseEnv?: NodeJS.ProcessEnv; }"
|
|
53
|
+
}],
|
|
54
|
+
returnType: "NodeJS.ProcessEnv",
|
|
55
|
+
children: _alloy_js_core.code`const baseEnv = params.baseEnv ?? process.env;
|
|
56
|
+
const argv = params.argv;
|
|
57
|
+
const shouldSuppressNpmFund = (() => {
|
|
58
|
+
const cmd = basename(argv[0] ?? "");
|
|
59
|
+
if (cmd === "npm" || cmd === "npm.cmd" || cmd === "npm.exe") {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
if (cmd === "node" || cmd === "node.exe") {
|
|
63
|
+
const script = argv[1] ?? "";
|
|
64
|
+
|
|
65
|
+
return script.includes("npm-cli.js");
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
})();
|
|
69
|
+
|
|
70
|
+
const mergedEnv = params.env ? { ...baseEnv, ...params.env } : { ...baseEnv };
|
|
71
|
+
const resolvedEnv = Object.fromEntries(
|
|
72
|
+
Object.entries(mergedEnv)
|
|
73
|
+
.filter(([, value]) => value !== undefined)
|
|
74
|
+
.map(([key, value]) => [key, String(value)])
|
|
75
|
+
);
|
|
76
|
+
if (shouldSuppressNpmFund) {
|
|
77
|
+
resolvedEnv.NPM_CONFIG_FUND ??= "false";
|
|
78
|
+
resolvedEnv.npm_config_fund ??= "false";
|
|
79
|
+
}
|
|
80
|
+
return resolvedEnv;`
|
|
81
|
+
}),
|
|
82
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
83
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
84
|
+
name: "isWindowsBatchCommand",
|
|
85
|
+
parameters: [{
|
|
86
|
+
name: "resolvedCommand",
|
|
87
|
+
type: "string"
|
|
88
|
+
}],
|
|
89
|
+
returnType: "boolean",
|
|
90
|
+
children: _alloy_js_core.code`if (!isWindows) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
const ext = extname(resolvedCommand).toLowerCase();
|
|
94
|
+
|
|
95
|
+
return ext === ".cmd" || ext === ".bat";`
|
|
96
|
+
}),
|
|
97
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
98
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
99
|
+
name: "escapeForCmdExe",
|
|
100
|
+
parameters: [{
|
|
101
|
+
name: "arg",
|
|
102
|
+
type: "string"
|
|
103
|
+
}],
|
|
104
|
+
returnType: "string",
|
|
105
|
+
children: _alloy_js_core.code`if (/[&|<>^%\\\\r\\\\n]/.test(arg)) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
\`Unsafe Windows cmd.exe argument detected: \${JSON.stringify(arg)}. \` +
|
|
108
|
+
"Pass an explicit shell-wrapper argv at the call site instead."
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
if (!arg.includes(" ") && !arg.includes('"')) {
|
|
112
|
+
return arg;
|
|
113
|
+
}
|
|
114
|
+
return \`"\${arg.replace(/"/g, '""')}"\`;`
|
|
115
|
+
}),
|
|
116
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
117
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
118
|
+
name: "buildCmdExeCommandLine",
|
|
119
|
+
parameters: [{
|
|
120
|
+
name: "resolvedCommand",
|
|
121
|
+
type: "string"
|
|
122
|
+
}, {
|
|
123
|
+
name: "args",
|
|
124
|
+
type: "string[]"
|
|
125
|
+
}],
|
|
126
|
+
returnType: "string",
|
|
127
|
+
children: _alloy_js_core.code`return [escapeForCmdExe(resolvedCommand), ...args.map(escapeForCmdExe)].join(
|
|
128
|
+
" "
|
|
129
|
+
);`
|
|
130
|
+
}),
|
|
131
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
132
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
133
|
+
name: "resolveNpmArgvForWindows",
|
|
134
|
+
doc: "On Windows, Node 18.20.2+ (CVE-2024-27980) rejects spawning .cmd/.bat directly without shell, causing EINVAL. Resolve npm/npx to node + cli script so we spawn node.exe instead of npm.cmd.",
|
|
135
|
+
parameters: [{
|
|
136
|
+
name: "argv",
|
|
137
|
+
type: "string[]"
|
|
138
|
+
}],
|
|
139
|
+
returnType: "string[] | null",
|
|
140
|
+
children: _alloy_js_core.code`if (!isWindows || argv.length === 0) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
const base = basename(argv[0] ?? "")
|
|
144
|
+
.toLowerCase()
|
|
145
|
+
.replace(/\.(?:cmd|exe|bat)$/, "");
|
|
146
|
+
const cliName =
|
|
147
|
+
base === "npx" ? "npx-cli.js" : base === "npm" ? "npm-cli.js" : null;
|
|
148
|
+
if (!cliName) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
const nodeDir = dirname(process.execPath);
|
|
152
|
+
const cliPath = join(nodeDir, "node_modules", "npm", "bin", cliName);
|
|
153
|
+
if (!existsSync(cliPath)) {
|
|
154
|
+
const command = argv[0] ?? "";
|
|
155
|
+
const ext = extname(command).toLowerCase();
|
|
156
|
+
const shimmedCommand = ext ? command : \`\${command}.cmd\`;
|
|
157
|
+
|
|
158
|
+
return [shimmedCommand, ...argv.slice(1)];
|
|
159
|
+
}
|
|
160
|
+
return [process.execPath, cliPath, ...argv.slice(1)];`
|
|
161
|
+
}),
|
|
162
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
163
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
164
|
+
name: "resolveCommand",
|
|
165
|
+
doc: "Resolves a command for Windows compatibility. On Windows, non-.exe commands (like pnpm, yarn) are resolved to .cmd; npm/npx are handled by resolveNpmArgvForWindows to avoid spawn EINVAL (no direct .cmd).",
|
|
166
|
+
parameters: [{
|
|
167
|
+
name: "command",
|
|
168
|
+
type: "string"
|
|
169
|
+
}],
|
|
170
|
+
returnType: "string",
|
|
171
|
+
children: _alloy_js_core.code`if (!isWindows) {
|
|
172
|
+
return command;
|
|
173
|
+
}
|
|
174
|
+
const base = basename(command).toLowerCase();
|
|
175
|
+
if (extname(base)) {
|
|
176
|
+
return command;
|
|
177
|
+
}
|
|
178
|
+
if (["pnpm", "yarn"].includes(base)) {
|
|
179
|
+
return \`\${command}.cmd\`;
|
|
180
|
+
}
|
|
181
|
+
return command;`
|
|
182
|
+
}),
|
|
183
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
184
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
185
|
+
name: "resolveCommandStdio",
|
|
186
|
+
parameters: [{
|
|
187
|
+
name: "params",
|
|
188
|
+
type: "{ hasInput: boolean; preferInherit: boolean; }"
|
|
189
|
+
}],
|
|
190
|
+
returnType: "[\"pipe\" | \"inherit\" | \"ignore\", \"pipe\", \"pipe\"]",
|
|
191
|
+
children: _alloy_js_core.code`const stdin = params.hasInput
|
|
192
|
+
? "pipe"
|
|
193
|
+
: params.preferInherit
|
|
194
|
+
? "inherit"
|
|
195
|
+
: "pipe";
|
|
196
|
+
|
|
197
|
+
return [stdin, "pipe", "pipe"];`
|
|
198
|
+
}),
|
|
199
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
200
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
201
|
+
name: "resolveChildProcessInvocation",
|
|
202
|
+
parameters: [{
|
|
203
|
+
name: "params",
|
|
204
|
+
type: "{ argv: string[]; windowsVerbatimArguments?: boolean; }"
|
|
205
|
+
}],
|
|
206
|
+
returnType: "{ args: string[]; command: string; usesWindowsExitCodeShim: boolean; windowsHide: true; windowsVerbatimArguments?: boolean; }",
|
|
207
|
+
children: _alloy_js_core.code`const finalArgv =
|
|
208
|
+
isWindows
|
|
209
|
+
? (resolveNpmArgvForWindows(params.argv) ?? params.argv)
|
|
210
|
+
: params.argv;
|
|
211
|
+
const resolvedCommand =
|
|
212
|
+
finalArgv !== params.argv
|
|
213
|
+
? (finalArgv[0] ?? "")
|
|
214
|
+
: resolveCommand(params.argv[0] ?? "");
|
|
215
|
+
const useCmdWrapper = isWindowsBatchCommand(resolvedCommand);
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
command: useCmdWrapper
|
|
219
|
+
? (process.env.ComSpec ?? "cmd.exe")
|
|
220
|
+
: resolvedCommand,
|
|
221
|
+
args: useCmdWrapper
|
|
222
|
+
? [
|
|
223
|
+
"/d",
|
|
224
|
+
"/s",
|
|
225
|
+
"/c",
|
|
226
|
+
buildCmdExeCommandLine(resolvedCommand, finalArgv.slice(1))
|
|
227
|
+
]
|
|
228
|
+
: finalArgv.slice(1),
|
|
229
|
+
usesWindowsExitCodeShim:
|
|
230
|
+
isWindows &&
|
|
231
|
+
(useCmdWrapper || finalArgv !== params.argv),
|
|
232
|
+
windowsHide: true,
|
|
233
|
+
windowsVerbatimArguments: useCmdWrapper
|
|
234
|
+
? true
|
|
235
|
+
: params.windowsVerbatimArguments
|
|
236
|
+
};`
|
|
237
|
+
}),
|
|
238
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
239
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
240
|
+
name: "resolveProcessExitCode",
|
|
241
|
+
parameters: [{
|
|
242
|
+
name: "params",
|
|
243
|
+
type: "{ explicitCode: number | null | undefined; childExitCode: number | null | undefined; resolvedSignal: NodeJS.Signals | null; usesWindowsExitCodeShim: boolean; timedOut: boolean; noOutputTimedOut: boolean; killIssuedByTimeout: boolean; }"
|
|
244
|
+
}],
|
|
245
|
+
returnType: "number | null",
|
|
246
|
+
children: _alloy_js_core.code`return (
|
|
247
|
+
params.explicitCode ??
|
|
248
|
+
params.childExitCode ??
|
|
249
|
+
(params.usesWindowsExitCodeShim &&
|
|
250
|
+
params.resolvedSignal == null &&
|
|
251
|
+
!params.timedOut &&
|
|
252
|
+
!params.noOutputTimedOut &&
|
|
253
|
+
!params.killIssuedByTimeout
|
|
254
|
+
? 0
|
|
255
|
+
: null)
|
|
256
|
+
);`
|
|
257
|
+
}),
|
|
258
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
259
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
260
|
+
name: "shouldSpawnWithShell",
|
|
261
|
+
parameters: [{
|
|
262
|
+
name: "params",
|
|
263
|
+
type: "{ resolvedCommand: string; platform: NodeJS.Platform; }"
|
|
264
|
+
}],
|
|
265
|
+
returnType: "boolean",
|
|
266
|
+
children: _alloy_js_core.code`// SECURITY: never enable \`shell\` for argv-based execution.
|
|
267
|
+
// \`shell\` routes through cmd.exe on Windows, which turns untrusted argv values
|
|
268
|
+
// (like chat prompts passed as CLI args) into command-injection primitives.
|
|
269
|
+
// If you need a shell, use an explicit shell-wrapper argv (e.g. \`cmd.exe /c ...\`)
|
|
270
|
+
// and validate/escape at the call site.
|
|
271
|
+
void params;
|
|
272
|
+
return false;`
|
|
273
|
+
}),
|
|
274
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
275
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The result of a spawn operation." }),
|
|
276
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceDeclaration, {
|
|
277
|
+
"export": true,
|
|
278
|
+
name: "SpawnResult",
|
|
279
|
+
get children() {
|
|
280
|
+
return [
|
|
281
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The PID of the spawned child process, if available." }),
|
|
282
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
283
|
+
name: "pid",
|
|
284
|
+
optional: true,
|
|
285
|
+
type: "number"
|
|
286
|
+
}),
|
|
287
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
288
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The standard output produced by the child process." }),
|
|
289
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
290
|
+
name: "stdout",
|
|
291
|
+
type: "string"
|
|
292
|
+
}),
|
|
293
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
294
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The standard error produced by the child process." }),
|
|
295
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
296
|
+
name: "stderr",
|
|
297
|
+
type: "string"
|
|
298
|
+
}),
|
|
299
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
300
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The exit code of the child process, if available." }),
|
|
301
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
302
|
+
name: "code",
|
|
303
|
+
type: "number | null"
|
|
304
|
+
}),
|
|
305
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
306
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The signal that caused the child process to terminate, if it was killed by a signal." }),
|
|
307
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
308
|
+
name: "signal",
|
|
309
|
+
type: "NodeJS.Signals | null"
|
|
310
|
+
}),
|
|
311
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
312
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "Whether the child process was killed." }),
|
|
313
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
314
|
+
name: "killed",
|
|
315
|
+
type: "boolean"
|
|
316
|
+
}),
|
|
317
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
318
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The reason for the child process termination." }),
|
|
319
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
320
|
+
name: "termination",
|
|
321
|
+
type: _alloy_js_core.code`"exit" | "timeout" | "no-output-timeout" | "signal"`
|
|
322
|
+
}),
|
|
323
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
324
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "Whether the child process timed out due to no output." }),
|
|
325
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
326
|
+
name: "noOutputTimedOut",
|
|
327
|
+
optional: true,
|
|
328
|
+
type: "boolean"
|
|
329
|
+
})
|
|
330
|
+
];
|
|
331
|
+
}
|
|
332
|
+
}),
|
|
333
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
334
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "Options for spawning a child process." }),
|
|
335
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceDeclaration, {
|
|
336
|
+
"export": true,
|
|
337
|
+
name: "SpawnOptions",
|
|
338
|
+
get children() {
|
|
339
|
+
return [
|
|
340
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
341
|
+
heading: "The timeout in milliseconds for the spawn operation. If the process runs longer than this, it will be killed and the spawn promise will reject. This can also be provided as a number directly to the spawn function for convenience. Providing \\`-1\\` will disable the timeout.",
|
|
342
|
+
get children() {
|
|
343
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocDefaultValue, {
|
|
344
|
+
get type() {
|
|
345
|
+
return _powerlines_deepkit_vendor_type.ReflectionKind.number;
|
|
346
|
+
},
|
|
347
|
+
defaultValue: "300000"
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}),
|
|
351
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
352
|
+
name: "timeoutMs",
|
|
353
|
+
type: "number"
|
|
354
|
+
}),
|
|
355
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
356
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The current working directory of the child process." }),
|
|
357
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
358
|
+
name: "cwd",
|
|
359
|
+
optional: true,
|
|
360
|
+
type: "string"
|
|
361
|
+
}),
|
|
362
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
363
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The input to be passed to the child process." }),
|
|
364
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
365
|
+
name: "input",
|
|
366
|
+
optional: true,
|
|
367
|
+
type: "string"
|
|
368
|
+
}),
|
|
369
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
370
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The environment variables for the child process." }),
|
|
371
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
372
|
+
name: "env",
|
|
373
|
+
optional: true,
|
|
374
|
+
type: "NodeJS.ProcessEnv"
|
|
375
|
+
}),
|
|
376
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
377
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "Whether to pass arguments to the child process verbatim on Windows." }),
|
|
378
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
379
|
+
name: "windowsVerbatimArguments",
|
|
380
|
+
optional: true,
|
|
381
|
+
type: "boolean"
|
|
382
|
+
}),
|
|
383
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
384
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The timeout in milliseconds for the child process to produce output on stdout or stderr. If the process produces no output for this duration, it will be killed and the spawn promise will reject with a no-output-timeout termination reason." }),
|
|
385
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
386
|
+
name: "noOutputTimeoutMs",
|
|
387
|
+
optional: true,
|
|
388
|
+
type: "number"
|
|
389
|
+
})
|
|
390
|
+
];
|
|
391
|
+
}
|
|
392
|
+
}),
|
|
393
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
394
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
395
|
+
"const": true,
|
|
396
|
+
name: "WINDOWS_CLOSE_STATE_SETTLE_TIMEOUT_MS",
|
|
397
|
+
initializer: _alloy_js_core.code`250`
|
|
398
|
+
}),
|
|
399
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
400
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
401
|
+
"const": true,
|
|
402
|
+
name: "WINDOWS_CLOSE_STATE_POLL_MS",
|
|
403
|
+
initializer: _alloy_js_core.code`10`
|
|
404
|
+
}),
|
|
405
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
406
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
407
|
+
heading: "Spawns a child process with the given arguments and options, returning a promise that resolves with the result of the spawn operation.",
|
|
408
|
+
get children() {
|
|
409
|
+
return [
|
|
410
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
|
|
411
|
+
name: "argv",
|
|
412
|
+
children: "The command and its arguments to spawn."
|
|
413
|
+
}),
|
|
414
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
|
|
415
|
+
name: "optionsOrTimeoutMs",
|
|
416
|
+
children: `The options for spawning the command, or a number representing the timeout in milliseconds. This allows for a convenient shorthand when only a timeout is needed. Providing \`-1\` will disable the timeout. If no options or timeout are provided, a default timeout of 5 minutes will be used.`
|
|
417
|
+
}),
|
|
418
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "A promise that resolves with the result of the spawn operation, including stdout, stderr, exit code, signal, and termination reason." })
|
|
419
|
+
];
|
|
420
|
+
}
|
|
421
|
+
}),
|
|
422
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
423
|
+
"export": true,
|
|
424
|
+
async: true,
|
|
425
|
+
name: "spawn",
|
|
426
|
+
parameters: [{
|
|
427
|
+
name: "argv",
|
|
428
|
+
type: "string[]"
|
|
429
|
+
}, {
|
|
430
|
+
name: "optionsOrTimeoutMs",
|
|
431
|
+
type: "number | SpawnOptions",
|
|
432
|
+
default: "300000"
|
|
433
|
+
}],
|
|
434
|
+
returnType: "Promise<SpawnResult>",
|
|
435
|
+
children: _alloy_js_core.code`const options: SpawnOptions =
|
|
436
|
+
typeof optionsOrTimeoutMs === "number"
|
|
437
|
+
? { timeoutMs: optionsOrTimeoutMs }
|
|
438
|
+
: optionsOrTimeoutMs;
|
|
439
|
+
const { timeoutMs, cwd, input, env, noOutputTimeoutMs } = options;
|
|
440
|
+
const hasInput = input !== undefined;
|
|
441
|
+
const resolvedEnv = resolveCommandEnv({ argv, env });
|
|
442
|
+
const stdio = resolveCommandStdio({ hasInput, preferInherit: true });
|
|
443
|
+
const invocation = resolveChildProcessInvocation({
|
|
444
|
+
argv,
|
|
445
|
+
windowsVerbatimArguments: options.windowsVerbatimArguments
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
const child = _spawn(invocation.command, invocation.args, {
|
|
449
|
+
stdio,
|
|
450
|
+
cwd,
|
|
451
|
+
env: resolvedEnv,
|
|
452
|
+
windowsHide: invocation.windowsHide,
|
|
453
|
+
windowsVerbatimArguments: invocation.windowsVerbatimArguments,
|
|
454
|
+
...(shouldSpawnWithShell({
|
|
455
|
+
resolvedCommand: invocation.command,
|
|
456
|
+
platform: process.platform
|
|
457
|
+
})
|
|
458
|
+
? { shell: true }
|
|
459
|
+
: {})
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
return new Promise((resolve, reject) => {
|
|
463
|
+
let stdout = "";
|
|
464
|
+
let stderr = "";
|
|
465
|
+
let settled = false;
|
|
466
|
+
let timedOut = false;
|
|
467
|
+
let noOutputTimedOut = false;
|
|
468
|
+
let killIssuedByTimeout = false;
|
|
469
|
+
let childExitState: {
|
|
470
|
+
code: number | null;
|
|
471
|
+
signal: NodeJS.Signals | null;
|
|
472
|
+
} | null = null;
|
|
473
|
+
let closeFallbackTimer: NodeJS.Timeout | null = null;
|
|
474
|
+
let noOutputTimer: NodeJS.Timeout | null = null;
|
|
475
|
+
const shouldTrackOutputTimeout =
|
|
476
|
+
typeof noOutputTimeoutMs === "number" &&
|
|
477
|
+
Number.isFinite(noOutputTimeoutMs) &&
|
|
478
|
+
noOutputTimeoutMs > 0;
|
|
479
|
+
|
|
480
|
+
const clearNoOutputTimer = () => {
|
|
481
|
+
if (!noOutputTimer) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
clearTimeout(noOutputTimer);
|
|
485
|
+
noOutputTimer = null;
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const clearCloseFallbackTimer = () => {
|
|
489
|
+
if (!closeFallbackTimer) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
clearTimeout(closeFallbackTimer);
|
|
493
|
+
closeFallbackTimer = null;
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
const killChild = () => {
|
|
497
|
+
if (settled || typeof child?.kill !== "function") {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
killIssuedByTimeout = true;
|
|
501
|
+
child.kill("SIGKILL");
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
const armNoOutputTimer = () => {
|
|
505
|
+
if (!shouldTrackOutputTimeout || settled) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
clearNoOutputTimer();
|
|
509
|
+
noOutputTimer = setTimeout(() => {
|
|
510
|
+
if (settled) {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
noOutputTimedOut = true;
|
|
514
|
+
killChild();
|
|
515
|
+
}, Math.floor(noOutputTimeoutMs));
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
const timer = setTimeout(() => {
|
|
519
|
+
timedOut = true;
|
|
520
|
+
killChild();
|
|
521
|
+
}, timeoutMs >= 0 ? timeoutMs : Number.POSITIVE_INFINITY);
|
|
522
|
+
armNoOutputTimer();
|
|
523
|
+
|
|
524
|
+
if (hasInput && child.stdin) {
|
|
525
|
+
child.stdin.write(input ?? "");
|
|
526
|
+
child.stdin.end();
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
child.stdout?.on("data", (d: Stream) => {
|
|
530
|
+
stdout += d.toString();
|
|
531
|
+
armNoOutputTimer();
|
|
532
|
+
});
|
|
533
|
+
child.stderr?.on("data", (d: Stream) => {
|
|
534
|
+
stderr += d.toString();
|
|
535
|
+
armNoOutputTimer();
|
|
536
|
+
});
|
|
537
|
+
child.on("error", err => {
|
|
538
|
+
if (settled) {
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
settled = true;
|
|
542
|
+
clearTimeout(timer);
|
|
543
|
+
clearNoOutputTimer();
|
|
544
|
+
clearCloseFallbackTimer();
|
|
545
|
+
reject(err);
|
|
546
|
+
});
|
|
547
|
+
child.on("exit", (code, signal) => {
|
|
548
|
+
childExitState = { code, signal };
|
|
549
|
+
if (settled || closeFallbackTimer) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
closeFallbackTimer = setTimeout(() => {
|
|
553
|
+
if (settled) {
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
child.stdout?.destroy();
|
|
557
|
+
child.stderr?.destroy();
|
|
558
|
+
}, 250);
|
|
559
|
+
});
|
|
560
|
+
const resolveFromClose = (
|
|
561
|
+
code: number | null,
|
|
562
|
+
signal: NodeJS.Signals | null
|
|
563
|
+
) => {
|
|
564
|
+
if (settled) {
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
settled = true;
|
|
568
|
+
clearTimeout(timer);
|
|
569
|
+
clearNoOutputTimer();
|
|
570
|
+
clearCloseFallbackTimer();
|
|
571
|
+
const resolvedSignal =
|
|
572
|
+
childExitState?.signal ?? signal ?? child.signalCode ?? null;
|
|
573
|
+
const resolvedCode = resolveProcessExitCode({
|
|
574
|
+
explicitCode: childExitState?.code ?? code,
|
|
575
|
+
childExitCode: child.exitCode,
|
|
576
|
+
resolvedSignal,
|
|
577
|
+
usesWindowsExitCodeShim: invocation.usesWindowsExitCodeShim,
|
|
578
|
+
timedOut,
|
|
579
|
+
noOutputTimedOut,
|
|
580
|
+
killIssuedByTimeout
|
|
581
|
+
});
|
|
582
|
+
const termination = noOutputTimedOut
|
|
583
|
+
? "no-output-timeout"
|
|
584
|
+
: timedOut
|
|
585
|
+
? "timeout"
|
|
586
|
+
: resolvedSignal != null
|
|
587
|
+
? "signal"
|
|
588
|
+
: "exit";
|
|
589
|
+
const normalizedCode =
|
|
590
|
+
termination === "timeout" || termination === "no-output-timeout"
|
|
591
|
+
? resolvedCode === 0
|
|
592
|
+
? 124
|
|
593
|
+
: resolvedCode
|
|
594
|
+
: resolvedCode;
|
|
595
|
+
resolve({
|
|
596
|
+
pid: child.pid ?? undefined,
|
|
597
|
+
stdout,
|
|
598
|
+
stderr,
|
|
599
|
+
code: normalizedCode,
|
|
600
|
+
signal: resolvedSignal,
|
|
601
|
+
killed: child.killed,
|
|
602
|
+
termination,
|
|
603
|
+
noOutputTimedOut
|
|
604
|
+
});
|
|
605
|
+
};
|
|
606
|
+
child.on("close", (code, signal) => {
|
|
607
|
+
if (
|
|
608
|
+
!isWindows ||
|
|
609
|
+
childExitState != null ||
|
|
610
|
+
code != null ||
|
|
611
|
+
signal != null ||
|
|
612
|
+
child.exitCode != null ||
|
|
613
|
+
child.signalCode != null
|
|
614
|
+
) {
|
|
615
|
+
resolveFromClose(code, signal);
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
const startedAt = Date.now();
|
|
620
|
+
const waitForExitState = () => {
|
|
621
|
+
if (settled) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
if (
|
|
625
|
+
childExitState != null ||
|
|
626
|
+
child.exitCode != null ||
|
|
627
|
+
child.signalCode != null
|
|
628
|
+
) {
|
|
629
|
+
resolveFromClose(code, signal);
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
if (Date.now() - startedAt >= WINDOWS_CLOSE_STATE_SETTLE_TIMEOUT_MS) {
|
|
633
|
+
resolveFromClose(code, signal);
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
setTimeout(waitForExitState, WINDOWS_CLOSE_STATE_POLL_MS);
|
|
637
|
+
};
|
|
638
|
+
waitForExitState();
|
|
639
|
+
});
|
|
640
|
+
});`
|
|
641
|
+
}),
|
|
642
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
643
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
644
|
+
get when() {
|
|
645
|
+
return Boolean(children);
|
|
646
|
+
},
|
|
647
|
+
children
|
|
648
|
+
})
|
|
649
|
+
];
|
|
650
|
+
}
|
|
651
|
+
}));
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
//#endregion
|
|
655
|
+
exports.SpawnBuiltin = SpawnBuiltin;
|
|
656
|
+
//# sourceMappingURL=spawn-builtin.cjs.map
|