@statewalker/cellb 0.8.7 → 0.8.9

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.
Files changed (70) hide show
  1. package/README.md +1 -1
  2. package/dist/adapters/node-sqlite.js +42 -13
  3. package/dist/adapters/node-sqlite.js.map +1 -1
  4. package/dist/bindings/cjs-module.d.ts +7 -0
  5. package/dist/bindings/cjs-module.js +96 -0
  6. package/dist/bindings/cjs-module.js.map +1 -0
  7. package/dist/bindings/module-registry.d.ts +33 -0
  8. package/dist/bindings/module-registry.js +180 -0
  9. package/dist/bindings/module-registry.js.map +1 -0
  10. package/dist/bindings/worker-loader.d.ts +23 -5
  11. package/dist/bindings/worker-loader.js +75 -4
  12. package/dist/bindings/worker-loader.js.map +1 -1
  13. package/dist/core/handles.d.ts +21 -1
  14. package/dist/core/handles.js +49 -3
  15. package/dist/core/handles.js.map +1 -1
  16. package/dist/core/namespace.js +4 -1
  17. package/dist/core/namespace.js.map +1 -1
  18. package/dist/core/runtime.d.ts +8 -0
  19. package/dist/core/runtime.js +3 -3
  20. package/dist/core/runtime.js.map +1 -1
  21. package/dist/index.d.ts +5 -0
  22. package/dist/index.js +5 -0
  23. package/dist/index.js.map +1 -1
  24. package/dist/isolate/browser.d.ts +1 -1
  25. package/dist/isolate/browser.js +3 -1
  26. package/dist/isolate/browser.js.map +1 -1
  27. package/dist/isolate/host.js +20 -2
  28. package/dist/isolate/host.js.map +1 -1
  29. package/dist/isolate/isolate-worker.js +13 -1
  30. package/dist/isolate/isolate-worker.js.map +1 -1
  31. package/dist/isolate/isolate.js +11 -0
  32. package/dist/isolate/isolate.js.map +1 -1
  33. package/dist/isolate/node-entry.js +33 -0
  34. package/dist/isolate/node-entry.js.map +1 -1
  35. package/dist/isolate/protocol.d.ts +1 -0
  36. package/dist/isolate/protocol.js +228 -13
  37. package/dist/isolate/protocol.js.map +1 -1
  38. package/dist/isolate/writable-globals.d.ts +9 -0
  39. package/dist/isolate/writable-globals.js +45 -0
  40. package/dist/isolate/writable-globals.js.map +1 -0
  41. package/dist/node-compat/bundle-files.d.ts +26 -0
  42. package/dist/node-compat/bundle-files.js +210 -0
  43. package/dist/node-compat/bundle-files.js.map +1 -0
  44. package/dist/node-compat/fs.d.ts +13 -1
  45. package/dist/node-compat/fs.js +54 -15
  46. package/dist/node-compat/fs.js.map +1 -1
  47. package/dist/project/browser-modules.d.ts +1 -1
  48. package/dist/project/browser-modules.js +25 -5
  49. package/dist/project/browser-modules.js.map +1 -1
  50. package/dist/project/cloudflare-workers.d.ts +9 -0
  51. package/dist/project/cloudflare-workers.js +14 -0
  52. package/dist/project/cloudflare-workers.js.map +1 -1
  53. package/dist/project/module-rules.js +31 -10
  54. package/dist/project/module-rules.js.map +1 -1
  55. package/dist/project/node-project.d.ts +2 -0
  56. package/dist/project/node-project.js +154 -25
  57. package/dist/project/node-project.js.map +1 -1
  58. package/dist/project/site-loader.js +2 -1
  59. package/dist/project/site-loader.js.map +1 -1
  60. package/dist/project/uint8array-base64.d.ts +7 -0
  61. package/dist/project/uint8array-base64.js +96 -0
  62. package/dist/project/uint8array-base64.js.map +1 -0
  63. package/dist/project/workers-globals-module.d.ts +1 -0
  64. package/dist/project/workers-globals-module.js +3 -0
  65. package/dist/project/workers-globals-module.js.map +1 -1
  66. package/dist/project/wrangler.js +8 -9
  67. package/dist/project/wrangler.js.map +1 -1
  68. package/dist/ws/upgrade.js +18 -1
  69. package/dist/ws/upgrade.js.map +1 -1
  70. package/package.json +10 -10
@@ -5,7 +5,8 @@ import { join, resolve } from "node:path";
5
5
  import { Worker as NodeWorker } from "node:worker_threads";
6
6
  import { build } from "esbuild";
7
7
  import { applyD1Migrations } from "../bindings/d1-migrations.js";
8
- import { moduleText, outboundFetch, } from "../bindings/worker-loader.js";
8
+ import { exportNamesByModule, IMPORT_FROM, prefixModule, RESOLVE_MODULE_NAME_SOURCE, routeDynamicImports, } from "../bindings/module-registry.js";
9
+ import { compileWasmModules, moduleText, outboundFetch, wasmModulesOf, } from "../bindings/worker-loader.js";
9
10
  import { ctxExports } from "../core/handles.js";
10
11
  import { isolatedModuleLoader } from "../isolate/host.js";
11
12
  import * as workersClasses from "./cloudflare-workers.js";
@@ -28,6 +29,72 @@ const nodeBuiltinName = new RegExp(`^(${builtinModules
28
29
  .filter((m) => !m.startsWith("_") && !m.includes(":"))
29
30
  .map((m) => m.replace(/[/]/g, "\\/"))
30
31
  .join("|")})$`);
32
+ /** Worker code's `node:fs` under nodejs_compat on Node: Node's own, with workerd's `/bundle`. */
33
+ const FS_OVERLAY = `import * as real from "node:fs";
34
+ import { bundleFs } from "cellb:bundle-fs";
35
+ export * from "node:fs";
36
+ const o = bundleFs(real);
37
+ export const { existsSync, readFileSync, statSync, lstatSync, readdirSync, accessSync, readFile, stat, lstat, readdir, access, promises } = o;
38
+ export default { ...real, ...o };`;
39
+ /** Worker code's `node:fs/promises`, the same way. */
40
+ const FS_PROMISES_OVERLAY = `import * as real from "node:fs/promises";
41
+ import { bundleFsPromises } from "cellb:bundle-fs";
42
+ export * from "node:fs/promises";
43
+ const o = bundleFsPromises(real);
44
+ export const { readFile, stat, lstat, readdir, access } = o;
45
+ export default o;`;
46
+ /**
47
+ * The modules of loaded code as ES module text, each `import()` the bundler cannot link going to
48
+ * the `cellb:modules` registry instead (module-registry.ts).
49
+ */
50
+ function loadedModuleTexts(code) {
51
+ const texts = {};
52
+ const names = new Set(Object.keys(code.modules));
53
+ for (const [name, m] of Object.entries(code.modules))
54
+ texts[name] = moduleText(m, name, names);
55
+ const modules = {};
56
+ for (const [name, text] of Object.entries(texts)) {
57
+ const routed = routeDynamicImports(text, name);
58
+ let prelude = routed === undefined ? "" : `import { importFrom as ${IMPORT_FROM} } from "cellb:modules"; `;
59
+ // The main module evaluates the registry, so it is there before any code runs.
60
+ if (name === code.mainModule && !prelude)
61
+ prelude = 'import "cellb:modules"; ';
62
+ modules[name] = prelude ? prefixModule(routed ?? text, prelude) : text;
63
+ }
64
+ return { modules, registry: registrySource(texts, code.mainModule) };
65
+ }
66
+ /**
67
+ * What an import of loaded code that names none of its modules becomes: a module that throws when
68
+ * it is evaluated, so the failure comes where workerd's would (when the importing module runs), not
69
+ * at build time or when an unrelated module loads. CommonJS, so any named import of it builds.
70
+ */
71
+ function missingModule(spec, importer) {
72
+ const message = `No such module "${spec}" (imported from "${importer}")`;
73
+ return {
74
+ path: `${importer}\u0000${spec}`,
75
+ namespace: "cells-missing",
76
+ pluginData: `throw new Error(${JSON.stringify(message)});\nmodule.exports = {};`,
77
+ };
78
+ }
79
+ /**
80
+ * The `cellb:modules` registry of a bundle of loaded code: each module, imported on demand. It
81
+ * also publishes itself as `globalThis.__cellbLoadedModules`, where an isolate thread's module
82
+ * hooks find it (node-entry.ts: `import()` from code built with `Function`).
83
+ */
84
+ function registrySource(texts, main) {
85
+ const q = JSON.stringify;
86
+ const names = Object.keys(texts);
87
+ return [
88
+ `const names = new Set(${q(names)});`,
89
+ `const resolve = ${RESOLVE_MODULE_NAME_SOURCE};`,
90
+ `const table = { ${names.map((n) => `${q(n)}: () => import(${q(`memory:${n}`)})`).join(", ")} };`,
91
+ "export const importFrom = (spec, importer) => {",
92
+ " const name = resolve(String(spec), importer, names);",
93
+ " return name === undefined ? import(spec) : table[name]();",
94
+ "};",
95
+ `globalThis.__cellbLoadedModules = { main: ${q(main)}, names, exportNames: ${q(exportNamesByModule(texts))}, load: (name) => table[name]() };`,
96
+ ].join("\n");
97
+ }
31
98
  /**
32
99
  * Node host: bundles `main` with esbuild (as `celld deploy` does) and builds the runtime.
33
100
  * `cloudflare:workers` resolves to cellb's module so user classes extend the
@@ -121,8 +188,23 @@ export async function bundleWorker(entry, logs, outbound, opts = {}) {
121
188
  path: "console",
122
189
  namespace: "cells-console",
123
190
  }));
124
- // nodejs_compat on a Node host: `node:*` are the real Node.js modules.
191
+ // nodejs_compat on a Node host: `node:*` are the real Node.js modules, except that
192
+ // `node:fs` also reads workerd's `/bundle` (node-compat/bundle-files.ts).
125
193
  if (opts.nodeCompat) {
194
+ b.onResolve({ filter: /^(node:)?fs(\/promises)?$/ }, (a) => {
195
+ const name = a.path.replace(/^node:/, "");
196
+ return a.namespace === "cells-fs"
197
+ ? { path: `node:${name}`, external: true }
198
+ : { path: name, namespace: "cells-fs" };
199
+ });
200
+ b.onResolve({ filter: /^cellb:bundle-fs$/ }, () => ({
201
+ path: ownModule(join(import.meta.dirname, "../node-compat"), "bundle-files"),
202
+ external: true,
203
+ }));
204
+ b.onLoad({ filter: /.*/, namespace: "cells-fs" }, (a) => ({
205
+ contents: a.path === "fs" ? FS_OVERLAY : FS_PROMISES_OVERLAY,
206
+ loader: "js",
207
+ }));
126
208
  b.onResolve({ filter: /^node:/ }, (a) => ({ path: a.path, external: true }));
