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.js CHANGED
@@ -4060,6 +4060,214 @@ var init_builtins = __esm({
4060
4060
  }
4061
4061
  });
4062
4062
 
4063
+ // src/util/binary.ts
4064
+ async function nodeBuiltin(name) {
4065
+ const specifier = `node:${name}`;
4066
+ return await import(
4067
+ /* @vite-ignore */
4068
+ /* webpackIgnore: true */
4069
+ specifier
4070
+ );
4071
+ }
4072
+ async function nodeOnlyModule(specifier) {
4073
+ const parts = specifier.split("/");
4074
+ const runtimeSpecifier = parts.join("/");
4075
+ return await import(
4076
+ /* @vite-ignore */
4077
+ /* webpackIgnore: true */
4078
+ runtimeSpecifier
4079
+ );
4080
+ }
4081
+ function nodeZlib() {
4082
+ zlibPromise ??= nodeBuiltin("zlib");
4083
+ return zlibPromise;
4084
+ }
4085
+ async function throughStream(data, stream) {
4086
+ const source = new Blob([data]).stream();
4087
+ const piped = source.pipeThrough(stream);
4088
+ return new Uint8Array(await new Response(piped).arrayBuffer());
4089
+ }
4090
+ async function gzip(data) {
4091
+ if (isNode) return new Uint8Array((await nodeZlib()).gzipSync(data));
4092
+ return throughStream(data, new CompressionStream("gzip"));
4093
+ }
4094
+ async function gunzip(data) {
4095
+ if (isNode) return new Uint8Array((await nodeZlib()).gunzipSync(data));
4096
+ return throughStream(data, new DecompressionStream("gzip"));
4097
+ }
4098
+ async function deflate(data) {
4099
+ if (isNode) return new Uint8Array((await nodeZlib()).deflateSync(data));
4100
+ return throughStream(data, new CompressionStream("deflate"));
4101
+ }
4102
+ async function inflate(data) {
4103
+ if (isNode) return new Uint8Array((await nodeZlib()).inflateSync(data));
4104
+ return throughStream(data, new DecompressionStream("deflate"));
4105
+ }
4106
+ function nodeCrypto() {
4107
+ cryptoPromise ??= nodeBuiltin("crypto");
4108
+ return cryptoPromise;
4109
+ }
4110
+ async function digestHex(algorithm, data) {
4111
+ if (isNode) {
4112
+ const { createHash } = await nodeCrypto();
4113
+ return createHash(algorithm).update(data).digest("hex");
4114
+ }
4115
+ if (algorithm === "md5") return md5Hex(data);
4116
+ const name = SUBTLE_NAMES[algorithm];
4117
+ if (!name) throw new UnsupportedAlgorithmError(algorithm);
4118
+ const buffer = await crypto.subtle.digest(name, data);
4119
+ return toHex(new Uint8Array(buffer));
4120
+ }
4121
+ async function randomUuid() {
4122
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return crypto.randomUUID();
4123
+ const { randomUUID } = await nodeCrypto();
4124
+ return randomUUID();
4125
+ }
4126
+ function toHex(bytes2) {
4127
+ let out = "";
4128
+ for (const byte of bytes2) out += byte.toString(16).padStart(2, "0");
4129
+ return out;
4130
+ }
4131
+ function md5Hex(input) {
4132
+ const S = [
4133
+ 7,
4134
+ 12,
4135
+ 17,
4136
+ 22,
4137
+ 7,
4138
+ 12,
4139
+ 17,
4140
+ 22,
4141
+ 7,
4142
+ 12,
4143
+ 17,
4144
+ 22,
4145
+ 7,
4146
+ 12,
4147
+ 17,
4148
+ 22,
4149
+ 5,
4150
+ 9,
4151
+ 14,
4152
+ 20,
4153
+ 5,
4154
+ 9,
4155
+ 14,
4156
+ 20,
4157
+ 5,
4158
+ 9,
4159
+ 14,
4160
+ 20,
4161
+ 5,
4162
+ 9,
4163
+ 14,
4164
+ 20,
4165
+ 4,
4166
+ 11,
4167
+ 16,
4168
+ 23,
4169
+ 4,
4170
+ 11,
4171
+ 16,
4172
+ 23,
4173
+ 4,
4174
+ 11,
4175
+ 16,
4176
+ 23,
4177
+ 4,
4178
+ 11,
4179
+ 16,
4180
+ 23,
4181
+ 6,
4182
+ 10,
4183
+ 15,
4184
+ 21,
4185
+ 6,
4186
+ 10,
4187
+ 15,
4188
+ 21,
4189
+ 6,
4190
+ 10,
4191
+ 15,
4192
+ 21,
4193
+ 6,
4194
+ 10,
4195
+ 15,
4196
+ 21
4197
+ ];
4198
+ const K = new Uint32Array(64);
4199
+ for (let i = 0; i < 64; i++) K[i] = Math.floor(Math.abs(Math.sin(i + 1)) * 2 ** 32);
4200
+ const bitLength = input.length * 8;
4201
+ const padded = new Uint8Array(((input.length + 8 >> 6) + 1) * 64);
4202
+ padded.set(input);
4203
+ padded[input.length] = 128;
4204
+ const view = new DataView(padded.buffer);
4205
+ view.setUint32(padded.length - 8, bitLength >>> 0, true);
4206
+ view.setUint32(padded.length - 4, Math.floor(bitLength / 2 ** 32), true);
4207
+ let a0 = 1732584193;
4208
+ let b0 = 4023233417;
4209
+ let c0 = 2562383102;
4210
+ let d0 = 271733878;
4211
+ for (let chunk = 0; chunk < padded.length; chunk += 64) {
4212
+ const M = new Uint32Array(16);
4213
+ for (let i = 0; i < 16; i++) M[i] = view.getUint32(chunk + i * 4, true);
4214
+ let [a, b, c, d] = [a0, b0, c0, d0];
4215
+ for (let i = 0; i < 64; i++) {
4216
+ let f;
4217
+ let g;
4218
+ if (i < 16) {
4219
+ f = b & c | ~b & d;
4220
+ g = i;
4221
+ } else if (i < 32) {
4222
+ f = d & b | ~d & c;
4223
+ g = (5 * i + 1) % 16;
4224
+ } else if (i < 48) {
4225
+ f = b ^ c ^ d;
4226
+ g = (3 * i + 5) % 16;
4227
+ } else {
4228
+ f = c ^ (b | ~d);
4229
+ g = 7 * i % 16;
4230
+ }
4231
+ const tmp = d;
4232
+ d = c;
4233
+ c = b;
4234
+ const sum = a + f + K[i] + M[g] >>> 0;
4235
+ b = b + (sum << S[i] | sum >>> 32 - S[i]) >>> 0;
4236
+ a = tmp;
4237
+ }
4238
+ a0 = a0 + a >>> 0;
4239
+ b0 = b0 + b >>> 0;
4240
+ c0 = c0 + c >>> 0;
4241
+ d0 = d0 + d >>> 0;
4242
+ }
4243
+ const out = new Uint8Array(16);
4244
+ new DataView(out.buffer).setUint32(0, a0, true);
4245
+ new DataView(out.buffer).setUint32(4, b0, true);
4246
+ new DataView(out.buffer).setUint32(8, c0, true);
4247
+ new DataView(out.buffer).setUint32(12, d0, true);
4248
+ return toHex(out);
4249
+ }
4250
+ var isNode, zlibPromise, cryptoPromise, SUBTLE_NAMES, UnsupportedAlgorithmError;
4251
+ var init_binary = __esm({
4252
+ "src/util/binary.ts"() {
4253
+ isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
4254
+ zlibPromise = null;
4255
+ cryptoPromise = null;
4256
+ SUBTLE_NAMES = {
4257
+ sha1: "SHA-1",
4258
+ sha256: "SHA-256",
4259
+ sha384: "SHA-384",
4260
+ sha512: "SHA-512"
4261
+ };
4262
+ UnsupportedAlgorithmError = class extends Error {
4263
+ constructor(algorithm) {
4264
+ super(`${algorithm} is not available in this environment`);
4265
+ this.name = "UnsupportedAlgorithmError";
4266
+ }
4267
+ };
4268
+ }
4269
+ });
4270
+
4063
4271
  // src/pkg/zip.ts
