sandboxedjs 0.1.72 → 0.1.73

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/dist/index.cjs CHANGED
@@ -4077,6 +4077,214 @@ var init_builtins = __esm({
4077
4077
  }
4078
4078
  });
4079
4079
 
4080
+ // src/util/binary.ts
4081
+ async function nodeBuiltin(name) {
4082
+ const specifier = `node:${name}`;
4083
+ return await import(
4084
+ /* @vite-ignore */
4085
+ /* webpackIgnore: true */
4086
+ specifier
4087
+ );
4088
+ }
4089
+ async function nodeOnlyModule(specifier) {
4090
+ const parts = specifier.split("/");
4091
+ const runtimeSpecifier = parts.join("/");
4092
+ return await import(
4093
+ /* @vite-ignore */
4094
+ /* webpackIgnore: true */
4095
+ runtimeSpecifier
4096
+ );
4097
+ }
4098
+ function nodeZlib() {
4099
+ zlibPromise ??= nodeBuiltin("zlib");
4100
+ return zlibPromise;
4101
+ }
4102
+ async function throughStream(data, stream) {
4103
+ const source = new Blob([data]).stream();
4104
+ const piped = source.pipeThrough(stream);
4105
+ return new Uint8Array(await new Response(piped).arrayBuffer());
4106
+ }
4107
+ async function gzip(data) {
4108
+ if (isNode) return new Uint8Array((await nodeZlib()).gzipSync(data));
4109
+ return throughStream(data, new CompressionStream("gzip"));
4110
+ }
4111
+ async function gunzip(data) {
4112
+ if (isNode) return new Uint8Array((await nodeZlib()).gunzipSync(data));
4113
+ return throughStream(data, new DecompressionStream("gzip"));
4114
+ }
4115
+ async function deflate(data) {
4116
+ if (isNode) return new Uint8Array((await nodeZlib()).deflateSync(data));
4117
+ return throughStream(data, new CompressionStream("deflate"));
4118
+ }
4119
+ async function inflate(data) {
4120
+ if (isNode) return new Uint8Array((await nodeZlib()).inflateSync(data));
4121
+ return throughStream(data, new DecompressionStream("deflate"));
4122
+ }
4123
+ function nodeCrypto() {
4124
+ cryptoPromise ??= nodeBuiltin("crypto");
4125
+ return cryptoPromise;
4126
+ }
4127
+ async function digestHex(algorithm, data) {
4128
+ if (isNode) {
4129
+ const { createHash } = await nodeCrypto();
4130
+ return createHash(algorithm).update(data).digest("hex");
4131
+ }
4132
+ if (algorithm === "md5") return md5Hex(data);
4133
+ const name = SUBTLE_NAMES[algorithm];
4134
+ if (!name) throw new UnsupportedAlgorithmError(algorithm);
4135
+ const buffer = await crypto.subtle.digest(name, data);
4136
+ return toHex(new Uint8Array(buffer));
4137
+ }
4138
+ async function randomUuid() {
4139
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return crypto.randomUUID();
4140
+ const { randomUUID } = await nodeCrypto();
4141
+ return randomUUID();
4142
+ }
4143
+ function toHex(bytes2) {
4144
+ let out = "";
4145
+ for (const byte of bytes2) out += byte.toString(16).padStart(2, "0");
4146
+ return out;
4147
+ }
4148
+ function md5Hex(input) {
4149
+ const S = [
4150
+ 7,
4151
+ 12,
4152
+ 17,
4153
+ 22,
4154
+ 7,
4155
+ 12,
4156
+ 17,
4157
+ 22,
4158
+ 7,
4159
+ 12,
4160
+ 17,
4161
+ 22,
4162
+ 7,
4163
+ 12,
4164
+ 17,
4165
+ 22,
4166
+ 5,
4167
+ 9,
4168
+ 14,
4169
+ 20,
4170
+ 5,
4171
+ 9,
4172
+ 14,
4173
+ 20,
4174
+ 5,
4175
+ 9,
4176
+ 14,
4177
+ 20,
4178
+ 5,
4179
+ 9,
4180
+ 14,
4181
+ 20,
4182
+ 4,
4183
+ 11,
4184
+ 16,
4185
+ 23,
4186
+ 4,
4187
+ 11,
4188
+ 16,
4189
+ 23,
4190
+ 4,
4191
+ 11,
4192
+ 16,
4193
+ 23,
4194
+ 4,
4195
+ 11,
4196
+ 16,
4197
+ 23,
4198
+ 6,
4199
+ 10,
4200
+ 15,
4201
+ 21,
4202
+ 6,
4203
+ 10,
4204
+ 15,
4205
+ 21,
4206
+ 6,
4207
+ 10,
4208
+ 15,
4209
+ 21,
4210
+ 6,
4211
+ 10,
4212
+ 15,
4213
+ 21
4214
+ ];
4215
+ const K = new Uint32Array(64);
4216
+ for (let i = 0; i < 64; i++) K[i] = Math.floor(Math.abs(Math.sin(i + 1)) * 2 ** 32);
4217
+ const bitLength = input.length * 8;
4218
+ const padded = new Uint8Array(((input.length + 8 >> 6) + 1) * 64);
4219
+ padded.set(input);
4220
+ padded[input.length] = 128;
4221
+ const view = new DataView(padded.buffer);
4222
+ view.setUint32(padded.length - 8, bitLength >>> 0, true);
4223
+ view.setUint32(padded.length - 4, Math.floor(bitLength / 2 ** 32), true);
4224
+ let a0 = 1732584193;
4225
+ let b0 = 4023233417;
4226
+ let c0 = 2562383102;
4227
+ let d0 = 271733878;
4228
+ for (let chunk = 0; chunk < padded.length; chunk += 64) {
4229
+ const M = new Uint32Array(16);
4230
+ for (let i = 0; i < 16; i++) M[i] = view.getUint32(chunk + i * 4, true);
4231
+ let [a, b, c, d] = [a0, b0, c0, d0];
4232
+ for (let i = 0; i < 64; i++) {
4233
+ let f;
4234
+ let g;
4235
+ if (i < 16) {
4236
+ f = b & c | ~b & d;
4237
+ g = i;
4238
+ } else if (i < 32) {
4239
+ f = d & b | ~d & c;
4240
+ g = (5 * i + 1) % 16;
4241
+ } else if (i < 48) {
4242
+ f = b ^ c ^ d;
4243
+ g = (3 * i + 5) % 16;
4244
+ } else {
4245
+ f = c ^ (b | ~d);
4246
+ g = 7 * i % 16;
4247
+ }
4248
+ const tmp = d;
4249
+ d = c;
4250
+ c = b;
4251
+ const sum = a + f + K[i] + M[g] >>> 0;
4252
+ b = b + (sum << S[i] | sum >>> 32 - S[i]) >>> 0;
4253
+ a = tmp;
4254
+ }
4255
+ a0 = a0 + a >>> 0;
4256
+ b0 = b0 + b >>> 0;
4257
+ c0 = c0 + c >>> 0;
4258
+ d0 = d0 + d >>> 0;
4259
+ }
4260
+ const out = new Uint8Array(16);
4261
+ new DataView(out.buffer).setUint32(0, a0, true);
4262
+ new DataView(out.buffer).setUint32(4, b0, true);
4263
+ new DataView(out.buffer).setUint32(8, c0, true);
4264
+ new DataView(out.buffer).setUint32(12, d0, true);
4265
+ return toHex(out);
4266
+ }
4267
+ var isNode, zlibPromise, cryptoPromise, SUBTLE_NAMES, UnsupportedAlgorithmError;
4268
+ var init_binary = __esm({
4269
+ "src/util/binary.ts"() {
4270
+ isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
4271
+ zlibPromise = null;
4272
+ cryptoPromise = null;
4273
+ SUBTLE_NAMES = {
4274
+ sha1: "SHA-1",
4275
+ sha256: "SHA-256",
4276
+ sha384: "SHA-384",
4277
+ sha512: "SHA-512"
4278
+ };
4279
+ UnsupportedAlgorithmError = class extends Error {
4280
+ constructor(algorithm) {
4281
+ super(`${algorithm} is not available in this environment`);
4282
+ this.name = "UnsupportedAlgorithmError";
4283
+ }
4284
+ };
4285
+ }
4286
+ });
4287
+
4080
4288
  // src/pkg/zip.ts