127
209
  // workerd's nodejs_compat also takes the bare names ("path", "fs/promises").
128
210
  b.onResolve({ filter: nodeBuiltinName }, (a) => ({
@@ -168,16 +250,41 @@ export async function bundleWorker(entry, logs, outbound, opts = {}) {
168
250
  path: a.path.slice(7),
169
251
  namespace: "memory",
170
252
  }));
171
- b.onResolve({ filter: /^\.{1,2}\// }, (a) => a.namespace === "memory"
172
- ? {
173
- path: new URL(a.path, `file:///${a.importer}`).pathname.slice(1),
174
- namespace: "memory",
175
- }
176
- : undefined);
253
+ b.onResolve({ filter: /^\.{1,2}\// }, (a) => {
254
+ if (a.namespace !== "memory")
255
+ return undefined;
256
+ const path = new URL(a.path, `file:///${a.importer}`).pathname.slice(1);
257
+ // Not one of the loaded modules: it fails when it runs, as on workerd (missingModule).
258
+ return path in memory
259
+ ? { path, namespace: "memory" }
260
+ : missingModule(a.path, a.importer);
261
+ });
177
262
  b.onLoad({ filter: /.*/, namespace: "memory" }, (a) => ({
178
263
  contents: memory[a.path],
179
264
  loader: "js",
180
265
  }));
266
+ b.onResolve({ filter: /^cellb:modules$/ }, () => ({
267
+ path: "modules",
268
+ namespace: "cells-modules",
269
+ }));
270
+ b.onLoad({ filter: /.*/, namespace: "cells-modules" }, () => ({
271
+ contents: entry.registry ??
272
+ "export const importFrom = (s) => import(s);",
273
+ loader: "js",
274
+ }));
275
+ // Anything else loaded code imports: a module's whole name (a URL, say), as workerd names
276
+ // modules, or else a module that throws when it is evaluated (missingModule).
277
+ b.onResolve({ filter: /.*/ }, (a) => {
278
+ if (a.namespace !== "memory")
279
+ return undefined;
280
+ if (a.path in memory)
281
+ return { path: a.path, namespace: "memory" };
282
+ return missingModule(a.path, a.importer);
283
+ });
284
+ b.onLoad({ filter: /.*/, namespace: "cells-missing" }, (a) => ({
285
+ contents: a.pluginData,
286
+ loader: "js",
287
+ }));
181
288
  },
182
289
  },
183
290
  moduleRulesPlugin(opts.rules),
@@ -186,15 +293,14 @@ export async function bundleWorker(entry, logs, outbound, opts = {}) {
186
293
  return (await import(/* @vite-ignore */ out));
187
294
  }
188
295
  /** Worker Loader on Node: compiles `WorkerCode.modules` with esbuild (as celld compiles loaded code). */
189
- export const nodeModuleLoader = async (_id, code, logs) => {
296
+ export const nodeModuleLoader = async (_id, loaded, logs) => {
297
+ const code = await compileWasmModules(loaded);
190
298
  const outbound = outboundFetch(code);
191
- const modules = {};
192
- for (const [name, m] of Object.entries(code.modules))
193
- modules[name] = moduleText(m);
299
+ const { modules, registry } = loadedModuleTexts(code);
194
300
  // `env` and `exports` of the loaded code's `cloudflare:workers` are its own (WorkerCode.env).
195
301
  const env = code.env ?? {};
196
302
  const scope = workerScope(env);
197
- const module = (await bundleWorker({ modules, main: code.mainModule }, logs, outbound, {
303
+ const module = (await bundleWorker({ modules, main: code.mainModule, registry }, logs, outbound, {
198
304
  scope,
199
305
  }));
200
306
  scope.bind({ env, exports: ctxExports(module, env) });
@@ -285,12 +391,10 @@ export function nodeIsolatedLoader(storage) {
285
391
  port.unref(); // an idle isolate never keeps the process alive
286
392
  return { port: port, terminate: () => void port.terminate() };
287
393
  },
288
- prepare: async (_id, code) => {
394
+ prepare: async (_id, loaded) => {
289
395
  isolateEntry ??= buildIsolateEntry();
290
- await isolateEntry;
291
- const modules = {};
292
- for (const [name, m] of Object.entries(code.modules))
293
- modules[name] = moduleText(m);
396
+ const [code] = await Promise.all([compileWasmModules(loaded), isolateEntry]);
397
+ const { modules, registry } = loadedModuleTexts(code);
294
398
  const out = await build({
295
399
  entryPoints: [`memory:${code.mainModule}`],
296
400
  write: false,
@@ -325,21 +429,46 @@ export function nodeIsolatedLoader(storage) {
325
429
  path: a.path.slice(7),
326
430
  namespace: "memory",
327
431
  }));
328
- b.onResolve({ filter: /^\.{1,2}\// }, (a) => a.namespace === "memory"
329
- ? {
330
- path: new URL(a.path, `file:///${a.importer}`).pathname.slice(1),
331
- namespace: "memory",
332
- }
333
- : undefined);
432
+ b.onResolve({ filter: /^\.{1,2}\// }, (a) => {
433
+ if (a.namespace !== "memory")
434
+ return undefined;
435
+ const path = new URL(a.path, `file:///${a.importer}`).pathname.slice(1);
436
+ // Not one of the loaded modules: it fails when it runs, as on workerd (missingModule).
437
+ return path in modules
438
+ ? { path, namespace: "memory" }
439
+ : missingModule(a.path, a.importer);
440
+ });
334
441
  b.onLoad({ filter: /.*/, namespace: "memory" }, (a) => ({
335
442
  contents: modules[a.path],
336
443
  loader: "js",
337
444
  }));
445
+ b.onResolve({ filter: /^cellb:modules$/ }, () => ({
446
+ path: "modules",
447
+ namespace: "cells-modules",
448
+ }));
449
+ b.onLoad({ filter: /.*/, namespace: "cells-modules" }, () => ({
450
+ contents: registry,
451
+ loader: "js",
452
+ }));
453
+ // Anything else loaded code imports: a module's whole name (a URL, say), as workerd names
454
+ // modules, or else a module that throws when it is evaluated (missingModule).
455
+ b.onResolve({ filter: /.*/ }, (a) => {
456
+ if (a.namespace !== "memory")
457
+ return undefined;
458
+ if (a.path in modules)
459
+ return { path: a.path, namespace: "memory" };
460
+ return missingModule(a.path, a.importer);
461
+ });
462
+ b.onLoad({ filter: /.*/, namespace: "cells-missing" }, (a) => ({
463
+ contents: a.pluginData,
464
+ loader: "js",
465
+ }));
338
466
  },
339
467
  },
340
468
  ],
341
469
  });
342
- return { source: out.outputFiles[0].text };
470
+ // Compiled wasm modules travel beside the source (a worker thread takes them as they are).
471
+ return { source: out.outputFiles[0].text, wasm: wasmModulesOf(code) };
343
472
  },
344
473
  });
345
474
  }
