sandboxedjs 0.2.6 → 0.2.8
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 +23 -16
- package/bin/sandboxedjs-egress.mjs +117 -0
- package/dist/browser-host.cjs +137 -0
- package/dist/browser-host.d.cts +12 -0
- package/dist/browser-host.d.ts +12 -0
- package/dist/browser-host.js +137 -0
- package/dist/egress.cjs +12 -1
- package/dist/egress.d.cts +33 -1
- package/dist/egress.d.ts +33 -1
- package/dist/egress.js +11 -2
- package/dist/index.cjs +174 -128
- package/dist/index.js +174 -128
- package/dist/worker-entry.js +63 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -605,32 +605,32 @@ var init_variables = __esm({
|
|
|
605
605
|
return this.find(name) !== void 0;
|
|
606
606
|
}
|
|
607
607
|
get(name) {
|
|
608
|
-
const
|
|
609
|
-
if (!
|
|
610
|
-
if (
|
|
611
|
-
return
|
|
608
|
+
const found2 = this.find(name);
|
|
609
|
+
if (!found2) return void 0;
|
|
610
|
+
if (found2.entry.array) return found2.entry.array[0] ?? "";
|
|
611
|
+
return found2.entry.value;
|
|
612
612
|
}
|
|
613
613
|
entry(name) {
|
|
614
614
|
return this.find(name)?.entry;
|
|
615
615
|
}
|
|
616
616
|
getArray(name) {
|
|
617
|
-
const
|
|
618
|
-
if (!
|
|
619
|
-
return
|
|
617
|
+
const found2 = this.find(name);
|
|
618
|
+
if (!found2) return void 0;
|
|
619
|
+
return found2.entry.array ?? [found2.entry.value];
|
|
620
620
|
}
|
|
621
621
|
isArray(name) {
|
|
622
622
|
return this.find(name)?.entry.array !== void 0;
|
|
623
623
|
}
|
|
624
624
|
set(name, value, attrs = {}) {
|
|
625
|
-
const
|
|
626
|
-
if (
|
|
625
|
+
const found2 = this.find(name);
|
|
626
|
+
if (found2?.entry.readonly) throw new ReadonlyVariableError(name);
|
|
627
627
|
let next = value;
|
|
628
|
-
if (
|
|
629
|
-
if (
|
|
630
|
-
if (
|
|
631
|
-
|
|
632
|
-
delete
|
|
633
|
-
Object.assign(
|
|
628
|
+
if (found2?.entry.upper || attrs.upper) next = next.toUpperCase();
|
|
629
|
+
if (found2?.entry.lower || attrs.lower) next = next.toLowerCase();
|
|
630
|
+
if (found2) {
|
|
631
|
+
found2.entry.value = next;
|
|
632
|
+
delete found2.entry.array;
|
|
633
|
+
Object.assign(found2.entry, attrs);
|
|
634
634
|
} else {
|
|
635
635
|
this.scopes[this.scopes.length - 1].set(name, { value: next, ...attrs });
|
|
636
636
|
}
|
|
@@ -640,28 +640,28 @@ var init_variables = __esm({
|
|
|
640
640
|
this.scopes[this.scopes.length - 1].set(name, { value, ...attrs });
|
|
641
641
|
}
|
|
642
642
|
setArray(name, values, attrs = {}) {
|
|
643
|
-
const
|
|
644
|
-
if (
|
|
645
|
-
if (
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
Object.assign(
|
|
643
|
+
const found2 = this.find(name);
|
|
644
|
+
if (found2?.entry.readonly) throw new ReadonlyVariableError(name);
|
|
645
|
+
if (found2) {
|
|
646
|
+
found2.entry.array = values.slice();
|
|
647
|
+
found2.entry.value = values[0] ?? "";
|
|
648
|
+
Object.assign(found2.entry, attrs);
|
|
649
649
|
} else {
|
|
650
650
|
this.scopes[this.scopes.length - 1].set(name, { value: values[0] ?? "", array: values.slice(), ...attrs });
|
|
651
651
|
}
|
|
652
652
|
}
|
|
653
653
|
setIndex(name, index, value) {
|
|
654
|
-
const
|
|
655
|
-
if (
|
|
656
|
-
const arr =
|
|
654
|
+
const found2 = this.find(name);
|
|
655
|
+
if (found2?.entry.readonly) throw new ReadonlyVariableError(name);
|
|
656
|
+
const arr = found2?.entry.array ?? (found2 ? [found2.entry.value] : []);
|
|
657
657
|
while (arr.length < index) arr.push("");
|
|
658
658
|
arr[index] = value;
|
|
659
659
|
this.setArray(name, arr);
|
|
660
660
|
}
|
|
661
661
|
append(name, value) {
|
|
662
|
-
const
|
|
663
|
-
if (
|
|
664
|
-
this.setArray(name, [...
|
|
662
|
+
const found2 = this.find(name);
|
|
663
|
+
if (found2?.entry.array) {
|
|
664
|
+
this.setArray(name, [...found2.entry.array, value]);
|
|
665
665
|
return;
|
|
666
666
|
}
|
|
667
667
|
this.set(name, (this.get(name) ?? "") + value);
|
|
@@ -678,13 +678,13 @@ var init_variables = __esm({
|
|
|
678
678
|
return false;
|
|
679
679
|
}
|
|
680
680
|
export(name, exported = true) {
|
|
681
|
-
const
|
|
682
|
-
if (
|
|
681
|
+
const found2 = this.find(name);
|
|
682
|
+
if (found2) found2.entry.exported = exported;
|
|
683
683
|
else this.scopes[this.scopes.length - 1].set(name, { value: "", exported });
|
|
684
684
|
}
|
|
685
685
|
markReadonly(name) {
|
|
686
|
-
const
|
|
687
|
-
if (
|
|
686
|
+
const found2 = this.find(name);
|
|
687
|
+
if (found2) found2.entry.readonly = true;
|
|
688
688
|
else this.scopes[this.scopes.length - 1].set(name, { value: "", readonly: true });
|
|
689
689
|
}
|
|
690
690
|
names() {
|
|
@@ -2930,8 +2930,8 @@ async function builtinSource({ shell, argv, io }) {
|
|
|
2930
2930
|
}
|
|
2931
2931
|
let path = resolve(shell.cwd, target);
|
|
2932
2932
|
if (!target.includes("/")) {
|
|
2933
|
-
const
|
|
2934
|
-
if (
|
|
2933
|
+
const found2 = shell.kernel.which(target, shell.cwd, shell.vars.environment(), shell.cred);
|
|
2934
|
+
if (found2) path = found2;
|
|
2935
2935
|
}
|
|
2936
2936
|
let text2;
|
|
2937
2937
|
try {
|
|
@@ -3565,32 +3565,32 @@ function builtinType({ shell, argv, io }) {
|
|
|
3565
3565
|
const names = args.filter((a) => !a.startsWith("-"));
|
|
3566
3566
|
let status = 0;
|
|
3567
3567
|
for (const name of names) {
|
|
3568
|
-
const
|
|
3568
|
+
const found2 = [];
|
|
3569
3569
|
if (shell.aliases.has(name)) {
|
|
3570
|
-
if (typeOnly)
|
|
3571
|
-
else if (!pathOnly)
|
|
3570
|
+
if (typeOnly) found2.push("alias");
|
|
3571
|
+
else if (!pathOnly) found2.push(`${name} is aliased to \`${shell.aliases.get(name)}'`);
|
|
3572
3572
|
}
|
|
3573
3573
|
if (shell.functions.has(name)) {
|
|
3574
|
-
if (typeOnly)
|
|
3575
|
-
else if (!pathOnly)
|
|
3574
|
+
if (typeOnly) found2.push("function");
|
|
3575
|
+
else if (!pathOnly) found2.push(`${name} is a function`);
|
|
3576
3576
|
}
|
|
3577
3577
|
if (isBuiltinName(name)) {
|
|
3578
|
-
if (typeOnly)
|
|
3579
|
-
else if (!pathOnly)
|
|
3578
|
+
if (typeOnly) found2.push("builtin");
|
|
3579
|
+
else if (!pathOnly) found2.push(`${name} is a shell builtin`);
|
|
3580
3580
|
}
|
|
3581
3581
|
const path = shell.kernel.which(name, shell.cwd, shell.vars.environment(), shell.cred);
|
|
3582
3582
|
if (path) {
|
|
3583
|
-
if (typeOnly)
|
|
3584
|
-
else if (pathOnly)
|
|
3585
|
-
else
|
|
3583
|
+
if (typeOnly) found2.push("file");
|
|
3584
|
+
else if (pathOnly) found2.push(path);
|
|
3585
|
+
else found2.push(`${name} is ${path}`);
|
|
3586
3586
|
}
|
|
3587
|
-
if (
|
|
3587
|
+
if (found2.length === 0) {
|
|
3588
3588
|
if (!pathOnly && !typeOnly) io.stderr.write(`type: ${name}: not found
|
|
3589
3589
|
`);
|
|
3590
3590
|
status = 1;
|
|
3591
3591
|
continue;
|
|
3592
3592
|
}
|
|
3593
|
-
for (const line of all ?
|
|
3593
|
+
for (const line of all ? found2 : [found2[0]]) io.stdout.write(line + "\n");
|
|
3594
3594
|
}
|
|
3595
3595
|
return status;
|
|
3596
3596
|
}
|
|
@@ -5947,9 +5947,9 @@ function parseArgs(argv, specs, opts = {}) {
|
|
|
5947
5947
|
const resolveLong = (name) => {
|
|
5948
5948
|
const exact = byLong.get(name);
|
|
5949
5949
|
if (exact) return exact;
|
|
5950
|
-
const
|
|
5951
|
-
if (
|
|
5952
|
-
if (
|
|
5950
|
+
const candidates2 = [...byLong.keys()].filter((k) => k.startsWith(name));
|
|
5951
|
+
if (candidates2.length === 1) return byLong.get(candidates2[0]);
|
|
5952
|
+
if (candidates2.length > 1) throw new UsageError(`option '--${name}' is ambiguous`);
|
|
5953
5953
|
return void 0;
|
|
5954
5954
|
};
|
|
5955
5955
|
for (; i < argv.length; i++) {
|
|
@@ -6468,19 +6468,19 @@ var WasiHost = class {
|
|
|
6468
6468
|
}
|
|
6469
6469
|
// ── descriptors ──────────────────────────────────────────────────────────
|
|
6470
6470
|
get(fd) {
|
|
6471
|
-
const
|
|
6472
|
-
if (!
|
|
6473
|
-
return
|
|
6471
|
+
const found2 = this.fds.get(fd);
|
|
6472
|
+
if (!found2) throw new WasiError(WASI_EBADF);
|
|
6473
|
+
return found2;
|
|
6474
6474
|
}
|
|
6475
6475
|
dir(fd) {
|
|
6476
|
-
const
|
|
6477
|
-
if (
|
|
6478
|
-
return
|
|
6476
|
+
const found2 = this.get(fd);
|
|
6477
|
+
if (found2.kind !== "dir") throw new WasiError(WASI_ENOTDIR);
|
|
6478
|
+
return found2;
|
|
6479
6479
|
}
|
|
6480
6480
|
file(fd) {
|
|
6481
|
-
const
|
|
6482
|
-
if (
|
|
6483
|
-
return
|
|
6481
|
+
const found2 = this.get(fd);
|
|
6482
|
+
if (found2.kind !== "file") throw new WasiError(WASI_EBADF);
|
|
6483
|
+
return found2;
|
|
6484
6484
|
}
|
|
6485
6485
|
/**
|
|
6486
6486
|
* Resolve a guest path against a directory descriptor.
|
|
@@ -7425,13 +7425,13 @@ var Kernel = class {
|
|
|
7425
7425
|
* Find `name` the way `execvp` does. Returns null when nothing matches.
|
|
7426
7426
|
*/
|
|
7427
7427
|
resolveExecutable(name, cwd, env2, cred = ROOT_CRED) {
|
|
7428
|
-
const
|
|
7428
|
+
const candidates2 = [];
|
|
7429
7429
|
if (name.includes("/")) {
|
|
7430
|
-
|
|
7430
|
+
candidates2.push(resolve(cwd, name));
|
|
7431
7431
|
} else {
|
|
7432
|
-
for (const dir3 of this.pathDirs(env2))
|
|
7432
|
+
for (const dir3 of this.pathDirs(env2)) candidates2.push(join(dir3, name));
|
|
7433
7433
|
}
|
|
7434
|
-
for (const candidate of
|
|
7434
|
+
for (const candidate of candidates2) {
|
|
7435
7435
|
let real;
|
|
7436
7436
|
try {
|
|
7437
7437
|
real = this.vfs.realpath(candidate, cred);
|
|
@@ -8407,10 +8407,55 @@ function isBrowser() {
|
|
|
8407
8407
|
}
|
|
8408
8408
|
function browserBlocked(hostname, message) {
|
|
8409
8409
|
return new Error(
|
|
8410
|
-
`${message} \u2014 the request to ${hostname} was blocked by the browser. A page can only read a response from a host that sends CORS headers, and most APIs send none.
|
|
8410
|
+
`${message} \u2014 the request to ${hostname} was blocked by the browser. A page can only read a response from a host that sends CORS headers, and most APIs send none. The container looked on this origin for a proxy to make the request for it and found none: run \`npx sandboxedjs-egress init\` to add one to this deployment, or \`npx sandboxedjs-egress\` while developing, and it is used with no further configuration (network: { proxy } names one somewhere else) \u2014 or run the container on a server, where CORS does not apply.`
|
|
8411
8411
|
);
|
|
8412
8412
|
}
|
|
8413
8413
|
|
|
8414
|
+
// src/net/discover-egress.ts
|
|
8415
|
+
var EGRESS_PATH = "/__sandboxedjs__/egress";
|
|
8416
|
+
var EGRESS_PATHS = [
|
|
8417
|
+
EGRESS_PATH,
|
|
8418
|
+
`/api${EGRESS_PATH}`,
|
|
8419
|
+
"/.netlify/functions/sandboxedjs-egress"
|
|
8420
|
+
];
|
|
8421
|
+
var EGRESS_MARKER = { sandboxedjs: "egress", protocol: 1 };
|
|
8422
|
+
var CLI_PORT = 4181;
|
|
8423
|
+
var found = null;
|
|
8424
|
+
var PROBE_TIMEOUT_MS = 1500;
|
|
8425
|
+
async function isEgress(url, fetchImpl) {
|
|
8426
|
+
const control = new AbortController();
|
|
8427
|
+
const timer = setTimeout(() => control.abort(), PROBE_TIMEOUT_MS);
|
|
8428
|
+
try {
|
|
8429
|
+
const answer = await fetchImpl(url, { method: "GET", signal: control.signal });
|
|
8430
|
+
if (!answer.ok) return false;
|
|
8431
|
+
const payload = await answer.json();
|
|
8432
|
+
return payload?.sandboxedjs === EGRESS_MARKER.sandboxedjs;
|
|
8433
|
+
} catch {
|
|
8434
|
+
return false;
|
|
8435
|
+
} finally {
|
|
8436
|
+
clearTimeout(timer);
|
|
8437
|
+
}
|
|
8438
|
+
}
|
|
8439
|
+
function candidates() {
|
|
8440
|
+
const origin = globalThis.location?.origin;
|
|
8441
|
+
const list = [];
|
|
8442
|
+
if (origin && /^https?:/.test(origin)) list.push(...EGRESS_PATHS.map((path) => `${origin}${path}`));
|
|
8443
|
+
list.push(`http://127.0.0.1:${CLI_PORT}/`);
|
|
8444
|
+
return list;
|
|
8445
|
+
}
|
|
8446
|
+
async function discoverEgress(fetchImpl = fetch) {
|
|
8447
|
+
if (!isBrowser()) return null;
|
|
8448
|
+
if (!found) {
|
|
8449
|
+
found = (async () => {
|
|
8450
|
+
const list = candidates();
|
|
8451
|
+
const answers = await Promise.all(list.map((candidate) => isEgress(candidate, fetchImpl)));
|
|
8452
|
+
const at = answers.findIndex(Boolean);
|
|
8453
|
+
return at === -1 ? null : list[at];
|
|
8454
|
+
})();
|
|
8455
|
+
}
|
|
8456
|
+
return await found;
|
|
8457
|
+
}
|
|
8458
|
+
|
|
8414
8459
|
// src/net/policy.ts
|
|
8415
8460
|
function isLoopbackHostname(hostname) {
|
|
8416
8461
|
const host2 = hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
@@ -8453,7 +8498,8 @@ function policedFetch(policy, fetchImpl) {
|
|
|
8453
8498
|
if (!outboundAllowed(policy, url)) {
|
|
8454
8499
|
throw Object.assign(new TypeError("fetch failed"), { cause: outboundBlockedError(url) });
|
|
8455
8500
|
}
|
|
8456
|
-
|
|
8501
|
+
const proxy = policy.proxy ?? await discoverEgress(fetchImpl);
|
|
8502
|
+
if (proxy) return await fetchThroughProxy(proxy, fetchImpl, input, init);
|
|
8457
8503
|
try {
|
|
8458
8504
|
return await fetchImpl(input, init);
|
|
8459
8505
|
} catch (error) {
|
|
@@ -8989,7 +9035,7 @@ var Lexer = class _Lexer {
|
|
|
8989
9035
|
const quoted = /['"\\]/.test(rawTag);
|
|
8990
9036
|
const tag2 = rawTag.replace(/['"\\]/g, "");
|
|
8991
9037
|
const lines = [];
|
|
8992
|
-
let
|
|
9038
|
+
let found2 = false;
|
|
8993
9039
|
while (this.pos < this.src.length) {
|
|
8994
9040
|
let eol = this.src.indexOf("\n", this.pos);
|
|
8995
9041
|
if (eol < 0) eol = this.src.length;
|
|
@@ -8997,13 +9043,13 @@ var Lexer = class _Lexer {
|
|
|
8997
9043
|
this.pos = eol + 1;
|
|
8998
9044
|
const compare = stripTabs ? rawLine.replace(/^\t+/, "") : rawLine;
|
|
8999
9045
|
if (compare === tag2) {
|
|
9000
|
-
|
|
9046
|
+
found2 = true;
|
|
9001
9047
|
break;
|
|
9002
9048
|
}
|
|
9003
9049
|
lines.push(stripTabs ? rawLine.replace(/^\t+/, "") : rawLine);
|
|
9004
9050
|
if (eol >= this.src.length) break;
|
|
9005
9051
|
}
|
|
9006
|
-
if (!
|
|
9052
|
+
if (!found2) {
|
|
9007
9053
|
throw new IncompleteInputError(`here-document delimited by end-of-file (wanted \`${tag2}')`, opToken.pos);
|
|
9008
9054
|
}
|
|
9009
9055
|
opToken.heredoc = { tag: tag2, stripTabs, quoted, body: lines.length ? lines.join("\n") + "\n" : "" };
|
|
@@ -14458,8 +14504,8 @@ var Interpreter = class {
|
|
|
14458
14504
|
for (let i = this.locals.length - 1; i >= 0; i--) {
|
|
14459
14505
|
const scope = this.locals[i];
|
|
14460
14506
|
if (scope.has(name)) {
|
|
14461
|
-
const
|
|
14462
|
-
return
|
|
14507
|
+
const found2 = scope.get(name);
|
|
14508
|
+
return found2 instanceof Map ? Value.uninitialized : found2;
|
|
14463
14509
|
}
|
|
14464
14510
|
}
|
|
14465
14511
|
if (name === "NF") {
|
|
@@ -14491,8 +14537,8 @@ var Interpreter = class {
|
|
|
14491
14537
|
for (let i = this.locals.length - 1; i >= 0; i--) {
|
|
14492
14538
|
const scope = this.locals[i];
|
|
14493
14539
|
if (scope.has(name)) {
|
|
14494
|
-
const
|
|
14495
|
-
if (
|
|
14540
|
+
const found2 = scope.get(name);
|
|
14541
|
+
if (found2 instanceof Map) return found2;
|
|
14496
14542
|
const created = /* @__PURE__ */ new Map();
|
|
14497
14543
|
scope.set(name, created);
|
|
14498
14544
|
return created;
|
|
@@ -17570,7 +17616,7 @@ async function performRequest(ctx, url, init) {
|
|
|
17570
17616
|
`outbound network access to ${url.hostname} is disabled for this container (enable with network: { allowOutbound: true })`
|
|
17571
17617
|
);
|
|
17572
17618
|
}
|
|
17573
|
-
const proxy = ctx.kernel.net.proxy;
|
|
17619
|
+
const proxy = ctx.kernel.net.proxy ?? await discoverEgress();
|
|
17574
17620
|
if (proxy) {
|
|
17575
17621
|
const result = await proxyExchange(proxy, {
|
|
17576
17622
|
url: url.toString(),
|
|
@@ -18541,14 +18587,14 @@ var apropos = defineCommand({
|
|
|
18541
18587
|
return 1;
|
|
18542
18588
|
}
|
|
18543
18589
|
const patterns = ctx.args.map((a) => new RegExp(a, "i"));
|
|
18544
|
-
let
|
|
18590
|
+
let found2 = 0;
|
|
18545
18591
|
for (const command of ctx.kernel.commands.all()) {
|
|
18546
18592
|
const haystack = `${command.name} ${command.summary ?? ""}`;
|
|
18547
18593
|
if (!patterns.some((p) => p.test(haystack))) continue;
|
|
18548
|
-
|
|
18594
|
+
found2++;
|
|
18549
18595
|
ctx.line(`${command.name} (1)${" ".repeat(Math.max(1, 16 - command.name.length))}- ${command.summary ?? ""}`);
|
|
18550
18596
|
}
|
|
18551
|
-
if (
|
|
18597
|
+
if (found2 === 0) {
|
|
18552
18598
|
ctx.line(`${ctx.args.join(" ")}: nothing appropriate.`);
|
|
18553
18599
|
return 1;
|
|
18554
18600
|
}
|
|
@@ -19572,8 +19618,8 @@ ${prelude}${preloadRequires(preloads)}${source}
|
|
|
19572
19618
|
}
|
|
19573
19619
|
function resolveScript(ctx, operand) {
|
|
19574
19620
|
const base2 = ctx.path(operand);
|
|
19575
|
-
const
|
|
19576
|
-
for (const candidate of
|
|
19621
|
+
const candidates2 = [base2, `${base2}.js`, `${base2}.mjs`, `${base2}.cjs`, `${base2}.json`];
|
|
19622
|
+
for (const candidate of candidates2) {
|
|
19577
19623
|
try {
|
|
19578
19624
|
const st = ctx.vfs.stat(candidate, { cred: ctx.cred });
|
|
19579
19625
|
if (st.isFile()) return ctx.vfs.realpath(candidate, ctx.cred);
|
|
@@ -21040,7 +21086,7 @@ var wheels_default = {
|
|
|
21040
21086
|
|
|
21041
21087
|
// package.json
|
|
21042
21088
|
var package_default = {
|
|
21043
|
-
version: "0.2.
|
|
21089
|
+
version: "0.2.8"};
|
|
21044
21090
|
|
|
21045
21091
|
// src/python/extension-abi.ts
|
|
21046
21092
|
var EXTENSION_ABI = {
|
|
@@ -23912,7 +23958,7 @@ function explain(name, constraints, chosenVersion, available2 = []) {
|
|
|
23912
23958
|
return lines;
|
|
23913
23959
|
}
|
|
23914
23960
|
async function fetchCandidates(client, name, allowSourceBuilds, prebuilt, rejected = { versions: /* @__PURE__ */ new Set(), sourceAvailable: false }) {
|
|
23915
|
-
const
|
|
23961
|
+
const candidates2 = [];
|
|
23916
23962
|
if (prebuilt) assertIndexUsable(prebuilt);
|
|
23917
23963
|
for (const wheel of prebuilt?.wheels ?? []) {
|
|
23918
23964
|
if (normalize2(wheel.name) !== normalize2(name)) continue;
|
|
@@ -23921,7 +23967,7 @@ async function fetchCandidates(client, name, allowSourceBuilds, prebuilt, reject
|
|
|
23921
23967
|
`${wheel.filename} in the wheel index was built for ABI ${wheel.abiId}, but this runtime implements ${EXTENSION_ABI.abiId}; rebuild it`
|
|
23922
23968
|
);
|
|
23923
23969
|
}
|
|
23924
|
-
|
|
23970
|
+
candidates2.push({
|
|
23925
23971
|
name: normalize2(wheel.name),
|
|
23926
23972
|
version: wheel.version,
|
|
23927
23973
|
kind: "sbx-wasm",
|
|
@@ -23932,13 +23978,13 @@ async function fetchCandidates(client, name, allowSourceBuilds, prebuilt, reject
|
|
|
23932
23978
|
indexedRequires: wheel.requires
|
|
23933
23979
|
});
|
|
23934
23980
|
}
|
|
23935
|
-
|
|
23936
|
-
if (isBuiltinOnly(normalize2(name))) return
|
|
23981
|
+
candidates2.push(...builtinCandidates(normalize2(name)));
|
|
23982
|
+
if (isBuiltinOnly(normalize2(name))) return candidates2;
|
|
23937
23983
|
let index;
|
|
23938
23984
|
try {
|
|
23939
23985
|
index = await client.json(`https://pypi.org/pypi/${name}/json`, { timeoutMs: 3e4 });
|
|
23940
23986
|
} catch (error) {
|
|
23941
|
-
if (
|
|
23987
|
+
if (candidates2.length > 0) return candidates2;
|
|
23942
23988
|
throw error;
|
|
23943
23989
|
}
|
|
23944
23990
|
for (const [version, files] of Object.entries(index.releases ?? {})) {
|
|
@@ -23951,7 +23997,7 @@ async function fetchCandidates(client, name, allowSourceBuilds, prebuilt, reject
|
|
|
23951
23997
|
rejected.versions.add(version);
|
|
23952
23998
|
continue;
|
|
23953
23999
|
}
|
|
23954
|
-
|
|
24000
|
+
candidates2.push({
|
|
23955
24001
|
name: normalize2(name),
|
|
23956
24002
|
version,
|
|
23957
24003
|
kind,
|
|
@@ -23962,7 +24008,7 @@ async function fetchCandidates(client, name, allowSourceBuilds, prebuilt, reject
|
|
|
23962
24008
|
});
|
|
23963
24009
|
}
|
|
23964
24010
|
}
|
|
23965
|
-
return
|
|
24011
|
+
return candidates2;
|
|
23966
24012
|
}
|
|
23967
24013
|
function newest(versions) {
|
|
23968
24014
|
return versions.reduce((a, b) => compareVersions(b, a, ">") ? b : a);
|
|
@@ -24259,17 +24305,17 @@ function createProcessService(ctx) {
|
|
|
24259
24305
|
return proc.pid;
|
|
24260
24306
|
},
|
|
24261
24307
|
async wait(pid, options) {
|
|
24262
|
-
const
|
|
24263
|
-
if (
|
|
24308
|
+
const candidates2 = pid > 0 ? [children.get(pid)].filter((p) => p !== void 0) : [...children.values()];
|
|
24309
|
+
if (candidates2.length === 0) throw new PosixError(Errno.ECHILD);
|
|
24264
24310
|
const reap = (proc) => {
|
|
24265
24311
|
children.delete(proc.pid);
|
|
24266
24312
|
return { pid: proc.pid, status: waitStatus(proc) };
|
|
24267
24313
|
};
|
|
24268
|
-
const done =
|
|
24314
|
+
const done = candidates2.find(exited);
|
|
24269
24315
|
if (done) return reap(done);
|
|
24270
24316
|
if (options & WNOHANG) return { pid: 0, status: 0 };
|
|
24271
|
-
await Promise.race(
|
|
24272
|
-
const finished =
|
|
24317
|
+
await Promise.race(candidates2.map((proc) => proc.wait()));
|
|
24318
|
+
const finished = candidates2.find(exited);
|
|
24273
24319
|
if (!finished) throw new PosixError(Errno.ECHILD);
|
|
24274
24320
|
return reap(finished);
|
|
24275
24321
|
},
|
|
@@ -26497,9 +26543,9 @@ function resolveVersion(metadata, range) {
|
|
|
26497
26543
|
const tag2 = metadata["dist-tags"]?.[range];
|
|
26498
26544
|
if (tag2) return tag2;
|
|
26499
26545
|
if (valid(range) && metadata.versions[range]) return range;
|
|
26500
|
-
const
|
|
26501
|
-
if (!
|
|
26502
|
-
return
|
|
26546
|
+
const found2 = maxSatisfying(Object.keys(metadata.versions), range === "latest" ? "*" : range, { includePrerelease: false });
|
|
26547
|
+
if (!found2) throw new Error(`No matching version found for ${metadata.name}@${range}`);
|
|
26548
|
+
return found2;
|
|
26503
26549
|
}
|
|
26504
26550
|
function verifyIntegrity(data, integrity, shasum, identity) {
|
|
26505
26551
|
if (integrity) {
|
|
@@ -26961,23 +27007,23 @@ var npm = defineCommand({
|
|
|
26961
27007
|
case "uninstall":
|
|
26962
27008
|
case "remove":
|
|
26963
27009
|
case "rm": {
|
|
26964
|
-
const
|
|
27010
|
+
const found2 = readManifest(ctx, root);
|
|
26965
27011
|
for (const name of rest.filter((a) => !a.startsWith("-"))) {
|
|
26966
27012
|
const target = join(root, "node_modules", name);
|
|
26967
27013
|
if (ctx.vfs.lexists(target)) ctx.vfs.rmrf(target, ctx.cred);
|
|
26968
|
-
if (
|
|
26969
|
-
delete
|
|
26970
|
-
delete
|
|
27014
|
+
if (found2) {
|
|
27015
|
+
delete found2.manifest.dependencies?.[name];
|
|
27016
|
+
delete found2.manifest.devDependencies?.[name];
|
|
26971
27017
|
}
|
|
26972
27018
|
ctx.line(`removed ${name}`);
|
|
26973
27019
|
}
|
|
26974
|
-
if (
|
|
27020
|
+
if (found2) writeManifest(ctx, found2.path, found2.manifest);
|
|
26975
27021
|
return 0;
|
|
26976
27022
|
}
|
|
26977
27023
|
case "ls":
|
|
26978
27024
|
case "list": {
|
|
26979
|
-
const
|
|
26980
|
-
ctx.line(`${
|
|
27025
|
+
const found2 = readManifest(ctx, root);
|
|
27026
|
+
ctx.line(`${found2?.manifest.name ?? basename(root)}@${found2?.manifest.version ?? "1.0.0"} ${root}`);
|
|
26981
27027
|
const modules = join(root, "node_modules");
|
|
26982
27028
|
if (!ctx.vfs.lexists(modules)) return 0;
|
|
26983
27029
|
const names = ctx.vfs.readdir(modules, ctx.cred).filter((n) => !n.startsWith("."));
|
|
@@ -26999,29 +27045,29 @@ var npm = defineCommand({
|
|
|
26999
27045
|
case "build": {
|
|
27000
27046
|
const scriptName = subcommand === "run" || subcommand === "run-script" ? rest[0] : subcommand;
|
|
27001
27047
|
const scriptArgs = subcommand === "run" || subcommand === "run-script" ? rest.slice(1) : rest;
|
|
27002
|
-
const
|
|
27003
|
-
if (!
|
|
27048
|
+
const found2 = readManifest(ctx, root);
|
|
27049
|
+
if (!found2) return ctx.fail("could not read package.json", 1);
|
|
27004
27050
|
if (scriptName === void 0) {
|
|
27005
|
-
ctx.line("Lifecycle scripts included in " + (
|
|
27006
|
-
for (const [name, body] of Object.entries(
|
|
27051
|
+
ctx.line("Lifecycle scripts included in " + (found2.manifest.name ?? "app") + ":");
|
|
27052
|
+
for (const [name, body] of Object.entries(found2.manifest.scripts ?? {})) {
|
|
27007
27053
|
ctx.line(` ${name}`);
|
|
27008
27054
|
ctx.line(` ${body}`);
|
|
27009
27055
|
}
|
|
27010
27056
|
return 0;
|
|
27011
27057
|
}
|
|
27012
|
-
const script =
|
|
27058
|
+
const script = found2.manifest.scripts?.[scriptName];
|
|
27013
27059
|
if (script === void 0) {
|
|
27014
|
-
if (scriptName === "start" &&
|
|
27015
|
-
return await runScript(ctx, root, `node ${
|
|
27060
|
+
if (scriptName === "start" && found2.manifest.main) {
|
|
27061
|
+
return await runScript(ctx, root, `node ${found2.manifest.main}`, scriptArgs, found2.manifest);
|
|
27016
27062
|
}
|
|
27017
27063
|
ctx.warn(`Missing script: "${scriptName}"`);
|
|
27018
27064
|
return 1;
|
|
27019
27065
|
}
|
|
27020
27066
|
ctx.line("");
|
|
27021
|
-
ctx.line(`> ${
|
|
27067
|
+
ctx.line(`> ${found2.manifest.name ?? "app"}@${found2.manifest.version ?? "1.0.0"} ${scriptName}`);
|
|
27022
27068
|
ctx.line(`> ${script}`);
|
|
27023
27069
|
ctx.line("");
|
|
27024
|
-
return await runScript(ctx, root, script, scriptArgs,
|
|
27070
|
+
return await runScript(ctx, root, script, scriptArgs, found2.manifest);
|
|
27025
27071
|
}
|
|
27026
27072
|
case "exec":
|
|
27027
27073
|
return await runScript(ctx, root, rest.join(" "), [], readManifest(ctx, root)?.manifest ?? {});
|
|
@@ -29457,23 +29503,23 @@ var CommonJsEngine = class {
|
|
|
29457
29503
|
const builtin = this.builtin(specifier);
|
|
29458
29504
|
if (builtin.found) return specifier;
|
|
29459
29505
|
if (specifier.startsWith("#")) {
|
|
29460
|
-
const
|
|
29461
|
-
if (
|
|
29506
|
+
const found2 = this.resolveImports(specifier, importer, kind);
|
|
29507
|
+
if (found2) return found2;
|
|
29462
29508
|
throw this.moduleNotFound(specifier, importer);
|
|
29463
29509
|
}
|
|
29464
29510
|
const baseDir = dirname(importer);
|
|
29465
29511
|
if (specifier.startsWith("/") || specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
29466
29512
|
const resolved = specifier.startsWith("/") ? clean(specifier) : resolve(baseDir, specifier);
|
|
29467
|
-
const
|
|
29468
|
-
if (
|
|
29513
|
+
const found2 = this.resolvePath(resolved, kind);
|
|
29514
|
+
if (found2) return found2;
|
|
29469
29515
|
} else {
|
|
29470
29516
|
const aliased = this.aliasFor(specifier);
|
|
29471
29517
|
if (aliased) {
|
|
29472
29518
|
const substituted = this.resolvePackage(aliased, baseDir, kind);
|
|
29473
29519
|
if (substituted) return substituted;
|
|
29474
29520
|
}
|
|
29475
|
-
const
|
|
29476
|
-
if (
|
|
29521
|
+
const found2 = this.resolvePackage(specifier, baseDir, kind);
|
|
29522
|
+
if (found2) return found2;
|
|
29477
29523
|
}
|
|
29478
29524
|
throw this.moduleNotFound(specifier, importer);
|
|
29479
29525
|
}
|
|
@@ -29639,8 +29685,8 @@ ${code}
|
|
|
29639
29685
|
continue;
|
|
29640
29686
|
}
|
|
29641
29687
|
for (const target of targets ?? []) {
|
|
29642
|
-
const
|
|
29643
|
-
if (
|
|
29688
|
+
const found2 = this.resolvePath(resolve(root, target), kind);
|
|
29689
|
+
if (found2) return found2;
|
|
29644
29690
|
}
|
|
29645
29691
|
}
|
|
29646
29692
|
return null;
|
|
@@ -29649,8 +29695,8 @@ ${code}
|
|
|
29649
29695
|
for (const field of ENTRY_FIELDS[kind]) {
|
|
29650
29696
|
const value = manifest?.[field];
|
|
29651
29697
|
if (typeof value === "string") {
|
|
29652
|
-
const
|
|
29653
|
-
if (
|
|
29698
|
+
const found2 = this.resolvePath(resolve(root, value), kind);
|
|
29699
|
+
if (found2) return found2;
|
|
29654
29700
|
}
|
|
29655
29701
|
}
|
|
29656
29702
|
return this.resolveIndex(root);
|
|
@@ -29673,8 +29719,8 @@ ${code}
|
|
|
29673
29719
|
continue;
|
|
29674
29720
|
}
|
|
29675
29721
|
for (const target of targets ?? []) {
|
|
29676
|
-
const
|
|
29677
|
-
if (
|
|
29722
|
+
const found2 = target.startsWith(".") ? this.resolvePath(resolve(root, target), kind) : this.resolvePackage(target, root, kind);
|
|
29723
|
+
if (found2) return found2;
|
|
29678
29724
|
}
|
|
29679
29725
|
}
|
|
29680
29726
|
return null;
|
|
@@ -36308,12 +36354,12 @@ async function loadNodeRolldownMemfsBinding() {
|
|
|
36308
36354
|
function resolveWorkerPath(node2) {
|
|
36309
36355
|
const { dirname: dirname3, existsSync, fileURLToPath: fileURLToPath2, join: join3 } = node2;
|
|
36310
36356
|
const here = dirname3(fileURLToPath2(import.meta.url));
|
|
36311
|
-
const
|
|
36357
|
+
const candidates2 = [
|
|
36312
36358
|
join3(here, WORKER_FILE),
|
|
36313
36359
|
/* src/tools → dist, for a checkout that has been built. */
|
|
36314
36360
|
join3(here, "..", "..", "dist", WORKER_FILE)
|
|
36315
36361
|
];
|
|
36316
|
-
return
|
|
36362
|
+
return candidates2.find((candidate) => existsSync(candidate)) ?? null;
|
|
36317
36363
|
}
|
|
36318
36364
|
function resolveSubpath(node2, require2, packageName, subpath) {
|
|
36319
36365
|
const { dirname: dirname3, join: join3, pathToFileURL: pathToFileURL2, readFileSync } = node2;
|
|
@@ -38667,17 +38713,17 @@ var Terminal = class {
|
|
|
38667
38713
|
const match2 = /(\S*)$/.exec(left);
|
|
38668
38714
|
const word = match2?.[1] ?? "";
|
|
38669
38715
|
const isFirstWord = left.slice(0, left.length - word.length).trim() === "";
|
|
38670
|
-
const
|
|
38671
|
-
if (
|
|
38672
|
-
if (
|
|
38673
|
-
const completion =
|
|
38716
|
+
const candidates2 = isFirstWord && !word.includes("/") ? this.completeCommand(word) : this.completePath(word);
|
|
38717
|
+
if (candidates2.length === 0) return;
|
|
38718
|
+
if (candidates2.length === 1) {
|
|
38719
|
+
const completion = candidates2[0];
|
|
38674
38720
|
const suffix = completion.slice(word.length);
|
|
38675
38721
|
this.buffer = this.buffer.slice(0, this.cursor) + suffix + this.buffer.slice(this.cursor);
|
|
38676
38722
|
this.cursor += suffix.length;
|
|
38677
38723
|
this.redraw();
|
|
38678
38724
|
return;
|
|
38679
38725
|
}
|
|
38680
|
-
const common = longestCommonPrefix(
|
|
38726
|
+
const common = longestCommonPrefix(candidates2);
|
|
38681
38727
|
if (common.length > word.length) {
|
|
38682
38728
|
const suffix = common.slice(word.length);
|
|
38683
38729
|
this.buffer = this.buffer.slice(0, this.cursor) + suffix + this.buffer.slice(this.cursor);
|
|
@@ -38685,7 +38731,7 @@ var Terminal = class {
|
|
|
38685
38731
|
this.redraw();
|
|
38686
38732
|
return;
|
|
38687
38733
|
}
|
|
38688
|
-
this.write("\r\n" + formatColumns(
|
|
38734
|
+
this.write("\r\n" + formatColumns(candidates2, this.columns) + "\r\n");
|
|
38689
38735
|
this.redraw();
|
|
38690
38736
|
}
|
|
38691
38737
|
completeCommand(word) {
|