4081
4289
  var zip_exports = {};
4082
4290
  __export(zip_exports, {
@@ -4165,6 +4373,122 @@ var init_zip = __esm({
4165
4373
  }
4166
4374
  });
4167
4375
 
4376
+ // src/python/local-builder.ts
4377
+ var local_builder_exports = {};
4378
+ __export(local_builder_exports, {
4379
+ buildFromSource: () => buildFromSource
4380
+ });
4381
+ async function pipelineRoot() {
4382
+ const [{ existsSync }, { fileURLToPath: fileURLToPath2 }, { dirname: dirname3, resolve: resolve3 }] = await Promise.all([
4383
+ nodeBuiltin("fs"),
4384
+ nodeBuiltin("url"),
4385
+ nodeBuiltin("path")
4386
+ ]);
4387
+ 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))));
4388
+ for (const candidate of [
4389
+ resolve3(here, "../python-runtime"),
4390
+ resolve3(here, "../../python-runtime"),
4391
+ resolve3(here, "../../../python-runtime")
4392
+ ]) {
4393
+ if (existsSync(resolve3(candidate, "scripts/build_extension.py"))) return candidate;
4394
+ }
4395
+ return null;
4396
+ }
4397
+ async function run(command, args, cwd) {
4398
+ const { spawn } = await nodeBuiltin("child_process");
4399
+ return await new Promise((resolveRun) => {
4400
+ const child = spawn(command, args, { cwd });
4401
+ let stdout = "";
4402
+ let stderr = "";
4403
+ child.stdout.on("data", (chunk) => {
4404
+ stdout += String(chunk);
4405
+ });
4406
+ child.stderr.on("data", (chunk) => {
4407
+ stderr += String(chunk);
4408
+ });
4409
+ child.on("error", (error) => resolveRun({ code: -1, stdout, stderr: String(error) }));
4410
+ child.on("close", (code) => resolveRun({ code: code ?? -1, stdout, stderr }));
4411
+ });
4412
+ }
4413
+ async function readIndex(root) {
4414
+ const [{ readFileSync, existsSync }, { pathToFileURL: pathToFileURL2 }, { resolve: resolve3 }] = await Promise.all([
4415
+ nodeBuiltin("fs"),
4416
+ nodeBuiltin("url"),
4417
+ nodeBuiltin("path")
4418
+ ]);
4419
+ const directory2 = resolve3(root, "out/wheels");
4420
+ const file3 = resolve3(directory2, "index.json");
4421
+ if (!existsSync(file3)) return null;
4422
+ const parsed = JSON.parse(readFileSync(file3, "utf8"));
4423
+ return {
4424
+ ...parsed,
4425
+ baseUrl: pathToFileURL2(directory2).href
4426
+ };
4427
+ }
4428
+ async function buildFromSource(requirement, log = () => {
4429
+ }) {
4430
+ const root = await pipelineRoot();
4431
+ if (root === null) {
4432
+ return {
4433
+ built: false,
4434
+ index: null,
4435
+ classification: "blocked-toolchain",
4436
+ reason: "the build pipeline is not present; wheels can only be built from a checkout"
4437
+ };
4438
+ }
4439
+ log(`Building ${requirement} from source (no wheel for this runtime yet)`);
4440
+ const recipe = await run("python3", ["scripts/auto_recipe.py", requirement], root);
4441
+ if (recipe.code !== 0) {
4442
+ try {
4443
+ const reported = JSON.parse(recipe.stdout.trim().split("\n").at(-1) ?? "{}");
4444
+ if (reported.reason) {
4445
+ return {
4446
+ built: false,
4447
+ index: null,
4448
+ classification: reported.classification ?? "blocked-toolchain",
4449
+ reason: reported.reason
4450
+ };
4451
+ }
4452
+ } catch {
4453
+ }
4454
+ return {
4455
+ built: false,
4456
+ index: null,
4457
+ classification: "blocked-toolchain",
4458
+ reason: `could not describe ${requirement}: ${recipe.stderr.trim().slice(-400)}`
4459
+ };
4460
+ }
4461
+ const recipePath = recipe.stdout.trim().split("\n").at(-1);
4462
+ const build = await run("python3", ["scripts/build_extension.py", recipePath], root);
4463
+ if (build.code !== 0) {
4464
+ const tail2 = `${build.stdout}
4465
+ ${build.stderr}`.trim().split("\n").slice(-12).join("\n");
4466
+ return {
4467
+ built: false,
4468
+ index: null,
4469
+ classification: "blocked-toolchain",
4470
+ reason: `building ${requirement} failed:
4471
+ ${tail2}`
4472
+ };
4473
+ }
4474
+ const indexed = await run("python3", ["scripts/build_index.py"], root);
4475
+ if (indexed.code !== 0) {
4476
+ return {
4477
+ built: false,
4478
+ index: null,
4479
+ classification: "blocked-toolchain",
4480
+ reason: `built ${requirement} but could not index it: ${indexed.stderr.trim().slice(-300)}`
4481
+ };
4482
+ }
4483
+ log(`Built ${requirement}`);
4484
+ return { built: true, index: await readIndex(root) };
4485
+ }
4486
+ var init_local_builder = __esm({
4487
+ "src/python/local-builder.ts"() {
4488
+ init_binary();
4489
+ }
4490
+ });
4491
+
4168
4492
  // src/fs/vfs.ts
4169
4493
  init_errno();
4170
4494
  init_path();
@@ -15427,211 +15751,7 @@ var commands5 = [grep, find, xargs, diff, cmp];
15427
15751
  // src/bin/archive.ts
15428
15752
  init_mode();
15429
15753
  init_path();
