@nimbus-sh/worker 0.12.0 → 0.13.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 (198) hide show
  1. package/dist/esbuild-cli-artifact.generated.d.ts +1 -1
  2. package/dist/esbuild-cli-artifact.generated.js +4 -4
  3. package/dist/esbuild-wasm-bundle.generated.d.ts +11 -10
  4. package/dist/esbuild-wasm-bundle.generated.d.ts.map +1 -1
  5. package/dist/esbuild-wasm-bundle.generated.js +11 -10
  6. package/dist/facets/build-facet.d.ts +53 -0
  7. package/dist/facets/build-facet.d.ts.map +1 -0
  8. package/dist/facets/build-facet.js +346 -0
  9. package/dist/facets/cirrus-real.d.ts +3 -0
  10. package/dist/facets/cirrus-real.d.ts.map +1 -1
  11. package/dist/facets/cirrus-real.js +1 -2
  12. package/dist/facets/compose.d.ts +1 -0
  13. package/dist/facets/compose.d.ts.map +1 -1
  14. package/dist/facets/compose.js +3 -0
  15. package/dist/facets/data-plan.d.ts +14 -30
  16. package/dist/facets/data-plan.d.ts.map +1 -1
  17. package/dist/facets/data-plan.js +153 -13
  18. package/dist/facets/dev-stylesheet.d.ts +27 -0
  19. package/dist/facets/dev-stylesheet.d.ts.map +1 -0
  20. package/dist/facets/dev-stylesheet.js +65 -0
  21. package/dist/facets/esbuild-transform.d.ts +23 -18
  22. package/dist/facets/esbuild-transform.d.ts.map +1 -1
  23. package/dist/facets/esbuild-transform.js +63 -109
  24. package/dist/facets/manager.d.ts +49 -9
  25. package/dist/facets/manager.d.ts.map +1 -1
  26. package/dist/facets/manager.js +238 -69
  27. package/dist/facets/oxc-transform.d.ts +29 -0
  28. package/dist/facets/oxc-transform.d.ts.map +1 -0
  29. package/dist/facets/oxc-transform.js +198 -0
  30. package/dist/facets/prebundle-pool.d.ts +23 -0
  31. package/dist/facets/prebundle-pool.d.ts.map +1 -0
  32. package/dist/facets/prebundle-pool.js +55 -0
  33. package/dist/facets/process.d.ts +13 -6
  34. package/dist/facets/process.d.ts.map +1 -1
  35. package/dist/facets/process.js +37 -31
  36. package/dist/facets/transform-store.d.ts +4 -4
  37. package/dist/facets/transform-store.js +4 -4
  38. package/dist/facets/vite-dev-server.d.ts +89 -12
  39. package/dist/facets/vite-dev-server.d.ts.map +1 -1
  40. package/dist/facets/vite-dev-server.js +66 -43
  41. package/dist/hosted/commands.d.ts.map +1 -1
  42. package/dist/hosted/commands.js +20 -4
  43. package/dist/hosted/runtime.d.ts.map +1 -1
  44. package/dist/hosted/runtime.js +7 -2
  45. package/dist/hosted/services.d.ts +3 -3
  46. package/dist/hosted/services.d.ts.map +1 -1
  47. package/dist/hosted/services.js +102 -95
  48. package/dist/hosted/session.d.ts +1 -0
  49. package/dist/hosted/session.d.ts.map +1 -1
  50. package/dist/loaders/generated-workers.d.ts +3 -0
  51. package/dist/loaders/generated-workers.d.ts.map +1 -1
  52. package/dist/loaders/generated-workers.js +3 -0
  53. package/dist/napi-wasm-artifacts.generated.js +2 -2
  54. package/dist/node-shims-artifact.generated.d.ts +14 -1
  55. package/dist/node-shims-artifact.generated.d.ts.map +1 -1
  56. package/dist/node-shims-artifact.generated.js +23 -10
  57. package/dist/npm/bin-links.d.ts +7 -4
  58. package/dist/npm/bin-links.d.ts.map +1 -1
  59. package/dist/npm/bin-links.js +14 -55
  60. package/dist/npm/cache.d.ts +6 -0
  61. package/dist/npm/cache.d.ts.map +1 -1
  62. package/dist/npm/cache.js +26 -4
  63. package/dist/npm/installer.d.ts +1 -1
  64. package/dist/npm/installer.d.ts.map +1 -1
  65. package/dist/npm/installer.js +26 -52
  66. package/dist/npm/pre-bundle-facet.d.ts +15 -117
  67. package/dist/npm/pre-bundle-facet.d.ts.map +1 -1
  68. package/dist/npm/pre-bundle-facet.js +13 -511
  69. package/dist/oxc-facet-artifact.generated.d.ts +18 -0
  70. package/dist/oxc-facet-artifact.generated.d.ts.map +1 -0
  71. package/dist/oxc-facet-artifact.generated.js +17 -0
  72. package/dist/oxc-wasm-artifact.generated.d.ts +20 -0
  73. package/dist/oxc-wasm-artifact.generated.d.ts.map +1 -0
  74. package/dist/oxc-wasm-artifact.generated.js +19 -0
  75. package/dist/rolldown-facet-artifact.generated.d.ts +18 -0
  76. package/dist/rolldown-facet-artifact.generated.d.ts.map +1 -0
  77. package/dist/rolldown-facet-artifact.generated.js +17 -0
  78. package/dist/router/remote-api.d.ts.map +1 -1
  79. package/dist/router/remote-api.js +9 -0
  80. package/dist/runtime/bash-repl.d.ts.map +1 -1
  81. package/dist/runtime/bash-repl.js +1 -4
  82. package/dist/runtime/cpython-resident.d.ts.map +1 -1
  83. package/dist/runtime/cpython-resident.js +1 -0
  84. package/dist/runtime/esbuild-wasm-bytes.d.ts +25 -23
  85. package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -1
  86. package/dist/runtime/esbuild-wasm-bytes.js +30 -25
  87. package/dist/runtime/facet-loader-host.d.ts +5 -4
  88. package/dist/runtime/facet-loader-host.d.ts.map +1 -1
  89. package/dist/runtime/facet-loader-host.js +5 -4
  90. package/dist/runtime/node-runner.d.ts +2 -0
  91. package/dist/runtime/node-runner.d.ts.map +1 -1
  92. package/dist/runtime/node-runner.js +1 -0
  93. package/dist/runtime/node-shims-artifact.d.ts +8 -1
  94. package/dist/runtime/node-shims-artifact.d.ts.map +1 -1
  95. package/dist/runtime/node-shims-artifact.js +32 -4
  96. package/dist/runtime/node-shims.d.ts.map +1 -1
  97. package/dist/runtime/node-shims.js +145 -109
  98. package/dist/runtime/opencode-facet-runner.d.ts.map +1 -1
  99. package/dist/runtime/opencode-facet-runner.js +6 -2
  100. package/dist/runtime/oxc-wasm-bytes.d.ts +19 -0
  101. package/dist/runtime/oxc-wasm-bytes.d.ts.map +1 -0
  102. package/dist/runtime/oxc-wasm-bytes.js +39 -0
  103. package/dist/runtime/package-manager.js +1 -1
  104. package/dist/runtime/process-logs-api.d.ts.map +1 -1
  105. package/dist/runtime/process-logs-api.js +2 -0
  106. package/dist/runtime/project-fs.d.ts +8 -1
  107. package/dist/runtime/project-fs.d.ts.map +1 -1
  108. package/dist/runtime/project-fs.js +15 -1
  109. package/dist/runtime/python-repl.d.ts +40 -1
  110. package/dist/runtime/python-repl.d.ts.map +1 -1
  111. package/dist/runtime/python-repl.js +19 -11
  112. package/dist/runtime/ruby-repl.d.ts +38 -0
  113. package/dist/runtime/ruby-repl.d.ts.map +1 -1
  114. package/dist/runtime/ruby-repl.js +24 -5
  115. package/dist/runtime/ruby-resident.d.ts.map +1 -1
  116. package/dist/runtime/ruby-resident.js +2 -0
  117. package/dist/session/nimbus-session.d.ts +13 -8
  118. package/dist/session/nimbus-session.d.ts.map +1 -1
  119. package/dist/session/nimbus-session.js +11 -5
  120. package/dist/session/programmatic.d.ts +25 -30
  121. package/dist/session/programmatic.d.ts.map +1 -1
  122. package/dist/session/programmatic.js +65 -93
  123. package/dist/session/routes.d.ts.map +1 -1
  124. package/dist/session/routes.js +23 -7
  125. package/dist/session/rpc.d.ts +16 -6
  126. package/dist/session/rpc.d.ts.map +1 -1
  127. package/dist/session/rpc.js +53 -13
  128. package/dist/session/start-real-vite.d.ts +24 -9
  129. package/dist/session/start-real-vite.d.ts.map +1 -1
  130. package/dist/session/start-real-vite.js +40 -4
  131. package/dist/session/supervisor-op.d.ts +14 -0
  132. package/dist/session/supervisor-op.d.ts.map +1 -1
  133. package/dist/session/supervisor-op.js +49 -0
  134. package/dist/session/supervisor-rpc.d.ts +11 -0
  135. package/dist/session/supervisor-rpc.d.ts.map +1 -1
  136. package/dist/session/supervisor-rpc.js +18 -0
  137. package/dist/session/vite-command.d.ts.map +1 -1
  138. package/dist/session/vite-command.js +23 -19
  139. package/dist/session/ws-relay.d.ts.map +1 -1
  140. package/dist/session/ws-relay.js +13 -1
  141. package/dist/shell/npm-bin-entrypoints.d.ts +3 -1
  142. package/dist/shell/npm-bin-entrypoints.d.ts.map +1 -1
  143. package/dist/shell/npm-bin-entrypoints.js +53 -25
  144. package/dist/vfs/facet-resident-store.d.ts.map +1 -1
  145. package/dist/vfs/facet-resident-store.js +11 -5
  146. package/dist/wrangler/nimbus-wrangler.d.ts +8 -0
  147. package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -1
  148. package/dist/wrangler/nimbus-wrangler.js +54 -57
  149. package/package.json +7 -5
  150. package/public/_assets/esbuild-0.24.2.wasm +0 -0
  151. package/public/_assets/napi-wasm/loader/{99efae93dd1dcc2b → ab7e57fe9e8750c2}/napi-wasm-loader.mjs +4 -4
  152. package/public/_assets/napi-wasm/loader/{99efae93dd1dcc2b → ab7e57fe9e8750c2}/provenance.json +2 -2
  153. package/public/_assets/oxc/nimbus-oxc-1aa8c4c7057c6c28.provenance.json +72 -0
  154. package/public/_assets/oxc/nimbus-oxc-1aa8c4c7057c6c28.wasm +0 -0
  155. package/public/_assets/runtime/esbuild-cli-f13e6a112b03ac07.js +1143 -0
  156. package/public/_assets/runtime/js-interpreter-3c37c48024f0f651.js +23 -0
  157. package/public/_assets/runtime/js-interpreter-ops-2f4dfec6798e70fc.js +290 -0
  158. package/public/_assets/runtime/js-interpreter-primordials-e620a61b7e9800fa.js +1 -0
  159. package/public/_assets/runtime/{node-shims-f92f16c7d7c532e9.js → node-shims-e3adc4576da31e6e.js} +651 -103
  160. package/public/_assets/runtime/{esbuild-cli-b7aecffd4c6a36fe.js → oxc-facet-fd86fefcdf16bf9c.js} +217 -1047
  161. package/public/_assets/runtime/{resident-store-92386265e8b306dc.js → resident-store-009f39539ac989fc.js} +11 -5
  162. package/public/_assets/runtime/rolldown-facet-09983434e2dbe93e.js +15165 -0
  163. package/public/_assets/runtime/{vfs-write-ledger-d33ee0034446c3e0.js → vfs-write-ledger-9e9594591425a9b8.js} +4 -1
  164. package/scripts/acorn-primordials.mjs +637 -0
  165. package/scripts/bundle-esbuild-wasm.mjs +42 -50
  166. package/scripts/bundle-facet-workers.mjs +247 -18
  167. package/scripts/bundle-node-shims.mjs +29 -2
  168. package/scripts/bundle-oxc-wasm.mjs +105 -0
  169. package/scripts/interpreter-bundle.mjs +105 -0
  170. package/scripts/napi-wasm/build.mjs +4 -1
  171. package/scripts/napi-wasm/loader/napi-wasm-loader.ts +38 -3
  172. package/scripts/oxc-wasm/Cargo.lock +1246 -0
  173. package/scripts/oxc-wasm/Cargo.toml +30 -0
  174. package/scripts/oxc-wasm/build.mjs +249 -0
  175. package/scripts/oxc-wasm/examples/memory.rs +51 -0
  176. package/scripts/oxc-wasm/examples/transform.rs +20 -0
  177. package/scripts/oxc-wasm/inputs.mjs +32 -0
  178. package/scripts/oxc-wasm/rust-toolchain.toml +5 -0
  179. package/scripts/oxc-wasm/src/abi.rs +136 -0
  180. package/scripts/oxc-wasm/src/diagnostics.rs +49 -0
  181. package/scripts/oxc-wasm/src/helpers.rs +139 -0
  182. package/scripts/oxc-wasm/src/lib.rs +247 -0
  183. package/scripts/oxc-wasm/src/module.rs +978 -0
  184. package/scripts/oxc-wasm/src/names.rs +175 -0
  185. package/scripts/oxc-wasm/src/options.rs +154 -0
  186. package/scripts/parser-audit.mjs +492 -0
  187. package/scripts/rolldown-facet/entry.mjs +21 -0
  188. package/scripts/rolldown-facet/shims.mjs +64 -0
  189. package/dist/facets/esbuild-bundle-pool.d.ts +0 -43
  190. package/dist/facets/esbuild-bundle-pool.d.ts.map +0 -1
  191. package/dist/facets/esbuild-bundle-pool.js +0 -80
  192. package/dist/loaders/pre-bundle-preamble.d.ts +0 -44
  193. package/dist/loaders/pre-bundle-preamble.d.ts.map +0 -1
  194. package/dist/loaders/pre-bundle-preamble.js +0 -116
  195. package/dist/runtime/host-wasm.d.ts +0 -8
  196. package/dist/runtime/host-wasm.d.ts.map +0 -1
  197. package/dist/runtime/host-wasm.js +0 -33
  198. /package/public/_assets/napi-wasm/loader/{99efae93dd1dcc2b → ab7e57fe9e8750c2}/wasi-trampoline.wasm +0 -0
