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.cjs
CHANGED
|
@@ -622,32 +622,32 @@ var init_variables = __esm({
|
|
|
622
622
|
return this.find(name) !== void 0;
|
|
623
623
|
}
|
|
624
624
|
get(name) {
|
|
625
|
-
const
|
|
626
|
-
if (!
|
|
627
|
-
if (
|
|
628
|
-
return
|
|
625
|
+
const found2 = this.find(name);
|
|
626
|
+
if (!found2) return void 0;
|
|
627
|
+
if (found2.entry.array) return found2.entry.array[0] ?? "";
|
|
628
|
+
return found2.entry.value;
|
|
629
629
|
}
|
|
630
630
|
entry(name) {
|
|
631
631
|
return this.find(name)?.entry;
|
|
632
632
|
}
|
|
633
633
|
getArray(name) {
|
|
634
|
-
const
|
|
635
|
-
if (!
|
|
636
|
-
return
|
|
634
|
+
const found2 = this.find(name);
|
|
635
|
+
if (!found2) return void 0;
|
|
636
|
+
return found2.entry.array ?? [found2.entry.value];
|
|
637
637
|
}
|
|
638
638
|
isArray(name) {
|
|
639
639
|
return this.find(name)?.entry.array !== void 0;
|
|
640
640
|
}
|
|
641
641
|
set(name, value, attrs = {}) {
|
|
642
|
-
const
|
|
643
|
-
if (
|
|
642
|
+
const found2 = this.find(name);
|
|
643
|
+
if (found2?.entry.readonly) throw new ReadonlyVariableError(name);
|
|
644
644
|
let next = value;
|
|
645
|
-
if (
|
|
646
|
-
if (
|
|
647
|
-
if (
|
|
648
|
-
|
|
649
|
-
delete
|
|
650
|
-
Object.assign(
|
|
645
|
+
if (found2?.entry.upper || attrs.upper) next = next.toUpperCase();
|
|
646
|
+
if (found2?.entry.lower || attrs.lower) next = next.toLowerCase();
|
|
647
|
+
if (found2) {
|
|
648
|
+
found2.entry.value = next;
|
|
649
|
+
delete found2.entry.array;
|
|
650
|
+
Object.assign(found2.entry, attrs);
|
|
651
651
|
} else {
|
|
652
652
|
this.scopes[this.scopes.length - 1].set(name, { value: next, ...attrs });
|
|
653
653
|
}
|
|
@@ -657,28 +657,28 @@ var init_variables = __esm({
|
|
|
657
657
|
this.scopes[this.scopes.length - 1].set(name, { value, ...attrs });
|
|
658
658
|
}
|
|
659
659
|
setArray(name, values, attrs = {}) {
|
|
660
|
-
const
|
|
661
|
-
if (
|
|
662
|
-
if (
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
Object.assign(
|
|
660
|
+
const found2 = this.find(name);
|
|
661
|
+
if (found2?.entry.readonly) throw new ReadonlyVariableError(name);
|
|
662
|
+
if (found2) {
|
|
663
|
+
found2.entry.array = values.slice();
|
|
664
|
+
found2.entry.value = values[0] ?? "";
|
|
665
|
+
Object.assign(found2.entry, attrs);
|
|
666
666
|
} else {
|
|
667
667
|
this.scopes[this.scopes.length - 1].set(name, { value: values[0] ?? "", array: values.slice(), ...attrs });
|
|
668
668
|
}
|
|
669
669
|
}
|
|
670
670
|
setIndex(name, index, value) {
|
|
671
|
-
const
|
|
672
|
-
if (
|
|
673
|
-
const arr =
|
|
671
|
+
const found2 = this.find(name);
|
|
672
|
+
if (found2?.entry.readonly) throw new ReadonlyVariableError(name);
|
|
673
|
+
const arr = found2?.entry.array ?? (found2 ? [found2.entry.value] : []);
|
|
674
674
|
while (arr.length < index) arr.push("");
|
|
675
675
|
arr[index] = value;
|
|
676
676
|
this.setArray(name, arr);
|
|
677
677
|
}
|
|
678
678
|
append(name, value) {
|
|
679
|
-
const
|
|
680
|
-
if (
|
|
681
|
-
this.setArray(name, [...
|
|
679
|
+
const found2 = this.find(name);
|
|
680
|
+
if (found2?.entry.array) {
|
|
681
|
+
this.setArray(name, [...found2.entry.array, value]);
|
|
682
682
|
return;
|
|
683
683
|
}
|
|
684
684
|
this.set(name, (this.get(name) ?? "") + value);
|
|
@@ -695,13 +695,13 @@ var init_variables = __esm({
|
|
|
695
695
|
return false;
|
|
696
696
|
}
|
|
697
697
|
export(name, exported = true) {
|
|
698
|
-
const
|
|
699
|
-
if (
|
|
698
|
+
const found2 = this.find(name);
|
|
699
|
+
if (found2) found2.entry.exported = exported;
|
|
700
700
|
else this.scopes[this.scopes.length - 1].set(name, { value: "", exported });
|
|
701
701
|
}
|
|
702
702
|
markReadonly(name) {
|
|
703
|
-
const
|
|
704
|
-
if (
|
|
703
|
+
const found2 = this.find(name);
|
|
704
|
+
if (found2) found2.entry.readonly = true;
|
|
705
705
|
else this.scopes[this.scopes.length - 1].set(name, { value: "", readonly: true });
|
|
706
706
|
}
|
|
707
707
|
names() {
|
|
@@ -2947,8 +2947,8 @@ async function builtinSource({ shell, argv, io }) {
|
|
|
2947
2947
|
}
|
|
2948
2948
|
let path = resolve(shell.cwd, target);
|
|
2949
2949
|
if (!target.includes("/")) {
|
|
2950
|
-
const
|
|
2951
|
-
if (
|
|
2950
|
+
const found2 = shell.kernel.which(target, shell.cwd, shell.vars.environment(), shell.cred);
|
|
2951
|
+
if (found2) path = found2;
|
|
2952
2952
|
}
|
|
2953
2953
|
let text2;
|
|
2954
2954
|
try {
|
|
@@ -3582,32 +3582,32 @@ function builtinType({ shell, argv, io }) {
|
|
|
3582
3582
|
const names = args.filter((a) => !a.startsWith("-"));
|
|
3583
3583
|
let status = 0;
|
|
3584
3584
|
for (const name of names) {
|
|
3585
|
-
const
|
|
3585
|
+
const found2 = [];
|
|
3586
3586
|
if (shell.aliases.has(name)) {
|
|
3587
|
-
if (typeOnly)
|
|
3588
|
-
else if (!pathOnly)
|
|
3587
|
+
if (typeOnly) found2.push("alias");
|
|
3588
|
+
else if (!pathOnly) found2.push(`${name} is aliased to \`${shell.aliases.get(name)}'`);
|
|
3589
3589
|
}
|
|
3590
3590
|
if (shell.functions.has(name)) {
|
|
3591
|
-
if (typeOnly)
|
|
3592
|
-
else if (!pathOnly)
|
|
3591
|
+
if (typeOnly) found2.push("function");
|
|
3592
|
+
else if (!pathOnly) found2.push(`${name} is a function`);
|
|
3593
3593
|
}
|
|
3594
3594
|
if (isBuiltinName(name)) {
|
|
3595
|
-
if (typeOnly)
|
|
3596
|
-
else if (!pathOnly)
|
|
3595
|
+
if (typeOnly) found2.push("builtin");
|
|
3596
|
+
else if (!pathOnly) found2.push(`${name} is a shell builtin`);
|
|
3597
3597
|
}
|
|
3598
3598
|
const path = shell.kernel.which(name, shell.cwd, shell.vars.environment(), shell.cred);
|
|
3599
3599
|
if (path) {
|
|
3600
|
-
if (typeOnly)
|
|
3601
|
-
else if (pathOnly)
|
|
3602
|
-
else
|
|
3600
|
+
if (typeOnly) found2.push("file");
|
|
3601
|
+
else if (pathOnly) found2.push(path);
|
|
3602
|
+
else found2.push(`${name} is ${path}`);
|
|
3603
3603
|
}
|
|
3604
|
-
if (
|
|
3604
|
+
if (found2.length === 0) {
|
|
3605
3605
|
if (!pathOnly && !typeOnly) io.stderr.write(`type: ${name}: not found
|
|
3606
3606
|
`);
|
|
3607
3607
|
status = 1;
|
|
3608
3608
|
continue;
|
|
3609
3609
|
}
|
|
3610
|
-
for (const line of all ?
|
|
3610
|
+
for (const line of all ? found2 : [found2[0]]) io.stdout.write(line + "\n");
|
|
3611
3611
|
}
|
|
3612
3612
|
return status;
|
|
3613
3613
|
}
|
|
@@ -5964,9 +5964,9 @@ function parseArgs(argv, specs, opts = {}) {
|
|
|
5964
5964
|
const resolveLong = (name) => {
|
|
5965
5965
|
const exact = byLong.get(name);
|
|
5966
5966
|
if (exact) return exact;
|
|
5967
|
-
const
|
|
5968
|
-
if (
|
|
5969
|
-
if (
|
|
5967
|
+
const candidates2 = [...byLong.keys()].filter((k) => k.startsWith(name));
|
|
5968
|
+
if (candidates2.length === 1) return byLong.get(candidates2[0]);
|
|
5969
|
+
if (candidates2.length > 1) throw new UsageError(`option '--${name}' is ambiguous`);
|
|
5970
5970
|
return void 0;
|
|
5971
5971
|
};
|
|
5972
5972
|
for (; i < argv.length; i++) {
|
|
@@ -6485,19 +6485,19 @@ var WasiHost = class {
|
|
|
6485
6485
|
}
|
|
6486
6486
|
// ── descriptors ──────────────────────────────────────────────────────────
|
|
6487
6487
|
get(fd) {
|
|
6488
|
-
const
|
|
6489
|
-
if (!
|
|
6490
|
-
return
|
|
6488
|
+
const found2 = this.fds.get(fd);
|
|
6489
|
+
if (!found2) throw new WasiError(WASI_EBADF);
|
|
6490
|
+
return found2;
|
|
6491
6491
|
}
|
|
6492
6492
|
dir(fd) {
|
|
6493
|
-
const
|
|
6494
|
-
if (
|
|
6495
|
-
return
|
|
6493
|
+
const found2 = this.get(fd);
|
|
6494
|
+
if (found2.kind !== "dir") throw new WasiError(WASI_ENOTDIR);
|
|
6495
|
+
return found2;
|
|
6496
6496
|
}
|
|
6497
6497
|
file(fd) {
|
|
6498
|
-
const
|
|
6499
|
-
if (
|
|
6500
|
-
return
|
|
6498
|
+
const found2 = this.get(fd);
|
|
6499
|
+
if (found2.kind !== "file") throw new WasiError(WASI_EBADF);
|
|
6500
|
+
return found2;
|
|
6501
6501
|
}
|
|
6502
6502
|
/**
|
|
6503
6503
|
* Resolve a guest path against a directory descriptor.
|
|
@@ -7442,13 +7442,13 @@ var Kernel = class {
|
|
|
7442
7442
|
* Find `name` the way `execvp` does. Returns null when nothing matches.
|
|
7443
7443
|
*/
|
|
7444
7444
|
resolveExecutable(name, cwd, env2, cred = ROOT_CRED) {
|
|
7445
|
-
const
|
|
7445
|
+
const candidates2 = [];
|
|
7446
7446
|
if (name.includes("/")) {
|
|
7447
|
-
|
|
7447
|
+
candidates2.push(resolve(cwd, name));
|
|
7448
7448
|
} else {
|
|
7449
|
-
for (const dir3 of this.pathDirs(env2))
|
|
7449
|
+
for (const dir3 of this.pathDirs(env2)) candidates2.push(join(dir3, name));
|
|
7450
7450
|
}
|
|
7451
|
-
for (const candidate of
|
|
7451
|
+
for (const candidate of candidates2) {
|
|
7452
7452
|
let real;
|
|
7453
7453
|
try {
|
|
7454
7454
|
real = this.vfs.realpath(candidate, cred);
|
|
@@ -8424,10 +8424,55 @@ function isBrowser() {
|
|
|
8424
8424
|
}
|
|
8425
8425
|
function browserBlocked(hostname, message) {
|
|
8426
8426
|
return new Error(
|
|
8427
|
-
`${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.
|
|
8427
|
+
`${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.`
|
|
8428
8428
|
);
|
|
8429
8429
|
}
|
|
8430
8430
|
|
|
8431
|
+
// src/net/discover-egress.ts
|
|
8432
|
+
var EGRESS_PATH = "/__sandboxedjs__/egress";
|
|
8433
|
+
var EGRESS_PATHS = [
|
|
8434
|
+
EGRESS_PATH,
|
|
8435
|
+
`/api${EGRESS_PATH}`,
|
|
8436
|
+
"/.netlify/functions/sandboxedjs-egress"
|
|
8437
|
+
];
|
|
8438
|
+
var EGRESS_MARKER = { sandboxedjs: "egress", protocol: 1 };
|
|
8439
|
+
var CLI_PORT = 4181;
|
|
8440
|
+
var found = null;
|
|
8441
|
+
var PROBE_TIMEOUT_MS = 1500;
|
|
8442
|
+
async function isEgress(url, fetchImpl) {
|
|
8443
|
+
const control = new AbortController();
|
|
8444
|
+
const timer = setTimeout(() => control.abort(), PROBE_TIMEOUT_MS);
|
|
8445
|
+
try {
|
|
8446
|
+
const answer = await fetchImpl(url, { method: "GET", signal: control.signal });
|
|
8447
|
+
if (!answer.ok) return false;
|
|
8448
|
+
const payload = await answer.json();
|
|
8449
|
+
return payload?.sandboxedjs === EGRESS_MARKER.sandboxedjs;
|
|
8450
|
+
} catch {
|
|
8451
|
+
return false;
|
|
8452
|
+
} finally {
|
|
8453
|
+
clearTimeout(timer);
|
|
8454
|
+
}
|
|
8455
|
+
}
|
|
8456
|
+
function candidates() {
|
|
8457
|
+
const origin = globalThis.location?.origin;
|
|
8458
|
+
const list = [];
|
|
8459
|
+
if (origin && /^https?:/.test(origin)) list.push(...EGRESS_PATHS.map((path) => `${origin}${path}`));
|
|
8460
|
+
list.push(`http://127.0.0.1:${CLI_PORT}/`);
|
|
8461
|
+
return list;
|
|
8462
|
+
}
|
|
8463
|
+
async function discoverEgress(fetchImpl = fetch) {
|
|
8464
|
+
if (!isBrowser()) return null;
|
|
8465
|
+
if (!found) {
|
|
8466
|
+
found = (async () => {
|
|
8467
|
+
const list = candidates();
|
|
8468
|
+
const answers = await Promise.all(list.map((candidate) => isEgress(candidate, fetchImpl)));
|
|
8469
|
+
const at = answers.findIndex(Boolean);
|
|
8470
|
+
return at === -1 ? null : list[at];
|
|
8471
|
+
})();
|
|
8472
|
+
}
|
|
8473
|
+
return await found;
|
|
8474
|
+
}
|
|
8475
|
+
|
|
8431
8476
|
// src/net/policy.ts
|
|
8432
8477
|
function isLoopbackHostname(hostname) {
|
|
8433
8478
|
const host2 = hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
@@ -8470,7 +8515,8 @@ function policedFetch(policy, fetchImpl) {
|
|
|
8470
8515
|
if (!outboundAllowed(policy, url)) {
|
|
8471
8516
|
throw Object.assign(new TypeError("fetch failed"), { cause: outboundBlockedError(url) });
|
|
8472
8517
|
}
|
|
8473
|
-
|
|
8518
|
+
const proxy = policy.proxy ?? await discoverEgress(fetchImpl);
|
|
8519
|
+
if (proxy) return await fetchThroughProxy(proxy, fetchImpl, input, init);
|
|
8474
8520
|
try {
|
|
8475
8521
|
return await fetchImpl(input, init);
|
|
8476
8522
|
} catch (error) {
|
|
@@ -9006,7 +9052,7 @@ var Lexer = class _Lexer {
|
|
|
9006
9052
|
const quoted = /['"\\]/.test(rawTag);
|
|
9007
9053
|
const tag2 = rawTag.replace(/['"\\]/g, "");
|
|
9008
9054
|
const lines = [];
|
|
9009
|
-
let
|
|
9055
|
+
let found2 = false;
|
|
9010
9056
|
while (this.pos < this.src.length) {
|
|
9011
9057
|
let eol = this.src.indexOf("\n", this.pos);
|
|
9012
9058
|
if (eol < 0) eol = this.src.length;
|
|
@@ -9014,13 +9060,13 @@ var Lexer = class _Lexer {
|
|
|
9014
9060
|
this.pos = eol + 1;
|
|
9015
9061
|
const compare = stripTabs ? rawLine.replace(/^\t+/, "") : rawLine;
|
|
9016
9062
|
if (compare === tag2) {
|
|
9017
|
-
|
|
9063
|
+
found2 = true;
|
|
9018
9064
|
break;
|
|
9019
9065
|
}
|
|
9020
9066
|
lines.push(stripTabs ? rawLine.replace(/^\t+/, "") : rawLine);
|
|
9021
9067
|
if (eol >= this.src.length) break;
|
|
9022
9068
|
}
|
|
9023
|
-
if (!
|
|
9069
|
+
if (!found2) {
|
|
9024
9070
|
throw new IncompleteInputError(`here-document delimited by end-of-file (wanted \`${tag2}')`, opToken.pos);
|
|
9025
9071
|
}
|
|
9026
9072
|
opToken.heredoc = { tag: tag2, stripTabs, quoted, body: lines.length ? lines.join("\n") + "\n" : "" };
|
|
@@ -14475,8 +14521,8 @@ var Interpreter = class {
|
|
|
14475
14521
|
for (let i = this.locals.length - 1; i >= 0; i--) {
|
|
14476
14522
|
const scope = this.locals[i];
|
|
14477
14523
|
if (scope.has(name)) {
|
|
14478
|
-
const
|
|
14479
|
-
return
|
|
14524
|
+
const found2 = scope.get(name);
|
|
14525
|
+
return found2 instanceof Map ? Value.uninitialized : found2;
|
|
14480
14526
|
}
|
|
14481
14527
|
}
|
|
14482
14528
|
if (name === "NF") {
|
|
@@ -14508,8 +14554,8 @@ var Interpreter = class {
|
|
|
14508
14554
|
for (let i = this.locals.length - 1; i >= 0; i--) {
|
|
14509
14555
|
const scope = this.locals[i];
|
|
14510
14556
|
if (scope.has(name)) {
|
|
14511
|
-
const
|
|
14512
|
-
if (
|
|
14557
|
+
const found2 = scope.get(name);
|
|
14558
|
+
if (found2 instanceof Map) return found2;
|
|
14513
14559
|
const created = /* @__PURE__ */ new Map();
|
|
14514
14560
|
scope.set(name, created);
|
|
14515
14561
|
return created;
|
|
@@ -17587,7 +17633,7 @@ async function performRequest(ctx, url, init) {
|
|
|
17587
17633
|
`outbound network access to ${url.hostname} is disabled for this container (enable with network: { allowOutbound: true })`
|
|
17588
17634
|
);
|
|
17589
17635
|
}
|
|
17590
|
-
const proxy = ctx.kernel.net.proxy;
|
|
17636
|
+
const proxy = ctx.kernel.net.proxy ?? await discoverEgress();
|
|
17591
17637
|
if (proxy) {
|
|
17592
17638
|
const result = await proxyExchange(proxy, {
|
|
17593
17639
|
url: url.toString(),
|
|
@@ -18558,14 +18604,14 @@ var apropos = defineCommand({
|
|
|
18558
18604
|
return 1;
|
|
18559
18605
|
}
|
|
18560
18606
|
const patterns = ctx.args.map((a) => new RegExp(a, "i"));
|
|
18561
|
-
let
|
|
18607
|
+
let found2 = 0;
|
|
18562
18608
|
for (const command of ctx.kernel.commands.all()) {
|
|
18563
18609
|
const haystack = `${command.name} ${command.summary ?? ""}`;
|
|
18564
18610
|
if (!patterns.some((p) => p.test(haystack))) continue;
|
|
18565
|
-
|
|
18611
|
+
found2++;
|
|
18566
18612
|
ctx.line(`${command.name} (1)${" ".repeat(Math.max(1, 16 - command.name.length))}- ${command.summary ?? ""}`);
|
|
18567
18613
|
}
|
|
18568
|
-
if (
|
|
18614
|
+
if (found2 === 0) {
|
|
18569
18615
|
ctx.line(`${ctx.args.join(" ")}: nothing appropriate.`);
|
|
18570
18616
|
return 1;
|
|
18571
18617
|
}
|
|
@@ -19589,8 +19635,8 @@ ${prelude}${preloadRequires(preloads)}${source}
|
|
|
19589
19635
|
}
|
|
19590
19636
|
function resolveScript(ctx, operand) {
|
|
19591
19637
|
const base2 = ctx.path(operand);
|
|
19592
|
-
const
|
|
19593
|
-
for (const candidate of
|
|
19638
|
+
const candidates2 = [base2, `${base2}.js`, `${base2}.mjs`, `${base2}.cjs`, `${base2}.json`];
|
|
19639
|
+
for (const candidate of candidates2) {
|
|
19594
19640
|
try {
|
|
19595
19641
|
const st = ctx.vfs.stat(candidate, { cred: ctx.cred });
|
|
19596
19642
|
if (st.isFile()) return ctx.vfs.realpath(candidate, ctx.cred);
|
|
@@ -21057,7 +21103,7 @@ var wheels_default = {
|
|
|
21057
21103
|
|
|
21058
21104
|
// package.json
|
|
21059
21105
|
var package_default = {
|
|
21060
|
-
version: "0.2.
|
|
21106
|
+
version: "0.2.8"};
|
|
21061
21107
|
|
|
21062
21108
|
// src/python/extension-abi.ts
|
|
21063
21109
|
var EXTENSION_ABI = {
|
|
@@ -23929,7 +23975,7 @@ function explain(name, constraints, chosenVersion, available2 = []) {
|
|
|
23929
23975
|
return lines;
|
|
23930
23976
|
}
|
|
23931
23977
|
async function fetchCandidates(client, name, allowSourceBuilds, prebuilt, rejected = { versions: /* @__PURE__ */ new Set(), sourceAvailable: false }) {
|
|
23932
|
-
const
|
|
23978
|
+
const candidates2 = [];
|
|
23933
23979
|
if (prebuilt) assertIndexUsable(prebuilt);
|
|
23934
23980
|
for (const wheel of prebuilt?.wheels ?? []) {
|
|
23935
23981
|
if (normalize2(wheel.name) !== normalize2(name)) continue;
|
|
@@ -23938,7 +23984,7 @@ async function fetchCandidates(client, name, allowSourceBuilds, prebuilt, reject
|
|
|
23938
23984
|
`${wheel.filename} in the wheel index was built for ABI ${wheel.abiId}, but this runtime implements ${EXTENSION_ABI.abiId}; rebuild it`
|
|
23939
23985
|
);
|
|
23940
23986
|
}
|
|
23941
|
-
|
|
23987
|
+
candidates2.push({
|
|
23942
23988
|
name: normalize2(wheel.name),
|
|
23943
23989
|
version: wheel.version,
|
|
23944
23990
|
kind: "sbx-wasm",
|
|
@@ -23949,13 +23995,13 @@ async function fetchCandidates(client, name, allowSourceBuilds, prebuilt, reject
|
|
|
23949
23995
|
indexedRequires: wheel.requires
|
|
23950
23996
|
});
|
|
23951
23997
|
}
|
|
23952
|
-
|
|
23953
|
-
if (isBuiltinOnly(normalize2(name))) return
|
|
23998
|
+
candidates2.push(...builtinCandidates(normalize2(name)));
|
|
23999
|
+
if (isBuiltinOnly(normalize2(name))) return candidates2;
|
|
23954
24000
|
let index;
|
|
23955
24001
|
try {
|
|
23956
24002
|
index = await client.json(`https://pypi.org/pypi/${name}/json`, { timeoutMs: 3e4 });
|
|
23957
24003
|
} catch (error) {
|
|
23958
|
-
if (
|
|
24004
|
+
if (candidates2.length > 0) return candidates2;
|
|
23959
24005
|
throw error;
|
|
23960
24006
|
}
|
|
23961
24007
|
for (const [version, files] of Object.entries(index.releases ?? {})) {
|
|
@@ -23968,7 +24014,7 @@ async function fetchCandidates(client, name, allowSourceBuilds, prebuilt, reject
|
|
|
23968
24014
|
rejected.versions.add(version);
|
|
23969
24015
|
continue;
|
|
23970
24016
|
}
|
|
23971
|
-
|
|
24017
|
+
candidates2.push({
|
|
23972
24018
|
name: normalize2(name),
|
|
23973
24019
|
version,
|
|
23974
24020
|
kind,
|
|
@@ -23979,7 +24025,7 @@ async function fetchCandidates(client, name, allowSourceBuilds, prebuilt, reject
|
|
|
23979
24025
|
});
|
|
23980
24026
|
}
|
|
23981
24027
|
}
|
|
23982
|
-
return
|
|
24028
|
+
return candidates2;
|
|
23983
24029
|
}
|
|
23984
24030
|
function newest(versions) {
|
|
23985
24031
|
return versions.reduce((a, b) => compareVersions(b, a, ">") ? b : a);
|
|
@@ -24276,17 +24322,17 @@ function createProcessService(ctx) {
|
|
|
24276
24322
|
return proc.pid;
|
|
24277
24323
|
},
|
|
24278
24324
|
async wait(pid, options) {
|
|
24279
|
-
const
|
|
24280
|
-
if (
|
|
24325
|
+
const candidates2 = pid > 0 ? [children.get(pid)].filter((p) => p !== void 0) : [...children.values()];
|
|
24326
|
+
if (candidates2.length === 0) throw new PosixError(Errno.ECHILD);
|
|
24281
24327
|
const reap = (proc) => {
|
|
24282
24328
|
children.delete(proc.pid);
|
|
24283
24329
|
return { pid: proc.pid, status: waitStatus(proc) };
|
|
24284
24330
|
};
|
|
24285
|
-
const done =
|
|
24331
|
+
const done = candidates2.find(exited);
|
|
24286
24332
|
if (done) return reap(done);
|
|
24287
24333
|
if (options & WNOHANG) return { pid: 0, status: 0 };
|
|
24288
|
-
await Promise.race(
|
|
24289
|
-
const finished =
|
|
24334
|
+
await Promise.race(candidates2.map((proc) => proc.wait()));
|
|
24335
|
+
const finished = candidates2.find(exited);
|
|
24290
24336
|
if (!finished) throw new PosixError(Errno.ECHILD);
|
|
24291
24337
|
return reap(finished);
|
|
24292
24338
|
},
|
|
@@ -26514,9 +26560,9 @@ function resolveVersion(metadata, range) {
|
|
|
26514
26560
|
const tag2 = metadata["dist-tags"]?.[range];
|
|
26515
26561
|
if (tag2) return tag2;
|
|
26516
26562
|
if (semver.valid(range) && metadata.versions[range]) return range;
|
|
26517
|
-
const
|
|
26518
|
-
if (!
|
|
26519
|
-
return
|
|
26563
|
+
const found2 = semver.maxSatisfying(Object.keys(metadata.versions), range === "latest" ? "*" : range, { includePrerelease: false });
|
|
26564
|
+
if (!found2) throw new Error(`No matching version found for ${metadata.name}@${range}`);
|
|
26565
|
+
return found2;
|
|
26520
26566
|
}
|
|
26521
26567
|
function verifyIntegrity(data, integrity, shasum, identity) {
|
|
26522
26568
|
if (integrity) {
|
|
@@ -26978,23 +27024,23 @@ var npm = defineCommand({
|
|
|
26978
27024
|
case "uninstall":
|
|
26979
27025
|
case "remove":
|
|
26980
27026
|
case "rm": {
|
|
26981
|
-
const
|
|
27027
|
+
const found2 = readManifest(ctx, root);
|
|
26982
27028
|
for (const name of rest.filter((a) => !a.startsWith("-"))) {
|
|
26983
27029
|
const target = join(root, "node_modules", name);
|
|
26984
27030
|
if (ctx.vfs.lexists(target)) ctx.vfs.rmrf(target, ctx.cred);
|
|
26985
|
-
if (
|
|
26986
|
-
delete
|
|
26987
|
-
delete
|
|
27031
|
+
if (found2) {
|
|
27032
|
+
delete found2.manifest.dependencies?.[name];
|
|
27033
|
+
delete found2.manifest.devDependencies?.[name];
|
|
26988
27034
|
}
|
|
26989
27035
|
ctx.line(`removed ${name}`);
|
|
26990
27036
|
}
|
|
26991
|
-
if (
|
|
27037
|
+
if (found2) writeManifest(ctx, found2.path, found2.manifest);
|
|
26992
27038
|
return 0;
|
|
26993
27039
|
}
|
|
26994
27040
|
case "ls":
|
|
26995
27041
|
case "list": {
|
|
26996
|
-
const
|
|
26997
|
-
ctx.line(`${
|
|
27042
|
+
const found2 = readManifest(ctx, root);
|
|
27043
|
+
ctx.line(`${found2?.manifest.name ?? basename(root)}@${found2?.manifest.version ?? "1.0.0"} ${root}`);
|
|
26998
27044
|
const modules = join(root, "node_modules");
|
|
26999
27045
|
if (!ctx.vfs.lexists(modules)) return 0;
|
|
27000
27046
|
const names = ctx.vfs.readdir(modules, ctx.cred).filter((n) => !n.startsWith("."));
|
|
@@ -27016,29 +27062,29 @@ var npm = defineCommand({
|
|
|
27016
27062
|
case "build": {
|
|
27017
27063
|
const scriptName = subcommand === "run" || subcommand === "run-script" ? rest[0] : subcommand;
|
|
27018
27064
|
const scriptArgs = subcommand === "run" || subcommand === "run-script" ? rest.slice(1) : rest;
|
|
27019
|
-
const
|
|
27020
|
-
if (!
|
|
27065
|
+
const found2 = readManifest(ctx, root);
|
|
27066
|
+
if (!found2) return ctx.fail("could not read package.json", 1);
|
|
27021
27067
|
if (scriptName === void 0) {
|
|
27022
|
-
ctx.line("Lifecycle scripts included in " + (
|
|
27023
|
-
for (const [name, body] of Object.entries(
|
|
27068
|
+
ctx.line("Lifecycle scripts included in " + (found2.manifest.name ?? "app") + ":");
|
|
27069
|
+
for (const [name, body] of Object.entries(found2.manifest.scripts ?? {})) {
|
|
27024
27070
|
ctx.line(` ${name}`);
|
|
27025
27071
|
ctx.line(` ${body}`);
|
|
27026
27072
|
}
|
|
27027
27073
|
return 0;
|
|
27028
27074
|
}
|
|
27029
|
-
const script =
|
|
27075
|
+
const script = found2.manifest.scripts?.[scriptName];
|
|
27030
27076
|
if (script === void 0) {
|
|
27031
|
-
if (scriptName === "start" &&
|
|
27032
|
-
return await runScript(ctx, root, `node ${
|
|
27077
|
+
if (scriptName === "start" && found2.manifest.main) {
|
|
27078
|
+
return await runScript(ctx, root, `node ${found2.manifest.main}`, scriptArgs, found2.manifest);
|
|
27033
27079
|
}
|
|
27034
27080
|
ctx.warn(`Missing script: "${scriptName}"`);
|
|
27035
27081
|
return 1;
|
|
27036
27082
|
}
|
|
27037
27083
|
ctx.line("");
|
|
27038
|
-
ctx.line(`> ${
|
|
27084
|
+
ctx.line(`> ${found2.manifest.name ?? "app"}@${found2.manifest.version ?? "1.0.0"} ${scriptName}`);
|
|
27039
27085
|
ctx.line(`> ${script}`);
|
|
27040
27086
|
ctx.line("");
|
|
27041
|
-
return await runScript(ctx, root, script, scriptArgs,
|
|
27087
|
+
return await runScript(ctx, root, script, scriptArgs, found2.manifest);
|
|
27042
27088
|
}
|
|
27043
27089
|
case "exec":
|
|
27044
27090
|
return await runScript(ctx, root, rest.join(" "), [], readManifest(ctx, root)?.manifest ?? {});
|
|
@@ -29474,23 +29520,23 @@ var CommonJsEngine = class {
|
|
|
29474
29520
|
const builtin = this.builtin(specifier);
|
|
29475
29521
|
if (builtin.found) return specifier;
|
|
29476
29522
|
if (specifier.startsWith("#")) {
|
|
29477
|
-
const
|
|
29478
|
-
if (
|
|
29523
|
+
const found2 = this.resolveImports(specifier, importer, kind);
|
|
29524
|
+
if (found2) return found2;
|
|
29479
29525
|
throw this.moduleNotFound(specifier, importer);
|
|
29480
29526
|
}
|
|
29481
29527
|
const baseDir = dirname(importer);
|
|
29482
29528
|
if (specifier.startsWith("/") || specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
29483
29529
|
const resolved = specifier.startsWith("/") ? clean(specifier) : resolve(baseDir, specifier);
|
|
29484
|
-
const
|
|
29485
|
-
if (
|
|
29530
|
+
const found2 = this.resolvePath(resolved, kind);
|
|
29531
|
+
if (found2) return found2;
|
|
29486
29532
|
} else {
|
|
29487
29533
|
const aliased = this.aliasFor(specifier);
|
|
29488
29534
|
if (aliased) {
|
|
29489
29535
|
const substituted = this.resolvePackage(aliased, baseDir, kind);
|
|
29490
29536
|
if (substituted) return substituted;
|
|
29491
29537
|
}
|
|
29492
|
-
const
|
|
29493
|
-
if (
|
|
29538
|
+
const found2 = this.resolvePackage(specifier, baseDir, kind);
|
|
29539
|
+
if (found2) return found2;
|
|
29494
29540
|
}
|
|
29495
29541
|
throw this.moduleNotFound(specifier, importer);
|
|
29496
29542
|
}
|
|
@@ -29656,8 +29702,8 @@ ${code}
|
|
|
29656
29702
|
continue;
|
|
29657
29703
|
}
|
|
29658
29704
|
for (const target of targets ?? []) {
|
|
29659
|
-
const
|
|
29660
|
-
if (
|
|
29705
|
+
const found2 = this.resolvePath(resolve(root, target), kind);
|
|
29706
|
+
if (found2) return found2;
|
|
29661
29707
|
}
|
|
29662
29708
|
}
|
|
29663
29709
|
return null;
|
|
@@ -29666,8 +29712,8 @@ ${code}
|
|
|
29666
29712
|
for (const field of ENTRY_FIELDS[kind]) {
|
|
29667
29713
|
const value = manifest?.[field];
|
|
29668
29714
|
if (typeof value === "string") {
|
|
29669
|
-
const
|
|
29670
|
-
if (
|
|
29715
|
+
const found2 = this.resolvePath(resolve(root, value), kind);
|
|
29716
|
+
if (found2) return found2;
|
|
29671
29717
|
}
|
|
29672
29718
|
}
|
|
29673
29719
|
return this.resolveIndex(root);
|
|
@@ -29690,8 +29736,8 @@ ${code}
|
|
|
29690
29736
|
continue;
|
|
29691
29737
|
}
|
|
29692
29738
|
for (const target of targets ?? []) {
|
|
29693
|
-
const
|
|
29694
|
-
if (
|
|
29739
|
+
const found2 = target.startsWith(".") ? this.resolvePath(resolve(root, target), kind) : this.resolvePackage(target, root, kind);
|
|
29740
|
+
if (found2) return found2;
|
|
29695
29741
|
}
|
|
29696
29742
|
}
|
|
29697
29743
|
return null;
|
|
@@ -36325,12 +36371,12 @@ async function loadNodeRolldownMemfsBinding() {
|
|
|
36325
36371
|
function resolveWorkerPath(node2) {
|
|
36326
36372
|
const { dirname: dirname3, existsSync, fileURLToPath: fileURLToPath2, join: join3 } = node2;
|
|
36327
36373
|
const here = dirname3(fileURLToPath2((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
36328
|
-
const
|
|
36374
|
+
const candidates2 = [
|
|
36329
36375
|
join3(here, WORKER_FILE),
|
|
36330
36376
|
/* src/tools → dist, for a checkout that has been built. */
|
|
36331
36377
|
join3(here, "..", "..", "dist", WORKER_FILE)
|
|
36332
36378
|
];
|
|
36333
|
-
return
|
|
36379
|
+
return candidates2.find((candidate) => existsSync(candidate)) ?? null;
|
|
36334
36380
|
}
|
|
36335
36381
|
function resolveSubpath(node2, require2, packageName, subpath) {
|
|
36336
36382
|
const { dirname: dirname3, join: join3, pathToFileURL: pathToFileURL2, readFileSync } = node2;
|
|
@@ -38684,17 +38730,17 @@ var Terminal = class {
|
|
|
38684
38730
|
const match2 = /(\S*)$/.exec(left);
|
|
38685
38731
|
const word = match2?.[1] ?? "";
|
|
38686
38732
|
const isFirstWord = left.slice(0, left.length - word.length).trim() === "";
|
|
38687
|
-
const
|
|
38688
|
-
if (
|
|
38689
|
-
if (
|
|
38690
|
-
const completion =
|
|
38733
|
+
const candidates2 = isFirstWord && !word.includes("/") ? this.completeCommand(word) : this.completePath(word);
|
|
38734
|
+
if (candidates2.length === 0) return;
|
|
38735
|
+
if (candidates2.length === 1) {
|
|
38736
|
+
const completion = candidates2[0];
|
|
38691
38737
|
const suffix = completion.slice(word.length);
|
|
38692
38738
|
this.buffer = this.buffer.slice(0, this.cursor) + suffix + this.buffer.slice(this.cursor);
|
|
38693
38739
|
this.cursor += suffix.length;
|
|
38694
38740
|
this.redraw();
|
|
38695
38741
|
return;
|
|
38696
38742
|
}
|
|
38697
|
-
const common = longestCommonPrefix(
|
|
38743
|
+
const common = longestCommonPrefix(candidates2);
|
|
38698
38744
|
if (common.length > word.length) {
|
|
38699
38745
|
const suffix = common.slice(word.length);
|
|
38700
38746
|
this.buffer = this.buffer.slice(0, this.cursor) + suffix + this.buffer.slice(this.cursor);
|
|
@@ -38702,7 +38748,7 @@ var Terminal = class {
|
|
|
38702
38748
|
this.redraw();
|
|
38703
38749
|
return;
|
|
38704
38750
|
}
|
|
38705
|
-
this.write("\r\n" + formatColumns(
|
|
38751
|
+
this.write("\r\n" + formatColumns(candidates2, this.columns) + "\r\n");
|
|
38706
38752
|
this.redraw();
|
|
38707
38753
|
}
|
|
38708
38754
|
completeCommand(word) {
|