@nimbus-sh/worker 0.9.0 → 0.11.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 (286) hide show
  1. package/NOTICE.md +5 -0
  2. package/README.md +10 -0
  3. package/dist/_shared/session-router.d.ts +7 -0
  4. package/dist/_shared/session-router.d.ts.map +1 -1
  5. package/dist/_shared/session-router.js +7 -0
  6. package/dist/bindings/body.d.ts +6 -0
  7. package/dist/bindings/body.d.ts.map +1 -0
  8. package/dist/bindings/body.js +37 -0
  9. package/dist/bindings/kv.d.ts +0 -2
  10. package/dist/bindings/kv.d.ts.map +1 -1
  11. package/dist/bindings/kv.js +3 -42
  12. package/dist/bindings/r2.d.ts +0 -2
  13. package/dist/bindings/r2.d.ts.map +1 -1
  14. package/dist/bindings/r2.js +4 -44
  15. package/dist/esbuild-cli-artifact.generated.d.ts +18 -0
  16. package/dist/esbuild-cli-artifact.generated.d.ts.map +1 -0
  17. package/dist/esbuild-cli-artifact.generated.js +17 -0
  18. package/dist/esbuild-wasm-bundle.generated.d.ts +24 -24
  19. package/dist/esbuild-wasm-bundle.generated.d.ts.map +1 -1
  20. package/dist/esbuild-wasm-bundle.generated.js +24 -24
  21. package/dist/facets/cirrus-real.d.ts.map +1 -1
  22. package/dist/facets/cirrus-real.js +11 -6
  23. package/dist/facets/compose.d.ts +11 -7
  24. package/dist/facets/compose.d.ts.map +1 -1
  25. package/dist/facets/compose.js +8 -31
  26. package/dist/facets/data-plan.d.ts +79 -0
  27. package/dist/facets/data-plan.d.ts.map +1 -0
  28. package/dist/facets/data-plan.js +477 -0
  29. package/dist/facets/esbuild-bundle-pool.d.ts +1 -1
  30. package/dist/facets/esbuild-bundle-pool.js +3 -3
  31. package/dist/facets/esbuild-transform.d.ts +38 -8
  32. package/dist/facets/esbuild-transform.d.ts.map +1 -1
  33. package/dist/facets/esbuild-transform.js +219 -19
  34. package/dist/facets/exec-telemetry.d.ts +7 -3
  35. package/dist/facets/exec-telemetry.d.ts.map +1 -1
  36. package/dist/facets/manager.d.ts +198 -69
  37. package/dist/facets/manager.d.ts.map +1 -1
  38. package/dist/facets/manager.js +1276 -652
  39. package/dist/facets/opencode-staging.d.ts +0 -2
  40. package/dist/facets/opencode-staging.d.ts.map +1 -1
  41. package/dist/facets/opencode-staging.js +5 -11
  42. package/dist/facets/process.d.ts +4 -0
  43. package/dist/facets/process.d.ts.map +1 -1
  44. package/dist/facets/process.js +3 -0
  45. package/dist/facets/read-profile.d.ts +149 -0
  46. package/dist/facets/read-profile.d.ts.map +1 -0
  47. package/dist/facets/read-profile.js +483 -0
  48. package/dist/facets/real-vite-hmr.d.ts +2 -0
  49. package/dist/facets/real-vite-hmr.d.ts.map +1 -1
  50. package/dist/facets/real-vite-hmr.js +3 -2
  51. package/dist/facets/resident-identity.d.ts +0 -1
  52. package/dist/facets/resident-identity.d.ts.map +1 -1
  53. package/dist/facets/resident-identity.js +0 -3
  54. package/dist/facets/wasm-swap-registry.d.ts +34 -25
  55. package/dist/facets/wasm-swap-registry.d.ts.map +1 -1
  56. package/dist/facets/wasm-swap-registry.js +62 -56
  57. package/dist/facets/ws-terminal.d.ts +4 -4
  58. package/dist/facets/ws-terminal.d.ts.map +1 -1
  59. package/dist/facets/ws-terminal.js +4 -5
  60. package/dist/git/commands.d.ts +33 -10
  61. package/dist/git/commands.d.ts.map +1 -1
  62. package/dist/git/commands.js +1891 -197
  63. package/dist/git/network-facet.d.ts +12 -2
  64. package/dist/git/network-facet.d.ts.map +1 -1
  65. package/dist/git/network-facet.js +69 -18
  66. package/dist/git/unified-diff.d.ts +74 -0
  67. package/dist/git/unified-diff.d.ts.map +1 -0
  68. package/dist/git/unified-diff.js +676 -0
  69. package/dist/git-bundle.generated.d.ts +7 -11
  70. package/dist/git-bundle.generated.d.ts.map +1 -1
  71. package/dist/git-bundle.generated.js +7 -11
  72. package/dist/hosted/commands.d.ts.map +1 -1
  73. package/dist/hosted/commands.js +64 -245
  74. package/dist/hosted/runtime.d.ts +22 -15
  75. package/dist/hosted/runtime.d.ts.map +1 -1
  76. package/dist/hosted/runtime.js +72 -14
  77. package/dist/hosted/services.d.ts +8 -1
  78. package/dist/hosted/services.d.ts.map +1 -1
  79. package/dist/hosted/services.js +12 -13
  80. package/dist/hosted/session.d.ts +165 -0
  81. package/dist/hosted/session.d.ts.map +1 -0
  82. package/dist/hosted/session.js +132 -0
  83. package/dist/loaders/generated-workers.d.ts +6 -3
  84. package/dist/loaders/generated-workers.d.ts.map +1 -1
  85. package/dist/loaders/generated-workers.js +8 -5
  86. package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -1
  87. package/dist/loaders/npm-resolve-preamble.js +0 -27
  88. package/dist/loaders/pre-bundle-preamble.d.ts +6 -3
  89. package/dist/loaders/pre-bundle-preamble.d.ts.map +1 -1
  90. package/dist/loaders/pre-bundle-preamble.js +13 -8
  91. package/dist/node-shims-artifact.generated.d.ts +13 -4
  92. package/dist/node-shims-artifact.generated.d.ts.map +1 -1
  93. package/dist/node-shims-artifact.generated.js +16 -7
  94. package/dist/npm/bin-links.d.ts +3 -1
  95. package/dist/npm/bin-links.d.ts.map +1 -1
  96. package/dist/npm/bin-links.js +32 -8
  97. package/dist/npm/cache.d.ts +11 -1
  98. package/dist/npm/cache.d.ts.map +1 -1
  99. package/dist/npm/cache.js +21 -7
  100. package/dist/npm/install-batch-facet.d.ts +4 -2
  101. package/dist/npm/install-batch-facet.d.ts.map +1 -1
  102. package/dist/npm/install-batch-facet.js +32 -18
  103. package/dist/npm/installer.d.ts +23 -3
  104. package/dist/npm/installer.d.ts.map +1 -1
  105. package/dist/npm/installer.js +330 -131
  106. package/dist/npm/npx-install.d.ts +3 -1
  107. package/dist/npm/npx-install.d.ts.map +1 -1
  108. package/dist/npm/npx-install.js +4 -1
  109. package/dist/npm/package-lock.d.ts +32 -0
  110. package/dist/npm/package-lock.d.ts.map +1 -0
  111. package/dist/npm/package-lock.js +65 -0
  112. package/dist/npm/placement.d.ts +16 -0
  113. package/dist/npm/placement.d.ts.map +1 -0
  114. package/dist/npm/placement.js +33 -0
  115. package/dist/npm/pre-bundle-facet.d.ts +1 -30
  116. package/dist/npm/pre-bundle-facet.d.ts.map +1 -1
  117. package/dist/npm/pre-bundle-facet.js +3 -5
  118. package/dist/npm/r2-cache.d.ts +12 -6
  119. package/dist/npm/r2-cache.d.ts.map +1 -1
  120. package/dist/npm/r2-cache.js +34 -16
  121. package/dist/npm/resolve-one-facet.d.ts +3 -0
  122. package/dist/npm/resolve-one-facet.d.ts.map +1 -1
  123. package/dist/npm/resolve-one-facet.js +15 -3
  124. package/dist/npm/resolver.d.ts +11 -13
  125. package/dist/npm/resolver.d.ts.map +1 -1
  126. package/dist/npm/resolver.js +12 -25
  127. package/dist/opencode-artifact.generated.js +2 -2
  128. package/dist/replica/routing.d.ts +2 -38
  129. package/dist/replica/routing.d.ts.map +1 -1
  130. package/dist/replica/routing.js +3 -55
  131. package/dist/router/index.d.ts.map +1 -1
  132. package/dist/router/index.js +15 -2
  133. package/dist/router/public-directory.d.ts +18 -0
  134. package/dist/router/public-directory.d.ts.map +1 -1
  135. package/dist/router/public-directory.js +1 -1
  136. package/dist/router/remote-api.d.ts +3 -1
  137. package/dist/router/remote-api.d.ts.map +1 -1
  138. package/dist/router/remote-api.js +42 -79
  139. package/dist/runtime/bash-repl.js +2 -2
  140. package/dist/runtime/bun-repl.d.ts.map +1 -1
  141. package/dist/runtime/bun-repl.js +2 -13
  142. package/dist/runtime/cpython-resident.d.ts.map +1 -1
  143. package/dist/runtime/cpython-resident.js +2 -10
  144. package/dist/runtime/esbuild-wasm-bytes.d.ts +37 -18
  145. package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -1
  146. package/dist/runtime/esbuild-wasm-bytes.js +66 -92
  147. package/dist/runtime/facet-loader-host.d.ts.map +1 -1
  148. package/dist/runtime/facet-loader-host.js +0 -7
  149. package/dist/runtime/git-bundle-artifact.d.ts +17 -0
  150. package/dist/runtime/git-bundle-artifact.d.ts.map +1 -0
  151. package/dist/runtime/git-bundle-artifact.js +25 -0
  152. package/dist/runtime/node-repl.d.ts.map +1 -1
  153. package/dist/runtime/node-repl.js +2 -13
  154. package/dist/runtime/node-shims-artifact.d.ts +22 -23
  155. package/dist/runtime/node-shims-artifact.d.ts.map +1 -1
  156. package/dist/runtime/node-shims-artifact.js +48 -78
  157. package/dist/runtime/node-shims.d.ts.map +1 -1
  158. package/dist/runtime/node-shims.js +2358 -996
  159. package/dist/runtime/opencode-artifact.d.ts.map +1 -1
  160. package/dist/runtime/opencode-artifact.js +17 -53
  161. package/dist/runtime/opencode-facet-runner.d.ts +3 -6
  162. package/dist/runtime/opencode-facet-runner.d.ts.map +1 -1
  163. package/dist/runtime/opencode-facet-runner.js +45 -10
  164. package/dist/runtime/opentui-wasm-bytes.d.ts.map +1 -1
  165. package/dist/runtime/opentui-wasm-bytes.js +16 -49
  166. package/dist/runtime/package-manager.d.ts +0 -2
  167. package/dist/runtime/package-manager.d.ts.map +1 -1
  168. package/dist/runtime/package-manager.js +0 -3
  169. package/dist/runtime/python-repl.d.ts.map +1 -1
  170. package/dist/runtime/python-repl.js +4 -35
  171. package/dist/runtime/repl-session.d.ts +10 -0
  172. package/dist/runtime/repl-session.d.ts.map +1 -1
  173. package/dist/runtime/repl-session.js +7 -0
  174. package/dist/runtime/ruby-repl.d.ts.map +1 -1
  175. package/dist/runtime/ruby-repl.js +2 -2
  176. package/dist/runtime/ruby-resident.d.ts.map +1 -1
  177. package/dist/runtime/ruby-resident.js +41 -51
  178. package/dist/runtime/runtime-catalog.d.ts +10 -3
  179. package/dist/runtime/runtime-catalog.d.ts.map +1 -1
  180. package/dist/runtime/runtime-catalog.js +125 -15
  181. package/dist/runtime/sqlite-wasm-bytes.d.ts +4 -4
  182. package/dist/runtime/sqlite-wasm-bytes.d.ts.map +1 -1
  183. package/dist/runtime/sqlite-wasm-bytes.js +21 -57
  184. package/dist/runtime/staged-source.d.ts +67 -0
  185. package/dist/runtime/staged-source.d.ts.map +1 -0
  186. package/dist/runtime/staged-source.js +113 -0
  187. package/dist/runtime/wasi/preamble.d.ts +0 -22
  188. package/dist/runtime/wasi/preamble.d.ts.map +1 -1
  189. package/dist/runtime/wasi/preamble.js +98 -1425
  190. package/dist/runtime-catalog.generated.js +1 -1
  191. package/dist/session/agent.d.ts +14 -2
  192. package/dist/session/agent.d.ts.map +1 -1
  193. package/dist/session/agent.js +57 -19
  194. package/dist/session/ai.d.ts +0 -11
  195. package/dist/session/ai.d.ts.map +1 -1
  196. package/dist/session/ai.js +0 -4
  197. package/dist/session/fs-watch.d.ts +0 -11
  198. package/dist/session/fs-watch.d.ts.map +1 -1
  199. package/dist/session/fs-watch.js +0 -21
  200. package/dist/session/hibernation.d.ts +68 -2
  201. package/dist/session/hibernation.d.ts.map +1 -1
  202. package/dist/session/hibernation.js +95 -1
  203. package/dist/session/init-phases.d.ts +1 -2
  204. package/dist/session/init-phases.d.ts.map +1 -1
  205. package/dist/session/init-phases.js +1 -2
  206. package/dist/session/init.d.ts.map +1 -1
  207. package/dist/session/init.js +7 -20
  208. package/dist/session/keys.d.ts +0 -3
  209. package/dist/session/keys.d.ts.map +1 -1
  210. package/dist/session/keys.js +0 -3
  211. package/dist/session/legacy-reset.d.ts +11 -0
  212. package/dist/session/legacy-reset.d.ts.map +1 -0
  213. package/dist/session/legacy-reset.js +16 -0
  214. package/dist/session/nimbus-session.d.ts +50 -16
  215. package/dist/session/nimbus-session.d.ts.map +1 -1
  216. package/dist/session/nimbus-session.js +77 -71
  217. package/dist/session/npm-install-port.d.ts.map +1 -1
  218. package/dist/session/npm-install-port.js +2 -0
  219. package/dist/session/programmatic.d.ts +13 -18
  220. package/dist/session/programmatic.d.ts.map +1 -1
  221. package/dist/session/programmatic.js +53 -39
  222. package/dist/session/replica-routes.d.ts +2 -3
  223. package/dist/session/replica-routes.d.ts.map +1 -1
  224. package/dist/session/replica-routes.js +3 -10
  225. package/dist/session/routes.d.ts.map +1 -1
  226. package/dist/session/routes.js +11 -12
  227. package/dist/session/rpc.d.ts +108 -21
  228. package/dist/session/rpc.d.ts.map +1 -1
  229. package/dist/session/rpc.js +194 -39
  230. package/dist/session/start-real-vite.js +2 -2
  231. package/dist/session/state-store.d.ts +1 -17
  232. package/dist/session/state-store.d.ts.map +1 -1
  233. package/dist/session/state-store.js +3 -53
  234. package/dist/session/supervisor-op.d.ts +7 -0
  235. package/dist/session/supervisor-op.d.ts.map +1 -1
  236. package/dist/session/supervisor-op.js +6 -1
  237. package/dist/session/supervisor-rpc.d.ts +116 -19
  238. package/dist/session/supervisor-rpc.d.ts.map +1 -1
  239. package/dist/session/supervisor-rpc.js +194 -84
  240. package/dist/session/vite-command.d.ts.map +1 -1
  241. package/dist/session/vite-command.js +17 -14
  242. package/dist/session/ws.d.ts.map +1 -1
  243. package/dist/session/ws.js +20 -8
  244. package/dist/shell/npm-bin-entrypoints.d.ts.map +1 -1
  245. package/dist/shell/npm-bin-entrypoints.js +30 -5
  246. package/dist/vfs/facet-resident-limits.d.ts +33 -0
  247. package/dist/vfs/facet-resident-limits.d.ts.map +1 -0
  248. package/dist/vfs/facet-resident-limits.js +33 -0
  249. package/dist/vfs/facet-resident-store.d.ts +2 -10
  250. package/dist/vfs/facet-resident-store.d.ts.map +1 -1
  251. package/dist/vfs/facet-resident-store.js +1594 -219
  252. package/dist/workspace-host.d.ts +3 -1
  253. package/dist/workspace-host.d.ts.map +1 -1
  254. package/dist/workspace-host.js +2 -0
  255. package/dist/wrangler/nimbus-wrangler.d.ts +0 -2
  256. package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -1
  257. package/dist/wrangler/nimbus-wrangler.js +8 -22
  258. package/package.json +34 -7
  259. package/public/_assets/esbuild-0.24.2.js +2380 -0
  260. package/public/_assets/opencode/1.16.2/index-attach.js +2 -2
  261. package/public/_assets/runtime/esbuild-cli-c4fda380d52befc1.js +6892 -0
  262. package/public/_assets/runtime/git-de3e60c9f3ff006a.js +103 -0
  263. package/public/_assets/runtime/{node-shims-acaa037e6d26ec0d.js → node-shims-06565b121555c194.js} +2879 -992
  264. package/public/_assets/runtime/resident-store-6ffb1939c53d982f.js +2264 -0
  265. package/public/_assets/runtime/vfs-write-ledger-e501e8fc793bc2c1.js +889 -0
  266. package/scripts/build-opencode-attach-entry.mjs +51 -1
  267. package/scripts/bundle-esbuild-wasm.mjs +55 -39
  268. package/scripts/bundle-facet-workers.mjs +159 -10
  269. package/scripts/bundle-git.mjs +88 -27
  270. package/scripts/bundle-node-shims.mjs +72 -46
  271. package/scripts/bundle-runtime.mjs +18 -421
  272. package/scripts/cf-git-patch.mjs +137 -0
  273. package/scripts/patch-install-deps.mjs +49 -96
  274. package/scripts/runtime-specs.mjs +435 -0
  275. package/vendor/git-http.generated.d.ts +82 -0
  276. package/vendor/git-upstream.generated.d.ts +4378 -0
  277. package/vendor/git.LICENSE +7 -0
  278. package/vendor/git.generated.d.mts +21 -0
  279. package/vendor/git.generated.mjs +103 -0
  280. package/dist/replica/suspension.d.ts +0 -36
  281. package/dist/replica/suspension.d.ts.map +0 -1
  282. package/dist/replica/suspension.js +0 -49
  283. package/dist/runtime/static-server.d.ts +0 -3
  284. package/dist/runtime/static-server.d.ts.map +0 -1
  285. package/dist/runtime/static-server.js +0 -133
  286. package/scripts/clean-dist.mjs +0 -7
