@nimbus-sh/worker 0.1.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.
- package/README.md +219 -0
- package/dist/_shared/bytes.d.ts +18 -0
- package/dist/_shared/bytes.d.ts.map +1 -0
- package/dist/_shared/bytes.js +17 -0
- package/dist/_shared/cache-stats.d.ts +146 -0
- package/dist/_shared/cache-stats.d.ts.map +1 -0
- package/dist/_shared/cache-stats.js +162 -0
- package/dist/_shared/exports-resolver.d.ts +76 -0
- package/dist/_shared/exports-resolver.d.ts.map +1 -0
- package/dist/_shared/exports-resolver.js +284 -0
- package/dist/_shared/install-phase.d.ts +47 -0
- package/dist/_shared/install-phase.d.ts.map +1 -0
- package/dist/_shared/install-phase.js +1 -0
- package/dist/_shared/real-node-imports.d.ts +38 -0
- package/dist/_shared/real-node-imports.d.ts.map +1 -0
- package/dist/_shared/real-node-imports.js +46 -0
- package/dist/_shared/retry.d.ts +93 -0
- package/dist/_shared/retry.d.ts.map +1 -0
- package/dist/_shared/retry.js +161 -0
- package/dist/_shared/session-id.d.ts +39 -0
- package/dist/_shared/session-id.d.ts.map +1 -0
- package/dist/_shared/session-id.js +127 -0
- package/dist/_shared/session-router.d.ts +104 -0
- package/dist/_shared/session-router.d.ts.map +1 -0
- package/dist/_shared/session-router.js +165 -0
- package/dist/_shared/w7-frame.d.ts +93 -0
- package/dist/_shared/w7-frame.d.ts.map +1 -0
- package/dist/_shared/w7-frame.js +402 -0
- package/dist/auth/index.d.ts +16 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +15 -0
- package/dist/auth/middleware.d.ts +85 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +150 -0
- package/dist/auth/token.d.ts +96 -0
- package/dist/auth/token.d.ts.map +1 -0
- package/dist/auth/token.js +226 -0
- package/dist/auth/types.d.ts +141 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +114 -0
- package/dist/bindings/d1.d.ts +102 -0
- package/dist/bindings/d1.d.ts.map +1 -0
- package/dist/bindings/d1.js +549 -0
- package/dist/bindings/kv.d.ts +82 -0
- package/dist/bindings/kv.d.ts.map +1 -0
- package/dist/bindings/kv.js +290 -0
- package/dist/bindings/r2.d.ts +137 -0
- package/dist/bindings/r2.d.ts.map +1 -0
- package/dist/bindings/r2.js +379 -0
- package/dist/cirrus-npm-cjs.generated.d.ts +17 -0
- package/dist/cirrus-npm-cjs.generated.d.ts.map +1 -0
- package/dist/cirrus-npm-cjs.generated.js +41 -0
- package/dist/cirrus-plugin-react.generated.d.ts +34 -0
- package/dist/cirrus-plugin-react.generated.d.ts.map +1 -0
- package/dist/cirrus-plugin-react.generated.js +33 -0
- package/dist/constants.d.ts +34 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +116 -0
- package/dist/esbuild-wasm-bundle.generated.d.ts +41 -0
- package/dist/esbuild-wasm-bundle.generated.d.ts.map +1 -0
- package/dist/esbuild-wasm-bundle.generated.js +40 -0
- package/dist/facets/cirrus-real.d.ts +147 -0
- package/dist/facets/cirrus-real.d.ts.map +1 -0
- package/dist/facets/cirrus-real.js +981 -0
- package/dist/facets/inner-do-registry.d.ts +41 -0
- package/dist/facets/inner-do-registry.d.ts.map +1 -0
- package/dist/facets/inner-do-registry.js +51 -0
- package/dist/facets/manager.d.ts +314 -0
- package/dist/facets/manager.d.ts.map +1 -0
- package/dist/facets/manager.js +2681 -0
- package/dist/facets/process.d.ts +318 -0
- package/dist/facets/process.d.ts.map +1 -0
- package/dist/facets/process.js +567 -0
- package/dist/facets/real-vite-fs-shim.d.ts +151 -0
- package/dist/facets/real-vite-fs-shim.d.ts.map +1 -0
- package/dist/facets/real-vite-fs-shim.js +1279 -0
- package/dist/facets/real-vite-hmr.d.ts +142 -0
- package/dist/facets/real-vite-hmr.d.ts.map +1 -0
- package/dist/facets/real-vite-hmr.js +476 -0
- package/dist/facets/vite-dev-server.d.ts +293 -0
- package/dist/facets/vite-dev-server.d.ts.map +1 -0
- package/dist/facets/vite-dev-server.js +2580 -0
- package/dist/facets/wasm-swap-registry.d.ts +261 -0
- package/dist/facets/wasm-swap-registry.d.ts.map +1 -0
- package/dist/facets/wasm-swap-registry.js +551 -0
- package/dist/facets/ws-terminal.d.ts +107 -0
- package/dist/facets/ws-terminal.d.ts.map +1 -0
- package/dist/facets/ws-terminal.js +207 -0
- package/dist/git/commands.d.ts +13 -0
- package/dist/git/commands.d.ts.map +1 -0
- package/dist/git/commands.js +633 -0
- package/dist/git/network-facet.d.ts +61 -0
- package/dist/git/network-facet.d.ts.map +1 -0
- package/dist/git/network-facet.js +700 -0
- package/dist/git-bundle.generated.d.ts +16 -0
- package/dist/git-bundle.generated.d.ts.map +1 -0
- package/dist/git-bundle.generated.js +15 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/loaders/child-process/spawn-facet.d.ts +90 -0
- package/dist/loaders/child-process/spawn-facet.d.ts.map +1 -0
- package/dist/loaders/child-process/spawn-facet.js +103 -0
- package/dist/loaders/child-process/spawn-pool.d.ts +110 -0
- package/dist/loaders/child-process/spawn-pool.d.ts.map +1 -0
- package/dist/loaders/child-process/spawn-pool.js +161 -0
- package/dist/loaders/fanout-pool.d.ts +195 -0
- package/dist/loaders/fanout-pool.d.ts.map +1 -0
- package/dist/loaders/fanout-pool.js +326 -0
- package/dist/loaders/generated-workers.d.ts +26 -0
- package/dist/loaders/generated-workers.d.ts.map +1 -0
- package/dist/loaders/generated-workers.js +25 -0
- package/dist/loaders/index.d.ts +15 -0
- package/dist/loaders/index.d.ts.map +1 -0
- package/dist/loaders/index.js +13 -0
- package/dist/loaders/loader-pool.d.ts +273 -0
- package/dist/loaders/loader-pool.d.ts.map +1 -0
- package/dist/loaders/loader-pool.js +624 -0
- package/dist/loaders/npm-resolve-preamble.d.ts +34 -0
- package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -0
- package/dist/loaders/npm-resolve-preamble.js +237 -0
- package/dist/loaders/pre-bundle-preamble.d.ts +41 -0
- package/dist/loaders/pre-bundle-preamble.d.ts.map +1 -0
- package/dist/loaders/pre-bundle-preamble.js +114 -0
- package/dist/loaders/vendor/codegen.d.ts +24 -0
- package/dist/loaders/vendor/codegen.d.ts.map +1 -0
- package/dist/loaders/vendor/codegen.js +44 -0
- package/dist/loaders/vendor/errors.d.ts +24 -0
- package/dist/loaders/vendor/errors.d.ts.map +1 -0
- package/dist/loaders/vendor/errors.js +46 -0
- package/dist/loaders/vendor/index.d.ts +16 -0
- package/dist/loaders/vendor/index.d.ts.map +1 -0
- package/dist/loaders/vendor/index.js +11 -0
- package/dist/loaders/vendor/pool.d.ts +88 -0
- package/dist/loaders/vendor/pool.d.ts.map +1 -0
- package/dist/loaders/vendor/pool.js +353 -0
- package/dist/loaders/vendor/primitives.d.ts +11 -0
- package/dist/loaders/vendor/primitives.d.ts.map +1 -0
- package/dist/loaders/vendor/primitives.js +33 -0
- package/dist/loaders/vendor/serialize.d.ts +3 -0
- package/dist/loaders/vendor/serialize.d.ts.map +1 -0
- package/dist/loaders/vendor/serialize.js +25 -0
- package/dist/loaders/vendor/types.d.ts +60 -0
- package/dist/loaders/vendor/types.d.ts.map +1 -0
- package/dist/loaders/vendor/types.js +4 -0
- package/dist/npm/cache.d.ts +136 -0
- package/dist/npm/cache.d.ts.map +1 -0
- package/dist/npm/cache.js +429 -0
- package/dist/npm/install-batch-facet.d.ts +129 -0
- package/dist/npm/install-batch-facet.d.ts.map +1 -0
- package/dist/npm/install-batch-facet.js +598 -0
- package/dist/npm/install-facet.d.ts +29 -0
- package/dist/npm/install-facet.d.ts.map +1 -0
- package/dist/npm/install-facet.js +9 -0
- package/dist/npm/installer.d.ts +239 -0
- package/dist/npm/installer.d.ts.map +1 -0
- package/dist/npm/installer.js +2022 -0
- package/dist/npm/npx-install.d.ts +74 -0
- package/dist/npm/npx-install.d.ts.map +1 -0
- package/dist/npm/npx-install.js +302 -0
- package/dist/npm/pre-bundle-facet.d.ts +168 -0
- package/dist/npm/pre-bundle-facet.d.ts.map +1 -0
- package/dist/npm/pre-bundle-facet.js +653 -0
- package/dist/npm/r2-cache.d.ts +286 -0
- package/dist/npm/r2-cache.d.ts.map +1 -0
- package/dist/npm/r2-cache.js +506 -0
- package/dist/npm/resolve-facet.d.ts +202 -0
- package/dist/npm/resolve-facet.d.ts.map +1 -0
- package/dist/npm/resolve-facet.js +833 -0
- package/dist/npm/resolve-one-facet.d.ts +204 -0
- package/dist/npm/resolve-one-facet.d.ts.map +1 -0
- package/dist/npm/resolve-one-facet.js +437 -0
- package/dist/npm/resolver.d.ts +109 -0
- package/dist/npm/resolver.d.ts.map +1 -0
- package/dist/npm/resolver.js +899 -0
- package/dist/npm/tarball-stream.d.ts +85 -0
- package/dist/npm/tarball-stream.d.ts.map +1 -0
- package/dist/npm/tarball-stream.js +205 -0
- package/dist/npm/tarball.d.ts +51 -0
- package/dist/npm/tarball.d.ts.map +1 -0
- package/dist/npm/tarball.js +185 -0
- package/dist/observability/diag-counters.d.ts +292 -0
- package/dist/observability/diag-counters.d.ts.map +1 -0
- package/dist/observability/diag-counters.js +302 -0
- package/dist/observability/heap-estimate.d.ts +166 -0
- package/dist/observability/heap-estimate.d.ts.map +1 -0
- package/dist/observability/heap-estimate.js +192 -0
- package/dist/observability/heavy-alloc-coord.d.ts +95 -0
- package/dist/observability/heavy-alloc-coord.d.ts.map +1 -0
- package/dist/observability/heavy-alloc-coord.js +149 -0
- package/dist/observability/oom-classify.d.ts +56 -0
- package/dist/observability/oom-classify.d.ts.map +1 -0
- package/dist/observability/oom-classify.js +118 -0
- package/dist/observability/oom-discriminator.d.ts +192 -0
- package/dist/observability/oom-discriminator.d.ts.map +1 -0
- package/dist/observability/oom-discriminator.js +233 -0
- package/dist/real-vite-bundle.generated.d.ts +46 -0
- package/dist/real-vite-bundle.generated.d.ts.map +1 -0
- package/dist/real-vite-bundle.generated.js +53 -0
- package/dist/replica/routing.d.ts +171 -0
- package/dist/replica/routing.d.ts.map +1 -0
- package/dist/replica/routing.js +288 -0
- package/dist/replica/suspension.d.ts +36 -0
- package/dist/replica/suspension.d.ts.map +1 -0
- package/dist/replica/suspension.js +49 -0
- package/dist/router/index.d.ts +156 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +220 -0
- package/dist/runtime/assets-loader.d.ts +71 -0
- package/dist/runtime/assets-loader.d.ts.map +1 -0
- package/dist/runtime/assets-loader.js +128 -0
- package/dist/runtime/barrel-detect.d.ts +46 -0
- package/dist/runtime/barrel-detect.d.ts.map +1 -0
- package/dist/runtime/barrel-detect.js +73 -0
- package/dist/runtime/barrel-synthesizer.d.ts +181 -0
- package/dist/runtime/barrel-synthesizer.d.ts.map +1 -0
- package/dist/runtime/barrel-synthesizer.js +541 -0
- package/dist/runtime/bun-repl.d.ts +46 -0
- package/dist/runtime/bun-repl.d.ts.map +1 -0
- package/dist/runtime/bun-repl.js +326 -0
- package/dist/runtime/bun-runner.d.ts +66 -0
- package/dist/runtime/bun-runner.d.ts.map +1 -0
- package/dist/runtime/bun-runner.js +219 -0
- package/dist/runtime/clang-runner.d.ts +38 -0
- package/dist/runtime/clang-runner.d.ts.map +1 -0
- package/dist/runtime/clang-runner.js +1033 -0
- package/dist/runtime/comment-strip.d.ts +37 -0
- package/dist/runtime/comment-strip.d.ts.map +1 -0
- package/dist/runtime/comment-strip.js +74 -0
- package/dist/runtime/esbuild-service.d.ts +201 -0
- package/dist/runtime/esbuild-service.d.ts.map +1 -0
- package/dist/runtime/esbuild-service.js +1444 -0
- package/dist/runtime/esbuild-wasm-bytes.d.ts +87 -0
- package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -0
- package/dist/runtime/esbuild-wasm-bytes.js +131 -0
- package/dist/runtime/framework-detect.d.ts +71 -0
- package/dist/runtime/framework-detect.d.ts.map +1 -0
- package/dist/runtime/framework-detect.js +178 -0
- package/dist/runtime/long-running-handle.d.ts +133 -0
- package/dist/runtime/long-running-handle.d.ts.map +1 -0
- package/dist/runtime/long-running-handle.js +192 -0
- package/dist/runtime/node-repl.d.ts +36 -0
- package/dist/runtime/node-repl.d.ts.map +1 -0
- package/dist/runtime/node-repl.js +293 -0
- package/dist/runtime/node-runner.d.ts +111 -0
- package/dist/runtime/node-runner.d.ts.map +1 -0
- package/dist/runtime/node-runner.js +194 -0
- package/dist/runtime/node-shims.d.ts +24 -0
- package/dist/runtime/node-shims.d.ts.map +1 -0
- package/dist/runtime/node-shims.js +3019 -0
- package/dist/runtime/package-manager.d.ts +118 -0
- package/dist/runtime/package-manager.d.ts.map +1 -0
- package/dist/runtime/package-manager.js +420 -0
- package/dist/runtime/port-registry.d.ts +80 -0
- package/dist/runtime/port-registry.d.ts.map +1 -0
- package/dist/runtime/port-registry.js +166 -0
- package/dist/runtime/process-logs-api.d.ts +102 -0
- package/dist/runtime/process-logs-api.d.ts.map +1 -0
- package/dist/runtime/process-logs-api.js +253 -0
- package/dist/runtime/process-logs.d.ts +311 -0
- package/dist/runtime/process-logs.d.ts.map +1 -0
- package/dist/runtime/process-logs.js +656 -0
- package/dist/runtime/process-table.d.ts +65 -0
- package/dist/runtime/process-table.d.ts.map +1 -0
- package/dist/runtime/process-table.js +107 -0
- package/dist/runtime/project-detect.d.ts +21 -0
- package/dist/runtime/project-detect.d.ts.map +1 -0
- package/dist/runtime/project-detect.js +46 -0
- package/dist/runtime/python-repl.d.ts +66 -0
- package/dist/runtime/python-repl.d.ts.map +1 -0
- package/dist/runtime/python-repl.js +563 -0
- package/dist/runtime/python-runner.d.ts +50 -0
- package/dist/runtime/python-runner.d.ts.map +1 -0
- package/dist/runtime/python-runner.js +870 -0
- package/dist/runtime/repl-session.d.ts +160 -0
- package/dist/runtime/repl-session.d.ts.map +1 -0
- package/dist/runtime/repl-session.js +393 -0
- package/dist/runtime/require-resolver.d.ts +52 -0
- package/dist/runtime/require-resolver.d.ts.map +1 -0
- package/dist/runtime/require-resolver.js +690 -0
- package/dist/runtime/router-basename.d.ts +36 -0
- package/dist/runtime/router-basename.d.ts.map +1 -0
- package/dist/runtime/router-basename.js +310 -0
- package/dist/runtime/ruby-repl.d.ts +43 -0
- package/dist/runtime/ruby-repl.d.ts.map +1 -0
- package/dist/runtime/ruby-repl.js +229 -0
- package/dist/runtime/ruby-runner.d.ts +62 -0
- package/dist/runtime/ruby-runner.d.ts.map +1 -0
- package/dist/runtime/ruby-runner.js +737 -0
- package/dist/runtime/runtime-catalog.d.ts +99 -0
- package/dist/runtime/runtime-catalog.d.ts.map +1 -0
- package/dist/runtime/runtime-catalog.js +183 -0
- package/dist/runtime/runtime-registry.d.ts +136 -0
- package/dist/runtime/runtime-registry.d.ts.map +1 -0
- package/dist/runtime/runtime-registry.js +318 -0
- package/dist/runtime/streams.d.ts +13 -0
- package/dist/runtime/streams.d.ts.map +1 -0
- package/dist/runtime/streams.js +402 -0
- package/dist/runtime/wasi-instance.d.ts +190 -0
- package/dist/runtime/wasi-instance.d.ts.map +1 -0
- package/dist/runtime/wasi-instance.js +2044 -0
- package/dist/runtime/wasm-runner.d.ts +117 -0
- package/dist/runtime/wasm-runner.d.ts.map +1 -0
- package/dist/runtime/wasm-runner.js +705 -0
- package/dist/session/bindings.d.ts +168 -0
- package/dist/session/bindings.d.ts.map +1 -0
- package/dist/session/bindings.js +524 -0
- package/dist/session/ctx-exports.d.ts +16 -0
- package/dist/session/ctx-exports.d.ts.map +1 -0
- package/dist/session/ctx-exports.js +22 -0
- package/dist/session/diag.d.ts +62 -0
- package/dist/session/diag.d.ts.map +1 -0
- package/dist/session/diag.js +118 -0
- package/dist/session/fs-watch.d.ts +132 -0
- package/dist/session/fs-watch.d.ts.map +1 -0
- package/dist/session/fs-watch.js +255 -0
- package/dist/session/helpers.d.ts +150 -0
- package/dist/session/helpers.d.ts.map +1 -0
- package/dist/session/helpers.js +472 -0
- package/dist/session/hibernation.d.ts +145 -0
- package/dist/session/hibernation.d.ts.map +1 -0
- package/dist/session/hibernation.js +385 -0
- package/dist/session/init-phases.d.ts +87 -0
- package/dist/session/init-phases.d.ts.map +1 -0
- package/dist/session/init-phases.js +137 -0
- package/dist/session/init.d.ts +46 -0
- package/dist/session/init.d.ts.map +1 -0
- package/dist/session/init.js +3579 -0
- package/dist/session/keys.d.ts +56 -0
- package/dist/session/keys.d.ts.map +1 -0
- package/dist/session/keys.js +55 -0
- package/dist/session/nimbus-session.d.ts +434 -0
- package/dist/session/nimbus-session.d.ts.map +1 -0
- package/dist/session/nimbus-session.js +1084 -0
- package/dist/session/programmatic.d.ts +105 -0
- package/dist/session/programmatic.d.ts.map +1 -0
- package/dist/session/programmatic.js +326 -0
- package/dist/session/replica-routes.d.ts +68 -0
- package/dist/session/replica-routes.d.ts.map +1 -0
- package/dist/session/replica-routes.js +77 -0
- package/dist/session/routes.d.ts +29 -0
- package/dist/session/routes.d.ts.map +1 -0
- package/dist/session/routes.js +1331 -0
- package/dist/session/rpc.d.ts +323 -0
- package/dist/session/rpc.d.ts.map +1 -0
- package/dist/session/rpc.js +808 -0
- package/dist/session/state-store.d.ts +210 -0
- package/dist/session/state-store.d.ts.map +1 -0
- package/dist/session/state-store.js +459 -0
- package/dist/session/supervisor-rpc.d.ts +269 -0
- package/dist/session/supervisor-rpc.d.ts.map +1 -0
- package/dist/session/supervisor-rpc.js +437 -0
- package/dist/session/ws-hibernation-config.d.ts +64 -0
- package/dist/session/ws-hibernation-config.d.ts.map +1 -0
- package/dist/session/ws-hibernation-config.js +89 -0
- package/dist/session/ws.d.ts +95 -0
- package/dist/session/ws.d.ts.map +1 -0
- package/dist/session/ws.js +395 -0
- package/dist/shell/features.d.ts +410 -0
- package/dist/shell/features.d.ts.map +1 -0
- package/dist/shell/features.js +1885 -0
- package/dist/shell/unix-commands.d.ts +15 -0
- package/dist/shell/unix-commands.d.ts.map +1 -0
- package/dist/shell/unix-commands.js +3703 -0
- package/dist/stubs/lifo-ui.d.ts +10 -0
- package/dist/stubs/lifo-ui.d.ts.map +1 -0
- package/dist/stubs/lifo-ui.js +1 -0
- package/dist/tailwind-play.generated.d.ts +19 -0
- package/dist/tailwind-play.generated.d.ts.map +1 -0
- package/dist/tailwind-play.generated.js +18 -0
- package/dist/vfs/dev-provider.d.ts +64 -0
- package/dist/vfs/dev-provider.d.ts.map +1 -0
- package/dist/vfs/dev-provider.js +191 -0
- package/dist/vfs/events.d.ts +51 -0
- package/dist/vfs/events.d.ts.map +1 -0
- package/dist/vfs/events.js +127 -0
- package/dist/vfs/path.d.ts +30 -0
- package/dist/vfs/path.d.ts.map +1 -0
- package/dist/vfs/path.js +41 -0
- package/dist/vfs/seed-project.d.ts +62 -0
- package/dist/vfs/seed-project.d.ts.map +1 -0
- package/dist/vfs/seed-project.js +1045 -0
- package/dist/vfs/sqlite-vfs.d.ts +435 -0
- package/dist/vfs/sqlite-vfs.d.ts.map +1 -0
- package/dist/vfs/sqlite-vfs.js +1670 -0
- package/dist/vfs/symlink-registry.d.ts +64 -0
- package/dist/vfs/symlink-registry.d.ts.map +1 -0
- package/dist/vfs/symlink-registry.js +137 -0
- package/dist/wrangler/nimbus-wrangler.d.ts +157 -0
- package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -0
- package/dist/wrangler/nimbus-wrangler.js +931 -0
- package/package.json +77 -0
- package/public/_assets/cirrus-plugin-react.bundle.js +70740 -0
- package/public/_assets/esbuild-0.24.2.wasm +0 -0
- package/public/_assets/real-vite-bundle.js +101478 -0
- package/public/_assets/rollup.wasm +0 -0
- package/public/favicon.svg +8 -0
- package/public/index.html +565 -0
- package/public/s/index.html +2379 -0
- package/scripts/bundle-esbuild-wasm.mjs +244 -0
- package/scripts/bundle-facet-workers.mjs +137 -0
- package/scripts/bundle-git.mjs +118 -0
- package/scripts/bundle-npm-cjs.mjs +363 -0
- package/scripts/bundle-plugin-react.mjs +480 -0
- package/scripts/bundle-real-vite.mjs +959 -0
- package/scripts/bundle-runtime.mjs +600 -0
- package/scripts/bundle-tailwind-play.mjs +130 -0
- package/scripts/patch-lifo-ui.mjs +131 -0
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pre-bundle-facet.ts — NimbusLoaderPool entry for esbuild pre-bundling.
|
|
3
|
+
*
|
|
4
|
+
* Why this exists
|
|
5
|
+
* ───────────────
|
|
6
|
+
* Pre-bundling npm packages (the `Pre-bundling N modules…` step in
|
|
7
|
+
* src/npm-installer.ts:704) 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
|
+
* NimbusLoaderPool 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. Same pattern as
|
|
20
|
+
* src/npm-install-facet.ts (tarball extraction).
|
|
21
|
+
*
|
|
22
|
+
* File-slice strategy (zero per-read RPC)
|
|
23
|
+
* ──────────────────────────────────────
|
|
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/parallel/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.
|
|
46
|
+
*/
|
|
47
|
+
import { getSharedRuntimeExternals, BUNDLER_VERSION } from '../runtime/esbuild-service.js';
|
|
48
|
+
export function buildSliceForSpecifier(vfs, specifier, nmDir) {
|
|
49
|
+
return buildSliceForSpecifierWithCap(vfs, specifier, nmDir, 24 * 1024 * 1024);
|
|
50
|
+
}
|
|
51
|
+
export function buildSliceForSpecifierWithCap(vfs, specifier, nmDir, capBytes) {
|
|
52
|
+
const externals = new Set();
|
|
53
|
+
for (const e of getSharedRuntimeExternals(specifier)) {
|
|
54
|
+
// strip glob suffix: "react/*" → "react"
|
|
55
|
+
if (e.endsWith('/*'))
|
|
56
|
+
externals.add(e.slice(0, -2));
|
|
57
|
+
else
|
|
58
|
+
externals.add(e);
|
|
59
|
+
}
|
|
60
|
+
const slice = [];
|
|
61
|
+
let totalBytes = 0;
|
|
62
|
+
const visitedPkgs = new Set();
|
|
63
|
+
// Bare-specifier → top-level package name (handles @scope/pkg).
|
|
64
|
+
const pkgNameFor = (spec) => spec.startsWith('@') ? spec.split('/').slice(0, 2).join('/') : spec.split('/')[0];
|
|
65
|
+
const addFile = (path) => {
|
|
66
|
+
try {
|
|
67
|
+
if (vfs.isDirectory(path)) {
|
|
68
|
+
slice.push({ path: '/' + path.replace(/^\/+/, ''), isDir: true });
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
const bytes = vfs.readFile(path);
|
|
72
|
+
totalBytes += bytes.length + path.length;
|
|
73
|
+
if (totalBytes > capBytes)
|
|
74
|
+
return false; // caller bails
|
|
75
|
+
slice.push({ path: '/' + path.replace(/^\/+/, ''), bytes, isDir: false });
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return true; /* skip unreadable */
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Walk every file under `pkgDir`, depth-limited to keep us out of
|
|
84
|
+
* pathological tarballs (tests have seen 30-deep trees but not 100).
|
|
85
|
+
* Skip nested node_modules — those are dependencies handled separately
|
|
86
|
+
* by the recursive descent below, and including them here would cause
|
|
87
|
+
* double-shipping for many large libraries.
|
|
88
|
+
*/
|
|
89
|
+
const walkDir = (dir, depth) => {
|
|
90
|
+
if (depth > 12)
|
|
91
|
+
return true;
|
|
92
|
+
let entries;
|
|
93
|
+
try {
|
|
94
|
+
entries = vfs.readdir(dir);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
for (const entry of entries) {
|
|
100
|
+
if (entry.name === 'node_modules')
|
|
101
|
+
continue; // handled by dep recursion
|
|
102
|
+
const child = dir + '/' + entry.name;
|
|
103
|
+
if (entry.type === 'directory') {
|
|
104
|
+
if (!addFile(child))
|
|
105
|
+
return false;
|
|
106
|
+
if (!walkDir(child, depth + 1))
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
if (!addFile(child))
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return true;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Recurse into a package: ship its files, then descend into each
|
|
118
|
+
* non-external `dependencies` entry. Idempotent via visitedPkgs.
|
|
119
|
+
*
|
|
120
|
+
* `isRoot=true` for the FIRST call (the spec's own package). The
|
|
121
|
+
* spec's own package is ALWAYS walked even when its pkgName is also
|
|
122
|
+
* in the externals set — this is required for subpath specs like
|
|
123
|
+
* `react/jsx-runtime` (pkgName = 'react', externals = ['react']).
|
|
124
|
+
* Without this, the slice was empty for jsx-runtime, esbuild got
|
|
125
|
+
* nothing to bundle, the on-demand bundler returned an empty body,
|
|
126
|
+
* and serveModule fell through to the CDN fallback (esm.sh) which
|
|
127
|
+
* shipped a DIFFERENT React instance and broke the dual-React
|
|
128
|
+
* invariant. Verified on prod: jsx-runtime served 178B CDN wrapper
|
|
129
|
+
* instead of a real bundle.
|
|
130
|
+
*/
|
|
131
|
+
const visitPkg = (pkgName, isRoot) => {
|
|
132
|
+
if (visitedPkgs.has(pkgName))
|
|
133
|
+
return true;
|
|
134
|
+
visitedPkgs.add(pkgName);
|
|
135
|
+
// External specifiers' files are deliberately omitted (esbuild will
|
|
136
|
+
// mark them external; the bundle leaves the import unresolved for
|
|
137
|
+
// the browser to fetch from /preview/@modules/) — UNLESS this is
|
|
138
|
+
// the spec's own package, which we always need to walk so the
|
|
139
|
+
// entry point and its non-external internals are in the slice.
|
|
140
|
+
if (externals.has(pkgName) && !isRoot)
|
|
141
|
+
return true;
|
|
142
|
+
const pkgDir = nmDir + '/' + pkgName;
|
|
143
|
+
if (!vfs.exists(pkgDir) || !vfs.isDirectory(pkgDir))
|
|
144
|
+
return true;
|
|
145
|
+
if (!addFile(pkgDir))
|
|
146
|
+
return false;
|
|
147
|
+
if (!walkDir(pkgDir, 0))
|
|
148
|
+
return false;
|
|
149
|
+
// Read deps; recurse. Recursion is never `isRoot` — only the
|
|
150
|
+
// outermost spec gets that exemption.
|
|
151
|
+
let pkgJson = null;
|
|
152
|
+
const pkgJsonPath = pkgDir + '/package.json';
|
|
153
|
+
if (vfs.exists(pkgJsonPath)) {
|
|
154
|
+
try {
|
|
155
|
+
pkgJson = JSON.parse(vfs.readFileString(pkgJsonPath));
|
|
156
|
+
}
|
|
157
|
+
catch { }
|
|
158
|
+
}
|
|
159
|
+
const deps = pkgJson?.dependencies ? Object.keys(pkgJson.dependencies) : [];
|
|
160
|
+
for (const dep of deps) {
|
|
161
|
+
if (!visitPkg(dep, false))
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
return true;
|
|
165
|
+
};
|
|
166
|
+
const pkgName = pkgNameFor(specifier);
|
|
167
|
+
if (!visitPkg(pkgName, true)) {
|
|
168
|
+
// Cap exceeded — caller bails out. Empty caller = caller will fall
|
|
169
|
+
// back to legacy in-supervisor path or skip pre-bundling entirely.
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
return { slice, totalBytes };
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Choose the externals list for a specifier, exported so the supervisor
|
|
176
|
+
* can compute the same value when building the spec without re-pulling
|
|
177
|
+
* the helper from esbuild-service.ts on the call site.
|
|
178
|
+
*/
|
|
179
|
+
export function externalsForSpecifier(specifier) {
|
|
180
|
+
return getSharedRuntimeExternals(specifier);
|
|
181
|
+
}
|
|
182
|
+
// ── Facet function ──────────────────────────────────────────────────────
|
|
183
|
+
//
|
|
184
|
+
// `prebundleOne` runs inside a NimbusLoaderPool isolate. cloudflare-parallel
|
|
185
|
+
// serialises it via fn.toString(); the helpers it references at module
|
|
186
|
+
// scope (ESBUILD_WASM_JS_FN_BODY, resolvePackageEntry) are NOT in the
|
|
187
|
+
// facet's lexical scope at runtime. Instead they're injected by the
|
|
188
|
+
// pre-bundle preamble; see src/parallel/pre-bundle-preamble.ts.
|
|
189
|
+
//
|
|
190
|
+
// The wasm BYTES are NOT in the preamble (intentionally — that was a
|
|
191
|
+
// 16 MiB allocation per dispatch which OOM'd the DO). They live in
|
|
192
|
+
// env.ASSETS, the supervisor fetches once at pool construction
|
|
193
|
+
// (src/esbuild-wasm-bytes.ts), and the bytes flow into the facet via
|
|
194
|
+
// the LOADER `modules` map. workerd compiles at facet module-load
|
|
195
|
+
// (startup phase, eval permitted) and exposes the resulting
|
|
196
|
+
// WebAssembly.Module via the standard ESM import the pool's
|
|
197
|
+
// generated worker.js performs.
|
|
198
|
+
/**
|
|
199
|
+
* Bundle one specifier in a facet isolate. Returns the ESM bundle output
|
|
200
|
+
* to the supervisor; bundle bytes flow through `pool.map`'s return value
|
|
201
|
+
* (no RPC writeBatch — pkg_esm_bundles is supervisor-side SQLite, not VFS).
|
|
202
|
+
*
|
|
203
|
+
* Memory plan (verified by /api/_diag/memory after the rollout):
|
|
204
|
+
* - Slice retained in facet memory: ~3–10 MiB per typical React lib.
|
|
205
|
+
* - esbuild WASM linear memory: ~30–80 MiB during build.
|
|
206
|
+
* - Output bundle: usually <2 MiB.
|
|
207
|
+
* - Peak in the facet: ~100 MiB worst case (well under 128 MB cap).
|
|
208
|
+
*
|
|
209
|
+
* The supervisor never holds more than the spec arg + result return at
|
|
210
|
+
* once, so its peak stays in the low tens of MiB during the entire
|
|
211
|
+
* pre-bundle phase.
|
|
212
|
+
*/
|
|
213
|
+
export const prebundleOne = async function prebundleOne(spec, _env) {
|
|
214
|
+
const t0 = Date.now();
|
|
215
|
+
const warnings = [];
|
|
216
|
+
if (!spec || typeof spec !== 'object') {
|
|
217
|
+
throw new Error('prebundleOne: missing spec');
|
|
218
|
+
}
|
|
219
|
+
if (!Array.isArray(spec.slice)) {
|
|
220
|
+
throw new Error('prebundleOne: spec.slice missing');
|
|
221
|
+
}
|
|
222
|
+
// 1. Build an in-memory slice index. Path → bytes for files, set
|
|
223
|
+
// membership for directories. esbuild's plugin will look up paths
|
|
224
|
+
// here exactly the way it would have looked them up in the VFS.
|
|
225
|
+
const fileMap = new Map();
|
|
226
|
+
const dirSet = new Set();
|
|
227
|
+
const norm = (p) => p.startsWith('/') ? p : '/' + p;
|
|
228
|
+
for (const ent of spec.slice) {
|
|
229
|
+
if (ent.isDir)
|
|
230
|
+
dirSet.add(norm(ent.path));
|
|
231
|
+
else
|
|
232
|
+
fileMap.set(norm(ent.path), ent.bytes);
|
|
233
|
+
}
|
|
234
|
+
// Every file path implicitly creates its ancestor dirs in the slice's
|
|
235
|
+
// worldview, even if the supervisor walker didn't emit them.
|
|
236
|
+
for (const p of fileMap.keys()) {
|
|
237
|
+
let d = p;
|
|
238
|
+
while (d.length > 1) {
|
|
239
|
+
const slash = d.lastIndexOf('/');
|
|
240
|
+
if (slash <= 0)
|
|
241
|
+
break;
|
|
242
|
+
d = d.substring(0, slash);
|
|
243
|
+
dirSet.add(d);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
// 2. Pick up the esbuild namespace materialised by the preamble at
|
|
247
|
+
// module startup. workerd's deployed config disallows "Code
|
|
248
|
+
// generation from strings" at REQUEST time inside dynamic workers,
|
|
249
|
+
// so we cannot run `new Function(jsBody)()` here. The preamble
|
|
250
|
+
// runs that at module-load time (where eval is permitted) and
|
|
251
|
+
// stashes the result on the module-scope const __NIMBUS_ESBUILD_NS.
|
|
252
|
+
//
|
|
253
|
+
// The WASM module is shipped into the facet via NimbusLoaderPool's
|
|
254
|
+
// `wasmModules` option, registered in the LOADER's modules map as
|
|
255
|
+
// { wasm: ArrayBuffer }. Workerd compiles it during the worker's
|
|
256
|
+
// module-load phase (eval permitted there), and the pool's
|
|
257
|
+
// generated worker.js exposes the resulting WebAssembly.Module on
|
|
258
|
+
// globalThis.__NIMBUS_WASM[<key>]. We read it here at request time
|
|
259
|
+
// — no RPC, no compile, no structured-clone of Module values.
|
|
260
|
+
//
|
|
261
|
+
// First-dispatch costs (per warm slot):
|
|
262
|
+
// - 0 (esb namespace materialised at startup)
|
|
263
|
+
// - 0 (wasm Module already compiled by workerd at startup)
|
|
264
|
+
// - esb.initialize (~10 ms)
|
|
265
|
+
// Subsequent dispatches: pure cache hit.
|
|
266
|
+
// @ts-ignore — preamble symbol.
|
|
267
|
+
const esbInitErr = __NIMBUS_ESBUILD_INIT_ERR;
|
|
268
|
+
if (esbInitErr) {
|
|
269
|
+
throw new Error(`prebundleOne: esbuild namespace unavailable (preamble eval failed: ${esbInitErr})`);
|
|
270
|
+
}
|
|
271
|
+
// @ts-ignore — preamble symbol.
|
|
272
|
+
const esb = __NIMBUS_ESBUILD_NS;
|
|
273
|
+
if (!esb) {
|
|
274
|
+
throw new Error('prebundleOne: __NIMBUS_ESBUILD_NS is null (preamble did not run?)');
|
|
275
|
+
}
|
|
276
|
+
// Initialize esbuild's wasm exactly once per facet isolate. With
|
|
277
|
+
// pool concurrency > 1, multiple dispatches may run concurrently in
|
|
278
|
+
// the same slot — without an in-flight promise gate, both observe
|
|
279
|
+
// `!ready`, both call esb.initialize, the second errors with
|
|
280
|
+
// "You need to wait for the promise returned from 'initialize' to
|
|
281
|
+
// be resolved before calling this." Cache the in-flight Promise so
|
|
282
|
+
// concurrent callers await the same init; resolved Promise is
|
|
283
|
+
// cheap to await on subsequent dispatches.
|
|
284
|
+
let initPromise = globalThis.__nimbusFacetEsbuildInit;
|
|
285
|
+
if (!initPromise) {
|
|
286
|
+
initPromise = (async () => {
|
|
287
|
+
// Read the WebAssembly.Module the pool registered. The key matches
|
|
288
|
+
// the name passed to NimbusLoaderPool's `wasmModules` option (see
|
|
289
|
+
// src/npm-installer.ts:prebundleUsedModules dispatch site).
|
|
290
|
+
const wasmRegistry = globalThis.__NIMBUS_WASM;
|
|
291
|
+
const wasmModule = wasmRegistry && wasmRegistry['esbuild.wasm'];
|
|
292
|
+
if (!wasmModule) {
|
|
293
|
+
throw new Error(`prebundleOne: globalThis.__NIMBUS_WASM['esbuild.wasm'] missing — ` +
|
|
294
|
+
`pool was constructed without wasmModules?`);
|
|
295
|
+
}
|
|
296
|
+
try {
|
|
297
|
+
await esb.initialize({ wasmModule, worker: false });
|
|
298
|
+
}
|
|
299
|
+
catch (e) {
|
|
300
|
+
// "more than once" is harmless — this isolate already initialized
|
|
301
|
+
// in a previous warm dispatch; treat as success.
|
|
302
|
+
if (!String(e?.message || '').includes('more than once'))
|
|
303
|
+
throw e;
|
|
304
|
+
}
|
|
305
|
+
})();
|
|
306
|
+
globalThis.__nimbusFacetEsbuildInit = initPromise;
|
|
307
|
+
}
|
|
308
|
+
await initPromise;
|
|
309
|
+
// 3. Build the VFS plugin. The plugin reads from `fileMap` exclusively;
|
|
310
|
+
// every miss is logged into `warnings` so the supervisor can see
|
|
311
|
+
// whether the slice walker is missing something the bundle path
|
|
312
|
+
// actually wanted.
|
|
313
|
+
const EXTS = ['', '.ts', '.tsx', '.js', '.jsx', '.mts', '.mjs', '.cjs', '.json', '.css'];
|
|
314
|
+
const INDEX_FILES = ['index.ts', 'index.tsx', 'index.js', 'index.jsx', 'index.mjs'];
|
|
315
|
+
const stripLeadingSlash = (p) => p.replace(/^\/+/, '');
|
|
316
|
+
const normalizePath = (p) => {
|
|
317
|
+
// Resolve any `..` segments to keep tryResolve's exists() lookups
|
|
318
|
+
// canonical; mirrors src/vfs-path.ts behaviour without importing.
|
|
319
|
+
const parts = p.split('/');
|
|
320
|
+
const out = [];
|
|
321
|
+
for (const seg of parts) {
|
|
322
|
+
if (seg === '' || seg === '.')
|
|
323
|
+
continue;
|
|
324
|
+
if (seg === '..') {
|
|
325
|
+
if (out.length > 0)
|
|
326
|
+
out.pop();
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
out.push(seg);
|
|
330
|
+
}
|
|
331
|
+
return (p.startsWith('/') ? '/' : '') + out.join('/');
|
|
332
|
+
};
|
|
333
|
+
const fileExists = (p) => fileMap.has(norm(p));
|
|
334
|
+
const dirExists = (p) => dirSet.has(norm(p));
|
|
335
|
+
const tryResolve = (base) => {
|
|
336
|
+
const n = normalizePath(base);
|
|
337
|
+
for (const ext of EXTS) {
|
|
338
|
+
const cand = n + ext;
|
|
339
|
+
if (fileExists(cand))
|
|
340
|
+
return cand;
|
|
341
|
+
}
|
|
342
|
+
// Bundler-style swap: import './x.js' → ./x.ts on disk.
|
|
343
|
+
const m = n.match(/\.(js|mjs|cjs|jsx)$/);
|
|
344
|
+
if (m) {
|
|
345
|
+
const without = n.slice(0, n.length - m[0].length);
|
|
346
|
+
const swapMap = {
|
|
347
|
+
js: ['.ts', '.tsx'], jsx: ['.tsx', '.ts'],
|
|
348
|
+
mjs: ['.mts', '.ts'], cjs: ['.cts', '.ts'],
|
|
349
|
+
};
|
|
350
|
+
for (const ext of swapMap[m[1]] || []) {
|
|
351
|
+
const cand = without + ext;
|
|
352
|
+
if (fileExists(cand))
|
|
353
|
+
return cand;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (dirExists(n)) {
|
|
357
|
+
for (const idx of INDEX_FILES) {
|
|
358
|
+
const cand = n + '/' + idx;
|
|
359
|
+
if (fileExists(cand))
|
|
360
|
+
return cand;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return null;
|
|
364
|
+
};
|
|
365
|
+
// Subpath imports (`#X`) → resolve via the importing module's owning
|
|
366
|
+
// package.json `imports` field. Walks up from `fromDir` looking for
|
|
367
|
+
// package.json; first one with `#X` in its `imports` map wins.
|
|
368
|
+
// Reuses `resolveExports` (provided by the pre-bundle preamble) since
|
|
369
|
+
// imports/exports share the same shape (subpath → conditions →
|
|
370
|
+
// target).
|
|
371
|
+
//
|
|
372
|
+
// This is the slice-path counterpart to esbuild-service.ts's
|
|
373
|
+
// `resolvePackageImport` (which serves the supervisor's in-process
|
|
374
|
+
// bundler). Both must walk up only as far as the first package.json —
|
|
375
|
+
// Node's spec is "imports field of the importing module's package",
|
|
376
|
+
// never the parent's.
|
|
377
|
+
//
|
|
378
|
+
// Without this, packages like vfile / unified / remark / mdx (heavy
|
|
379
|
+
// users of `#minpath` / `#minurl` / `#minproc`) leak literal `#X`
|
|
380
|
+
// specifiers into the bundle output, and the browser then chokes
|
|
381
|
+
// with `Failed to resolve module specifier "#minpath"`. Fix: resolve
|
|
382
|
+
// here so the bundle output references the actual file path.
|
|
383
|
+
const resolvePackageImport = (specifier, fromDir) => {
|
|
384
|
+
let dir = stripLeadingSlash(fromDir);
|
|
385
|
+
const visited = new Set();
|
|
386
|
+
while (dir && !visited.has(dir)) {
|
|
387
|
+
visited.add(dir);
|
|
388
|
+
const pkgJsonPath = '/' + dir + '/package.json';
|
|
389
|
+
if (fileExists(pkgJsonPath)) {
|
|
390
|
+
try {
|
|
391
|
+
const pkgJsonText = new TextDecoder().decode(fileMap.get(norm(pkgJsonPath)));
|
|
392
|
+
const pkgJson = JSON.parse(pkgJsonText);
|
|
393
|
+
if (pkgJson && pkgJson.imports) {
|
|
394
|
+
// @ts-ignore — preamble symbol.
|
|
395
|
+
const target = resolveExports(pkgJson.imports, specifier);
|
|
396
|
+
if (target) {
|
|
397
|
+
const r = tryResolve('/' + dir + '/' + target.replace(/^\.\//, ''));
|
|
398
|
+
if (r)
|
|
399
|
+
return r;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
catch { /* malformed package.json — keep walking */ }
|
|
404
|
+
// First package.json wins regardless of whether it had `imports`
|
|
405
|
+
// (Node spec). Stop here even on a miss.
|
|
406
|
+
return null;
|
|
407
|
+
}
|
|
408
|
+
const lastSlash = dir.lastIndexOf('/');
|
|
409
|
+
if (lastSlash <= 0)
|
|
410
|
+
break;
|
|
411
|
+
dir = dir.substring(0, lastSlash);
|
|
412
|
+
}
|
|
413
|
+
return null;
|
|
414
|
+
};
|
|
415
|
+
// Conditions per-resolution. CJS `require('X')` callers need the
|
|
416
|
+
// `require` condition selected so packages that ship a dual-export
|
|
417
|
+
// CJS trick (e.g. @babel/runtime/helpers/X — `module.exports = fn;
|
|
418
|
+
// module.exports.default = module.exports;`) resolve to the CJS
|
|
419
|
+
// file. The ESM helper file (`./helpers/esm/X.js`) declares only
|
|
420
|
+
// `export { fn as default }`, which esbuild's __toCommonJS wrap
|
|
421
|
+
// would surface to a CJS require as `{ default: fn }` — and the
|
|
422
|
+
// downstream callsite `_objectWithoutPropertiesLoose2(...)` calls
|
|
423
|
+
// the namespace as a function and crashes with
|
|
424
|
+
// `_objectWithoutPropertiesLoose2 is not a function` at runtime.
|
|
425
|
+
//
|
|
426
|
+
// This is the same logic Node uses: `require()` triggers the
|
|
427
|
+
// `require` condition, `import` triggers `import`. esbuild's own
|
|
428
|
+
// resolver does this when it owns resolution; we own it via the
|
|
429
|
+
// VFS plugin, so we must pass conditions through ourselves.
|
|
430
|
+
//
|
|
431
|
+
// Affects every CJS-shipping npm package that depends on
|
|
432
|
+
// `@babel/runtime/helpers/*` (thousands — anything compiled with
|
|
433
|
+
// @babel/preset-env's `transform-runtime`). Verified to fix:
|
|
434
|
+
// - react-textarea-autosize → Markflow's /write route
|
|
435
|
+
// - @emotion/* CJS bundles
|
|
436
|
+
// - downstream of `babel-plugin-transform-runtime`
|
|
437
|
+
const ESM_CONDITIONS = ['import', 'module', 'browser', 'default'];
|
|
438
|
+
const CJS_CONDITIONS = ['require', 'node', 'browser', 'default'];
|
|
439
|
+
// Bare specifier → entry path resolution. Mirrors EsbuildService's
|
|
440
|
+
// makeVfsPlugin.resolveBarePkg but reads from fileMap.
|
|
441
|
+
const resolveBarePkg = (specifier, fromDir, conditions) => {
|
|
442
|
+
let pkgName, subpath;
|
|
443
|
+
if (specifier.startsWith('@')) {
|
|
444
|
+
const parts = specifier.split('/');
|
|
445
|
+
pkgName = parts.slice(0, 2).join('/');
|
|
446
|
+
subpath = parts.slice(2).join('/');
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
const parts = specifier.split('/');
|
|
450
|
+
pkgName = parts[0];
|
|
451
|
+
subpath = parts.slice(1).join('/');
|
|
452
|
+
}
|
|
453
|
+
let dir = stripLeadingSlash(fromDir);
|
|
454
|
+
const visited = new Set();
|
|
455
|
+
while (dir && !visited.has(dir)) {
|
|
456
|
+
visited.add(dir);
|
|
457
|
+
const nm = '/' + dir + '/node_modules/' + pkgName;
|
|
458
|
+
if (dirExists(nm)) {
|
|
459
|
+
const pkgJsonPath = nm + '/package.json';
|
|
460
|
+
if (fileExists(pkgJsonPath)) {
|
|
461
|
+
try {
|
|
462
|
+
const pkgJsonText = new TextDecoder().decode(fileMap.get(pkgJsonPath));
|
|
463
|
+
const pkgJson = JSON.parse(pkgJsonText);
|
|
464
|
+
const subKey = subpath ? './' + subpath : '.';
|
|
465
|
+
// @ts-ignore — `resolvePackageEntry` is provided by the
|
|
466
|
+
// pre-bundle preamble at facet-load time; no static import.
|
|
467
|
+
const entry = resolvePackageEntry(pkgJson, subKey, conditions);
|
|
468
|
+
if (entry) {
|
|
469
|
+
const r = tryResolve(nm + '/' + entry.replace(/^\.\//, ''));
|
|
470
|
+
if (r)
|
|
471
|
+
return r;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
catch { /* fall through */ }
|
|
475
|
+
}
|
|
476
|
+
if (subpath) {
|
|
477
|
+
const r = tryResolve(nm + '/' + subpath);
|
|
478
|
+
if (r)
|
|
479
|
+
return r;
|
|
480
|
+
}
|
|
481
|
+
const r2 = tryResolve(nm + '/index');
|
|
482
|
+
if (r2)
|
|
483
|
+
return r2;
|
|
484
|
+
}
|
|
485
|
+
const lastSlash = dir.lastIndexOf('/');
|
|
486
|
+
if (lastSlash <= 0)
|
|
487
|
+
break;
|
|
488
|
+
dir = dir.substring(0, lastSlash);
|
|
489
|
+
}
|
|
490
|
+
return null;
|
|
491
|
+
};
|
|
492
|
+
const externalSet = new Set();
|
|
493
|
+
const externalPrefixes = [];
|
|
494
|
+
for (const pat of spec.externals) {
|
|
495
|
+
if (pat.endsWith('/*'))
|
|
496
|
+
externalPrefixes.push(pat.slice(0, -1));
|
|
497
|
+
else
|
|
498
|
+
externalSet.add(pat);
|
|
499
|
+
}
|
|
500
|
+
const isExternal = (s) => {
|
|
501
|
+
if (externalSet.has(s))
|
|
502
|
+
return true;
|
|
503
|
+
for (const pre of externalPrefixes)
|
|
504
|
+
if (s.startsWith(pre))
|
|
505
|
+
return true;
|
|
506
|
+
return false;
|
|
507
|
+
};
|
|
508
|
+
const inferLoader = (path) => {
|
|
509
|
+
if (path.endsWith('.ts') || path.endsWith('.mts') || path.endsWith('.cts'))
|
|
510
|
+
return 'ts';
|
|
511
|
+
if (path.endsWith('.tsx'))
|
|
512
|
+
return 'tsx';
|
|
513
|
+
if (path.endsWith('.jsx'))
|
|
514
|
+
return 'jsx';
|
|
515
|
+
if (path.endsWith('.json'))
|
|
516
|
+
return 'json';
|
|
517
|
+
if (path.endsWith('.css'))
|
|
518
|
+
return 'css';
|
|
519
|
+
if (path.endsWith('.wasm') || path.endsWith('.node'))
|
|
520
|
+
return 'binary';
|
|
521
|
+
return 'js';
|
|
522
|
+
};
|
|
523
|
+
const plugin = {
|
|
524
|
+
name: 'nimbus-pre-bundle-slice',
|
|
525
|
+
setup(build) {
|
|
526
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
527
|
+
// Subpath imports (#X) — resolve against the importing module's
|
|
528
|
+
// owning package.json `imports` field (Node spec). Done BEFORE
|
|
529
|
+
// the bare/external/absolute branches so a #X never falls
|
|
530
|
+
// through to `external` (which would leak it to the browser
|
|
531
|
+
// and crash the preview with "Failed to resolve module
|
|
532
|
+
// specifier #X").
|
|
533
|
+
if (args.path.startsWith('#') && args.resolveDir) {
|
|
534
|
+
const r = resolvePackageImport(args.path, args.resolveDir);
|
|
535
|
+
if (r)
|
|
536
|
+
return { path: r, namespace: 'nimbus-slice' };
|
|
537
|
+
// Fall through to `external` only as a last resort. We log a
|
|
538
|
+
// warning so the supervisor can surface "looks like #X is
|
|
539
|
+
// unresolved" rather than the user seeing an opaque crash.
|
|
540
|
+
warnings.push(`unresolved subpath import "${args.path}" from ${args.importer || '?'} ` +
|
|
541
|
+
`(no owning package.json#imports entry); marked external`);
|
|
542
|
+
return { external: true };
|
|
543
|
+
}
|
|
544
|
+
// Bare external — leave for the browser to resolve.
|
|
545
|
+
if (!args.path.startsWith('/') && !args.path.startsWith('.') && !args.path.startsWith('#')) {
|
|
546
|
+
if (isExternal(args.path))
|
|
547
|
+
return { external: true };
|
|
548
|
+
}
|
|
549
|
+
if (args.path.startsWith('/')) {
|
|
550
|
+
const r = tryResolve(args.path);
|
|
551
|
+
if (r)
|
|
552
|
+
return { path: r, namespace: 'nimbus-slice' };
|
|
553
|
+
}
|
|
554
|
+
if (args.path.startsWith('.') && args.resolveDir) {
|
|
555
|
+
const r = tryResolve(args.resolveDir + '/' + args.path);
|
|
556
|
+
if (r)
|
|
557
|
+
return { path: r, namespace: 'nimbus-slice' };
|
|
558
|
+
}
|
|
559
|
+
if (!args.path.startsWith('/') && !args.path.startsWith('.') && !args.path.startsWith('#')) {
|
|
560
|
+
const fromDir = args.resolveDir || '/home/user';
|
|
561
|
+
// Per Node spec: `require()` selects 'require' condition,
|
|
562
|
+
// `import` selects 'import'. esbuild surfaces this via
|
|
563
|
+
// args.kind. See ESM_CONDITIONS / CJS_CONDITIONS comments
|
|
564
|
+
// above for the bug class this fixes.
|
|
565
|
+
const conditions = args.kind === 'require-call' || args.kind === 'require-resolve'
|
|
566
|
+
? CJS_CONDITIONS
|
|
567
|
+
: ESM_CONDITIONS;
|
|
568
|
+
const r = resolveBarePkg(args.path, fromDir, conditions);
|
|
569
|
+
if (r)
|
|
570
|
+
return { path: r, namespace: 'nimbus-slice' };
|
|
571
|
+
// Mark unresolved as external — same fail-soft behaviour as
|
|
572
|
+
// EsbuildService.makeVfsPlugin, with a warning so the slice
|
|
573
|
+
// walker can be tightened.
|
|
574
|
+
warnings.push(`unresolved bare import "${args.path}" from ${args.importer || '?'} → marked external`);
|
|
575
|
+
return { external: true };
|
|
576
|
+
}
|
|
577
|
+
return { external: true };
|
|
578
|
+
});
|
|
579
|
+
build.onLoad({ filter: /.*/, namespace: 'nimbus-slice' }, (args) => {
|
|
580
|
+
const bytes = fileMap.get(norm(args.path));
|
|
581
|
+
if (!bytes) {
|
|
582
|
+
return { errors: [{ text: 'pre-bundle slice miss: ' + args.path }] };
|
|
583
|
+
}
|
|
584
|
+
const loader = inferLoader(args.path);
|
|
585
|
+
const lastSlash = args.path.lastIndexOf('/');
|
|
586
|
+
const resolveDir = lastSlash > 0 ? args.path.substring(0, lastSlash) : '/';
|
|
587
|
+
if (loader === 'binary') {
|
|
588
|
+
return { contents: bytes, loader, resolveDir };
|
|
589
|
+
}
|
|
590
|
+
const text = new TextDecoder().decode(bytes);
|
|
591
|
+
return { contents: text, loader, resolveDir };
|
|
592
|
+
});
|
|
593
|
+
},
|
|
594
|
+
};
|
|
595
|
+
// 4. Run esbuild.
|
|
596
|
+
try {
|
|
597
|
+
// NOTE: do NOT pass `external: spec.externals` here at the top level.
|
|
598
|
+
// esbuild's top-level external matches by file PATH too — when bundling
|
|
599
|
+
// a subpath like 'react/jsx-runtime', the resolved entry path
|
|
600
|
+
// /home/user/app/node_modules/react/jsx-runtime.js matches the 'react'
|
|
601
|
+
// external and esbuild errors with
|
|
602
|
+
// "The entry point '...' cannot be marked as external"
|
|
603
|
+
//
|
|
604
|
+
// Externals are enforced by the VFS plugin's onResolve callback above
|
|
605
|
+
// (line ~524), which only matches BARE specifiers — never the entry
|
|
606
|
+
// path. This means jsx-runtime CAN externalize 'react' without
|
|
607
|
+
// tripping the entry check, AND react-dom/client CAN externalize
|
|
608
|
+
// 'react' / 'react/jsx-runtime' the same way.
|
|
609
|
+
const result = await esb.build({
|
|
610
|
+
entryPoints: [spec.entryPath.startsWith('/') ? spec.entryPath : '/' + spec.entryPath],
|
|
611
|
+
bundle: true,
|
|
612
|
+
format: 'esm',
|
|
613
|
+
target: 'esnext',
|
|
614
|
+
platform: 'browser',
|
|
615
|
+
write: false,
|
|
616
|
+
conditions: ['import', 'module', 'browser', 'default'],
|
|
617
|
+
mainFields: ['module', 'browser', 'main'],
|
|
618
|
+
define: spec.define && Object.keys(spec.define).length > 0 ? spec.define : undefined,
|
|
619
|
+
plugins: [plugin],
|
|
620
|
+
});
|
|
621
|
+
const out = result.outputFiles?.[0];
|
|
622
|
+
if (!out) {
|
|
623
|
+
return {
|
|
624
|
+
specifier: spec.specifier,
|
|
625
|
+
ok: false,
|
|
626
|
+
esmCode: '',
|
|
627
|
+
errorText: 'no output produced',
|
|
628
|
+
elapsed: Date.now() - t0,
|
|
629
|
+
warnings,
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
return {
|
|
633
|
+
specifier: spec.specifier,
|
|
634
|
+
ok: true,
|
|
635
|
+
esmCode: out.text,
|
|
636
|
+
elapsed: Date.now() - t0,
|
|
637
|
+
warnings,
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
catch (e) {
|
|
641
|
+
const msg = e?.errors?.[0]?.text || e?.message || String(e);
|
|
642
|
+
return {
|
|
643
|
+
specifier: spec.specifier,
|
|
644
|
+
ok: false,
|
|
645
|
+
esmCode: '',
|
|
646
|
+
errorText: msg,
|
|
647
|
+
elapsed: Date.now() - t0,
|
|
648
|
+
warnings,
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
// Re-export so the supervisor can stamp results without re-importing.
|
|
653
|
+
export { BUNDLER_VERSION };
|