token-goat 2.9.26 → 2.9.29
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 +30 -88
- package/SECURITY.md +14 -0
- package/dist/{token-goat-chunk-OZRSREKR.mjs → token-goat-chunk-2AWQ2R5X.mjs} +2 -2
- package/dist/{token-goat-chunk-BH4ZVRB2.mjs → token-goat-chunk-2NNUA2LR.mjs} +4 -4
- package/dist/token-goat-chunk-2WOUYWLM.mjs +955 -0
- package/dist/{token-goat-chunk-IKZLSRII.mjs → token-goat-chunk-435UQTKD.mjs} +5 -3
- package/dist/{token-goat-chunk-62IHOU6L.mjs → token-goat-chunk-44BM7DDQ.mjs} +5 -3
- package/dist/token-goat-chunk-52NSDWYY.mjs +96 -0
- package/dist/{token-goat-chunk-CXBOFPF4.mjs → token-goat-chunk-67BNIKKO.mjs} +32 -18
- package/dist/{token-goat-chunk-XBESNWEX.mjs → token-goat-chunk-6AK46ZT7.mjs} +2 -3
- package/dist/{token-goat-chunk-7SXPJOSZ.mjs → token-goat-chunk-7CPMDFGB.mjs} +166 -40
- package/dist/token-goat-chunk-ASLWOQ3I.mjs +14 -0
- package/dist/{token-goat-chunk-MWID3YOY.mjs → token-goat-chunk-BGYOZ6DO.mjs} +6 -4
- package/dist/{token-goat-chunk-PAV6NNY7.mjs → token-goat-chunk-C5YPNZKQ.mjs} +22 -8
- package/dist/{token-goat-chunk-D2X7XN5M.mjs → token-goat-chunk-CIQ2FTY3.mjs} +23 -242
- package/dist/token-goat-chunk-D4ETHJD6.mjs +246 -0
- package/dist/{token-goat-chunk-7Y6GWTII.mjs → token-goat-chunk-DNRPXHYH.mjs} +25 -17
- package/dist/{token-goat-chunk-L43RKNHA.mjs → token-goat-chunk-DNSPXQXQ.mjs} +2 -2
- package/dist/token-goat-chunk-DPNLUJWB.mjs +220 -0
- package/dist/token-goat-chunk-E4ZOJIZK.mjs +1382 -0
- package/dist/token-goat-chunk-E5TK5DNO.mjs +718 -0
- package/dist/{token-goat-chunk-VVROQBQJ.mjs → token-goat-chunk-EUSDXRXU.mjs} +62 -12
- package/dist/{token-goat-chunk-POOI26O6.mjs → token-goat-chunk-FTP4U4QA.mjs} +12 -8
- package/dist/token-goat-chunk-G23DWHV4.mjs +142 -0
- package/dist/{token-goat-chunk-MDV5VWF4.mjs → token-goat-chunk-G7IWXCFF.mjs} +223 -15
- package/dist/{token-goat-chunk-C2PG4K5D.mjs → token-goat-chunk-GLXRTTLE.mjs} +7 -5
- package/dist/{token-goat-chunk-M6CVNHTW.mjs → token-goat-chunk-H5J3C56Q.mjs} +95 -573
- package/dist/{token-goat-chunk-BAWKGODL.mjs → token-goat-chunk-HNFZZHFW.mjs} +2 -2
- package/dist/{token-goat-chunk-TG5ZPD6B.mjs → token-goat-chunk-HUYUHODZ.mjs} +1036 -759
- package/dist/token-goat-chunk-IVE6U7KV.mjs +53 -0
- package/dist/{token-goat-chunk-ZZT6PVB3.mjs → token-goat-chunk-IVWI2OCK.mjs} +72 -45
- package/dist/{token-goat-chunk-GMOUBOX4.mjs → token-goat-chunk-JTKCQMQA.mjs} +37 -5
- package/dist/{token-goat-chunk-H2CPLEMP.mjs → token-goat-chunk-KOPIR3KZ.mjs} +46 -23
- package/dist/token-goat-chunk-L7H3U27L.mjs +35 -0
- package/dist/{token-goat-chunk-FLEYOCAS.mjs → token-goat-chunk-LZNBQTDK.mjs} +6 -4
- package/dist/token-goat-chunk-MELOKFDJ.mjs +199 -0
- package/dist/{token-goat-chunk-RH27ZSPF.mjs → token-goat-chunk-NMBWLRHW.mjs} +164 -50
- package/dist/{token-goat-chunk-43JFN26X.mjs → token-goat-chunk-O6I2XU4P.mjs} +27 -967
- package/dist/{token-goat-chunk-G6EYO5CD.mjs → token-goat-chunk-ONXH6NZ5.mjs} +2 -87
- package/dist/token-goat-chunk-ORNFMIER.mjs +295 -0
- package/dist/{token-goat-chunk-LHUP4DXZ.mjs → token-goat-chunk-PGTH2U4C.mjs} +1 -1
- package/dist/{token-goat-chunk-5BQ7W7D7.mjs → token-goat-chunk-PKRWMHVP.mjs} +76 -59
- package/dist/{token-goat-chunk-DA43OE7L.mjs → token-goat-chunk-PQ53BSCF.mjs} +1 -1
- package/dist/{token-goat-chunk-STYRLQIW.mjs → token-goat-chunk-PYSUADX4.mjs} +2 -2
- package/dist/{token-goat-chunk-JALB3KWJ.mjs → token-goat-chunk-QO3LXVVR.mjs} +4247 -5005
- package/dist/{token-goat-chunk-L45IWWMC.mjs → token-goat-chunk-RLP6J7WR.mjs} +6 -6
- package/dist/token-goat-chunk-RQGGMPCR.mjs +205 -0
- package/dist/{token-goat-chunk-MBDJR6HU.mjs → token-goat-chunk-RTMVLHWX.mjs} +3708 -4003
- package/dist/{token-goat-chunk-E3K3BTEQ.mjs → token-goat-chunk-S4VSXURL.mjs} +8 -6
- package/dist/{token-goat-chunk-LKSXAMJB.mjs → token-goat-chunk-SE6E4BKJ.mjs} +1 -1
- package/dist/token-goat-chunk-TCQANXYC.mjs +351 -0
- package/dist/token-goat-chunk-TDUT2CL6.mjs +564 -0
- package/dist/{token-goat-chunk-LRIZ7K3F.mjs → token-goat-chunk-TGOXNAHW.mjs} +54 -111
- package/dist/{token-goat-chunk-WNBSCSAI.mjs → token-goat-chunk-UA5BKWWQ.mjs} +1 -1
- package/dist/{token-goat-chunk-RIB6XY2V.mjs → token-goat-chunk-UXSXQQIY.mjs} +1 -1
- package/dist/{token-goat-chunk-7EPYB34H.mjs → token-goat-chunk-VMFWNHGR.mjs} +84 -73
- package/dist/token-goat-chunk-VQ6F6T7X.mjs +36 -0
- package/dist/{token-goat-chunk-5M3NRJD2.mjs → token-goat-chunk-VZQEWRVH.mjs} +6 -4
- package/dist/{token-goat-chunk-OSUFN2FV.mjs → token-goat-chunk-XB5KKOCG.mjs} +5 -25
- package/dist/{token-goat-chunk-6E2IDLHF.mjs → token-goat-chunk-XYWPOSCN.mjs} +57 -615
- package/dist/{token-goat-chunk-CQHY4SL7.mjs → token-goat-chunk-YAGLESS3.mjs} +8 -5
- package/dist/token-goat-chunk-YKSRAWUU.mjs +33 -0
- package/dist/{token-goat-chunk-F2ARFHLJ.mjs → token-goat-chunk-YOOVFPTP.mjs} +2 -2
- package/dist/{token-goat-chunk-EEIDFMEM.mjs → token-goat-chunk-YZAAZU2S.mjs} +12 -3
- package/dist/token-goat-chunk-Z6KBMOBI.mjs +53 -0
- package/dist/{token-goat-chunk-4GEDH2WU.mjs → token-goat-chunk-ZER6EAXZ.mjs} +81 -70
- package/dist/token-goat-hook-client.cjs +475 -0
- package/dist/token-goat-hook-client.mjs +26 -0
- package/dist/token-goat-hook.mjs +31 -21
- package/dist/token-goat.core.mjs +9 -39
- package/docs/C4_RUNTIME_ARCHITECTURE.md +2 -2
- package/docs/cli.md +35 -23
- package/docs/install.md +18 -14
- package/package.json +1 -1
- package/dist/token-goat-chunk-ADMR3QVF.mjs +0 -41
- package/dist/token-goat-chunk-E6B2UFDF.mjs +0 -30
- package/dist/token-goat-chunk-GKZ2US5B.mjs +0 -187
- package/dist/token-goat-chunk-MZTO4FXH.mjs +0 -26
|
@@ -2,7 +2,7 @@ import { createRequire as __cjsRequire } from 'node:module';
|
|
|
2
2
|
const require = __cjsRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
4
|
clearModuleCaches
|
|
5
|
-
} from "./token-goat-chunk-
|
|
5
|
+
} from "./token-goat-chunk-YZAAZU2S.mjs";
|
|
6
6
|
import {
|
|
7
7
|
init_define_import_meta_env
|
|
8
8
|
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
@@ -44,7 +44,7 @@ function captureOutput() {
|
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
-
async function serveOne(req, runFn) {
|
|
47
|
+
async function serveOne(req, runFn, reset = clearModuleCaches) {
|
|
48
48
|
const cwdBefore = process.cwd();
|
|
49
49
|
const restoreEnv = swapEnv(req.env ?? { ...process.env });
|
|
50
50
|
const cap = captureOutput();
|
|
@@ -65,7 +65,7 @@ async function serveOne(req, runFn) {
|
|
|
65
65
|
process.chdir(cwdBefore);
|
|
66
66
|
} catch {
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
reset();
|
|
69
69
|
return { id: req.id, status, stdout: captured.out, stderr: captured.err };
|
|
70
70
|
}
|
|
71
71
|
cap.restore();
|
|
@@ -77,7 +77,7 @@ async function serveOne(req, runFn) {
|
|
|
77
77
|
process.chdir(cwdBefore);
|
|
78
78
|
} catch {
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
reset();
|
|
81
81
|
return { id: req.id, status, stdout, stderr };
|
|
82
82
|
}
|
|
83
83
|
function serveBatch(token, runFn) {
|
|
@@ -106,7 +106,9 @@ function serveBatch(token, runFn) {
|
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
|
+
|
|
109
110
|
export {
|
|
110
|
-
|
|
111
|
-
serveOne
|
|
111
|
+
swapEnv,
|
|
112
|
+
serveOne,
|
|
113
|
+
serveBatch
|
|
112
114
|
};
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from "./token-goat-chunk-Y4AFKTHK.mjs";
|
|
10
10
|
import {
|
|
11
11
|
compileGuardedRegex
|
|
12
|
-
} from "./token-goat-chunk-
|
|
12
|
+
} from "./token-goat-chunk-JTKCQMQA.mjs";
|
|
13
13
|
import {
|
|
14
14
|
init_define_import_meta_env
|
|
15
15
|
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
MSYS_PATH_RE,
|
|
5
|
+
WSL_PATH_RE,
|
|
6
|
+
expandShortPath,
|
|
7
|
+
isUncOrDevicePath,
|
|
8
|
+
lowercaseDriveLetter,
|
|
9
|
+
normalizeDarwinSystemAlias
|
|
10
|
+
} from "./token-goat-chunk-NMTKNYGF.mjs";
|
|
11
|
+
import {
|
|
12
|
+
init_define_import_meta_env
|
|
13
|
+
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
14
|
+
|
|
15
|
+
// src/path_containment.ts
|
|
16
|
+
init_define_import_meta_env();
|
|
17
|
+
import * as fs from "node:fs";
|
|
18
|
+
import * as path from "node:path";
|
|
19
|
+
function isCaseInsensitiveFs() {
|
|
20
|
+
const o = process.env["TOKEN_GOAT_CASE_INSENSITIVE_FS"];
|
|
21
|
+
if (o === "1") return true;
|
|
22
|
+
if (o === "0") return false;
|
|
23
|
+
return process.platform === "win32" || process.platform === "darwin";
|
|
24
|
+
}
|
|
25
|
+
function foldPath(p) {
|
|
26
|
+
return isCaseInsensitiveFs() ? foldCase(p) : p;
|
|
27
|
+
}
|
|
28
|
+
function isNodeModulesPath(p) {
|
|
29
|
+
const check = foldPath(p);
|
|
30
|
+
return check.includes("/node_modules/") || check.includes("\\node_modules\\");
|
|
31
|
+
}
|
|
32
|
+
function foldCase(s) {
|
|
33
|
+
return s.toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
function foldCaseForContainment(s) {
|
|
36
|
+
return s.replace(/[A-Z]/g, (c) => c.toLowerCase());
|
|
37
|
+
}
|
|
38
|
+
function foldPathForContainment(p) {
|
|
39
|
+
return isCaseInsensitiveFs() ? foldCaseForContainment(p) : p;
|
|
40
|
+
}
|
|
41
|
+
var CYGWIN_PREFIX_RE = /^\/cygdrive\/([a-zA-Z])\/(.*)$/s;
|
|
42
|
+
function normalizeShellDrivePrefix(posixStr) {
|
|
43
|
+
let m = WSL_PATH_RE.exec(posixStr);
|
|
44
|
+
if (m) {
|
|
45
|
+
return `${m[1].toLowerCase()}:/${m[2]}`;
|
|
46
|
+
}
|
|
47
|
+
m = CYGWIN_PREFIX_RE.exec(posixStr);
|
|
48
|
+
if (m) {
|
|
49
|
+
return `${m[1].toLowerCase()}:/${m[2]}`;
|
|
50
|
+
}
|
|
51
|
+
m = MSYS_PATH_RE.exec(posixStr);
|
|
52
|
+
if (m) {
|
|
53
|
+
return `${m[1].toLowerCase()}:${m[2] ?? "/"}`;
|
|
54
|
+
}
|
|
55
|
+
return posixStr;
|
|
56
|
+
}
|
|
57
|
+
function canonicalize(inputPath, baseDir) {
|
|
58
|
+
const pathStr = typeof inputPath === "string" ? inputPath : inputPath.pathname;
|
|
59
|
+
const isWin32 = process.platform === "win32";
|
|
60
|
+
const base = baseDir ?? process.cwd();
|
|
61
|
+
const slashed = pathStr.replace(/\\/g, "/");
|
|
62
|
+
let pre = isWin32 ? normalizeShellDrivePrefix(slashed) : slashed;
|
|
63
|
+
if (pre !== slashed) {
|
|
64
|
+
pre = (isWin32 ? path.win32.resolve : path.resolve)(base, pre);
|
|
65
|
+
} else {
|
|
66
|
+
pre = (isWin32 ? path.win32.resolve : path.resolve)(base, pathStr);
|
|
67
|
+
}
|
|
68
|
+
let normalized = pre.replace(/\\/g, "/");
|
|
69
|
+
if (isWin32) {
|
|
70
|
+
normalized = normalizeShellDrivePrefix(normalized);
|
|
71
|
+
}
|
|
72
|
+
normalized = expandShortPath(normalized);
|
|
73
|
+
normalized = normalizeDarwinSystemAlias(normalized);
|
|
74
|
+
normalized = lowercaseDriveLetter(normalized);
|
|
75
|
+
return normalized;
|
|
76
|
+
}
|
|
77
|
+
var UNRESOLVABLE_PATH = "unresolvable-link-chain";
|
|
78
|
+
var MAX_LINK_HOPS = 40;
|
|
79
|
+
var MAX_RESOLVE_PATH_BYTES = 4096;
|
|
80
|
+
var MAX_WALK_SEGMENTS = MAX_RESOLVE_PATH_BYTES * (MAX_LINK_HOPS + 1);
|
|
81
|
+
function rootAndSegments(p) {
|
|
82
|
+
const parts = p.replace(/\\/g, "/").split("/");
|
|
83
|
+
const up = parts.indexOf("..");
|
|
84
|
+
const head = up === -1 ? parts.join("/") : parts.slice(0, up).join("/");
|
|
85
|
+
const canon = canonicalize(head === "" ? "." : head);
|
|
86
|
+
const m = /^(\/\/[^/]+\/[^/]+|[a-z]:\/|\/)/i.exec(canon);
|
|
87
|
+
const root = m === null ? "/" : m[1];
|
|
88
|
+
const rest = canon.slice(root.length).split("/");
|
|
89
|
+
return { root, segs: up === -1 ? rest : [...rest, ...parts.slice(up)] };
|
|
90
|
+
}
|
|
91
|
+
function joinSegment(base, seg) {
|
|
92
|
+
return base.endsWith("/") ? base + seg : `${base}/${seg}`;
|
|
93
|
+
}
|
|
94
|
+
function parentSegment(base, root) {
|
|
95
|
+
const cut = base.lastIndexOf("/");
|
|
96
|
+
return cut < root.length ? root : base.slice(0, cut);
|
|
97
|
+
}
|
|
98
|
+
var DRIVE_RELATIVE_PATH = /^[a-z]:(?![\\/])/i;
|
|
99
|
+
function linkTarget(link) {
|
|
100
|
+
const raw = link.replace(/\\/g, "/").replace(/^\/\/\?\/(UNC\/)?/i, (_m, unc) => unc === void 0 ? "" : "//");
|
|
101
|
+
if (!/^(\/\/[^/]+\/|[a-z]:\/|\/)/i.test(raw)) return { root: null, segs: raw.split("/") };
|
|
102
|
+
const abs = rootAndSegments(raw);
|
|
103
|
+
return { root: abs.root, segs: abs.segs };
|
|
104
|
+
}
|
|
105
|
+
function resolveThroughLinks(p) {
|
|
106
|
+
if (Buffer.byteLength(p, "utf8") > MAX_RESOLVE_PATH_BYTES) return UNRESOLVABLE_PATH;
|
|
107
|
+
const start = rootAndSegments(p);
|
|
108
|
+
let root = start.root;
|
|
109
|
+
let base = root;
|
|
110
|
+
const stack = start.segs.slice().reverse();
|
|
111
|
+
let hops = 0;
|
|
112
|
+
let walked = 0;
|
|
113
|
+
while (stack.length > 0) {
|
|
114
|
+
if (++walked > MAX_WALK_SEGMENTS) return UNRESOLVABLE_PATH;
|
|
115
|
+
const seg = stack.pop();
|
|
116
|
+
if (seg === "" || seg === ".") continue;
|
|
117
|
+
if (seg === "..") {
|
|
118
|
+
base = parentSegment(base, root);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const candidate = joinSegment(base, seg);
|
|
122
|
+
if (Buffer.byteLength(candidate, "utf8") > MAX_RESOLVE_PATH_BYTES) return UNRESOLVABLE_PATH;
|
|
123
|
+
let link = null;
|
|
124
|
+
try {
|
|
125
|
+
if (fs.lstatSync(candidate).isSymbolicLink()) link = fs.readlinkSync(candidate);
|
|
126
|
+
} catch (err) {
|
|
127
|
+
const code = err.code;
|
|
128
|
+
if (code !== "ENOENT" && code !== "ENOTDIR") return UNRESOLVABLE_PATH;
|
|
129
|
+
link = null;
|
|
130
|
+
}
|
|
131
|
+
if (link === null) {
|
|
132
|
+
base = candidate;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (++hops > MAX_LINK_HOPS) return UNRESOLVABLE_PATH;
|
|
136
|
+
if (DRIVE_RELATIVE_PATH.test(link)) return UNRESOLVABLE_PATH;
|
|
137
|
+
const target = linkTarget(link);
|
|
138
|
+
if (target.root !== null) {
|
|
139
|
+
if (!isUncOrDevicePath(root) && isUncOrDevicePath(target.root)) return UNRESOLVABLE_PATH;
|
|
140
|
+
root = target.root;
|
|
141
|
+
base = target.root;
|
|
142
|
+
}
|
|
143
|
+
for (let i = target.segs.length - 1; i >= 0; i--) stack.push(target.segs[i]);
|
|
144
|
+
}
|
|
145
|
+
return base;
|
|
146
|
+
}
|
|
147
|
+
function normalizeForFs(p) {
|
|
148
|
+
return process.platform === "darwin" ? p.normalize("NFC") : p;
|
|
149
|
+
}
|
|
150
|
+
function escapesOntoNetworkThroughLinks(target, cwd) {
|
|
151
|
+
if (isUncOrDevicePath(target)) return true;
|
|
152
|
+
let absolute;
|
|
153
|
+
try {
|
|
154
|
+
absolute = path.resolve(cwd ?? process.cwd(), target);
|
|
155
|
+
} catch {
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
if (isUncOrDevicePath(absolute)) return true;
|
|
159
|
+
const resolved = resolveThroughLinks(absolute);
|
|
160
|
+
return resolved === UNRESOLVABLE_PATH || isUncOrDevicePath(resolved);
|
|
161
|
+
}
|
|
162
|
+
function isInsideRoot(target, root) {
|
|
163
|
+
if (reachesForeignShare(target, root)) return false;
|
|
164
|
+
const rt = resolveThroughLinks(target);
|
|
165
|
+
const rr = resolveThroughLinks(root);
|
|
166
|
+
if (rt === UNRESOLVABLE_PATH || rr === UNRESOLVABLE_PATH) return false;
|
|
167
|
+
const nt = normalizeForFs(rt);
|
|
168
|
+
const nr = normalizeForFs(rr);
|
|
169
|
+
const t = foldPathForContainment(nt);
|
|
170
|
+
const r = foldPathForContainment(nr);
|
|
171
|
+
if (t !== r && !t.startsWith(r.endsWith("/") ? r : r + "/")) return false;
|
|
172
|
+
if (nt.slice(0, nr.length) === nr) return true;
|
|
173
|
+
return sameDirectory(nt.slice(0, nr.length), nr);
|
|
174
|
+
}
|
|
175
|
+
function isNetworkPath(p, platform = process.platform) {
|
|
176
|
+
return networkShareRoot(p, platform) !== null;
|
|
177
|
+
}
|
|
178
|
+
function networkShareRoot(p, platform = process.platform) {
|
|
179
|
+
if (platform !== "win32") return null;
|
|
180
|
+
const device = /^[\\/]{2}([?.][\\/])?/.exec(p);
|
|
181
|
+
if (device === null) return null;
|
|
182
|
+
let rest = p.slice(device[0].length);
|
|
183
|
+
if (device[1] !== void 0) {
|
|
184
|
+
const unc = /^UNC[\\/]/i.exec(rest);
|
|
185
|
+
if (unc === null) return null;
|
|
186
|
+
rest = rest.slice(unc[0].length);
|
|
187
|
+
}
|
|
188
|
+
const [host = "", share = ""] = rest.split(/[\\/]/);
|
|
189
|
+
return `//${foldCase(host)}/${foldCase(share)}`;
|
|
190
|
+
}
|
|
191
|
+
function reachesForeignShare(target, root, platform = process.platform) {
|
|
192
|
+
const share = networkShareRoot(target, platform);
|
|
193
|
+
return share !== null && share !== networkShareRoot(root, platform);
|
|
194
|
+
}
|
|
195
|
+
function sameDirectory(a, b, platform = process.platform) {
|
|
196
|
+
if (isNetworkPath(a, platform) || isNetworkPath(b, platform)) return false;
|
|
197
|
+
let canonicalRoot;
|
|
198
|
+
try {
|
|
199
|
+
canonicalRoot = fs.realpathSync.native(b);
|
|
200
|
+
} catch {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
return fs.realpathSync.native(a) === canonicalRoot;
|
|
205
|
+
} catch {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// src/process_util.ts
|
|
211
|
+
init_define_import_meta_env();
|
|
212
|
+
import { existsSync, realpathSync as realpathSync2, statSync } from "node:fs";
|
|
213
|
+
import * as path2 from "node:path";
|
|
214
|
+
function sleepSync(ms) {
|
|
215
|
+
if (ms <= 0) return;
|
|
216
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
217
|
+
}
|
|
218
|
+
function isWindows() {
|
|
219
|
+
return process.platform === "win32";
|
|
220
|
+
}
|
|
221
|
+
function windowsCmdQuoteArg(arg) {
|
|
222
|
+
if (arg === "") return '""';
|
|
223
|
+
if (arg[0] === '"' && arg[arg.length - 1] === '"') {
|
|
224
|
+
throw new Error(`windowsCmdQuoteArg: cannot faithfully encode an argument that both starts and ends with a literal double quote for cmd.exe: ${JSON.stringify(arg)}`);
|
|
225
|
+
}
|
|
226
|
+
let out = "";
|
|
227
|
+
let inQuote = false;
|
|
228
|
+
let backslashes = 0;
|
|
229
|
+
const flushBackslashesPlain = () => {
|
|
230
|
+
if (backslashes > 0) {
|
|
231
|
+
out += "\\".repeat(backslashes);
|
|
232
|
+
backslashes = 0;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
const flushBackslashesDoubled = () => {
|
|
236
|
+
out += "\\".repeat(backslashes * 2);
|
|
237
|
+
backslashes = 0;
|
|
238
|
+
};
|
|
239
|
+
const ensureQuoteOpen = () => {
|
|
240
|
+
if (!inQuote) {
|
|
241
|
+
flushBackslashesDoubled();
|
|
242
|
+
out += '"';
|
|
243
|
+
inQuote = true;
|
|
244
|
+
} else {
|
|
245
|
+
flushBackslashesPlain();
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const ensureQuoteClosed = () => {
|
|
249
|
+
if (inQuote) {
|
|
250
|
+
flushBackslashesDoubled();
|
|
251
|
+
out += '"';
|
|
252
|
+
inQuote = false;
|
|
253
|
+
} else {
|
|
254
|
+
flushBackslashesPlain();
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
for (const ch of arg) {
|
|
258
|
+
if (ch === "\\") {
|
|
259
|
+
backslashes++;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
if (ch === '"') {
|
|
263
|
+
flushBackslashesDoubled();
|
|
264
|
+
if (inQuote) {
|
|
265
|
+
out += '"';
|
|
266
|
+
inQuote = false;
|
|
267
|
+
}
|
|
268
|
+
out += '\\^"';
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if (ch === "%" || ch === "!") {
|
|
272
|
+
ensureQuoteClosed();
|
|
273
|
+
out += `^${ch}`;
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
ensureQuoteOpen();
|
|
277
|
+
out += ch;
|
|
278
|
+
}
|
|
279
|
+
ensureQuoteClosed();
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
function quoteShellPath(value) {
|
|
283
|
+
if (process.platform === "win32") return `"${value}"`;
|
|
284
|
+
return `"${value.replace(/[\\$`"]/g, "\\$&")}"`;
|
|
285
|
+
}
|
|
286
|
+
function quotePowershellPath(value) {
|
|
287
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
288
|
+
}
|
|
289
|
+
function resolveOnPath(label) {
|
|
290
|
+
if (path2.isAbsolute(label)) return existsSync(label) ? label : null;
|
|
291
|
+
if (label.includes("/") || label.includes("\\")) return null;
|
|
292
|
+
const onWindows = process.platform === "win32";
|
|
293
|
+
const exts = onWindows ? (process.env["PATHEXT"] ?? ".COM;.EXE;.BAT;.CMD").split(";").filter((e) => e.trim() !== "") : [""];
|
|
294
|
+
let cwd;
|
|
295
|
+
try {
|
|
296
|
+
cwd = realpathSync2(process.cwd());
|
|
297
|
+
} catch {
|
|
298
|
+
cwd = path2.resolve(process.cwd());
|
|
299
|
+
}
|
|
300
|
+
for (const rawDir of (process.env["PATH"] ?? "").split(path2.delimiter)) {
|
|
301
|
+
const dir = rawDir.trim().replace(/^"|"$/g, "");
|
|
302
|
+
if (dir === "" || dir === ".") continue;
|
|
303
|
+
let resolvedDir;
|
|
304
|
+
try {
|
|
305
|
+
resolvedDir = realpathSync2(path2.resolve(dir));
|
|
306
|
+
} catch {
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (foldPath(resolvedDir) === foldPath(cwd)) continue;
|
|
310
|
+
for (const ext of exts) {
|
|
311
|
+
const candidate = path2.join(resolvedDir, label + ext);
|
|
312
|
+
try {
|
|
313
|
+
if (statSync(candidate).isFile()) return candidate;
|
|
314
|
+
} catch {
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
function installEpipeGuard(streams) {
|
|
321
|
+
const targets = (streams ?? [process.stdout, process.stderr]).filter((s) => s !== void 0);
|
|
322
|
+
for (const stream of targets) {
|
|
323
|
+
stream.on("error", (err) => {
|
|
324
|
+
if (err.code === "EPIPE") {
|
|
325
|
+
process.exitCode = 0;
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
throw err;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
return targets;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export {
|
|
335
|
+
isCaseInsensitiveFs,
|
|
336
|
+
foldPath,
|
|
337
|
+
isNodeModulesPath,
|
|
338
|
+
foldCase,
|
|
339
|
+
foldCaseForContainment,
|
|
340
|
+
foldPathForContainment,
|
|
341
|
+
canonicalize,
|
|
342
|
+
escapesOntoNetworkThroughLinks,
|
|
343
|
+
isInsideRoot,
|
|
344
|
+
sleepSync,
|
|
345
|
+
isWindows,
|
|
346
|
+
windowsCmdQuoteArg,
|
|
347
|
+
quoteShellPath,
|
|
348
|
+
quotePowershellPath,
|
|
349
|
+
resolveOnPath,
|
|
350
|
+
installEpipeGuard
|
|
351
|
+
};
|