@nimbus-sh/worker 0.12.0 → 0.13.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 (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 +6 -4
  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
@@ -0,0 +1,29 @@
1
+ import { type EsbuildTransformHost } from '@nimbus-sh/core/runtime/esbuild-service.js';
2
+ import type { WorkerCode } from '@nimbus-sh/fabric/vendor/types.js';
3
+ export declare const OXC_FACET_WORKER_ID: string;
4
+ /**
5
+ * Slim Worker Loader module whose DO class owns the Oxc wasm. `wasm` is the
6
+ * staged module's verified bytes, compiled by the loader at startup; `runtime`
7
+ * is the facet's staged runtime script.
8
+ */
9
+ export declare function oxcFacetWorkerCode(wasm: ArrayBuffer, runtime: string): WorkerCode;
10
+ /**
11
+ * The transform host a Durable Object's transforms run on: its transform
12
+ * facet, a slice per call. Transforms are pure, so a slice whose call failed
13
+ * (the facet reset, the connection dropped) is sent once more, to a freshly
14
+ * minted stub; an overloaded facet is not asked again. A slice that still
15
+ * fails answers each of its requests with a transient error, which is no
16
+ * verdict on the source, and the other slices keep their answers.
17
+ *
18
+ * A module whose outcome says Oxc ran out of native stack on it
19
+ * (`stackExhausted`, set by the driver from the RangeError, never read off
20
+ * message text) goes to `stackFallback`, the esbuild facet in production:
21
+ * every such module, in calls of at most STACK_FALLBACK_MODULES, each with a
22
+ * deadline, each module logged. Its answer stands; the modules of a call that
23
+ * fails or misses its deadline answer transient. Without a fallback the
24
+ * exhaustion stands.
25
+ */
26
+ export declare function oxcTransformHost(ctx: DurableObjectState, env: unknown, stackFallback?: EsbuildTransformHost, { fallbackDeadlineMs }?: {
27
+ fallbackDeadlineMs?: number;
28
+ }): EsbuildTransformHost;
29
+ //# sourceMappingURL=oxc-transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oxc-transform.d.ts","sourceRoot":"","sources":["../../src/facets/oxc-transform.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,oBAAoB,EAG1B,MAAM,4CAA4C,CAAC;AAMpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AA4CpE,eAAO,MAAM,mBAAmB,QAAwF,CAAC;AAMzH;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,CAiBjF;AA+DD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,kBAAkB,EACvB,GAAG,EAAE,OAAO,EACZ,aAAa,CAAC,EAAE,oBAAoB,EACpC,EAAE,kBAA+C,EAAE,GAAE;IAAE,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAAO,GACxF,oBAAoB,CAkDtB"}
@@ -0,0 +1,198 @@
1
+ import { CF_COMPAT_DATE, GUEST_COMPAT_FLAGS } from '@nimbus-sh/core/constants.js';
2
+ import { generateTransformFacetRuntimeSource, transformSlices, } from '@nimbus-sh/core/runtime/esbuild-service.js';
3
+ import { errorText } from '@nimbus-sh/core/_shared/error-text.js';
4
+ import { beginLoaderFetch } from '@nimbus-sh/fabric/budgets.js';
5
+ import { hashSource } from '@nimbus-sh/fabric/vendor/serialize.js';
6
+ import { classifyDoCall } from '@nimbus-sh/platform/oom-classify.js';
7
+ import { OXC_WASM_BUILD_ID } from '../oxc-wasm-artifact.generated.js';
8
+ import { OXC_FACET_BUILD_ID } from '../oxc-facet-artifact.generated.js';
9
+ import { fetchOxcFacetRuntime, fetchOxcWasmBytes } from '../runtime/oxc-wasm-bytes.js';
10
+ /**
11
+ * The Oxc wasm's linear memory past which the facet drops its instance after
12
+ * a call. The module starts at 4.25 MiB and a call grows it to the module's
13
+ * working set, about 17 times a minified source (62 MiB for pi's 3.6 MiB
14
+ * chunk; a 256 KiB transform slice stays near 10 MiB). Memory never shrinks,
15
+ * so an instance a large module grew is released, and the next call starts
16
+ * a fresh one in about a millisecond.
17
+ */
18
+ const TRANSFORM_OXC_HIGH_WATER_BYTES = 32 * 1024 * 1024;
19
+ /**
20
+ * Everything of the facet's module but its staged parts. `oxcWasm` is the
21
+ * module map's compiled wasm, and the staged runtime (core
22
+ * runtime/oxc-facet/preamble.ts) installs the wasm's driver, the
23
+ * dynamic-import rewrite and the top-level-await lowering as globals.
24
+ * Requests run one at a time on one instance, each answered or refused on
25
+ * its own: a module Oxc rejects (or that crashes the instance, which is then
26
+ * replaced) is a verdict on that module, never on its slice.
27
+ */
28
+ const OXC_FACET_BODY = [
29
+ generateTransformFacetRuntimeSource(),
30
+ `const oxc = globalThis.__nimbusCreateOxcTransform(oxcWasm, { retireAboveBytes: ${TRANSFORM_OXC_HIGH_WATER_BYTES} });`,
31
+ 'export class OxcFacet extends DurableObject {',
32
+ ' async transformMany(requests) {',
33
+ ' const outcomes = [];',
34
+ ' for (const { code, options } of requests) {',
35
+ ' try {',
36
+ ' outcomes.push(await runTransformRequest(oxc, code, options, globalThis.__nimbusRewriteDynamicImports, globalThis.__nimbusLowerAsyncModule));',
37
+ ' } catch (e) {',
38
+ ' const error = String((e && e.message) || e);',
39
+ ' outcomes.push(e && e.stackExhausted === true ? { error, stackExhausted: true } : { error });',
40
+ ' }',
41
+ ' }',
42
+ ' return outcomes;',
43
+ ' }',
44
+ '}',
45
+ ].join('\n');
46
+ // The loader serves the code it cached under an id, so the id carries the code.
47
+ export const OXC_FACET_WORKER_ID = `nimbus-oxc:${OXC_WASM_BUILD_ID}:${OXC_FACET_BUILD_ID}:${hashSource(OXC_FACET_BODY)}`;
48
+ /**
49
+ * Slim Worker Loader module whose DO class owns the Oxc wasm. `wasm` is the
50
+ * staged module's verified bytes, compiled by the loader at startup; `runtime`
51
+ * is the facet's staged runtime script.
52
+ */
53
+ export function oxcFacetWorkerCode(wasm, runtime) {
54
+ const source = [
55
+ 'import { DurableObject } from "cloudflare:workers";',
56
+ 'import oxcWasm from "oxc.wasm";',
57
+ runtime,
58
+ OXC_FACET_BODY,
59
+ ].join('\n');
60
+ return {
61
+ compatibilityDate: CF_COMPAT_DATE,
62
+ compatibilityFlags: [...GUEST_COMPAT_FLAGS],
63
+ mainModule: 'worker.js',
64
+ modules: {
65
+ 'worker.js': source,
66
+ 'oxc.wasm': { wasm },
67
+ },
68
+ globalOutbound: null,
69
+ };
70
+ }
71
+ /**
72
+ * A Durable Object's transform facet: one loader-backed child that owns the
73
+ * Oxc wasm, so the object's own isolate never instantiates it. Needs
74
+ * `env.LOADER`, `env.ASSETS` and `ctx.facets`, and nothing of any host.
75
+ */
76
+ async function oxcFacet(ctx, env) {
77
+ const loader = Reflect.get(Object(env), 'LOADER');
78
+ if (!loader || typeof loader.get !== 'function')
79
+ throw new Error('Nimbus: env.LOADER unavailable for the transform facet');
80
+ const assets = Reflect.get(Object(env), 'ASSETS');
81
+ if (!assets || typeof assets.fetch !== 'function')
82
+ throw new Error('Nimbus: env.ASSETS unavailable for the transform facet');
83
+ const worker = await loader.get(OXC_FACET_WORKER_ID, async () => {
84
+ const assetsEnv = { ASSETS: assets };
85
+ const [wasm, runtime] = await Promise.all([fetchOxcWasmBytes(assetsEnv), fetchOxcFacetRuntime(assetsEnv)]);
86
+ return oxcFacetWorkerCode(wasm, runtime);
87
+ });
88
+ const facetClass = worker.getDurableObjectClass('OxcFacet');
89
+ return ctx.facets.get(OXC_FACET_WORKER_ID, async () => ({ class: facetClass }));
90
+ }
91
+ /**
92
+ * One stub per Durable Object: a caller that starts while another is still
93
+ * loading the facet waits on that load. A load or call that failed drops the
94
+ * entry; the next caller mints a fresh stub.
95
+ */
96
+ const sharedFacets = new WeakMap();
97
+ function sharedOxcFacet(ctx, env) {
98
+ const current = sharedFacets.get(ctx);
99
+ if (current)
100
+ return current;
101
+ const minted = oxcFacet(ctx, env);
102
+ sharedFacets.set(ctx, minted);
103
+ minted.catch(() => forgetOxcFacet(ctx, minted));
104
+ return minted;
105
+ }
106
+ function forgetOxcFacet(ctx, stub) {
107
+ if (sharedFacets.get(ctx) === stub)
108
+ sharedFacets.delete(ctx);
109
+ }
110
+ /** Modules one stack-fallback call carries; a batch with more makes more calls. */
111
+ const STACK_FALLBACK_MODULES = 4;
112
+ /** How long one stack-fallback call may take before its modules' answers are transient. */
113
+ const STACK_FALLBACK_DEADLINE_MS = 30_000;
114
+ /** `call`, or a rejection once `ms` pass first. */
115
+ async function withDeadline(call, ms) {
116
+ let timer = null;
117
+ const deadline = new Promise((_, reject) => {
118
+ timer = setTimeout(() => reject(new Error(`no answer within ${ms} ms`)), ms);
119
+ });
120
+ try {
121
+ return await Promise.race([call, deadline]);
122
+ }
123
+ finally {
124
+ clearTimeout(timer);
125
+ }
126
+ }
127
+ /** Calls per slice: a slice whose call failed is sent once more. */
128
+ const SLICE_ATTEMPTS = 2;
129
+ /**
130
+ * The transform host a Durable Object's transforms run on: its transform
131
+ * facet, a slice per call. Transforms are pure, so a slice whose call failed
132
+ * (the facet reset, the connection dropped) is sent once more, to a freshly
133
+ * minted stub; an overloaded facet is not asked again. A slice that still
134
+ * fails answers each of its requests with a transient error, which is no
135
+ * verdict on the source, and the other slices keep their answers.
136
+ *
137
+ * A module whose outcome says Oxc ran out of native stack on it
138
+ * (`stackExhausted`, set by the driver from the RangeError, never read off
139
+ * message text) goes to `stackFallback`, the esbuild facet in production:
140
+ * every such module, in calls of at most STACK_FALLBACK_MODULES, each with a
141
+ * deadline, each module logged. Its answer stands; the modules of a call that
142
+ * fails or misses its deadline answer transient. Without a fallback the
143
+ * exhaustion stands.
144
+ */
145
+ export function oxcTransformHost(ctx, env, stackFallback, { fallbackDeadlineMs = STACK_FALLBACK_DEADLINE_MS } = {}) {
146
+ return async (requests) => {
147
+ let facet = null;
148
+ const outcomes = [];
149
+ // The facet's worker is in flight for the whole batch, bracketed rather
150
+ // than wrapped (see beginLoaderFetch).
151
+ const endFetch = beginLoaderFetch(ctx, OXC_FACET_WORKER_ID);
152
+ try {
153
+ for (const slice of transformSlices(requests, (request) => request.code.length)) {
154
+ let answered = null;
155
+ let failure = null;
156
+ for (let attempt = 1; answered === null && attempt <= SLICE_ATTEMPTS; attempt++) {
157
+ try {
158
+ facet ??= sharedOxcFacet(ctx, env);
159
+ answered = await (await facet).transformMany(slice);
160
+ }
161
+ catch (error) {
162
+ // A stub that threw may be broken for good; the next call mints its own.
163
+ if (facet)
164
+ forgetOxcFacet(ctx, facet);
165
+ facet = null;
166
+ failure = error;
167
+ if (classifyDoCall(error) === 'overloaded')
168
+ break;
169
+ }
170
+ }
171
+ if (answered === null) {
172
+ const error = `transform facet unavailable: ${errorText(failure)}`;
173
+ answered = slice.map(() => ({ error, transient: true }));
174
+ }
175
+ for (const outcome of answered)
176
+ outcomes.push(outcome);
177
+ }
178
+ }
179
+ finally {
180
+ endFetch();
181
+ }
182
+ if (stackFallback) {
183
+ // Every module answered here: some callers (a prefetch bundle) have no
184
+ // store or pacer that would send a deferred one again.
185
+ const exhausted = outcomes.flatMap((outcome, index) => ('stackExhausted' in outcome && outcome.stackExhausted === true ? [index] : []));
186
+ for (let at = 0; at < exhausted.length; at += STACK_FALLBACK_MODULES) {
187
+ const group = exhausted.slice(at, at + STACK_FALLBACK_MODULES);
188
+ for (const index of group) {
189
+ const reason = 'error' in outcomes[index] ? outcomes[index].error.split('\n').at(-1) : '';
190
+ console.warn(`[oxc-transform] ${requests[index].options?.dynamicImportParent ?? '<unnamed module>'}: ${reason}; transforming it with esbuild`);
191
+ }
192
+ const answered = await withDeadline(stackFallback(group.map((index) => requests[index])), fallbackDeadlineMs).catch((error) => group.map(() => ({ error: `esbuild facet unavailable: ${errorText(error)}`, transient: true })));
193
+ group.forEach((index, i) => { outcomes[index] = answered[i]; });
194
+ }
195
+ }
196
+ return outcomes;
197
+ };
198
+ }
@@ -0,0 +1,23 @@
1
+ import type { PrebundleResult, PrebundleSpec } from '../npm/pre-bundle-facet.js';
2
+ /** What both pre-bundling pipelines call. */
3
+ export interface BundlePool {
4
+ prebundle(spec: PrebundleSpec): Promise<PrebundleResult>;
5
+ }
6
+ /** What a pre-bundling pipeline receives from its host. */
7
+ export interface BundlePoolProvider {
8
+ /** The session's pool, its facet loaded. */
9
+ acquire(): Promise<BundlePool>;
10
+ }
11
+ export declare class PrebundlePool implements BundlePoolProvider {
12
+ private readonly env;
13
+ private readonly ctx;
14
+ private readonly pool;
15
+ /** Pre-bundles waiting for a slot, oldest first; a finishing one hands its slot to the next. */
16
+ private readonly waiting;
17
+ private running;
18
+ constructor(env: unknown, ctx: DurableObjectState);
19
+ acquire(): Promise<BundlePool>;
20
+ /** The build facet is the Durable Object's, not the pool's: nothing to release. */
21
+ dispose(): void;
22
+ }
23
+ //# sourceMappingURL=prebundle-pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prebundle-pool.d.ts","sourceRoot":"","sources":["../../src/facets/prebundle-pool.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAGjF,6CAA6C;AAC7C,MAAM,WAAW,UAAU;IACzB,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC1D;AAED,2DAA2D;AAC3D,MAAM,WAAW,kBAAkB;IACjC,4CAA4C;IAC5C,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;CAChC;AAED,qBAAa,aAAc,YAAW,kBAAkB;IAOpD,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAPtB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,gGAAgG;IAChG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,OAAO,CAAK;gBAGD,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,kBAAkB;IAkBpC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC;IAKpC,mFAAmF;IACnF,OAAO,IAAI,IAAI;CAChB"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * PrebundlePool — where a session's pre-bundles run.
3
+ *
4
+ * Install-time pre-bundling (npm/installer.ts) and the Vite dev server's
5
+ * on-demand /@modules/ bundles send each npm specifier, with the slice of
6
+ * package files it needs (npm/pre-bundle-facet.ts), to the session's build
7
+ * facet (facets/build-facet.ts `prebundle`): rolldown over the staged
8
+ * binding, whose runtime the facet's module map loads, so no pre-bundle
9
+ * dispatches any source. One at a time (PRE_BUNDLE_CONCURRENCY), as the
10
+ * isolate pool that ran esbuild did: each holds up to a slice cap of files,
11
+ * and the facet's binding never gives back what a bundle grew it to.
12
+ *
13
+ * `acquire()` loads the facet before resolving, so its staged parts are
14
+ * fetched, verified and handed to the loader before a caller builds and
15
+ * holds a slice.
16
+ */
17
+ import { PRE_BUNDLE_CONCURRENCY } from '@nimbus-sh/platform/limits.js';
18
+ import { buildFacetPrebundler, loadBuildFacet } from './build-facet.js';
19
+ export class PrebundlePool {
20
+ env;
21
+ ctx;
22
+ pool;
23
+ /** Pre-bundles waiting for a slot, oldest first; a finishing one hands its slot to the next. */
24
+ waiting = [];
25
+ running = 0;
26
+ constructor(env, ctx) {
27
+ this.env = env;
28
+ this.ctx = ctx;
29
+ const prebundle = buildFacetPrebundler(ctx, env);
30
+ this.pool = {
31
+ prebundle: async (spec) => {
32
+ if (this.running < PRE_BUNDLE_CONCURRENCY)
33
+ this.running++;
34
+ else
35
+ await new Promise((resolve) => this.waiting.push(resolve));
36
+ try {
37
+ return await prebundle(spec);
38
+ }
39
+ finally {
40
+ const next = this.waiting.shift();
41
+ if (next)
42
+ next();
43
+ else
44
+ this.running--;
45
+ }
46
+ },
47
+ };
48
+ }
49
+ async acquire() {
50
+ await loadBuildFacet(this.ctx, this.env);
51
+ return this.pool;
52
+ }
53
+ /** The build facet is the Durable Object's, not the pool's: nothing to release. */
54
+ dispose() { }
55
+ }
@@ -71,10 +71,8 @@ interface ChildEntry {
71
71
  stdinChunks: Uint8Array[];
72
72
  stdinClosed: boolean;
73
73
  stdinTotalBytes: number;
74
- stdinWaiters: Array<(r: {
75
- data: Uint8Array;
76
- ended: boolean;
77
- }) => void>;
74
+ /** Woken when stdin gains a chunk, closes, or the child exits; each takes from `stdinChunks` itself. */
75
+ stdinWaiters: Array<() => void>;
78
76
  outputs: {
79
77
  1: OutputChunk[];
80
78
  2: OutputChunk[];
@@ -160,13 +158,20 @@ export interface FacetManagerLike {
160
158
  }, hooks: OutputHooks): Promise<number>;
161
159
  abort?(facetName: string, signal?: string): boolean;
162
160
  }
161
+ /** Where a child runs from: its pid (whose credential it has), directory and environment. */
162
+ export interface ChildOrigin {
163
+ readonly pid: number;
164
+ readonly cwd: string;
165
+ readonly env: Record<string, string>;
166
+ }
163
167
  /**
164
168
  * The minimum shape we need from the command registry.
165
169
  */
166
170
  export interface CommandRegistryLike {
167
- resolve(name: string): {
171
+ /** How `name` runs as the child `from` describes; null while nothing can run it. */
172
+ resolve(name: string, from: ChildOrigin): Promise<{
168
173
  kind: CommandKind;
169
- } | null;
174
+ } | null>;
170
175
  runPureBuiltin(pid: number, name: string, args: string[], env: Record<string, string>, cwd: string, stdin: string, hooks: OutputHooks): Promise<number>;
171
176
  }
172
177
  export interface ShellExecutorLike {
@@ -251,6 +256,8 @@ export declare class FacetProcessManager {
251
256
  ok: boolean;
252
257
  };
253
258
  stdinEnd(childPid: number): void;
259
+ /** The child's next stdin packet: a queued chunk, else the end once stdin closed or the child exited; null while neither. */
260
+ private _takeStdin;
254
261
  /**
255
262
  * Long-poll: child facet asks the supervisor for its next stdin chunk.
256
263
  * Returns immediately if data is already queued OR if stdin is closed.
@@ -1 +1 @@
1
- {"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/facets/process.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAIH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uDAAuD,CAAC;AACtG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAG5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAE3E;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,UAAU,WAAW;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;;GAIG;AACH,UAAU,UAAU;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,OA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MAAM,GAAE,MAAoB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IAwBtI,mEAAmE;IACnE,IAAI,CAAC,QAAQ,SAAS,GAAG,MAAM;IAY/B,IAAI,KAAK;;;;;MAQR;IAED,qCAAqC;IACrC,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;CAGpD"}
@@ -197,17 +197,20 @@ export class FacetProcessManager {
197
197
  const dispatchReq = shellPlan
198
198
  ? req
199
199
  : { ...req, command: normalizedCommand };
200
- // Resolve command kind. Resolution failure → exit 127 (command not
201
- // found), no facet at all. Same shell semantics.
202
- const reg = shellPlan ? { kind: 'shell-direct' } : this.deps.commandRegistry.resolve(normalizedCommand);
203
- const kind = reg ? reg.kind : 'unknown';
204
- // Dispatch after the cpSpawn RPC has had a chance to return to the
205
- // parent facet. That lets immediate child.stdin.write(); child.stdin.end()
206
- // calls land in the stdin queue before a preseeded child runtime starts.
200
+ // Classify and dispatch after the cpSpawn RPC has had a chance to return
201
+ // to the parent facet. That lets immediate child.stdin.write();
202
+ // child.stdin.end() calls land in the stdin queue before a preseeded
203
+ // child runtime starts. Nothing found to run is exit 127 (command not
204
+ // found), no facet at all, as in the shell.
207
205
  setTimeout(() => {
208
- void this._dispatch(child, kind, dispatchReq).catch((e) => {
209
- // Last-resort: if both runners somehow throw, exit 1 with the error
210
- // on stderr.
206
+ void (async () => {
207
+ const reg = shellPlan
208
+ ? { kind: 'shell-direct' }
209
+ : await this.deps.commandRegistry.resolve(normalizedCommand, { pid, cwd: req.cwd, env: childEnv });
210
+ await this._dispatch(child, reg ? reg.kind : 'unknown', dispatchReq);
211
+ })().catch((e) => {
212
+ // Last resort: a classification or both runners threw (a registered
213
+ // command's module that fails to load). Exit 1 with the error on stderr.
211
214
  this._appendText(child, 2, `Error: ${e?.message || String(e)}\n`);
212
215
  this._stampExit(child, 1, null);
213
216
  });
@@ -519,10 +522,8 @@ export class FacetProcessManager {
519
522
  }
520
523
  child.stdinChunks.push(data);
521
524
  child.stdinTotalBytes += data.byteLength;
522
- // Flush any waiters
523
- for (const w of child.stdinWaiters.splice(0)) {
524
- w({ data, ended: false });
525
- }
525
+ for (const w of child.stdinWaiters.splice(0))
526
+ w();
526
527
  return { ok: true };
527
528
  }
528
529
  stdinEnd(childPid) {
@@ -530,9 +531,19 @@ export class FacetProcessManager {
530
531
  if (!child)
531
532
  return;
532
533
  child.stdinClosed = true;
533
- for (const w of child.stdinWaiters.splice(0)) {
534
- w({ data: EMPTY_BYTES, ended: true });
534
+ for (const w of child.stdinWaiters.splice(0))
535
+ w();
536
+ }
537
+ /** The child's next stdin packet: a queued chunk, else the end once stdin closed or the child exited; null while neither. */
538
+ _takeStdin(child) {
539
+ const data = child.stdinChunks.shift();
540
+ if (data !== undefined) {
541
+ child.stdinTotalBytes -= data.byteLength;
542
+ return { data, ended: false };
535
543
  }
544
+ if (child.stdinClosed || child.exitCode !== null)
545
+ return { data: EMPTY_BYTES, ended: true };
546
+ return null;
536
547
  }
537
548
  /**
538
549
  * Long-poll: child facet asks the supervisor for its next stdin chunk.
@@ -542,14 +553,11 @@ export class FacetProcessManager {
542
553
  const child = this.children.get(childPid);
543
554
  if (!child)
544
555
  return { data: EMPTY_BYTES, ended: true };
545
- if (child.stdinChunks.length > 0) {
546
- const data = child.stdinChunks.shift();
547
- child.stdinTotalBytes -= data.byteLength;
548
- return { data, ended: false };
549
- }
550
- if (child.stdinClosed)
551
- return { data: EMPTY_BYTES, ended: true };
552
- // Long-poll
556
+ const ready = this._takeStdin(child);
557
+ if (ready)
558
+ return ready;
559
+ // Long-poll. The chunk that wakes this reader stays queued until taken
560
+ // here, so no other reader is handed it too.
553
561
  return new Promise((resolve) => {
554
562
  const timer = setTimeout(() => {
555
563
  const idx = child.stdinWaiters.indexOf(wrapped);
@@ -557,9 +565,9 @@ export class FacetProcessManager {
557
565
  child.stdinWaiters.splice(idx, 1);
558
566
  resolve({ data: EMPTY_BYTES, ended: false });
559
567
  }, Math.min(waitMs, 5000));
560
- const wrapped = (r) => {
568
+ const wrapped = () => {
561
569
  clearTimeout(timer);
562
- resolve(r);
570
+ resolve(this._takeStdin(child) ?? { data: EMPTY_BYTES, ended: false });
563
571
  };
564
572
  child.stdinWaiters.push(wrapped);
565
573
  });
@@ -746,11 +754,9 @@ export class FacetProcessManager {
746
754
  const fresh = child.outputs[w.fd].filter((c) => c.seq > w.sinceSeq);
747
755
  w.resolve({ chunks: fresh, closed: true, maxSeq: child.outputSeq[w.fd] });
748
756
  }
749
- // Wake stdin waiters with ended=true so a child blocked on cpReadStdin
750
- // unblocks and exits cleanly.
751
- for (const w of child.stdinWaiters.splice(0)) {
752
- w({ data: EMPTY_BYTES, ended: true });
753
- }
757
+ // A child blocked on cpReadStdin is told stdin ended, and exits cleanly.
758
+ for (const w of child.stdinWaiters.splice(0))
759
+ w();
754
760
  }
755
761
  /**
756
762
  * Late-arriving reportExit from the facet. Idempotent; if kill() or
@@ -14,8 +14,8 @@
14
14
  * a function of: the pipeline's code (TRANSFORM_PIPELINE_ID, which core's
15
15
  * build pins from the bundled closure of bundle-cell-transform.ts and
16
16
  * EsbuildService and ships with that code), the transform host's code (the
17
- * store is bound to one host — for the session, its esbuild facet, whose id
18
- * carries the esbuild version, the facet body and the staged CLI runner),
17
+ * store is bound to one host — for the session, its transform facet and the
18
+ * esbuild facet that answers what is too deep for it: TRANSFORM_HOST_ID),
19
19
  * what is transformed (a module cell or an entry script), where it is staged
20
20
  * (its path or URL: the loader, format, TypeScript-ness and import.meta all
21
21
  * follow from it), and the source. The old in-heap key was a 32-bit hash of
@@ -98,8 +98,8 @@ export declare class TransformStore implements BundleCellResultStore {
98
98
  private opened;
99
99
  /**
100
100
  * @param host The identity of the transform host whose results this store
101
- * holds: EsbuildService.transformHostId, for the session its esbuild
102
- * facet's ESBUILD_FACET_WORKER_ID.
101
+ * holds: EsbuildService.transformHostId, for the session
102
+ * esbuild-transform.ts's TRANSFORM_HOST_ID (both engines' code).
103
103
  * @param ledger The session's storage ledger, which admits every write.
104
104
  */
105
105
  constructor(sql: SqlDatabase, transactions: SqlTransactions, ledger: TransformStoreLedger, host: string, options?: TransformStoreOptions);
@@ -14,8 +14,8 @@
14
14
  * a function of: the pipeline's code (TRANSFORM_PIPELINE_ID, which core's
15
15
  * build pins from the bundled closure of bundle-cell-transform.ts and
16
16
  * EsbuildService and ships with that code), the transform host's code (the
17
- * store is bound to one host — for the session, its esbuild facet, whose id
18
- * carries the esbuild version, the facet body and the staged CLI runner),
17
+ * store is bound to one host — for the session, its transform facet and the
18
+ * esbuild facet that answers what is too deep for it: TRANSFORM_HOST_ID),
19
19
  * what is transformed (a module cell or an entry script), where it is staged
20
20
  * (its path or URL: the loader, format, TypeScript-ness and import.meta all
21
21
  * follow from it), and the source. The old in-heap key was a 32-bit hash of
@@ -157,8 +157,8 @@ export class TransformStore {
157
157
  opened = false;
158
158
  /**
159
159
  * @param host The identity of the transform host whose results this store
160
- * holds: EsbuildService.transformHostId, for the session its esbuild
161
- * facet's ESBUILD_FACET_WORKER_ID.
160
+ * holds: EsbuildService.transformHostId, for the session
161
+ * esbuild-transform.ts's TRANSFORM_HOST_ID (both engines' code).
162
162
  * @param ledger The session's storage ledger, which admits every write.
163
163
  */
164
164
  constructor(sql, transactions, ledger, host, options = {}) {