@statewalker/cellb 0.8.9 → 0.9.1

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 (38) hide show
  1. package/README.md +10 -6
  2. package/dist/adapters/node-sqlite-module.d.ts +6 -0
  3. package/dist/adapters/node-sqlite-module.js +12 -0
  4. package/dist/adapters/node-sqlite-module.js.map +1 -1
  5. package/dist/adapters/node-sqlite.js +3 -3
  6. package/dist/adapters/node-sqlite.js.map +1 -1
  7. package/dist/adapters/wasm-sqlite.d.ts +2 -0
  8. package/dist/adapters/wasm-sqlite.js +15 -0
  9. package/dist/adapters/wasm-sqlite.js.map +1 -1
  10. package/dist/bindings/cron.js +9 -2
  11. package/dist/bindings/cron.js.map +1 -1
  12. package/dist/bindings/module-registry.d.ts +19 -9
  13. package/dist/bindings/module-registry.js +42 -30
  14. package/dist/bindings/module-registry.js.map +1 -1
  15. package/dist/bucket/sqlite-object-store.js +2 -2
  16. package/dist/bucket/sqlite-object-store.js.map +1 -1
  17. package/dist/core/alarms.js +12 -2
  18. package/dist/core/alarms.js.map +1 -1
  19. package/dist/isolate/function-imports.d.ts +10 -0
  20. package/dist/isolate/function-imports.js +93 -0
  21. package/dist/isolate/function-imports.js.map +1 -0
  22. package/dist/isolate/isolate-worker.js +5 -1
  23. package/dist/isolate/isolate-worker.js.map +1 -1
  24. package/dist/isolate/protocol.js +17 -3
  25. package/dist/isolate/protocol.js.map +1 -1
  26. package/dist/project/browser-host.d.ts +2 -0
  27. package/dist/project/browser-host.js +2 -0
  28. package/dist/project/browser-host.js.map +1 -1
  29. package/dist/project/browser-load.js +1 -0
  30. package/dist/project/browser-load.js.map +1 -1
  31. package/dist/project/browser-modules.d.ts +7 -1
  32. package/dist/project/browser-modules.js +5 -1
  33. package/dist/project/browser-modules.js.map +1 -1
  34. package/dist/project/built-project.d.ts +7 -0
  35. package/dist/project/built-project.js.map +1 -1
  36. package/dist/project/node-project.js +9 -6
  37. package/dist/project/node-project.js.map +1 -1
  38. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"built-project.js","sourceRoot":"","sources":["../../src/project/built-project.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,kDAAkD;AAClD,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAC3C,0DAA0D;AAC1D,MAAM,CAAC,MAAM,YAAY,GAAG,eAAe,CAAC;AAC5C,4CAA4C;AAC5C,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;AACxC,8CAA8C;AAC9C,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AA4DrC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAI,MAAqB,EAAE,IAAY;IACnE,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,KAAK,CAAC,CAAC,CAAE,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AACtE,CAAC;AAED,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,MAAqB;IAC3D,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAgB,MAAM,EAAE,cAAc,CAAC,CAAC;IACvE,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChC,IAAI,QAAQ,CAAC,MAAM,KAAK,YAAY;QAClC,MAAM,IAAI,KAAK,CAAC,GAAG,cAAc,oBAAoB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC1F,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,0FAA0F;AAC1F,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAqB,EACrB,QAAwB;IAExB,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MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;IAC9E,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,MAAM,CAAC,MAAoB;IAClC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1C,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IACrE,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACf,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC;IACjB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * The folder `cellb build` writes, and what `loadProject` reads, on both platforms:\n *\n * wrangler.json the project's configuration (`main` → \"worker.js\", `assets.directory` → \"assets\")\n * worker.js `main` bundled for a browser realm (bundleWorkerForBrowser), if there is a `main`\n * assets/… the files of `assets.directory`, as they are\n * cellb.json this manifest: the format, and the asset paths (a static host cannot list a folder)\n *\n * Platform-neutral: it reads through a `ProjectReader` (Node's fs, `fetch` of a URL, a FilesApi).\n */\nimport type { FilesApi } from \"@statewalker/webrun-files\";\nimport type { AssetFiles } from \"../bindings/assets.js\";\nimport type { WorkersAiOptions } from \"../bindings/workers-ai.js\";\nimport type { CellRuntime } from \"../core/runtime.js\";\nimport { parseJsonc } from \"./jsonc.js\";\nimport type { WranglerConfig } from \"./wrangler.js\";\n\n/** The manifest's file name in a built folder. */\nexport const BUILD_MANIFEST = \"cellb.json\";\n/** The format a built folder declares in its manifest. */\nexport const BUILD_FORMAT = \"cellb-build/1\";\n/** The bundled `main` in a built folder. */\nexport const BUILT_WORKER = \"worker.js\";\n/** The assets directory in a built folder. */\nexport const BUILT_ASSETS = \"assets\";\n\nexport interface BuildManifest {\n format: typeof BUILD_FORMAT;\n /** `worker.js`, or null for a project without `main` (assets only). */\n main: string | null;\n /** The asset files, as paths under `assets/` (\"/index.html\", \"/css/site.css\"). */\n assets: string[];\n}\n\n/** A built project in memory: what `browserProjectRuntime` takes. */\nexport interface BuiltProject {\n config: WranglerConfig;\n /** `main` bundled for a browser realm, or null. */\n code: string | null;\n assets: AssetFiles;\n}\n\n/** Reads the files of a project folder, wherever it lives; `undefined` for a missing file. */\nexport interface ProjectReader {\n bytes(path: string): Promise<Uint8Array | undefined>;\n /** The files under `dir`, as paths relative to it (\"/a/b.html\"); only where the source can list. */\n list?(dir: string): Promise<string[]>;\n}\n\n/** Where `loadProject` finds a project. */\nexport type ProjectSource =\n /** Node: a folder with wrangler.json(c), built or not; browser: the URL of a `cellb build` folder. */\n | string\n | URL\n /** Any FilesApi holding either kind of folder at its root. */\n | FilesApi;\n\n/** Options of `loadProject`, the same on Node and in browsers. */\nexport interface LoadProjectOptions<Bucket = unknown> {\n /**\n * Where cells keep their data. Node: a directory (SQLite files and the project's files under\n * it; default: memory). Browser: an OPFS name, the pool (`<data>`) and the files directory\n * (`<data>-files`) (default: the project's `name`).\n */\n data?: string;\n /** A fleet bucket: a `BrowserBucket` in browsers, a `CellStorage` on Node. */\n bucket?: Bucket;\n /** The OpenAI-compatible endpoint behind the project's `ai` binding (Workers AI). */\n ai?: WorkersAiOptions;\n /** Browser only: an initialized SQLite WASM module (default: loads `@sqlite.org/sqlite-wasm`). */\n sqlite3?: unknown;\n}\n\n/** A running project. */\nexport interface LoadedProject {\n config: WranglerConfig;\n runtime: CellRuntime;\n /** Configuration entries cellb does not run (reported, not silently ignored). */\n unsupported: string[];\n /** A request to the project, as its Worker (and assets) answer it. */\n fetch(req: Request): Promise<Response>;\n close(): Promise<void>;\n}\n\nconst decoder = new TextDecoder();\n\n/** Reads JSON (or JSONC) at `path`, or undefined when the file is missing. */\nexport async function readJson<T>(reader: ProjectReader, path: string): Promise<T | undefined> {\n const bytes = await reader.bytes(path);\n return bytes ? (parseJsonc(decoder.decode(bytes)) as T) : undefined;\n}\n\n/** The manifest of a built folder, or undefined when the folder is not one. */\nexport async function readBuildManifest(reader: ProjectReader): Promise<BuildManifest | undefined> {\n const manifest = await readJson<BuildManifest>(reader, BUILD_MANIFEST);\n if (!manifest) return undefined;\n if (manifest.format !== BUILD_FORMAT)\n throw new Error(`${BUILD_MANIFEST}: unknown format ${JSON.stringify(manifest.format)}`);\n return manifest;\n}\n\n/** Reads a `cellb build` folder: its configuration, its bundled `main` and its assets. */\nexport async function readBuiltProject(\n reader: ProjectReader,\n manifest?: BuildManifest,\n): Promise<BuiltProject> {\n manifest ??= await readBuildManifest(reader);\n if (!manifest) throw new Error(`no ${BUILD_MANIFEST}: not a folder written by \\`cellb build\\``);\n const config = await readJson<WranglerConfig>(reader, \"wrangler.json\");\n if (!config) throw new Error(\"no wrangler.json in the built folder\");\n let code: string | null = null;\n if (manifest.main) {\n const bytes = await reader.bytes(manifest.main);\n if (!bytes) throw new Error(`${manifest.main} is missing from the built folder`);\n code = decoder.decode(bytes);\n }\n const assets: AssetFiles = new Map();\n await Promise.all(\n manifest.assets.map(async (p) => {\n const bytes = await reader.bytes(`${BUILT_ASSETS}${p}`);\n if (!bytes) throw new Error(`${BUILT_ASSETS}${p} is missing from the built folder`);\n assets.set(p, bytes);\n }),\n );\n return { config, code, assets };\n}\n\n/** A reader over a FilesApi, rooted at `root` (\"/\" by default). */\nexport function filesApiReader(files: FilesApi, root = \"/\"): ProjectReader {\n const base = root.endsWith(\"/\") ? root : `${root}/`;\n const at = (p: string) => `${base}${p.replace(/^\\/+/, \"\")}`;\n return {\n async bytes(path) {\n const full = at(path);\n const stats = await files.stats(full);\n if (!stats || stats.kind !== \"file\") return undefined;\n const chunks: Uint8Array[] = [];\n for await (const c of files.read(full)) chunks.push(c);\n return concat(chunks);\n },\n async list(dir) {\n const full = at(dir).replace(/\\/+$/, \"\");\n const out: string[] = [];\n for await (const e of files.list(full, { recursive: true }))\n if (e.kind === \"file\") out.push(e.path.slice(full.length));\n return out;\n },\n };\n}\n\n/** A reader over HTTP: files of the folder at `base` (a URL ending in \"/\"). */\nexport function urlReader(base: URL, fetchFn: typeof fetch = fetch): ProjectReader {\n return {\n async bytes(path) {\n const res = await fetchFn(new URL(path.replace(/^\\/+/, \"\"), base));\n if (res.status === 404) {\n await res.body?.cancel();\n return undefined;\n }\n if (!res.ok) throw new Error(`GET ${new URL(path, base)}: ${res.status} ${res.statusText}`);\n return new Uint8Array(await res.arrayBuffer());\n },\n };\n}\n\n/** Whether `v` is a FilesApi (a source given as files rather than a path or URL). */\nexport function isFilesApi(v: unknown): v is FilesApi {\n return (\n typeof v === \"object\" &&\n v !== null &&\n !(v instanceof URL) &&\n typeof (v as FilesApi).read === \"function\" &&\n typeof (v as FilesApi).list === \"function\" &&\n typeof (v as FilesApi).stats === \"function\"\n );\n}\n\n/** A built project's configuration as `wrangler.json` holds it: `main` and assets renamed. */\nexport function builtConfig(config: WranglerConfig): WranglerConfig {\n const out: WranglerConfig = { ...config };\n if (config.main) out.main = BUILT_WORKER;\n if (config.assets) out.assets = { ...config.assets, directory: BUILT_ASSETS };\n return out;\n}\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n if (chunks.length === 1) return chunks[0];\n const out = new Uint8Array(chunks.reduce((n, c) => n + c.length, 0));\n let at = 0;\n for (const c of chunks) {\n out.set(c, at);\n at += c.length;\n }\n return out;\n}\n"]}