@@ -1,48 +1,21 @@
1
1
  /**
2
- * pre-bundle-facet.ts — IsolatePool entry for esbuild pre-bundling.
2
+ * pre-bundle-facet.ts — the supervisor's half of pre-bundling npm packages
3
+ * (the `Pre-bundling N modules…` step in npm/installer.ts, and the Vite dev
4
+ * server's on-demand /@modules/ bundles).
3
5
  *
4
- * Why this exists
5
- * ───────────────
6
- * Pre-bundling npm packages (the `Pre-bundling N modules…` step in
7
- * src/npm/installer.ts) used to call `EsbuildService.build(...)`
8
- * inside the supervisor DO isolate. Each `esbuild.build` allocates
9
- * 30–80 MiB of WASM linear memory plus the input/output graph; against
10
- * the 128 MB DO heap cap this OOM-killed the supervisor on installs
11
- * touching large React libraries (motion, framer-motion, etc.). The
12
- * symptom was a banner re-print after `npm install` succeeded —
13
- * NimbusSession's constructor running again because workerd had killed
14
- * the previous isolate.
15
- *
16
- * The fix is to dispatch each per-specifier `esbuild.build` to a
17
- * IsolatePool isolate. Each facet has its own 128 MB budget and
18
- * stable-slot reuse keeps the warm-up cost amortized across the 8
19
- * concurrent specs of a typical install. The install-batch facet uses
20
- * the same isolate boundary for tarball extraction.
6
+ * Bundling runs in the Durable Object's build facet (facets/build-facet.ts:
7
+ * `prebundle`, rolldown, core runtime/prebundle-slice.ts), never in the
8
+ * supervisor: a bundle's working set (the engine's wasm memory plus the
9
+ * input and output graph) would not fit beside the supervisor's own heap.
21
10
  *
22
11
  * File-slice strategy (zero per-read RPC)
23
12
  * ──────────────────────────────────────
24
- * esbuild's VFS plugin would naturally call back to the supervisor for
25
- * every onLoad / onResolve hit. With workerd's ~5–20 ms RPC latency and
26
- * 50–200 reads per bundle × 8 specs that's 4–32 seconds of pure RPC
27
- * overhead per install — measurably worse than the current OOM-y path.
28
- *
29
- * Instead the supervisor walks the spec's transitive non-external
30
- * dependency tree once (fast — direct VFS access) and ships the
31
- * entire `{path → bytes}` slice as part of the spec. The facet's VFS
32
- * plugin reads from this in-memory map. Zero RPC during bundling.
33
- *
34
- * Stability invariants
35
- * ───────────────────
36
- * cloudflare-parallel serializes the function via `fn.toString()`.
37
- * - No `this` references (arrow / anonymous async).
38
- * - No free variables other than preamble names + explicit args.
39
- * - Module-level constants the function references must come from
40
- * the preamble (src/loaders/pre-bundle-preamble.ts) — see
41
- * `ESBUILD_PRELOAD_PREAMBLE`.
42
- *
43
- * The supervisor RPC surface (env.SUPERVISOR) is available for emergency
44
- * fallbacks but the bundle path MUST NOT use it — slice-up-front is the
45
- * contract.
13
+ * A VFS plugin would naturally call back to the supervisor for every
14
+ * resolve and load. With workerd's ~5–20 ms RPC latency and 50–200 reads
15
+ * per bundle that is seconds of pure RPC overhead per install. Instead the
16
+ * supervisor walks the spec's transitive non-external dependency tree once
17
+ * (fast — direct VFS access) and ships the entire `{path → bytes}` slice as
18
+ * part of the spec; the bundler reads from that in-memory map.
46
19
  */
