stim 1.20.2 → 1.22.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 +141 -8
- package/dist/acquire-artifact-Co2k4f7O.mjs +171 -0
- package/dist/act-DsuqEkiM.mjs +2801 -0
- package/dist/activity-CMLmzp7o.mjs +1397 -0
- package/dist/{agent-device-usage-output-Dzgv6lgR.mjs → agent-device-usage-output-DUFaTMdd.mjs} +23 -67
- package/dist/{android-DCKZrNvV.mjs → android-ByRMUoiJ.mjs} +157 -93
- package/dist/{android-Mz_Inn3w.mjs → android-C7sVmyI9.mjs} +299 -116
- package/dist/{android-Dlzxshgp.mjs → android-DGkNqa_c.mjs} +5 -5
- package/dist/{android-HqP1_vB_.mjs → android-DR5lZ2Az.mjs} +2 -2
- package/dist/android-cas-compiler.mjs +2 -2
- package/dist/{android-cas-Bl-cLJBk.mjs → android-cas-ngferVq2.mjs} +7 -6
- package/dist/android-project-BCAAmMwz.mjs +12 -0
- package/dist/android-project-DVWyCbWU.d.mts +391 -0
- package/dist/api.d.mts +810 -64
- package/dist/api.mjs +782 -1
- package/dist/{artifact-HSwkIWEQ.mjs → artifact-8EY8SAPw.mjs} +240 -213
- package/dist/{artifact-D3czlUvT.mjs → artifact-DJPy518Y.mjs} +203 -164
- package/dist/artifact-platform-CXcmX_j3.mjs +27 -0
- package/dist/{browser-web-CA-F1GQo.mjs → browser-web-Bcv99PBM.mjs} +194 -64
- package/dist/budget-Cvwn54qV.mjs +9285 -0
- package/dist/{build-DYDbfkk5.mjs → build-CabC3G23.mjs} +153 -98
- package/dist/build-cache-Dv7RN200.mjs +602 -0
- package/dist/build-plan-DUC8Ka9y.mjs +248 -0
- package/dist/{cache-manifest-XH-fvDUj.mjs → cache-manifest-DSeQjt-Q.mjs} +2 -2
- package/dist/cache-manifest.mjs +1 -1
- package/dist/{ccache-zdKiYQ3E.mjs → ccache-Btwc36-I.mjs} +10 -9
- package/dist/{cdp-Dq_ypAlJ.mjs → cdp-3fwICjzi.mjs} +18 -5
- package/dist/{chrome-BnzZMqsR.mjs → chrome-Bbw689-6.mjs} +7 -4
- package/dist/{cli-CLP3diBm.mjs → cli-CHZa9Lvk.mjs} +20 -20
- package/dist/cli.mjs +1 -1
- package/dist/client-OyRoEuSr.mjs +1577 -0
- package/dist/collector-run.d.mts +4 -40
- package/dist/collector-run.mjs +9 -8
- package/dist/{command-output-BTy8hZ0F.mjs → command-output-gwpm28fu.mjs} +1 -1
- package/dist/config-DlrsduwG.mjs +955 -0
- package/dist/{created-devices-Dzd5C2LF.mjs → created-devices-x9rN6bhs.mjs} +14 -4
- package/dist/{dependency-state-DG0p31-y.mjs → dependency-state-1I9KZT1Y.mjs} +20 -5
- package/dist/{detached-entry-B9C_zeQC.mjs → detached-entry-BwNEtIrP.mjs} +1 -1
- package/dist/{dev-client-DAWVIGBu.mjs → dev-client-BSDR5h3F.mjs} +2 -2
- package/dist/{device-BECOiufl.mjs → device-B-L3Fbxy.mjs} +91 -34
- package/dist/device-DklWZLqb.mjs +1068 -0
- package/dist/{device-capacity-CBUAcRyQ.mjs → device-capacity-DK5_EwRS.mjs} +42 -13
- package/dist/device-host-worker.mjs +76 -79
- package/dist/{device-ios-COSi6oS1.mjs → device-ios-DoB6KFCO.mjs} +77 -51
- package/dist/{device-lease-run-Cw2M4z51.mjs → device-lease-run-xJPQ_QQG.mjs} +14 -26
- package/dist/{device-pool-Bf-pOhSw.mjs → device-pool-BMkdsefq.mjs} +5 -5
- package/dist/{doctor-kfMBnUw6.mjs → doctor-Bo7BXLux.mjs} +271 -320
- package/dist/{doctor-CB8oZKCk.mjs → doctor-D5_EzwfA.mjs} +186 -91
- package/dist/doctor-fingerprint-DZLoYFVb.mjs +16 -0
- package/dist/doctor-fingerprint.mjs +19 -0
- package/dist/doctor-thjWAV0z.mjs +2 -0
- package/dist/{doctor-watchman-BRyV2adA.mjs → doctor-watchman-N2wDotwQ.mjs} +40 -21
- package/dist/{eas-build-JyfqyHfC.mjs → eas-build-CwknaQYj.mjs} +53 -20
- package/dist/{build-plan-B7SZsc2N.mjs → eas-fallback-CSgAulr5.mjs} +41 -214
- package/dist/{watchman-CPQFZLXY.mjs → eas-session-ledger-DlY_serQ.mjs} +230 -11
- package/dist/{error-diagnostics-BR677IDM.mjs → error-diagnostics-DBWO2rxE.mjs} +172 -82
- package/dist/exec-DEoAhcze.mjs +858 -0
- package/dist/exec-DnYc4HGH.d.mts +78 -0
- package/dist/{gc-qWOMdnER.mjs → gc-CXxN-4SE.mjs} +1091 -1029
- package/dist/gc-DnNDQyaP.mjs +3 -0
- package/dist/{guide-G9cAbVAc.mjs → guide-Br0LEfKy.mjs} +1165 -297
- package/dist/{hosted-android-C3MHGld1.mjs → hosted-android-B-9f-jkd.mjs} +10 -8
- package/dist/{hosted-client-ZEKpS9vw.mjs → hosted-client-DZAPrcro.mjs} +34 -19
- package/dist/{hosted-ios-l-o3iM9J.mjs → hosted-ios-CsCS21hn.mjs} +1 -1
- package/dist/{hosted-logs-EzQM7-3Z.mjs → hosted-logs-FIRx9X2f.mjs} +77 -43
- package/dist/{hosted-macos-BACVAVqE.mjs → hosted-macos-_awYSpfv.mjs} +35 -22
- package/dist/{hosted-native-A4s1QPXe.mjs → hosted-native-BdzE668-.mjs} +49 -27
- package/dist/idle-C4cZ757K.d.mts +24 -0
- package/dist/{idle-shutdown-DtxhPTKe.mjs → idle-shutdown-DDg3SdvY.mjs} +11 -10
- package/dist/ios-CDvlmUs7.d.mts +24 -0
- package/dist/{ios-BwVCF7oA.mjs → ios-Ds1clbIt.mjs} +8 -8
- package/dist/{ios-device-D7pi2Sca.mjs → ios-device--h_-8ENa.mjs} +51 -26
- package/dist/{ios-device-B5veSDDQ.mjs → ios-device-BXZ0c7Kb.mjs} +1 -1
- package/dist/{ios-RkW4pnQf.mjs → ios-hcBpnEGk.mjs} +200 -93
- package/dist/{ios-Ce7bc7br.mjs → ios-pm4nL6By.mjs} +160 -108
- package/dist/{ios-project-K9hY_Jab.mjs → ios-project-CZhKODF3.mjs} +13 -13
- package/dist/ios-signing-BtAffm0A.mjs +489 -0
- package/dist/{ios-state-CBLe1xYw.mjs → ios-state-Dtw5K2aI.mjs} +1 -1
- package/dist/{ios-nOLJGVdy.mjs → ios-xtlRHaeB.mjs} +1 -1
- package/dist/{js-swap-Bb3nsS07.mjs → js-swap-Bwhh4S7V.mjs} +30 -25
- package/dist/{launch-C3qJ6Agb.mjs → launch-BjxemNpK.mjs} +85 -543
- package/dist/{launch-F4sOqAhB.mjs → launch-CCzXlc8r.mjs} +91 -90
- package/dist/logs-BfwwadsZ.mjs +479 -0
- package/dist/logs-jTS_lHSo.mjs +248 -0
- package/dist/{macos-D7uDvO-z.mjs → macos-DVlSSyUg.mjs} +1 -1
- package/dist/macos-NfV2D7dO.mjs +694 -0
- package/dist/macos-run.mjs +1 -1
- package/dist/maintenance-run.mjs +123 -248
- package/dist/{metro-DnCEjCxs.mjs → metro-DiXtA3Ty.mjs} +107 -30
- package/dist/metro-gateway-CKZqKqx7.mjs +209 -0
- package/dist/{named-ports-4WopRPg-.mjs → named-ports-DkEzOfzO.mjs} +42 -90
- package/dist/native-android-CqgnOgsT.mjs +645 -0
- package/dist/native-gradle-artifact-inputs-DHFnmrVf.mjs +270 -0
- package/dist/native-gradle-inputs-Dnh84Zbd.mjs +211 -0
- package/dist/native-inputs-TRTTTRxt.mjs +91 -0
- package/dist/native-run-NwUuxbkg.mjs +276 -0
- package/dist/{native-runtime-k8dTIrbK.mjs → native-runtime-B7KIafpM.mjs} +11 -9
- package/dist/native-source-Y0yLhFyQ.mjs +133 -0
- package/dist/{native-xcode-inputs-CykopJdM.mjs → native-xcode-inputs-D_VOfFL7.mjs} +26 -18
- package/dist/{native-xcode-ios-Bbf30Gm0.mjs → native-xcode-ios-BYDOHWLN.mjs} +104 -60
- package/dist/{ndjson-GOnbyvso.mjs → ndjson-CgE_o3Dl.mjs} +3 -3
- package/dist/offload-worker.d.mts +59 -41
- package/dist/offload-worker.mjs +478 -115
- package/dist/operation-exec-BW0em61G.mjs +171 -0
- package/dist/{ownership-DCtw_2IA.mjs → ownership-C5fo5Edb.mjs} +3 -3
- package/dist/{page-DRHy329N.mjs → page-DBL2PiUU.mjs} +12 -5
- package/dist/paths-BsJMoPP2.mjs +12 -0
- package/dist/paths-DQtTgsBf.mjs +42 -0
- package/dist/{placement-log-MOfPVgaM.mjs → placement-log-BnGgJRRZ.mjs} +5 -5
- package/dist/{plan-placement-V0TdzYXp.mjs → plan-placement-DIsMtN-d.mjs} +15 -11
- package/dist/{ports-DdSUicVo.mjs → ports-Cy1RkmuQ.mjs} +3 -3
- package/dist/prebuild-D4JoEAEs.mjs +484 -0
- package/dist/{project-_phNIJfs.mjs → project-wM_XFTvE.mjs} +65 -37
- package/dist/{pull-request-CQ8sPbZa.mjs → pull-request-W1IuLXDt.mjs} +102 -20
- package/dist/pull-request-eODyIqZF.d.mts +124 -0
- package/dist/pull-requests.d.mts +2 -120
- package/dist/pull-requests.mjs +2 -2
- package/dist/{react-native-android-CM1XRDwv.mjs → react-native-android-6OZ7MSM7.mjs} +121 -72
- package/dist/{gradle-DSrXb6lG.mjs → react-native-build-Dvd8hC21.mjs} +292 -15
- package/dist/react-native-doctor-DsoSF1Y9.mjs +234 -0
- package/dist/{react-native-ios-Dhq_eiYQ.mjs → react-native-ios-4u1Rn-GR.mjs} +71 -39
- package/dist/{recordings-D0d5aQt0.mjs → recordings-CQmfzAh7.mjs} +12 -9
- package/dist/registration-BcRgF6Ox.mjs +51 -0
- package/dist/{reload-C8JhxjSh.mjs → reload-BzkYabB-.mjs} +94 -47
- package/dist/reload-D7AVlb8N.mjs +2 -0
- package/dist/{remote-BiR6aYjy.mjs → remote-DjGDmlTZ.mjs} +26 -18
- package/dist/result-D2Ykz_iD.mjs +435 -0
- package/dist/{run-BtPgpKks.mjs → run-DidHghD1.mjs} +5 -5
- package/dist/selection-DSMbWEX2.mjs +620 -0
- package/dist/{server-bare-R2m_gsH8.mjs → server-bare-CafzuyFB.mjs} +3 -4
- package/dist/{server-command-CTtCkmcQ.mjs → server-command-C6QjeupS.mjs} +14 -7
- package/dist/{server-expo-DsguMGUF.mjs → server-expo-CrjB29pq.mjs} +54 -11
- package/dist/server-expo-D58c9L0M.mjs +2 -0
- package/dist/{settings-B717odTD.mjs → settings-C7O8A6ZI.mjs} +309 -119
- package/dist/settings-DpR-1Wnn.mjs +114 -0
- package/dist/settings-write-CzD60rOD.mjs +360 -0
- package/dist/settings.schema.json +176 -16
- package/dist/{simslim-CCr3rE-A.mjs → simslim-BNckWpXi.mjs} +14 -12
- package/dist/{slot-launch-DPt0m9Nd.mjs → slot-launch-CbfmNgM6.mjs} +15 -20
- package/dist/{spawn-entry-Dcb7sDUz.mjs → spawn-entry-jw19m8Nl.mjs} +0 -1
- package/dist/stage-Bps5oius.mjs +200 -0
- package/dist/{start-TXeMmmO2.mjs → start-Br-oxqMD.mjs} +1 -1
- package/dist/start-EojN4WFz.mjs +1364 -0
- package/dist/{state-D1Icyjlu.mjs → state--smjFSTL.mjs} +55 -13
- package/dist/{state-CG_OFoaA.mjs → state-08I3hw3_.mjs} +3 -2
- package/dist/{stats-BoY5sEPU.mjs → stats-D3GerlFW.mjs} +7 -13
- package/dist/stats-report-BzaPrRm6.mjs +16 -0
- package/dist/{status-BTA7kKiQ.mjs → status-BRROykC8.mjs} +7 -5
- package/dist/status-EvrK72L2.mjs +2 -0
- package/dist/{status-WgFbkRzj.mjs → status-WBDajew2.mjs} +554 -452
- package/dist/{status-watch-C23ILtf9.mjs → status-watch-Bg_u-pwR.mjs} +222 -25
- package/dist/status-worker.d.mts +1 -0
- package/dist/status-worker.mjs +19 -0
- package/dist/stim-desktop-D5OGpYZM.mjs +112 -0
- package/dist/{stop-DR6VoDIk.mjs → stop-DTZ9uTw3.mjs} +2 -2
- package/dist/{stop-DPEhunlw.mjs → stop-Dky10AEJ.mjs} +33 -23
- package/dist/{stop-BNmBMi1F.mjs → stop-Mv6W9FAk.mjs} +137 -98
- package/dist/supervisor-run.d.mts +8 -17
- package/dist/supervisor-run.mjs +56 -28
- package/dist/{support-CwjbFs9H.mjs → support-CNioewsd.mjs} +14 -14
- package/dist/{support-DMTqj3Hm.mjs → support-yUiOjnVY.mjs} +20 -13
- package/dist/swiftpm-artifact-inputs-DFcGsXDP.mjs +153 -0
- package/dist/swiftpm-macos-BIak-Rxv.mjs +532 -0
- package/dist/toolchain-BY8X8HXx.mjs +2 -0
- package/dist/toolchain-DpJMHq0n.mjs +876 -0
- package/dist/{trigger-CigAYjeL.mjs → trigger-Cbyc41d_.mjs} +21 -6
- package/dist/trigger-yb_nFzPF.mjs +2 -0
- package/dist/{warm-progress-BuY-Fvfn.mjs → warm-progress-CA3TgT3-.mjs} +263 -156
- package/dist/web-CZ07gd77.mjs +2 -0
- package/dist/{web-BDBMxDpx.mjs → web-DKx6yoFA.mjs} +20 -14
- package/dist/web-run.mjs +13 -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-state-DJt_MMvf.mjs → workspace-state-U08dEzhG.mjs} +62 -58
- package/dist/{workspaces-C36s2jb9.mjs → workspaces-CpANmBlq.mjs} +1723 -1286
- package/dist/{worktree-CgvJYJ-Q.mjs → worktree-CHecZ4Oq.mjs} +1097 -547
- package/dist/worktree-ZqZVjD9K.mjs +2 -0
- package/dist/xcode-BXn9-xYx.mjs +896 -0
- package/package.json +7 -5
- package/shim/android-audio/Main.java +24 -0
- package/shim/android-audio/README.md +17 -0
- package/shim/android-audio.jar +0 -0
- 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/macos-Ch5VJmcS.mjs +0 -584
- package/dist/metro-gateway-CX9Xlkq2.mjs +0 -103
- package/dist/miss-reason-mKzZ4VvN.mjs +0 -238
- package/dist/native-android-D5qc3-_v.mjs +0 -226
- package/dist/native-gradle-inputs-BsLRrl7u.mjs +0 -349
- 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/settings-vk3mJGSm.d.mts +0 -13
- package/dist/spawn-claims-DVS5RkMS.mjs +0 -72
- package/dist/stage-KNTQopqv.mjs +0 -157
- package/dist/start-BWqzODpb.mjs +0 -1116
- package/dist/stim-desktop-BzBN2Em2.mjs +0 -63
- package/dist/swiftpm-macos-DRNVJWlb.mjs +0 -119
- 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,858 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { ambientContext, ambientEnv } from "@stim-cli/core";
|
|
4
|
+
import { createDebugLog, runId } from "@stim-cli/core/state";
|
|
5
|
+
import { basename as basename$1, delimiter as delimiter$1, resolve as resolve$1 } from "path";
|
|
6
|
+
import { execSync } from "child_process";
|
|
7
|
+
import spawn from "cross-spawn";
|
|
8
|
+
import which from "which";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
11
|
+
//#region \0rolldown/runtime.js
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
17
|
+
var __exportAll = (all, no_symbols) => {
|
|
18
|
+
let target = {};
|
|
19
|
+
for (var name in all) __defProp(target, name, {
|
|
20
|
+
get: all[name],
|
|
21
|
+
enumerable: true
|
|
22
|
+
});
|
|
23
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
24
|
+
return target;
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
28
|
+
key = keys[i];
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
30
|
+
get: ((k) => from[k]).bind(null, key),
|
|
31
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
37
|
+
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/ownership-claim.ts
|
|
40
|
+
var ownership_claim_exports = /* @__PURE__ */ __exportAll({});
|
|
41
|
+
import * as import__stim_cli_core_ownership_claim from "@stim-cli/core/ownership-claim";
|
|
42
|
+
__reExport(ownership_claim_exports, import__stim_cli_core_ownership_claim);
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/debug-log.ts
|
|
45
|
+
const debugLog = createDebugLog("cli", { base: () => ({ runId: runId() }) });
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/report-runtime.ts
|
|
48
|
+
const reports = /* @__PURE__ */ new WeakMap();
|
|
49
|
+
function reportSignal(context) {
|
|
50
|
+
return context && reports.has(context) ? context.signal : void 0;
|
|
51
|
+
}
|
|
52
|
+
function trackReportResource(context, closed, cancel, signal = context?.signal, cleanupFailure) {
|
|
53
|
+
const state = context && reports.get(context);
|
|
54
|
+
if (!context || !state || !signal) return;
|
|
55
|
+
const { pending } = state;
|
|
56
|
+
const abort = () => {
|
|
57
|
+
const cancelled = Promise.resolve().then(cancel);
|
|
58
|
+
pending.set(cancelled, cleanupFailure);
|
|
59
|
+
cancelled.then(() => pending.delete(cancelled), (error) => {
|
|
60
|
+
state.failure ??= error;
|
|
61
|
+
pending.delete(cancelled);
|
|
62
|
+
pending.delete(closed);
|
|
63
|
+
signal.removeEventListener("abort", abort);
|
|
64
|
+
state.abort(error);
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
pending.set(closed, cleanupFailure);
|
|
68
|
+
const settled = () => {
|
|
69
|
+
signal.removeEventListener("abort", abort);
|
|
70
|
+
pending.delete(closed);
|
|
71
|
+
};
|
|
72
|
+
closed.then(settled, (error) => {
|
|
73
|
+
state.failure ??= error;
|
|
74
|
+
settled();
|
|
75
|
+
state.abort(error);
|
|
76
|
+
});
|
|
77
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
78
|
+
if (signal.aborted) abort();
|
|
79
|
+
}
|
|
80
|
+
async function runReport(context, work, timeoutMs = 6e4) {
|
|
81
|
+
const controller = new AbortController();
|
|
82
|
+
const signal = AbortSignal.any([context.signal, controller.signal]);
|
|
83
|
+
const operation = {
|
|
84
|
+
...context,
|
|
85
|
+
signal,
|
|
86
|
+
output: ((stream, text) => {
|
|
87
|
+
if (!signal.aborted) context.output(stream, text);
|
|
88
|
+
})
|
|
89
|
+
};
|
|
90
|
+
const pending = /* @__PURE__ */ new Map();
|
|
91
|
+
const state = {
|
|
92
|
+
pending,
|
|
93
|
+
abort: (reason) => controller.abort(reason)
|
|
94
|
+
};
|
|
95
|
+
reports.set(operation, state);
|
|
96
|
+
const deadline = performance.now() + timeoutMs;
|
|
97
|
+
const expire = () => {
|
|
98
|
+
controller.abort(Object.assign(/* @__PURE__ */ new Error(`The report exceeded its ${timeoutMs / 1e3} second budget.`), { code: "STIM_REPORT_TIMEOUT" }));
|
|
99
|
+
};
|
|
100
|
+
const timer = setTimeout(expire, timeoutMs);
|
|
101
|
+
let rejectCancellation;
|
|
102
|
+
const cancelled = new Promise((_, reject) => {
|
|
103
|
+
rejectCancellation = reject;
|
|
104
|
+
});
|
|
105
|
+
const abort = () => rejectCancellation(signal.reason);
|
|
106
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
107
|
+
const outcome = await (async () => {
|
|
108
|
+
try {
|
|
109
|
+
signal.throwIfAborted();
|
|
110
|
+
const result = await Promise.race([work(operation), cancelled]);
|
|
111
|
+
if (performance.now() >= deadline) expire();
|
|
112
|
+
signal.throwIfAborted();
|
|
113
|
+
return { result };
|
|
114
|
+
} catch (error) {
|
|
115
|
+
return { error };
|
|
116
|
+
}
|
|
117
|
+
})().finally(async () => {
|
|
118
|
+
clearTimeout(timer);
|
|
119
|
+
signal.removeEventListener("abort", abort);
|
|
120
|
+
controller.abort();
|
|
121
|
+
const cleanupDeadline = performance.now() + 35e3;
|
|
122
|
+
const expireCleanup = () => {
|
|
123
|
+
state.failure ??= [...pending.values()].find((failure) => failure !== void 0) ?? Object.assign(/* @__PURE__ */ new Error("Report cleanup did not finish within 35 seconds."), {
|
|
124
|
+
code: "STIM_CLAIM_UNAVAILABLE",
|
|
125
|
+
reportCleanup: true
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
let cleanupTimer;
|
|
129
|
+
try {
|
|
130
|
+
await Promise.race([(async () => {
|
|
131
|
+
while (pending.size) await Promise.allSettled(pending.keys());
|
|
132
|
+
})(), new Promise((resolve) => {
|
|
133
|
+
cleanupTimer = setTimeout(() => {
|
|
134
|
+
expireCleanup();
|
|
135
|
+
resolve();
|
|
136
|
+
}, 35e3);
|
|
137
|
+
})]);
|
|
138
|
+
if (performance.now() >= cleanupDeadline) expireCleanup();
|
|
139
|
+
} finally {
|
|
140
|
+
clearTimeout(cleanupTimer);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
if ("failure" in state) throw state.failure;
|
|
144
|
+
if ("error" in outcome) throw outcome.error;
|
|
145
|
+
return outcome.result;
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/process-identity.ts
|
|
149
|
+
var process_identity_exports = /* @__PURE__ */ __exportAll({});
|
|
150
|
+
import * as import__stim_cli_core_process_identity from "@stim-cli/core/process-identity";
|
|
151
|
+
__reExport(process_identity_exports, import__stim_cli_core_process_identity);
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/engine/operation-state.ts
|
|
154
|
+
const states = /* @__PURE__ */ new WeakMap();
|
|
155
|
+
let detached;
|
|
156
|
+
function fresh() {
|
|
157
|
+
return {
|
|
158
|
+
cancelled: null,
|
|
159
|
+
runSignal: void 0,
|
|
160
|
+
declaring: /* @__PURE__ */ new Set(),
|
|
161
|
+
running: /* @__PURE__ */ new Set(),
|
|
162
|
+
refusal: null,
|
|
163
|
+
handled: false,
|
|
164
|
+
draining: false,
|
|
165
|
+
exitCleanups: /* @__PURE__ */ new Set(),
|
|
166
|
+
buildMachineFlag: void 0,
|
|
167
|
+
takesSignals: false,
|
|
168
|
+
abortOperation: void 0
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** The state of `context`'s operation; code that is not passed a context yet shares one state per process. */
|
|
172
|
+
function operationState(context) {
|
|
173
|
+
if (!context) return detached ??= fresh();
|
|
174
|
+
let state = states.get(context);
|
|
175
|
+
if (!state) {
|
|
176
|
+
state = fresh();
|
|
177
|
+
states.set(context, state);
|
|
178
|
+
}
|
|
179
|
+
return state;
|
|
180
|
+
}
|
|
181
|
+
/** Whether an abort reason asks the operation to terminate rather than interrupt it. */
|
|
182
|
+
function isTermination(reason) {
|
|
183
|
+
return reason === "SIGTERM";
|
|
184
|
+
}
|
|
185
|
+
/** Keeps asynchronous work unwinding on the CLI's first interrupt until its owned work has settled. */
|
|
186
|
+
async function withDrainingCancellation(context, signal, work) {
|
|
187
|
+
if (!context) return work();
|
|
188
|
+
const abort = () => {
|
|
189
|
+
const state = operationState(context);
|
|
190
|
+
state.handled = true;
|
|
191
|
+
if (!isTermination(context.signal.reason)) state.draining = true;
|
|
192
|
+
};
|
|
193
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
194
|
+
if (signal?.aborted) abort();
|
|
195
|
+
try {
|
|
196
|
+
return await work();
|
|
197
|
+
} finally {
|
|
198
|
+
signal?.removeEventListener("abort", abort);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/engine/spawn-claims.ts
|
|
203
|
+
/**
|
|
204
|
+
* Record every child `context`'s operation later starts through `spawnDeclared` on `claim` until
|
|
205
|
+
* `stopDeclaringSpawnsOn(context, claim)`.
|
|
206
|
+
*/
|
|
207
|
+
function declareSpawnsOn(context, claim) {
|
|
208
|
+
if (claim) operationState(context).declaring.add(claim);
|
|
209
|
+
}
|
|
210
|
+
function stopDeclaringSpawnsOn(context, claim) {
|
|
211
|
+
if (claim) operationState(context).declaring.delete(claim);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Start a child that every claim `context`'s operation passed to `declareSpawnsOn` records until it exits. The child keeps
|
|
215
|
+
* the caller's process group, so a terminal interrupt still reaches it; the claim follows the child
|
|
216
|
+
* itself. A claim that cannot be marked stops the spawn rather than letting it run unprotected. A claim
|
|
217
|
+
* records one child, so declared spawns must not overlap. `until: 'close'` also holds the declaration
|
|
218
|
+
* while a launcher's child retains its stdio pipes after the launcher exits. A promise holds the declaration until
|
|
219
|
+
* cleanup resolves; a rejection keeps the child record for recovery.
|
|
220
|
+
*/
|
|
221
|
+
function spawnDeclared(context, spawn, { until = "exit" } = {}) {
|
|
222
|
+
const { declaring, running, refusal } = operationState(context);
|
|
223
|
+
if (refusal !== null) throw new Error(refusal);
|
|
224
|
+
const claims = [...declaring];
|
|
225
|
+
if (claims.length === 0) return spawn();
|
|
226
|
+
const forget = () => {
|
|
227
|
+
for (const claim of claims) try {
|
|
228
|
+
(0, ownership_claim_exports.clearClaimChild)(claim);
|
|
229
|
+
} catch {}
|
|
230
|
+
};
|
|
231
|
+
let child;
|
|
232
|
+
try {
|
|
233
|
+
for (const claim of claims) (0, ownership_claim_exports.markClaimChildPending)(claim);
|
|
234
|
+
child = spawn();
|
|
235
|
+
} catch (error) {
|
|
236
|
+
forget();
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
const pid = child.pid;
|
|
240
|
+
if (pid === void 0) {
|
|
241
|
+
forget();
|
|
242
|
+
return child;
|
|
243
|
+
}
|
|
244
|
+
running.add(child);
|
|
245
|
+
const captured = (0, process_identity_exports.captureProcessIdentity)(pid);
|
|
246
|
+
if (captured.ok) for (const claim of claims) try {
|
|
247
|
+
(0, ownership_claim_exports.setClaimChild)(claim, {
|
|
248
|
+
pid,
|
|
249
|
+
processToken: captured.token
|
|
250
|
+
});
|
|
251
|
+
} catch {}
|
|
252
|
+
const settled = () => {
|
|
253
|
+
running.delete(child);
|
|
254
|
+
forget();
|
|
255
|
+
};
|
|
256
|
+
if (typeof until === "string") child.once(until, settled);
|
|
257
|
+
else until.then(settled, () => {});
|
|
258
|
+
return child;
|
|
259
|
+
}
|
|
260
|
+
/** Refuse every later `spawnDeclared` of `context`'s operation with `reason` until `allowDeclaredSpawns`. */
|
|
261
|
+
function refuseDeclaredSpawns(context, reason) {
|
|
262
|
+
operationState(context).refusal = reason;
|
|
263
|
+
}
|
|
264
|
+
function allowDeclaredSpawns(context) {
|
|
265
|
+
operationState(context).refusal = null;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Send `signal` to every child `context`'s operation started through `spawnDeclared` that has not exited; returns how
|
|
269
|
+
* many were signalled.
|
|
270
|
+
*/
|
|
271
|
+
function signalDeclaredSpawns(context, signal) {
|
|
272
|
+
let signalled = 0;
|
|
273
|
+
for (const child of operationState(context).running) {
|
|
274
|
+
if (child.exitCode !== null || child.signalCode !== null) continue;
|
|
275
|
+
try {
|
|
276
|
+
if (child.kill(signal)) signalled += 1;
|
|
277
|
+
} catch {}
|
|
278
|
+
}
|
|
279
|
+
return signalled;
|
|
280
|
+
}
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/engine/workspace-process-lock.ts
|
|
283
|
+
const DEFAULT_WAIT_MS = 6e4;
|
|
284
|
+
const POLL_MS = 25;
|
|
285
|
+
var WorkspaceProcessCleanupError = class extends Error {
|
|
286
|
+
code = "STIM_CLAIM_UNAVAILABLE";
|
|
287
|
+
claims;
|
|
288
|
+
remedy;
|
|
289
|
+
constructor(claims, message, remedy) {
|
|
290
|
+
super(`${message} Its ownership claims remain held at ${claims.map((claim) => claim.path).join(", ")}.`);
|
|
291
|
+
this.claims = claims;
|
|
292
|
+
this.remedy = `${remedy} After verifying no child remains, remove only these claims: ${claims.map((claim) => (0, ownership_claim_exports.claimRemoveCommand)(claim.path)).join("; ")}`;
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
function workspaceProcessLockError(err) {
|
|
296
|
+
const code = err?.code;
|
|
297
|
+
if (code === "STIM_LOCK_REFUSED") return "refused";
|
|
298
|
+
if (code === "STIM_LOCK_TIMEOUT") return "timeout";
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
function workspaceProcessLockPath(root, name, external) {
|
|
302
|
+
return external ? join(root, `${name}.lock`) : join(root, ".stim", `${name}.lock`);
|
|
303
|
+
}
|
|
304
|
+
async function withWorkspaceProcessLock(root, name, fn, { now = Date.now, signal, sleep = (ms) => setTimeout$1(ms, void 0, { signal }), waitMs = DEFAULT_WAIT_MS, ownerPurpose, details = {}, onHeld, rejectOwnerPurposes = [], external = false, declareSpawnsFor } = {}) {
|
|
305
|
+
const path = workspaceProcessLockPath(root, name, external);
|
|
306
|
+
const deadline = now() + waitMs;
|
|
307
|
+
for (;;) {
|
|
308
|
+
signal?.throwIfAborted();
|
|
309
|
+
const attempt = (0, ownership_claim_exports.tryAcquireClaim)({
|
|
310
|
+
root: path,
|
|
311
|
+
mode: "exclusive",
|
|
312
|
+
label: `${name} lock`,
|
|
313
|
+
details: ownerPurpose ? {
|
|
314
|
+
...details,
|
|
315
|
+
purpose: ownerPurpose
|
|
316
|
+
} : details
|
|
317
|
+
});
|
|
318
|
+
if (attempt.pending) (0, ownership_claim_exports.releaseClaim)(attempt.pending);
|
|
319
|
+
if (attempt.acquired) {
|
|
320
|
+
if (declareSpawnsFor) declareSpawnsOn(declareSpawnsFor, attempt.acquired);
|
|
321
|
+
let retained = false;
|
|
322
|
+
try {
|
|
323
|
+
return await fn(attempt.acquired);
|
|
324
|
+
} catch (cause) {
|
|
325
|
+
retained = cause instanceof WorkspaceProcessCleanupError && cause.claims.includes(attempt.acquired);
|
|
326
|
+
throw cause;
|
|
327
|
+
} finally {
|
|
328
|
+
if (declareSpawnsFor) stopDeclaringSpawnsOn(declareSpawnsFor, attempt.acquired);
|
|
329
|
+
if (!retained) (0, ownership_claim_exports.releaseClaim)(attempt.acquired);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const holder = attempt.held ?? attempt.waitingFor?.[0];
|
|
333
|
+
const purpose = holder?.details.purpose;
|
|
334
|
+
if (typeof purpose === "string" && rejectOwnerPurposes.includes(purpose)) {
|
|
335
|
+
const error = /* @__PURE__ */ new Error(`The ${name} lock at ${path} is held for ${purpose}.`);
|
|
336
|
+
error.code = "STIM_LOCK_REFUSED";
|
|
337
|
+
throw error;
|
|
338
|
+
}
|
|
339
|
+
if (holder && onHeld) await onHeld(holder);
|
|
340
|
+
if (now() >= deadline) {
|
|
341
|
+
const error = /* @__PURE__ */ new Error(`Timed out waiting for the ${name} lock at ${path}.`);
|
|
342
|
+
error.code = "STIM_LOCK_TIMEOUT";
|
|
343
|
+
throw error;
|
|
344
|
+
}
|
|
345
|
+
await sleep(POLL_MS);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/exec.ts
|
|
350
|
+
const MAX_BUFFER = 67108864;
|
|
351
|
+
function spawnReportProbe(file, args, opts, containProcessTree = false) {
|
|
352
|
+
if (process.platform !== "win32" || !containProcessTree && !reportSignal(ambientContext()) || !executableIn(file, opts.env ?? ambientEnv(), opts.cwd ?? process.cwd())) return spawn(file, args, opts);
|
|
353
|
+
const env = opts.env ?? ambientEnv();
|
|
354
|
+
const systemRoot = process.env.SystemRoot ?? process.env.SYSTEMROOT;
|
|
355
|
+
if (!systemRoot) throw new Error("SystemRoot is required to contain Windows report probes.");
|
|
356
|
+
return spawn(resolve$1(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe"), [
|
|
357
|
+
"-NoLogo",
|
|
358
|
+
"-NoProfile",
|
|
359
|
+
"-NonInteractive",
|
|
360
|
+
"-ExecutionPolicy",
|
|
361
|
+
"Bypass",
|
|
362
|
+
"-File",
|
|
363
|
+
fileURLToPath(new URL("../dist/windows-report.ps1", import.meta.url))
|
|
364
|
+
], {
|
|
365
|
+
...opts,
|
|
366
|
+
windowsHide: true,
|
|
367
|
+
env: {
|
|
368
|
+
...env,
|
|
369
|
+
STIM_REPORT_CHILD: JSON.stringify({
|
|
370
|
+
file,
|
|
371
|
+
args,
|
|
372
|
+
node: process.execPath,
|
|
373
|
+
entry: fileURLToPath(new URL("../dist/windows-report.mjs", import.meta.url))
|
|
374
|
+
})
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
function reportChild(child, signal, failed) {
|
|
379
|
+
const context = ambientContext();
|
|
380
|
+
const report = reportSignal(context);
|
|
381
|
+
signal ??= report;
|
|
382
|
+
if (!signal) return;
|
|
383
|
+
let rejectClosed;
|
|
384
|
+
let ended = false;
|
|
385
|
+
let finishNativeClose;
|
|
386
|
+
const nativeClosed = new Promise((resolve) => {
|
|
387
|
+
finishNativeClose = resolve;
|
|
388
|
+
});
|
|
389
|
+
const closed = new Promise((resolve, reject) => {
|
|
390
|
+
rejectClosed = reject;
|
|
391
|
+
child.once("close", () => {
|
|
392
|
+
ended = true;
|
|
393
|
+
finishNativeClose();
|
|
394
|
+
cancel().then(resolve, reject);
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
const pid = child.pid;
|
|
398
|
+
const captured = pid === void 0 ? null : (0, process_identity_exports.captureProcessIdentity)(pid);
|
|
399
|
+
const observe = () => {
|
|
400
|
+
if (pid === void 0) return "gone";
|
|
401
|
+
if (captured?.ok) return (0, process_identity_exports.inspectProcessIdentity)({
|
|
402
|
+
pid,
|
|
403
|
+
processToken: captured.token
|
|
404
|
+
});
|
|
405
|
+
if (process.platform === "win32") return ended ? "gone" : "unknown";
|
|
406
|
+
try {
|
|
407
|
+
process.kill(-pid, 0);
|
|
408
|
+
} catch (error) {
|
|
409
|
+
if (error instanceof Error && "code" in error && error.code === "ESRCH") return "gone";
|
|
410
|
+
}
|
|
411
|
+
return "unknown";
|
|
412
|
+
};
|
|
413
|
+
const refuse = (message) => {
|
|
414
|
+
const failure = Object.assign(new Error(message), {
|
|
415
|
+
code: "STIM_CLAIM_UNAVAILABLE",
|
|
416
|
+
reportCleanup: true
|
|
417
|
+
});
|
|
418
|
+
const error = failed?.(failure) ?? failure;
|
|
419
|
+
child.stdin?.destroy();
|
|
420
|
+
child.stdout?.destroy();
|
|
421
|
+
child.stderr?.destroy();
|
|
422
|
+
child.unref();
|
|
423
|
+
rejectClosed(error);
|
|
424
|
+
throw error;
|
|
425
|
+
};
|
|
426
|
+
let cancelled;
|
|
427
|
+
const cancel = () => cancelled ??= (async () => {
|
|
428
|
+
let identity = observe();
|
|
429
|
+
if (pid !== void 0) {
|
|
430
|
+
const deadline = performance.now() + 1e3;
|
|
431
|
+
while (identity === "unknown" && performance.now() < deadline) {
|
|
432
|
+
await setTimeout$1(50);
|
|
433
|
+
identity = observe();
|
|
434
|
+
}
|
|
435
|
+
if (identity === "unknown") refuse(`Cannot verify cleanup for report child ${pid}; its process or descendants were left untouched.`);
|
|
436
|
+
}
|
|
437
|
+
if (pid !== void 0 && captured?.ok && (identity === "same" || process.platform !== "win32" && identity === "gone")) {
|
|
438
|
+
if (process.platform === "win32") {
|
|
439
|
+
if (report) child.kill("SIGKILL");
|
|
440
|
+
else {
|
|
441
|
+
const killer = spawn("taskkill", [
|
|
442
|
+
"/PID",
|
|
443
|
+
String(pid),
|
|
444
|
+
"/T",
|
|
445
|
+
"/F"
|
|
446
|
+
], { stdio: "ignore" });
|
|
447
|
+
const timer = setTimeout(() => killer.kill("SIGKILL"), 5e3);
|
|
448
|
+
await new Promise((resolve) => {
|
|
449
|
+
killer.once("error", () => child.kill("SIGKILL"));
|
|
450
|
+
killer.once("close", (status) => {
|
|
451
|
+
if (status !== 0) child.kill("SIGKILL");
|
|
452
|
+
resolve();
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
clearTimeout(timer);
|
|
456
|
+
}
|
|
457
|
+
} else try {
|
|
458
|
+
process.kill(-pid, "SIGKILL");
|
|
459
|
+
} catch {
|
|
460
|
+
child.kill("SIGKILL");
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
child.stdin?.destroy();
|
|
464
|
+
child.stdout?.destroy();
|
|
465
|
+
child.stderr?.destroy();
|
|
466
|
+
if (!ended) {
|
|
467
|
+
let timer;
|
|
468
|
+
await Promise.race([nativeClosed, new Promise((resolve) => {
|
|
469
|
+
timer = setTimeout(resolve, 1e3);
|
|
470
|
+
})]);
|
|
471
|
+
clearTimeout(timer);
|
|
472
|
+
if (!ended) refuse(`Report child ${pid} did not close within the cleanup budget.`);
|
|
473
|
+
}
|
|
474
|
+
if (pid !== void 0 && process.platform !== "win32") {
|
|
475
|
+
const deadline = performance.now() + 1e3;
|
|
476
|
+
while ((0, ownership_claim_exports.processGroupAlive)(pid) && performance.now() < deadline) await setTimeout$1(25);
|
|
477
|
+
if ((0, ownership_claim_exports.processGroupAlive)(pid)) refuse(`Report child ${pid} still has descendants after cleanup.`);
|
|
478
|
+
}
|
|
479
|
+
})();
|
|
480
|
+
if (report) trackReportResource(context, closed, cancel, signal);
|
|
481
|
+
else {
|
|
482
|
+
const abort = () => {
|
|
483
|
+
cancel().catch(() => {});
|
|
484
|
+
};
|
|
485
|
+
const callerSignal = signal;
|
|
486
|
+
callerSignal.addEventListener("abort", abort, { once: true });
|
|
487
|
+
const settled = () => callerSignal.removeEventListener("abort", abort);
|
|
488
|
+
closed.then(settled, settled);
|
|
489
|
+
if (callerSignal.aborted) abort();
|
|
490
|
+
}
|
|
491
|
+
return {
|
|
492
|
+
cancel,
|
|
493
|
+
closed
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
function budgetMs(timeoutMs) {
|
|
497
|
+
if (timeoutMs === "unbounded") return void 0;
|
|
498
|
+
if (!(timeoutMs > 0)) throw new RangeError(`timeoutMs must be a positive number of milliseconds or 'unbounded', got ${timeoutMs}`);
|
|
499
|
+
return timeoutMs;
|
|
500
|
+
}
|
|
501
|
+
/** Whether an exec error is a child killed for exceeding its `timeoutMs`. */
|
|
502
|
+
function isTimeoutError(error) {
|
|
503
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "ETIMEDOUT";
|
|
504
|
+
}
|
|
505
|
+
function nameTimeout(error, command, timeoutMs) {
|
|
506
|
+
if (error?.code === "ETIMEDOUT" && error instanceof Error) error.message = `Command timed out after ${timeoutMs}ms: ${command}`;
|
|
507
|
+
return error;
|
|
508
|
+
}
|
|
509
|
+
const WINDOWS_BATCH_FILE = /\.(?:bat|cmd)$/i;
|
|
510
|
+
const BATCH_UNSAFE_ARGUMENT = /["\r\n]/;
|
|
511
|
+
function isUnsafeBatchSpawn(target, args, platform = process.platform) {
|
|
512
|
+
return platform === "win32" && WINDOWS_BATCH_FILE.test(target) && args.some((arg) => BATCH_UNSAFE_ARGUMENT.test(arg));
|
|
513
|
+
}
|
|
514
|
+
function executableIn(file, env, cwd) {
|
|
515
|
+
const windows = process.platform === "win32";
|
|
516
|
+
const value = (name) => env[name] ?? (windows ? Object.entries(env).find(([key, field]) => field !== void 0 && key.toUpperCase() === name)?.[1] : void 0);
|
|
517
|
+
const directory = typeof cwd === "string" ? cwd : fileURLToPath(cwd);
|
|
518
|
+
const path = file.includes("/") || windows && file.includes("\\");
|
|
519
|
+
const directories = path ? [""] : (value("PATH") ?? "").split(delimiter$1);
|
|
520
|
+
if (windows && !path) directories.unshift(directory);
|
|
521
|
+
for (const entry of directories) {
|
|
522
|
+
const candidate = resolve$1(directory, entry.replace(/^"(.*)"$/, "$1"), file);
|
|
523
|
+
const found = which.sync(candidate, {
|
|
524
|
+
nothrow: true,
|
|
525
|
+
path: "",
|
|
526
|
+
pathExt: value("PATHEXT") ?? ""
|
|
527
|
+
});
|
|
528
|
+
if (found) return found;
|
|
529
|
+
}
|
|
530
|
+
return null;
|
|
531
|
+
}
|
|
532
|
+
function refuseUnsafeBatchArguments(file, args, env = ambientEnv(), cwd = ambientContext()?.cwd ?? process.cwd()) {
|
|
533
|
+
if (process.platform !== "win32") return;
|
|
534
|
+
const target = executableIn(file, env, cwd) ?? file;
|
|
535
|
+
if (isUnsafeBatchSpawn(target, args)) throw new Error(`Refusing to run ${basename$1(target)}: an argument contains a character cmd.exe could misinterpret (a double quote or a line break).`);
|
|
536
|
+
}
|
|
537
|
+
function redactError(error, values) {
|
|
538
|
+
const secrets = values?.filter(Boolean) ?? [];
|
|
539
|
+
if (secrets.length === 0 || !error || typeof error !== "object") return error;
|
|
540
|
+
const scrub = (text) => secrets.reduce((acc, secret) => acc.split(secret).join("***"), text);
|
|
541
|
+
const fields = error;
|
|
542
|
+
for (const key of Object.getOwnPropertyNames(error)) {
|
|
543
|
+
const value = fields[key];
|
|
544
|
+
if (typeof value === "string") fields[key] = scrub(value);
|
|
545
|
+
else if (Array.isArray(value)) fields[key] = value.map((item) => typeof item === "string" ? scrub(item) : item);
|
|
546
|
+
}
|
|
547
|
+
return error;
|
|
548
|
+
}
|
|
549
|
+
const defaultExecutor = {
|
|
550
|
+
reportSignal: () => reportSignal(ambientContext()),
|
|
551
|
+
run(cmd, { timeoutMs, killSignal, cwd, env }) {
|
|
552
|
+
const opts = {
|
|
553
|
+
encoding: "utf-8",
|
|
554
|
+
stdio: [
|
|
555
|
+
"pipe",
|
|
556
|
+
"pipe",
|
|
557
|
+
"pipe"
|
|
558
|
+
],
|
|
559
|
+
maxBuffer: MAX_BUFFER
|
|
560
|
+
};
|
|
561
|
+
const timeout = budgetMs(timeoutMs);
|
|
562
|
+
if (timeout !== void 0) opts.timeout = timeout;
|
|
563
|
+
if (killSignal) opts.killSignal = killSignal;
|
|
564
|
+
const childCwd = cwd ?? ambientContext()?.cwd;
|
|
565
|
+
if (childCwd) opts.cwd = childCwd;
|
|
566
|
+
if (env || ambientContext()) opts.env = {
|
|
567
|
+
...ambientEnv(),
|
|
568
|
+
...env
|
|
569
|
+
};
|
|
570
|
+
try {
|
|
571
|
+
return String(execSync(cmd, opts)).trim();
|
|
572
|
+
} catch (error) {
|
|
573
|
+
throw nameTimeout(error, cmd, timeoutMs);
|
|
574
|
+
}
|
|
575
|
+
},
|
|
576
|
+
runFile(file, args = [], { timeoutMs, killSignal, cwd, env, omitEnv, input, untrimmed, rejectStderr, detachedSilent, redact }) {
|
|
577
|
+
const opts = {
|
|
578
|
+
encoding: "utf-8",
|
|
579
|
+
stdio: detachedSilent ? "ignore" : [
|
|
580
|
+
"pipe",
|
|
581
|
+
"pipe",
|
|
582
|
+
"pipe"
|
|
583
|
+
],
|
|
584
|
+
maxBuffer: MAX_BUFFER
|
|
585
|
+
};
|
|
586
|
+
if (detachedSilent) opts.detached = true;
|
|
587
|
+
const timeout = budgetMs(timeoutMs);
|
|
588
|
+
if (timeout !== void 0) opts.timeout = timeout;
|
|
589
|
+
if (killSignal) opts.killSignal = killSignal;
|
|
590
|
+
const childCwd = cwd ?? ambientContext()?.cwd;
|
|
591
|
+
if (childCwd) opts.cwd = childCwd;
|
|
592
|
+
if (input !== void 0) opts.input = input;
|
|
593
|
+
if (env || omitEnv?.length || ambientContext()) {
|
|
594
|
+
const childEnv = {
|
|
595
|
+
...ambientEnv(),
|
|
596
|
+
...env
|
|
597
|
+
};
|
|
598
|
+
for (const key of omitEnv ?? []) delete childEnv[key];
|
|
599
|
+
opts.env = childEnv;
|
|
600
|
+
}
|
|
601
|
+
refuseUnsafeBatchArguments(file, args, opts.env, opts.cwd);
|
|
602
|
+
const result = spawn.sync(file, args, opts);
|
|
603
|
+
if (result.error) throw redactError(nameTimeout(Object.assign(result.error, result), [file, ...args].join(" "), timeoutMs), redact);
|
|
604
|
+
if (result.status !== 0 || rejectStderr && String(result.stderr ?? "").trim()) {
|
|
605
|
+
const stderr = String(result.stderr ?? "");
|
|
606
|
+
const message = `Command failed: ${[file, ...args].join(" ")}${stderr ? `\n${stderr}` : ""}`;
|
|
607
|
+
throw redactError(Object.assign(new Error(message), result), redact);
|
|
608
|
+
}
|
|
609
|
+
if (detachedSilent) return "";
|
|
610
|
+
return untrimmed ? String(result.stdout) : String(result.stdout).trim();
|
|
611
|
+
},
|
|
612
|
+
runFileAsync(file, args = [], { timeoutMs, killSignal, cwd, env, omitEnv, input, untrimmed, rejectStderr, onSpawn, declareFor, detachedSilent, containProcessTree, cleanupOnExit, redact, signal: callSignal }) {
|
|
613
|
+
const command = [file, ...args].join(" ");
|
|
614
|
+
return new Promise((resolve, reject) => {
|
|
615
|
+
const report = callSignal ?? reportSignal(ambientContext());
|
|
616
|
+
report?.throwIfAborted();
|
|
617
|
+
const timeout = budgetMs(timeoutMs);
|
|
618
|
+
const opts = detachedSilent ? {
|
|
619
|
+
stdio: "ignore",
|
|
620
|
+
detached: true
|
|
621
|
+
} : { stdio: [
|
|
622
|
+
input === void 0 ? "ignore" : "pipe",
|
|
623
|
+
"pipe",
|
|
624
|
+
"pipe"
|
|
625
|
+
] };
|
|
626
|
+
if (report && process.platform !== "win32") opts.detached = true;
|
|
627
|
+
const childCwd = cwd ?? ambientContext()?.cwd;
|
|
628
|
+
if (childCwd) opts.cwd = childCwd;
|
|
629
|
+
if (env || omitEnv?.length || ambientContext()) {
|
|
630
|
+
const childEnv = {
|
|
631
|
+
...ambientEnv(),
|
|
632
|
+
...env
|
|
633
|
+
};
|
|
634
|
+
for (const key of omitEnv ?? []) delete childEnv[key];
|
|
635
|
+
opts.env = childEnv;
|
|
636
|
+
}
|
|
637
|
+
refuseUnsafeBatchArguments(file, args, opts.env, opts.cwd);
|
|
638
|
+
const claims = declareFor ? [...operationState(declareFor).declaring] : [];
|
|
639
|
+
let clearDeclaration;
|
|
640
|
+
let retainDeclaration;
|
|
641
|
+
const declaration = claims.length > 0 && report ? new Promise((resolveDeclaration, rejectDeclaration) => {
|
|
642
|
+
clearDeclaration = resolveDeclaration;
|
|
643
|
+
retainDeclaration = rejectDeclaration;
|
|
644
|
+
}) : void 0;
|
|
645
|
+
const start = () => spawnReportProbe(file, args, opts, containProcessTree || Boolean(report));
|
|
646
|
+
const child = declareFor ? spawnDeclared(declareFor, start, declaration ? { until: declaration } : {}) : start();
|
|
647
|
+
let lifetime;
|
|
648
|
+
let cancel;
|
|
649
|
+
let timer;
|
|
650
|
+
try {
|
|
651
|
+
lifetime = reportChild(child, report, (error) => {
|
|
652
|
+
const failure = claims.length ? Object.assign(new WorkspaceProcessCleanupError(claims, error.message, "Verify the child and its descendants have stopped."), { reportCleanup: true }) : error;
|
|
653
|
+
clearTimeout(timer);
|
|
654
|
+
return failure;
|
|
655
|
+
});
|
|
656
|
+
cancel = lifetime?.cancel;
|
|
657
|
+
if (cleanupOnExit && cancel) child.once("exit", () => {
|
|
658
|
+
clearTimeout(timer);
|
|
659
|
+
cancel?.().catch(reject);
|
|
660
|
+
});
|
|
661
|
+
lifetime?.closed.catch(reject);
|
|
662
|
+
if (declaration) lifetime?.closed.then(clearDeclaration, retainDeclaration);
|
|
663
|
+
onSpawn?.(child);
|
|
664
|
+
} catch (error) {
|
|
665
|
+
if (cancel) cancel().then(() => lifetime?.closed).then(() => reject(error), reject);
|
|
666
|
+
else {
|
|
667
|
+
if (!report) child.kill("SIGKILL");
|
|
668
|
+
reject(error);
|
|
669
|
+
}
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
if (input !== void 0) {
|
|
673
|
+
child.stdin?.on("error", () => {});
|
|
674
|
+
child.stdin?.end(input);
|
|
675
|
+
}
|
|
676
|
+
const stdout = [];
|
|
677
|
+
const stderr = [];
|
|
678
|
+
let timedOut = false;
|
|
679
|
+
let overflowed = false;
|
|
680
|
+
let bufferedBytes = 0;
|
|
681
|
+
const capture = (chunks, chunk) => {
|
|
682
|
+
if (overflowed) return;
|
|
683
|
+
const remaining = MAX_BUFFER - bufferedBytes;
|
|
684
|
+
if (chunk.length <= remaining) {
|
|
685
|
+
chunks.push(chunk);
|
|
686
|
+
bufferedBytes += chunk.length;
|
|
687
|
+
} else {
|
|
688
|
+
if (remaining > 0) chunks.push(chunk.subarray(0, remaining));
|
|
689
|
+
bufferedBytes = MAX_BUFFER;
|
|
690
|
+
overflowed = true;
|
|
691
|
+
if (cancel) cancel().catch(reject);
|
|
692
|
+
else {
|
|
693
|
+
child.kill("SIGKILL");
|
|
694
|
+
child.stdin?.destroy();
|
|
695
|
+
child.stdout?.destroy();
|
|
696
|
+
child.stderr?.destroy();
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
timer = timeout === void 0 ? void 0 : setTimeout(() => {
|
|
701
|
+
timedOut = true;
|
|
702
|
+
if (cancel) cancel().catch(reject);
|
|
703
|
+
else {
|
|
704
|
+
child.kill(killSignal ?? "SIGTERM");
|
|
705
|
+
child.stdin?.destroy();
|
|
706
|
+
child.stdout?.destroy();
|
|
707
|
+
child.stderr?.destroy();
|
|
708
|
+
}
|
|
709
|
+
}, timeout);
|
|
710
|
+
child.stdout?.on("data", (chunk) => capture(stdout, chunk));
|
|
711
|
+
child.stderr?.on("data", (chunk) => capture(stderr, chunk));
|
|
712
|
+
child.on("error", (error) => {
|
|
713
|
+
clearTimeout(timer);
|
|
714
|
+
reject(redactError(error, redact));
|
|
715
|
+
});
|
|
716
|
+
const finish = async (status, signal) => {
|
|
717
|
+
clearTimeout(timer);
|
|
718
|
+
await lifetime?.closed;
|
|
719
|
+
const discardOutput = (timedOut || overflowed || report?.aborted) && redact?.some(Boolean);
|
|
720
|
+
const out = discardOutput ? "" : Buffer.concat(stdout).toString("utf-8");
|
|
721
|
+
const err = discardOutput ? "" : Buffer.concat(stderr).toString("utf-8");
|
|
722
|
+
const result = {
|
|
723
|
+
status,
|
|
724
|
+
signal,
|
|
725
|
+
stdout: out,
|
|
726
|
+
stderr: err
|
|
727
|
+
};
|
|
728
|
+
if (report?.aborted) reject(report.reason);
|
|
729
|
+
else if (timedOut) reject(redactError(nameTimeout(Object.assign(new Error(command), result, { code: "ETIMEDOUT" }), command, timeoutMs), redact));
|
|
730
|
+
else if (overflowed) reject(redactError(Object.assign(/* @__PURE__ */ new Error(`Command output exceeded ${MAX_BUFFER} bytes: ${command}`), result, { code: "ENOBUFS" }), redact));
|
|
731
|
+
else if (status !== 0 || rejectStderr && err.trim()) reject(redactError(Object.assign(/* @__PURE__ */ new Error(`Command failed: ${command}${err ? `\n${err}` : ""}`), result), redact));
|
|
732
|
+
else resolve(detachedSilent ? "" : untrimmed ? out : out.trim());
|
|
733
|
+
};
|
|
734
|
+
child.on("close", (status, signal) => {
|
|
735
|
+
finish(status, signal).catch(reject);
|
|
736
|
+
});
|
|
737
|
+
});
|
|
738
|
+
},
|
|
739
|
+
runQuiet(cmd, opts) {
|
|
740
|
+
budgetMs(opts.timeoutMs);
|
|
741
|
+
try {
|
|
742
|
+
return this.run(cmd, opts);
|
|
743
|
+
} catch {
|
|
744
|
+
return null;
|
|
745
|
+
}
|
|
746
|
+
},
|
|
747
|
+
runFileQuiet(file, args, opts) {
|
|
748
|
+
budgetMs(opts.timeoutMs);
|
|
749
|
+
try {
|
|
750
|
+
return this.runFile(file, args, opts);
|
|
751
|
+
} catch {
|
|
752
|
+
return null;
|
|
753
|
+
}
|
|
754
|
+
},
|
|
755
|
+
runFileQuietAsync(file, args, opts) {
|
|
756
|
+
budgetMs(opts.timeoutMs);
|
|
757
|
+
return this.runFileAsync(file, args, opts).catch(() => null);
|
|
758
|
+
},
|
|
759
|
+
spawn(cmd, args = [], opts = {}) {
|
|
760
|
+
const report = reportSignal(ambientContext());
|
|
761
|
+
report?.throwIfAborted();
|
|
762
|
+
const context = ambientContext();
|
|
763
|
+
const childOpts = context ? {
|
|
764
|
+
...opts,
|
|
765
|
+
cwd: opts.cwd ?? context.cwd,
|
|
766
|
+
env: opts.env ?? context.env
|
|
767
|
+
} : opts;
|
|
768
|
+
if (report && process.platform !== "win32") childOpts.detached = true;
|
|
769
|
+
refuseUnsafeBatchArguments(cmd, args, childOpts.env ?? ambientEnv(), childOpts.cwd);
|
|
770
|
+
const claims = report ? [...operationState(context).declaring] : [];
|
|
771
|
+
const child = spawnReportProbe(cmd, args, childOpts);
|
|
772
|
+
reportChild(child, void 0, (error) => claims.length ? Object.assign(new WorkspaceProcessCleanupError(claims, error.message, "Verify the child and its descendants have stopped."), { reportCleanup: true }) : error);
|
|
773
|
+
return child;
|
|
774
|
+
},
|
|
775
|
+
findExecutable(name, options = {}) {
|
|
776
|
+
return executableIn(name, options.env ?? ambientEnv(), options.cwd ?? ambientContext()?.cwd ?? process.cwd());
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
/** The program a call runs, without its arguments: those can carry tokens. */
|
|
780
|
+
const programOf = (command) => basename$1(command.trim().split(/\s+/)[0] ?? "");
|
|
781
|
+
function outcomeOf(error) {
|
|
782
|
+
const { status, signal, code } = error ?? {};
|
|
783
|
+
return {
|
|
784
|
+
ok: false,
|
|
785
|
+
...typeof status === "number" ? { exit: status } : {},
|
|
786
|
+
...signal ? { signal } : {},
|
|
787
|
+
...code ? { code } : {}
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
let executionId = 0;
|
|
791
|
+
function timedSync(fn, program) {
|
|
792
|
+
return (...args) => {
|
|
793
|
+
if (!debugLog.enabled()) return fn(...args);
|
|
794
|
+
const id = ++executionId;
|
|
795
|
+
const name = program(...args);
|
|
796
|
+
const started = performance.now();
|
|
797
|
+
debugLog.log("exec.start", {
|
|
798
|
+
program: name,
|
|
799
|
+
executionId: id
|
|
800
|
+
});
|
|
801
|
+
try {
|
|
802
|
+
const out = fn(...args);
|
|
803
|
+
debugLog.log("exec", {
|
|
804
|
+
program: name,
|
|
805
|
+
executionId: id,
|
|
806
|
+
ms: Math.round(performance.now() - started),
|
|
807
|
+
ok: true
|
|
808
|
+
});
|
|
809
|
+
return out;
|
|
810
|
+
} catch (error) {
|
|
811
|
+
debugLog.log("exec", {
|
|
812
|
+
program: name,
|
|
813
|
+
executionId: id,
|
|
814
|
+
ms: Math.round(performance.now() - started),
|
|
815
|
+
...outcomeOf(error)
|
|
816
|
+
});
|
|
817
|
+
throw error;
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
let active = {
|
|
822
|
+
...defaultExecutor,
|
|
823
|
+
run: timedSync((cmd, opts) => defaultExecutor.run(cmd, opts), programOf),
|
|
824
|
+
runFile: timedSync((file, args, opts) => defaultExecutor.runFile(file, args, opts), (file) => basename$1(file)),
|
|
825
|
+
async runFileAsync(file, args, opts) {
|
|
826
|
+
if (!debugLog.enabled()) return defaultExecutor.runFileAsync(file, args, opts);
|
|
827
|
+
const id = ++executionId;
|
|
828
|
+
const name = basename$1(file);
|
|
829
|
+
const started = performance.now();
|
|
830
|
+
debugLog.log("exec.start", {
|
|
831
|
+
program: name,
|
|
832
|
+
executionId: id
|
|
833
|
+
});
|
|
834
|
+
try {
|
|
835
|
+
const out = await defaultExecutor.runFileAsync(file, args, opts);
|
|
836
|
+
debugLog.log("exec", {
|
|
837
|
+
program: name,
|
|
838
|
+
executionId: id,
|
|
839
|
+
ms: Math.round(performance.now() - started),
|
|
840
|
+
ok: true
|
|
841
|
+
});
|
|
842
|
+
return out;
|
|
843
|
+
} catch (error) {
|
|
844
|
+
debugLog.log("exec", {
|
|
845
|
+
program: name,
|
|
846
|
+
executionId: id,
|
|
847
|
+
ms: Math.round(performance.now() - started),
|
|
848
|
+
...outcomeOf(error)
|
|
849
|
+
});
|
|
850
|
+
throw error;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
function getExecutor() {
|
|
855
|
+
return active;
|
|
856
|
+
}
|
|
857
|
+
//#endregion
|
|
858
|
+
export { __require as C, __commonJSMin as S, reportSignal as _, workspaceProcessLockError as a, debugLog as b, declareSpawnsOn as c, spawnDeclared as d, stopDeclaringSpawnsOn as f, process_identity_exports as g, withDrainingCancellation as h, withWorkspaceProcessLock as i, refuseDeclaredSpawns as l, operationState as m, isTimeoutError as n, workspaceProcessLockPath as o, isTermination as p, WorkspaceProcessCleanupError as r, allowDeclaredSpawns as s, getExecutor as t, signalDeclaredSpawns as u, runReport as v, ownership_claim_exports as x, trackReportResource as y };
|