stim 1.20.2 → 1.21.0
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/README.md +88 -8
- package/dist/acquire-artifact-CD4lbiWE.mjs +153 -0
- package/dist/act-DHAw2A2S.mjs +2667 -0
- package/dist/activity-BzVfHSrY.mjs +1376 -0
- package/dist/{agent-device-usage-output-Dzgv6lgR.mjs → agent-device-usage-output-zh1vhbLp.mjs} +21 -65
- package/dist/{android-HqP1_vB_.mjs → android-BEJ8Jpl7.mjs} +2 -2
- package/dist/{android-DCKZrNvV.mjs → android-BLgbNqox.mjs} +128 -78
- package/dist/{android-Dlzxshgp.mjs → android-CV_GCELZ.mjs} +5 -5
- package/dist/{android-Mz_Inn3w.mjs → android-DUYkNF4u.mjs} +184 -102
- package/dist/{android-cas-Bl-cLJBk.mjs → android-cas-Ct5b1xCK.mjs} +7 -6
- package/dist/android-cas-compiler.mjs +2 -2
- package/dist/android-project-BCAAmMwz.mjs +12 -0
- package/dist/api.d.mts +740 -8
- package/dist/api.mjs +585 -1
- package/dist/{artifact-HSwkIWEQ.mjs → artifact-B8T3S5gi.mjs} +223 -201
- package/dist/{artifact-D3czlUvT.mjs → artifact-DAuZ-FNU.mjs} +158 -148
- package/dist/{browser-web-CA-F1GQo.mjs → browser-web-QQzVjz3O.mjs} +26 -24
- package/dist/budget-Bs6SxxzO.mjs +9154 -0
- package/dist/{build-DYDbfkk5.mjs → build-CoPzQRNw.mjs} +144 -96
- package/dist/build-cache-DmyR9Zzc.mjs +602 -0
- package/dist/build-plan-CaFskB7_.mjs +188 -0
- package/dist/{cache-manifest-XH-fvDUj.mjs → cache-manifest-DkkqguoK.mjs} +2 -2
- package/dist/cache-manifest.mjs +1 -1
- package/dist/{ccache-zdKiYQ3E.mjs → ccache-BJRZ9pG3.mjs} +10 -9
- package/dist/{cdp-Dq_ypAlJ.mjs → cdp-CWmIUMbw.mjs} +18 -5
- package/dist/{chrome-BnzZMqsR.mjs → chrome-B6tfCta1.mjs} +7 -4
- package/dist/{cli-CLP3diBm.mjs → cli-0DYf8QhQ.mjs} +20 -20
- package/dist/cli.mjs +1 -1
- package/dist/client-B7QVOlCr.d.mts +253 -0
- package/dist/client-UXD70ZbM.mjs +1406 -0
- package/dist/collector-run.d.mts +4 -40
- package/dist/collector-run.mjs +9 -8
- package/dist/{command-output-BTy8hZ0F.mjs → command-output-B1UrjZHL.mjs} +1 -1
- package/dist/config-CYcBF478.mjs +949 -0
- package/dist/{created-devices-Dzd5C2LF.mjs → created-devices-CqeBlrEn.mjs} +3 -3
- package/dist/{dependency-state-DG0p31-y.mjs → dependency-state-BbKQW83h.mjs} +20 -5
- package/dist/{detached-entry-B9C_zeQC.mjs → detached-entry-DFRyG1_o.mjs} +1 -1
- package/dist/{dev-client-DAWVIGBu.mjs → dev-client-UOeESKm6.mjs} +2 -2
- package/dist/device-DCxH7_By.mjs +1068 -0
- package/dist/{device-BECOiufl.mjs → device-ExJq8Ei7.mjs} +35 -35
- package/dist/{device-capacity-CBUAcRyQ.mjs → device-capacity-CMlqEcvw.mjs} +43 -13
- package/dist/device-host-worker.mjs +65 -61
- package/dist/{device-ios-COSi6oS1.mjs → device-ios-DRUeKaFV.mjs} +48 -45
- package/dist/{device-lease-run-Cw2M4z51.mjs → device-lease-run-C8raGFoP.mjs} +14 -26
- package/dist/{device-pool-Bf-pOhSw.mjs → device-pool-DMRpVX9a.mjs} +5 -5
- package/dist/doctor-BLHCYxzi.mjs +2 -0
- package/dist/{doctor-kfMBnUw6.mjs → doctor-DTvaDOda.mjs} +281 -317
- package/dist/{doctor-CB8oZKCk.mjs → doctor-Dhqebm0q.mjs} +183 -91
- package/dist/doctor-fingerprint.mjs +19 -0
- package/dist/{doctor-watchman-BRyV2adA.mjs → doctor-watchman-Cv1F10Kj.mjs} +40 -21
- package/dist/{eas-build-JyfqyHfC.mjs → eas-build-BomfRnFT.mjs} +53 -20
- package/dist/{build-plan-B7SZsc2N.mjs → eas-fallback-DJwZpy0c.mjs} +26 -208
- package/dist/{watchman-CPQFZLXY.mjs → eas-session-ledger-op6A54yi.mjs} +229 -11
- package/dist/{error-diagnostics-BR677IDM.mjs → error-diagnostics-Bf0rZvG9.mjs} +172 -82
- package/dist/exec-H20xSg2T.d.mts +65 -0
- package/dist/exec-_UbtCQcG.mjs +750 -0
- package/dist/gc-C-WwL0yi.mjs +3 -0
- package/dist/{gc-qWOMdnER.mjs → gc-_-dCXdyL.mjs} +584 -796
- package/dist/git-C3iTsJaZ.mjs +73 -0
- package/dist/{guide-G9cAbVAc.mjs → guide-Yqwt2bd6.mjs} +941 -269
- package/dist/{hosted-android-C3MHGld1.mjs → hosted-android-Bw-honsd.mjs} +8 -6
- package/dist/{hosted-client-ZEKpS9vw.mjs → hosted-client-DB_gBPfY.mjs} +34 -19
- package/dist/{hosted-ios-l-o3iM9J.mjs → hosted-ios-CUvOf4Vr.mjs} +1 -1
- package/dist/{hosted-logs-EzQM7-3Z.mjs → hosted-logs-DL_P5AdN.mjs} +77 -43
- package/dist/{hosted-macos-BACVAVqE.mjs → hosted-macos-QI141yKk.mjs} +21 -17
- package/dist/{hosted-native-A4s1QPXe.mjs → hosted-native-Ksyjgzq-.mjs} +30 -21
- package/dist/idle-BVeRGroT.d.mts +24 -0
- package/dist/{idle-shutdown-DtxhPTKe.mjs → idle-shutdown-DaKmZi0z.mjs} +11 -10
- package/dist/{ios-BwVCF7oA.mjs → ios-CQ68hG9s.mjs} +8 -8
- package/dist/{ios-RkW4pnQf.mjs → ios-CpByZy12.mjs} +140 -80
- package/dist/{ios-device-B5veSDDQ.mjs → ios-device-CXGP1bsD.mjs} +1 -1
- package/dist/{ios-device-D7pi2Sca.mjs → ios-device-CwFMehUS.mjs} +51 -26
- package/dist/{ios-project-K9hY_Jab.mjs → ios-project-WuwwBdvW.mjs} +13 -13
- package/dist/{ios-nOLJGVdy.mjs → ios-qNJt4dFm.mjs} +1 -1
- package/dist/ios-signing-DTTIChGs.mjs +489 -0
- package/dist/{ios-state-CBLe1xYw.mjs → ios-state-DvFX-K_l.mjs} +1 -1
- package/dist/{ios-Ce7bc7br.mjs → ios-ubFsBzwq.mjs} +129 -86
- package/dist/{js-swap-Bb3nsS07.mjs → js-swap-Cc1dttps.mjs} +53 -26
- package/dist/{launch-F4sOqAhB.mjs → launch-CD1yVc7U.mjs} +91 -90
- package/dist/{launch-C3qJ6Agb.mjs → launch-Zq2mOSDy.mjs} +82 -541
- package/dist/logs-BS00Anxf.mjs +352 -0
- package/dist/logs-CMm05HxN.mjs +255 -0
- package/dist/{macos-D7uDvO-z.mjs → macos-B65--pPd.mjs} +1 -1
- package/dist/{macos-Ch5VJmcS.mjs → macos-C-0qJ6zq.mjs} +225 -212
- package/dist/macos-run.mjs +1 -1
- package/dist/maintenance-run.mjs +122 -247
- package/dist/{metro-DnCEjCxs.mjs → metro-DEXpIhHC.mjs} +67 -12
- package/dist/{metro-gateway-CX9Xlkq2.mjs → metro-gateway-BMJNlj3E.mjs} +20 -12
- package/dist/{named-ports-4WopRPg-.mjs → named-ports-BWTzt6mu.mjs} +8 -63
- package/dist/native-android-JACyjTZs.mjs +844 -0
- package/dist/{native-gradle-inputs-BsLRrl7u.mjs → native-gradle-inputs-Bep9JcSF.mjs} +128 -140
- package/dist/native-inputs-TRTTTRxt.mjs +91 -0
- package/dist/native-run-DY_RLx3C.mjs +277 -0
- package/dist/{native-runtime-k8dTIrbK.mjs → native-runtime-Dg1Q7tfF.mjs} +9 -8
- package/dist/{native-xcode-inputs-CykopJdM.mjs → native-xcode-inputs-CB2iQeWq.mjs} +27 -18
- package/dist/{native-xcode-ios-Bbf30Gm0.mjs → native-xcode-ios-CXX39F7o.mjs} +96 -47
- package/dist/{ndjson-GOnbyvso.mjs → ndjson-CgE_o3Dl.mjs} +3 -3
- package/dist/offload-worker.d.mts +1 -46
- package/dist/offload-worker.mjs +197 -66
- package/dist/{ownership-DCtw_2IA.mjs → ownership-DEmM5vhh.mjs} +3 -3
- package/dist/{page-DRHy329N.mjs → page-CPaHeYqj.mjs} +7 -4
- package/dist/paths-BsJMoPP2.mjs +12 -0
- package/dist/paths-DQtTgsBf.mjs +42 -0
- package/dist/{placement-log-MOfPVgaM.mjs → placement-log-BqGbTa61.mjs} +5 -5
- package/dist/{plan-placement-V0TdzYXp.mjs → plan-placement-Bwj-IjY1.mjs} +6 -6
- package/dist/{ports-DdSUicVo.mjs → ports-D-MmCTdv.mjs} +3 -3
- package/dist/prebuild-uD_ipCxF.mjs +449 -0
- package/dist/{project-_phNIJfs.mjs → project-BZNjmW_8.mjs} +65 -37
- package/dist/{pull-request-CQ8sPbZa.mjs → pull-request-Lfetn8Kr.mjs} +2 -2
- package/dist/pull-request-zjCSAryH.d.mts +120 -0
- package/dist/pull-requests.d.mts +1 -119
- package/dist/pull-requests.mjs +1 -1
- package/dist/{react-native-android-CM1XRDwv.mjs → react-native-android-DuzH0cn3.mjs} +74 -48
- package/dist/{gradle-DSrXb6lG.mjs → react-native-build-rhk4smwQ.mjs} +292 -15
- package/dist/react-native-doctor-CQpuIMso.mjs +234 -0
- package/dist/{react-native-ios-Dhq_eiYQ.mjs → react-native-ios-Bhq1rJeV.mjs} +46 -28
- package/dist/{recordings-D0d5aQt0.mjs → recordings-DYteQSu4.mjs} +12 -9
- package/dist/{reload-C8JhxjSh.mjs → reload-CmTRFJaX.mjs} +93 -47
- package/dist/reload-DzjSl5P_.mjs +2 -0
- package/dist/{remote-BiR6aYjy.mjs → remote-ByYkXdGD.mjs} +15 -10
- package/dist/result-DNiS-tTP.mjs +434 -0
- package/dist/{run-BtPgpKks.mjs → run-D23HmJMs.mjs} +4 -5
- package/dist/selection-CSl9i5qU.mjs +619 -0
- package/dist/{server-bare-R2m_gsH8.mjs → server-bare-CxTrvDg8.mjs} +3 -4
- package/dist/{server-command-CTtCkmcQ.mjs → server-command-CtzloH3v.mjs} +14 -7
- package/dist/server-expo-C-90EhcG.mjs +2 -0
- package/dist/{server-expo-DsguMGUF.mjs → server-expo-DT_F_uVI.mjs} +50 -9
- package/dist/{settings-B717odTD.mjs → settings-CsJDEXgK.mjs} +234 -24
- package/dist/{settings-vk3mJGSm.d.mts → settings-DkdmlelE.d.mts} +6 -4
- package/dist/settings-T1gtc3bf.mjs +114 -0
- package/dist/settings-write-HyVZ8eQ8.mjs +359 -0
- package/dist/settings.schema.json +163 -16
- package/dist/{simslim-CCr3rE-A.mjs → simslim-Cgk17SXV.mjs} +14 -12
- package/dist/{slot-launch-DPt0m9Nd.mjs → slot-launch-DF8VfT64.mjs} +15 -20
- package/dist/{spawn-entry-Dcb7sDUz.mjs → spawn-entry-jw19m8Nl.mjs} +0 -1
- package/dist/stage-BIS0ydsV.mjs +183 -0
- package/dist/{start-BWqzODpb.mjs → start-7lpH7hmN.mjs} +63 -44
- package/dist/{start-TXeMmmO2.mjs → start-RChynRDp.mjs} +1 -1
- package/dist/{state-D1Icyjlu.mjs → state-C4ZtUisW.mjs} +40 -13
- package/dist/{state-CG_OFoaA.mjs → state-XMziexv2.mjs} +3 -2
- package/dist/{stats-BoY5sEPU.mjs → stats-53T7OTb9.mjs} +7 -13
- package/dist/stats-report-BFfMpWWF.mjs +16 -0
- package/dist/{status-WgFbkRzj.mjs → status-BL7jVyAB.mjs} +535 -447
- package/dist/status-CSi6tlRq.mjs +2 -0
- package/dist/{status-BTA7kKiQ.mjs → status-DqEUSSxs.mjs} +6 -4
- package/dist/{status-watch-C23ILtf9.mjs → status-watch-GDCfqpTE.mjs} +187 -22
- package/dist/status-worker.d.mts +1 -0
- package/dist/status-worker.mjs +19 -0
- package/dist/stim-desktop-C12we7lz.mjs +112 -0
- package/dist/{stop-DR6VoDIk.mjs → stop-Bk_1qiV6.mjs} +2 -2
- package/dist/{stop-BNmBMi1F.mjs → stop-CPzlM1L-.mjs} +138 -98
- package/dist/{stop-DPEhunlw.mjs → stop-D7h6jAXQ.mjs} +11 -10
- package/dist/supervisor-run.d.mts +8 -17
- package/dist/supervisor-run.mjs +63 -27
- package/dist/{support-DMTqj3Hm.mjs → support-67vraa1Q.mjs} +18 -11
- package/dist/{support-CwjbFs9H.mjs → support-Dlu37g6H.mjs} +12 -12
- package/dist/{swiftpm-macos-DRNVJWlb.mjs → swiftpm-macos-p8WZbxKU.mjs} +35 -24
- package/dist/toolchain-DhKwp9iI.mjs +2 -0
- package/dist/toolchain-Hp9sCpK4.mjs +873 -0
- package/dist/{trigger-CigAYjeL.mjs → trigger-BAahxUPq.mjs} +20 -5
- package/dist/trigger-Bf3uDcpv.mjs +2 -0
- package/dist/{warm-progress-BuY-Fvfn.mjs → warm-progress-BHX5r0Ei.mjs} +250 -156
- package/dist/{web-BDBMxDpx.mjs → web-CJmIj6AI.mjs} +18 -13
- package/dist/web-DknQETPs.mjs +2 -0
- package/dist/web-run.mjs +11 -12
- package/dist/windows-report.d.mts +1 -0
- package/dist/windows-report.mjs +18 -0
- package/dist/windows-report.ps1 +43 -0
- package/dist/workspace-process-lock-1_1OoVW5.mjs +57 -0
- package/dist/{workspace-state-DJt_MMvf.mjs → workspace-state-Cjuigeeu.mjs} +62 -58
- package/dist/{workspaces-C36s2jb9.mjs → workspaces-BccMFmGQ.mjs} +1188 -1079
- package/dist/worktree-CK2MpJW5.mjs +2 -0
- package/dist/{worktree-CgvJYJ-Q.mjs → worktree-DQ6Zi2Mv.mjs} +304 -53
- package/dist/xcode-Zlx3qjEs.mjs +896 -0
- package/package.json +7 -5
- package/shim/android-optimizations.gradle +7 -5
- package/dist/activity-BSV745Kz.mjs +0 -629
- package/dist/api-qvOzWyfO.mjs +0 -154
- package/dist/api-run.mjs +0 -294
- package/dist/app-install-BIKtMfPq.mjs +0 -896
- package/dist/artifact-lifecycle-DzPpBYvK.mjs +0 -30
- package/dist/budget-f7516Zk0.mjs +0 -4106
- package/dist/build-facts-DcLv2HSd.d.mts +0 -111
- package/dist/cancellation-C_22VQTH.mjs +0 -24
- package/dist/client-qQAaXSUs.mjs +0 -1771
- package/dist/config-BYDxlMY3.mjs +0 -562
- package/dist/device-DuiPJQSn.mjs +0 -290
- package/dist/device-lease-BX1sJQ2E.mjs +0 -1224
- package/dist/device-remote-xRT0Vmo9.mjs +0 -1272
- package/dist/eas-session-ledger-Cm0Gwq2F.mjs +0 -207
- package/dist/exec-DqKo9GKJ.mjs +0 -268
- package/dist/git-DDfFzkMm.mjs +0 -45
- package/dist/launch-verify-B6Q8hZP-.mjs +0 -428
- package/dist/logs-BGrEUaEs.mjs +0 -383
- package/dist/miss-reason-mKzZ4VvN.mjs +0 -238
- package/dist/native-android-D5qc3-_v.mjs +0 -226
- package/dist/ndjson-Du3j0AQ9.d.mts +0 -17
- package/dist/plan-C4TjdPsR.mjs +0 -260
- package/dist/prebuild-DYbucPXy.mjs +0 -212
- package/dist/preview-78a9kR_-.mjs +0 -1011
- package/dist/react-native-build-CtCccJtb.mjs +0 -239
- package/dist/react-native-doctor-CfRnFfjs.mjs +0 -78
- package/dist/remote-cache-OyOyVIS3.mjs +0 -526
- package/dist/result-CaJg5Iat.mjs +0 -186
- package/dist/server-expo-Bigriskl.mjs +0 -2
- package/dist/settings-BORNaaCO.mjs +0 -402
- package/dist/spawn-claims-DVS5RkMS.mjs +0 -72
- package/dist/stage-KNTQopqv.mjs +0 -157
- package/dist/stim-desktop-BzBN2Em2.mjs +0 -63
- package/dist/tailnet-Dh-qiYzG.mjs +0 -265
- package/dist/toolchain-BFkAcstd.mjs +0 -2
- package/dist/toolchain-DxSsNssu.mjs +0 -1657
- package/dist/trigger-9_USgmxz.mjs +0 -2
- package/dist/web-Dq-i3wzJ.mjs +0 -2
- package/dist/worktree-DpLdCHga.mjs +0 -2
- package/dist/{api-run.d.mts → doctor-fingerprint.d.mts} +0 -0
- package/dist/{errors-DzkMYh8Q.mjs → errors-ccaPc4ox.mjs} +2 -2
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { ambientContext, ambientEnv } from "@stim-cli/core";
|
|
3
|
+
import { createDebugLog, runId } from "@stim-cli/core/state";
|
|
4
|
+
import { basename, delimiter, resolve } from "path";
|
|
5
|
+
import { execSync } from "child_process";
|
|
6
|
+
import spawn from "cross-spawn";
|
|
7
|
+
import which from "which";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
10
|
+
//#region \0rolldown/runtime.js
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
16
|
+
var __exportAll = (all, no_symbols) => {
|
|
17
|
+
let target = {};
|
|
18
|
+
for (var name in all) __defProp(target, name, {
|
|
19
|
+
get: all[name],
|
|
20
|
+
enumerable: true
|
|
21
|
+
});
|
|
22
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
23
|
+
return target;
|
|
24
|
+
};
|
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
27
|
+
key = keys[i];
|
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
29
|
+
get: ((k) => from[k]).bind(null, key),
|
|
30
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
36
|
+
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/debug-log.ts
|
|
39
|
+
const debugLog = createDebugLog("cli", { base: () => ({ runId: runId() }) });
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/report-runtime.ts
|
|
42
|
+
const reports = /* @__PURE__ */ new WeakMap();
|
|
43
|
+
function reportSignal(context) {
|
|
44
|
+
return context && reports.has(context) ? context.signal : void 0;
|
|
45
|
+
}
|
|
46
|
+
function trackReportResource(context, closed, cancel, signal = context?.signal) {
|
|
47
|
+
const state = context && reports.get(context);
|
|
48
|
+
if (!context || !state || !signal) return;
|
|
49
|
+
const { pending } = state;
|
|
50
|
+
const abort = () => {
|
|
51
|
+
const cancelled = Promise.resolve().then(cancel);
|
|
52
|
+
pending.add(cancelled);
|
|
53
|
+
cancelled.then(() => pending.delete(cancelled), (error) => {
|
|
54
|
+
state.failure ??= error;
|
|
55
|
+
pending.delete(cancelled);
|
|
56
|
+
pending.delete(closed);
|
|
57
|
+
signal.removeEventListener("abort", abort);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
pending.add(closed);
|
|
61
|
+
const settled = () => {
|
|
62
|
+
signal.removeEventListener("abort", abort);
|
|
63
|
+
pending.delete(closed);
|
|
64
|
+
};
|
|
65
|
+
closed.then(settled, (error) => {
|
|
66
|
+
state.failure ??= error;
|
|
67
|
+
settled();
|
|
68
|
+
});
|
|
69
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
70
|
+
if (signal.aborted) abort();
|
|
71
|
+
}
|
|
72
|
+
async function runReport(context, work) {
|
|
73
|
+
const controller = new AbortController();
|
|
74
|
+
const signal = AbortSignal.any([context.signal, controller.signal]);
|
|
75
|
+
const operation = {
|
|
76
|
+
...context,
|
|
77
|
+
signal,
|
|
78
|
+
output: ((stream, text) => {
|
|
79
|
+
if (!signal.aborted) context.output(stream, text);
|
|
80
|
+
})
|
|
81
|
+
};
|
|
82
|
+
const pending = /* @__PURE__ */ new Set();
|
|
83
|
+
const state = { pending };
|
|
84
|
+
reports.set(operation, state);
|
|
85
|
+
const deadline = performance.now() + 6e4;
|
|
86
|
+
const expire = () => {
|
|
87
|
+
controller.abort(Object.assign(/* @__PURE__ */ new Error("The report exceeded its 60 second budget."), { code: "STIM_REPORT_TIMEOUT" }));
|
|
88
|
+
};
|
|
89
|
+
const timer = setTimeout(expire, 6e4);
|
|
90
|
+
let rejectCancellation;
|
|
91
|
+
const cancelled = new Promise((_, reject) => {
|
|
92
|
+
rejectCancellation = reject;
|
|
93
|
+
});
|
|
94
|
+
const abort = () => rejectCancellation(signal.reason);
|
|
95
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
96
|
+
const outcome = await (async () => {
|
|
97
|
+
try {
|
|
98
|
+
signal.throwIfAborted();
|
|
99
|
+
const result = await Promise.race([work(operation), cancelled]);
|
|
100
|
+
if (performance.now() >= deadline) expire();
|
|
101
|
+
signal.throwIfAborted();
|
|
102
|
+
return { result };
|
|
103
|
+
} catch (error) {
|
|
104
|
+
return { error };
|
|
105
|
+
}
|
|
106
|
+
})().finally(async () => {
|
|
107
|
+
clearTimeout(timer);
|
|
108
|
+
signal.removeEventListener("abort", abort);
|
|
109
|
+
controller.abort();
|
|
110
|
+
const cleanupDeadline = performance.now() + 35e3;
|
|
111
|
+
const expireCleanup = () => {
|
|
112
|
+
state.failure ??= Object.assign(/* @__PURE__ */ new Error("Report cleanup did not finish within 35 seconds."), {
|
|
113
|
+
code: "STIM_CLAIM_UNAVAILABLE",
|
|
114
|
+
reportCleanup: true
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
let cleanupTimer;
|
|
118
|
+
try {
|
|
119
|
+
await Promise.race([(async () => {
|
|
120
|
+
while (pending.size) await Promise.allSettled(pending);
|
|
121
|
+
})(), new Promise((resolve) => {
|
|
122
|
+
cleanupTimer = setTimeout(() => {
|
|
123
|
+
expireCleanup();
|
|
124
|
+
resolve();
|
|
125
|
+
}, 35e3);
|
|
126
|
+
})]);
|
|
127
|
+
if (performance.now() >= cleanupDeadline) expireCleanup();
|
|
128
|
+
} finally {
|
|
129
|
+
clearTimeout(cleanupTimer);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
if ("failure" in state) throw state.failure;
|
|
133
|
+
if ("error" in outcome) throw outcome.error;
|
|
134
|
+
return outcome.result;
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/process-identity.ts
|
|
138
|
+
var process_identity_exports = /* @__PURE__ */ __exportAll({});
|
|
139
|
+
import * as import__stim_cli_core_process_identity from "@stim-cli/core/process-identity";
|
|
140
|
+
__reExport(process_identity_exports, import__stim_cli_core_process_identity);
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/ownership-claim.ts
|
|
143
|
+
var ownership_claim_exports = /* @__PURE__ */ __exportAll({});
|
|
144
|
+
import * as import__stim_cli_core_ownership_claim from "@stim-cli/core/ownership-claim";
|
|
145
|
+
__reExport(ownership_claim_exports, import__stim_cli_core_ownership_claim);
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/engine/operation-state.ts
|
|
148
|
+
const states = /* @__PURE__ */ new WeakMap();
|
|
149
|
+
let detached;
|
|
150
|
+
function fresh() {
|
|
151
|
+
return {
|
|
152
|
+
cancelled: null,
|
|
153
|
+
runSignal: void 0,
|
|
154
|
+
declaring: /* @__PURE__ */ new Set(),
|
|
155
|
+
running: /* @__PURE__ */ new Set(),
|
|
156
|
+
refusal: null,
|
|
157
|
+
handled: false,
|
|
158
|
+
draining: false,
|
|
159
|
+
exitCleanups: /* @__PURE__ */ new Set(),
|
|
160
|
+
buildMachineFlag: void 0,
|
|
161
|
+
takesSignals: false,
|
|
162
|
+
abortOperation: void 0
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** The state of `context`'s operation; code that is not passed a context yet shares one state per process. */
|
|
166
|
+
function operationState(context) {
|
|
167
|
+
if (!context) return detached ??= fresh();
|
|
168
|
+
let state = states.get(context);
|
|
169
|
+
if (!state) {
|
|
170
|
+
state = fresh();
|
|
171
|
+
states.set(context, state);
|
|
172
|
+
}
|
|
173
|
+
return state;
|
|
174
|
+
}
|
|
175
|
+
/** Whether an abort reason asks the operation to terminate rather than interrupt it. */
|
|
176
|
+
function isTermination(reason) {
|
|
177
|
+
return reason === "SIGTERM";
|
|
178
|
+
}
|
|
179
|
+
/** Keeps asynchronous work unwinding on the CLI's first interrupt until its owned work has settled. */
|
|
180
|
+
async function withDrainingCancellation(context, signal, work) {
|
|
181
|
+
if (!context) return work();
|
|
182
|
+
const abort = () => {
|
|
183
|
+
const state = operationState(context);
|
|
184
|
+
state.handled = true;
|
|
185
|
+
if (!isTermination(context.signal.reason)) state.draining = true;
|
|
186
|
+
};
|
|
187
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
188
|
+
if (signal?.aborted) abort();
|
|
189
|
+
try {
|
|
190
|
+
return await work();
|
|
191
|
+
} finally {
|
|
192
|
+
signal?.removeEventListener("abort", abort);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/engine/spawn-claims.ts
|
|
197
|
+
/**
|
|
198
|
+
* Record every child `context`'s operation later starts through `spawnDeclared` on `claim` until
|
|
199
|
+
* `stopDeclaringSpawnsOn(context, claim)`.
|
|
200
|
+
*/
|
|
201
|
+
function declareSpawnsOn(context, claim) {
|
|
202
|
+
if (claim) operationState(context).declaring.add(claim);
|
|
203
|
+
}
|
|
204
|
+
function stopDeclaringSpawnsOn(context, claim) {
|
|
205
|
+
if (claim) operationState(context).declaring.delete(claim);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Start a child that every claim `context`'s operation passed to `declareSpawnsOn` records until it exits. The child keeps
|
|
209
|
+
* the caller's process group, so a terminal interrupt still reaches it; the claim follows the child
|
|
210
|
+
* itself. A claim that cannot be marked stops the spawn rather than letting it run unprotected. A claim
|
|
211
|
+
* records one child, so declared spawns must not overlap. `until: 'close'` also holds the declaration
|
|
212
|
+
* while a launcher's child retains its stdio pipes after the launcher exits.
|
|
213
|
+
*/
|
|
214
|
+
function spawnDeclared(context, spawn, { until = "exit" } = {}) {
|
|
215
|
+
const { declaring, running, refusal } = operationState(context);
|
|
216
|
+
if (refusal !== null) throw new Error(refusal);
|
|
217
|
+
const claims = [...declaring];
|
|
218
|
+
if (claims.length === 0) return spawn();
|
|
219
|
+
const forget = () => {
|
|
220
|
+
for (const claim of claims) try {
|
|
221
|
+
(0, ownership_claim_exports.clearClaimChild)(claim);
|
|
222
|
+
} catch {}
|
|
223
|
+
};
|
|
224
|
+
let child;
|
|
225
|
+
try {
|
|
226
|
+
for (const claim of claims) (0, ownership_claim_exports.markClaimChildPending)(claim);
|
|
227
|
+
child = spawn();
|
|
228
|
+
} catch (error) {
|
|
229
|
+
forget();
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
const pid = child.pid;
|
|
233
|
+
if (pid === void 0) {
|
|
234
|
+
forget();
|
|
235
|
+
return child;
|
|
236
|
+
}
|
|
237
|
+
running.add(child);
|
|
238
|
+
child.once(until, () => running.delete(child));
|
|
239
|
+
const captured = (0, process_identity_exports.captureProcessIdentity)(pid);
|
|
240
|
+
if (captured.ok) for (const claim of claims) try {
|
|
241
|
+
(0, ownership_claim_exports.setClaimChild)(claim, {
|
|
242
|
+
pid,
|
|
243
|
+
processToken: captured.token
|
|
244
|
+
});
|
|
245
|
+
} catch {}
|
|
246
|
+
child.once(until, forget);
|
|
247
|
+
return child;
|
|
248
|
+
}
|
|
249
|
+
/** Refuse every later `spawnDeclared` of `context`'s operation with `reason` until `allowDeclaredSpawns`. */
|
|
250
|
+
function refuseDeclaredSpawns(context, reason) {
|
|
251
|
+
operationState(context).refusal = reason;
|
|
252
|
+
}
|
|
253
|
+
function allowDeclaredSpawns(context) {
|
|
254
|
+
operationState(context).refusal = null;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Send `signal` to every child `context`'s operation started through `spawnDeclared` that has not exited; returns how
|
|
258
|
+
* many were signalled.
|
|
259
|
+
*/
|
|
260
|
+
function signalDeclaredSpawns(context, signal) {
|
|
261
|
+
let signalled = 0;
|
|
262
|
+
for (const child of operationState(context).running) {
|
|
263
|
+
if (child.exitCode !== null || child.signalCode !== null) continue;
|
|
264
|
+
try {
|
|
265
|
+
if (child.kill(signal)) signalled += 1;
|
|
266
|
+
} catch {}
|
|
267
|
+
}
|
|
268
|
+
return signalled;
|
|
269
|
+
}
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/exec.ts
|
|
272
|
+
const MAX_BUFFER = 67108864;
|
|
273
|
+
function spawnReportProbe(file, args, opts) {
|
|
274
|
+
if (process.platform !== "win32" || !reportSignal(ambientContext()) || !executableIn(file, opts.env ?? ambientEnv(), opts.cwd ?? process.cwd())) return spawn(file, args, opts);
|
|
275
|
+
const env = opts.env ?? ambientEnv();
|
|
276
|
+
const systemRoot = process.env.SystemRoot ?? process.env.SYSTEMROOT;
|
|
277
|
+
if (!systemRoot) throw new Error("SystemRoot is required to contain Windows report probes.");
|
|
278
|
+
return spawn(resolve(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe"), [
|
|
279
|
+
"-NoLogo",
|
|
280
|
+
"-NoProfile",
|
|
281
|
+
"-NonInteractive",
|
|
282
|
+
"-ExecutionPolicy",
|
|
283
|
+
"Bypass",
|
|
284
|
+
"-File",
|
|
285
|
+
fileURLToPath(new URL("../dist/windows-report.ps1", import.meta.url))
|
|
286
|
+
], {
|
|
287
|
+
...opts,
|
|
288
|
+
windowsHide: true,
|
|
289
|
+
env: {
|
|
290
|
+
...env,
|
|
291
|
+
STIM_REPORT_CHILD: JSON.stringify({
|
|
292
|
+
file,
|
|
293
|
+
args,
|
|
294
|
+
node: process.execPath,
|
|
295
|
+
entry: fileURLToPath(new URL("../dist/windows-report.mjs", import.meta.url))
|
|
296
|
+
})
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
function reportChild(child, signal, failed) {
|
|
301
|
+
const context = ambientContext();
|
|
302
|
+
const report = reportSignal(context);
|
|
303
|
+
signal ??= report;
|
|
304
|
+
if (!signal) return;
|
|
305
|
+
let rejectClosed;
|
|
306
|
+
let ended = false;
|
|
307
|
+
let finishNativeClose;
|
|
308
|
+
const nativeClosed = new Promise((resolve) => {
|
|
309
|
+
finishNativeClose = resolve;
|
|
310
|
+
});
|
|
311
|
+
const closed = new Promise((resolve, reject) => {
|
|
312
|
+
rejectClosed = reject;
|
|
313
|
+
child.once("close", () => {
|
|
314
|
+
ended = true;
|
|
315
|
+
finishNativeClose();
|
|
316
|
+
if (report) cancel().then(resolve, reject);
|
|
317
|
+
else resolve();
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
const pid = child.pid;
|
|
321
|
+
const captured = pid === void 0 ? null : (0, process_identity_exports.captureProcessIdentity)(pid);
|
|
322
|
+
const observe = () => {
|
|
323
|
+
if (pid === void 0) return "gone";
|
|
324
|
+
if (captured?.ok) return (0, process_identity_exports.inspectProcessIdentity)({
|
|
325
|
+
pid,
|
|
326
|
+
processToken: captured.token
|
|
327
|
+
});
|
|
328
|
+
if (process.platform === "win32") return ended ? "gone" : "unknown";
|
|
329
|
+
try {
|
|
330
|
+
process.kill(-pid, 0);
|
|
331
|
+
} catch (error) {
|
|
332
|
+
if (error instanceof Error && "code" in error && error.code === "ESRCH") return "gone";
|
|
333
|
+
}
|
|
334
|
+
return "unknown";
|
|
335
|
+
};
|
|
336
|
+
const refuse = (message) => {
|
|
337
|
+
const error = Object.assign(new Error(message), {
|
|
338
|
+
code: "STIM_CLAIM_UNAVAILABLE",
|
|
339
|
+
reportCleanup: true
|
|
340
|
+
});
|
|
341
|
+
child.stdin?.destroy();
|
|
342
|
+
child.stdout?.destroy();
|
|
343
|
+
child.stderr?.destroy();
|
|
344
|
+
child.unref();
|
|
345
|
+
failed?.(error);
|
|
346
|
+
rejectClosed(error);
|
|
347
|
+
throw error;
|
|
348
|
+
};
|
|
349
|
+
let cancelled;
|
|
350
|
+
const cancel = () => cancelled ??= (async () => {
|
|
351
|
+
let identity = observe();
|
|
352
|
+
if (pid !== void 0) {
|
|
353
|
+
const deadline = performance.now() + 1e3;
|
|
354
|
+
while (identity === "unknown" && performance.now() < deadline) {
|
|
355
|
+
await setTimeout$1(50);
|
|
356
|
+
identity = observe();
|
|
357
|
+
}
|
|
358
|
+
if (identity === "unknown") refuse(`Cannot verify cleanup for report child ${pid}; its process or descendants were left untouched.`);
|
|
359
|
+
}
|
|
360
|
+
if (pid !== void 0 && captured?.ok && (identity === "same" || process.platform !== "win32" && identity === "gone")) {
|
|
361
|
+
if (process.platform === "win32") {
|
|
362
|
+
if (report) child.kill("SIGKILL");
|
|
363
|
+
else {
|
|
364
|
+
const killer = spawn("taskkill", [
|
|
365
|
+
"/PID",
|
|
366
|
+
String(pid),
|
|
367
|
+
"/T",
|
|
368
|
+
"/F"
|
|
369
|
+
], { stdio: "ignore" });
|
|
370
|
+
const timer = setTimeout(() => killer.kill("SIGKILL"), 5e3);
|
|
371
|
+
await new Promise((resolve) => {
|
|
372
|
+
killer.once("error", () => child.kill("SIGKILL"));
|
|
373
|
+
killer.once("close", (status) => {
|
|
374
|
+
if (status !== 0) child.kill("SIGKILL");
|
|
375
|
+
resolve();
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
clearTimeout(timer);
|
|
379
|
+
}
|
|
380
|
+
} else try {
|
|
381
|
+
process.kill(-pid, "SIGKILL");
|
|
382
|
+
} catch {
|
|
383
|
+
child.kill("SIGKILL");
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
child.stdin?.destroy();
|
|
387
|
+
child.stdout?.destroy();
|
|
388
|
+
child.stderr?.destroy();
|
|
389
|
+
if (!ended) {
|
|
390
|
+
let timer;
|
|
391
|
+
await Promise.race([nativeClosed, new Promise((resolve) => {
|
|
392
|
+
timer = setTimeout(resolve, 1e3);
|
|
393
|
+
})]);
|
|
394
|
+
clearTimeout(timer);
|
|
395
|
+
if (!ended) refuse(`Report child ${pid} did not close within the cleanup budget.`);
|
|
396
|
+
}
|
|
397
|
+
})();
|
|
398
|
+
if (report) trackReportResource(context, closed, cancel, signal);
|
|
399
|
+
else {
|
|
400
|
+
const abort = () => {
|
|
401
|
+
cancel().catch(() => {});
|
|
402
|
+
};
|
|
403
|
+
const callerSignal = signal;
|
|
404
|
+
callerSignal.addEventListener("abort", abort, { once: true });
|
|
405
|
+
const settled = () => callerSignal.removeEventListener("abort", abort);
|
|
406
|
+
closed.then(settled, settled);
|
|
407
|
+
if (callerSignal.aborted) abort();
|
|
408
|
+
}
|
|
409
|
+
return cancel;
|
|
410
|
+
}
|
|
411
|
+
function budgetMs(timeoutMs) {
|
|
412
|
+
if (timeoutMs === "unbounded") return void 0;
|
|
413
|
+
if (!(timeoutMs > 0)) throw new RangeError(`timeoutMs must be a positive number of milliseconds or 'unbounded', got ${timeoutMs}`);
|
|
414
|
+
return timeoutMs;
|
|
415
|
+
}
|
|
416
|
+
/** Whether an exec error is a child killed for exceeding its `timeoutMs`. */
|
|
417
|
+
function isTimeoutError(error) {
|
|
418
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "ETIMEDOUT";
|
|
419
|
+
}
|
|
420
|
+
function nameTimeout(error, command, timeoutMs) {
|
|
421
|
+
if (error?.code === "ETIMEDOUT" && error instanceof Error) error.message = `Command timed out after ${timeoutMs}ms: ${command}`;
|
|
422
|
+
return error;
|
|
423
|
+
}
|
|
424
|
+
const WINDOWS_BATCH_FILE = /\.(?:bat|cmd)$/i;
|
|
425
|
+
const BATCH_UNSAFE_ARGUMENT = /["\r\n]/;
|
|
426
|
+
function isUnsafeBatchSpawn(target, args, platform = process.platform) {
|
|
427
|
+
return platform === "win32" && WINDOWS_BATCH_FILE.test(target) && args.some((arg) => BATCH_UNSAFE_ARGUMENT.test(arg));
|
|
428
|
+
}
|
|
429
|
+
function executableIn(file, env, cwd) {
|
|
430
|
+
const windows = process.platform === "win32";
|
|
431
|
+
const value = (name) => env[name] ?? (windows ? Object.entries(env).find(([key, field]) => field !== void 0 && key.toUpperCase() === name)?.[1] : void 0);
|
|
432
|
+
const directory = typeof cwd === "string" ? cwd : fileURLToPath(cwd);
|
|
433
|
+
const path = file.includes("/") || windows && file.includes("\\");
|
|
434
|
+
const directories = path ? [""] : (value("PATH") ?? "").split(delimiter);
|
|
435
|
+
if (windows && !path) directories.unshift(directory);
|
|
436
|
+
for (const entry of directories) {
|
|
437
|
+
const candidate = resolve(directory, entry.replace(/^"(.*)"$/, "$1"), file);
|
|
438
|
+
const found = which.sync(candidate, {
|
|
439
|
+
nothrow: true,
|
|
440
|
+
path: "",
|
|
441
|
+
pathExt: value("PATHEXT") ?? ""
|
|
442
|
+
});
|
|
443
|
+
if (found) return found;
|
|
444
|
+
}
|
|
445
|
+
return null;
|
|
446
|
+
}
|
|
447
|
+
function refuseUnsafeBatchArguments(file, args, env = ambientEnv(), cwd = ambientContext()?.cwd ?? process.cwd()) {
|
|
448
|
+
if (process.platform !== "win32") return;
|
|
449
|
+
const target = executableIn(file, env, cwd) ?? file;
|
|
450
|
+
if (isUnsafeBatchSpawn(target, args)) throw new Error(`Refusing to run ${basename(target)}: an argument contains a character cmd.exe could misinterpret (a double quote or a line break).`);
|
|
451
|
+
}
|
|
452
|
+
function redactError(error, values) {
|
|
453
|
+
const secrets = values?.filter(Boolean) ?? [];
|
|
454
|
+
if (secrets.length === 0 || !error || typeof error !== "object") return error;
|
|
455
|
+
const scrub = (text) => secrets.reduce((acc, secret) => acc.split(secret).join("***"), text);
|
|
456
|
+
const fields = error;
|
|
457
|
+
for (const key of Object.getOwnPropertyNames(error)) {
|
|
458
|
+
const value = fields[key];
|
|
459
|
+
if (typeof value === "string") fields[key] = scrub(value);
|
|
460
|
+
else if (Array.isArray(value)) fields[key] = value.map((item) => typeof item === "string" ? scrub(item) : item);
|
|
461
|
+
}
|
|
462
|
+
return error;
|
|
463
|
+
}
|
|
464
|
+
const defaultExecutor = {
|
|
465
|
+
reportSignal: () => reportSignal(ambientContext()),
|
|
466
|
+
run(cmd, { timeoutMs, killSignal, cwd, env }) {
|
|
467
|
+
const opts = {
|
|
468
|
+
encoding: "utf-8",
|
|
469
|
+
stdio: [
|
|
470
|
+
"pipe",
|
|
471
|
+
"pipe",
|
|
472
|
+
"pipe"
|
|
473
|
+
],
|
|
474
|
+
maxBuffer: MAX_BUFFER
|
|
475
|
+
};
|
|
476
|
+
const timeout = budgetMs(timeoutMs);
|
|
477
|
+
if (timeout !== void 0) opts.timeout = timeout;
|
|
478
|
+
if (killSignal) opts.killSignal = killSignal;
|
|
479
|
+
const childCwd = cwd ?? ambientContext()?.cwd;
|
|
480
|
+
if (childCwd) opts.cwd = childCwd;
|
|
481
|
+
if (env || ambientContext()) opts.env = {
|
|
482
|
+
...ambientEnv(),
|
|
483
|
+
...env
|
|
484
|
+
};
|
|
485
|
+
try {
|
|
486
|
+
return String(execSync(cmd, opts)).trim();
|
|
487
|
+
} catch (error) {
|
|
488
|
+
throw nameTimeout(error, cmd, timeoutMs);
|
|
489
|
+
}
|
|
490
|
+
},
|
|
491
|
+
runFile(file, args = [], { timeoutMs, killSignal, cwd, env, omitEnv, input, untrimmed, rejectStderr, detachedSilent, redact }) {
|
|
492
|
+
const opts = {
|
|
493
|
+
encoding: "utf-8",
|
|
494
|
+
stdio: detachedSilent ? "ignore" : [
|
|
495
|
+
"pipe",
|
|
496
|
+
"pipe",
|
|
497
|
+
"pipe"
|
|
498
|
+
],
|
|
499
|
+
maxBuffer: MAX_BUFFER
|
|
500
|
+
};
|
|
501
|
+
if (detachedSilent) opts.detached = true;
|
|
502
|
+
const timeout = budgetMs(timeoutMs);
|
|
503
|
+
if (timeout !== void 0) opts.timeout = timeout;
|
|
504
|
+
if (killSignal) opts.killSignal = killSignal;
|
|
505
|
+
const childCwd = cwd ?? ambientContext()?.cwd;
|
|
506
|
+
if (childCwd) opts.cwd = childCwd;
|
|
507
|
+
if (input !== void 0) opts.input = input;
|
|
508
|
+
if (env || omitEnv?.length || ambientContext()) {
|
|
509
|
+
const childEnv = {
|
|
510
|
+
...ambientEnv(),
|
|
511
|
+
...env
|
|
512
|
+
};
|
|
513
|
+
for (const key of omitEnv ?? []) delete childEnv[key];
|
|
514
|
+
opts.env = childEnv;
|
|
515
|
+
}
|
|
516
|
+
refuseUnsafeBatchArguments(file, args, opts.env, opts.cwd);
|
|
517
|
+
const result = spawn.sync(file, args, opts);
|
|
518
|
+
if (result.error) throw redactError(nameTimeout(Object.assign(result.error, result), [file, ...args].join(" "), timeoutMs), redact);
|
|
519
|
+
if (result.status !== 0 || rejectStderr && String(result.stderr ?? "").trim()) {
|
|
520
|
+
const stderr = String(result.stderr ?? "");
|
|
521
|
+
const message = `Command failed: ${[file, ...args].join(" ")}${stderr ? `\n${stderr}` : ""}`;
|
|
522
|
+
throw redactError(Object.assign(new Error(message), result), redact);
|
|
523
|
+
}
|
|
524
|
+
if (detachedSilent) return "";
|
|
525
|
+
return untrimmed ? String(result.stdout) : String(result.stdout).trim();
|
|
526
|
+
},
|
|
527
|
+
runFileAsync(file, args = [], { timeoutMs, killSignal, cwd, env, omitEnv, input, untrimmed, rejectStderr, onSpawn, declareFor, detachedSilent, redact, signal: callSignal }) {
|
|
528
|
+
const command = [file, ...args].join(" ");
|
|
529
|
+
return new Promise((resolve, reject) => {
|
|
530
|
+
const report = callSignal ?? reportSignal(ambientContext());
|
|
531
|
+
report?.throwIfAborted();
|
|
532
|
+
const timeout = budgetMs(timeoutMs);
|
|
533
|
+
const opts = detachedSilent ? {
|
|
534
|
+
stdio: "ignore",
|
|
535
|
+
detached: true
|
|
536
|
+
} : { stdio: [
|
|
537
|
+
input === void 0 ? "ignore" : "pipe",
|
|
538
|
+
"pipe",
|
|
539
|
+
"pipe"
|
|
540
|
+
] };
|
|
541
|
+
if (report && process.platform !== "win32") opts.detached = true;
|
|
542
|
+
const childCwd = cwd ?? ambientContext()?.cwd;
|
|
543
|
+
if (childCwd) opts.cwd = childCwd;
|
|
544
|
+
if (env || omitEnv?.length || ambientContext()) {
|
|
545
|
+
const childEnv = {
|
|
546
|
+
...ambientEnv(),
|
|
547
|
+
...env
|
|
548
|
+
};
|
|
549
|
+
for (const key of omitEnv ?? []) delete childEnv[key];
|
|
550
|
+
opts.env = childEnv;
|
|
551
|
+
}
|
|
552
|
+
refuseUnsafeBatchArguments(file, args, opts.env, opts.cwd);
|
|
553
|
+
const start = () => spawnReportProbe(file, args, opts);
|
|
554
|
+
const child = declareFor ? spawnDeclared(declareFor, start) : start();
|
|
555
|
+
let cancel;
|
|
556
|
+
let timer;
|
|
557
|
+
try {
|
|
558
|
+
cancel = reportChild(child, report, (error) => {
|
|
559
|
+
clearTimeout(timer);
|
|
560
|
+
reject(error);
|
|
561
|
+
});
|
|
562
|
+
onSpawn?.(child);
|
|
563
|
+
} catch (error) {
|
|
564
|
+
if (cancel) cancel().catch(reject);
|
|
565
|
+
else if (!report) child.kill("SIGKILL");
|
|
566
|
+
reject(error);
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
if (input !== void 0) {
|
|
570
|
+
child.stdin?.on("error", () => {});
|
|
571
|
+
child.stdin?.end(input);
|
|
572
|
+
}
|
|
573
|
+
const stdout = [];
|
|
574
|
+
const stderr = [];
|
|
575
|
+
let timedOut = false;
|
|
576
|
+
let overflowed = false;
|
|
577
|
+
let bufferedBytes = 0;
|
|
578
|
+
const capture = (chunks, chunk) => {
|
|
579
|
+
if (overflowed) return;
|
|
580
|
+
const remaining = MAX_BUFFER - bufferedBytes;
|
|
581
|
+
if (chunk.length <= remaining) {
|
|
582
|
+
chunks.push(chunk);
|
|
583
|
+
bufferedBytes += chunk.length;
|
|
584
|
+
} else {
|
|
585
|
+
if (remaining > 0) chunks.push(chunk.subarray(0, remaining));
|
|
586
|
+
bufferedBytes = MAX_BUFFER;
|
|
587
|
+
overflowed = true;
|
|
588
|
+
if (cancel) cancel().catch(reject);
|
|
589
|
+
else {
|
|
590
|
+
child.kill("SIGKILL");
|
|
591
|
+
child.stdin?.destroy();
|
|
592
|
+
child.stdout?.destroy();
|
|
593
|
+
child.stderr?.destroy();
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
timer = timeout === void 0 ? void 0 : setTimeout(() => {
|
|
598
|
+
timedOut = true;
|
|
599
|
+
if (cancel) cancel().catch(reject);
|
|
600
|
+
else {
|
|
601
|
+
child.kill(killSignal ?? "SIGTERM");
|
|
602
|
+
child.stdin?.destroy();
|
|
603
|
+
child.stdout?.destroy();
|
|
604
|
+
child.stderr?.destroy();
|
|
605
|
+
}
|
|
606
|
+
}, timeout);
|
|
607
|
+
child.stdout?.on("data", (chunk) => capture(stdout, chunk));
|
|
608
|
+
child.stderr?.on("data", (chunk) => capture(stderr, chunk));
|
|
609
|
+
child.on("error", (error) => {
|
|
610
|
+
clearTimeout(timer);
|
|
611
|
+
reject(redactError(error, redact));
|
|
612
|
+
});
|
|
613
|
+
child.on("close", (status, signal) => {
|
|
614
|
+
clearTimeout(timer);
|
|
615
|
+
const discardOutput = (timedOut || overflowed || report?.aborted) && redact?.some(Boolean);
|
|
616
|
+
const out = discardOutput ? "" : Buffer.concat(stdout).toString("utf-8");
|
|
617
|
+
const err = discardOutput ? "" : Buffer.concat(stderr).toString("utf-8");
|
|
618
|
+
const result = {
|
|
619
|
+
status,
|
|
620
|
+
signal,
|
|
621
|
+
stdout: out,
|
|
622
|
+
stderr: err
|
|
623
|
+
};
|
|
624
|
+
if (report?.aborted) reject(report.reason);
|
|
625
|
+
else if (timedOut) reject(redactError(nameTimeout(Object.assign(new Error(command), result, { code: "ETIMEDOUT" }), command, timeoutMs), redact));
|
|
626
|
+
else if (overflowed) reject(redactError(Object.assign(/* @__PURE__ */ new Error(`Command output exceeded ${MAX_BUFFER} bytes: ${command}`), result, { code: "ENOBUFS" }), redact));
|
|
627
|
+
else if (status !== 0 || rejectStderr && err.trim()) reject(redactError(Object.assign(/* @__PURE__ */ new Error(`Command failed: ${command}${err ? `\n${err}` : ""}`), result), redact));
|
|
628
|
+
else resolve(detachedSilent ? "" : untrimmed ? out : out.trim());
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
},
|
|
632
|
+
runQuiet(cmd, opts) {
|
|
633
|
+
budgetMs(opts.timeoutMs);
|
|
634
|
+
try {
|
|
635
|
+
return this.run(cmd, opts);
|
|
636
|
+
} catch {
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
639
|
+
},
|
|
640
|
+
runFileQuiet(file, args, opts) {
|
|
641
|
+
budgetMs(opts.timeoutMs);
|
|
642
|
+
try {
|
|
643
|
+
return this.runFile(file, args, opts);
|
|
644
|
+
} catch {
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
},
|
|
648
|
+
runFileQuietAsync(file, args, opts) {
|
|
649
|
+
budgetMs(opts.timeoutMs);
|
|
650
|
+
return this.runFileAsync(file, args, opts).catch(() => null);
|
|
651
|
+
},
|
|
652
|
+
spawn(cmd, args = [], opts = {}) {
|
|
653
|
+
const report = reportSignal(ambientContext());
|
|
654
|
+
report?.throwIfAborted();
|
|
655
|
+
const context = ambientContext();
|
|
656
|
+
const childOpts = context ? {
|
|
657
|
+
...opts,
|
|
658
|
+
cwd: opts.cwd ?? context.cwd,
|
|
659
|
+
env: opts.env ?? context.env
|
|
660
|
+
} : opts;
|
|
661
|
+
if (report && process.platform !== "win32") childOpts.detached = true;
|
|
662
|
+
refuseUnsafeBatchArguments(cmd, args, childOpts.env ?? ambientEnv(), childOpts.cwd);
|
|
663
|
+
const child = spawnReportProbe(cmd, args, childOpts);
|
|
664
|
+
reportChild(child);
|
|
665
|
+
return child;
|
|
666
|
+
},
|
|
667
|
+
findExecutable(name) {
|
|
668
|
+
return executableIn(name, ambientEnv(), ambientContext()?.cwd ?? process.cwd());
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
/** The program a call runs, without its arguments: those can carry tokens. */
|
|
672
|
+
const programOf = (command) => basename(command.trim().split(/\s+/)[0] ?? "");
|
|
673
|
+
function outcomeOf(error) {
|
|
674
|
+
const { status, signal, code } = error ?? {};
|
|
675
|
+
return {
|
|
676
|
+
ok: false,
|
|
677
|
+
...typeof status === "number" ? { exit: status } : {},
|
|
678
|
+
...signal ? { signal } : {},
|
|
679
|
+
...code ? { code } : {}
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
let executionId = 0;
|
|
683
|
+
function timedSync(fn, program) {
|
|
684
|
+
return (...args) => {
|
|
685
|
+
if (!debugLog.enabled()) return fn(...args);
|
|
686
|
+
const id = ++executionId;
|
|
687
|
+
const name = program(...args);
|
|
688
|
+
const started = performance.now();
|
|
689
|
+
debugLog.log("exec.start", {
|
|
690
|
+
program: name,
|
|
691
|
+
executionId: id
|
|
692
|
+
});
|
|
693
|
+
try {
|
|
694
|
+
const out = fn(...args);
|
|
695
|
+
debugLog.log("exec", {
|
|
696
|
+
program: name,
|
|
697
|
+
executionId: id,
|
|
698
|
+
ms: Math.round(performance.now() - started),
|
|
699
|
+
ok: true
|
|
700
|
+
});
|
|
701
|
+
return out;
|
|
702
|
+
} catch (error) {
|
|
703
|
+
debugLog.log("exec", {
|
|
704
|
+
program: name,
|
|
705
|
+
executionId: id,
|
|
706
|
+
ms: Math.round(performance.now() - started),
|
|
707
|
+
...outcomeOf(error)
|
|
708
|
+
});
|
|
709
|
+
throw error;
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
let active = {
|
|
714
|
+
...defaultExecutor,
|
|
715
|
+
run: timedSync((cmd, opts) => defaultExecutor.run(cmd, opts), programOf),
|
|
716
|
+
runFile: timedSync((file, args, opts) => defaultExecutor.runFile(file, args, opts), (file) => basename(file)),
|
|
717
|
+
async runFileAsync(file, args, opts) {
|
|
718
|
+
if (!debugLog.enabled()) return defaultExecutor.runFileAsync(file, args, opts);
|
|
719
|
+
const id = ++executionId;
|
|
720
|
+
const name = basename(file);
|
|
721
|
+
const started = performance.now();
|
|
722
|
+
debugLog.log("exec.start", {
|
|
723
|
+
program: name,
|
|
724
|
+
executionId: id
|
|
725
|
+
});
|
|
726
|
+
try {
|
|
727
|
+
const out = await defaultExecutor.runFileAsync(file, args, opts);
|
|
728
|
+
debugLog.log("exec", {
|
|
729
|
+
program: name,
|
|
730
|
+
executionId: id,
|
|
731
|
+
ms: Math.round(performance.now() - started),
|
|
732
|
+
ok: true
|
|
733
|
+
});
|
|
734
|
+
return out;
|
|
735
|
+
} catch (error) {
|
|
736
|
+
debugLog.log("exec", {
|
|
737
|
+
program: name,
|
|
738
|
+
executionId: id,
|
|
739
|
+
ms: Math.round(performance.now() - started),
|
|
740
|
+
...outcomeOf(error)
|
|
741
|
+
});
|
|
742
|
+
throw error;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
function getExecutor() {
|
|
747
|
+
return active;
|
|
748
|
+
}
|
|
749
|
+
//#endregion
|
|
750
|
+
export { debugLog as _, refuseDeclaredSpawns as a, stopDeclaringSpawnsOn as c, withDrainingCancellation as d, ownership_claim_exports as f, trackReportResource as g, runReport as h, declareSpawnsOn as i, isTermination as l, reportSignal as m, isTimeoutError as n, signalDeclaredSpawns as o, process_identity_exports as p, allowDeclaredSpawns as r, spawnDeclared as s, getExecutor as t, operationState as u, __commonJSMin as v, __require as y };
|