@statewalker/cellb 0.6.0 → 0.7.0

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 (40) hide show
  1. package/README.md +40 -6
  2. package/dist/browser.d.ts +1 -0
  3. package/dist/browser.js.map +1 -1
  4. package/dist/bundle.d.ts +2 -0
  5. package/dist/bundle.js +5 -0
  6. package/dist/bundle.js.map +1 -0
  7. package/dist/core/object-host.d.ts +7 -0
  8. package/dist/core/object-host.js +40 -7
  9. package/dist/core/object-host.js.map +1 -1
  10. package/dist/node-compat/browser-registry.d.ts +1 -0
  11. package/dist/node-compat/browser-registry.js +5 -0
  12. package/dist/node-compat/browser-registry.js.map +1 -1
  13. package/dist/node-compat/util-guard.d.ts +2 -0
  14. package/dist/node-compat/util-guard.js +14 -0
  15. package/dist/node-compat/util-guard.js.map +1 -0
  16. package/dist/project/browser-host.js +2 -2
  17. package/dist/project/browser-host.js.map +1 -1
  18. package/dist/project/browser-load.d.ts +16 -4
  19. package/dist/project/browser-load.js +46 -9
  20. package/dist/project/browser-load.js.map +1 -1
  21. package/dist/project/build.js +2 -2
  22. package/dist/project/build.js.map +1 -1
  23. package/dist/project/bundle-compiler.d.ts +31 -0
  24. package/dist/project/bundle-compiler.js +73 -0
  25. package/dist/project/bundle-compiler.js.map +1 -0
  26. package/dist/project/node-project.js +3 -3
  27. package/dist/project/node-project.js.map +1 -1
  28. package/dist/project/site-compiler.d.ts +67 -0
  29. package/dist/project/site-compiler.js +134 -0
  30. package/dist/project/site-compiler.js.map +1 -0
  31. package/dist/project/source-project.d.ts +46 -0
  32. package/dist/project/source-project.js +45 -0
  33. package/dist/project/source-project.js.map +1 -0
  34. package/dist/project/wrangler.d.ts +4 -0
  35. package/dist/project/wrangler.js +7 -1
  36. package/dist/project/wrangler.js.map +1 -1
  37. package/dist/site.d.ts +2 -0
  38. package/dist/site.js +4 -3
  39. package/dist/site.js.map +1 -1
  40. package/package.json +11 -1