1
+ {"version":3,"file":"built-project.js","sourceRoot":"","sources":["../../src/project/built-project.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,kDAAkD;AAClD,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAC3C,0DAA0D;AAC1D,MAAM,CAAC,MAAM,YAAY,GAAG,eAAe,CAAC;AAC5C,4C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EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IACrE,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACf,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC;IACjB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * The folder `cellb build` writes, and what `loadProject` reads, on both platforms:\n *\n * wrangler.json the project's configuration (`main` → \"worker.js\", `assets.directory` → \"assets\")\n * worker.js `main` bundled for a browser realm (bundleWorkerForBrowser), if there is a `main`\n * assets/… the files of `assets.directory`, as they are\n * cellb.json this manifest: the format, and the asset paths (a static host cannot list a folder)\n *\n * Platform-neutral: it reads through a `ProjectReader` (Node's fs, `fetch` of a URL, a FilesApi).\n */\nimport type { FilesApi } from \"@statewalker/webrun-files\";\nimport type { AssetFiles } from \"../bindings/assets.js\";\nimport type { WorkersAiOptions } from \"../bindings/workers-ai.js\";\nimport type { CellRuntime } from \"../core/runtime.js\";\nimport { parseJsonc } from \"./jsonc.js\";\nimport type { WranglerConfig } from \"./wrangler.js\";\n\n/** The manifest's file name in a built folder. */\nexport const BUILD_MANIFEST = \"cellb.json\";\n/** The format a built folder declares in its manifest. */\nexport const BUILD_FORMAT = \"cellb-build/1\";\n/** The bundled `main` in a built folder. */\nexport const BUILT_WORKER = \"worker.js\";\n/** The assets directory in a built folder. */\nexport const BUILT_ASSETS = \"assets\";\n\nexport interface BuildManifest {\n format: typeof BUILD_FORMAT;\n /** `worker.js`, or null for a project without `main` (assets only). */\n main: string | null;\n /** The asset files, as paths under `assets/` (\"/index.html\", \"/css/site.css\"). */\n assets: string[];\n}\n\n/** A built project in memory: what `browserProjectRuntime` takes. */\nexport interface BuiltProject {\n config: WranglerConfig;\n /** `main` bundled for a browser realm, or null. */\n code: string | null;\n assets: AssetFiles;\n}\n\n/** Reads the files of a project folder, wherever it lives; `undefined` for a missing file. */\nexport interface ProjectReader {\n bytes(path: string): Promise<Uint8Array | undefined>;\n /** The files under `dir`, as paths relative to it (\"/a/b.html\"); only where the source can list. */\n list?(dir: string): Promise<string[]>;\n}\n\n/** Where `loadProject` finds a project. */\nexport type ProjectSource =\n /** Node: a folder with wrangler.json(c), built or not; browser: the URL of a `cellb build` folder. */\n | string\n | URL\n /** Any FilesApi holding either kind of folder at its root. */\n | FilesApi;\n\n/** Options of `loadProject`, the same on Node and in browsers. */\nexport interface LoadProjectOptions<Bucket = unknown> {\n /**\n * Where cells keep their data. Node: a directory (SQLite files and the project's files under\n * it; default: memory). Browser: an OPFS name, the pool (`<data>`) and the files directory\n * (`<data>-files`) (default: the project's `name`).\n */\n data?: string;\n /** A fleet bucket: a `BrowserBucket` in browsers, a `CellStorage` on Node. */\n bucket?: Bucket;\n /** The OpenAI-compatible endpoint behind the project's `ai` binding (Workers AI). */\n ai?: WorkersAiOptions;\n /** Browser only: an initialized SQLite WASM module (default: loads `@sqlite.org/sqlite-wasm`). */\n sqlite3?: unknown;\n}\n\n/** A running project. */\nexport interface LoadedProject {\n config: WranglerConfig;\n runtime: CellRuntime;\n /** Configuration entries cellb does not run (reported, not silently ignored). */\n unsupported: string[];\n /** A request to the project, as its Worker (and assets) answer it. */\n fetch(req: Request): Promise<Response>;\n /**\n * In a browser (an OPFS pool): the cells' databases as `[file name, bytes]`, named as\n * `nodeSqliteOpener(dir)` names them, so that a data directory on Node (`loadProject(dir,\n * { data })`) starts where this browser's cells are. CellB's own databases (`__cellb_*`) are\n * included; R2 objects are not. Empty with a bucket (it holds the cells); not defined on Node.\n */\n exportCells?(): Promise<[string, Uint8Array][]>;\n close(): Promise<void>;\n}\n\nconst decoder = new TextDecoder();\n\n/** Reads JSON (or JSONC) at `path`, or undefined when the file is missing. */\nexport async function readJson<T>(reader: ProjectReader, path: string): Promise<T | undefined> {\n const bytes = await reader.bytes(path);\n return bytes ? (parseJsonc(decoder.decode(bytes)) as T) : undefined;\n}\n\n/** The manifest of a built folder, or undefined when the folder is not one. */\nexport async function readBuildManifest(reader: ProjectReader): Promise<BuildManifest | undefined> {\n const manifest = await readJson<BuildManifest>(reader, BUILD_MANIFEST);\n if (!manifest) return undefined;\n if (manifest.format !== BUILD_FORMAT)\n throw new Error(`${BUILD_MANIFEST}: unknown format ${JSON.stringify(manifest.format)}`);\n return manifest;\n}\n\n/** Reads a `cellb build` folder: its configuration, its bundled `main` and its assets. */\nexport async function readBuiltProject(\n reader: ProjectReader,\n manifest?: BuildManifest,\n): Promise<BuiltProject> {\n manifest ??= await readBuildManifest(reader);\n if (!manifest) throw new Error(`no ${BUILD_MANIFEST}: not a folder written by \\`cellb build\\``);\n const config = await readJson<WranglerConfig>(reader, \"wrangler.json\");\n if (!config) throw new Error(\"no wrangler.json in the built folder\");\n let code: string | null = null;\n if (manifest.main) {\n const bytes = await reader.bytes(manifest.main);\n if (!bytes) throw new Error(`${manifest.main} is missing from the built folder`);\n code = decoder.decode(bytes);\n }\n const assets: AssetFiles = new Map();\n await Promise.all(\n manifest.assets.map(async (p) => {\n const bytes = await reader.bytes(`${BUILT_ASSETS}${p}`);\n if (!bytes) throw new Error(`${BUILT_ASSETS}${p} is missing from the built folder`);\n assets.set(p, bytes);\n }),\n );\n return { config, code, assets };\n}\n\n/** A reader over a FilesApi, rooted at `root` (\"/\" by default). */\nexport function filesApiReader(files: FilesApi, root = \"/\"): ProjectReader {\n const base = root.endsWith(\"/\") ? root : `${root}/`;\n const at = (p: string) => `${base}${p.replace(/^\\/+/, \"\")}`;\n return {\n async bytes(path) {\n const full = at(path);\n const stats = await files.stats(full);\n if (!stats || stats.kind !== \"file\") return undefined;\n const chunks: Uint8Array[] = [];\n for await (const c of files.read(full)) chunks.push(c);\n return concat(chunks);\n },\n async list(dir) {\n const full = at(dir).replace(/\\/+$/, \"\");\n const out: string[] = [];\n for await (const e of files.list(full, { recursive: true }))\n if (e.kind === \"file\") out.push(e.path.slice(full.length));\n return out;\n },\n };\n}\n\n/** A reader over HTTP: files of the folder at `base` (a URL ending in \"/\"). */\nexport function urlReader(base: URL, fetchFn: typeof fetch = fetch): ProjectReader {\n return {\n async bytes(path) {\n const res = await fetchFn(new URL(path.replace(/^\\/+/, \"\"), base));\n if (res.status === 404) {\n await res.body?.cancel();\n return undefined;\n }\n if (!res.ok) throw new Error(`GET ${new URL(path, base)}: ${res.status} ${res.statusText}`);\n return new Uint8Array(await res.arrayBuffer());\n },\n };\n}\n\n/** Whether `v` is a FilesApi (a source given as files rather than a path or URL). */\nexport function isFilesApi(v: unknown): v is FilesApi {\n return (\n typeof v === \"object\" &&\n v !== null &&\n !(v instanceof URL) &&\n typeof (v as FilesApi).read === \"function\" &&\n typeof (v as FilesApi).list === \"function\" &&\n typeof (v as FilesApi).stats === \"function\"\n );\n}\n\n/** A built project's configuration as `wrangler.json` holds it: `main` and assets renamed. */\nexport function builtConfig(config: WranglerConfig): WranglerConfig {\n const out: WranglerConfig = { ...config };\n if (config.main) out.main = BUILT_WORKER;\n if (config.assets) out.assets = { ...config.assets, directory: BUILT_ASSETS };\n return out;\n}\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n if (chunks.length === 1) return chunks[0];\n const out = new Uint8Array(chunks.reduce((n, c) => n + c.length, 0));\n let at = 0;\n for (const c of chunks) {\n out.set(c, at);\n at += c.length;\n }\n return out;\n}\n"]}
@@ -5,7 +5,7 @@ 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 { exportNamesByModule, IMPORT_FROM, prefixModule, RESOLVE_MODULE_NAME_SOURCE, routeDynamicImports, } from "../bindings/module-registry.js";
8
+ import { analyzeModule, exportNamesByModule, IMPORT_FROM, prefixModule, RESOLVE_MODULE_NAME_SOURCE, } from "../bindings/module-registry.js";
9
9
  import { compileWasmModules, moduleText, outboundFetch, wasmModulesOf, } from "../bindings/worker-loader.js";