47
20
  import { getSharedRuntimeExternals, BUNDLER_VERSION } from '@nimbus-sh/core/runtime/esbuild-service.js';
48
21
  // ── Supervisor-side: build the slice for one specifier ──────────────────
@@ -177,476 +150,5 @@ export function buildSliceForSpecifierWithCap(vfs, specifier, nmDir, capBytes) {
177
150
  export function externalsForSpecifier(specifier) {
178
151
  return getSharedRuntimeExternals(specifier);
179
152
  }
180
- // ── Facet function ──────────────────────────────────────────────────────
181
- //
182
- // `prebundleOne` runs inside a IsolatePool isolate. cloudflare-parallel
183
- // serialises it via fn.toString(); the helpers it references at module
184
- // scope (ESBUILD_WASM_JS_FN_BODY, resolvePackageEntry) are NOT in the
185
- // facet's lexical scope at runtime. Instead they're injected by the
186
- // pre-bundle preamble; see src/loaders/pre-bundle-preamble.ts.
187
- //
188
- // The wasm BYTES are NOT in the preamble (intentionally — that was a
189
- // 16 MiB allocation per dispatch which OOM'd the DO). They live in
190
- // env.ASSETS, the supervisor fetches once at pool construction
191
- // (src/esbuild-wasm-bytes.ts), and the bytes flow into the facet via
192
- // the LOADER `modules` map. workerd compiles at facet module-load
193
- // (startup phase, eval permitted) and exposes the resulting
194
- // WebAssembly.Module via the standard ESM import the pool's
195
- // generated worker.js performs.
196
- /**
197
- * Bundle one specifier in a facet isolate. Returns the ESM bundle output
198
- * to the supervisor; bundle bytes flow through `pool.map`'s return value
199
- * (no RPC writeBatch — pkg_esm_bundles is supervisor-side SQLite, not VFS).
200
- *
201
- * Memory plan (verified by /api/_diag/memory after the rollout):
202
- * - Slice retained in facet memory: ~3–10 MiB per typical React lib.
203
- * - esbuild WASM linear memory: ~30–80 MiB during build.
204
- * - Output bundle: usually <2 MiB.
205
- * - Peak in the facet: ~100 MiB worst case (well under 128 MB cap).
206
- *
207
- * The supervisor never holds more than the spec arg + result return at
208
- * once, so its peak stays in the low tens of MiB during the entire
209
- * pre-bundle phase.
210
- */
211
- export const prebundleOne = async function prebundleOne(spec, _env) {
212
- const t0 = Date.now();
213
- const warnings = [];
214
- if (!spec || typeof spec !== 'object') {
215
- throw new Error('prebundleOne: missing spec');
216
- }
217
- if (!Array.isArray(spec.slice)) {
218
- throw new Error('prebundleOne: spec.slice missing');
219
- }
220
- // 1. Build an in-memory slice index. Path → bytes for files, set
221
- // membership for directories. esbuild's plugin will look up paths
222
- // here exactly the way it would have looked them up in the VFS.
223
- const fileMap = new Map();
224
- const dirSet = new Set();
225
- const norm = (p) => p.startsWith('/') ? p : '/' + p;
226
- for (const ent of spec.slice) {
227
- if (ent.isDir)
228
- dirSet.add(norm(ent.path));
229
- else
230
- fileMap.set(norm(ent.path), ent.bytes);
231
- }
232
- // Every file path implicitly creates its ancestor dirs in the slice's
233
- // worldview, even if the supervisor walker didn't emit them.
234
- for (const p of fileMap.keys()) {
235
- let d = p;
236
- while (d.length > 1) {
237
- const slash = d.lastIndexOf('/');
238
- if (slash <= 0)
239
- break;
240
- d = d.substring(0, slash);
241
- dirSet.add(d);
242
- }
243
- }
244
- // 2. Pick up the esbuild namespace materialised by the preamble at
245
- // module startup. workerd's deployed config disallows "Code
246
- // generation from strings" at REQUEST time inside dynamic workers,
247
- // so we cannot run `new Function(jsBody)()` here. The preamble
248
- // runs that at module-load time (where eval is permitted) and
249
- // stashes the result on the module-scope const __NIMBUS_ESBUILD_NS.
250
- //
251
- // The WASM module is shipped into the facet via IsolatePool's
252
- // `wasmModules` option, registered in the LOADER's modules map as
253
- // { wasm: ArrayBuffer }. Workerd compiles it during the worker's
254
- // module-load phase (eval permitted there), and the pool's
255
- // generated worker.js exposes the resulting WebAssembly.Module on
256
- // globalThis.__NIMBUS_WASM[<key>]. We read it here at request time
257
- // — no RPC, no compile, no structured-clone of Module values.
258
- //
259
- // First-dispatch costs (per warm slot):
260
- // - 0 (esb namespace materialised at startup)
261
- // - 0 (wasm Module already compiled by workerd at startup)
262
- // - esb.initialize (~10 ms)
263
- // Subsequent dispatches: pure cache hit.
264
- // @ts-ignore — preamble symbol.
265
- const esbInitErr = __NIMBUS_ESBUILD_INIT_ERR;
266
- if (esbInitErr) {
267
- throw new Error(`prebundleOne: esbuild namespace unavailable (preamble eval failed: ${esbInitErr})`);
268
- }
269
- // @ts-ignore — preamble symbol.
270
- const esb = __NIMBUS_ESBUILD_NS;
271
- if (!esb) {
272
- throw new Error('prebundleOne: __NIMBUS_ESBUILD_NS is null (preamble did not run?)');
273
- }
274
- // Initialize esbuild's wasm exactly once per facet isolate. With
275
- // pool concurrency > 1, multiple dispatches may run concurrently in
276
- // the same slot — without an in-flight promise gate, both observe
277
- // `!ready`, both call esb.initialize, the second errors with
278
- // "You need to wait for the promise returned from 'initialize' to
279
- // be resolved before calling this." Cache the in-flight Promise so
280
- // concurrent callers await the same init; resolved Promise is
281
- // cheap to await on subsequent dispatches.
282
- let initPromise = globalThis.__nimbusFacetEsbuildInit;
283
- if (!initPromise) {
284
- initPromise = (async () => {
285
- // Read the WebAssembly.Module the pool registered. The key matches
286
- // the name passed to IsolatePool's `wasmModules` option (see
287
- // src/npm/installer.ts:prebundleUsedModules dispatch site).
288
- const wasmRegistry = globalThis.__NIMBUS_WASM;
289
- const wasmModule = wasmRegistry && wasmRegistry['esbuild.wasm'];
290
- if (!wasmModule) {
291
- throw new Error(`prebundleOne: globalThis.__NIMBUS_WASM['esbuild.wasm'] missing — ` +
292
- `pool was constructed without wasmModules?`);
293
- }
294
- try {
295
- await esb.initialize({ wasmModule, worker: false });
296
- }
297
- catch (e) {
298
- // "more than once" is harmless — this isolate already initialized
299
- // in a previous warm dispatch; treat as success.
300
- if (!String(e?.message || '').includes('more than once'))
301
- throw e;
302
- }
303
- })();
304
- globalThis.__nimbusFacetEsbuildInit = initPromise;
305
- }
306
- await initPromise;
307
- // 3. Build the VFS plugin. The plugin reads from `fileMap` exclusively;
308
- // every miss is logged into `warnings` so the supervisor can see
309
- // whether the slice walker is missing something the bundle path
310
- // actually wanted.
311
- const EXTS = ['', '.ts', '.tsx', '.js', '.jsx', '.mts', '.mjs', '.cjs', '.json', '.css'];
312
- const INDEX_FILES = ['index.ts', 'index.tsx', 'index.js', 'index.jsx', 'index.mjs'];
313
- const stripLeadingSlash = (p) => p.replace(/^\/+/, '');
314
- const normalizePath = (p) => {
315
- // Resolve any `..` segments to keep tryResolve's exists() lookups
316
- // canonical. This helper runs inside the serialized facet function,
317
- // so it mirrors src/vfs/path.ts instead of importing it.
318
- const parts = p.split('/');
319
- const out = [];
320
- for (const seg of parts) {
321
- if (seg === '' || seg === '.')
322
- continue;
323
- if (seg === '..') {
324
- if (out.length > 0)
325
- out.pop();
326
- continue;
327
- }
328
- out.push(seg);
329
- }
330
- return (p.startsWith('/') ? '/' : '') + out.join('/');
331
- };
332
- const fileExists = (p) => fileMap.has(norm(p));
333
- const dirExists = (p) => dirSet.has(norm(p));
334
- const tryResolve = (base) => {
335
- const n = normalizePath(base);
336
- for (const ext of EXTS) {
337
- const cand = n + ext;
338
- if (fileExists(cand))
339
- return cand;
340
- }
341
- // Bundler-style swap: import './x.js' → ./x.ts on disk.
342
- const m = n.match(/\.(js|mjs|cjs|jsx)$/);
343
- if (m) {
344
- const without = n.slice(0, n.length - m[0].length);
345
- const swapMap = {
346
- js: ['.ts', '.tsx'], jsx: ['.tsx', '.ts'],
347
- mjs: ['.mts', '.ts'], cjs: ['.cts', '.ts'],
348
- };
349
- for (const ext of swapMap[m[1]] || []) {
350
- const cand = without + ext;
351
- if (fileExists(cand))
352
- return cand;
353
- }
354
- }
355
- if (dirExists(n)) {
356
- for (const idx of INDEX_FILES) {
357
- const cand = n + '/' + idx;
358
- if (fileExists(cand))
359
- return cand;
360
- }
361
- }
362
- return null;
363
- };
364
- // Subpath imports (`#X`) → resolve via the importing module's owning
365
- // package.json `imports` field. Walks up from `fromDir` looking for
366
- // package.json; first one with `#X` in its `imports` map wins.
367
- // Reuses `resolveExports` (provided by the pre-bundle preamble) since
368
- // imports/exports share the same shape (subpath → conditions →
369
- // target).
370
- //
371
- // This is the slice-path counterpart to esbuild-service.ts's
372
- // `resolvePackageImport` (which serves the supervisor's in-process
373
- // bundler). Both must walk up only as far as the first package.json —
374
- // Node's spec is "imports field of the importing module's package",
375
- // never the parent's.
376
- //
377
- // Without this, packages like vfile / unified / remark / mdx (heavy
378
- // users of `#minpath` / `#minurl` / `#minproc`) leak literal `#X`
379
- // specifiers into the bundle output, and the browser then chokes
380
- // with `Failed to resolve module specifier "#minpath"`. Fix: resolve
381
- // here so the bundle output references the actual file path.
382
- const resolvePackageImport = (specifier, fromDir) => {
383
- let dir = stripLeadingSlash(fromDir);
384
- const visited = new Set();
385
- while (dir && !visited.has(dir)) {
386
- visited.add(dir);
387
- const pkgJsonPath = '/' + dir + '/package.json';
388
- if (fileExists(pkgJsonPath)) {
389
- try {
390
- const pkgJsonText = new TextDecoder().decode(fileMap.get(norm(pkgJsonPath)));
391
- const pkgJson = JSON.parse(pkgJsonText);
392
- if (pkgJson && pkgJson.imports) {
393
- // @ts-ignore — preamble symbol.
394
- const target = resolveExports(pkgJson.imports, specifier);
395
- if (target) {
396
- const r = tryResolve('/' + dir + '/' + target.replace(/^\.\//, ''));
397
- if (r)
398
- return r;
399
- }
400
- }
401
- }
402
- catch { /* malformed package.json — keep walking */ }
403
- // First package.json wins regardless of whether it had `imports`
404
- // (Node spec). Stop here even on a miss.
405
- return null;
406
- }
407
- const lastSlash = dir.lastIndexOf('/');
408
- if (lastSlash <= 0)
409
- break;
410
- dir = dir.substring(0, lastSlash);
411
- }
412
- return null;
413
- };
414
- // Conditions per-resolution. CJS `require('X')` callers need the
415
- // `require` condition selected so packages that ship a dual-export
416
- // CJS trick (e.g. @babel/runtime/helpers/X — `module.exports = fn;
417
- // module.exports.default = module.exports;`) resolve to the CJS
418
- // file. The ESM helper file (`./helpers/esm/X.js`) declares only
419
- // `export { fn as default }`, which esbuild's __toCommonJS wrap
420
- // would surface to a CJS require as `{ default: fn }` — and the
421
- // downstream callsite `_objectWithoutPropertiesLoose2(...)` calls
422
- // the namespace as a function and crashes with
423
- // `_objectWithoutPropertiesLoose2 is not a function` at runtime.
424
- //
425
- // This is the same logic Node uses: `require()` triggers the
426
- // `require` condition, `import` triggers `import`. esbuild's own
427
- // resolver does this when it owns resolution; we own it via the
428
- // VFS plugin, so we must pass conditions through ourselves.
429
- //
430
- // Affects every CJS-shipping npm package that depends on
431
- // `@babel/runtime/helpers/*` (thousands — anything compiled with
432
- // @babel/preset-env's `transform-runtime`). Verified to fix:
433
- // - react-textarea-autosize → Markflow's /write route
434
- // - @emotion/* CJS bundles
435
- // - downstream of `babel-plugin-transform-runtime`
436
- const ESM_CONDITIONS = ['import', 'module', 'browser', 'default'];
437
- const CJS_CONDITIONS = ['require', 'node', 'browser', 'default'];
438
- // Bare specifier → entry path resolution. Mirrors EsbuildService's
439
- // makeVfsPlugin.resolveBarePkg but reads from fileMap.
440
- const resolveBarePkg = (specifier, fromDir, conditions) => {
441
- let pkgName, subpath;
442
- if (specifier.startsWith('@')) {
443
- const parts = specifier.split('/');
444
- pkgName = parts.slice(0, 2).join('/');
445
- subpath = parts.slice(2).join('/');
446
- }
447
- else {
448
- const parts = specifier.split('/');
449
- pkgName = parts[0];
450
- subpath = parts.slice(1).join('/');
451
- }
452
- let dir = stripLeadingSlash(fromDir);
453
- const visited = new Set();
454
- while (dir && !visited.has(dir)) {
455
- visited.add(dir);
456
- const nm = '/' + dir + '/node_modules/' + pkgName;
457
- if (dirExists(nm)) {
458
- const pkgJsonPath = nm + '/package.json';
459
- if (fileExists(pkgJsonPath)) {
460
- try {
461
- const pkgJsonText = new TextDecoder().decode(fileMap.get(pkgJsonPath));
462
- const pkgJson = JSON.parse(pkgJsonText);
463
- const subKey = subpath ? './' + subpath : '.';
464
- // @ts-ignore — `resolvePackageEntry` is provided by the
465
- // pre-bundle preamble at facet-load time; no static import.
466
- const entry = resolvePackageEntry(pkgJson, subKey, conditions);
467
- if (entry) {
468
- const r = tryResolve(nm + '/' + entry.replace(/^\.\//, ''));
469
- if (r)
470
- return r;
471
- }
472
- }
473
- catch { /* fall through */ }
474
- }
475
- if (subpath) {
476
- const r = tryResolve(nm + '/' + subpath);
477
- if (r)
478
- return r;
479
- }
480
- const r2 = tryResolve(nm + '/index');
481
- if (r2)
482
- return r2;
483
- }
484
- const lastSlash = dir.lastIndexOf('/');
485
- if (lastSlash <= 0)
486
- break;
487
- dir = dir.substring(0, lastSlash);
488
- }
489
- return null;
490
- };
491
- const externalSet = new Set();
492
- const externalPrefixes = [];
493
- for (const pat of spec.externals) {
494
- if (pat.endsWith('/*'))
495
- externalPrefixes.push(pat.slice(0, -1));
496
- else
497
- externalSet.add(pat);
498
- }
499
- const isExternal = (s) => {
500
- if (externalSet.has(s))
501
- return true;
502
- for (const pre of externalPrefixes)
503
- if (s.startsWith(pre))
504
- return true;
505
- return false;
506
- };
507
- const inferLoader = (path) => {
508
- if (path.endsWith('.ts') || path.endsWith('.mts') || path.endsWith('.cts'))
509
- return 'ts';
510
- if (path.endsWith('.tsx'))
511
- return 'tsx';
512
- if (path.endsWith('.jsx'))
513
- return 'jsx';
514
- if (path.endsWith('.json'))
515
- return 'json';
516
- if (path.endsWith('.css'))
517
- return 'css';
518
- if (path.endsWith('.wasm') || path.endsWith('.node'))
519
- return 'binary';
520
- return 'js';
521
- };
522
- const plugin = {
523
- name: 'nimbus-pre-bundle-slice',
524
- setup(build) {
525
- build.onResolve({ filter: /.*/ }, (args) => {
526
- // Subpath imports (#X) — resolve against the importing module's
527
- // owning package.json `imports` field (Node spec). Done BEFORE
528
- // the bare/external/absolute branches so a #X never falls
529
- // through to `external` (which would leak it to the browser
530
- // and crash the preview with "Failed to resolve module
531
- // specifier #X").
532
- if (args.path.startsWith('#') && args.resolveDir) {
533
- const r = resolvePackageImport(args.path, args.resolveDir);
534
- if (r)
535
- return { path: r, namespace: 'nimbus-slice' };
536
- // Fall through to `external` only as a last resort. We log a
537
- // warning so the supervisor can surface "looks like #X is
538
- // unresolved" rather than the user seeing an opaque crash.
539
- warnings.push(`unresolved subpath import "${args.path}" from ${args.importer || '?'} ` +
540
- `(no owning package.json#imports entry); marked external`);
541
- return { external: true };
542
- }
543
- // Bare external — leave for the browser to resolve.
544
- if (!args.path.startsWith('/') && !args.path.startsWith('.') && !args.path.startsWith('#')) {
545
- if (isExternal(args.path))
546
- return { external: true };
547
- }
548
- if (args.path.startsWith('/')) {
549
- const r = tryResolve(args.path);
550
- if (r)
551
- return { path: r, namespace: 'nimbus-slice' };
552
- }
553
- if (args.path.startsWith('.') && args.resolveDir) {
554
- const r = tryResolve(args.resolveDir + '/' + args.path);
555
- if (r)
556
- return { path: r, namespace: 'nimbus-slice' };
557
- }
558
- if (!args.path.startsWith('/') && !args.path.startsWith('.') && !args.path.startsWith('#')) {
559
- const fromDir = args.resolveDir || '/home/user';
560
- // Per Node spec: `require()` selects 'require' condition,
561
- // `import` selects 'import'. esbuild surfaces this via
562
- // args.kind. See ESM_CONDITIONS / CJS_CONDITIONS comments
563
- // above for the bug class this fixes.
564
- const conditions = args.kind === 'require-call' || args.kind === 'require-resolve'
565
- ? CJS_CONDITIONS
566
- : ESM_CONDITIONS;
567
- const r = resolveBarePkg(args.path, fromDir, conditions);
568
- if (r)
569
- return { path: r, namespace: 'nimbus-slice' };
570
- // Mark unresolved as external — same fail-soft behaviour as
571
- // EsbuildService.makeVfsPlugin, with a warning so the slice
572
- // walker can be tightened.
573
- warnings.push(`unresolved bare import "${args.path}" from ${args.importer || '?'} → marked external`);
574
- return { external: true };
575
- }
576
- return { external: true };
577
- });
578
- build.onLoad({ filter: /.*/, namespace: 'nimbus-slice' }, (args) => {
579
- const bytes = fileMap.get(norm(args.path));
580
- if (!bytes) {
581
- return { errors: [{ text: 'pre-bundle slice miss: ' + args.path }] };
582
- }
583
- const loader = inferLoader(args.path);
584
- const lastSlash = args.path.lastIndexOf('/');
585
- const resolveDir = lastSlash > 0 ? args.path.substring(0, lastSlash) : '/';
586
- if (loader === 'binary') {
587
- return { contents: bytes, loader, resolveDir };
588
- }
589
- const text = new TextDecoder().decode(bytes);
590
- return { contents: text, loader, resolveDir };
591
- });
592
- },
593
- };
594
- // 4. Run esbuild.
595
- try {
596
- // NOTE: do NOT pass `external: spec.externals` here at the top level.
597
- // esbuild's top-level external matches by file PATH too — when bundling
598
- // a subpath like 'react/jsx-runtime', the resolved entry path
599
- // /home/user/example-app/node_modules/react/jsx-runtime.js matches the 'react'
600
- // external and esbuild errors with
601
- // "The entry point '...' cannot be marked as external"
602
- //
603
- // Externals are enforced by the VFS plugin's onResolve callback above
604
- // (line ~524), which only matches BARE specifiers — never the entry
605
- // path. This means jsx-runtime CAN externalize 'react' without
606
- // tripping the entry check, AND react-dom/client CAN externalize
607
- // 'react' / 'react/jsx-runtime' the same way.
608
- const result = await esb.build({
609
- entryPoints: [spec.entryPath.startsWith('/') ? spec.entryPath : '/' + spec.entryPath],
610
- bundle: true,
611
- format: 'esm',
612
- target: 'esnext',
613
- platform: 'browser',
614
- write: false,
615
- conditions: ['import', 'module', 'browser', 'default'],
616
- mainFields: ['module', 'browser', 'main'],
617
- define: spec.define && Object.keys(spec.define).length > 0 ? spec.define : undefined,
618
- plugins: [plugin],
619
- });
620
- const out = result.outputFiles?.[0];
621
- if (!out) {
622
- return {
623
- specifier: spec.specifier,
624
- ok: false,
625
- esmCode: '',
626
- errorText: 'no output produced',
627
- elapsed: Date.now() - t0,
628
- warnings,
629
- };
630
- }
631
- return {
632
- specifier: spec.specifier,
633
- ok: true,
634
- esmCode: out.text,
635
- elapsed: Date.now() - t0,
636
- warnings,
637
- };
638
- }
639
- catch (e) {
640
- const msg = e?.errors?.[0]?.text || e?.message || String(e);
641
- return {
642
- specifier: spec.specifier,
643
- ok: false,
644
- esmCode: '',
645
- errorText: msg,
646
- elapsed: Date.now() - t0,
647
- warnings,
648
- };
649
- }
650
- };
651
153
  // Re-export so the supervisor can stamp results without re-importing.
652
154
  export { BUNDLER_VERSION };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * oxc-facet-artifact.generated.ts — AUTO-GENERATED by
3
+ * scripts/bundle-facet-workers.mjs. DO NOT EDIT.
4
+ *
5
+ * Pins the staged runtime of the transform facet: @nimbus-sh/core
6
+ * src/runtime/oxc-facet/preamble.ts as an IIFE (the Oxc wasm's driver, the
7
+ * dynamic-import rewrite and the top-level-await lowering). Only the
8
+ * transform facet evaluates it, so src/runtime/oxc-wasm-bytes.ts fetches it
9
+ * from ASSETS when that facet is built.
10
+ * OXC_FACET_BUILD_ID is a content-hash prefix, OXC_FACET_SHA256 the
11
+ * digest every fetch is verified against.
12
+ *
13
+ * Size: 319.30 KiB
14
+ */
15
+ export declare const OXC_FACET_ASSET_PATH: string;
16
+ export declare const OXC_FACET_BUILD_ID: string;
17
+ export declare const OXC_FACET_SHA256: string;
18
+ //# sourceMappingURL=oxc-facet-artifact.generated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oxc-facet-artifact.generated.d.ts","sourceRoot":"","sources":["../src/oxc-facet-artifact.generated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,oBAAoB,EAAE,MAAyD,CAAC;AAC7F,eAAO,MAAM,kBAAkB,EAAE,MAA2B,CAAC;AAC7D,eAAO,MAAM,gBAAgB,EAAE,MAA2E,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * oxc-facet-artifact.generated.ts — AUTO-GENERATED by
3
+ * scripts/bundle-facet-workers.mjs. DO NOT EDIT.
4
+ *
5
+ * Pins the staged runtime of the transform facet: @nimbus-sh/core
6
+ * src/runtime/oxc-facet/preamble.ts as an IIFE (the Oxc wasm's driver, the
7
+ * dynamic-import rewrite and the top-level-await lowering). Only the
8
+ * transform facet evaluates it, so src/runtime/oxc-wasm-bytes.ts fetches it
9
+ * from ASSETS when that facet is built.
10
+ * OXC_FACET_BUILD_ID is a content-hash prefix, OXC_FACET_SHA256 the
11
+ * digest every fetch is verified against.
12
+ *
13
+ * Size: 319.30 KiB
14
+ */
15
+ export const OXC_FACET_ASSET_PATH = "/_assets/runtime/oxc-facet-fd86fefcdf16bf9c.js";
16
+ export const OXC_FACET_BUILD_ID = "fd86fefcdf16bf9c";
17
+ export const OXC_FACET_SHA256 = "fd86fefcdf16bf9c7cb03c667318499796724a776d8d365942f8770c616124ac";
@@ -0,0 +1,20 @@
1
+ /**
2
+ * oxc-wasm-artifact.generated.ts — AUTO-GENERATED by scripts/bundle-oxc-wasm.mjs
3
+ * DO NOT EDIT.
4
+ *
5
+ * Nimbus's Oxc transform (scripts/oxc-wasm, built by its build.mjs; inputs in
6
+ * the staged provenance.json), staged under public/_assets/oxc/. The transform
7
+ * facet's builder (runtime/oxc-wasm-bytes.ts) fetches it and verifies it
8
+ * against OXC_WASM_SHA256 before the loader compiles it. The module imports
9
+ * nothing; its memory starts at OXC_WASM_MEMORY_PAGES pages (stack and static
10
+ * data) and grows only while a transform runs.
11
+ *
12
+ * oxc 0.152.0, rustc 1.98.1 (48a229cea 2026-09-01), 2.17 MiB
13
+ */
14
+ export declare const OXC_VERSION: string;
15
+ export declare const OXC_WASM_ASSET_PATH: string;
16
+ export declare const OXC_WASM_BUILD_ID: string;
17
+ export declare const OXC_WASM_SHA256: string;
18
+ export declare const OXC_WASM_BYTES: number;
19
+ export declare const OXC_WASM_MEMORY_PAGES: number;
20
+ //# sourceMappingURL=oxc-wasm-artifact.generated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oxc-wasm-artifact.generated.d.ts","sourceRoot":"","sources":["../src/oxc-wasm-artifact.generated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,WAAW,EAAE,MAAkB,CAAC;AAC7C,eAAO,MAAM,mBAAmB,EAAE,MAAwD,CAAC;AAC3F,eAAO,MAAM,iBAAiB,EAAE,MAA2B,CAAC;AAC5D,eAAO,MAAM,eAAe,EAAE,MAA2E,CAAC;AAC1G,eAAO,MAAM,cAAc,EAAE,MAAgB,CAAC;AAC9C,eAAO,MAAM,qBAAqB,EAAE,MAAW,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * oxc-wasm-artifact.generated.ts — AUTO-GENERATED by scripts/bundle-oxc-wasm.mjs
3
+ * DO NOT EDIT.
4
+ *
5
+ * Nimbus's Oxc transform (scripts/oxc-wasm, built by its build.mjs; inputs in
6
+ * the staged provenance.json), staged under public/_assets/oxc/. The transform
7
+ * facet's builder (runtime/oxc-wasm-bytes.ts) fetches it and verifies it
8
+ * against OXC_WASM_SHA256 before the loader compiles it. The module imports
9
+ * nothing; its memory starts at OXC_WASM_MEMORY_PAGES pages (stack and static
10
+ * data) and grows only while a transform runs.
11
+ *
12
+ * oxc 0.152.0, rustc 1.98.1 (48a229cea 2026-09-01), 2.17 MiB
13
+ */
14
+ export const OXC_VERSION = "0.152.0";
15
+ export const OXC_WASM_ASSET_PATH = "/_assets/oxc/nimbus-oxc-1aa8c4c7057c6c28.wasm";
16
+ export const OXC_WASM_BUILD_ID = "1aa8c4c7057c6c28";
17
+ export const OXC_WASM_SHA256 = "1aa8c4c7057c6c28c5f11b7b6cd4dd66daae5653d79e8d17fabfdd1e7d1447b8";
18
+ export const OXC_WASM_BYTES = 2276933;
19
+ export const OXC_WASM_MEMORY_PAGES = 67;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * rolldown-facet-artifact.generated.ts — AUTO-GENERATED by
3
+ * scripts/bundle-facet-workers.mjs. DO NOT EDIT.
4
+ *
5
+ * Pins the staged runtime of the build facet: scripts/rolldown-facet/entry.mjs
6
+ * as an ES module (rolldown's JavaScript API over the staged threadless
7
+ * binding, and @nimbus-sh/core runtime/rolldown-build.ts). Only the build
8
+ * facet imports it, so facets/build-facet.ts fetches it from ASSETS when
9
+ * that facet is built.
10
+ * ROLLDOWN_FACET_BUILD_ID is a content-hash prefix, ROLLDOWN_FACET_SHA256 the
11
+ * digest every fetch is verified against.
12
+ *
13
+ * Size: 559.65 KiB
14
+ */
15
+ export declare const ROLLDOWN_FACET_ASSET_PATH: string;
16
+ export declare const ROLLDOWN_FACET_BUILD_ID: string;
17
+ export declare const ROLLDOWN_FACET_SHA256: string;
18
+ //# sourceMappingURL=rolldown-facet-artifact.generated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rolldown-facet-artifact.generated.d.ts","sourceRoot":"","sources":["../src/rolldown-facet-artifact.generated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,yBAAyB,EAAE,MAA8D,CAAC;AACvG,eAAO,MAAM,uBAAuB,EAAE,MAA2B,CAAC;AAClE,eAAO,MAAM,qBAAqB,EAAE,MAA2E,CAAC"}