15430
-
15431
- // src/util/binary.ts
15432
- var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
15433
- async function nodeBuiltin(name) {
15434
- const specifier = `node:${name}`;
15435
- return await import(
15436
- /* @vite-ignore */
15437
- /* webpackIgnore: true */
15438
- specifier
15439
- );
15440
- }
15441
- async function nodeOnlyModule(specifier) {
15442
- const parts = specifier.split("/");
15443
- const runtimeSpecifier = parts.join("/");
15444
- return await import(
15445
- /* @vite-ignore */
15446
- /* webpackIgnore: true */
15447
- runtimeSpecifier
15448
- );
15449
- }
15450
- var zlibPromise = null;
15451
- function nodeZlib() {
15452
- zlibPromise ??= nodeBuiltin("zlib");
15453
- return zlibPromise;
15454
- }
15455
- async function throughStream(data, stream) {
15456
- const source = new Blob([data]).stream();
15457
- const piped = source.pipeThrough(stream);
15458
- return new Uint8Array(await new Response(piped).arrayBuffer());
15459
- }
15460
- async function gzip(data) {
15461
- if (isNode) return new Uint8Array((await nodeZlib()).gzipSync(data));
15462
- return throughStream(data, new CompressionStream("gzip"));
15463
- }
15464
- async function gunzip(data) {
15465
- if (isNode) return new Uint8Array((await nodeZlib()).gunzipSync(data));
15466
- return throughStream(data, new DecompressionStream("gzip"));
15467
- }
15468
- async function deflate(data) {
15469
- if (isNode) return new Uint8Array((await nodeZlib()).deflateSync(data));
15470
- return throughStream(data, new CompressionStream("deflate"));
15471
- }
15472
- async function inflate(data) {
15473
- if (isNode) return new Uint8Array((await nodeZlib()).inflateSync(data));
15474
- return throughStream(data, new DecompressionStream("deflate"));
15475
- }
15476
- var cryptoPromise = null;
15477
- function nodeCrypto() {
15478
- cryptoPromise ??= nodeBuiltin("crypto");
15479
- return cryptoPromise;
15480
- }
15481
- var SUBTLE_NAMES = {
15482
- sha1: "SHA-1",
15483
- sha256: "SHA-256",
15484
- sha384: "SHA-384",
15485
- sha512: "SHA-512"
15486
- };
15487
- var UnsupportedAlgorithmError = class extends Error {
15488
- constructor(algorithm) {
15489
- super(`${algorithm} is not available in this environment`);
15490
- this.name = "UnsupportedAlgorithmError";
15491
- }
15492
- };
15493
- async function digestHex(algorithm, data) {
15494
- if (isNode) {
15495
- const { createHash } = await nodeCrypto();
15496
- return createHash(algorithm).update(data).digest("hex");
15497
- }
15498
- if (algorithm === "md5") return md5Hex(data);
15499
- const name = SUBTLE_NAMES[algorithm];
15500
- if (!name) throw new UnsupportedAlgorithmError(algorithm);
15501
- const buffer = await crypto.subtle.digest(name, data);
15502
- return toHex(new Uint8Array(buffer));
15503
- }
15504
- async function randomUuid() {
15505
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return crypto.randomUUID();
15506
- const { randomUUID } = await nodeCrypto();
15507
- return randomUUID();
15508
- }
15509
- function toHex(bytes2) {
15510
- let out = "";
15511
- for (const byte of bytes2) out += byte.toString(16).padStart(2, "0");
15512
- return out;
15513
- }
15514
- function md5Hex(input) {
15515
- const S = [
15516
- 7,
15517
- 12,
15518
- 17,
15519
- 22,
15520
- 7,
15521
- 12,
15522
- 17,
15523
- 22,
15524
- 7,
15525
- 12,
15526
- 17,
15527
- 22,
15528
- 7,
15529
- 12,
15530
- 17,
15531
- 22,
15532
- 5,
15533
- 9,
15534
- 14,
15535
- 20,
15536
- 5,
15537
- 9,
15538
- 14,
15539
- 20,
15540
- 5,
15541
- 9,
15542
- 14,
15543
- 20,
15544
- 5,
15545
- 9,
15546
- 14,
15547
- 20,
15548
- 4,
15549
- 11,
15550
- 16,
15551
- 23,
15552
- 4,
15553
- 11,
15554
- 16,
15555
- 23,
15556
- 4,
15557
- 11,
15558
- 16,
15559
- 23,
15560
- 4,
15561
- 11,
15562
- 16,
15563
- 23,
15564
- 6,
15565
- 10,
15566
- 15,
15567
- 21,
15568
- 6,
15569
- 10,
15570
- 15,
15571
- 21,
15572
- 6,
15573
- 10,
15574
- 15,
15575
- 21,
15576
- 6,
15577
- 10,
15578
- 15,
15579
- 21
15580
- ];
15581
- const K = new Uint32Array(64);
15582
- for (let i = 0; i < 64; i++) K[i] = Math.floor(Math.abs(Math.sin(i + 1)) * 2 ** 32);
15583
- const bitLength = input.length * 8;
15584
- const padded = new Uint8Array(((input.length + 8 >> 6) + 1) * 64);
15585
- padded.set(input);
15586
- padded[input.length] = 128;
15587
- const view = new DataView(padded.buffer);
15588
- view.setUint32(padded.length - 8, bitLength >>> 0, true);
15589
- view.setUint32(padded.length - 4, Math.floor(bitLength / 2 ** 32), true);
15590
- let a0 = 1732584193;
15591
- let b0 = 4023233417;
15592
- let c0 = 2562383102;
15593
- let d0 = 271733878;
15594
- for (let chunk = 0; chunk < padded.length; chunk += 64) {
15595
- const M = new Uint32Array(16);
15596
- for (let i = 0; i < 16; i++) M[i] = view.getUint32(chunk + i * 4, true);
15597
- let [a, b, c, d] = [a0, b0, c0, d0];
15598
- for (let i = 0; i < 64; i++) {
15599
- let f;
15600
- let g;
15601
- if (i < 16) {
15602
- f = b & c | ~b & d;
15603
- g = i;
15604
- } else if (i < 32) {
15605
- f = d & b | ~d & c;
15606
- g = (5 * i + 1) % 16;
15607
- } else if (i < 48) {
15608
- f = b ^ c ^ d;
15609
- g = (3 * i + 5) % 16;
15610
- } else {
15611
- f = c ^ (b | ~d);
15612
- g = 7 * i % 16;
15613
- }
15614
- const tmp = d;
15615
- d = c;
15616
- c = b;
15617
- const sum = a + f + K[i] + M[g] >>> 0;
15618
- b = b + (sum << S[i] | sum >>> 32 - S[i]) >>> 0;
15619
- a = tmp;
15620
- }
15621
- a0 = a0 + a >>> 0;
15622
- b0 = b0 + b >>> 0;
15623
- c0 = c0 + c >>> 0;
15624
- d0 = d0 + d >>> 0;
15625
- }
15626
- const out = new Uint8Array(16);
15627
- new DataView(out.buffer).setUint32(0, a0, true);
15628
- new DataView(out.buffer).setUint32(4, b0, true);
15629
- new DataView(out.buffer).setUint32(8, c0, true);
15630
- new DataView(out.buffer).setUint32(12, d0, true);
15631
- return toHex(out);
15632
- }
15633
-
15634
- // src/bin/archive.ts
15754
+ init_binary();
15635
15755
  var BLOCK = 512;
15636
15756
  var encoder4 = new TextEncoder();
15637
15757
  var decoder6 = new TextDecoder();