10
10
  import { ctxExports } from "../core/handles.js";
11
11
  import { isolatedModuleLoader } from "../isolate/host.js";
@@ -53,15 +53,19 @@ function loadedModuleTexts(code) {
53
53
  for (const [name, m] of Object.entries(code.modules))
54
54
  texts[name] = moduleText(m, name, names);
55
55
  const modules = {};
56
+ const exports = new Map();
56
57
  for (const [name, text] of Object.entries(texts)) {
57
- const routed = routeDynamicImports(text, name);
58
+ // One parse per module: the import() calls to route, and the exports the registry lists.
59
+ const analysis = analyzeModule(text, name);
60
+ exports.set(name, analysis?.exports ?? { names: [], stars: [] });
61
+ const routed = analysis?.routed;
58
62
  let prelude = routed === undefined ? "" : `import { importFrom as ${IMPORT_FROM} } from "cellb:modules"; `;
59
63
  // The main module evaluates the registry, so it is there before any code runs.
60
64
  if (name === code.mainModule && !prelude)
61
65
  prelude = 'import "cellb:modules"; ';
62
66
  modules[name] = prelude ? prefixModule(routed ?? text, prelude) : text;
63
67
  }
64
- return { modules, registry: registrySource(texts, code.mainModule) };
68
+ return { modules, registry: registrySource(Object.keys(texts), exports, code.mainModule) };
65
69
  }
