@veryfront/ext-content-mdx 0.1.1239 → 0.1.1241
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/esm/deno.d.ts +14 -5
- package/esm/deno.js +23 -7
- package/esm/src/errors/error-registry/runtime.d.ts +2 -0
- package/esm/src/errors/error-registry/runtime.d.ts.map +1 -1
- package/esm/src/errors/error-registry/runtime.js +8 -0
- package/esm/src/errors/error-registry.d.ts +1 -0
- package/esm/src/errors/error-registry.d.ts.map +1 -1
- package/esm/src/errors/veryfront-error.d.ts.map +1 -1
- package/esm/src/observability/telemetry-error.js +2 -2
- package/esm/src/observability/tracing/telemetry-env.js +1 -1
- package/esm/src/platform/compat/process/lifecycle.d.ts +10 -0
- package/esm/src/platform/compat/process/lifecycle.d.ts.map +1 -1
- package/esm/src/platform/compat/process/lifecycle.js +23 -0
- package/esm/src/transforms/import-rewriter/url-builder.d.ts +2 -19
- package/esm/src/transforms/import-rewriter/url-builder.d.ts.map +1 -1
- package/esm/src/transforms/import-rewriter/url-builder.js +2 -67
- package/esm/src/transforms/shared/esm-sh-specifier.d.ts +18 -0
- package/esm/src/transforms/shared/esm-sh-specifier.d.ts.map +1 -0
- package/esm/src/transforms/shared/esm-sh-specifier.js +253 -0
- package/esm/src/utils/feature-flags.js +1 -1
- package/esm/src/utils/perf-timer.js +1 -1
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +2 -2
- package/esm/src/platform/compat/abort-signal.d.ts +0 -20
- package/esm/src/platform/compat/abort-signal.d.ts.map +0 -1
- package/esm/src/platform/compat/abort-signal.js +0 -64
- package/esm/src/platform/compat/dynamic-import.d.ts +0 -11
- package/esm/src/platform/compat/dynamic-import.d.ts.map +0 -1
- package/esm/src/platform/compat/dynamic-import.js +0 -10
- package/esm/src/platform/compat/process/command.d.ts +0 -56
- package/esm/src/platform/compat/process/command.d.ts.map +0 -1
- package/esm/src/platform/compat/process/command.js +0 -525
- package/esm/src/platform/compat/process.d.ts +0 -5
- package/esm/src/platform/compat/process.d.ts.map +0 -1
- package/esm/src/platform/compat/process.js +0 -4
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
|
-
import { dynamicImport } from "../dynamic-import.js";
|
|
3
|
-
import { addAbortSignalListenerOnce, isAbortSignalAborted, isAbortSignalWithoutHooks, removeAbortSignalListener, } from "../abort-signal.js";
|
|
4
|
-
import { getDenoRuntime, isBun as IS_BUN, isDeno as IS_DENO } from "../runtime.js";
|
|
5
|
-
import { isWindowsPlatform, runtimeProcess } from "./runtime-process.js";
|
|
6
|
-
const COMMAND_TIMEOUT_EXIT_CODE = 124;
|
|
7
|
-
const COMMAND_OUTPUT_LIMIT_EXIT_CODE = 125;
|
|
8
|
-
const COMMAND_ABORT_EXIT_CODE = 130;
|
|
9
|
-
const FORCE_KILL_GRACE_MS = 250;
|
|
10
|
-
const DEFAULT_MAX_OUTPUT_BYTES = 16 * 1024 * 1024;
|
|
11
|
-
const MAX_COMMAND_TIMEOUT_MS = 2_147_483_647;
|
|
12
|
-
const apply = Reflect.apply;
|
|
13
|
-
const uint8ArraySlice = Uint8Array.prototype.slice;
|
|
14
|
-
function createTerminationResult(reason, detail, stdout, stderr, outputTruncated = reason === "output-limit") {
|
|
15
|
-
const message = reason === "timeout"
|
|
16
|
-
? `Command timed out after ${detail}ms`
|
|
17
|
-
: reason === "output-limit"
|
|
18
|
-
? `Command output exceeded ${detail} bytes`
|
|
19
|
-
: "Command aborted";
|
|
20
|
-
return {
|
|
21
|
-
success: false,
|
|
22
|
-
code: reason === "timeout"
|
|
23
|
-
? COMMAND_TIMEOUT_EXIT_CODE
|
|
24
|
-
: reason === "output-limit"
|
|
25
|
-
? COMMAND_OUTPUT_LIMIT_EXIT_CODE
|
|
26
|
-
: COMMAND_ABORT_EXIT_CODE,
|
|
27
|
-
stdout,
|
|
28
|
-
stderr: `${stderr ?? ""}\n${message}`.trim(),
|
|
29
|
-
outputTruncated: outputTruncated || undefined,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function validateAbortSignal(signal) {
|
|
33
|
-
if (signal === undefined)
|
|
34
|
-
return;
|
|
35
|
-
if (!isAbortSignalWithoutHooks(signal)) {
|
|
36
|
-
throw new TypeError("signal must be an AbortSignal");
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function resolveCommandTimeoutMs(timeoutMs) {
|
|
40
|
-
if (typeof timeoutMs !== "number" || !(timeoutMs > 0))
|
|
41
|
-
return undefined;
|
|
42
|
-
return Math.min(Math.floor(timeoutMs), MAX_COMMAND_TIMEOUT_MS);
|
|
43
|
-
}
|
|
44
|
-
/** @internal Exported so Windows tree-termination arguments can be tested on every host. */
|
|
45
|
-
export function buildWindowsTaskkillArgs(pid, force) {
|
|
46
|
-
if (!Number.isSafeInteger(pid) || pid <= 0) {
|
|
47
|
-
throw new RangeError("Windows taskkill pid must be a positive safe integer");
|
|
48
|
-
}
|
|
49
|
-
return ["/PID", String(pid), "/T", ...(force ? ["/F"] : [])];
|
|
50
|
-
}
|
|
51
|
-
function tryDirectSignal(signalDirect, signal) {
|
|
52
|
-
try {
|
|
53
|
-
signalDirect(signal);
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
// The target may have exited before taskkill failure became observable.
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function tryForceSettledProcessTree(signalTree) {
|
|
60
|
-
try {
|
|
61
|
-
signalTree("SIGKILL");
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// A settled command with no remaining descendants has no process group or
|
|
65
|
-
// live direct handle. Cleanup is intentionally idempotent in that case.
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function signalWindowsTreeWithDeno(deno, pid, force, signalDirect) {
|
|
69
|
-
const signal = force ? "SIGKILL" : "SIGTERM";
|
|
70
|
-
if (!Number.isSafeInteger(pid) || (pid ?? 0) <= 0) {
|
|
71
|
-
tryDirectSignal(signalDirect, signal);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
const taskkill = new deno.Command("taskkill", {
|
|
76
|
-
args: buildWindowsTaskkillArgs(pid, force),
|
|
77
|
-
stdin: "null",
|
|
78
|
-
stdout: "null",
|
|
79
|
-
stderr: "null",
|
|
80
|
-
}).spawn();
|
|
81
|
-
void taskkill.status.then((status) => {
|
|
82
|
-
if (!status.success)
|
|
83
|
-
tryDirectSignal(signalDirect, signal);
|
|
84
|
-
}).catch(() => tryDirectSignal(signalDirect, signal));
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
tryDirectSignal(signalDirect, signal);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function signalWindowsTreeWithBun(bun, pid, force, signalDirect) {
|
|
91
|
-
const signal = force ? "SIGKILL" : "SIGTERM";
|
|
92
|
-
if (!Number.isSafeInteger(pid) || (pid ?? 0) <= 0) {
|
|
93
|
-
tryDirectSignal(signalDirect, signal);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
const taskkill = bun.spawn({
|
|
98
|
-
cmd: ["taskkill", ...buildWindowsTaskkillArgs(pid, force)],
|
|
99
|
-
stdout: "ignore",
|
|
100
|
-
stderr: "ignore",
|
|
101
|
-
});
|
|
102
|
-
taskkill.unref?.();
|
|
103
|
-
void taskkill.exited.then((code) => {
|
|
104
|
-
if (code !== 0)
|
|
105
|
-
tryDirectSignal(signalDirect, signal);
|
|
106
|
-
}).catch(() => tryDirectSignal(signalDirect, signal));
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
tryDirectSignal(signalDirect, signal);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function signalWindowsTreeWithNode(spawn, pid, force, signalDirect) {
|
|
113
|
-
const signal = force ? "SIGKILL" : "SIGTERM";
|
|
114
|
-
if (!Number.isSafeInteger(pid) || (pid ?? 0) <= 0) {
|
|
115
|
-
tryDirectSignal(signalDirect, signal);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
const taskkill = spawn("taskkill", buildWindowsTaskkillArgs(pid, force), {
|
|
120
|
-
stdio: "ignore",
|
|
121
|
-
windowsHide: true,
|
|
122
|
-
});
|
|
123
|
-
taskkill.once("error", () => tryDirectSignal(signalDirect, signal));
|
|
124
|
-
taskkill.once("close", (code) => {
|
|
125
|
-
if (code !== 0)
|
|
126
|
-
tryDirectSignal(signalDirect, signal);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
catch {
|
|
130
|
-
tryDirectSignal(signalDirect, signal);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
function signalProcessTree(pid, signal, detachedProcessGroup, signalGroup, signalDirect) {
|
|
134
|
-
if (detachedProcessGroup && Number.isSafeInteger(pid) && (pid ?? 0) > 0) {
|
|
135
|
-
try {
|
|
136
|
-
signalGroup(-pid, signal);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
catch (_) {
|
|
140
|
-
// The child may have exited before its process group became observable.
|
|
141
|
-
// Fall through to the direct handle so cancellation remains best effort.
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
signalDirect(signal);
|
|
145
|
-
}
|
|
146
|
-
function createProcessGuard(timeoutMs, signal, terminate, forceTerminate, releaseAfterForce) {
|
|
147
|
-
let terminationReason = null;
|
|
148
|
-
let timeoutId;
|
|
149
|
-
let forceKillId;
|
|
150
|
-
let forceTerminationCompleted = false;
|
|
151
|
-
const abortListener = () => stop("abort");
|
|
152
|
-
if (timeoutMs && timeoutMs > 0) {
|
|
153
|
-
timeoutId = dntShim.setTimeout(() => {
|
|
154
|
-
stop("timeout");
|
|
155
|
-
}, timeoutMs);
|
|
156
|
-
}
|
|
157
|
-
if (signal) {
|
|
158
|
-
addAbortSignalListenerOnce(signal, abortListener);
|
|
159
|
-
if (isAbortSignalAborted(signal))
|
|
160
|
-
stop("abort");
|
|
161
|
-
}
|
|
162
|
-
return {
|
|
163
|
-
stop,
|
|
164
|
-
reason: () => terminationReason,
|
|
165
|
-
clear: () => {
|
|
166
|
-
if (timeoutId)
|
|
167
|
-
clearTimeout(timeoutId);
|
|
168
|
-
if (signal)
|
|
169
|
-
removeAbortSignalListener(signal, abortListener);
|
|
170
|
-
if (terminationReason === null) {
|
|
171
|
-
if (forceKillId)
|
|
172
|
-
clearTimeout(forceKillId);
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
// The directly managed process may settle after SIGTERM while a child in
|
|
176
|
-
// its process group remains alive. Do not cancel escalation on that
|
|
177
|
-
// abnormal settlement; force it immediately before releasing lifecycle
|
|
178
|
-
// ownership.
|
|
179
|
-
forceTerminateOnce();
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
function stop(reason) {
|
|
183
|
-
if (terminationReason !== null)
|
|
184
|
-
return;
|
|
185
|
-
terminationReason = reason;
|
|
186
|
-
try {
|
|
187
|
-
terminate();
|
|
188
|
-
}
|
|
189
|
-
catch (_) {
|
|
190
|
-
/* expected: best-effort terminate may fail if process already exited */
|
|
191
|
-
}
|
|
192
|
-
forceKillId = dntShim.setTimeout(forceTerminateOnce, FORCE_KILL_GRACE_MS);
|
|
193
|
-
}
|
|
194
|
-
function forceTerminateOnce() {
|
|
195
|
-
if (forceTerminationCompleted)
|
|
196
|
-
return;
|
|
197
|
-
forceTerminationCompleted = true;
|
|
198
|
-
if (forceKillId) {
|
|
199
|
-
clearTimeout(forceKillId);
|
|
200
|
-
forceKillId = undefined;
|
|
201
|
-
}
|
|
202
|
-
try {
|
|
203
|
-
forceTerminate();
|
|
204
|
-
}
|
|
205
|
-
catch (_) {
|
|
206
|
-
/* expected: best-effort force terminate may fail if process already exited */
|
|
207
|
-
}
|
|
208
|
-
finally {
|
|
209
|
-
releaseAfterForce();
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function createCaptureBudget(maxOutputBytes, onExceeded) {
|
|
214
|
-
return {
|
|
215
|
-
remaining: maxOutputBytes,
|
|
216
|
-
exceeded: false,
|
|
217
|
-
onExceeded,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
function captureChunk(chunks, chunk, budget) {
|
|
221
|
-
const available = budget.remaining;
|
|
222
|
-
if (available > 0) {
|
|
223
|
-
// Invoke the typed-array intrinsic directly: Buffer#slice() returns a view
|
|
224
|
-
// and can retain a much larger pooled backing allocation.
|
|
225
|
-
const retained = apply(uint8ArraySlice, chunk, [
|
|
226
|
-
0,
|
|
227
|
-
Math.min(chunk.byteLength, available),
|
|
228
|
-
]);
|
|
229
|
-
chunks.push(retained);
|
|
230
|
-
budget.remaining -= retained.byteLength;
|
|
231
|
-
}
|
|
232
|
-
if (chunk.byteLength > available && !budget.exceeded) {
|
|
233
|
-
budget.exceeded = true;
|
|
234
|
-
budget.onExceeded();
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
function decodeChunks(chunks) {
|
|
238
|
-
const total = chunks.reduce((acc, chunk) => acc + chunk.byteLength, 0);
|
|
239
|
-
const merged = new Uint8Array(total);
|
|
240
|
-
let offset = 0;
|
|
241
|
-
for (const chunk of chunks) {
|
|
242
|
-
merged.set(chunk, offset);
|
|
243
|
-
offset += chunk.byteLength;
|
|
244
|
-
}
|
|
245
|
-
return new TextDecoder().decode(merged);
|
|
246
|
-
}
|
|
247
|
-
function captureStreamToString(stream, budget) {
|
|
248
|
-
const reader = stream.getReader();
|
|
249
|
-
const chunks = [];
|
|
250
|
-
let cancelled = false;
|
|
251
|
-
return {
|
|
252
|
-
result: (async () => {
|
|
253
|
-
try {
|
|
254
|
-
while (true) {
|
|
255
|
-
const { done, value } = await reader.read();
|
|
256
|
-
if (done)
|
|
257
|
-
break;
|
|
258
|
-
if (value)
|
|
259
|
-
captureChunk(chunks, value, budget);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
catch (error) {
|
|
263
|
-
if (!cancelled)
|
|
264
|
-
throw error;
|
|
265
|
-
}
|
|
266
|
-
finally {
|
|
267
|
-
reader.releaseLock();
|
|
268
|
-
}
|
|
269
|
-
return decodeChunks(chunks);
|
|
270
|
-
})(),
|
|
271
|
-
cancel: (reason) => {
|
|
272
|
-
if (cancelled)
|
|
273
|
-
return;
|
|
274
|
-
cancelled = true;
|
|
275
|
-
try {
|
|
276
|
-
const cancellation = reader.cancel(reason);
|
|
277
|
-
void cancellation.catch(() => { });
|
|
278
|
-
}
|
|
279
|
-
catch {
|
|
280
|
-
// The stream may already have closed between termination and release.
|
|
281
|
-
}
|
|
282
|
-
},
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
function resolveShellCommand(cmd, args) {
|
|
286
|
-
if (isWindowsPlatform()) {
|
|
287
|
-
return { cmd: "cmd.exe", args: ["/d", "/s", "/c", cmd, ...args] };
|
|
288
|
-
}
|
|
289
|
-
if (args.length === 0) {
|
|
290
|
-
return { cmd: "sh", args: ["-c", cmd] };
|
|
291
|
-
}
|
|
292
|
-
return {
|
|
293
|
-
cmd: "sh",
|
|
294
|
-
args: ["-c", 'exec "$@"', "sh", cmd, ...args],
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Run a command and return the result.
|
|
299
|
-
* Works across Deno, Node.js, and Bun.
|
|
300
|
-
*
|
|
301
|
-
* @param cmd - Command to run
|
|
302
|
-
* @param options - Command options
|
|
303
|
-
* @param options.capture - Capture stdout/stderr to return in result
|
|
304
|
-
* @param options.inherit - Inherit stdio from parent (shows output in terminal)
|
|
305
|
-
* @param options.shell - Use shell to run command (needed for .cmd on Windows)
|
|
306
|
-
*/
|
|
307
|
-
export async function runCommand(cmd, options = {}) {
|
|
308
|
-
const { args = [], cwd: cmdCwd, env: cmdEnv, clearEnv = false, capture = false, inherit = false, shell = false, timeoutMs, signal, terminateProcessTreeOnExit = false, maxOutputBytes = DEFAULT_MAX_OUTPUT_BYTES, } = options;
|
|
309
|
-
validateAbortSignal(signal);
|
|
310
|
-
if (typeof terminateProcessTreeOnExit !== "boolean") {
|
|
311
|
-
throw new TypeError("terminateProcessTreeOnExit must be a boolean");
|
|
312
|
-
}
|
|
313
|
-
const effectiveTimeoutMs = resolveCommandTimeoutMs(timeoutMs);
|
|
314
|
-
if (!Number.isSafeInteger(maxOutputBytes) || maxOutputBytes <= 0) {
|
|
315
|
-
throw new RangeError("maxOutputBytes must be a positive safe integer");
|
|
316
|
-
}
|
|
317
|
-
if (signal && isAbortSignalAborted(signal)) {
|
|
318
|
-
return createTerminationResult("abort", 0);
|
|
319
|
-
}
|
|
320
|
-
// Determine stdio mode: inherit > capture > null
|
|
321
|
-
const shouldCapture = capture && !inherit;
|
|
322
|
-
const stdioMode = inherit ? "inherit" : shouldCapture ? "piped" : "null";
|
|
323
|
-
const detachedProcessGroup = !isWindowsPlatform() &&
|
|
324
|
-
(effectiveTimeoutMs !== undefined ||
|
|
325
|
-
signal !== undefined ||
|
|
326
|
-
shouldCapture ||
|
|
327
|
-
terminateProcessTreeOnExit);
|
|
328
|
-
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
329
|
-
if (deno) {
|
|
330
|
-
const denoCommand = shell ? resolveShellCommand(cmd, args) : { cmd, args };
|
|
331
|
-
const command = new deno.Command(denoCommand.cmd, {
|
|
332
|
-
args: [...denoCommand.args],
|
|
333
|
-
cwd: cmdCwd,
|
|
334
|
-
env: cmdEnv,
|
|
335
|
-
clearEnv,
|
|
336
|
-
stdin: inherit ? "inherit" : "null",
|
|
337
|
-
stdout: stdioMode,
|
|
338
|
-
stderr: stdioMode,
|
|
339
|
-
detached: detachedProcessGroup,
|
|
340
|
-
});
|
|
341
|
-
const child = command.spawn();
|
|
342
|
-
const windowsPlatform = isWindowsPlatform();
|
|
343
|
-
const directSignal = (terminationSignal) => child.kill(terminationSignal);
|
|
344
|
-
const signalChild = (terminationSignal) => windowsPlatform
|
|
345
|
-
? signalWindowsTreeWithDeno(deno, child.pid, terminationSignal === "SIGKILL", directSignal)
|
|
346
|
-
: signalProcessTree(child.pid, terminationSignal, detachedProcessGroup, (processGroupId, groupSignal) => deno.kill(processGroupId, groupSignal), directSignal);
|
|
347
|
-
const captures = {};
|
|
348
|
-
const guard = createProcessGuard(effectiveTimeoutMs, signal, () => signalChild("SIGTERM"), () => signalChild("SIGKILL"), () => {
|
|
349
|
-
const reason = new Error("Command capture closed after forced termination");
|
|
350
|
-
captures.stdout?.cancel(reason);
|
|
351
|
-
captures.stderr?.cancel(reason);
|
|
352
|
-
});
|
|
353
|
-
const captureBudget = createCaptureBudget(maxOutputBytes, () => guard.stop("output-limit"));
|
|
354
|
-
captures.stdout = shouldCapture && child.stdout
|
|
355
|
-
? captureStreamToString(child.stdout, captureBudget)
|
|
356
|
-
: undefined;
|
|
357
|
-
captures.stderr = shouldCapture && child.stderr
|
|
358
|
-
? captureStreamToString(child.stderr, captureBudget)
|
|
359
|
-
: undefined;
|
|
360
|
-
try {
|
|
361
|
-
const [status, stdout, stderr] = await Promise.all([
|
|
362
|
-
child.status,
|
|
363
|
-
captures.stdout?.result ?? Promise.resolve(undefined),
|
|
364
|
-
captures.stderr?.result ?? Promise.resolve(undefined),
|
|
365
|
-
]);
|
|
366
|
-
const reason = guard.reason();
|
|
367
|
-
if (reason) {
|
|
368
|
-
return createTerminationResult(reason, reason === "timeout" ? effectiveTimeoutMs ?? 0 : maxOutputBytes, stdout, stderr, captureBudget.exceeded);
|
|
369
|
-
}
|
|
370
|
-
return {
|
|
371
|
-
success: status.success,
|
|
372
|
-
code: status.code,
|
|
373
|
-
stdout,
|
|
374
|
-
stderr,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
finally {
|
|
378
|
-
if (terminateProcessTreeOnExit && guard.reason() === null) {
|
|
379
|
-
tryForceSettledProcessTree(signalChild);
|
|
380
|
-
}
|
|
381
|
-
guard.clear();
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
if (IS_BUN) {
|
|
385
|
-
const bunGlobal = dntShim.dntGlobalThis;
|
|
386
|
-
const bunStdio = inherit ? "inherit" : shouldCapture ? "pipe" : "ignore";
|
|
387
|
-
const shellCommand = shell ? resolveShellCommand(cmd, args) : null;
|
|
388
|
-
const bunCmd = shellCommand ? [shellCommand.cmd, ...shellCommand.args] : [cmd, ...args];
|
|
389
|
-
const proc = bunGlobal.Bun.spawn({
|
|
390
|
-
cmd: bunCmd,
|
|
391
|
-
cwd: cmdCwd,
|
|
392
|
-
detached: detachedProcessGroup,
|
|
393
|
-
env: clearEnv ? cmdEnv ?? {} : cmdEnv,
|
|
394
|
-
stdout: bunStdio,
|
|
395
|
-
stderr: bunStdio,
|
|
396
|
-
});
|
|
397
|
-
const windowsPlatform = isWindowsPlatform();
|
|
398
|
-
const directSignal = (terminationSignal) => proc.kill?.(terminationSignal);
|
|
399
|
-
const signalChild = (terminationSignal) => windowsPlatform
|
|
400
|
-
? signalWindowsTreeWithBun(bunGlobal.Bun, proc.pid, terminationSignal === "SIGKILL", directSignal)
|
|
401
|
-
: signalProcessTree(proc.pid, terminationSignal, detachedProcessGroup, (processGroupId, groupSignal) => {
|
|
402
|
-
if (!runtimeProcess)
|
|
403
|
-
throw new Error("Runtime process unavailable");
|
|
404
|
-
runtimeProcess.kill(processGroupId, groupSignal);
|
|
405
|
-
}, directSignal);
|
|
406
|
-
const captures = {};
|
|
407
|
-
const guard = createProcessGuard(effectiveTimeoutMs, signal, () => signalChild("SIGTERM"), () => signalChild("SIGKILL"), () => {
|
|
408
|
-
const reason = new Error("Command capture closed after forced termination");
|
|
409
|
-
captures.stdout?.cancel(reason);
|
|
410
|
-
captures.stderr?.cancel(reason);
|
|
411
|
-
});
|
|
412
|
-
const captureBudget = createCaptureBudget(maxOutputBytes, () => guard.stop("output-limit"));
|
|
413
|
-
captures.stdout = shouldCapture && proc.stdout
|
|
414
|
-
? captureStreamToString(proc.stdout, captureBudget)
|
|
415
|
-
: undefined;
|
|
416
|
-
captures.stderr = shouldCapture && proc.stderr
|
|
417
|
-
? captureStreamToString(proc.stderr, captureBudget)
|
|
418
|
-
: undefined;
|
|
419
|
-
try {
|
|
420
|
-
const [code, stdout, stderr] = await Promise.all([
|
|
421
|
-
proc.exited,
|
|
422
|
-
captures.stdout?.result ?? Promise.resolve(undefined),
|
|
423
|
-
captures.stderr?.result ?? Promise.resolve(undefined),
|
|
424
|
-
]);
|
|
425
|
-
const reason = guard.reason();
|
|
426
|
-
if (reason) {
|
|
427
|
-
return createTerminationResult(reason, reason === "timeout" ? effectiveTimeoutMs ?? 0 : maxOutputBytes, stdout, stderr, captureBudget.exceeded);
|
|
428
|
-
}
|
|
429
|
-
return { success: code === 0, code, stdout, stderr };
|
|
430
|
-
}
|
|
431
|
-
finally {
|
|
432
|
-
if (terminateProcessTreeOnExit && guard.reason() === null) {
|
|
433
|
-
tryForceSettledProcessTree(signalChild);
|
|
434
|
-
}
|
|
435
|
-
guard.clear();
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
if (!runtimeProcess)
|
|
439
|
-
return { success: false, code: 1 };
|
|
440
|
-
const process = runtimeProcess;
|
|
441
|
-
const { spawn } = await dynamicImport("node:child_process");
|
|
442
|
-
if (signal && isAbortSignalAborted(signal)) {
|
|
443
|
-
return createTerminationResult("abort", 0);
|
|
444
|
-
}
|
|
445
|
-
const nodeStdio = inherit
|
|
446
|
-
? ["inherit", "inherit", "inherit"]
|
|
447
|
-
: capture
|
|
448
|
-
? ["ignore", "pipe", "pipe"]
|
|
449
|
-
: ["ignore", "ignore", "ignore"];
|
|
450
|
-
return await new Promise((resolve) => {
|
|
451
|
-
const child = spawn(cmd, args, {
|
|
452
|
-
cwd: cmdCwd,
|
|
453
|
-
env: clearEnv ? cmdEnv ?? {} : cmdEnv ? { ...process.env, ...cmdEnv } : undefined,
|
|
454
|
-
stdio: nodeStdio,
|
|
455
|
-
shell,
|
|
456
|
-
detached: detachedProcessGroup,
|
|
457
|
-
});
|
|
458
|
-
const stdoutChunks = [];
|
|
459
|
-
const stderrChunks = [];
|
|
460
|
-
const windowsPlatform = isWindowsPlatform();
|
|
461
|
-
const directSignal = (terminationSignal) => child.kill(terminationSignal);
|
|
462
|
-
const signalChild = (terminationSignal) => windowsPlatform
|
|
463
|
-
? signalWindowsTreeWithNode(spawn, child.pid, terminationSignal === "SIGKILL", directSignal)
|
|
464
|
-
: signalProcessTree(child.pid, terminationSignal, detachedProcessGroup, (processGroupId, groupSignal) => process.kill(processGroupId, groupSignal), directSignal);
|
|
465
|
-
const guard = createProcessGuard(effectiveTimeoutMs, signal, () => signalChild("SIGTERM"), () => signalChild("SIGKILL"), () => {
|
|
466
|
-
child.stdout?.destroy();
|
|
467
|
-
child.stderr?.destroy();
|
|
468
|
-
});
|
|
469
|
-
const captureBudget = createCaptureBudget(maxOutputBytes, () => guard.stop("output-limit"));
|
|
470
|
-
let resultSettled = false;
|
|
471
|
-
const settleProcessOwnership = () => {
|
|
472
|
-
if (resultSettled)
|
|
473
|
-
return false;
|
|
474
|
-
resultSettled = true;
|
|
475
|
-
if (terminateProcessTreeOnExit && guard.reason() === null) {
|
|
476
|
-
tryForceSettledProcessTree(signalChild);
|
|
477
|
-
}
|
|
478
|
-
guard.clear();
|
|
479
|
-
return true;
|
|
480
|
-
};
|
|
481
|
-
if (shouldCapture) {
|
|
482
|
-
child.stdout?.on("data", (data) => {
|
|
483
|
-
captureChunk(stdoutChunks, data, captureBudget);
|
|
484
|
-
});
|
|
485
|
-
child.stderr?.on("data", (data) => {
|
|
486
|
-
captureChunk(stderrChunks, data, captureBudget);
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
child.on("close", (code) => {
|
|
490
|
-
if (!settleProcessOwnership())
|
|
491
|
-
return;
|
|
492
|
-
const stdout = shouldCapture ? decodeChunks(stdoutChunks) : undefined;
|
|
493
|
-
const stderr = shouldCapture ? decodeChunks(stderrChunks) : undefined;
|
|
494
|
-
const reason = guard.reason();
|
|
495
|
-
if (reason) {
|
|
496
|
-
resolve(createTerminationResult(reason, reason === "timeout" ? effectiveTimeoutMs ?? 0 : maxOutputBytes, stdout, stderr, captureBudget.exceeded));
|
|
497
|
-
return;
|
|
498
|
-
}
|
|
499
|
-
resolve({
|
|
500
|
-
success: code === 0,
|
|
501
|
-
code: code ?? 1,
|
|
502
|
-
stdout,
|
|
503
|
-
stderr,
|
|
504
|
-
});
|
|
505
|
-
});
|
|
506
|
-
child.on("error", (spawnError) => {
|
|
507
|
-
if (!settleProcessOwnership())
|
|
508
|
-
return;
|
|
509
|
-
const stdout = shouldCapture ? decodeChunks(stdoutChunks) : undefined;
|
|
510
|
-
const stderr = shouldCapture ? decodeChunks(stderrChunks) : undefined;
|
|
511
|
-
// Include the spawn error message so callers can distinguish ENOENT
|
|
512
|
-
// ("command not found"), EACCES ("permission denied"), etc.
|
|
513
|
-
resolve({
|
|
514
|
-
success: false,
|
|
515
|
-
code: 1,
|
|
516
|
-
stdout,
|
|
517
|
-
stderr: shouldCapture
|
|
518
|
-
? (stderr
|
|
519
|
-
? `${stderr}\nSpawn error: ${spawnError.message}`
|
|
520
|
-
: `Spawn error: ${spawnError.message}`)
|
|
521
|
-
: undefined,
|
|
522
|
-
});
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { deleteEnv, env, type EnvBooleanOptions, getEnv, getEnvBoolean, getEnvNumber, getEnvOverlayStorage, getEnvString, getHostEnv, setEnv, } from "veryfront/platform/env";
|
|
2
|
-
export { chdir, cwd, execPath, exit, getArgs, getOsType, getRuntimeVersion, getStdout, getTerminalSize, isInteractive, isStdoutTTY, memoryUsage, onGlobalError, onSignal, pid, promptSync, readStdinByteSync, unrefTimer, uptime, writeStdout, writeStdoutAsync, } from "./process/lifecycle.js";
|
|
3
|
-
export { testHasRuntimeProcess } from "./process/runtime-process.js";
|
|
4
|
-
export { type CommandOptions, type CommandResult, runCommand } from "./process/command.js";
|
|
5
|
-
//# sourceMappingURL=process.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../../../src/src/platform/compat/process.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,GAAG,EACH,KAAK,iBAAiB,EACtB,MAAM,EACN,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,UAAU,EACV,MAAM,GACP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,EACL,GAAG,EACH,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,aAAa,EACb,WAAW,EACX,WAAW,EACX,aAAa,EACb,QAAQ,EACR,GAAG,EACH,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,MAAM,EACN,WAAW,EACX,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { deleteEnv, env, getEnv, getEnvBoolean, getEnvNumber, getEnvOverlayStorage, getEnvString, getHostEnv, setEnv, } from "./process/env.js";
|
|
2
|
-
export { chdir, cwd, execPath, exit, getArgs, getOsType, getRuntimeVersion, getStdout, getTerminalSize, isInteractive, isStdoutTTY, memoryUsage, onGlobalError, onSignal, pid, promptSync, readStdinByteSync, unrefTimer, uptime, writeStdout, writeStdoutAsync, } from "./process/lifecycle.js";
|
|
3
|
-
export { testHasRuntimeProcess } from "./process/runtime-process.js";
|
|
4
|
-
export { runCommand } from "./process/command.js";
|