@@ -1 +1 @@
1
- {"version":3,"file":"node-project.js","sourceRoot":"","sources":["../../src/project/node-project.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAGL,UAAU,EACV,aAAa,GACd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,KAAK,cAAc,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAmB,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAoB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,WAAW,EAGX,mBAAmB,EACnB,YAAY,EACZ,cAAc,GAEf,MAAM,eAAe,CAAC;AAEvB,oGAAoG;AACpG,MAAM,UAA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AC,6BAA6B,CAAC,CAAC;IACtE,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AACD,KAAK,UAAU,iBAAiB;IAC9B,gBAAgB,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,gBAAgB,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;IACtF,MAAM,KAAK,CAAC;QACV,WAAW,EAAE,CAAC,SAAS,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;QACtE,OAAO,EAAE,gBAAgB;QACzB,MAAM,EAAE,IAAI;QACZ,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,QAAQ;QAChB,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAC;IACH,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,wFAAwF;AACxF,SAAS,wBAAwB,CAAC,KAAkB;IAClD,MAAM,CAAC,GAAG,UAAqC,CAAC;IAChD,CAAC,CAAC,mBAAmB,GAAG,KAAK,CAAC;IAC9B,CAAC,CAAC,oBAAoB,KAAK,cAAc,CAAC;IAC1C,uEAAuE;IACvE,CAAC,CAAC,kBAAkB,KAAK,IAAI,KAAK,CAChC,EAAE,EACF,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAC5E,CAAC;AACJ,CAAC;AACD,MAAM,cAAc,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC","sourcesContent":["import {\n existsSync,\n mkdtempSync,\n readdirSync,\n readFileSync,\n statSync,\n writeFileSync,\n} from \"node:fs\";\nimport { builtinModules, createRequire } from \"node:module\";\nimport { tmpdir } from \"node:os\";\nimport { join, resolve } from \"node:path\";\nimport { Worker as NodeWorker } from \"node:worker_threads\";\nimport { build } from \"esbuild\";\nimport { applyD1Migrations } from \"../bindings/d1-migrations.js\";\nimport {\n type LogSink,\n type ModuleLoader,\n moduleText,\n outboundFetch,\n} from \"../bindings/worker-loader.js\";\nimport { ctxExports } from \"../core/handles.js\";\nimport type { WorkerModule } from \"../core/runtime.js\";\nimport { isolatedModuleLoader } from \"../isolate/host.js\";\nimport type { PortLike } from \"../isolate/protocol.js\";\nimport type { CellStorage } from \"../ports.js\";\nimport * as workersClasses from \"./cloudflare-workers.js\";\nimport { parseJsonc } from \"./jsonc.js\";\nimport { type ModuleRule, moduleRulesPlugin } from \"./module-rules.js\";\nimport { ownModule } from \"./own-module.js\";\nimport { type WorkerScope, workerScope } from \"./worker-scope.js\";\nimport {\n createProjectRuntime,\n hasNodeCompat,\n loadProjectBindings,\n loadTimeEnv,\n type ProjectHost,\n type ProjectRuntime,\n populatesProcessEnv,\n processEnvOf,\n WRANGLER_FILES,\n type WranglerConfig,\n} from \"./wrangler.js\";\n\n/** Reads `wrangler.jsonc` / `wrangler.json` of a project directory (celld reads the same files). */\nexport function readWranglerConfig(dir: string): WranglerConfig {\n for (const name of WRANGLER_FILES) {\n const p = join(dir, name);\n if (existsSync(p)) return parseJsonc(readFileSync(p, \"utf8\")) as WranglerConfig;\n }\n throw new Error(`no wrangler.jsonc or wrangler.json in ${dir}`);\n}\n\n/** A bare Node.js built-in specifier (\"path\", \"fs/promises\"), not one of a package. */\nconst nodeBuiltinName = new RegExp(\n `^(${builtinModules\n .filter((m) => !m.startsWith(\"_\") && !m.includes(\":\"))\n .map((m) => m.replace(/[/]/g, \"\\\\/\"))\n .join(\"|\")})$`,\n);\n\n/**\n * Node host: bundles `main` with esbuild (as `celld deploy` does) and builds the runtime.\n * `cloudflare:workers` resolves to cellb's module so user classes extend the\n * runtime's own DurableObject / WorkerEntrypoint.\n */\n/** Bundles Worker code (a file, or in-memory modules) with the runtime's module mappings, then imports it. */\nexport async function bundleWorker(\n entry: { path: string } | { modules: Record<string, string>; main: string },\n logs?: LogSink,\n outbound?: typeof fetch,\n opts: {\n nodeCompat?: boolean;\n standardBinaryType?: boolean;\n scope?: WorkerScope;\n /** wrangler `rules` for non-JS imports (the defaults: `.wasm`, `.bin`, `.txt`…, as wrangler). */\n rules?: ModuleRule[];\n } = {},\n): Promise<WorkerModule> {\n // `env` and `exports` of `cloudflare:workers` belong to one Worker: the bundle reads them\n // from its own scope (empty objects for code that has none).\n const scopeKey = opts.scope ? `s${Math.random().toString(36).slice(2)}` : \"\";\n if (opts.scope) {\n const g = globalThis as Record<string, unknown>;\n g.__cellsWorkerScopes ??= {};\n (g.__cellsWorkerScopes as Record<string, unknown>)[scopeKey] = opts.scope;\n }\n // Loaded code gets a bundle-local `fetch` (globalOutbound policy)…\n const outboundKey = outbound ? `o${Math.random().toString(36).slice(2)}` : \"\";\n if (outbound) {\n const g = globalThis as Record<string, unknown>;\n g.__cellsOutbound ??= {};\n (g.__cellsOutbound as Record<string, unknown>)[outboundKey] = outbound;\n }\n // …and a bundle-local `console` that also feeds its Tail Workers.\n const consoleKey = logs ? `c${Math.random().toString(36).slice(2)}` : \"\";\n if (logs) {\n const g = globalThis as Record<string, unknown>;\n g.__cellsConsoles ??= {};\n const registry = g.__cellsConsoles as Record<string, unknown>;\n const real = globalThis.console;\n const wrap =\n (level: \"log\" | \"info\" | \"warn\" | \"error\" | \"debug\") =>\n (...args: unknown[]) => {\n logs(level, args);\n real[level](...args);\n };\n registry[consoleKey] = Object.assign(Object.create(real), {\n log: wrap(\"log\"),\n info: wrap(\"info\"),\n warn: wrap(\"warn\"),\n error: wrap(\"error\"),\n debug: wrap(\"debug\"),\n });\n }\n const outDir = mkdtempSync(join(tmpdir(), \"cells-worker-\"));\n const out = join(outDir, \"worker.mjs\");\n const cfWorkers = ownModule(import.meta.dirname, \"cloudflare-workers\");\n // This bundle's `cloudflare:workers`: the runtime's classes plus its own `env` and `exports`.\n // A file of its own, kept out of the bundle so it adds no names to the Worker's scope.\n const workersModule = join(outDir, \"cloudflare-workers.mjs\");\n writeFileSync(\n workersModule,\n [\n `export * from ${JSON.stringify(cfWorkers)};`,\n `const scope = globalThis.__cellsWorkerScopes?.[${JSON.stringify(scopeKey)}];`,\n \"export const env = scope ? scope.env : {};\",\n \"export const exports = scope ? scope.exports : {};\",\n \"export const waitUntil = (p) => scope?.waitUntil(p);\",\n ].join(\"\\n\"),\n );\n const memory = \"modules\" in entry ? entry.modules : undefined;\n await build({\n entryPoints: [\n memory ? `memory:${(entry as { main: string }).main}` : (entry as { path: string }).path,\n ],\n outfile: out,\n bundle: true,\n format: \"esm\",\n platform: \"neutral\",\n // As `celld deploy` resolves packages: workerd's conditions, then `module` and `main` (the\n // neutral platform has no main fields, so a package with only `main` would not resolve).\n conditions: [\"workerd\", \"worker\", \"browser\"],\n mainFields: [\"module\", \"main\"],\n target: \"es2022\",\n logLevel: \"silent\",\n // nodejs_compat: CommonJS dependencies `require()` Node's built-ins (mime-types requires\n // node:path), as they may under workerd's nodejs_compat. In an ES module bundle esbuild's\n // require shim needs a `require` in scope: vitest's module runner provides one, plain Node\n // does not.\n ...(opts.nodeCompat\n ? {\n banner: {\n js: 'import { createRequire as __cellbCreateRequire } from \"node:module\";\\nconst require = __cellbCreateRequire(import.meta.url);',\n },\n }\n : {}),\n inject: [\n ownModule(import.meta.dirname, \"workers-globals\"),\n ...(logs ? [\"cellb:console\"] : []),\n ...(outbound ? [\"cellb:fetch\"] : []),\n ],\n plugins: [\n {\n name: \"cells-modules\",\n setup(b) {\n b.onResolve({ filter: /^cellb:console$/ }, () => ({\n path: \"console\",\n namespace: \"cells-console\",\n }));\n // nodejs_compat on a Node host: `node:*` are the real Node.js modules.\n if (opts.nodeCompat) {\n b.onResolve({ filter: /^node:/ }, (a) => ({ path: a.path, external: true }));\n // workerd's nodejs_compat also takes the bare names (\"path\", \"fs/promises\").\n b.onResolve({ filter: nodeBuiltinName }, (a) => ({\n path: `node:${a.path}`,\n external: true,\n }));\n }\n b.onResolve({ filter: /^cellb:compat$/ }, () => ({\n path: \"compat\",\n namespace: \"cells-compat\",\n }));\n b.onLoad({ filter: /.*/, namespace: \"cells-compat\" }, () => ({\n contents: `export const standardBinaryType = ${!!opts.standardBinaryType};`,\n loader: \"js\",\n }));\n b.onResolve({ filter: /^cellb:fetch$/ }, () => ({\n path: \"fetch\",\n namespace: \"cells-fetch\",\n }));\n b.onLoad({ filter: /.*/, namespace: \"cells-fetch\" }, () => ({\n contents: `export const fetch = globalThis.__cellsOutbound[${JSON.stringify(outboundKey)}];`,\n loader: \"js\",\n }));\n b.onLoad({ filter: /.*/, namespace: \"cells-console\" }, () => ({\n contents: `export const console = globalThis.__cellsConsoles[${JSON.stringify(consoleKey)}];`,\n loader: \"js\",\n }));\n b.onResolve({ filter: /^cloudflare:workers$/ }, () => ({\n path: workersModule,\n external: true,\n }));\n b.onResolve({ filter: /^cloudflare:email$/ }, () => ({\n path: ownModule(import.meta.dirname, \"cloudflare-email\"),\n external: true,\n }));\n b.onResolve({ filter: /^cellb:ws$/ }, () => ({\n path: ownModule(import.meta.dirname, \"workers-globals-module\"),\n external: true,\n }));\n if (!memory) return;\n b.onResolve({ filter: /^memory:/ }, (a) => ({\n path: a.path.slice(7),\n namespace: \"memory\",\n }));\n b.onResolve({ filter: /^\\.{1,2}\\// }, (a) =>\n a.namespace === \"memory\"\n ? {\n path: new URL(a.path, `file:///${a.importer}`).pathname.slice(1),\n namespace: \"memory\",\n }\n : undefined,\n );\n b.onLoad({ filter: /.*/, namespace: \"memory\" }, (a) => ({\n contents: memory[a.path],\n loader: \"js\",\n }));\n },\n },\n moduleRulesPlugin(opts.rules),\n ],\n });\n return (await import(/* @vite-ignore */ out)) as WorkerModule;\n}\n\n/** Worker Loader on Node: compiles `WorkerCode.modules` with esbuild (as celld compiles loaded code). */\nexport const nodeModuleLoader: ModuleLoader = async (_id, code, logs) => {\n const outbound = outboundFetch(code);\n const modules: Record<string, string> = {};\n for (const [name, m] of Object.entries(code.modules)) modules[name] = moduleText(m);\n // `env` and `exports` of the loaded code's `cloudflare:workers` are its own (WorkerCode.env).\n const env = code.env ?? {};\n const scope = workerScope(env);\n const module = (await bundleWorker({ modules, main: code.mainModule }, logs, outbound, {\n scope,\n })) as Record<string, unknown>;\n scope.bind({ env, exports: ctxExports(module, env) });\n return module;\n};\n\nexport async function loadNodeProject(\n dir: string,\n host: Omit<ProjectHost, \"loadModules\"> & Partial<Pick<ProjectHost, \"loadModules\">>,\n): Promise<ProjectRuntime & { config: WranglerConfig }> {\n const config = readWranglerConfig(dir);\n if (!config.main && !config.assets)\n throw new Error(\"wrangler config has neither `main` nor `assets`\");\n const flags = config.compatibility_flags ?? [];\n const nodeCompat = hasNodeCompat(config);\n const standardBinaryType = flags.includes(\"websocket_standard_binary_type\");\n // The module reads `env` from `cloudflare:workers` while it is evaluated, before the\n // runtime exists: until then the scope holds the configuration's vars (and `ai`).\n const scope = workerScope(loadTimeEnv(config, host.ai));\n // A bundle built elsewhere for cellb (cellbHostModule: webrun-bundler in a browser, say) reads\n // the runtime from globals, as in the browser realm: set them here too, so the same bundle\n // runs on Node. (One such project per process: the globals are the process's.)\n installHostModuleGlobals(scope);\n // As the browser host: nodejs_compat fills process.env with the text vars (from compatibility\n // date 2025-04-01). Node shares its real process with the Worker, so they land there.\n if (populatesProcessEnv(config))\n for (const [k, v] of Object.entries(processEnvOf(config))) process.env[k] ??= v;\n const module = config.main\n ? await bundleWorker({ path: resolve(dir, config.main) }, undefined, undefined, {\n nodeCompat,\n standardBinaryType,\n scope,\n rules: config.rules,\n })\n : ({ default: {} } as WorkerModule);\n const assetFiles = config.assets?.directory\n ? readAssetDirectory(resolve(dir, config.assets.directory))\n : undefined;\n const project = createProjectRuntime(config, module, {\n bindings: await loadProjectBindings(config),\n loadModules: nodeModuleLoader,\n // own realm, as celld; facets logged like the root's\n isolatedModules: nodeIsolatedLoader(() => host.storage),\n assetFiles,\n ...host,\n });\n scope.bind(project.runtime);\n return { ...project, config };\n}\n\n/** Reads an assets directory into \"/path\" → bytes (what `celld deploy` uploads). */\nexport function readAssetDirectory(root: string): Map<string, Uint8Array> {\n const files = new Map<string, Uint8Array>();\n const walk = (dir: string, prefix: string) => {\n for (const name of readdirSync(dir)) {\n const full = join(dir, name);\n if (statSync(full).isDirectory()) walk(full, `${prefix}${name}/`);\n else files.set(`${prefix}${name}`, new Uint8Array(readFileSync(full)));\n }\n };\n walk(root, \"/\");\n return files;\n}\n\n/**\n * `celld d1 migrations apply DATABASE` for a Node-hosted project: reads\n * `migrations_dir` (default \"migrations\") of the `d1_databases` entry and applies what is new.\n */\nexport async function applyNodeD1Migrations(\n dir: string,\n runtime: { env: Record<string, unknown> },\n database: string,\n) {\n const config = readWranglerConfig(dir);\n const d1 = config.d1_databases?.find(\n (d) => d.database_name === database || d.binding === database,\n );\n if (!d1) throw new Error(`no d1_databases entry named ${database}`);\n const mdir = resolve(dir, (d1 as { migrations_dir?: string }).migrations_dir ?? \"migrations\");\n const files: [string, string][] = existsSync(mdir)\n ? readdirSync(mdir).map((f) => [f, readFileSync(join(mdir, f), \"utf8\")])\n : [];\n return applyD1Migrations(\n runtime.env[d1.binding] as never,\n files,\n (d1 as { migrations_table?: string }).migrations_table ?? \"d1_migrations\",\n );\n}\n\n/**\n * Loaded Workers in worker threads (one realm each), like celld's isolates. The code is\n * bundled with esbuild (cloudflare:workers bundled in) and imported in the thread from a\n * data: URL; Durable Object classes for facets still load in this realm.\n */\nlet isolateEntry: Promise<string> | undefined;\nexport function nodeIsolatedLoader(storage?: () => CellStorage | undefined): ModuleLoader {\n return isolatedModuleLoader({\n storage,\n spawn: () => {\n const port = new NodeWorker(new URL(`file://${isolateEntryPathSync()}`));\n port.unref(); // an idle isolate never keeps the process alive\n return { port: port as unknown as PortLike, terminate: () => void port.terminate() };\n },\n prepare: async (_id, code) => {\n isolateEntry ??= buildIsolateEntry();\n await isolateEntry;\n const modules: Record<string, string> = {};\n for (const [name, m] of Object.entries(code.modules)) modules[name] = moduleText(m);\n const out = await build({\n entryPoints: [`memory:${code.mainModule}`],\n write: false,\n bundle: true,\n format: \"esm\",\n platform: \"neutral\",\n target: \"es2022\",\n logLevel: \"silent\",\n plugins: [\n {\n name: \"isolate-modules\",\n setup(b) {\n // The loaded Worker is its thread's own: `env` and `exports` are the scope\n // serveIsolate keeps for it.\n b.onResolve({ filter: /^cloudflare:workers$/ }, () => ({\n path: \"cloudflare:workers\",\n namespace: \"isolate-workers\",\n }));\n b.onLoad({ filter: /.*/, namespace: \"isolate-workers\" }, () => ({\n contents: [\n // cloudflare-workers.js in the published package (dist/), .ts in the sources.\n `export * from ${JSON.stringify(ownModule(import.meta.dirname, \"cloudflare-workers\"))};`,\n \"export const env = globalThis.__cellsProjectScope.env, exports = globalThis.__cellsProjectScope.exports, waitUntil = (p) => globalThis.__cellsProjectScope.waitUntil(p);\",\n ].join(\"\\n\"),\n loader: \"js\",\n resolveDir: import.meta.dirname,\n }));\n b.onResolve({ filter: /^cloudflare:email$/ }, () => ({\n path: ownModule(import.meta.dirname, \"cloudflare-email\"),\n }));\n b.onResolve({ filter: /^memory:/ }, (a) => ({\n path: a.path.slice(7),\n namespace: \"memory\",\n }));\n b.onResolve({ filter: /^\\.{1,2}\\// }, (a) =>\n a.namespace === \"memory\"\n ? {\n path: new URL(a.path, `file:///${a.importer}`).pathname.slice(1),\n namespace: \"memory\",\n }\n : undefined,\n );\n b.onLoad({ filter: /.*/, namespace: \"memory\" }, (a) => ({\n contents: modules[a.path],\n loader: \"js\",\n }));\n },\n },\n ],\n });\n return { source: out.outputFiles[0].text };\n },\n });\n}\n\nlet isolateEntryFile = \"\";\nfunction isolateEntryPathSync(): string {\n if (!isolateEntryFile) throw new Error(\"isolate entry not built yet\");\n return isolateEntryFile;\n}\nasync function buildIsolateEntry(): Promise<string> {\n isolateEntryFile = join(mkdtempSync(join(tmpdir(), \"cells-isolate-\")), \"isolate.mjs\");\n await build({\n entryPoints: [ownModule(import.meta.dirname, \"../isolate/node-entry\")],\n outfile: isolateEntryFile,\n bundle: true,\n format: \"esm\",\n platform: \"node\",\n target: \"node22\",\n logLevel: \"silent\",\n });\n return isolateEntryFile;\n}\n\n/** The globals `@statewalker/cellb/host-modules` bundles read (see host-modules.ts). */\nfunction installHostModuleGlobals(scope: WorkerScope): void {\n const g = globalThis as Record<string, unknown>;\n g.__cellsProjectScope = scope;\n g.__cellsWorkersModule ??= workersClasses;\n // node:* from Node itself (the browser realm gives cellb's polyfills).\n g.__cellsNodeModules ??= new Proxy(\n {},\n { get: (_t, k) => (typeof k === \"string\" ? requireBuiltin(k) : undefined) },\n );\n}\nconst requireBuiltin = createRequire(import.meta.url);\n"]}
1
+ {"version":3,"file":"node-project.js","sourceRoot":"","sources":["../../src/project/node-project.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,kBAAkB,EAGlB,UAAU,EACV,aAAa,EAEb,aAAa,GACd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,KAAK,cAAc,MAAM,yBAA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,SAAS,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;QACtE,OAAO,EAAE,gBAAgB;QACzB,MAAM,EAAE,IAAI;QACZ,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,QAAQ;QAChB,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAC;IACH,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,wFAAwF;AACxF,SAAS,wBAAwB,CAAC,KAAkB;IAClD,MAAM,CAAC,GAAG,UAAqC,CAAC;IAChD,CAAC,CAAC,mBAAmB,GAAG,KAAK,CAAC;IAC9B,CAAC,CAAC,oBAAoB,KAAK,cAAc,CAAC;IAC1C,uEAAuE;IACvE,CAAC,CAAC,kBAAkB,KAAK,IAAI,KAAK,CAChC,EAAE,EACF,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAC5E,CAAC;AACJ,CAAC;AACD,MAAM,cAAc,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC","sourcesContent":["import {\n existsSync,\n mkdtempSync,\n readdirSync,\n readFileSync,\n statSync,\n writeFileSync,\n} from \"node:fs\";\nimport { builtinModules, createRequire } from \"node:module\";\nimport { tmpdir } from \"node:os\";\nimport { join, resolve } from \"node:path\";\nimport { Worker as NodeWorker } from \"node:worker_threads\";\nimport { build } from \"esbuild\";\nimport { applyD1Migrations } from \"../bindings/d1-migrations.js\";\nimport {\n exportNamesByModule,\n IMPORT_FROM,\n prefixModule,\n RESOLVE_MODULE_NAME_SOURCE,\n routeDynamicImports,\n} from \"../bindings/module-registry.js\";\nimport {\n compileWasmModules,\n type LogSink,\n type ModuleLoader,\n moduleText,\n outboundFetch,\n type WorkerCode,\n wasmModulesOf,\n} from \"../bindings/worker-loader.js\";\nimport { ctxExports } from \"../core/handles.js\";\nimport type { WorkerModule } from \"../core/runtime.js\";\nimport { isolatedModuleLoader } from \"../isolate/host.js\";\nimport type { PortLike } from \"../isolate/protocol.js\";\nimport type { CellStorage } from \"../ports.js\";\nimport * as workersClasses from \"./cloudflare-workers.js\";\nimport { parseJsonc } from \"./jsonc.js\";\nimport { type ModuleRule, moduleRulesPlugin } from \"./module-rules.js\";\nimport { ownModule } from \"./own-module.js\";\nimport { type WorkerScope, workerScope } from \"./worker-scope.js\";\nimport {\n createProjectRuntime,\n hasNodeCompat,\n loadProjectBindings,\n loadTimeEnv,\n type ProjectHost,\n type ProjectRuntime,\n populatesProcessEnv,\n processEnvOf,\n WRANGLER_FILES,\n type WranglerConfig,\n} from \"./wrangler.js\";\n\n/** Reads `wrangler.jsonc` / `wrangler.json` of a project directory (celld reads the same files). */\nexport function readWranglerConfig(dir: string): WranglerConfig {\n for (const name of WRANGLER_FILES) {\n const p = join(dir, name);\n if (existsSync(p)) return parseJsonc(readFileSync(p, \"utf8\")) as WranglerConfig;\n }\n throw new Error(`no wrangler.jsonc or wrangler.json in ${dir}`);\n}\n\n/** A bare Node.js built-in specifier (\"path\", \"fs/promises\"), not one of a package. */\nconst nodeBuiltinName = new RegExp(\n `^(${builtinModules\n .filter((m) => !m.startsWith(\"_\") && !m.includes(\":\"))\n .map((m) => m.replace(/[/]/g, \"\\\\/\"))\n .join(\"|\")})$`,\n);\n\n/** Worker code's `node:fs` under nodejs_compat on Node: Node's own, with workerd's `/bundle`. */\nconst FS_OVERLAY = `import * as real from \"node:fs\";\nimport { bundleFs } from \"cellb:bundle-fs\";\nexport * from \"node:fs\";\nconst o = bundleFs(real);\nexport const { existsSync, readFileSync, statSync, lstatSync, readdirSync, accessSync, readFile, stat, lstat, readdir, access, promises } = o;\nexport default { ...real, ...o };`;\n/** Worker code's `node:fs/promises`, the same way. */\nconst FS_PROMISES_OVERLAY = `import * as real from \"node:fs/promises\";\nimport { bundleFsPromises } from \"cellb:bundle-fs\";\nexport * from \"node:fs/promises\";\nconst o = bundleFsPromises(real);\nexport const { readFile, stat, lstat, readdir, access } = o;\nexport default o;`;\n\n/**\n * The modules of loaded code as ES module text, each `import()` the bundler cannot link going to\n * the `cellb:modules` registry instead (module-registry.ts).\n */\nfunction loadedModuleTexts(code: WorkerCode): {\n modules: Record<string, string>;\n registry: string;\n} {\n const texts: Record<string, string> = {};\n const names = new Set(Object.keys(code.modules));\n for (const [name, m] of Object.entries(code.modules)) texts[name] = moduleText(m, name, names);\n const modules: Record<string, string> = {};\n for (const [name, text] of Object.entries(texts)) {\n const routed = routeDynamicImports(text, name);\n let prelude =\n routed === undefined ? \"\" : `import { importFrom as ${IMPORT_FROM} } from \"cellb:modules\"; `;\n // The main module evaluates the registry, so it is there before any code runs.\n if (name === code.mainModule && !prelude) prelude = 'import \"cellb:modules\"; ';\n modules[name] = prelude ? prefixModule(routed ?? text, prelude) : text;\n }\n return { modules, registry: registrySource(texts, code.mainModule) };\n}\n\n/**\n * What an import of loaded code that names none of its modules becomes: a module that throws when\n * it is evaluated, so the failure comes where workerd's would (when the importing module runs), not\n * at build time or when an unrelated module loads. CommonJS, so any named import of it builds.\n */\nfunction missingModule(spec: string, importer: string) {\n const message = `No such module \"${spec}\" (imported from \"${importer}\")`;\n return {\n path: `${importer}\\u0000${spec}`,\n namespace: \"cells-missing\",\n pluginData: `throw new Error(${JSON.stringify(message)});\\nmodule.exports = {};`,\n };\n}\n\n/**\n * The `cellb:modules` registry of a bundle of loaded code: each module, imported on demand. It\n * also publishes itself as `globalThis.__cellbLoadedModules`, where an isolate thread's module\n * hooks find it (node-entry.ts: `import()` from code built with `Function`).\n */\nfunction registrySource(texts: Record<string, string>, main: string): string {\n const q = JSON.stringify;\n const names = Object.keys(texts);\n return [\n `const names = new Set(${q(names)});`,\n `const resolve = ${RESOLVE_MODULE_NAME_SOURCE};`,\n `const table = { ${names.map((n) => `${q(n)}: () => import(${q(`memory:${n}`)})`).join(\", \")} };`,\n \"export const importFrom = (spec, importer) => {\",\n \" const name = resolve(String(spec), importer, names);\",\n \" return name === undefined ? import(spec) : table[name]();\",\n \"};\",\n `globalThis.__cellbLoadedModules = { main: ${q(main)}, names, exportNames: ${q(exportNamesByModule(texts))}, load: (name) => table[name]() };`,\n ].join(\"\\n\");\n}\n\n/**\n * Node host: bundles `main` with esbuild (as `celld deploy` does) and builds the runtime.\n * `cloudflare:workers` resolves to cellb's module so user classes extend the\n * runtime's own DurableObject / WorkerEntrypoint.\n */\n/** Bundles Worker code (a file, or in-memory modules) with the runtime's module mappings, then imports it. */\nexport async function bundleWorker(\n entry:\n | { path: string }\n | {\n modules: Record<string, string>;\n main: string;\n /** The `cellb:modules` registry the modules import (loadedModuleTexts). */\n registry?: string;\n },\n logs?: LogSink,\n outbound?: typeof fetch,\n opts: {\n nodeCompat?: boolean;\n standardBinaryType?: boolean;\n scope?: WorkerScope;\n /** wrangler `rules` for non-JS imports (the defaults: `.wasm`, `.bin`, `.txt`…, as wrangler). */\n rules?: ModuleRule[];\n } = {},\n): Promise<WorkerModule> {\n // `env` and `exports` of `cloudflare:workers` belong to one Worker: the bundle reads them\n // from its own scope (empty objects for code that has none).\n const scopeKey = opts.scope ? `s${Math.random().toString(36).slice(2)}` : \"\";\n if (opts.scope) {\n const g = globalThis as Record<string, unknown>;\n g.__cellsWorkerScopes ??= {};\n (g.__cellsWorkerScopes as Record<string, unknown>)[scopeKey] = opts.scope;\n }\n // Loaded code gets a bundle-local `fetch` (globalOutbound policy)…\n const outboundKey = outbound ? `o${Math.random().toString(36).slice(2)}` : \"\";\n if (outbound) {\n const g = globalThis as Record<string, unknown>;\n g.__cellsOutbound ??= {};\n (g.__cellsOutbound as Record<string, unknown>)[outboundKey] = outbound;\n }\n // …and a bundle-local `console` that also feeds its Tail Workers.\n const consoleKey = logs ? `c${Math.random().toString(36).slice(2)}` : \"\";\n if (logs) {\n const g = globalThis as Record<string, unknown>;\n g.__cellsConsoles ??= {};\n const registry = g.__cellsConsoles as Record<string, unknown>;\n const real = globalThis.console;\n const wrap =\n (level: \"log\" | \"info\" | \"warn\" | \"error\" | \"debug\") =>\n (...args: unknown[]) => {\n logs(level, args);\n real[level](...args);\n };\n registry[consoleKey] = Object.assign(Object.create(real), {\n log: wrap(\"log\"),\n info: wrap(\"info\"),\n warn: wrap(\"warn\"),\n error: wrap(\"error\"),\n debug: wrap(\"debug\"),\n });\n }\n const outDir = mkdtempSync(join(tmpdir(), \"cells-worker-\"));\n const out = join(outDir, \"worker.mjs\");\n const cfWorkers = ownModule(import.meta.dirname, \"cloudflare-workers\");\n // This bundle's `cloudflare:workers`: the runtime's classes plus its own `env` and `exports`.\n // A file of its own, kept out of the bundle so it adds no names to the Worker's scope.\n const workersModule = join(outDir, \"cloudflare-workers.mjs\");\n writeFileSync(\n workersModule,\n [\n `export * from ${JSON.stringify(cfWorkers)};`,\n `const scope = globalThis.__cellsWorkerScopes?.[${JSON.stringify(scopeKey)}];`,\n \"export const env = scope ? scope.env : {};\",\n \"export const exports = scope ? scope.exports : {};\",\n \"export const waitUntil = (p) => scope?.waitUntil(p);\",\n ].join(\"\\n\"),\n );\n const memory = \"modules\" in entry ? entry.modules : undefined;\n await build({\n entryPoints: [\n memory ? `memory:${(entry as { main: string }).main}` : (entry as { path: string }).path,\n ],\n outfile: out,\n bundle: true,\n format: \"esm\",\n platform: \"neutral\",\n // As `celld deploy` resolves packages: workerd's conditions, then `module` and `main` (the\n // neutral platform has no main fields, so a package with only `main` would not resolve).\n conditions: [\"workerd\", \"worker\", \"browser\"],\n mainFields: [\"module\", \"main\"],\n target: \"es2022\",\n logLevel: \"silent\",\n // nodejs_compat: CommonJS dependencies `require()` Node's built-ins (mime-types requires\n // node:path), as they may under workerd's nodejs_compat. In an ES module bundle esbuild's\n // require shim needs a `require` in scope: vitest's module runner provides one, plain Node\n // does not.\n ...(opts.nodeCompat\n ? {\n banner: {\n js: 'import { createRequire as __cellbCreateRequire } from \"node:module\";\\nconst require = __cellbCreateRequire(import.meta.url);',\n },\n }\n : {}),\n inject: [\n ownModule(import.meta.dirname, \"workers-globals\"),\n ...(logs ? [\"cellb:console\"] : []),\n ...(outbound ? [\"cellb:fetch\"] : []),\n ],\n plugins: [\n {\n name: \"cells-modules\",\n setup(b) {\n b.onResolve({ filter: /^cellb:console$/ }, () => ({\n path: \"console\",\n namespace: \"cells-console\",\n }));\n // nodejs_compat on a Node host: `node:*` are the real Node.js modules, except that\n // `node:fs` also reads workerd's `/bundle` (node-compat/bundle-files.ts).\n if (opts.nodeCompat) {\n b.onResolve({ filter: /^(node:)?fs(\\/promises)?$/ }, (a) => {\n const name = a.path.replace(/^node:/, \"\");\n return a.namespace === \"cells-fs\"\n ? { path: `node:${name}`, external: true }\n : { path: name, namespace: \"cells-fs\" };\n });\n b.onResolve({ filter: /^cellb:bundle-fs$/ }, () => ({\n path: ownModule(join(import.meta.dirname, \"../node-compat\"), \"bundle-files\"),\n external: true,\n }));\n b.onLoad({ filter: /.*/, namespace: \"cells-fs\" }, (a) => ({\n contents: a.path === \"fs\" ? FS_OVERLAY : FS_PROMISES_OVERLAY,\n loader: \"js\",\n }));\n b.onResolve({ filter: /^node:/ }, (a) => ({ path: a.path, external: true }));\n // workerd's nodejs_compat also takes the bare names (\"path\", \"fs/promises\").\n b.onResolve({ filter: nodeBuiltinName }, (a) => ({\n path: `node:${a.path}`,\n external: true,\n }));\n }\n b.onResolve({ filter: /^cellb:compat$/ }, () => ({\n path: \"compat\",\n namespace: \"cells-compat\",\n }));\n b.onLoad({ filter: /.*/, namespace: \"cells-compat\" }, () => ({\n contents: `export const standardBinaryType = ${!!opts.standardBinaryType};`,\n loader: \"js\",\n }));\n b.onResolve({ filter: /^cellb:fetch$/ }, () => ({\n path: \"fetch\",\n namespace: \"cells-fetch\",\n }));\n b.onLoad({ filter: /.*/, namespace: \"cells-fetch\" }, () => ({\n contents: `export const fetch = globalThis.__cellsOutbound[${JSON.stringify(outboundKey)}];`,\n loader: \"js\",\n }));\n b.onLoad({ filter: /.*/, namespace: \"cells-console\" }, () => ({\n contents: `export const console = globalThis.__cellsConsoles[${JSON.stringify(consoleKey)}];`,\n loader: \"js\",\n }));\n b.onResolve({ filter: /^cloudflare:workers$/ }, () => ({\n path: workersModule,\n external: true,\n }));\n b.onResolve({ filter: /^cloudflare:email$/ }, () => ({\n path: ownModule(import.meta.dirname, \"cloudflare-email\"),\n external: true,\n }));\n b.onResolve({ filter: /^cellb:ws$/ }, () => ({\n path: ownModule(import.meta.dirname, \"workers-globals-module\"),\n external: true,\n }));\n if (!memory) return;\n b.onResolve({ filter: /^memory:/ }, (a) => ({\n path: a.path.slice(7),\n namespace: \"memory\",\n }));\n b.onResolve({ filter: /^\\.{1,2}\\// }, (a) => {\n if (a.namespace !== \"memory\") return undefined;\n const path = new URL(a.path, `file:///${a.importer}`).pathname.slice(1);\n // Not one of the loaded modules: it fails when it runs, as on workerd (missingModule).\n return path in memory\n ? { path, namespace: \"memory\" }\n : missingModule(a.path, a.importer);\n });\n b.onLoad({ filter: /.*/, namespace: \"memory\" }, (a) => ({\n contents: memory[a.path],\n loader: \"js\",\n }));\n b.onResolve({ filter: /^cellb:modules$/ }, () => ({\n path: \"modules\",\n namespace: \"cells-modules\",\n }));\n b.onLoad({ filter: /.*/, namespace: \"cells-modules\" }, () => ({\n contents:\n (entry as { registry?: string }).registry ??\n \"export const importFrom = (s) => import(s);\",\n loader: \"js\",\n }));\n // Anything else loaded code imports: a module's whole name (a URL, say), as workerd names\n // modules, or else a module that throws when it is evaluated (missingModule).\n b.onResolve({ filter: /.*/ }, (a) => {\n if (a.namespace !== \"memory\") return undefined;\n if (a.path in memory) return { path: a.path, namespace: \"memory\" };\n return missingModule(a.path, a.importer);\n });\n b.onLoad({ filter: /.*/, namespace: \"cells-missing\" }, (a) => ({\n contents: a.pluginData as string,\n loader: \"js\",\n }));\n },\n },\n moduleRulesPlugin(opts.rules),\n ],\n });\n return (await import(/* @vite-ignore */ out)) as WorkerModule;\n}\n\n/** Worker Loader on Node: compiles `WorkerCode.modules` with esbuild (as celld compiles loaded code). */\nexport const nodeModuleLoader: ModuleLoader = async (_id, loaded, logs) => {\n const code = await compileWasmModules(loaded);\n const outbound = outboundFetch(code);\n const { modules, registry } = loadedModuleTexts(code);\n // `env` and `exports` of the loaded code's `cloudflare:workers` are its own (WorkerCode.env).\n const env = code.env ?? {};\n const scope = workerScope(env);\n const module = (await bundleWorker({ modules, main: code.mainModule, registry }, logs, outbound, {\n scope,\n })) as Record<string, unknown>;\n scope.bind({ env, exports: ctxExports(module, env) });\n return module;\n};\n\nexport async function loadNodeProject(\n dir: string,\n host: Omit<ProjectHost, \"loadModules\"> & Partial<Pick<ProjectHost, \"loadModules\">>,\n): Promise<ProjectRuntime & { config: WranglerConfig }> {\n const config = readWranglerConfig(dir);\n if (!config.main && !config.assets)\n throw new Error(\"wrangler config has neither `main` nor `assets`\");\n const flags = config.compatibility_flags ?? [];\n const nodeCompat = hasNodeCompat(config);\n const standardBinaryType = flags.includes(\"websocket_standard_binary_type\");\n // The module reads `env` from `cloudflare:workers` while it is evaluated, before the\n // runtime exists: until then the scope holds the configuration's vars (and `ai`).\n const scope = workerScope(loadTimeEnv(config, host.ai));\n // A bundle built elsewhere for cellb (cellbHostModule: webrun-bundler in a browser, say) reads\n // the runtime from globals, as in the browser realm: set them here too, so the same bundle\n // runs on Node. (One such project per process: the globals are the process's.)\n installHostModuleGlobals(scope);\n // As the browser host: nodejs_compat fills process.env with the text vars (from compatibility\n // date 2025-04-01). Node shares its real process with the Worker, so they land there.\n if (populatesProcessEnv(config))\n for (const [k, v] of Object.entries(processEnvOf(config))) process.env[k] ??= v;\n const module = config.main\n ? await bundleWorker({ path: resolve(dir, config.main) }, undefined, undefined, {\n nodeCompat,\n standardBinaryType,\n scope,\n rules: config.rules,\n })\n : ({ default: {} } as WorkerModule);\n const assetFiles = config.assets?.directory\n ? readAssetDirectory(resolve(dir, config.assets.directory))\n : undefined;\n const project = createProjectRuntime(config, module, {\n bindings: await loadProjectBindings(config),\n loadModules: nodeModuleLoader,\n // own realm, as celld; facets logged like the root's\n isolatedModules: nodeIsolatedLoader(() => host.storage),\n assetFiles,\n ...host,\n });\n scope.bind(project.runtime);\n return { ...project, config };\n}\n\n/** Reads an assets directory into \"/path\" → bytes (what `celld deploy` uploads). */\nexport function readAssetDirectory(root: string): Map<string, Uint8Array> {\n const files = new Map<string, Uint8Array>();\n const walk = (dir: string, prefix: string) => {\n for (const name of readdirSync(dir)) {\n const full = join(dir, name);\n if (statSync(full).isDirectory()) walk(full, `${prefix}${name}/`);\n else files.set(`${prefix}${name}`, new Uint8Array(readFileSync(full)));\n }\n };\n walk(root, \"/\");\n return files;\n}\n\n/**\n * `celld d1 migrations apply DATABASE` for a Node-hosted project: reads\n * `migrations_dir` (default \"migrations\") of the `d1_databases` entry and applies what is new.\n */\nexport async function applyNodeD1Migrations(\n dir: string,\n runtime: { env: Record<string, unknown> },\n database: string,\n) {\n const config = readWranglerConfig(dir);\n const d1 = config.d1_databases?.find(\n (d) => d.database_name === database || d.binding === database,\n );\n if (!d1) throw new Error(`no d1_databases entry named ${database}`);\n const mdir = resolve(dir, (d1 as { migrations_dir?: string }).migrations_dir ?? \"migrations\");\n const files: [string, string][] = existsSync(mdir)\n ? readdirSync(mdir).map((f) => [f, readFileSync(join(mdir, f), \"utf8\")])\n : [];\n return applyD1Migrations(\n runtime.env[d1.binding] as never,\n files,\n (d1 as { migrations_table?: string }).migrations_table ?? \"d1_migrations\",\n );\n}\n\n/**\n * Loaded Workers in worker threads (one realm each), like celld's isolates. The code is\n * bundled with esbuild (cloudflare:workers bundled in) and imported in the thread from a\n * data: URL; Durable Object classes for facets still load in this realm.\n */\nlet isolateEntry: Promise<string> | undefined;\nexport function nodeIsolatedLoader(storage?: () => CellStorage | undefined): ModuleLoader {\n return isolatedModuleLoader({\n storage,\n spawn: () => {\n const port = new NodeWorker(new URL(`file://${isolateEntryPathSync()}`));\n port.unref(); // an idle isolate never keeps the process alive\n return { port: port as unknown as PortLike, terminate: () => void port.terminate() };\n },\n prepare: async (_id, loaded) => {\n isolateEntry ??= buildIsolateEntry();\n const [code] = await Promise.all([compileWasmModules(loaded), isolateEntry]);\n const { modules, registry } = loadedModuleTexts(code);\n const out = await build({\n entryPoints: [`memory:${code.mainModule}`],\n write: false,\n bundle: true,\n format: \"esm\",\n platform: \"neutral\",\n target: \"es2022\",\n logLevel: \"silent\",\n plugins: [\n {\n name: \"isolate-modules\",\n setup(b) {\n // The loaded Worker is its thread's own: `env` and `exports` are the scope\n // serveIsolate keeps for it.\n b.onResolve({ filter: /^cloudflare:workers$/ }, () => ({\n path: \"cloudflare:workers\",\n namespace: \"isolate-workers\",\n }));\n b.onLoad({ filter: /.*/, namespace: \"isolate-workers\" }, () => ({\n contents: [\n // cloudflare-workers.js in the published package (dist/), .ts in the sources.\n `export * from ${JSON.stringify(ownModule(import.meta.dirname, \"cloudflare-workers\"))};`,\n \"export const env = globalThis.__cellsProjectScope.env, exports = globalThis.__cellsProjectScope.exports, waitUntil = (p) => globalThis.__cellsProjectScope.waitUntil(p);\",\n ].join(\"\\n\"),\n loader: \"js\",\n resolveDir: import.meta.dirname,\n }));\n b.onResolve({ filter: /^cloudflare:email$/ }, () => ({\n path: ownModule(import.meta.dirname, \"cloudflare-email\"),\n }));\n b.onResolve({ filter: /^memory:/ }, (a) => ({\n path: a.path.slice(7),\n namespace: \"memory\",\n }));\n b.onResolve({ filter: /^\\.{1,2}\\// }, (a) => {\n if (a.namespace !== \"memory\") return undefined;\n const path = new URL(a.path, `file:///${a.importer}`).pathname.slice(1);\n // Not one of the loaded modules: it fails when it runs, as on workerd (missingModule).\n return path in modules\n ? { path, namespace: \"memory\" }\n : missingModule(a.path, a.importer);\n });\n b.onLoad({ filter: /.*/, namespace: \"memory\" }, (a) => ({\n contents: modules[a.path],\n loader: \"js\",\n }));\n b.onResolve({ filter: /^cellb:modules$/ }, () => ({\n path: \"modules\",\n namespace: \"cells-modules\",\n }));\n b.onLoad({ filter: /.*/, namespace: \"cells-modules\" }, () => ({\n contents: registry,\n loader: \"js\",\n }));\n // Anything else loaded code imports: a module's whole name (a URL, say), as workerd names\n // modules, or else a module that throws when it is evaluated (missingModule).\n b.onResolve({ filter: /.*/ }, (a) => {\n if (a.namespace !== \"memory\") return undefined;\n if (a.path in modules) return { path: a.path, namespace: \"memory\" };\n return missingModule(a.path, a.importer);\n });\n b.onLoad({ filter: /.*/, namespace: \"cells-missing\" }, (a) => ({\n contents: a.pluginData as string,\n loader: \"js\",\n }));\n },\n },\n ],\n });\n // Compiled wasm modules travel beside the source (a worker thread takes them as they are).\n return { source: out.outputFiles[0].text, wasm: wasmModulesOf(code) };\n },\n });\n}\n\nlet isolateEntryFile = \"\";\nfunction isolateEntryPathSync(): string {\n if (!isolateEntryFile) throw new Error(\"isolate entry not built yet\");\n return isolateEntryFile;\n}\nasync function buildIsolateEntry(): Promise<string> {\n isolateEntryFile = join(mkdtempSync(join(tmpdir(), \"cells-isolate-\")), \"isolate.mjs\");\n await build({\n entryPoints: [ownModule(import.meta.dirname, \"../isolate/node-entry\")],\n outfile: isolateEntryFile,\n bundle: true,\n format: \"esm\",\n platform: \"node\",\n target: \"node22\",\n logLevel: \"silent\",\n });\n return isolateEntryFile;\n}\n\n/** The globals `@statewalker/cellb/host-modules` bundles read (see host-modules.ts). */\nfunction installHostModuleGlobals(scope: WorkerScope): void {\n const g = globalThis as Record<string, unknown>;\n g.__cellsProjectScope = scope;\n g.__cellsWorkersModule ??= workersClasses;\n // node:* from Node itself (the browser realm gives cellb's polyfills).\n g.__cellsNodeModules ??= new Proxy(\n {},\n { get: (_t, k) => (typeof k === \"string\" ? requireBuiltin(k) : undefined) },\n );\n}\nconst requireBuiltin = createRequire(import.meta.url);\n"]}
@@ -13,6 +13,7 @@ export const WORKERS_MODULE_NAMES = [
13
13
  "WorkerEntrypoint",
14
14
  "WorkflowEntrypoint",
15
15
  "RpcTarget",
16
+ "abortIsolate",
16
17
  "env",
17
18
  "exports",
18
19
  "waitUntil",
@@ -51,7 +52,7 @@ export function putLoadedModule(url, m) {
51
52
  const wrapped = typeof m === "object" && !("js" in m) && !("esModule" in m);
52
53
  return fetch(url, {
53
54
  method: "PUT",
54
- body: moduleText(m),
55
+ body: moduleText(m, url.slice(url.lastIndexOf("/") + 1)),
55
56
  headers: wrapped ? { [ESM_HEADER]: "1" } : {},
56
57
  });
57
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"site-loader.js","sourceRoot":"","sources":["../../src/project/site-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,aAAa,GAEd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAEvD,6FAA6F;AAC7F,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,eAAe;IACf,kBAAkB;IAClB,oBAAoB;IACpB,WAAW;IACX,KAAK;IACL,SAAS;IACT,WAAW;CACZ,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAenC;IACC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAkB;QACnC,CAAC,oBAAoB,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAC/F,CAAC,kBAAkB,EAAE,OAAO,CAAC,WAAW,CAAC;QACzC,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAU,CAAC;QAC5D,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;KACtC,CAAC,CAAC;IACH,MAAM,EAAE,oBAAoB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AAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;gBACvF,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC;gBAChB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;gBAClB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;gBAClB,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;gBACpB,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;aACrB,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,GAAG,IAAI,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,CAGnF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n type LogSink,\n type ModuleLoader,\n moduleText,\n outboundFetch,\n type WorkerCode,\n} from \"../bindings/worker-loader.js\";\nimport { WORKERS_GLOBAL_NAMES } from \"./workers-global-names.js\";\n\n/**\n * The runtime side of a project site (`createProjectSite`, in `@statewalker/cellb/site`): the\n * registry its `~deps` proxies read, and the Worker Loader that uploads code to it. Nothing here\n * compiles code, so the browser host and the isolates import this module without pulling in\n * webrun-modules (and lightningcss-wasm) — only projects that build a site do.\n */\nexport const LOADED_CONSOLES = \"__cellsLoadedConsoles\";\n\n/** What `cloudflare:workers` exports on a site (`env` and `exports` are a project's own). */\nexport const WORKERS_MODULE_NAMES = [\n \"DurableObject\",\n \"WorkerEntrypoint\",\n \"WorkflowEntrypoint\",\n \"RpcTarget\",\n \"env\",\n \"exports\",\n \"waitUntil\",\n];\n\n/**\n * The registry the `~deps` proxies read, for the realm that runs the Worker code. The project\n * and the Workers it loads share this realm's registry, but not their proxies: each has its own\n * module server, so a proxy of loaded code is a module under `<site>loaded/`. A proxy reads the\n * registry while it is evaluated, so the caller on the stack tells whose it is: loaded code gets\n * `workersModule` (`env` and `exports` empty), the project `projectWorkersModule` (its own).\n */\nexport function workersHostRegistry(entries: {\n /** nodejs_compat: \"node:buffer\" → module namespace, and the Buffer/process globals. */\n node?: Record<string, unknown>;\n workersModule: object;\n /** With `loadedPrefix` (`<site>loaded/`): the project's own `cloudflare:workers`. */\n projectWorkersModule?: object;\n loadedPrefix?: string;\n emailModule?: unknown;\n Request: unknown;\n Response: unknown;\n WebSocketPair: unknown;\n caches: unknown;\n HTMLRewriter: unknown;\n WebSocketRequestResponsePair?: unknown;\n WebSocket?: unknown;\n}): void {\n const map = new Map<string, unknown>([\n [\"cloudflare:workers\", { env: {}, exports: {}, waitUntil: () => {}, ...entries.workersModule }],\n [\"cloudflare:email\", entries.emailModule],\n ...WORKERS_GLOBAL_NAMES.map((n) => [n, entries[n]] as const),\n ...Object.entries(entries.node ?? {}),\n ]);\n const { projectWorkersModule: project, loadedPrefix } = entries;\n (globalThis as Record<string, unknown>).__webrunHostRegistry = {\n get: (k: string) =>\n k === \"cloudflare:workers\" && project && loadedPrefix\n ? (new Error().stack ?? \"\").includes(loadedPrefix)\n ? map.get(k)\n : project\n : map.get(k),\n has: (k: string) => map.has(k),\n set: (k: string, v: unknown) => void map.set(k, v),\n };\n}\n\nexport const ESM_HEADER = \"x-cellb-esm\";\n\n/**\n * Stores one module of loaded code on the site (PUT /loaded-src/<id>/<name>). Source goes\n * through webrun-modules; a text, json or wasm entry is stored as the ESM that wraps it.\n */\nexport function putLoadedModule(url: string, m: WorkerCode[\"modules\"][string]): Promise<Response> {\n const wrapped = typeof m === \"object\" && !(\"js\" in m) && !(\"esModule\" in m);\n return fetch(url, {\n method: \"PUT\",\n body: moduleText(m),\n headers: wrapped ? { [ESM_HEADER]: \"1\" } : {},\n });\n}\n\n/**\n * Worker Loader over the site: `LOADER.get(id, () => code)` uploads the modules to\n * `/loaded-src/<id>/…` and imports `/loaded/<id>/~/<main>` — compiled by webrun-modules and\n * fetched by the browser like any other module. Works in pages, workers and ServiceWorkers.\n */\nexport function siteModuleLoader(baseUrl: string): ModuleLoader {\n const base = baseUrl.endsWith(\"/\") ? baseUrl : `${baseUrl}/`;\n return async (id: string, code: WorkerCode, logs?: LogSink) => {\n const dir = encodeURIComponent(id);\n for (const [name, m] of Object.entries(code.modules)) {\n const res = await putLoadedModule(`${base}loaded-src/${dir}/${name}`, m);\n if (!res.ok) throw new Error(`Worker Loader: cannot store ${id}/${name}: ${res.status}`);\n }\n const outbound = outboundFetch(code);\n if (outbound) {\n const g = globalThis as Record<string, unknown>;\n g.__cellsLoadedOutbound ??= {};\n (g.__cellsLoadedOutbound as Record<string, unknown>)[id] = outbound;\n }\n if (logs) {\n const g = globalThis as Record<string, unknown>;\n g[LOADED_CONSOLES] ??= {};\n const real = globalThis.console;\n const wrap =\n (level: \"log\" | \"info\" | \"warn\" | \"error\" | \"debug\") =>\n (...args: unknown[]) => {\n logs(level, args);\n real[level](...args);\n };\n (g[LOADED_CONSOLES] as Record<string, unknown>)[id] = Object.assign(Object.create(real), {\n log: wrap(\"log\"),\n info: wrap(\"info\"),\n warn: wrap(\"warn\"),\n error: wrap(\"error\"),\n debug: wrap(\"debug\"),\n });\n }\n return (await import(/* @vite-ignore */ `${base}loaded/${dir}/~/${code.mainModule}`)) as Record<\n string,\n unknown\n >;\n };\n}\n"]}
1
+ {"version":3,"file":"site-loader.js","sourceRoot":"","sources":["../../src/project/site-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,aAAa,GAEd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAEvD,6FAA6F;AAC7F,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,eAAe;IACf,kBAAkB;IAClB,oBAAoB;IACpB,WAAW;IACX,cAAc;IACd,KAAK;IACL,SAAS;IACT,WAAW;CACZ,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAenC;IACC,MAAM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MAAM,CAAC,GAAG,UAAqC,CAAC;YAChD,CAAC,CAAC,qBAAqB,KAAK,EAAE,CAAC;YAC9B,CAAC,CAAC,qBAAiD,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC;QACtE,CAAC;QACD,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,CAAC,GAAG,UAAqC,CAAC;YAChD,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;YAC1B,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC;YAChC,MAAM,IAAI,GACR,CAAC,KAAkD,EAAE,EAAE,CACvD,CAAC,GAAG,IAAe,EAAE,EAAE;gBACrB,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;gBAClB,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;YACvB,CAAC,CAAC;YACH,CAAC,CAAC,eAAe,CAA6B,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;gBACvF,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC;gBAChB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;gBAClB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;gBAClB,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;gBACpB,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;aACrB,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,GAAG,IAAI,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,CAGnF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n type LogSink,\n type ModuleLoader,\n moduleText,\n outboundFetch,\n type WorkerCode,\n} from \"../bindings/worker-loader.js\";\nimport { WORKERS_GLOBAL_NAMES } from \"./workers-global-names.js\";\n\n/**\n * The runtime side of a project site (`createProjectSite`, in `@statewalker/cellb/site`): the\n * registry its `~deps` proxies read, and the Worker Loader that uploads code to it. Nothing here\n * compiles code, so the browser host and the isolates import this module without pulling in\n * webrun-modules (and lightningcss-wasm) — only projects that build a site do.\n */\nexport const LOADED_CONSOLES = \"__cellsLoadedConsoles\";\n\n/** What `cloudflare:workers` exports on a site (`env` and `exports` are a project's own). */\nexport const WORKERS_MODULE_NAMES = [\n \"DurableObject\",\n \"WorkerEntrypoint\",\n \"WorkflowEntrypoint\",\n \"RpcTarget\",\n \"abortIsolate\",\n \"env\",\n \"exports\",\n \"waitUntil\",\n];\n\n/**\n * The registry the `~deps` proxies read, for the realm that runs the Worker code. The project\n * and the Workers it loads share this realm's registry, but not their proxies: each has its own\n * module server, so a proxy of loaded code is a module under `<site>loaded/`. A proxy reads the\n * registry while it is evaluated, so the caller on the stack tells whose it is: loaded code gets\n * `workersModule` (`env` and `exports` empty), the project `projectWorkersModule` (its own).\n */\nexport function workersHostRegistry(entries: {\n /** nodejs_compat: \"node:buffer\" → module namespace, and the Buffer/process globals. */\n node?: Record<string, unknown>;\n workersModule: object;\n /** With `loadedPrefix` (`<site>loaded/`): the project's own `cloudflare:workers`. */\n projectWorkersModule?: object;\n loadedPrefix?: string;\n emailModule?: unknown;\n Request: unknown;\n Response: unknown;\n WebSocketPair: unknown;\n caches: unknown;\n HTMLRewriter: unknown;\n WebSocketRequestResponsePair?: unknown;\n WebSocket?: unknown;\n}): void {\n const map = new Map<string, unknown>([\n [\"cloudflare:workers\", { env: {}, exports: {}, waitUntil: () => {}, ...entries.workersModule }],\n [\"cloudflare:email\", entries.emailModule],\n ...WORKERS_GLOBAL_NAMES.map((n) => [n, entries[n]] as const),\n ...Object.entries(entries.node ?? {}),\n ]);\n const { projectWorkersModule: project, loadedPrefix } = entries;\n (globalThis as Record<string, unknown>).__webrunHostRegistry = {\n get: (k: string) =>\n k === \"cloudflare:workers\" && project && loadedPrefix\n ? (new Error().stack ?? \"\").includes(loadedPrefix)\n ? map.get(k)\n : project\n : map.get(k),\n has: (k: string) => map.has(k),\n set: (k: string, v: unknown) => void map.set(k, v),\n };\n}\n\nexport const ESM_HEADER = \"x-cellb-esm\";\n\n/**\n * Stores one module of loaded code on the site (PUT /loaded-src/<id>/<name>). Source goes\n * through webrun-modules; a text, json or wasm entry is stored as the ESM that wraps it.\n */\nexport function putLoadedModule(url: string, m: WorkerCode[\"modules\"][string]): Promise<Response> {\n const wrapped = typeof m === \"object\" && !(\"js\" in m) && !(\"esModule\" in m);\n return fetch(url, {\n method: \"PUT\",\n body: moduleText(m, url.slice(url.lastIndexOf(\"/\") + 1)),\n headers: wrapped ? { [ESM_HEADER]: \"1\" } : {},\n });\n}\n\n/**\n * Worker Loader over the site: `LOADER.get(id, () => code)` uploads the modules to\n * `/loaded-src/<id>/…` and imports `/loaded/<id>/~/<main>` — compiled by webrun-modules and\n * fetched by the browser like any other module. Works in pages, workers and ServiceWorkers.\n */\nexport function siteModuleLoader(baseUrl: string): ModuleLoader {\n const base = baseUrl.endsWith(\"/\") ? baseUrl : `${baseUrl}/`;\n return async (id: string, code: WorkerCode, logs?: LogSink) => {\n const dir = encodeURIComponent(id);\n for (const [name, m] of Object.entries(code.modules)) {\n const res = await putLoadedModule(`${base}loaded-src/${dir}/${name}`, m);\n if (!res.ok) throw new Error(`Worker Loader: cannot store ${id}/${name}: ${res.status}`);\n }\n const outbound = outboundFetch(code);\n if (outbound) {\n const g = globalThis as Record<string, unknown>;\n g.__cellsLoadedOutbound ??= {};\n (g.__cellsLoadedOutbound as Record<string, unknown>)[id] = outbound;\n }\n if (logs) {\n const g = globalThis as Record<string, unknown>;\n g[LOADED_CONSOLES] ??= {};\n const real = globalThis.console;\n const wrap =\n (level: \"log\" | \"info\" | \"warn\" | \"error\" | \"debug\") =>\n (...args: unknown[]) => {\n logs(level, args);\n real[level](...args);\n };\n (g[LOADED_CONSOLES] as Record<string, unknown>)[id] = Object.assign(Object.create(real), {\n log: wrap(\"log\"),\n info: wrap(\"info\"),\n warn: wrap(\"warn\"),\n error: wrap(\"error\"),\n debug: wrap(\"debug\"),\n });\n }\n return (await import(/* @vite-ignore */ `${base}loaded/${dir}/~/${code.mainModule}`)) as Record<\n string,\n unknown\n >;\n };\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * `Uint8Array.prototype.toBase64` / `toHex` and `Uint8Array.fromBase64` / `fromHex` (ES2026,
3
+ * which workerd has) where the engine lacks them: Node 22, and browsers before them. A prototype
4
+ * method cannot be substituted per bundle as the other Workers globals are, so the realm's own
5
+ * `Uint8Array` gets them; an engine that has them keeps its own.
6
+ */
7
+ export {};
@@ -0,0 +1,96 @@
1
+ /**
2
+ * `Uint8Array.prototype.toBase64` / `toHex` and `Uint8Array.fromBase64` / `fromHex` (ES2026,
3
+ * which workerd has) where the engine lacks them: Node 22, and browsers before them. A prototype
4
+ * method cannot be substituted per bundle as the other Workers globals are, so the realm's own
5
+ * `Uint8Array` gets them; an engine that has them keeps its own.
6
+ */
7
+ const B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
8
+ const B64URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
9
+ function toBase64(bytes, opts = {}) {
10
+ const table = alphabetOf(opts.alphabet) === "base64url" ? B64URL : B64;
11
+ let out = "";
12
+ let i = 0;
13
+ for (; i + 2 < bytes.length; i += 3) {
14
+ const n = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
15
+ out += table[n >> 18] + table[(n >> 12) & 63] + table[(n >> 6) & 63] + table[n & 63];
16
+ }
17
+ const pad = opts.omitPadding ? "" : "=";
18
+ if (i + 1 === bytes.length) {
19
+ const n = bytes[i] << 16;
20
+ out += table[n >> 18] + table[(n >> 12) & 63] + pad + pad;
21
+ }
22
+ else if (i + 2 === bytes.length) {
23
+ const n = (bytes[i] << 16) | (bytes[i + 1] << 8);
24
+ out += table[n >> 18] + table[(n >> 12) & 63] + table[(n >> 6) & 63] + pad;
25
+ }
26
+ return out;
27
+ }
28
+ function fromBase64(input, opts = {}) {
29
+ if (typeof input !== "string")
30
+ throw new TypeError("fromBase64: the input must be a string");
31
+ const table = alphabetOf(opts.alphabet) === "base64url" ? B64URL : B64;
32
+ const strict = opts.lastChunkHandling === "strict";
33
+ const s = input.replace(/[\t\n\f\r ]/g, "");
34
+ const body = s.replace(/=+$/, "");
35
+ const padding = s.length - body.length;
36
+ if (padding > 2 || (padding > 0 && s.length % 4 !== 0) || body.length % 4 === 1)
37
+ throw new SyntaxError("fromBase64: invalid base64 string");
38
+ if (strict && body.length % 4 !== 0 && padding === 0)
39
+ throw new SyntaxError("fromBase64: missing padding");
40
+ const out = new Uint8Array(Math.floor((body.length * 3) / 4));
41
+ let o = 0;
42
+ let acc = 0;
43
+ let bits = 0;
44
+ for (const c of body) {
45
+ const v = table.indexOf(c);
46
+ if (v < 0)
47
+ throw new SyntaxError(`fromBase64: invalid character ${JSON.stringify(c)}`);
48
+ acc = (acc << 6) | v;
49
+ bits += 6;
50
+ if (bits >= 8) {
51
+ bits -= 8;
52
+ out[o++] = (acc >> bits) & 0xff;
53
+ }
54
+ }
55
+ if (strict && bits > 0 && (acc & ((1 << bits) - 1)) !== 0)
56
+ throw new SyntaxError("fromBase64: non-zero padding bits");
57
+ return out;
58
+ }
59
+ function toHex(bytes) {
60
+ let out = "";
61
+ for (const b of bytes)
62
+ out += b.toString(16).padStart(2, "0");
63
+ return out;
64
+ }
65
+ function fromHex(input) {
66
+ if (typeof input !== "string")
67
+ throw new TypeError("fromHex: the input must be a string");
68
+ if (input.length % 2 !== 0 || /[^0-9a-fA-F]/.test(input))
69
+ throw new SyntaxError("fromHex: invalid hex string");
70
+ const out = new Uint8Array(input.length / 2);
71
+ for (let i = 0; i < out.length; i++)
72
+ out[i] = Number.parseInt(input.slice(i * 2, i * 2 + 2), 16);
73
+ return out;
74
+ }
75
+ function alphabetOf(alphabet) {
76
+ if (alphabet === undefined || alphabet === "base64" || alphabet === "base64url")
77
+ return alphabet ?? "base64";
78
+ throw new TypeError(`unknown base64 alphabet ${JSON.stringify(alphabet)}`);
79
+ }
80
+ const method = (value) => ({ value, writable: true, configurable: true });
81
+ const proto = Uint8Array.prototype;
82
+ const ctor = Uint8Array;
83
+ if (typeof proto.toBase64 !== "function")
84
+ Object.defineProperty(proto, "toBase64", method(function (opts) {
85
+ return toBase64(this, opts);
86
+ }));
87
+ if (typeof proto.toHex !== "function")
88
+ Object.defineProperty(proto, "toHex", method(function () {
89
+ return toHex(this);
90
+ }));
91
+ if (typeof ctor.fromBase64 !== "function")
92
+ Object.defineProperty(ctor, "fromBase64", method(fromBase64));
93
+ if (typeof ctor.fromHex !== "function")
94
+ Object.defineProperty(ctor, "fromHex", method(fromHex));
95
+ export {};
96
+ //# sourceMappingURL=uint8array-base64.js.map