@@ -1,27 +1,85 @@
1
1
  import { CF_COMPAT_DATE } from '@nimbus-sh/core/constants.js';
2
- import { BUNDLER_VERSION, generateEsbuildTransformRuntimeSource, } from '@nimbus-sh/core/runtime/esbuild-service.js';
2
+ import { EsbuildService, generateEsbuildFacetRuntimeSource, } from '@nimbus-sh/core/runtime/esbuild-service.js';
3
3
  import { ESBUILD_NAME_GLOBAL_SHIM } from '@nimbus-sh/core/_shared/esbuild-facet-shim.js';
4
- import { ESBUILD_WASM_JS_FN_BODY, ESBUILD_WASM_VERSION, } from '../esbuild-wasm-bundle.generated.js';
5
- export const ESBUILD_TRANSFORM_WORKER_ID = `nimbus-esbuild-transform:${ESBUILD_WASM_VERSION}:${BUNDLER_VERSION}`;
6
- /** Slim Worker Loader module whose DO class owns the esbuild wasm heap. */
7
- export function esbuildTransformWorkerCode(wasmBytes) {
4
+ import { errorText } from '@nimbus-sh/core/_shared/error-text.js';
5
+ import { supervisorEntrypoint } from '@nimbus-sh/fabric/composition.js';
6
+ import { supervisorBindingProps } from '@nimbus-sh/fabric/supervisor-props.js';
7
+ import { hashSource } from '@nimbus-sh/fabric/vendor/serialize.js';
8
+ import { classifyDoCall } from '@nimbus-sh/platform/oom-classify.js';
9
+ import { ESBUILD_WASM_VERSION } from '../esbuild-wasm-bundle.generated.js';
10
+ import { ESBUILD_CLI_BUILD_ID } from '../esbuild-cli-artifact.generated.js';
11
+ import { fetchEsbuildCliRunner, fetchEsbuildJsFnBody, fetchEsbuildWasmBytes } from '../runtime/esbuild-wasm-bytes.js';
12
+ /**
13
+ * Everything of the facet's module but its staged parts: esbuild's JS adapter,
14
+ * which the wasm version keys, and the `esbuild` command's runner, which its
15
+ * build id keys. `wasmModule`, `newEsbuild` and `esbuild` are bound by the
16
+ * lines before it, and the runner installs `globalThis.__esbuildCliRun` and
17
+ * the dynamic-import rewrite transforms run after esbuild,
18
+ * `globalThis.__nimbusRewriteDynamicImports`.
19
+ *
20
+ * Transforms share one esbuild, whose heap only grows. A build or an
21
+ * `esbuild` command gets its own Go instance, dropped when it ends, so what
22
+ * it grew goes with it.
23
+ */
24
+ const ESBUILD_FACET_BODY = [
25
+ ESBUILD_NAME_GLOBAL_SHIM,
26
+ generateEsbuildFacetRuntimeSource(),
27
+ 'let initialized;',
28
+ // One initialization per facet, shared by every transform. A failed one is
29
+ // forgotten, as esbuild forgets it, so the next call retries.
30
+ 'function ensureInitialized() {',
31
+ ' initialized ||= esbuild.initialize({ wasmModule, worker: false }).catch((e) => {',
32
+ ' initialized = undefined;',
33
+ ' throw e;',
34
+ ' });',
35
+ ' return initialized;',
36
+ '}',
37
+ 'export class EsbuildFacet extends DurableObject {',
38
+ ' async transformMany(requests) {',
39
+ ' if (requests.some(({ options }) => !options?.rewriteOnly)) await ensureInitialized();',
40
+ ' const outcomes = [];',
41
+ ' for (const { code, options } of requests) {',
42
+ ' try {',
43
+ ' outcomes.push(await runTransformRequest(esbuild, code, options, globalThis.__nimbusRewriteDynamicImports));',
44
+ ' } catch (e) {',
45
+ ' outcomes.push({ error: String((e && e.message) || e) });',
46
+ ' }',
47
+ ' }',
48
+ ' return outcomes;',
49
+ ' }',
50
+ ' async build(options, plugin) {',
51
+ ' const own = newEsbuild();',
52
+ ' await own.initialize({ wasmModule, worker: false });',
53
+ ' try {',
54
+ ' return await buildWithEsbuild(own, options, plugin);',
55
+ ' } finally {',
56
+ ' await own.stop();',
57
+ ' }',
58
+ ' }',
59
+ ' async cli(args, supervisor, output) {',
60
+ ' return globalThis.__esbuildCliRun(args, supervisor, output, wasmModule);',
61
+ ' }',
62
+ '}',
63
+ ].join('\n');
64
+ // The loader serves the code it cached under an id, so the id carries the code.
65
+ export const ESBUILD_FACET_WORKER_ID = `nimbus-esbuild:${ESBUILD_WASM_VERSION}:${ESBUILD_CLI_BUILD_ID}:${hashSource(ESBUILD_FACET_BODY)}`;
66
+ /** Source bytes per facet call: bounds what the caller's isolate holds for one round trip. */
67
+ const TRANSFORM_BATCH_SOURCE_BYTES = 4 * 1024 * 1024;
68
+ /**
69
+ * Slim Worker Loader module whose DO class owns the esbuild wasm.
70
+ * `jsFnBody` is the staged adapter (fetchEsbuildJsFnBody), compiled into a
71
+ * factory at startup, the one moment code may be generated from a string;
72
+ * each call of the factory is a separate esbuild. `cliRunner` is the staged
73
+ * runner of the `esbuild` command (fetchEsbuildCliRunner).
74
+ */
75
+ export function esbuildFacetWorkerCode(wasmBytes, jsFnBody, cliRunner) {
8
76
  const source = [
9
77
  'import { DurableObject } from "cloudflare:workers";',
10
78
  'import wasmModule from "esbuild.wasm";',
11
- `const esbuild = new Function(${JSON.stringify(ESBUILD_WASM_JS_FN_BODY)})();`,
12
- ESBUILD_NAME_GLOBAL_SHIM,
13
- generateEsbuildTransformRuntimeSource(),
14
- 'let initialized;',
15
- 'function ensureInitialized() {',
16
- ' initialized ||= esbuild.initialize({ wasmModule, worker: false });',
17
- ' return initialized;',
18
- '}',
19
- 'export class EsbuildTransformFacet extends DurableObject {',
20
- ' async transform(code, options) {',
21
- ' await ensureInitialized();',
22
- ' return transformWithEsbuild(esbuild, code, options);',
23
- ' }',
24
- '}',
79
+ `const newEsbuild = new Function(${JSON.stringify(jsFnBody)});`,
80
+ 'const esbuild = newEsbuild();',
81
+ cliRunner,
82
+ ESBUILD_FACET_BODY,
25
83
  ].join('\n');
26
84
  return {
27
85
  compatibilityDate: CF_COMPAT_DATE,
@@ -34,3 +92,145 @@ export function esbuildTransformWorkerCode(wasmBytes) {
34
92
  globalOutbound: null,
35
93
  };
36
94
  }
95
+ /**
96
+ * A Durable Object's esbuild facet: one loader-backed child that owns the
97
+ * esbuild wasm, so the object's own isolate never instantiates it. Needs
98
+ * `env.LOADER`, `env.ASSETS` and `ctx.facets`, and nothing of any host.
99
+ */
100
+ async function esbuildFacet(ctx, env) {
101
+ const loader = Reflect.get(Object(env), 'LOADER');
102
+ if (!loader || typeof loader.get !== 'function') {
103
+ throw new Error('Nimbus: env.LOADER unavailable for the esbuild facet');
104
+ }
105
+ const assets = Reflect.get(Object(env), 'ASSETS');
106
+ if (!assets || typeof assets.fetch !== 'function') {
107
+ throw new Error('Nimbus: env.ASSETS unavailable for the esbuild facet');
108
+ }
109
+ const worker = await loader.get(ESBUILD_FACET_WORKER_ID, async () => {
110
+ const assetsEnv = { ASSETS: assets };
111
+ const [wasmBytes, jsFnBody, cliRunner] = await Promise.all([
112
+ fetchEsbuildWasmBytes(assetsEnv),
113
+ fetchEsbuildJsFnBody(assetsEnv),
114
+ fetchEsbuildCliRunner(assetsEnv),
115
+ ]);
116
+ return esbuildFacetWorkerCode(wasmBytes, jsFnBody, cliRunner);
117
+ });
118
+ const facetClass = worker.getDurableObjectClass('EsbuildFacet');
119
+ return ctx.facets.get(ESBUILD_FACET_WORKER_ID, async () => ({ class: facetClass }));
120
+ }
121
+ /**
122
+ * The one way to a Durable Object's esbuild facet: its transforms, builds,
123
+ * and `esbuild` commands share one stub, so a caller that starts
124
+ * while another is still loading the facet (fetching and verifying the 12 MiB
125
+ * wasm) waits on that load instead of starting a second one. A load or call
126
+ * that failed drops the entry; the next caller mints a fresh stub.
127
+ */
128
+ const sharedFacets = new WeakMap();
129
+ function sharedEsbuildFacet(ctx, env) {
130
+ const current = sharedFacets.get(ctx);
131
+ if (current)
132
+ return current;
133
+ const minted = esbuildFacet(ctx, env);
134
+ sharedFacets.set(ctx, minted);
135
+ minted.catch(() => forgetEsbuildFacet(ctx, minted));
136
+ return minted;
137
+ }
138
+ function forgetEsbuildFacet(ctx, stub) {
139
+ if (sharedFacets.get(ctx) === stub)
140
+ sharedFacets.delete(ctx);
141
+ }
142
+ /** One call on the shared facet; a call that throws drops the stub it used. */
143
+ async function onEsbuildFacet(ctx, env, call) {
144
+ const stub = sharedEsbuildFacet(ctx, env);
145
+ try {
146
+ return await call(await stub);
147
+ }
148
+ catch (error) {
149
+ forgetEsbuildFacet(ctx, stub);
150
+ throw error;
151
+ }
152
+ }
153
+ /** Calls per slice: a slice whose call failed is sent once more. */
154
+ const SLICE_ATTEMPTS = 2;
155
+ /**
156
+ * The transform host a Durable Object's esbuild runs its transforms on: its
157
+ * esbuild facet, a slice per call. Transforms are pure, so a slice whose call
158
+ * failed (the facet reset, the connection dropped) is sent once more, to a
159
+ * freshly minted stub; an overloaded facet is not asked again. A slice that
160
+ * still fails answers each of its requests with a transient error, which is
161
+ * no verdict on the source, and the other slices keep their answers.
162
+ */
163
+ export function esbuildTransformHost(ctx, env) {
164
+ return async (requests) => {
165
+ let facet = null;
166
+ const outcomes = [];
167
+ for (let start = 0; start < requests.length;) {
168
+ let end = start;
169
+ let bytes = 0;
170
+ while (end < requests.length && (end === start || bytes + requests[end].code.length <= TRANSFORM_BATCH_SOURCE_BYTES)) {
171
+ bytes += requests[end].code.length;
172
+ end++;
173
+ }
174
+ const slice = requests.slice(start, end);
175
+ let answered = null;
176
+ let failure = null;
177
+ for (let attempt = 1; answered === null && attempt <= SLICE_ATTEMPTS; attempt++) {
178
+ try {
179
+ facet ??= sharedEsbuildFacet(ctx, env);
180
+ answered = await (await facet).transformMany(slice);
181
+ }
182
+ catch (error) {
183
+ // A stub that threw may be broken for good; the next call mints its own.
184
+ if (facet)
185
+ forgetEsbuildFacet(ctx, facet);
186
+ facet = null;
187
+ failure = error;
188
+ if (classifyDoCall(error) === 'overloaded')
189
+ break;
190
+ }
191
+ }
192
+ if (answered === null) {
193
+ const error = `esbuild facet unavailable: ${errorText(failure)}`;
194
+ answered = slice.map(() => ({ error, transient: true }));
195
+ }
196
+ for (const outcome of answered)
197
+ outcomes.push(outcome);
198
+ start = end;
199
+ }
200
+ return outcomes;
201
+ };
202
+ }
203
+ /**
204
+ * The build host a Durable Object's esbuild runs its builds on: its esbuild
205
+ * facet. The plugin, and with it every file read, stays with the caller.
206
+ */
207
+ export function esbuildBuildHost(ctx, env) {
208
+ return async (options, plugin) => {
209
+ return onEsbuildFacet(ctx, env, (facet) => facet.build(options, plugin));
210
+ };
211
+ }
212
+ /**
213
+ * Runs one `esbuild` command in the Durable Object's esbuild facet, as
214
+ * process `pid`: its files go through a supervisor capability minted for that
215
+ * pid, the one IsolatePool mints for a facet, and its stdout and stderr come
216
+ * back through `output` as esbuild writes them. Resolves to its exit status.
217
+ */
218
+ export async function runEsbuildCli(ctx, env, pid, args, output) {
219
+ const mint = supervisorEntrypoint();
220
+ if (!mint)
221
+ throw new Error('Nimbus: no supervisor entrypoint is composed, so the esbuild facet cannot reach the files');
222
+ const supervisor = mint({
223
+ props: supervisorBindingProps(ctx, pid),
224
+ });
225
+ return onEsbuildFacet(ctx, env, (facet) => facet.cli(args, supervisor, output));
226
+ }
227
+ /**
228
+ * The esbuild a Durable Object's supervisor shares: its transforms and its
229
+ * builds run in its esbuild facet, and build() reads `vfs` from here.
230
+ */
231
+ export function supervisorEsbuildService(ctx, env, vfs) {
232
+ return new EsbuildService(vfs, {
233
+ transformHost: esbuildTransformHost(ctx, env),
234
+ buildHost: esbuildBuildHost(ctx, env),
235
+ });
236
+ }
@@ -47,8 +47,12 @@ export interface ExecTelemetryRecord {
47
47
  * map and pre-compiling every cell in it.
48
48
  */
49
49
  bundleBytes: number;
50
- manifestBytes: number;
51
- metadataBytes: number;
50
+ /**
51
+ * Synchronous fs calls the facet refused because its namespace was being
52
+ * rebuilt after a failed relist (a failure state, repaired at the next
53
+ * barrier). Zero in a healthy session.
54
+ */
55
+ namespaceRefusals: number;
52
56
  /** Supervisor RPC writes the facet issued (__queueRpcWrite calls). */
53
57
  rpcWrites: number;
54
58
  /** Supervisor fs READ round trips the facet issued. A whole-file async
@@ -74,7 +78,7 @@ export interface ExecTelemetryRecord {
74
78
  * The fields `_execViaLoader` fills in on its way through, for the caller to
75
79
  * fold into a record. Derived from the record so the two cannot drift.
76
80
  */
77
- export type ExecDiagSink = Pick<ExecTelemetryRecord, 'loadMs' | 'runMs' | 'moduleMapBytes' | 'bundleBytes' | 'manifestBytes' | 'metadataBytes'>;
81
+ export type ExecDiagSink = Pick<ExecTelemetryRecord, 'loadMs' | 'runMs' | 'moduleMapBytes' | 'bundleBytes'>;
78
82
  /**
79
83
  * True when exec telemetry is enabled. Read once at exec entry; callers
80
84
  * skip building the record entirely when this is false so the path stays
@@ -1 +1 @@
1
- {"version":3,"file":"exec-telemetry.d.ts","sourceRoot":"","sources":["../../src/facets/exec-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,yDAAyD;AACzD,MAAM,WAAW,mBAAmB;IAClC,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,KAAK,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