@@ -15944,6 +16064,7 @@ var zlibCompress = defineCommand({
15944
16064
  var commands6 = [tar, gzip2, gunzip2, zcat, zlibCompress];
15945
16065
 
15946
16066
  // src/bin/hash.ts
16067
+ init_binary();
15947
16068
  function makeSum(name, algorithm, path) {
15948
16069
  return defineCommand({
15949
16070
  name,
@@ -17372,7 +17493,7 @@ var wlPaste = defineCommand({
17372
17493
  });
17373
17494
  var commands11 = [xsel, xclip, pbcopy, pbpaste, wlCopy, wlPaste];
17374
17495
 
17375
- // src/runtime/node.ts
17496
+ // src/node/node.ts
17376
17497
  init_path();
17377
17498
  var NODE_VERSION = "v22.12.0";
17378
17499
  new TextEncoder();
@@ -17769,10 +17890,10 @@ function nodeCommands() {
17769
17890
  return [node, nodeVersionFile];
17770
17891
  }
17771
17892
 
17772
- // src/runtime/python.ts
17893
+ // src/python/python.ts
17773
17894
  init_path();
17774
17895
 
17775
- // src/runtime/python/host-abi.ts
17896
+ // src/python/host-abi.ts
17776
17897
  var SBX_HOST_ABI_VERSION = 1;
17777
17898
  var SBX_REQUEST_HEADER_BYTES = 16;
17778
17899
  var SBX_RESPONSE_HEADER_BYTES = 20;
@@ -17885,7 +18006,7 @@ Object.fromEntries(
17885
18006
  Object.entries(Errno).map(([name, code]) => [code, name])
17886
18007
  );
17887
18008
 
17888
- // src/runtime/python/manifest.ts
18009
+ // src/python/manifest.ts
17889
18010
  var MANIFEST_FORMAT = "sandboxedjs-python-runtime";
17890
18011
  var MANIFEST_SCHEMA_VERSION = 1;
17891
18012
  var ManifestError = class extends Error {
@@ -18242,9 +18363,17 @@ var wheels_default = {
18242
18363
 
18243
18364
  // package.json
18244
18365
  var package_default = {
18245
- version: "0.1.72"};
18366
+ version: "0.1.73"};
18246
18367
 
18247
- // src/runtime/python/config.ts
18368
+ // src/python/config.ts
18369
+ function runtimeModuleUrl() {
18370
+ const url = new URL(
18371
+ (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)).includes("/src/python/") ? "../../dist/python/python.js" : "./python/python.js",
18372
+ (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))
18373
+ );
18374
+ if (url.protocol !== "file:") url.searchParams.set("sbx-runtime", package_default.version);
18375
+ return url;
18376
+ }
18248
18377
  var bundledManifest = {
18249
18378
  format: "sandboxedjs-python-runtime",
18250
18379
  schemaVersion: 1,
@@ -18253,16 +18382,7 @@ var bundledManifest = {
18253
18382
  pythonVersion: "3.13.5",
18254
18383
  profile: "dynamic",
18255
18384
  hostAbi: { name: "sbx_host_v1", version: 1 },
18256
- artifacts: {
18257
- moduleUrl: (() => {
18258
- const url = new URL(
18259
- (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)).includes("/src/runtime/python/") ? "../../../dist/python/python.js" : "./python/python.js",
18260
- (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))
18261
- );
18262
- if (url.protocol !== "file:") url.searchParams.set("sbx-runtime", package_default.version);
18263
- return url.href;
18264
- })()
18265
- },
18385
+ artifacts: { moduleUrl: runtimeModuleUrl().href },
18266
18386
  capabilities: {
18267
18387
  threads: true,
18268
18388
  nativeExtensions: "dynamic",
@@ -18271,24 +18391,31 @@ var bundledManifest = {
18271
18391
  persistence: "memory"
18272
18392
  }
18273
18393
  };
18274
- var bundledWheelNames = {
18394
+ var embeddedWheels = {
18275
18395
  "pydantic_core-2.23.2-cp313-cp313-emscripten_5_0_6_wasm32.whl": pydantic_core_2_23_2_cp313_cp313_emscripten_5_0_6_wasm32_default,
18276
18396
  "pydantic_core-2.46.5-cp313-cp313-emscripten_5_0_6_wasm32.whl": pydantic_core_2_46_5_cp313_cp313_emscripten_5_0_6_wasm32_default
18277
18397
  };
18278
18398
  var bundledWheelIndex = {
18279
- baseUrl: "sbx-wheel:",
18280
- wheels: wheels_default.wheels.filter(
18281
- (wheel) => wheel.filename in bundledWheelNames
18282
- ),
18283
- files: bundledWheelNames
18399
+ baseUrl: new URL("./wheels", runtimeModuleUrl()).href,
18400
+ wheels: wheels_default.wheels,
18401
+ files: embeddedWheels
18284
18402
  };
18285
18403
  var config = {
18286
18404
  backend: "sbx-cpython-wasm",
18287
18405
  manifest: bundledManifest,
18288
- wheelIndex: bundledWheelIndex
18406
+ wheelIndex: bundledWheelIndex,
18407
+ /* On by default only where it can possibly work: a Node process, running
18408
+ * from a checkout that has the build pipeline. A browser has no compiler and
18409
+ * never will, and a published package has no pipeline -- in both, building
18410
+ * would replace a clear "no wheel for this package" with a hang or a
18411
+ * confusing failure, so both keep reporting instead. `local-builder` checks
18412
+ * for the pipeline again before it runs, so this is a cheap hint rather than
18413
+ * a promise. */
18414
+ buildFromSource: typeof process !== "undefined" && Boolean(process.versions?.node) && (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)).startsWith("file:")
18289
18415
  };
18290
18416
  function setPythonBackend(options) {
18291
18417
  if (options.wheelIndex !== void 0) config.wheelIndex = options.wheelIndex;
18418
+ if (options.buildFromSource !== void 0) config.buildFromSource = options.buildFromSource;
18292
18419
  if (options.manifest !== void 0) config.manifest = validateManifest(options.manifest);
18293
18420
  if (options.workerUrl !== void 0) config.workerUrl = options.workerUrl;
18294
18421
  if (options.backend !== void 0) {
@@ -18962,10 +19089,11 @@ var FileService = class {
18962
19089
  }
18963
19090
  };
18964
19091
 
18965
- // src/runtime/python/backend.ts
19092
+ // src/python/backend.ts
18966
19093
  init_signals();
19094
+ init_binary();
18967
19095
 
18968
- // src/runtime/python/protocol.ts
19096
+ // src/python/protocol.ts
18969
19097
  var ProtocolError = class extends Error {
18970
19098
  code = "ERR_SBX_ABI_PROTOCOL";
18971
19099
  };
@@ -19442,7 +19570,7 @@ var VirtualTcpNetwork = class {
19442
19570
  }
19443
19571
  };
19444
19572
 
19445
- // src/runtime/python/syscall-server.ts
19573
+ // src/python/syscall-server.ts
19446
19574
  var MAX_TRANSFER = 8 * 1024 * 1024;
19447
19575
  var POLLIN = 1;
19448
19576
  var POLLOUT = 4;
@@ -19891,7 +20019,7 @@ function encodeStat(st) {
19891
20019
  return new Writer().u64(st.ino).u32(st.mode).u64(st.size).u32(st.uid).u32(st.gid).u32(st.nlink).i64(Math.round(st.atimeMs * 1e6)).i64(Math.round(st.mtimeMs * 1e6)).i64(Math.round(st.ctimeMs * 1e6)).finish();
19892
20020
  }
19893
20021
 
19894
- // src/runtime/python/sync-transport.ts
20022
+ // src/python/sync-transport.ts
19895
20023
  var STATE = 0;
19896
20024
  var LENGTH = 1;
19897
20025
  var MORE = 2;
@@ -19994,7 +20122,7 @@ function concat3(parts) {
19994
20122
  return joined;
19995
20123
  }
19996
20124
 
19997
- // src/runtime/worker-host.ts
20125
+ // src/worker/worker-host.ts
19998
20126
  function defaultWorkerUrl() {
19999
20127
  return new URL("./worker-entry.js", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
20000
20128
  }
@@ -20065,7 +20193,7 @@ async function startNodeWorker(url, workerData) {
20065
20193
  };
20066
20194
  }
20067
20195
 
20068
- // src/runtime/python/supervisor.ts
20196
+ // src/python/supervisor.ts
20069
20197
  var nextGeneration = 1;
20070
20198
  async function startPythonProcess(options) {
20071
20199
  const unavailable2 = syncTransportUnavailableReason();
@@ -20180,10 +20308,10 @@ async function startPythonProcess(options) {
20180
20308
  };
20181
20309
  }
20182
20310
 
20183
- // src/runtime/python/install.ts
20311
+ // src/python/install.ts
20184
20312
  init_zip();
20185
20313
 
20186
- // src/runtime/python/pypi.ts
20314
+ // src/python/pypi.ts
20187
20315
  function parseRequirement(text2) {
20188
20316
  const cleaned = text2.replace(/#.*$/, "").trim();
20189
20317
  if (!cleaned) return null;
@@ -20262,7 +20390,7 @@ function splitOnce(text2, separator) {
20262
20390
  return at < 0 ? [text2] : [text2.slice(0, at), text2.slice(at + 1)];
20263
20391
  }
20264
20392
 
20265
- // src/runtime/python/extension-abi.ts
20393
+ // src/python/extension-abi.ts
20266
20394
  var EXTENSION_ABI = {
20267
20395
  "abiId": "sbxabi1-c2637d04695ad927",
20268
20396
  "wheelTag": "cp313-cp313-emscripten_5_0_6_wasm32",
@@ -20276,7 +20404,7 @@ var EXTENSION_ABI = {
20276
20404
  var WHEEL_TAG = EXTENSION_ABI.wheelTag;
20277
20405
  var PURE_PYTHON_TAGS = EXTENSION_ABI.wheel.acceptedPurePythonTags;
20278
20406
 
20279
- // src/runtime/python/resolver.ts
20407
+ // src/python/resolver.ts
20280
20408
  var WHEEL_INDEX_SCHEMA_VERSION = 1;
20281
20409
  function assertIndexUsable(index) {
20282
20410
  const declared = index.schemaVersion;
@@ -20586,7 +20714,7 @@ function requiresFromMetadata(text2) {
20586
20714
  return result;
20587
20715
  }
20588
20716
 
20589
- // src/runtime/python/install.ts
20717
+ // src/python/install.ts
20590
20718
  var SITE_PACKAGES = "/usr/lib/python3.13/site-packages";
20591
20719
  var SCRIPTS = "/usr/local/bin";
20592
20720
  function markerEnvironment(pythonVersion) {
@@ -20713,7 +20841,7 @@ if __name__ == '__main__':
20713
20841
  `;
20714
20842
  }
20715
20843
 
20716
- // src/runtime/python/backend.ts
20844
+ // src/python/backend.ts
20717
20845
  var PENDING_INHERITANCE = /* @__PURE__ */ new Map();
20718
20846
  var INHERIT_TOKEN = "SBX_PYTHON_INHERIT";
20719
20847
  var WNOHANG = 1;
@@ -20866,7 +20994,7 @@ async function resolveWorkerUrl(explicit) {
20866
20994
  nodeBuiltin("url")
20867
20995
  ]);
20868
20996
  if (existsSync(fileURLToPath2(beside))) return beside;
20869
- const built = new URL("../../../dist/python-worker.js", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
20997
+ const built = new URL("../../dist/python-worker.js", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
20870
20998
  if (existsSync(fileURLToPath2(built))) return pathToFileURL2(fileURLToPath2(built));
20871
20999
  throw new Error(
20872
21000
  "the SandboxedJs Python process worker has not been built; run `npm run build` in the package, or pass configurePython({ workerUrl })."
@@ -20951,7 +21079,76 @@ function containerMounts(ctx) {
20951
21079
  return mounts;
20952
21080
  }
20953
21081
 
20954
- // src/runtime/python/pip-command.ts
21082
+ // src/python/pip-command.ts
21083
+ init_binary();
21084
+ async function requestRemoteBuild(service, requirement, line) {
21085
+ line(`Asking ${new URL(service).host} to build ${requirement}`);
21086
+ try {
21087
+ const deadline = Date.now() + 20 * 6e4;
21088
+ let verdict = {};
21089
+ for (; ; ) {
21090
+ const response = await fetch(service, {
21091
+ method: "POST",
21092
+ headers: { "content-type": "application/json" },
21093
+ body: JSON.stringify({ requirement })
21094
+ });
21095
+ if (!response.ok) {
21096
+ return {
21097
+ built: false,
21098
+ index: null,
21099
+ classification: "blocked-toolchain",
21100
+ reason: `${service} answered ${response.status}`
21101
+ };
21102
+ }
21103
+ verdict = await response.json();
21104
+ if (verdict.state !== "building-wheel" && verdict.state !== "queued") break;
21105
+ if (Date.now() > deadline) {
21106
+ return {
21107
+ built: false,
21108
+ index: null,
21109
+ classification: "blocked-toolchain",
21110
+ reason: `${service} is still building ${requirement} after 20 minutes`
21111
+ };
21112
+ }
21113
+ await new Promise((wait) => setTimeout(wait, 3e3));
21114
+ }
21115
+ if (!verdict.built) {
21116
+ return {
21117
+ built: false,
21118
+ index: null,
21119
+ classification: verdict.classification ?? "blocked-toolchain",
21120
+ reason: verdict.reason ?? "the build service reported no wheel"
21121
+ };
21122
+ }
21123
+ const base2 = (verdict.indexUrl ?? service.replace(/\/build\/?$/, "")).replace(/\/$/, "");
21124
+ const fresh = await fetch(`${base2}/index.json`, { cache: "no-store" });
21125
+ if (!fresh.ok) {
21126
+ return {
21127
+ built: false,
21128
+ index: null,
21129
+ classification: "blocked-toolchain",
21130
+ reason: `${base2}/index.json answered ${fresh.status} after the build`
21131
+ };
21132
+ }
21133
+ const loaded = await fresh.json();
21134
+ line(`Built ${requirement}`);
21135
+ return {
21136
+ built: true,
21137
+ index: {
21138
+ baseUrl: base2,
21139
+ wheels: loaded.wheels ?? [],
21140
+ ...loaded.schemaVersion === void 0 ? {} : { schemaVersion: loaded.schemaVersion }
21141
+ }
21142
+ };
21143
+ } catch (error) {
21144
+ return {
21145
+ built: false,
21146
+ index: null,
21147
+ classification: "blocked-toolchain",
21148
+ reason: `could not reach the build service at ${service}: ${error.message}`
21149
+ };
21150
+ }
21151
+ }
20955
21152
  var pipCommand = defineCommand({
20956
21153
  name: "pip",
20957
21154
  path: "/usr/bin/pip",
@@ -21004,15 +21201,19 @@ environments. A package with no usable wheel is an error, never a silent skip.`,
21004
21201
  const cache = /* @__PURE__ */ new Map();
21005
21202
  let embeddedFiles = {};
21006
21203
  const request = async (url, timeoutMs, read) => {
21007
- if (url.startsWith("sbx-wheel:")) {
21008
- const filename = decodeURIComponent(url.slice("sbx-wheel:".length).replace(/^\/+/, ""));
21009
- const encoded = embeddedFiles[filename];
21010
- if (!encoded) throw new Error(`bundled wheel ${filename} is missing`);
21011
- const binary = atob(encoded);
21204
+ const embedded = embeddedFiles[decodeURIComponent(
21205
+ url.replace(/[?#].*$/, "").split("/").pop() ?? ""
21206
+ )];
21207
+ if (embedded) {
21208
+ const binary = atob(embedded);
21012
21209
  const bytes2 = new Uint8Array(binary.length);
21013
21210
  for (let i = 0; i < binary.length; i += 1) bytes2[i] = binary.charCodeAt(i);
21014
21211
  return await read(new Response(bytes2));
21015
21212
  }
21213
+ if (url.startsWith("sbx-wheel:")) {
21214
+ const filename = decodeURIComponent(url.slice("sbx-wheel:".length).replace(/^\/+/, ""));
21215
+ throw new Error(`bundled wheel ${filename} is missing`);
21216
+ }
21016
21217
  if (url.startsWith("file:")) {
21017
21218
  try {
21018
21219
  const [{ readFile }, { fileURLToPath: fileURLToPath2 }] = await Promise.all([
@@ -21073,29 +21274,48 @@ environments. A package with no usable wheel is an error, never a silent skip.`,
21073
21274
  index = configured;
21074
21275
  embeddedFiles = configured.files ?? {};
21075
21276
  }
21076
- try {
21077
- const report = await installRequirements({
21078
- index,
21079
- client,
21080
- vfs: ctx.vfs,
21081
- cred: ctx.cred,
21082
- requirements,
21083
- pythonVersion: pythonBackend().manifest?.pythonVersion ?? "3.13.5",
21084
- progress: {
21085
- collecting: (name) => ctx.line(`Collecting ${name}`),
21086
- downloading: () => {
21277
+ let attemptsLeft = 12;
21278
+ for (; ; ) {
21279
+ try {
21280
+ const report = await installRequirements({
21281
+ index,
21282
+ client,
21283
+ vfs: ctx.vfs,
21284
+ cred: ctx.cred,
21285
+ requirements,
21286
+ pythonVersion: pythonBackend().manifest?.pythonVersion ?? "3.13.5",
21287
+ progress: {
21288
+ collecting: (name) => ctx.line(`Collecting ${name}`),
21289
+ downloading: () => {
21290
+ }
21087
21291
  }
21292
+ });
21293
+ for (const skipped of report.skipped) {
21294
+ ctx.line(` Skipping ${skipped.name} (marker: ${skipped.marker})`);
21088
21295
  }
21089
- });
21090
- for (const skipped of report.skipped) {
21091
- ctx.line(` Skipping ${skipped.name} (marker: ${skipped.marker})`);
21296
+ ctx.line(
21297
+ `Successfully installed ${report.installed.map((p) => `${p.name}-${p.version}`).join(" ")}`
21298
+ );
21299
+ return 0;
21300
+ } catch (error) {
21301
+ const failure2 = error.failure;
21302
+ const buildable = failure2?.reason === "no-compatible-distribution" && Boolean(failure2.package) && failure2.sourceAvailable === true;
21303
+ if (!buildable || !pythonBackend().buildFromSource || attemptsLeft <= 0) {
21304
+ return ctx.fail(error.message ?? String(error));
21305
+ }
21306
+ attemptsLeft -= 1;
21307
+ const builder = pythonBackend().buildFromSource;
21308
+ const outcome = typeof builder === "string" ? await requestRemoteBuild(builder, failure2.package, (l) => ctx.line(l)) : await (await Promise.resolve().then(() => (init_local_builder(), local_builder_exports))).buildFromSource(failure2.package, (line) => ctx.line(line));
21309
+ if (!outcome.built) {
21310
+ return ctx.fail(
21311
+ `${error.message}
21312
+ ${outcome.classification}: ${outcome.reason}`
21313
+ );
21314
+ }
21315
+ if (outcome.index) index = outcome.index;
21316
+ embeddedFiles = { ...embeddedFiles, ...outcome.index?.files ?? {} };
21317
+ cache.clear();
21092
21318
  }
21093
- ctx.line(
21094
- `Successfully installed ${report.installed.map((p) => `${p.name}-${p.version}`).join(" ")}`
21095
- );
21096
- return 0;
21097
- } catch (error) {
21098
- return ctx.fail(error.message ?? String(error));
21099
21319
  }
21100
21320
  }
21101
21321
  });
@@ -21113,7 +21333,7 @@ function listInstalled(ctx) {
21113
21333
  return 0;
21114
21334
  }
21115
21335
 
21116
- // src/runtime/emscripten-fs.ts
21336
+ // src/fs/emscripten-fs.ts
21117
21337
  init_errno();
21118
21338
  init_path();
21119
21339
  var EM_ERRNO = {
@@ -21368,7 +21588,10 @@ function mountContainerFs(FS, opts) {
21368
21588
  }
21369
21589
  }
21370
21590
 
21371
- // src/runtime/python-syscalls.ts
21591
+ // src/python/cpython.ts
21592
+ init_binary();
21593
+
21594
+ // src/python/python-syscalls.ts
21372
21595
  var EMPTY = new Uint8Array(0);
21373
21596
  function createStdinHost(ctx) {
21374
21597
  let pending = EMPTY;
@@ -22105,7 +22328,7 @@ function bindProgram(py, binding) {
22105
22328
  });
22106
22329
  }
22107
22330
 
22108
- // src/runtime/cpython.ts
22331
+ // src/python/cpython.ts
22109
22332
  var RESERVED_FOR_INTERPRETER = /* @__PURE__ */ new Set(["lib", "dev", "proc"]);
22110
22333
  var pyodideModule = null;
22111
22334
  var indexUrl;
@@ -22513,7 +22736,7 @@ var micropip = defineCommand({
22513
22736
  }
22514
22737
  });
22515
22738
 
22516
- // src/runtime/python.ts
22739
+ // src/python/python.ts
22517
22740
  var PYTHON_VERSION = "3.13";
22518
22741
  function configurePython(options = {}) {
22519
22742
  configureCPython({ indexURL: options.indexURL, moduleURL: options.pyodideURL });
@@ -22521,7 +22744,8 @@ function configurePython(options = {}) {
22521
22744
  ...options.backend !== void 0 ? { backend: options.backend } : {},
22522
22745
  ...options.manifest !== void 0 ? { manifest: options.manifest } : {},
22523
22746
  ...options.workerUrl !== void 0 ? { workerUrl: options.workerUrl } : {},
22524
- ...options.wheelIndex !== void 0 ? { wheelIndex: options.wheelIndex } : {}
22747
+ ...options.wheelIndex !== void 0 ? { wheelIndex: options.wheelIndex } : {},
22748
+ ...options.buildFromSource !== void 0 ? { buildFromSource: options.buildFromSource } : {}
22525
22749
  });
22526
22750
  }
22527
22751
  var isPythonAvailable = isCPythonAvailable;
@@ -22625,7 +22849,8 @@ function pythonCommands() {
22625
22849
  return usingOwnedPython() ? [python, pipCommand] : [python, micropip];
22626
22850
  }
22627
22851
 
22628
- // src/runtime/ffmpeg.ts
22852
+ // src/tools/ffmpeg.ts
22853
+ init_binary();
22629
22854
  var INSTALL_HINT = "ffmpeg is not installed in this container.\nThe FFmpeg runtime ships separately because it is a ~31MB WebAssembly build:\n npm install @ffmpeg/core";
22630
22855
  var compiled = null;
22631
22856
  async function loadFactory() {
@@ -24700,7 +24925,7 @@ unless the container was created with network: { allowOutbound: true }.`,
24700
24925
  const packageSpec = packages[0] ?? spec;
24701
24926
  const packageName = packages[0] ? splitPackageSpec(packages[0]).name : specName;
24702
24927
  let command = packages.length > 0 ? spec : basename(specName);
24703
- const run = async (binary) => {
24928
+ const run2 = async (binary) => {
24704
24929
  const env2 = {
24705
24930
  ...ctx.env,
24706
24931
  PATH: `${binDir}:${ctx.env.PATH ?? ""}`,
@@ -24717,8 +24942,8 @@ unless the container was created with network: { allowOutbound: true }.`,
24717
24942
  }).wait();
24718
24943
  };
24719
24944
  if (!version) {
24720
- if (findLocalBin(ctx, command)) return run(command);
24721
- if (ctx.kernel.which(command, ctx.cwd, ctx.env, ctx.cred)) return run(command);
24945
+ if (findLocalBin(ctx, command)) return run2(command);
24946
+ if (ctx.kernel.which(command, ctx.cwd, ctx.env, ctx.cred)) return run2(command);
24722
24947
  }
24723
24948
  if (args.has("no-install")) {
24724
24949
  ctx.warn(`command not found: ${command}`);
@@ -24756,7 +24981,7 @@ unless the container was created with network: { allowOutbound: true }.`,
24756
24981
  }
24757
24982
  command = chosen;
24758
24983
  }
24759
- return run(command);
24984
+ return run2(command);
24760
24985
  }
24761
24986
  });
24762
24987
  function makeNpmAlias(name, path) {
@@ -24950,6 +25175,9 @@ function installUserland(kernel) {
24950
25175
  }
24951
25176
  }
24952
25177
 
25178
+ // src/container/container.ts
25179
+ init_binary();
25180
+
24953
25181
  // src/container/fs.ts
24954
25182
  init_path();
24955
25183
  async function bytesFor(data) {
@@ -25147,7 +25375,7 @@ var Session = class {
25147
25375
  }
25148
25376
  };
25149
25377
 
25150
- // src/runtime/node-child-process-bridge.ts
25378
+ // src/node/node-child-process-bridge.ts
25151
25379
  var KernelChildProcess = class {
25152
25380
  pid;
25153
25381
  command;
@@ -25298,7 +25526,7 @@ function installNodeChildProcessBridge(pod, kernel, cred) {
25298
25526
  };
25299
25527
  }
25300
25528
 
25301
- // src/runtime/host-module-tracker.ts
25529
+ // src/node/host-module-tracker.ts
25302
25530
  var HostModuleTracker = class {
25303
25531
  active = 0;
25304
25532
  disposed = false;
@@ -25360,7 +25588,7 @@ var HostModuleTracker = class {
25360
25588
  }
25361
25589
  };
25362
25590
 
25363
- // src/runtime/commonjs-engine.ts
25591
+ // src/node/commonjs-engine.ts
25364
25592
  init_path();
25365
25593
  var HELPERS = {
25366
25594
  /** Import a specifier and return an ES-module-shaped namespace. */
@@ -26219,7 +26447,7 @@ function splitSpecifier(specifier) {
26219
26447
  return { name: parts.slice(0, size).join("/"), subpath: parts.slice(size).join("/") };
26220
26448
  }
26221
26449
 
26222
- // src/runtime/readable-from.ts
26450
+ // src/node/readable-from.ts
26223
26451
  function createReadableFrom(Readable) {
26224
26452
  return function from(source, options = {}) {
26225
26453
  if (source && typeof source.pipe === "function") return source;
@@ -26268,7 +26496,7 @@ function installReadableFrom(streamModule5) {
26268
26496
  streamModule5.Readable.from = createReadableFrom(streamModule5.Readable);
26269
26497
  }
26270
26498
 
26271
- // src/runtime/util-module.ts
26499
+ // src/node/util-module.ts
26272
26500
  var customInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
26273
26501
  var promisifyCustom = /* @__PURE__ */ Symbol.for("nodejs.util.promisify.custom");
26274
26502
  var BREAK_LENGTH = 72;
@@ -26642,7 +26870,7 @@ var utilModule = {
26642
26870
  };
26643
26871
  var util_module_default = utilModule;
26644
26872
 
26645
- // src/runtime/assert-module.ts
26873
+ // src/node/assert-module.ts
26646
26874
  var AssertionError = class extends Error {
26647
26875
  actual;
26648
26876
  expected;
@@ -26811,8 +27039,8 @@ var bytes = (data) => {
26811
27039
  if (data instanceof ArrayBuffer) return new Uint8Array(data);
26812
27040
  return data;
26813
27041
  };
26814
- function codec(name, run) {
26815
- const sync2 = (data, options) => Buffer2.from(run(bytes(data), options));
27042
+ function codec(name, run2) {
27043
+ const sync2 = (data, options) => Buffer2.from(run2(bytes(data), options));
26816
27044
  const async_ = (data, options, callback) => {
26817
27045
  const done = typeof options === "function" ? options : callback;
26818
27046
  const settings = typeof options === "function" ? void 0 : options;
@@ -26976,7 +27204,7 @@ var urlModule = {
26976
27204
  };
26977
27205
  var url_module_default = urlModule;
26978
27206
 
26979
- // src/runtime/core-modules.ts
27207
+ // src/node/core-modules.ts
26980
27208
  init_path();
26981
27209
  var VirtualIncomingMessage = class extends streamModule4__default.default.Readable {
26982
27210
  method;
@@ -27700,7 +27928,7 @@ function toBytes2(data, encoding) {
27700
27928
  return typeof data === "string" ? Buffer2.from(data, encoding) : data;
27701
27929
  }
27702
27930
 
27703
- // src/runtime/sync-channel.ts
27931
+ // src/worker/sync-channel.ts
27704
27932
  var STATE2 = 0;
27705
27933
  var LENGTH2 = 1;
27706
27934
  var MORE2 = 2;
@@ -27949,7 +28177,7 @@ function buildSyncFamily(syncSpawn, throughShell, defaultCwd, environmentFor) {
27949
28177
  spawnSync: unavailable("spawnSync")
27950
28178
  };
27951
28179
  }
27952
- const run = (file3, args, options) => {
28180
+ const run2 = (file3, args, options) => {
27953
28181
  const resolved = options.shell ? throughShell([file3, ...args].join(" "), options) : { file: file3, args };
27954
28182
  const input = options.input === void 0 ? void 0 : typeof options.input === "string" ? options.input : new TextDecoder().decode(options.input);
27955
28183
  const inherit = options.stdio === "inherit" || Array.isArray(options.stdio) && options.stdio[0] === "inherit";
@@ -27983,7 +28211,7 @@ ${result.stderr}`), {
27983
28211
  };
27984
28212
  const spawnSync = (file3, args = [], options = {}) => {
27985
28213
  const [list, opts] = Array.isArray(args) ? [args, options] : [[], args];
27986
- const result = run(file3, list, opts);
28214
+ const result = run2(file3, list, opts);
27987
28215
  return {
27988
28216
  pid: 0,
27989
28217
  status: result.status,
@@ -27996,9 +28224,9 @@ ${result.stderr}`), {
27996
28224
  };
27997
28225
  const execFileSync = (file3, args = [], options = {}) => {
27998
28226
  const [list, opts] = Array.isArray(args) ? [args, options] : [[], args];
27999
- return orThrow(run(file3, list, opts), [file3, ...list].join(" "), opts);
28227
+ return orThrow(run2(file3, list, opts), [file3, ...list].join(" "), opts);
28000
28228
  };
28001
- const execSync = (command, options = {}) => orThrow(run(command, [], { ...options, shell: options.shell ?? true }), command, options);
28229
+ const execSync = (command, options = {}) => orThrow(run2(command, [], { ...options, shell: options.shell ?? true }), command, options);
28002
28230
  return { spawnSync, execFileSync, execSync };
28003
28231
  }
28004
28232
  function normalize3(options, callback) {
@@ -28018,7 +28246,7 @@ function unavailable(name) {
28018
28246
  };
28019
28247
  }
28020
28248
 
28021
- // src/runtime/core-modules.ts
28249
+ // src/node/core-modules.ts
28022
28250
  init_signals();
28023
28251
  var CSI_KEYS = {
28024
28252
  "[A": "up",
@@ -28425,7 +28653,7 @@ function createReadlineModule(defaultInput, defaultOutput = () => void 0) {
28425
28653
  return { ...base2, promises: { ...base2, Interface, createInterface } };
28426
28654
  }
28427
28655
 
28428
- // src/runtime/core-modules.ts
28656
+ // src/node/core-modules.ts
28429
28657
  installReadableFrom(streamModule4__default.default);
28430
28658
  var Dirent = class {
28431
28659
  /** Node 20+ exposes the containing directory, and `fs.glob` consumers read it. */
@@ -29593,7 +29821,7 @@ var builtinNames2 = [
29593
29821
  ...stubNames
29594
29822
  ];
29595
29823
 
29596
- // src/runtime/memory-volume.ts
29824
+ // src/fs/memory-volume.ts
29597
29825
  init_path();
29598
29826
  var VolumeError = class extends Error {
29599
29827
  constructor(code, operation, path) {
@@ -29903,7 +30131,7 @@ var MemoryVolume = class {
29903
30131
  }
29904
30132
  };
29905
30133
 
29906
- // src/runtime/mirroring-volume.ts
30134
+ // src/fs/mirroring-volume.ts
29907
30135
  init_path();
29908
30136
  var MirroringVolume = class {
29909
30137
  constructor(inner = new MemoryVolume()) {
@@ -30309,7 +30537,8 @@ function sameBytes(a, b) {
30309
30537
  return true;
30310
30538
  }
30311
30539
 
30312
- // src/runtime/host-esbuild.ts
30540
+ // src/tools/host-esbuild.ts
30541
+ init_binary();
30313
30542
  var ASYNC_API = ["transform", "build", "context", "formatMessages", "analyzeMetafile"];
30314
30543
  function createHostEsbuild() {
30315
30544
  let loading = null;
@@ -30377,7 +30606,8 @@ function ensureProcessGlobal() {
30377
30606
  });
30378
30607
  }
30379
30608
 
30380
- // src/runtime/rolldown-node-binding.ts
30609
+ // src/tools/rolldown-node-binding.ts
30610
+ init_binary();
30381
30611
  async function loadNodeApi() {
30382
30612
  const [moduleApi, fsApi, pathApi, urlApi] = await Promise.all([
30383
30613
  nodeBuiltin("module"),
@@ -30495,7 +30725,7 @@ function resolveWorkerPath(node2) {
30495
30725
  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))));
30496
30726
  const candidates = [
30497
30727
  join3(here, WORKER_FILE),
30498
- /* src/runtime → dist, for a checkout that has been built. */
30728
+ /* src/tools → dist, for a checkout that has been built. */
30499
30729
  join3(here, "..", "..", "dist", WORKER_FILE)
30500
30730
  ];
30501
30731
  return candidates.find((candidate) => existsSync(candidate)) ?? null;
@@ -30529,7 +30759,7 @@ function unreferenceWorker(worker) {
30529
30759
  worker.unref();
30530
30760
  }
30531
30761
 
30532
- // src/runtime/host-rolldown.ts
30762
+ // src/tools/host-rolldown.ts
30533
30763
  var BUNDLER_HINT = "If this is a bundler pre-bundling the worker away, exclude the binding from dependency optimisation \u2014 in Vite:\n\n optimizeDeps: { exclude: ['@rolldown/binding-wasm32-wasi'] }";
30534
30764
  var isNodeHost = typeof process !== "undefined" && Boolean(process.versions?.node);
30535
30765
  async function loadHostRolldownBinding() {
@@ -30556,7 +30786,7 @@ ${BUNDLER_HINT}`),
30556
30786
  }
30557
30787
  }
30558
30788
 
30559
- // src/runtime/local-runtime-pod.ts
30789
+ // src/worker/local-runtime-pod.ts
30560
30790
  init_path();
30561
30791
  var WASM_ALIASES = {
30562
30792
  esbuild: "esbuild-wasm",
@@ -31195,7 +31425,7 @@ function attachRolldownMirror(binding, volume, root) {
31195
31425
  volume.attach(fs, root);
31196
31426
  }
31197
31427
 
31198
- // src/runtime/remote-volume.ts
31428
+ // src/fs/remote-volume.ts
31199
31429
  var encoder8 = new TextEncoder();
31200
31430
  var decoder8 = new TextDecoder();
31201
31431
  function encodeFrame(header, body) {
@@ -31258,7 +31488,7 @@ function serveVolume(volume) {
31258
31488
  };
31259
31489
  }
31260
31490
 
31261
- // src/runtime/sync-syscalls.ts
31491
+ // src/worker/sync-syscalls.ts
31262
31492
  var SPAWN_OP = "spawnSync";
31263
31493
  function serveSyncSyscalls(options) {
31264
31494
  const volumeHandler = serveVolume(options.volume);