66
70
  /**
67
71
  * What an import of loaded code that names none of its modules becomes: a module that throws when
@@ -81,9 +85,8 @@ function missingModule(spec, importer) {
81
85
  * also publishes itself as `globalThis.__cellbLoadedModules`, where an isolate thread's module
82
86
  * hooks find it (node-entry.ts: `import()` from code built with `Function`).
83
87
  */
84
- function registrySource(texts, main) {
88
+ function registrySource(names, exports, main) {
85
89
  const q = JSON.stringify;
86
- const names = Object.keys(texts);
87
90
  return [
88
91
  `const names = new Set(${q(names)});`,
89
92
  `const resolve = ${RESOLVE_MODULE_NAME_SOURCE};`,
@@ -92,7 +95,7 @@ function registrySource(texts, main) {
92
95
  " const name = resolve(String(spec), importer, names);",
93
96
  " return name === undefined ? import(spec) : table[name]();",
94
97
  "};",
95
- `globalThis.__cellbLoadedModules = { main: ${q(main)}, names, exportNames: ${q(exportNamesByModule(texts))}, load: (name) => table[name]() };`,
98
+ `globalThis.__cellbLoadedModules = { main: ${q(main)}, names, exportNames: ${q(exportNamesByModule(exports))}, load: (name) => table[name]() };`,
96
99
  ].join("\n");
97
100
  }
98
101
  /**
@@ -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,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,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,E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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"]}
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,I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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 analyzeModule,\n exportNamesByModule,\n IMPORT_FROM,\n type ModuleExports,\n prefixModule,\n RESOLVE_MODULE_NAME_SOURCE,\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 const exports = new Map<string, ModuleExports>();\n for (const [name, text] of Object.entries(texts)) {\n // One parse per module: the import() calls to route, and the exports the registry lists.\n const analysis = analyzeModule(text, name);\n exports.set(name, analysis?.exports ?? { names: [], stars: [] });\n const routed = analysis?.routed;\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(Object.keys(texts), exports, 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(\n names: string[],\n exports: Map<string, ModuleExports>,\n main: string,\n): string {\n const q = JSON.stringify;\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(exports))}, 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statewalker/cellb",
3
- "version": "0.8.9",
3
+ "version": "0.9.1",
4
4
  "description": "cellb: isomorphic Durable Objects runtime (celld/Cloudflare-compatible surface) for browsers and servers",
5
5
  "type": "module",
6
6
  "license": "MIT",