@@ -1 +1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B,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 { ownModule } from \"./own-module.js\";\nimport { type WorkerScope, workerScope } from \"./worker-scope.js\";\nimport {\n createProjectRuntime,\n loadTimeEnv,\n type ProjectHost,\n type ProjectRuntime,\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.jsonc\", \"wrangler.json\"]) {\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: { nodeCompat?: boolean; standardBinaryType?: boolean; scope?: WorkerScope } = {},\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 ],\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 = flags.some((f) => f.startsWith(\"nodejs_compat\"));\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 (\n nodeCompat &&\n !flags.includes(\"nodejs_compat_do_not_populate_process_env\") &&\n (flags.includes(\"nodejs_compat_populate_process_env\") ||\n (config.compatibility_date ?? \"\") >= \"2025-04-01\")\n )\n for (const [k, v] of Object.entries(config.vars ?? {}))\n if (typeof v === \"string\") 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 })\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 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,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,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAoB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,WAAW,EAGX,cAAc,GAEf,MAAM,eAAe,CAAC;AAEvB,oGAAoG;AACpG,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,KAAK,MAAM,IAAI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,IAAI,KAAK,CAAC,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 { ownModule } from \"./own-module.js\";\nimport { type WorkerScope, workerScope } from \"./worker-scope.js\";\nimport {\n createProjectRuntime,\n hasNodeCompat,\n loadTimeEnv,\n type ProjectHost,\n type ProjectRuntime,\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: { nodeCompat?: boolean; standardBinaryType?: boolean; scope?: WorkerScope } = {},\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 ],\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 (\n nodeCompat &&\n !flags.includes(\"nodejs_compat_do_not_populate_process_env\") &&\n (flags.includes(\"nodejs_compat_populate_process_env\") ||\n (config.compatibility_date ?? \"\") >= \"2025-04-01\")\n )\n for (const [k, v] of Object.entries(config.vars ?? {}))\n if (typeof v === \"string\") 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 })\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 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"]}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * `siteCompiler`: a project's sources served by an in-browser HTTP server (`createProjectSite`,
3
+ * hosted in a ServiceWorker by webrun-site-host), for `loadProject(files, { compile })`. Modules
4
+ * are compiled one by one as the browser imports them; nothing is bundled.
5
+ *
6
+ * `loadProject` runs in a Dedicated Worker, which cannot register a ServiceWorker: the site is
7
+ * hosted by a page. `siteHostOverPort` (worker) and `hostSitesForWorker` (page) do that over a
8
+ * MessagePort: the worker serves the site's handler, the page mounts it in its ServiceWorker.
9
+ */
10
+ import type { SiteHandler } from "@statewalker/webrun-site-builder";
11
+ import type { ProjectCompiler } from "./source-project.js";
12
+ /** A site, hosted: its base URL (ending in "/") and how to take it down. */
13
+ export interface HostedProjectSite {
14
+ baseUrl: string;
15
+ stop(): Promise<void>;
16
+ }
17
+ /** Hosts a site handler where this realm's code can `import()` from it. */
18
+ export type SiteHost = (handler: SiteHandler) => Promise<HostedProjectSite>;
19
+ export interface SiteCompilerOptions {
20
+ /**
21
+ * Where the site is hosted. Default: a ServiceWorker this realm registers (`HostedSiteBuilder`),
22
+ * which a page can do and a Dedicated Worker cannot; in a worker, pass `siteHostOverPort(port)`
23
+ * and call `hostSitesForWorker(port)` in the page.
24
+ */
25
+ host?: SiteHost;
26
+ /** The ServiceWorker script for the default host (default: `/sw-worker.js`). */
27
+ serviceWorkerUrl?: string;
28
+ /** `createProjectSite`'s `lowerAwait` (default: with nodejs_compat, unless AsyncContext). */
29
+ lowerAwait?: boolean;
30
+ }
31
+ /**
32
+ * A compiler for `loadProject(files, { compile })` that serves the project's modules from an
33
+ * in-browser HTTP server (`createProjectSite`): `main` and Worker Loader code are imported from
34
+ * it, so a change can rebuild one module. The site stops when the project closes.
35
+ */
36
+ export declare function siteCompiler(options?: SiteCompilerOptions): ProjectCompiler;
37
+ /**
38
+ * Where a worker and its page talk about sites: a MessagePort, the `Worker` (page side) or the
39
+ * worker's own scope (`self`). Other messages on it are left alone.
40
+ */
41
+ export interface SiteControl {
42
+ postMessage(message: unknown, transfer: Transferable[]): void;
43
+ addEventListener(type: "message", listener: (e: MessageEvent) => void): void;
44
+ removeEventListener(type: "message", listener: (e: MessageEvent) => void): void;
45
+ }
46
+ /**
47
+ * Worker side: hosts each site through the page at the other end of `control`, which runs
48
+ * `hostSitesForWorker`. The handler stays in this worker; the page's ServiceWorker forwards each
49
+ * request to it.
50
+ */
51
+ export declare function siteHostOverPort(control: SiteControl,
52
+ /**
53
+ * How long the page may take to host the site (default 30 s; a ServiceWorker's first install
54
+ * can be slow), and to confirm it stopped one (default 2 s; the worker stops serving anyway).
55
+ */
56
+ { timeoutMs, stopTimeoutMs, }?: {
57
+ timeoutMs?: number;
58
+ stopTimeoutMs?: number;
59
+ }): SiteHost;
60
+ /**
61
+ * Page side: hosts in this page's ServiceWorker the sites a worker asks for over `control`
62
+ * (`siteHostOverPort`). Returns a function that stops listening; the sites stop when the worker
63
+ * stops them.
64
+ */
65
+ export declare function hostSitesForWorker(control: SiteControl, options?: {
66
+ serviceWorkerUrl?: string;
67
+ }): () => void;
@@ -0,0 +1,134 @@
1
+ import { HostedSiteBuilder } from "@statewalker/webrun-site-host";
2
+ import { linkOverPort, serveHandlerOverPort } from "../transport/port.js";
3
+ import { createProjectSite } from "./site.js";
4
+ /** The default host: a ServiceWorker registered from this realm. */
5
+ function serviceWorkerHost(serviceWorkerUrl) {
6
+ return async (handler) => {
7
+ if (!globalThis.navigator?.serviceWorker)
8
+ throw new Error("siteCompiler: this realm cannot register a ServiceWorker (a Dedicated Worker cannot): " +
9
+ "pass `host: siteHostOverPort(port)` and call `hostSitesForWorker(port)` in the page");
10
+ const builder = new HostedSiteBuilder().setHandler(handler);
11
+ if (serviceWorkerUrl)
12
+ builder.setServiceWorkerUrl(serviceWorkerUrl);
13
+ const site = await builder.build();
14
+ return { baseUrl: site.baseUrl, stop: () => site.stop() };
15
+ };
16
+ }
17
+ /**
18
+ * A compiler for `loadProject(files, { compile })` that serves the project's modules from an
19
+ * in-browser HTTP server (`createProjectSite`): `main` and Worker Loader code are imported from
20
+ * it, so a change can rebuild one module. The site stops when the project closes.
21
+ */
22
+ export function siteCompiler(options = {}) {
23
+ const host = options.host ?? serviceWorkerHost(options.serviceWorkerUrl);
24
+ return {
25
+ kind: "site",
26
+ async compile({ files, nodeCompat }) {
27
+ let nodeModules;
28
+ if (nodeCompat) {
29
+ // The served `node:*` proxies take their export names from the registry entries, which
30
+ // the browser host binds in this realm; the npm `util` polyfill reads `process` when it
31
+ // is imported.
32
+ (await import("../node-compat/install.js")).installNodeGlobals();
33
+ nodeModules = (await import("../node-compat/browser-registry.js")).nodeRegistryEntries;
34
+ }
35
+ const handler = createProjectSite({
36
+ projectFiles: files,
37
+ nodeCompat,
38
+ nodeModules,
39
+ lowerAwait: options.lowerAwait,
40
+ });
41
+ const site = await host(handler);
42
+ const baseUrl = site.baseUrl.endsWith("/") ? site.baseUrl : `${site.baseUrl}/`;
43
+ return { code: { site: baseUrl }, close: () => site.stop() };
44
+ },
45
+ };
46
+ }
47
+ const HOST_SITE = "cellb:host-site";
48
+ const STOP_SITE = "cellb:stop-site";
49
+ /** The next message on `port`, or `{ error }` after `timeoutMs` (a page that never answers). */
50
+ const once = (port, timeoutMs) => new Promise((resolve) => {
51
+ const timer = setTimeout(() => resolve({ error: `no answer in ${timeoutMs} ms (does the page run hostSitesForWorker?)` }), timeoutMs);
52
+ port.onmessage = (e) => {
53
+ clearTimeout(timer);
54
+ resolve(e.data);
55
+ };
56
+ });
57
+ /**
58
+ * Worker side: hosts each site through the page at the other end of `control`, which runs
59
+ * `hostSitesForWorker`. The handler stays in this worker; the page's ServiceWorker forwards each
60
+ * request to it.
61
+ */
62
+ export function siteHostOverPort(control,
63
+ /**
64
+ * How long the page may take to host the site (default 30 s; a ServiceWorker's first install
65
+ * can be slow), and to confirm it stopped one (default 2 s; the worker stops serving anyway).
66
+ */
67
+ { timeoutMs = 30_000, stopTimeoutMs = 2_000, } = {}) {
68
+ return async (handler) => {
69
+ const link = new MessageChannel();
70
+ const reply = new MessageChannel();
71
+ const stopServing = await serveHandlerOverPort(link.port1, handler);
72
+ const answered = once(reply.port1, timeoutMs);
73
+ const request = { type: HOST_SITE, link: link.port2, reply: reply.port2 };
74
+ control.postMessage(request, [link.port2, reply.port2]);
75
+ const { baseUrl, error } = await answered;
76
+ if (!baseUrl) {
77
+ // A page that hosts the site after all finds this stop waiting for it, and takes the site
78
+ // down (its port stays open for that).
79
+ reply.port1.onmessage = null;
80
+ reply.port1.postMessage({ type: STOP_SITE });
81
+ await stopServing();
82
+ throw new Error(`the page did not host the site: ${error}`);
83
+ }
84
+ return {
85
+ baseUrl,
86
+ stop: async () => {
87
+ // A page that does not answer stops nothing: the worker stops serving all the same.
88
+ const stopped = once(reply.port1, stopTimeoutMs);
89
+ reply.port1.postMessage({ type: STOP_SITE });
90
+ await stopped;
91
+ reply.port1.close();
92
+ await stopServing();
93
+ },
94
+ };
95
+ };
96
+ }
97
+ /**
98
+ * Page side: hosts in this page's ServiceWorker the sites a worker asks for over `control`
99
+ * (`siteHostOverPort`). Returns a function that stops listening; the sites stop when the worker
100
+ * stops them.
101
+ */
102
+ export function hostSitesForWorker(control, options = {}) {
103
+ const listener = async (e) => {
104
+ const req = e.data;
105
+ if (req?.type !== HOST_SITE)
106
+ return;
107
+ try {
108
+ // The worker may give up waiting (`timeoutMs`) and ask to stop before the site is up: the
109
+ // stop then waits on `reply` until the handler below reads it.
110
+ const link = await linkOverPort(req.link);
111
+ const builder = new HostedSiteBuilder().setHandler(link.send);
112
+ if (options.serviceWorkerUrl)
113
+ builder.setServiceWorkerUrl(options.serviceWorkerUrl);
114
+ const site = await builder.build();
115
+ req.reply.onmessage = async (m) => {
116
+ if (m.data?.type !== STOP_SITE)
117
+ return;
118
+ await site.stop().catch(() => { });
119
+ await link.close().catch(() => { });
120
+ req.reply.postMessage({ stopped: true });
121
+ req.reply.close();
122
+ };
123
+ req.reply.postMessage({ baseUrl: site.baseUrl });
124
+ }
125
+ catch (err) {
126
+ req.reply.postMessage({ error: String(err?.message ?? err) });
127
+ req.reply.close();
128
+ }
129
+ };
130
+ control.addEventListener("message", listener);
131
+ control.start?.();
132
+ return () => control.removeEventListener("message", listener);
133
+ }
134
+ //# sourceMappingURL=site-compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-compiler.js","sourceRoot":"","sources":["../../src/project/site-compiler.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAyB9C,oEAAoE;AACpE,SAAS,iBAAiB,CAAC,gBAAyB;IAClD,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,IAAI,CAAE,UAA0D,CAAC,SAAS,EAAE,aAAa;YACvF,MAAM,IAAI,KAAK,CACb,wFAAwF;gBACtF,qFAAqF,CACxF,CAAC;QACJ,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC5D,IAAI,gBAAgB;YAAE,OAAO,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;QACpE,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACnC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,E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IAAI,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;YACnC,GAAG,CAAC,KAAK,CAAC,SAAS,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;gBAChC,IAAK,CAAC,CAAC,IAA0B,EAAE,IAAI,KAAK,SAAS;oBAAE,OAAO;gBAC9D,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;gBAClC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;gBACnC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;gBACzC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACpB,CAAC,CAAC;YACF,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACnD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,MAAM,CAAE,GAAa,EAAE,OAAO,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC;YACzE,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;IACH,CAAC,CAAC;IACF,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC7C,OAAkC,CAAC,KAAK,EAAE,EAAE,CAAC;IAC9C,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AAChE,CAAC","sourcesContent":["/**\n * `siteCompiler`: a project's sources served by an in-browser HTTP server (`createProjectSite`,\n * hosted in a ServiceWorker by webrun-site-host), for `loadProject(files, { compile })`. Modules\n * are compiled one by one as the browser imports them; nothing is bundled.\n *\n * `loadProject` runs in a Dedicated Worker, which cannot register a ServiceWorker: the site is\n * hosted by a page. `siteHostOverPort` (worker) and `hostSitesForWorker` (page) do that over a\n * MessagePort: the worker serves the site's handler, the page mounts it in its ServiceWorker.\n */\nimport type { SiteHandler } from \"@statewalker/webrun-site-builder\";\nimport { HostedSiteBuilder } from \"@statewalker/webrun-site-host\";\nimport { linkOverPort, serveHandlerOverPort } from \"../transport/port.js\";\nimport { createProjectSite } from \"./site.js\";\nimport type { ProjectCompiler } from \"./source-project.js\";\n\n/** A site, hosted: its base URL (ending in \"/\") and how to take it down. */\nexport interface HostedProjectSite {\n baseUrl: string;\n stop(): Promise<void>;\n}\n\n/** Hosts a site handler where this realm's code can `import()` from it. */\nexport type SiteHost = (handler: SiteHandler) => Promise<HostedProjectSite>;\n\nexport interface SiteCompilerOptions {\n /**\n * Where the site is hosted. Default: a ServiceWorker this realm registers (`HostedSiteBuilder`),\n * which a page can do and a Dedicated Worker cannot; in a worker, pass `siteHostOverPort(port)`\n * and call `hostSitesForWorker(port)` in the page.\n */\n host?: SiteHost;\n /** The ServiceWorker script for the default host (default: `/sw-worker.js`). */\n serviceWorkerUrl?: string;\n /** `createProjectSite`'s `lowerAwait` (default: with nodejs_compat, unless AsyncContext). */\n lowerAwait?: boolean;\n}\n\n/** The default host: a ServiceWorker registered from this realm. */\nfunction serviceWorkerHost(serviceWorkerUrl?: string): SiteHost {\n return async (handler) => {\n if (!(globalThis as { navigator?: { serviceWorker?: unknown } }).navigator?.serviceWorker)\n throw new Error(\n \"siteCompiler: this realm cannot register a ServiceWorker (a Dedicated Worker cannot): \" +\n \"pass `host: siteHostOverPort(port)` and call `hostSitesForWorker(port)` in the page\",\n );\n const builder = new HostedSiteBuilder().setHandler(handler);\n if (serviceWorkerUrl) builder.setServiceWorkerUrl(serviceWorkerUrl);\n const site = await builder.build();\n return { baseUrl: site.baseUrl, stop: () => site.stop() };\n };\n}\n\n/**\n * A compiler for `loadProject(files, { compile })` that serves the project's modules from an\n * in-browser HTTP server (`createProjectSite`): `main` and Worker Loader code are imported from\n * it, so a change can rebuild one module. The site stops when the project closes.\n */\nexport function siteCompiler(options: SiteCompilerOptions = {}): ProjectCompiler {\n const host = options.host ?? serviceWorkerHost(options.serviceWorkerUrl);\n return {\n kind: \"site\",\n async compile({ files, nodeCompat }) {\n let nodeModules: Record<string, unknown> | undefined;\n if (nodeCompat) {\n // The served `node:*` proxies take their export names from the registry entries, which\n // the browser host binds in this realm; the npm `util` polyfill reads `process` when it\n // is imported.\n (await import(\"../node-compat/install.js\")).installNodeGlobals();\n nodeModules = (await import(\"../node-compat/browser-registry.js\")).nodeRegistryEntries;\n }\n const handler = createProjectSite({\n projectFiles: files,\n nodeCompat,\n nodeModules,\n lowerAwait: options.lowerAwait,\n });\n const site = await host(handler);\n const baseUrl = site.baseUrl.endsWith(\"/\") ? site.baseUrl : `${site.baseUrl}/`;\n return { code: { site: baseUrl }, close: () => site.stop() };\n },\n };\n}\n\nconst HOST_SITE = \"cellb:host-site\";\nconst STOP_SITE = \"cellb:stop-site\";\n\n/**\n * Where a worker and its page talk about sites: a MessagePort, the `Worker` (page side) or the\n * worker's own scope (`self`). Other messages on it are left alone.\n */\nexport interface SiteControl {\n postMessage(message: unknown, transfer: Transferable[]): void;\n addEventListener(type: \"message\", listener: (e: MessageEvent) => void): void;\n removeEventListener(type: \"message\", listener: (e: MessageEvent) => void): void;\n}\n\n/** What a worker asks its page for, on the control port. */\ninterface HostSiteRequest {\n type: typeof HOST_SITE;\n /** The worker serves the site's handler on this port's other end. */\n link: MessagePort;\n /** The page answers here, and the worker asks to stop here. */\n reply: MessagePort;\n}\n\n/** The next message on `port`, or `{ error }` after `timeoutMs` (a page that never answers). */\nconst once = (port: MessagePort, timeoutMs: number) =>\n new Promise<{ baseUrl?: string; error?: string }>((resolve) => {\n const timer = setTimeout(\n () =>\n resolve({ error: `no answer in ${timeoutMs} ms (does the page run hostSitesForWorker?)` }),\n timeoutMs,\n );\n port.onmessage = (e) => {\n clearTimeout(timer);\n resolve(e.data);\n };\n });\n\n/**\n * Worker side: hosts each site through the page at the other end of `control`, which runs\n * `hostSitesForWorker`. The handler stays in this worker; the page's ServiceWorker forwards each\n * request to it.\n */\nexport function siteHostOverPort(\n control: SiteControl,\n /**\n * How long the page may take to host the site (default 30 s; a ServiceWorker's first install\n * can be slow), and to confirm it stopped one (default 2 s; the worker stops serving anyway).\n */\n {\n timeoutMs = 30_000,\n stopTimeoutMs = 2_000,\n }: { timeoutMs?: number; stopTimeoutMs?: number } = {},\n): SiteHost {\n return async (handler) => {\n const link = new MessageChannel();\n const reply = new MessageChannel();\n const stopServing = await serveHandlerOverPort(link.port1, handler);\n const answered = once(reply.port1, timeoutMs);\n const request: HostSiteRequest = { type: HOST_SITE, link: link.port2, reply: reply.port2 };\n control.postMessage(request, [link.port2, reply.port2]);\n const { baseUrl, error } = await answered;\n if (!baseUrl) {\n // A page that hosts the site after all finds this stop waiting for it, and takes the site\n // down (its port stays open for that).\n reply.port1.onmessage = null;\n reply.port1.postMessage({ type: STOP_SITE });\n await stopServing();\n throw new Error(`the page did not host the site: ${error}`);\n }\n return {\n baseUrl,\n stop: async () => {\n // A page that does not answer stops nothing: the worker stops serving all the same.\n const stopped = once(reply.port1, stopTimeoutMs);\n reply.port1.postMessage({ type: STOP_SITE });\n await stopped;\n reply.port1.close();\n await stopServing();\n },\n };\n };\n}\n\n/**\n * Page side: hosts in this page's ServiceWorker the sites a worker asks for over `control`\n * (`siteHostOverPort`). Returns a function that stops listening; the sites stop when the worker\n * stops them.\n */\nexport function hostSitesForWorker(\n control: SiteControl,\n options: { serviceWorkerUrl?: string } = {},\n): () => void {\n const listener = async (e: MessageEvent) => {\n const req = e.data as HostSiteRequest | undefined;\n if (req?.type !== HOST_SITE) return;\n try {\n // The worker may give up waiting (`timeoutMs`) and ask to stop before the site is up: the\n // stop then waits on `reply` until the handler below reads it.\n const link = await linkOverPort(req.link);\n const builder = new HostedSiteBuilder().setHandler(link.send);\n if (options.serviceWorkerUrl) builder.setServiceWorkerUrl(options.serviceWorkerUrl);\n const site = await builder.build();\n req.reply.onmessage = async (m) => {\n if ((m.data as { type?: string })?.type !== STOP_SITE) return;\n await site.stop().catch(() => {});\n await link.close().catch(() => {});\n req.reply.postMessage({ stopped: true });\n req.reply.close();\n };\n req.reply.postMessage({ baseUrl: site.baseUrl });\n } catch (err) {\n req.reply.postMessage({ error: String((err as Error)?.message ?? err) });\n req.reply.close();\n }\n };\n control.addEventListener(\"message\", listener);\n (control as { start?: () => void }).start?.();\n return () => control.removeEventListener(\"message\", listener);\n}\n"]}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * A project's sources (`wrangler.jsonc`, `main`, `package.json`, assets) in a FilesApi, and the
3
+ * compilers that turn them into code `browserProjectRuntime` runs (`loadProject`'s `compile`).
4
+ *
5
+ * Platform-neutral and free of compilers: a compiler is made by the entry point that owns it
6
+ * (`bundleCompiler` in `@statewalker/cellb/bundle`, `siteCompiler` in `@statewalker/cellb/site`),
7
+ * so a plain `loadProject` ships neither esbuild-wasm nor webrun-modules.
8
+ */
9
+ import type { FilesApi } from "@statewalker/webrun-files";
10
+ import type { AssetFiles } from "../bindings/assets.js";
11
+ import { hasNodeCompat, WRANGLER_FILES, type WranglerConfig } from "./wrangler.js";
12
+ export { hasNodeCompat, WRANGLER_FILES };
13
+ /** A source project read from a FilesApi: what a compiler needs besides the files. */
14
+ export interface SourceProject {
15
+ config: WranglerConfig;
16
+ /** The files of `assets.directory` ("/index.html" → bytes), or undefined without assets. */
17
+ assets?: AssetFiles;
18
+ }
19
+ /** What a compiler gives `browserProjectRuntime`: the project's code, and what to stop after. */
20
+ export interface CompiledProject {
21
+ /** `browserProjectRuntime`'s `code`. */
22
+ code: {
23
+ bundle: string | null;
24
+ } | {
25
+ site: string;
26
+ };
27
+ /** Releases what the compiler holds (a site's ServiceWorker registration); after `close()`. */
28
+ close?(): Promise<void>;
29
+ }
30
+ /** Turns a source project into code for `browserProjectRuntime` (`loadProject`'s `compile`). */
31
+ export interface ProjectCompiler {
32
+ /** A name for messages ("bundle", "site"). */
33
+ readonly kind: string;
34
+ compile(project: {
35
+ /** The project's files, its configuration at the root. */
36
+ files: FilesApi;
37
+ config: WranglerConfig;
38
+ /** Whether the project has `nodejs_compat` (or a `nodejs_compat_*` flag). */
39
+ nodeCompat: boolean;
40
+ }): Promise<CompiledProject>;
41
+ }
42
+ /**
43
+ * Reads a source folder at the root of `files`: its `wrangler.jsonc` (or `wrangler.json`) and the
44
+ * files of its `assets.directory`. Undefined when there is no configuration.
45
+ */
46
+ export declare function readSourceProject(files: FilesApi): Promise<SourceProject | undefined>;
@@ -0,0 +1,45 @@
1
+ import { filesApiReader, readJson } from "./built-project.js";
2
+ import { hasNodeCompat, WRANGLER_FILES } from "./wrangler.js";
3
+ export { hasNodeCompat, WRANGLER_FILES };
4
+ /**
5
+ * Reads a source folder at the root of `files`: its `wrangler.jsonc` (or `wrangler.json`) and the
6
+ * files of its `assets.directory`. Undefined when there is no configuration.
7
+ */
8
+ export async function readSourceProject(files) {
9
+ const reader = filesApiReader(files);
10
+ let config;
11
+ for (const name of WRANGLER_FILES) {
12
+ config = await readJson(reader, name);
13
+ if (config)
14
+ break;
15
+ }
16
+ if (!config)
17
+ return undefined;
18
+ if (!config.main && !config.assets)
19
+ throw new Error("wrangler config has neither `main` nor `assets`");
20
+ if (!config.assets?.directory)
21
+ return { config };
22
+ const dir = folderPath(config.assets.directory);
23
+ const paths = await reader.list(dir || "/");
24
+ const assets = new Map();
25
+ await Promise.all(paths.map(async (path) => {
26
+ const bytes = await reader.bytes(`${dir}${path}`);
27
+ if (bytes)
28
+ assets.set(path, bytes);
29
+ }));
30
+ return { config, assets };
31
+ }
32
+ /**
33
+ * A folder of the project as a path from its root, "" for the root itself: "./public/" →
34
+ * "/public", "." → "", "a/../b" → "/b" (as `path.resolve` takes `assets.directory` on Node).
35
+ */
36
+ function folderPath(dir) {
37
+ const parts = [];
38
+ for (const part of dir.split("/"))
39
+ if (part === "..")
40
+ parts.pop();
41
+ else if (part && part !== ".")
42
+ parts.push(part);
43
+ return parts.map((p) => `/${p}`).join("");
44
+ }
45
+ //# sourceMappingURL=source-project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-project.js","sourceRoot":"","sources":["../../src/project/source-project.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAuB,MAAM,eAAe,CAAC;AAEnF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC;AA8BzC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,KAAe;IACrD,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,MAAkC,CAAC;IACvC,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE,CAAC;QAClC,MAAM,GAAG,MAAM,QAAQ,CAAiB,MAAM,EAAE,IAAI,CAAC,CAAC;QACtD,IAAI,MAAM;YAAE,MAAM;IACpB,CAAC;IACD,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM;QAChC,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACjD,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,MAAO,MAAM,CAAC,IAAwC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;IACjF,MAAM,MAAM,GAAe,IAAI,GAAG,EAAE,CAAC;IACrC,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACvB,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,IAAI,EAAE,CAAC,CAAC;QAClD,IAAI,KAAK;YAAE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC,CAAC,CACH,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,SAAS,UAAU,CAAC,GAAW;IAC7B,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC;QAC/B,IAAI,IAAI,KAAK,IAAI;YAAE,KAAK,CAAC,GAAG,EAAE,CAAC;aAC1B,IAAI,IAAI,IAAI,IAAI,KAAK,GAAG;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["/**\n * A project's sources (`wrangler.jsonc`, `main`, `package.json`, assets) in a FilesApi, and the\n * compilers that turn them into code `browserProjectRuntime` runs (`loadProject`'s `compile`).\n *\n * Platform-neutral and free of compilers: a compiler is made by the entry point that owns it\n * (`bundleCompiler` in `@statewalker/cellb/bundle`, `siteCompiler` in `@statewalker/cellb/site`),\n * so a plain `loadProject` ships neither esbuild-wasm nor webrun-modules.\n */\nimport type { FilesApi } from \"@statewalker/webrun-files\";\nimport type { AssetFiles } from \"../bindings/assets.js\";\nimport { filesApiReader, readJson } from \"./built-project.js\";\nimport { hasNodeCompat, WRANGLER_FILES, type WranglerConfig } from \"./wrangler.js\";\n\nexport { hasNodeCompat, WRANGLER_FILES };\n\n/** A source project read from a FilesApi: what a compiler needs besides the files. */\nexport interface SourceProject {\n config: WranglerConfig;\n /** The files of `assets.directory` (\"/index.html\" → bytes), or undefined without assets. */\n assets?: AssetFiles;\n}\n\n/** What a compiler gives `browserProjectRuntime`: the project's code, and what to stop after. */\nexport interface CompiledProject {\n /** `browserProjectRuntime`'s `code`. */\n code: { bundle: string | null } | { site: string };\n /** Releases what the compiler holds (a site's ServiceWorker registration); after `close()`. */\n close?(): Promise<void>;\n}\n\n/** Turns a source project into code for `browserProjectRuntime` (`loadProject`'s `compile`). */\nexport interface ProjectCompiler {\n /** A name for messages (\"bundle\", \"site\"). */\n readonly kind: string;\n compile(project: {\n /** The project's files, its configuration at the root. */\n files: FilesApi;\n config: WranglerConfig;\n /** Whether the project has `nodejs_compat` (or a `nodejs_compat_*` flag). */\n nodeCompat: boolean;\n }): Promise<CompiledProject>;\n}\n\n/**\n * Reads a source folder at the root of `files`: its `wrangler.jsonc` (or `wrangler.json`) and the\n * files of its `assets.directory`. Undefined when there is no configuration.\n */\nexport async function readSourceProject(files: FilesApi): Promise<SourceProject | undefined> {\n const reader = filesApiReader(files);\n let config: WranglerConfig | undefined;\n for (const name of WRANGLER_FILES) {\n config = await readJson<WranglerConfig>(reader, name);\n if (config) break;\n }\n if (!config) return undefined;\n if (!config.main && !config.assets)\n throw new Error(\"wrangler config has neither `main` nor `assets`\");\n if (!config.assets?.directory) return { config };\n const dir = folderPath(config.assets.directory);\n const paths = await (reader.list as NonNullable<typeof reader.list>)(dir || \"/\");\n const assets: AssetFiles = new Map();\n await Promise.all(\n paths.map(async (path) => {\n const bytes = await reader.bytes(`${dir}${path}`);\n if (bytes) assets.set(path, bytes);\n }),\n );\n return { config, assets };\n}\n\n/**\n * A folder of the project as a path from its root, \"\" for the root itself: \"./public/\" →\n * \"/public\", \".\" → \"\", \"a/../b\" → \"/b\" (as `path.resolve` takes `assets.directory` on Node).\n */\nfunction folderPath(dir: string): string {\n const parts: string[] = [];\n for (const part of dir.split(\"/\"))\n if (part === \"..\") parts.pop();\n else if (part && part !== \".\") parts.push(part);\n return parts.map((p) => `/${p}`).join(\"\");\n}\n"]}
@@ -120,6 +120,10 @@ export declare function withResourceIds(config: WranglerConfig): WranglerConfig;
120
120
  * `nodejs_compat_do_not_populate_process_env` is set. Frameworks read their settings there
121
121
  * (EmDash's `EMDASH_SITE_URL`, for one).
122
122
  */
123
+ /** Whether `config` asks for nodejs_compat (the flag, or a `nodejs_compat_*` one). */
124
+ export declare function hasNodeCompat(config: WranglerConfig): boolean;
125
+ /** The configuration files of a project folder, in the order celld reads them. */
126
+ export declare const WRANGLER_FILES: string[];
123
127
  export declare function populatesProcessEnv(config: WranglerConfig): boolean;
124
128
  /** The text `vars` of a project, as `process.env` holds them. */
125
129
  export declare function processEnvOf(config: WranglerConfig): Record<string, string>;
@@ -355,9 +355,15 @@ export function withResourceIds(config) {
355
355
  * `nodejs_compat_do_not_populate_process_env` is set. Frameworks read their settings there
356
356
  * (EmDash's `EMDASH_SITE_URL`, for one).
357
357
  */
358
+ /** Whether `config` asks for nodejs_compat (the flag, or a `nodejs_compat_*` one). */
359
+ export function hasNodeCompat(config) {
360
+ return (config.compatibility_flags ?? []).some((f) => f.startsWith("nodejs_compat"));
361
+ }
362
+ /** The configuration files of a project folder, in the order celld reads them. */
363
+ export const WRANGLER_FILES = ["wrangler.jsonc", "wrangler.json"];
358
364
  export function populatesProcessEnv(config) {
359
365
  const flags = config.compatibility_flags ?? [];
360
- if (!flags.some((f) => f.startsWith("nodejs_compat")))
366
+ if (!hasNodeCompat(config))
361
367
  return false;
362
368
  if (flags.includes("nodejs_compat_do_not_populate_process_env"))
363
369
  return false;