4064
4272
  var zip_exports = {};
4065
4273
  __export(zip_exports, {
@@ -4148,6 +4356,122 @@ var init_zip = __esm({
4148
4356
  }
4149
4357
  });
4150
4358
 
4359
+ // src/python/local-builder.ts
4360
+ var local_builder_exports = {};
4361
+ __export(local_builder_exports, {
4362
+ buildFromSource: () => buildFromSource
4363
+ });
4364
+ async function pipelineRoot() {
4365
+ const [{ existsSync }, { fileURLToPath: fileURLToPath2 }, { dirname: dirname3, resolve: resolve3 }] = await Promise.all([
4366
+ nodeBuiltin("fs"),
4367
+ nodeBuiltin("url"),
4368
+ nodeBuiltin("path")
4369
+ ]);
4370
+ const here = dirname3(fileURLToPath2(import.meta.url));
4371
+ for (const candidate of [
4372
+ resolve3(here, "../python-runtime"),
4373
+ resolve3(here, "../../python-runtime"),
4374
+ resolve3(here, "../../../python-runtime")
4375
+ ]) {
4376
+ if (existsSync(resolve3(candidate, "scripts/build_extension.py"))) return candidate;
4377
+ }
4378
+ return null;
4379
+ }
4380
+ async function run(command, args, cwd) {
4381
+ const { spawn } = await nodeBuiltin("child_process");
4382
+ return await new Promise((resolveRun) => {
4383
+ const child = spawn(command, args, { cwd });
4384
+ let stdout = "";
4385
+ let stderr = "";
4386
+ child.stdout.on("data", (chunk) => {
4387
+ stdout += String(chunk);
4388
+ });
4389
+ child.stderr.on("data", (chunk) => {
4390
+ stderr += String(chunk);
4391
+ });
4392
+ child.on("error", (error) => resolveRun({ code: -1, stdout, stderr: String(error) }));
4393
+ child.on("close", (code) => resolveRun({ code: code ?? -1, stdout, stderr }));
4394
+ });
4395
+ }
4396
+ async function readIndex(root) {
4397
+ const [{ readFileSync, existsSync }, { pathToFileURL: pathToFileURL2 }, { resolve: resolve3 }] = await Promise.all([
4398
+ nodeBuiltin("fs"),
4399
+ nodeBuiltin("url"),
4400
+ nodeBuiltin("path")
4401
+ ]);
4402
+ const directory2 = resolve3(root, "out/wheels");
4403
+ const file3 = resolve3(directory2, "index.json");
4404
+ if (!existsSync(file3)) return null;
4405
+ const parsed = JSON.parse(readFileSync(file3, "utf8"));
4406
+ return {
4407
+ ...parsed,
4408
+ baseUrl: pathToFileURL2(directory2).href
4409
+ };
4410
+ }
4411
+ async function buildFromSource(requirement, log = () => {
4412
+ }) {
4413
+ const root = await pipelineRoot();
4414
+ if (root === null) {
4415
+ return {
4416
+ built: false,
4417
+ index: null,
4418
+ classification: "blocked-toolchain",
4419
+ reason: "the build pipeline is not present; wheels can only be built from a checkout"
4420
+ };
4421
+ }
4422
+ log(`Building ${requirement} from source (no wheel for this runtime yet)`);
4423
+ const recipe = await run("python3", ["scripts/auto_recipe.py", requirement], root);
4424
+ if (recipe.code !== 0) {
4425
+ try {
4426
+ const reported = JSON.parse(recipe.stdout.trim().split("\n").at(-1) ?? "{}");
4427
+ if (reported.reason) {
4428
+ return {
4429
+ built: false,
4430
+ index: null,
4431
+ classification: reported.classification ?? "blocked-toolchain",
4432
+ reason: reported.reason
4433
+ };
4434
+ }
4435
+ } catch {
4436
+ }
4437
+ return {
4438
+ built: false,
4439
+ index: null,
4440
+ classification: "blocked-toolchain",
4441
+ reason: `could not describe ${requirement}: ${recipe.stderr.trim().slice(-400)}`
4442
+ };
4443
+ }
4444
+ const recipePath = recipe.stdout.trim().split("\n").at(-1);
4445
+ const build = await run("python3", ["scripts/build_extension.py", recipePath], root);
4446
+ if (build.code !== 0) {
4447
+ const tail2 = `${build.stdout}
4448
+ ${build.stderr}`.trim().split("\n").slice(-12).join("\n");
4449
+ return {
4450
+ built: false,
4451
+ index: null,
4452
+ classification: "blocked-toolchain",
4453
+ reason: `building ${requirement} failed:
4454
+ ${tail2}`
4455
+ };
4456
+ }
4457
+ const indexed = await run("python3", ["scripts/build_index.py"], root);
4458
+ if (indexed.code !== 0) {
4459
+ return {
4460
+ built: false,
4461
+ index: null,
4462
+ classification: "blocked-toolchain",
4463
+ reason: `built ${requirement} but could not index it: ${indexed.stderr.trim().slice(-300)}`
4464
+ };
4465
+ }
4466
+ log(`Built ${requirement}`);
4467
+ return { built: true, index: await readIndex(root) };
4468
+ }
4469
+ var init_local_builder = __esm({
4470
+ "src/python/local-builder.ts"() {
4471
+ init_binary();
4472
+ }
4473
+ });
4474
+
4151
4475
  // src/fs/vfs.ts
4152
4476
  init_errno();
4153
4477
  init_path();
@@ -15410,211 +15734,7 @@ var commands5 = [grep, find, xargs, diff, cmp];
15410
15734
  // src/bin/archive.ts
15411
15735
  init_mode();
15412
15736
  init_path();
15413
-
15414
- // src/util/binary.ts
15415
- var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
15416
- async function nodeBuiltin(name) {
15417
- const specifier = `node:${name}`;
15418
- return await import(
15419
- /* @vite-ignore */
15420
- /* webpackIgnore: true */
15421
- specifier
15422
- );
15423
- }
15424
- async function nodeOnlyModule(specifier) {
15425
- const parts = specifier.split("/");
15426
- const runtimeSpecifier = parts.join("/");
15427
- return await import(
15428
- /* @vite-ignore */
15429
- /* webpackIgnore: true */
15430
- runtimeSpecifier
15431
- );
15432
- }
15433
- var zlibPromise = null;
15434
- function nodeZlib() {
15435
- zlibPromise ??= nodeBuiltin("zlib");
15436
- return zlibPromise;
15437
- }
15438
- async function throughStream(data, stream) {
15439
- const source = new Blob([data]).stream();
15440
- const piped = source.pipeThrough(stream);
15441
- return new Uint8Array(await new Response(piped).arrayBuffer());
15442
- }
15443
- async function gzip(data) {
15444
- if (isNode) return new Uint8Array((await nodeZlib()).gzipSync(data));
15445
- return throughStream(data, new CompressionStream("gzip"));
15446
- }
15447
- async function gunzip(data) {
15448
- if (isNode) return new Uint8Array((await nodeZlib()).gunzipSync(data));
15449
- return throughStream(data, new DecompressionStream("gzip"));
15450
- }
15451
- async function deflate(data) {
15452
- if (isNode) return new Uint8Array((await nodeZlib()).deflateSync(data));
15453
- return throughStream(data, new CompressionStream("deflate"));
15454
- }
15455
- async function inflate(data) {
15456
- if (isNode) return new Uint8Array((await nodeZlib()).inflateSync(data));
15457
- return throughStream(data, new DecompressionStream("deflate"));
15458
- }
15459
- var cryptoPromise = null;
15460
- function nodeCrypto() {
15461
- cryptoPromise ??= nodeBuiltin("crypto");
15462
- return cryptoPromise;
15463
- }
15464
- var SUBTLE_NAMES = {
15465
- sha1: "SHA-1",
15466
- sha256: "SHA-256",
15467
- sha384: "SHA-384",
15468
- sha512: "SHA-512"
15469
- };
15470
- var UnsupportedAlgorithmError = class extends Error {
15471
- constructor(algorithm) {
15472
- super(`${algorithm} is not available in this environment`);
15473
- this.name = "UnsupportedAlgorithmError";
15474
- }
15475
- };
15476
- async function digestHex(algorithm, data) {
15477
- if (isNode) {
15478
- const { createHash } = await nodeCrypto();
15479
- return createHash(algorithm).update(data).digest("hex");
15480
- }
15481
- if (algorithm === "md5") return md5Hex(data);
15482
- const name = SUBTLE_NAMES[algorithm];
15483
- if (!name) throw new UnsupportedAlgorithmError(algorithm);
15484
- const buffer = await crypto.subtle.digest(name, data);
15485
- return toHex(new Uint8Array(buffer));
15486
- }
15487
- async function randomUuid() {
15488
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return crypto.randomUUID();
15489
- const { randomUUID } = await nodeCrypto();
15490
- return randomUUID();
15491
- }
15492
- function toHex(bytes2) {
15493
- let out = "";
15494
- for (const byte of bytes2) out += byte.toString(16).padStart(2, "0");
15495
- return out;
15496
- }
15497
- function md5Hex(input) {
15498
- const S = [
15499
- 7,
15500
- 12,
15501
- 17,
15502
- 22,
15503
- 7,
15504
- 12,
15505
- 17,
15506
- 22,
15507
- 7,
15508
- 12,
15509
- 17,
15510
- 22,
15511
- 7,
15512
- 12,
15513
- 17,
15514
- 22,
15515
- 5,
15516
- 9,
15517
- 14,
15518
- 20,
15519
- 5,
15520
- 9,
15521
- 14,
15522
- 20,
15523
- 5,
15524
- 9,
15525
- 14,
15526
- 20,
15527
- 5,
15528
- 9,
15529
- 14,
15530
- 20,
15531
- 4,
15532
- 11,
15533
- 16,
15534
- 23,
15535
- 4,
15536
- 11,
15537
- 16,
15538
- 23,
15539
- 4,
15540
- 11,
15541
- 16,
15542
- 23,
15543
- 4,
15544
- 11,
15545
- 16,
15546
- 23,
15547
- 6,
15548
- 10,
15549
- 15,
15550
- 21,
15551
- 6,
15552
- 10,
15553
- 15,
15554
- 21,
15555
- 6,
15556
- 10,
15557
- 15,
15558
- 21,
15559
- 6,
15560
- 10,
15561
- 15,
15562
- 21
15563
- ];
15564
- const K = new Uint32Array(64);
15565
- for (let i = 0; i < 64; i++) K[i] = Math.floor(Math.abs(Math.sin(i + 1)) * 2 ** 32);
15566
- const bitLength = input.length * 8;
15567
- const padded = new Uint8Array(((input.length + 8 >> 6) + 1) * 64);
15568
- padded.set(input);
15569
- padded[input.length] = 128;
15570
- const view = new DataView(padded.buffer);
15571
- view.setUint32(padded.length - 8, bitLength >>> 0, true);
15572
- view.setUint32(padded.length - 4, Math.floor(bitLength / 2 ** 32), true);
15573
- let a0 = 1732584193;
15574
- let b0 = 4023233417;
15575
- let c0 = 2562383102;
15576
- let d0 = 271733878;
15577
- for (let chunk = 0; chunk < padded.length; chunk += 64) {
15578
- const M = new Uint32Array(16);
15579
- for (let i = 0; i < 16; i++) M[i] = view.getUint32(chunk + i * 4, true);
15580
- let [a, b, c, d] = [a0, b0, c0, d0];
15581
- for (let i = 0; i < 64; i++) {
15582
- let f;
15583
- let g;
15584
- if (i < 16) {
15585
- f = b & c | ~b & d;
15586
- g = i;
15587
- } else if (i < 32) {
15588
- f = d & b | ~d & c;
15589
- g = (5 * i + 1) % 16;
15590
- } else if (i < 48) {
15591
- f = b ^ c ^ d;
15592
- g = (3 * i + 5) % 16;
15593
- } else {
15594
- f = c ^ (b | ~d);
15595
- g = 7 * i % 16;
15596
- }
15597
- const tmp = d;
15598
- d = c;
15599
- c = b;
15600
- const sum = a + f + K[i] + M[g] >>> 0;
15601
- b = b + (sum << S[i] | sum >>> 32 - S[i]) >>> 0;
15602
- a = tmp;
15603
- }
15604
- a0 = a0 + a >>> 0;
15605
- b0 = b0 + b >>> 0;
15606
- c0 = c0 + c >>> 0;
15607
- d0 = d0 + d >>> 0;
15608
- }
15609
- const out = new Uint8Array(16);
15610
- new DataView(out.buffer).setUint32(0, a0, true);
15611
- new DataView(out.buffer).setUint32(4, b0, true);
15612
- new DataView(out.buffer).setUint32(8, c0, true);
15613
- new DataView(out.buffer).setUint32(12, d0, true);
15614
- return toHex(out);
15615
- }
15616
-
15617
- // src/bin/archive.ts
15737
+ init_binary();
15618
15738
  var BLOCK = 512;
15619
15739
  var encoder4 = new TextEncoder();
15620
15740
  var decoder6 = new TextDecoder();
@@ -15927,6 +16047,7 @@ var zlibCompress = defineCommand({
15927
16047
  var commands6 = [tar, gzip2, gunzip2, zcat, zlibCompress];
15928
16048
 
15929
16049
  // src/bin/hash.ts
16050
+ init_binary();
15930
16051
  function makeSum(name, algorithm, path) {
15931
16052
  return defineCommand({
15932
16053
  name,
@@ -17355,7 +17476,7 @@ var wlPaste = defineCommand({
17355
17476
  });
17356
17477
  var commands11 = [xsel, xclip, pbcopy, pbpaste, wlCopy, wlPaste];
17357
17478
 
17358
- // src/runtime/node.ts
17479
+ // src/node/node.ts
17359
17480
  init_path();
17360
17481
  var NODE_VERSION = "v22.12.0";
17361
17482
  new TextEncoder();
@@ -17752,10 +17873,10 @@ function nodeCommands() {
17752
17873
  return [node, nodeVersionFile];
17753
17874
  }
17754
17875
 
17755
- // src/runtime/python.ts
17876
+ // src/python/python.ts
17756
17877
  init_path();
17757
17878
 
17758
- // src/runtime/python/host-abi.ts
17879
+ // src/python/host-abi.ts
17759
17880
  var SBX_HOST_ABI_VERSION = 1;
17760
17881
  var SBX_REQUEST_HEADER_BYTES = 16;
17761
17882
  var SBX_RESPONSE_HEADER_BYTES = 20;
@@ -17868,7 +17989,7 @@ Object.fromEntries(
17868
17989
  Object.entries(Errno).map(([name, code]) => [code, name])
17869
17990
  );
17870
17991
 
17871
- // src/runtime/python/manifest.ts
17992
+ // src/python/manifest.ts
17872
17993
  var MANIFEST_FORMAT = "sandboxedjs-python-runtime";
17873
17994
  var MANIFEST_SCHEMA_VERSION = 1;
17874
17995
  var ManifestError = class extends Error {
@@ -18225,9 +18346,17 @@ var wheels_default = {
18225
18346
 
18226
18347
  // package.json
18227
18348
  var package_default = {
18228
- version: "0.1.72"};
18349
+ version: "0.1.73"};
18229
18350
 
18230
- // src/runtime/python/config.ts
18351
+ // src/python/config.ts
18352
+ function runtimeModuleUrl() {
18353
+ const url = new URL(
18354
+ import.meta.url.includes("/src/python/") ? "../../dist/python/python.js" : "./python/python.js",
18355
+ import.meta.url
18356
+ );
18357
+ if (url.protocol !== "file:") url.searchParams.set("sbx-runtime", package_default.version);
18358
+ return url;
18359
+ }
18231
18360
  var bundledManifest = {
18232
18361
  format: "sandboxedjs-python-runtime",
18233
18362
  schemaVersion: 1,
@@ -18236,16 +18365,7 @@ var bundledManifest = {
18236
18365
  pythonVersion: "3.13.5",
18237
18366
  profile: "dynamic",
18238
18367
  hostAbi: { name: "sbx_host_v1", version: 1 },
18239
- artifacts: {
18240
- moduleUrl: (() => {
18241
- const url = new URL(
18242
- import.meta.url.includes("/src/runtime/python/") ? "../../../dist/python/python.js" : "./python/python.js",
18243
- import.meta.url
18244
- );
18245
- if (url.protocol !== "file:") url.searchParams.set("sbx-runtime", package_default.version);
18246
- return url.href;
18247
- })()
18248
- },
18368
+ artifacts: { moduleUrl: runtimeModuleUrl().href },
18249
18369
  capabilities: {
18250
18370
  threads: true,
18251
18371
  nativeExtensions: "dynamic",
@@ -18254,24 +18374,31 @@ var bundledManifest = {
18254
18374
  persistence: "memory"
18255
18375
  }
18256
18376
  };
18257
- var bundledWheelNames = {
18377
+ var embeddedWheels = {
18258
18378
  "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,
18259
18379
  "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
18260
18380
  };
18261
18381
  var bundledWheelIndex = {
18262
- baseUrl: "sbx-wheel:",
18263
- wheels: wheels_default.wheels.filter(
18264
- (wheel) => wheel.filename in bundledWheelNames
18265
- ),
18266
- files: bundledWheelNames
18382
+ baseUrl: new URL("./wheels", runtimeModuleUrl()).href,
18383
+ wheels: wheels_default.wheels,
18384
+ files: embeddedWheels
18267
18385
  };
18268
18386
  var config = {
18269
18387
  backend: "sbx-cpython-wasm",
18270
18388
  manifest: bundledManifest,
18271
- wheelIndex: bundledWheelIndex
18389
+ wheelIndex: bundledWheelIndex,
18390
+ /* On by default only where it can possibly work: a Node process, running
18391
+ * from a checkout that has the build pipeline. A browser has no compiler and
18392
+ * never will, and a published package has no pipeline -- in both, building
18393
+ * would replace a clear "no wheel for this package" with a hang or a
18394
+ * confusing failure, so both keep reporting instead. `local-builder` checks
18395
+ * for the pipeline again before it runs, so this is a cheap hint rather than
18396
+ * a promise. */
18397
+ buildFromSource: typeof process !== "undefined" && Boolean(process.versions?.node) && import.meta.url.startsWith("file:")
18272
18398
  };
18273
18399
  function setPythonBackend(options) {
18274
18400
  if (options.wheelIndex !== void 0) config.wheelIndex = options.wheelIndex;
18401
+ if (options.buildFromSource !== void 0) config.buildFromSource = options.buildFromSource;
18275
18402
  if (options.manifest !== void 0) config.manifest = validateManifest(options.manifest);
18276
18403
  if (options.workerUrl !== void 0) config.workerUrl = options.workerUrl;
18277
18404
  if (options.backend !== void 0) {
@@ -18945,10 +19072,11 @@ var FileService = class {
18945
19072
  }
18946
19073
  };
18947
19074
 
18948
- // src/runtime/python/backend.ts
19075
+ // src/python/backend.ts
18949
19076
  init_signals();
19077
+ init_binary();
18950
19078
 
18951
- // src/runtime/python/protocol.ts
19079
+ // src/python/protocol.ts
18952
19080
  var ProtocolError = class extends Error {
18953
19081
  code = "ERR_SBX_ABI_PROTOCOL";
18954
19082
  };
@@ -19425,7 +19553,7 @@ var VirtualTcpNetwork = class {
19425
19553
  }
19426
19554
  };
19427
19555
 
19428
- // src/runtime/python/syscall-server.ts
19556
+ // src/python/syscall-server.ts
19429
19557
  var MAX_TRANSFER = 8 * 1024 * 1024;
19430
19558
  var POLLIN = 1;
19431
19559
  var POLLOUT = 4;
@@ -19874,7 +20002,7 @@ function encodeStat(st) {
19874
20002
  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();
19875
20003
  }
19876
20004
 
19877
- // src/runtime/python/sync-transport.ts
20005
+ // src/python/sync-transport.ts
19878
20006
  var STATE = 0;
19879
20007
  var LENGTH = 1;
19880
20008
  var MORE = 2;
@@ -19977,7 +20105,7 @@ function concat3(parts) {
19977
20105
  return joined;
19978
20106
  }
19979
20107
 
19980
- // src/runtime/worker-host.ts
20108
+ // src/worker/worker-host.ts
19981
20109
  function defaultWorkerUrl() {
19982
20110
  return new URL("./worker-entry.js", import.meta.url);
19983
20111
  }
@@ -20048,7 +20176,7 @@ async function startNodeWorker(url, workerData) {
20048
20176
  };
20049
20177
  }
20050
20178
 
20051
- // src/runtime/python/supervisor.ts
20179
+ // src/python/supervisor.ts
20052
20180
  var nextGeneration = 1;
20053
20181
  async function startPythonProcess(options) {
20054
20182
  const unavailable2 = syncTransportUnavailableReason();
@@ -20163,10 +20291,10 @@ async function startPythonProcess(options) {
20163
20291
  };
20164
20292
  }
20165
20293
 
20166
- // src/runtime/python/install.ts
20294
+ // src/python/install.ts
20167
20295
  init_zip();
20168
20296
 
20169
- // src/runtime/python/pypi.ts
20297
+ // src/python/pypi.ts
20170
20298
  function parseRequirement(text2) {
20171
20299
  const cleaned = text2.replace(/#.*$/, "").trim();
20172
20300
  if (!cleaned) return null;
@@ -20245,7 +20373,7 @@ function splitOnce(text2, separator) {
20245
20373
  return at < 0 ? [text2] : [text2.slice(0, at), text2.slice(at + 1)];
20246
20374
  }
20247
20375
 
20248
- // src/runtime/python/extension-abi.ts
20376
+ // src/python/extension-abi.ts
20249
20377
  var EXTENSION_ABI = {
20250
20378
  "abiId": "sbxabi1-c2637d04695ad927",
20251
20379
  "wheelTag": "cp313-cp313-emscripten_5_0_6_wasm32",
@@ -20259,7 +20387,7 @@ var EXTENSION_ABI = {
20259
20387
  var WHEEL_TAG = EXTENSION_ABI.wheelTag;
20260
20388
  var PURE_PYTHON_TAGS = EXTENSION_ABI.wheel.acceptedPurePythonTags;
20261
20389
 
20262
- // src/runtime/python/resolver.ts
20390
+ // src/python/resolver.ts
20263
20391
  var WHEEL_INDEX_SCHEMA_VERSION = 1;
20264
20392
  function assertIndexUsable(index) {
20265
20393
  const declared = index.schemaVersion;
@@ -20569,7 +20697,7 @@ function requiresFromMetadata(text2) {
20569
20697
  return result;
20570
20698
  }
20571
20699
 
20572
- // src/runtime/python/install.ts
20700
+ // src/python/install.ts
20573
20701
  var SITE_PACKAGES = "/usr/lib/python3.13/site-packages";
20574
20702
  var SCRIPTS = "/usr/local/bin";
20575
20703
  function markerEnvironment(pythonVersion) {
@@ -20696,7 +20824,7 @@ if __name__ == '__main__':
20696
20824
  `;
20697
20825
  }
20698
20826
 
20699
- // src/runtime/python/backend.ts
20827
+ // src/python/backend.ts
20700
20828
  var PENDING_INHERITANCE = /* @__PURE__ */ new Map();
20701
20829
  var INHERIT_TOKEN = "SBX_PYTHON_INHERIT";
20702
20830
  var WNOHANG = 1;
@@ -20849,7 +20977,7 @@ async function resolveWorkerUrl(explicit) {
20849
20977
  nodeBuiltin("url")
20850
20978
  ]);
20851
20979
  if (existsSync(fileURLToPath2(beside))) return beside;
20852
- const built = new URL("../../../dist/python-worker.js", import.meta.url);
20980
+ const built = new URL("../../dist/python-worker.js", import.meta.url);
20853
20981
  if (existsSync(fileURLToPath2(built))) return pathToFileURL2(fileURLToPath2(built));
20854
20982
  throw new Error(
20855
20983
  "the SandboxedJs Python process worker has not been built; run `npm run build` in the package, or pass configurePython({ workerUrl })."
@@ -20934,7 +21062,76 @@ function containerMounts(ctx) {
20934
21062
  return mounts;
20935
21063
  }
20936
21064
 
20937
- // src/runtime/python/pip-command.ts
21065
+ // src/python/pip-command.ts
21066
+ init_binary();
21067
+ async function requestRemoteBuild(service, requirement, line) {
21068
+ line(`Asking ${new URL(service).host} to build ${requirement}`);
21069
+ try {
21070
+ const deadline = Date.now() + 20 * 6e4;
21071
+ let verdict = {};
21072
+ for (; ; ) {
21073
+ const response = await fetch(service, {
21074
+ method: "POST",
21075
+ headers: { "content-type": "application/json" },
21076
+ body: JSON.stringify({ requirement })
21077
+ });
21078
+ if (!response.ok) {
21079
+ return {
21080
+ built: false,
21081
+ index: null,
21082
+ classification: "blocked-toolchain",
21083
+ reason: `${service} answered ${response.status}`
21084
+ };
21085
+ }
21086
+ verdict = await response.json();
21087
+ if (verdict.state !== "building-wheel" && verdict.state !== "queued") break;
21088
+ if (Date.now() > deadline) {
21089
+ return {
21090
+ built: false,
21091
+ index: null,
21092
+ classification: "blocked-toolchain",
21093
+ reason: `${service} is still building ${requirement} after 20 minutes`
21094
+ };
21095
+ }
21096
+ await new Promise((wait) => setTimeout(wait, 3e3));
21097
+ }
21098
+ if (!verdict.built) {
21099
+ return {
21100
+ built: false,
21101
+ index: null,
21102
+ classification: verdict.classification ?? "blocked-toolchain",
21103
+ reason: verdict.reason ?? "the build service reported no wheel"
21104
+ };
21105
+ }
21106
+ const base2 = (verdict.indexUrl ?? service.replace(/\/build\/?$/, "")).replace(/\/$/, "");
21107
+ const fresh = await fetch(`${base2}/index.json`, { cache: "no-store" });
21108
+ if (!fresh.ok) {
21109
+ return {
21110
+ built: false,
21111
+ index: null,
21112
+ classification: "blocked-toolchain",
21113
+ reason: `${base2}/index.json answered ${fresh.status} after the build`
21114
+ };
21115
+ }
21116
+ const loaded = await fresh.json();
21117
+ line(`Built ${requirement}`);
21118
+ return {
21119
+ built: true,
21120
+ index: {
21121
+ baseUrl: base2,
21122
+ wheels: loaded.wheels ?? [],
21123
+ ...loaded.schemaVersion === void 0 ? {} : { schemaVersion: loaded.schemaVersion }
21124
+ }
21125
+ };
21126
+ } catch (error) {
21127
+ return {
21128
+ built: false,
21129
+ index: null,
21130
+ classification: "blocked-toolchain",
21131
+ reason: `could not reach the build service at ${service}: ${error.message}`
21132
+ };
21133
+ }
21134
+ }
20938
21135
  var pipCommand = defineCommand({
20939
21136
  name: "pip",
20940
21137
  path: "/usr/bin/pip",
@@ -20987,15 +21184,19 @@ environments. A package with no usable wheel is an error, never a silent skip.`,
20987
21184
  const cache = /* @__PURE__ */ new Map();
20988
21185
  let embeddedFiles = {};
20989
21186
  const request = async (url, timeoutMs, read) => {
20990
- if (url.startsWith("sbx-wheel:")) {
20991
- const filename = decodeURIComponent(url.slice("sbx-wheel:".length).replace(/^\/+/, ""));
20992
- const encoded = embeddedFiles[filename];
20993
- if (!encoded) throw new Error(`bundled wheel ${filename} is missing`);
20994
- const binary = atob(encoded);
21187
+ const embedded = embeddedFiles[decodeURIComponent(
21188
+ url.replace(/[?#].*$/, "").split("/").pop() ?? ""
21189
+ )];
21190
+ if (embedded) {
21191
+ const binary = atob(embedded);
20995
21192
  const bytes2 = new Uint8Array(binary.length);
20996
21193
  for (let i = 0; i < binary.length; i += 1) bytes2[i] = binary.charCodeAt(i);
20997
21194
  return await read(new Response(bytes2));
20998
21195
  }
21196
+ if (url.startsWith("sbx-wheel:")) {
21197
+ const filename = decodeURIComponent(url.slice("sbx-wheel:".length).replace(/^\/+/, ""));
21198
+ throw new Error(`bundled wheel ${filename} is missing`);
21199
+ }
20999
21200
  if (url.startsWith("file:")) {
21000
21201
  try {
21001
21202
  const [{ readFile }, { fileURLToPath: fileURLToPath2 }] = await Promise.all([
@@ -21056,29 +21257,48 @@ environments. A package with no usable wheel is an error, never a silent skip.`,
21056
21257
  index = configured;
21057
21258
  embeddedFiles = configured.files ?? {};
21058
21259
  }
21059
- try {
21060
- const report = await installRequirements({
21061
- index,
21062
- client,
21063
- vfs: ctx.vfs,
21064
- cred: ctx.cred,
21065
- requirements,
21066
- pythonVersion: pythonBackend().manifest?.pythonVersion ?? "3.13.5",
21067
- progress: {
21068
- collecting: (name) => ctx.line(`Collecting ${name}`),
21069
- downloading: () => {
21260
+ let attemptsLeft = 12;
21261
+ for (; ; ) {
21262
+ try {
21263
+ const report = await installRequirements({
21264
+ index,
21265
+ client,
21266
+ vfs: ctx.vfs,
21267
+ cred: ctx.cred,
21268
+ requirements,
21269
+ pythonVersion: pythonBackend().manifest?.pythonVersion ?? "3.13.5",
21270
+ progress: {
21271
+ collecting: (name) => ctx.line(`Collecting ${name}`),
21272
+ downloading: () => {
21273
+ }
21070
21274
  }
21275
+ });
21276
+ for (const skipped of report.skipped) {
21277
+ ctx.line(` Skipping ${skipped.name} (marker: ${skipped.marker})`);
21071
21278
  }
21072
- });
21073
- for (const skipped of report.skipped) {
21074
- ctx.line(` Skipping ${skipped.name} (marker: ${skipped.marker})`);
21279
+ ctx.line(
21280
+ `Successfully installed ${report.installed.map((p) => `${p.name}-${p.version}`).join(" ")}`
21281
+ );
21282
+ return 0;
21283
+ } catch (error) {
21284
+ const failure2 = error.failure;
21285
+ const buildable = failure2?.reason === "no-compatible-distribution" && Boolean(failure2.package) && failure2.sourceAvailable === true;
21286
+ if (!buildable || !pythonBackend().buildFromSource || attemptsLeft <= 0) {
21287
+ return ctx.fail(error.message ?? String(error));
21288
+ }
21289
+ attemptsLeft -= 1;
21290
+ const builder = pythonBackend().buildFromSource;
21291
+ 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));
21292
+ if (!outcome.built) {
21293
+ return ctx.fail(
21294
+ `${error.message}
21295
+ ${outcome.classification}: ${outcome.reason}`
21296
+ );
21297
+ }
21298
+ if (outcome.index) index = outcome.index;
21299
+ embeddedFiles = { ...embeddedFiles, ...outcome.index?.files ?? {} };
21300
+ cache.clear();
21075
21301
  }
21076
- ctx.line(
21077
- `Successfully installed ${report.installed.map((p) => `${p.name}-${p.version}`).join(" ")}`
21078
- );
21079
- return 0;
21080
- } catch (error) {
21081
- return ctx.fail(error.message ?? String(error));
21082
21302
  }
21083
21303
  }
21084
21304
  });
@@ -21096,7 +21316,7 @@ function listInstalled(ctx) {
21096
21316
  return 0;
21097
21317
  }
21098
21318
 
21099
- // src/runtime/emscripten-fs.ts
21319
+ // src/fs/emscripten-fs.ts
21100
21320
  init_errno();
21101
21321
  init_path();
21102
21322
  var EM_ERRNO = {
@@ -21351,7 +21571,10 @@ function mountContainerFs(FS, opts) {
21351
21571
  }
21352
21572
  }
21353
21573
 
21354
- // src/runtime/python-syscalls.ts
21574
+ // src/python/cpython.ts
21575
+ init_binary();
21576
+
21577
+ // src/python/python-syscalls.ts
21355
21578
  var EMPTY = new Uint8Array(0);
21356
21579
  function createStdinHost(ctx) {
21357
21580
  let pending = EMPTY;
@@ -22088,7 +22311,7 @@ function bindProgram(py, binding) {
22088
22311
  });
22089
22312
  }
22090
22313
 
22091
- // src/runtime/cpython.ts
22314
+ // src/python/cpython.ts
22092
22315
  var RESERVED_FOR_INTERPRETER = /* @__PURE__ */ new Set(["lib", "dev", "proc"]);
22093
22316
  var pyodideModule = null;
22094
22317
  var indexUrl;
@@ -22496,7 +22719,7 @@ var micropip = defineCommand({
22496
22719
  }
22497
22720
  });
22498
22721
 
22499
- // src/runtime/python.ts
22722
+ // src/python/python.ts
22500
22723
  var PYTHON_VERSION = "3.13";
22501
22724
  function configurePython(options = {}) {
22502
22725
  configureCPython({ indexURL: options.indexURL, moduleURL: options.pyodideURL });
@@ -22504,7 +22727,8 @@ function configurePython(options = {}) {
22504
22727
  ...options.backend !== void 0 ? { backend: options.backend } : {},
22505
22728
  ...options.manifest !== void 0 ? { manifest: options.manifest } : {},
22506
22729
  ...options.workerUrl !== void 0 ? { workerUrl: options.workerUrl } : {},
22507
- ...options.wheelIndex !== void 0 ? { wheelIndex: options.wheelIndex } : {}
22730
+ ...options.wheelIndex !== void 0 ? { wheelIndex: options.wheelIndex } : {},
22731
+ ...options.buildFromSource !== void 0 ? { buildFromSource: options.buildFromSource } : {}
22508
22732
  });
22509
22733
  }
22510
22734
  var isPythonAvailable = isCPythonAvailable;
@@ -22608,7 +22832,8 @@ function pythonCommands() {
22608
22832
  return usingOwnedPython() ? [python, pipCommand] : [python, micropip];
22609
22833
  }
22610
22834
 
22611
- // src/runtime/ffmpeg.ts
22835
+ // src/tools/ffmpeg.ts
22836
+ init_binary();
22612
22837
  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";
22613
22838
  var compiled = null;
22614
22839
  async function loadFactory() {
@@ -24683,7 +24908,7 @@ unless the container was created with network: { allowOutbound: true }.`,
24683
24908
  const packageSpec = packages[0] ?? spec;
24684
24909
  const packageName = packages[0] ? splitPackageSpec(packages[0]).name : specName;
24685
24910
  let command = packages.length > 0 ? spec : basename(specName);
24686
- const run = async (binary) => {
24911
+ const run2 = async (binary) => {
24687
24912
  const env2 = {
24688
24913
  ...ctx.env,
24689
24914
  PATH: `${binDir}:${ctx.env.PATH ?? ""}`,
@@ -24700,8 +24925,8 @@ unless the container was created with network: { allowOutbound: true }.`,
24700
24925
  }).wait();
24701
24926
  };
24702
24927
  if (!version) {
24703
- if (findLocalBin(ctx, command)) return run(command);
24704
- if (ctx.kernel.which(command, ctx.cwd, ctx.env, ctx.cred)) return run(command);
24928
+ if (findLocalBin(ctx, command)) return run2(command);
24929
+ if (ctx.kernel.which(command, ctx.cwd, ctx.env, ctx.cred)) return run2(command);
24705
24930
  }
24706
24931
  if (args.has("no-install")) {
24707
24932
  ctx.warn(`command not found: ${command}`);
@@ -24739,7 +24964,7 @@ unless the container was created with network: { allowOutbound: true }.`,
24739
24964
  }
24740
24965
  command = chosen;
24741
24966
  }
24742
- return run(command);
24967
+ return run2(command);
24743
24968
  }
24744
24969
  });
24745
24970
  function makeNpmAlias(name, path) {
@@ -24933,6 +25158,9 @@ function installUserland(kernel) {
24933
25158
  }
24934
25159
  }
24935
25160
 
25161
+ // src/container/container.ts
25162
+ init_binary();
25163
+
24936
25164
  // src/container/fs.ts
24937
25165
  init_path();
24938
25166
  async function bytesFor(data) {
@@ -25130,7 +25358,7 @@ var Session = class {
25130
25358
  }
25131
25359
  };
25132
25360
 
25133
- // src/runtime/node-child-process-bridge.ts
25361
+ // src/node/node-child-process-bridge.ts
25134
25362
  var KernelChildProcess = class {
25135
25363
  pid;
25136
25364
  command;
@@ -25281,7 +25509,7 @@ function installNodeChildProcessBridge(pod, kernel, cred) {
25281
25509
  };
25282
25510
  }
25283
25511
 
25284
- // src/runtime/host-module-tracker.ts
25512
+ // src/node/host-module-tracker.ts
25285
25513
  var HostModuleTracker = class {
25286
25514
  active = 0;
25287
25515
  disposed = false;
@@ -25343,7 +25571,7 @@ var HostModuleTracker = class {
25343
25571
  }
25344
25572
  };
25345
25573
 
25346
- // src/runtime/commonjs-engine.ts
25574
+ // src/node/commonjs-engine.ts
25347
25575
  init_path();
25348
25576
  var HELPERS = {
25349
25577
  /** Import a specifier and return an ES-module-shaped namespace. */
@@ -26202,7 +26430,7 @@ function splitSpecifier(specifier) {
26202
26430
  return { name: parts.slice(0, size).join("/"), subpath: parts.slice(size).join("/") };
26203
26431
  }
26204
26432
 
26205
- // src/runtime/readable-from.ts
26433
+ // src/node/readable-from.ts
26206
26434
  function createReadableFrom(Readable) {
26207
26435
  return function from(source, options = {}) {
26208
26436
  if (source && typeof source.pipe === "function") return source;
@@ -26251,7 +26479,7 @@ function installReadableFrom(streamModule5) {
26251
26479
  streamModule5.Readable.from = createReadableFrom(streamModule5.Readable);
26252
26480
  }
26253
26481
 
26254
- // src/runtime/util-module.ts
26482
+ // src/node/util-module.ts
26255
26483
  var customInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
26256
26484
  var promisifyCustom = /* @__PURE__ */ Symbol.for("nodejs.util.promisify.custom");
26257
26485
  var BREAK_LENGTH = 72;
@@ -26625,7 +26853,7 @@ var utilModule = {
26625
26853
  };
26626
26854
  var util_module_default = utilModule;
26627
26855
 
26628
- // src/runtime/assert-module.ts
26856
+ // src/node/assert-module.ts
26629
26857
  var AssertionError = class extends Error {
26630
26858
  actual;
26631
26859
  expected;
@@ -26794,8 +27022,8 @@ var bytes = (data) => {
26794
27022
  if (data instanceof ArrayBuffer) return new Uint8Array(data);
26795
27023
  return data;
26796
27024
  };
26797
- function codec(name, run) {
26798
- const sync2 = (data, options) => Buffer2.from(run(bytes(data), options));
27025
+ function codec(name, run2) {
27026
+ const sync2 = (data, options) => Buffer2.from(run2(bytes(data), options));
26799
27027
  const async_ = (data, options, callback) => {
26800
27028
  const done = typeof options === "function" ? options : callback;
26801
27029
  const settings = typeof options === "function" ? void 0 : options;
@@ -26959,7 +27187,7 @@ var urlModule = {
26959
27187
  };
26960
27188
  var url_module_default = urlModule;
26961
27189
 
26962
- // src/runtime/core-modules.ts
27190
+ // src/node/core-modules.ts
26963
27191
  init_path();
26964
27192
  var VirtualIncomingMessage = class extends streamModule4.Readable {
26965
27193
  method;
@@ -27683,7 +27911,7 @@ function toBytes2(data, encoding) {
27683
27911
  return typeof data === "string" ? Buffer2.from(data, encoding) : data;
27684
27912
  }
27685
27913
 
27686
- // src/runtime/sync-channel.ts
27914
+ // src/worker/sync-channel.ts
27687
27915
  var STATE2 = 0;
27688
27916
  var LENGTH2 = 1;
27689
27917
  var MORE2 = 2;
@@ -27932,7 +28160,7 @@ function buildSyncFamily(syncSpawn, throughShell, defaultCwd, environmentFor) {
27932
28160
  spawnSync: unavailable("spawnSync")
27933
28161
  };
27934
28162
  }
27935
- const run = (file3, args, options) => {
28163
+ const run2 = (file3, args, options) => {
27936
28164
  const resolved = options.shell ? throughShell([file3, ...args].join(" "), options) : { file: file3, args };
27937
28165
  const input = options.input === void 0 ? void 0 : typeof options.input === "string" ? options.input : new TextDecoder().decode(options.input);
27938
28166
  const inherit = options.stdio === "inherit" || Array.isArray(options.stdio) && options.stdio[0] === "inherit";
@@ -27966,7 +28194,7 @@ ${result.stderr}`), {
27966
28194
  };
27967
28195
  const spawnSync = (file3, args = [], options = {}) => {
27968
28196
  const [list, opts] = Array.isArray(args) ? [args, options] : [[], args];
27969
- const result = run(file3, list, opts);
28197
+ const result = run2(file3, list, opts);
27970
28198
  return {
27971
28199
  pid: 0,
27972
28200
  status: result.status,
@@ -27979,9 +28207,9 @@ ${result.stderr}`), {
27979
28207
  };
27980
28208
  const execFileSync = (file3, args = [], options = {}) => {
27981
28209
  const [list, opts] = Array.isArray(args) ? [args, options] : [[], args];
27982
- return orThrow(run(file3, list, opts), [file3, ...list].join(" "), opts);
28210
+ return orThrow(run2(file3, list, opts), [file3, ...list].join(" "), opts);
27983
28211
  };
27984
- const execSync = (command, options = {}) => orThrow(run(command, [], { ...options, shell: options.shell ?? true }), command, options);
28212
+ const execSync = (command, options = {}) => orThrow(run2(command, [], { ...options, shell: options.shell ?? true }), command, options);
27985
28213
  return { spawnSync, execFileSync, execSync };
27986
28214
  }
27987
28215
  function normalize3(options, callback) {
@@ -28001,7 +28229,7 @@ function unavailable(name) {
28001
28229
  };
28002
28230
  }
28003
28231
 
28004
- // src/runtime/core-modules.ts
28232
+ // src/node/core-modules.ts
28005
28233
  init_signals();
28006
28234
  var CSI_KEYS = {
28007
28235
  "[A": "up",
@@ -28408,7 +28636,7 @@ function createReadlineModule(defaultInput, defaultOutput = () => void 0) {
28408
28636
  return { ...base2, promises: { ...base2, Interface, createInterface } };
28409
28637
  }
28410
28638
 
28411
- // src/runtime/core-modules.ts
28639
+ // src/node/core-modules.ts
28412
28640
  installReadableFrom(streamModule4);
28413
28641
  var Dirent = class {
28414
28642
  /** Node 20+ exposes the containing directory, and `fs.glob` consumers read it. */
@@ -29576,7 +29804,7 @@ var builtinNames2 = [
29576
29804
  ...stubNames
29577
29805
  ];
29578
29806
 
29579
- // src/runtime/memory-volume.ts
29807
+ // src/fs/memory-volume.ts
29580
29808
  init_path();
29581
29809
  var VolumeError = class extends Error {
29582
29810
  constructor(code, operation, path) {
@@ -29886,7 +30114,7 @@ var MemoryVolume = class {
29886
30114
  }
29887
30115
  };
29888
30116
 
29889
- // src/runtime/mirroring-volume.ts
30117
+ // src/fs/mirroring-volume.ts
29890
30118
  init_path();
29891
30119
  var MirroringVolume = class {
29892
30120
  constructor(inner = new MemoryVolume()) {
@@ -30292,7 +30520,8 @@ function sameBytes(a, b) {
30292
30520
  return true;
30293
30521
  }
30294
30522
 
30295
- // src/runtime/host-esbuild.ts
30523
+ // src/tools/host-esbuild.ts
30524
+ init_binary();
30296
30525
  var ASYNC_API = ["transform", "build", "context", "formatMessages", "analyzeMetafile"];
30297
30526
  function createHostEsbuild() {
30298
30527
  let loading = null;
@@ -30360,7 +30589,8 @@ function ensureProcessGlobal() {
30360
30589
  });
30361
30590
  }
30362
30591
 
30363
- // src/runtime/rolldown-node-binding.ts
30592
+ // src/tools/rolldown-node-binding.ts
30593
+ init_binary();
30364
30594
  async function loadNodeApi() {
30365
30595
  const [moduleApi, fsApi, pathApi, urlApi] = await Promise.all([
30366
30596
  nodeBuiltin("module"),
@@ -30478,7 +30708,7 @@ function resolveWorkerPath(node2) {
30478
30708
  const here = dirname3(fileURLToPath2(import.meta.url));
30479
30709
  const candidates = [
30480
30710
  join3(here, WORKER_FILE),
30481
- /* src/runtime → dist, for a checkout that has been built. */
30711
+ /* src/tools → dist, for a checkout that has been built. */
30482
30712
  join3(here, "..", "..", "dist", WORKER_FILE)
30483
30713
  ];
30484
30714
  return candidates.find((candidate) => existsSync(candidate)) ?? null;
@@ -30512,7 +30742,7 @@ function unreferenceWorker(worker) {
30512
30742
  worker.unref();
30513
30743
  }
30514
30744
 
30515
- // src/runtime/host-rolldown.ts
30745
+ // src/tools/host-rolldown.ts
30516
30746
  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'] }";
30517
30747
  var isNodeHost = typeof process !== "undefined" && Boolean(process.versions?.node);
30518
30748
  async function loadHostRolldownBinding() {
@@ -30539,7 +30769,7 @@ ${BUNDLER_HINT}`),
30539
30769
  }
30540
30770
  }
30541
30771
 
30542
- // src/runtime/local-runtime-pod.ts
30772
+ // src/worker/local-runtime-pod.ts
30543
30773
  init_path();
30544
30774
  var WASM_ALIASES = {
30545
30775
  esbuild: "esbuild-wasm",
@@ -31178,7 +31408,7 @@ function attachRolldownMirror(binding, volume, root) {
31178
31408
  volume.attach(fs, root);
31179
31409
  }
31180
31410
 
31181
- // src/runtime/remote-volume.ts
31411
+ // src/fs/remote-volume.ts
31182
31412
  var encoder8 = new TextEncoder();
31183
31413
  var decoder8 = new TextDecoder();
31184
31414
  function encodeFrame(header, body) {
@@ -31241,7 +31471,7 @@ function serveVolume(volume) {
31241
31471
  };
31242
31472
  }
31243
31473
 
31244
- // src/runtime/sync-syscalls.ts
31474
+ // src/worker/sync-syscalls.ts
31245
31475
  var SPAWN_OP = "spawnSync";
31246
31476
  function serveSyncSyscalls(options) {
31247
31477
  const volumeHandler = serveVolume(options.volume);