@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.
Files changed (408) hide show
  1. package/README.md +219 -0
  2. package/dist/_shared/bytes.d.ts +18 -0
  3. package/dist/_shared/bytes.d.ts.map +1 -0
  4. package/dist/_shared/bytes.js +17 -0
  5. package/dist/_shared/cache-stats.d.ts +146 -0
  6. package/dist/_shared/cache-stats.d.ts.map +1 -0
  7. package/dist/_shared/cache-stats.js +162 -0
  8. package/dist/_shared/exports-resolver.d.ts +76 -0
  9. package/dist/_shared/exports-resolver.d.ts.map +1 -0
  10. package/dist/_shared/exports-resolver.js +284 -0
  11. package/dist/_shared/install-phase.d.ts +47 -0
  12. package/dist/_shared/install-phase.d.ts.map +1 -0
  13. package/dist/_shared/install-phase.js +1 -0
  14. package/dist/_shared/real-node-imports.d.ts +38 -0
  15. package/dist/_shared/real-node-imports.d.ts.map +1 -0
  16. package/dist/_shared/real-node-imports.js +46 -0
  17. package/dist/_shared/retry.d.ts +93 -0
  18. package/dist/_shared/retry.d.ts.map +1 -0
  19. package/dist/_shared/retry.js +161 -0
  20. package/dist/_shared/session-id.d.ts +39 -0
  21. package/dist/_shared/session-id.d.ts.map +1 -0
  22. package/dist/_shared/session-id.js +127 -0
  23. package/dist/_shared/session-router.d.ts +104 -0
  24. package/dist/_shared/session-router.d.ts.map +1 -0
  25. package/dist/_shared/session-router.js +165 -0
  26. package/dist/_shared/w7-frame.d.ts +93 -0
  27. package/dist/_shared/w7-frame.d.ts.map +1 -0
  28. package/dist/_shared/w7-frame.js +402 -0
  29. package/dist/auth/index.d.ts +16 -0
  30. package/dist/auth/index.d.ts.map +1 -0
  31. package/dist/auth/index.js +15 -0
  32. package/dist/auth/middleware.d.ts +85 -0
  33. package/dist/auth/middleware.d.ts.map +1 -0
  34. package/dist/auth/middleware.js +150 -0
  35. package/dist/auth/token.d.ts +96 -0
  36. package/dist/auth/token.d.ts.map +1 -0
  37. package/dist/auth/token.js +226 -0
  38. package/dist/auth/types.d.ts +141 -0
  39. package/dist/auth/types.d.ts.map +1 -0
  40. package/dist/auth/types.js +114 -0
  41. package/dist/bindings/d1.d.ts +102 -0
  42. package/dist/bindings/d1.d.ts.map +1 -0
  43. package/dist/bindings/d1.js +549 -0
  44. package/dist/bindings/kv.d.ts +82 -0
  45. package/dist/bindings/kv.d.ts.map +1 -0
  46. package/dist/bindings/kv.js +290 -0
  47. package/dist/bindings/r2.d.ts +137 -0
  48. package/dist/bindings/r2.d.ts.map +1 -0
  49. package/dist/bindings/r2.js +379 -0
  50. package/dist/cirrus-npm-cjs.generated.d.ts +17 -0
  51. package/dist/cirrus-npm-cjs.generated.d.ts.map +1 -0
  52. package/dist/cirrus-npm-cjs.generated.js +41 -0
  53. package/dist/cirrus-plugin-react.generated.d.ts +34 -0
  54. package/dist/cirrus-plugin-react.generated.d.ts.map +1 -0
  55. package/dist/cirrus-plugin-react.generated.js +33 -0
  56. package/dist/constants.d.ts +34 -0
  57. package/dist/constants.d.ts.map +1 -0
  58. package/dist/constants.js +116 -0
  59. package/dist/esbuild-wasm-bundle.generated.d.ts +41 -0
  60. package/dist/esbuild-wasm-bundle.generated.d.ts.map +1 -0
  61. package/dist/esbuild-wasm-bundle.generated.js +40 -0
  62. package/dist/facets/cirrus-real.d.ts +147 -0
  63. package/dist/facets/cirrus-real.d.ts.map +1 -0
  64. package/dist/facets/cirrus-real.js +981 -0
  65. package/dist/facets/inner-do-registry.d.ts +41 -0
  66. package/dist/facets/inner-do-registry.d.ts.map +1 -0
  67. package/dist/facets/inner-do-registry.js +51 -0
  68. package/dist/facets/manager.d.ts +314 -0
  69. package/dist/facets/manager.d.ts.map +1 -0
  70. package/dist/facets/manager.js +2681 -0
  71. package/dist/facets/process.d.ts +318 -0
  72. package/dist/facets/process.d.ts.map +1 -0
  73. package/dist/facets/process.js +567 -0
  74. package/dist/facets/real-vite-fs-shim.d.ts +151 -0
  75. package/dist/facets/real-vite-fs-shim.d.ts.map +1 -0
  76. package/dist/facets/real-vite-fs-shim.js +1279 -0
  77. package/dist/facets/real-vite-hmr.d.ts +142 -0
  78. package/dist/facets/real-vite-hmr.d.ts.map +1 -0
  79. package/dist/facets/real-vite-hmr.js +476 -0
  80. package/dist/facets/vite-dev-server.d.ts +293 -0
  81. package/dist/facets/vite-dev-server.d.ts.map +1 -0
  82. package/dist/facets/vite-dev-server.js +2580 -0
  83. package/dist/facets/wasm-swap-registry.d.ts +261 -0
  84. package/dist/facets/wasm-swap-registry.d.ts.map +1 -0
  85. package/dist/facets/wasm-swap-registry.js +551 -0
  86. package/dist/facets/ws-terminal.d.ts +107 -0
  87. package/dist/facets/ws-terminal.d.ts.map +1 -0
  88. package/dist/facets/ws-terminal.js +207 -0
  89. package/dist/git/commands.d.ts +13 -0
  90. package/dist/git/commands.d.ts.map +1 -0
  91. package/dist/git/commands.js +633 -0
  92. package/dist/git/network-facet.d.ts +61 -0
  93. package/dist/git/network-facet.d.ts.map +1 -0
  94. package/dist/git/network-facet.js +700 -0
  95. package/dist/git-bundle.generated.d.ts +16 -0
  96. package/dist/git-bundle.generated.d.ts.map +1 -0
  97. package/dist/git-bundle.generated.js +15 -0
  98. package/dist/index.d.ts +41 -0
  99. package/dist/index.d.ts.map +1 -0
  100. package/dist/index.js +73 -0
  101. package/dist/loaders/child-process/spawn-facet.d.ts +90 -0
  102. package/dist/loaders/child-process/spawn-facet.d.ts.map +1 -0
  103. package/dist/loaders/child-process/spawn-facet.js +103 -0
  104. package/dist/loaders/child-process/spawn-pool.d.ts +110 -0
  105. package/dist/loaders/child-process/spawn-pool.d.ts.map +1 -0
  106. package/dist/loaders/child-process/spawn-pool.js +161 -0
  107. package/dist/loaders/fanout-pool.d.ts +195 -0
  108. package/dist/loaders/fanout-pool.d.ts.map +1 -0
  109. package/dist/loaders/fanout-pool.js +326 -0
  110. package/dist/loaders/generated-workers.d.ts +26 -0
  111. package/dist/loaders/generated-workers.d.ts.map +1 -0
  112. package/dist/loaders/generated-workers.js +25 -0
  113. package/dist/loaders/index.d.ts +15 -0
  114. package/dist/loaders/index.d.ts.map +1 -0
  115. package/dist/loaders/index.js +13 -0
  116. package/dist/loaders/loader-pool.d.ts +273 -0
  117. package/dist/loaders/loader-pool.d.ts.map +1 -0
  118. package/dist/loaders/loader-pool.js +624 -0
  119. package/dist/loaders/npm-resolve-preamble.d.ts +34 -0
  120. package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -0
  121. package/dist/loaders/npm-resolve-preamble.js +237 -0
  122. package/dist/loaders/pre-bundle-preamble.d.ts +41 -0
  123. package/dist/loaders/pre-bundle-preamble.d.ts.map +1 -0
  124. package/dist/loaders/pre-bundle-preamble.js +114 -0
  125. package/dist/loaders/vendor/codegen.d.ts +24 -0
  126. package/dist/loaders/vendor/codegen.d.ts.map +1 -0
  127. package/dist/loaders/vendor/codegen.js +44 -0
  128. package/dist/loaders/vendor/errors.d.ts +24 -0
  129. package/dist/loaders/vendor/errors.d.ts.map +1 -0
  130. package/dist/loaders/vendor/errors.js +46 -0
  131. package/dist/loaders/vendor/index.d.ts +16 -0
  132. package/dist/loaders/vendor/index.d.ts.map +1 -0
  133. package/dist/loaders/vendor/index.js +11 -0
  134. package/dist/loaders/vendor/pool.d.ts +88 -0
  135. package/dist/loaders/vendor/pool.d.ts.map +1 -0
  136. package/dist/loaders/vendor/pool.js +353 -0
  137. package/dist/loaders/vendor/primitives.d.ts +11 -0
  138. package/dist/loaders/vendor/primitives.d.ts.map +1 -0
  139. package/dist/loaders/vendor/primitives.js +33 -0
  140. package/dist/loaders/vendor/serialize.d.ts +3 -0
  141. package/dist/loaders/vendor/serialize.d.ts.map +1 -0
  142. package/dist/loaders/vendor/serialize.js +25 -0
  143. package/dist/loaders/vendor/types.d.ts +60 -0
  144. package/dist/loaders/vendor/types.d.ts.map +1 -0
  145. package/dist/loaders/vendor/types.js +4 -0
  146. package/dist/npm/cache.d.ts +136 -0
  147. package/dist/npm/cache.d.ts.map +1 -0
  148. package/dist/npm/cache.js +429 -0
  149. package/dist/npm/install-batch-facet.d.ts +129 -0
  150. package/dist/npm/install-batch-facet.d.ts.map +1 -0
  151. package/dist/npm/install-batch-facet.js +598 -0
  152. package/dist/npm/install-facet.d.ts +29 -0
  153. package/dist/npm/install-facet.d.ts.map +1 -0
  154. package/dist/npm/install-facet.js +9 -0
  155. package/dist/npm/installer.d.ts +239 -0
  156. package/dist/npm/installer.d.ts.map +1 -0
  157. package/dist/npm/installer.js +2022 -0
  158. package/dist/npm/npx-install.d.ts +74 -0
  159. package/dist/npm/npx-install.d.ts.map +1 -0
  160. package/dist/npm/npx-install.js +302 -0
  161. package/dist/npm/pre-bundle-facet.d.ts +168 -0
  162. package/dist/npm/pre-bundle-facet.d.ts.map +1 -0
  163. package/dist/npm/pre-bundle-facet.js +653 -0
  164. package/dist/npm/r2-cache.d.ts +286 -0
  165. package/dist/npm/r2-cache.d.ts.map +1 -0
  166. package/dist/npm/r2-cache.js +506 -0
  167. package/dist/npm/resolve-facet.d.ts +202 -0
  168. package/dist/npm/resolve-facet.d.ts.map +1 -0
  169. package/dist/npm/resolve-facet.js +833 -0
  170. package/dist/npm/resolve-one-facet.d.ts +204 -0
  171. package/dist/npm/resolve-one-facet.d.ts.map +1 -0
  172. package/dist/npm/resolve-one-facet.js +437 -0
  173. package/dist/npm/resolver.d.ts +109 -0
  174. package/dist/npm/resolver.d.ts.map +1 -0
  175. package/dist/npm/resolver.js +899 -0
  176. package/dist/npm/tarball-stream.d.ts +85 -0
  177. package/dist/npm/tarball-stream.d.ts.map +1 -0
  178. package/dist/npm/tarball-stream.js +205 -0
  179. package/dist/npm/tarball.d.ts +51 -0
  180. package/dist/npm/tarball.d.ts.map +1 -0
  181. package/dist/npm/tarball.js +185 -0
  182. package/dist/observability/diag-counters.d.ts +292 -0
  183. package/dist/observability/diag-counters.d.ts.map +1 -0
  184. package/dist/observability/diag-counters.js +302 -0
  185. package/dist/observability/heap-estimate.d.ts +166 -0
  186. package/dist/observability/heap-estimate.d.ts.map +1 -0
  187. package/dist/observability/heap-estimate.js +192 -0
  188. package/dist/observability/heavy-alloc-coord.d.ts +95 -0
  189. package/dist/observability/heavy-alloc-coord.d.ts.map +1 -0
  190. package/dist/observability/heavy-alloc-coord.js +149 -0
  191. package/dist/observability/oom-classify.d.ts +56 -0
  192. package/dist/observability/oom-classify.d.ts.map +1 -0
  193. package/dist/observability/oom-classify.js +118 -0
  194. package/dist/observability/oom-discriminator.d.ts +192 -0
  195. package/dist/observability/oom-discriminator.d.ts.map +1 -0
  196. package/dist/observability/oom-discriminator.js +233 -0
  197. package/dist/real-vite-bundle.generated.d.ts +46 -0
  198. package/dist/real-vite-bundle.generated.d.ts.map +1 -0
  199. package/dist/real-vite-bundle.generated.js +53 -0
  200. package/dist/replica/routing.d.ts +171 -0
  201. package/dist/replica/routing.d.ts.map +1 -0
  202. package/dist/replica/routing.js +288 -0
  203. package/dist/replica/suspension.d.ts +36 -0
  204. package/dist/replica/suspension.d.ts.map +1 -0
  205. package/dist/replica/suspension.js +49 -0
  206. package/dist/router/index.d.ts +156 -0
  207. package/dist/router/index.d.ts.map +1 -0
  208. package/dist/router/index.js +220 -0
  209. package/dist/runtime/assets-loader.d.ts +71 -0
  210. package/dist/runtime/assets-loader.d.ts.map +1 -0
  211. package/dist/runtime/assets-loader.js +128 -0
  212. package/dist/runtime/barrel-detect.d.ts +46 -0
  213. package/dist/runtime/barrel-detect.d.ts.map +1 -0
  214. package/dist/runtime/barrel-detect.js +73 -0
  215. package/dist/runtime/barrel-synthesizer.d.ts +181 -0
  216. package/dist/runtime/barrel-synthesizer.d.ts.map +1 -0
  217. package/dist/runtime/barrel-synthesizer.js +541 -0
  218. package/dist/runtime/bun-repl.d.ts +46 -0
  219. package/dist/runtime/bun-repl.d.ts.map +1 -0
  220. package/dist/runtime/bun-repl.js +326 -0
  221. package/dist/runtime/bun-runner.d.ts +66 -0
  222. package/dist/runtime/bun-runner.d.ts.map +1 -0
  223. package/dist/runtime/bun-runner.js +219 -0
  224. package/dist/runtime/clang-runner.d.ts +38 -0
  225. package/dist/runtime/clang-runner.d.ts.map +1 -0
  226. package/dist/runtime/clang-runner.js +1033 -0
  227. package/dist/runtime/comment-strip.d.ts +37 -0
  228. package/dist/runtime/comment-strip.d.ts.map +1 -0
  229. package/dist/runtime/comment-strip.js +74 -0
  230. package/dist/runtime/esbuild-service.d.ts +201 -0
  231. package/dist/runtime/esbuild-service.d.ts.map +1 -0
  232. package/dist/runtime/esbuild-service.js +1444 -0
  233. package/dist/runtime/esbuild-wasm-bytes.d.ts +87 -0
  234. package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -0
  235. package/dist/runtime/esbuild-wasm-bytes.js +131 -0
  236. package/dist/runtime/framework-detect.d.ts +71 -0
  237. package/dist/runtime/framework-detect.d.ts.map +1 -0
  238. package/dist/runtime/framework-detect.js +178 -0
  239. package/dist/runtime/long-running-handle.d.ts +133 -0
  240. package/dist/runtime/long-running-handle.d.ts.map +1 -0
  241. package/dist/runtime/long-running-handle.js +192 -0
  242. package/dist/runtime/node-repl.d.ts +36 -0
  243. package/dist/runtime/node-repl.d.ts.map +1 -0
  244. package/dist/runtime/node-repl.js +293 -0
  245. package/dist/runtime/node-runner.d.ts +111 -0
  246. package/dist/runtime/node-runner.d.ts.map +1 -0
  247. package/dist/runtime/node-runner.js +194 -0
  248. package/dist/runtime/node-shims.d.ts +24 -0
  249. package/dist/runtime/node-shims.d.ts.map +1 -0
  250. package/dist/runtime/node-shims.js +3019 -0
  251. package/dist/runtime/package-manager.d.ts +118 -0
  252. package/dist/runtime/package-manager.d.ts.map +1 -0
  253. package/dist/runtime/package-manager.js +420 -0
  254. package/dist/runtime/port-registry.d.ts +80 -0
  255. package/dist/runtime/port-registry.d.ts.map +1 -0
  256. package/dist/runtime/port-registry.js +166 -0
  257. package/dist/runtime/process-logs-api.d.ts +102 -0
  258. package/dist/runtime/process-logs-api.d.ts.map +1 -0
  259. package/dist/runtime/process-logs-api.js +253 -0
  260. package/dist/runtime/process-logs.d.ts +311 -0
  261. package/dist/runtime/process-logs.d.ts.map +1 -0
  262. package/dist/runtime/process-logs.js +656 -0
  263. package/dist/runtime/process-table.d.ts +65 -0
  264. package/dist/runtime/process-table.d.ts.map +1 -0
  265. package/dist/runtime/process-table.js +107 -0
  266. package/dist/runtime/project-detect.d.ts +21 -0
  267. package/dist/runtime/project-detect.d.ts.map +1 -0
  268. package/dist/runtime/project-detect.js +46 -0
  269. package/dist/runtime/python-repl.d.ts +66 -0
  270. package/dist/runtime/python-repl.d.ts.map +1 -0
  271. package/dist/runtime/python-repl.js +563 -0
  272. package/dist/runtime/python-runner.d.ts +50 -0
  273. package/dist/runtime/python-runner.d.ts.map +1 -0
  274. package/dist/runtime/python-runner.js +870 -0
  275. package/dist/runtime/repl-session.d.ts +160 -0
  276. package/dist/runtime/repl-session.d.ts.map +1 -0
  277. package/dist/runtime/repl-session.js +393 -0
  278. package/dist/runtime/require-resolver.d.ts +52 -0
  279. package/dist/runtime/require-resolver.d.ts.map +1 -0
  280. package/dist/runtime/require-resolver.js +690 -0
  281. package/dist/runtime/router-basename.d.ts +36 -0
  282. package/dist/runtime/router-basename.d.ts.map +1 -0
  283. package/dist/runtime/router-basename.js +310 -0
  284. package/dist/runtime/ruby-repl.d.ts +43 -0
  285. package/dist/runtime/ruby-repl.d.ts.map +1 -0
  286. package/dist/runtime/ruby-repl.js +229 -0
  287. package/dist/runtime/ruby-runner.d.ts +62 -0
  288. package/dist/runtime/ruby-runner.d.ts.map +1 -0
  289. package/dist/runtime/ruby-runner.js +737 -0
  290. package/dist/runtime/runtime-catalog.d.ts +99 -0
  291. package/dist/runtime/runtime-catalog.d.ts.map +1 -0
  292. package/dist/runtime/runtime-catalog.js +183 -0
  293. package/dist/runtime/runtime-registry.d.ts +136 -0
  294. package/dist/runtime/runtime-registry.d.ts.map +1 -0
  295. package/dist/runtime/runtime-registry.js +318 -0
  296. package/dist/runtime/streams.d.ts +13 -0
  297. package/dist/runtime/streams.d.ts.map +1 -0
  298. package/dist/runtime/streams.js +402 -0
  299. package/dist/runtime/wasi-instance.d.ts +190 -0
  300. package/dist/runtime/wasi-instance.d.ts.map +1 -0
  301. package/dist/runtime/wasi-instance.js +2044 -0
  302. package/dist/runtime/wasm-runner.d.ts +117 -0
  303. package/dist/runtime/wasm-runner.d.ts.map +1 -0
  304. package/dist/runtime/wasm-runner.js +705 -0
  305. package/dist/session/bindings.d.ts +168 -0
  306. package/dist/session/bindings.d.ts.map +1 -0
  307. package/dist/session/bindings.js +524 -0
  308. package/dist/session/ctx-exports.d.ts +16 -0
  309. package/dist/session/ctx-exports.d.ts.map +1 -0
  310. package/dist/session/ctx-exports.js +22 -0
  311. package/dist/session/diag.d.ts +62 -0
  312. package/dist/session/diag.d.ts.map +1 -0
  313. package/dist/session/diag.js +118 -0
  314. package/dist/session/fs-watch.d.ts +132 -0
  315. package/dist/session/fs-watch.d.ts.map +1 -0
  316. package/dist/session/fs-watch.js +255 -0
  317. package/dist/session/helpers.d.ts +150 -0
  318. package/dist/session/helpers.d.ts.map +1 -0
  319. package/dist/session/helpers.js +472 -0
  320. package/dist/session/hibernation.d.ts +145 -0
  321. package/dist/session/hibernation.d.ts.map +1 -0
  322. package/dist/session/hibernation.js +385 -0
  323. package/dist/session/init-phases.d.ts +87 -0
  324. package/dist/session/init-phases.d.ts.map +1 -0
  325. package/dist/session/init-phases.js +137 -0
  326. package/dist/session/init.d.ts +46 -0
  327. package/dist/session/init.d.ts.map +1 -0
  328. package/dist/session/init.js +3579 -0
  329. package/dist/session/keys.d.ts +56 -0
  330. package/dist/session/keys.d.ts.map +1 -0
  331. package/dist/session/keys.js +55 -0
  332. package/dist/session/nimbus-session.d.ts +434 -0
  333. package/dist/session/nimbus-session.d.ts.map +1 -0
  334. package/dist/session/nimbus-session.js +1084 -0
  335. package/dist/session/programmatic.d.ts +105 -0
  336. package/dist/session/programmatic.d.ts.map +1 -0
  337. package/dist/session/programmatic.js +326 -0
  338. package/dist/session/replica-routes.d.ts +68 -0
  339. package/dist/session/replica-routes.d.ts.map +1 -0
  340. package/dist/session/replica-routes.js +77 -0
  341. package/dist/session/routes.d.ts +29 -0
  342. package/dist/session/routes.d.ts.map +1 -0
  343. package/dist/session/routes.js +1331 -0
  344. package/dist/session/rpc.d.ts +323 -0
  345. package/dist/session/rpc.d.ts.map +1 -0
  346. package/dist/session/rpc.js +808 -0
  347. package/dist/session/state-store.d.ts +210 -0
  348. package/dist/session/state-store.d.ts.map +1 -0
  349. package/dist/session/state-store.js +459 -0
  350. package/dist/session/supervisor-rpc.d.ts +269 -0
  351. package/dist/session/supervisor-rpc.d.ts.map +1 -0
  352. package/dist/session/supervisor-rpc.js +437 -0
  353. package/dist/session/ws-hibernation-config.d.ts +64 -0
  354. package/dist/session/ws-hibernation-config.d.ts.map +1 -0
  355. package/dist/session/ws-hibernation-config.js +89 -0
  356. package/dist/session/ws.d.ts +95 -0
  357. package/dist/session/ws.d.ts.map +1 -0
  358. package/dist/session/ws.js +395 -0
  359. package/dist/shell/features.d.ts +410 -0
  360. package/dist/shell/features.d.ts.map +1 -0
  361. package/dist/shell/features.js +1885 -0
  362. package/dist/shell/unix-commands.d.ts +15 -0
  363. package/dist/shell/unix-commands.d.ts.map +1 -0
  364. package/dist/shell/unix-commands.js +3703 -0
  365. package/dist/stubs/lifo-ui.d.ts +10 -0
  366. package/dist/stubs/lifo-ui.d.ts.map +1 -0
  367. package/dist/stubs/lifo-ui.js +1 -0
  368. package/dist/tailwind-play.generated.d.ts +19 -0
  369. package/dist/tailwind-play.generated.d.ts.map +1 -0
  370. package/dist/tailwind-play.generated.js +18 -0
  371. package/dist/vfs/dev-provider.d.ts +64 -0
  372. package/dist/vfs/dev-provider.d.ts.map +1 -0
  373. package/dist/vfs/dev-provider.js +191 -0
  374. package/dist/vfs/events.d.ts +51 -0
  375. package/dist/vfs/events.d.ts.map +1 -0
  376. package/dist/vfs/events.js +127 -0
  377. package/dist/vfs/path.d.ts +30 -0
  378. package/dist/vfs/path.d.ts.map +1 -0
  379. package/dist/vfs/path.js +41 -0
  380. package/dist/vfs/seed-project.d.ts +62 -0
  381. package/dist/vfs/seed-project.d.ts.map +1 -0
  382. package/dist/vfs/seed-project.js +1045 -0
  383. package/dist/vfs/sqlite-vfs.d.ts +435 -0
  384. package/dist/vfs/sqlite-vfs.d.ts.map +1 -0
  385. package/dist/vfs/sqlite-vfs.js +1670 -0
  386. package/dist/vfs/symlink-registry.d.ts +64 -0
  387. package/dist/vfs/symlink-registry.d.ts.map +1 -0
  388. package/dist/vfs/symlink-registry.js +137 -0
  389. package/dist/wrangler/nimbus-wrangler.d.ts +157 -0
  390. package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -0
  391. package/dist/wrangler/nimbus-wrangler.js +931 -0
  392. package/package.json +77 -0
  393. package/public/_assets/cirrus-plugin-react.bundle.js +70740 -0
  394. package/public/_assets/esbuild-0.24.2.wasm +0 -0
  395. package/public/_assets/real-vite-bundle.js +101478 -0
  396. package/public/_assets/rollup.wasm +0 -0
  397. package/public/favicon.svg +8 -0
  398. package/public/index.html +565 -0
  399. package/public/s/index.html +2379 -0
  400. package/scripts/bundle-esbuild-wasm.mjs +244 -0
  401. package/scripts/bundle-facet-workers.mjs +137 -0
  402. package/scripts/bundle-git.mjs +118 -0
  403. package/scripts/bundle-npm-cjs.mjs +363 -0
  404. package/scripts/bundle-plugin-react.mjs +480 -0
  405. package/scripts/bundle-real-vite.mjs +959 -0
  406. package/scripts/bundle-runtime.mjs +600 -0
  407. package/scripts/bundle-tailwind-play.mjs +130 -0
  408. package/scripts/patch-lifo-ui.mjs +131 -0
@@ -0,0 +1,690 @@
1
+ /**
2
+ * require-resolver.ts — Server-side dependency graph resolver for Nimbus.
3
+ *
4
+ * Runs on the supervisor (which has synchronous VFS access) to trace
5
+ * all require() calls and build a complete file bundle reachable from
6
+ * the entry point. The output is consumed by `facet-manager.ts`'s
7
+ * `buildPrefetchBundle` (W2.6a) to ship ONLY the reachable set into
8
+ * the dynamic-worker module (rather than every file in node_modules
9
+ * up to the legacy cap).
10
+ *
11
+ * Algorithm:
12
+ * 1. Parse `require('xxx')` / `require("xxx")` / ``require(`xxx`)``
13
+ * and `require.resolve('xxx')` calls from entry code via regex.
14
+ * 2. Resolve each via the SHARED `resolvePackageEntry` helper from
15
+ * src/_shared/exports-resolver.ts — same impl that node-shims
16
+ * and npm-resolver use, so prefetch and runtime always agree on
17
+ * which file `require('xyz')` means (W2.6a D6: no dual impls).
18
+ * 3. Read the resolved file, recursively parse ITS requires.
19
+ * 4. Return Record<string, string> of path → content.
20
+ *
21
+ * Limits (sub-agent §Q1 caveats — extended regex still misses dynamic
22
+ * requires like `require(variable)` and ESM `import` statements; greedy
23
+ * oversampling in facet-manager.ts:buildPrefetchBundle compensates).
24
+ *
25
+ * History: this file was ARC-A-P1 quarantined after W2 because the
26
+ * legacy `buildVfsBundle` walked every file in node_modules. W2.6a
27
+ * de-quarantines it as the primary content-bundle source.
28
+ */
29
+ import { resolvePackageEntry as sharedResolvePackageEntry, resolveExports as sharedResolveExports, DEFAULT_CJS_CONDITIONS, } from '../_shared/exports-resolver.js';
30
+ import { stripCommentsForImports } from './comment-strip.js';
31
+ // Match literal-string require/require.resolve with single, double, or
32
+ // template-literal-no-interp specifier. The plain-string variant is by
33
+ // far the dominant npm pattern; the others catch a long tail of
34
+ // well-known cases (esbuild plugins, vite internals).
35
+ const REQUIRE_RE = /(?:require(?:\.resolve)?\s*\(\s*)(['"`])([^'"`]+?)\1\s*\)/g;
36
+ // X.5-C Fix #1: match ESM `import` and `export … from` statements.
37
+ //
38
+ // Why a second regex (not a unified one): REQUIRE_RE matches require(…)
39
+ // CALL EXPRESSIONS — those can appear anywhere (inside function bodies,
40
+ // conditionals, etc.). ESM import/export are STATEMENTS — they can only
41
+ // appear at the top of a line (modulo whitespace). Anchoring at start-of-
42
+ // line `(^|\n)\s*` avoids matching the substring `import` inside string
43
+ // literals or identifiers like `obj.import`. Same anchor strategy that
44
+ // `looksLikeEsm` in facet-manager.ts uses (precedent set by W3.5 Fix B).
45
+ //
46
+ // Forms covered by IMPORT_RE:
47
+ // import 'x'; ← side-effect (no `from`)
48
+ // import x from 'x'; ← default
49
+ // import * as x from 'x'; ← namespace
50
+ // import {a, b as c} from 'x'; ← named
51
+ // import x, {a} from 'x'; ← mixed default+named
52
+ // export {a, b} from 'x'; ← re-export named
53
+ // export * from 'x'; ← re-export wildcard
54
+ // export * as ns from 'x'; ← re-export wildcard with alias
55
+ // export {default as x} from 'x'; ← named-as-default re-export
56
+ //
57
+ // NOT covered (deliberate):
58
+ // import('x') / import.meta.<x> ← dynamic — needs full parsing;
59
+ // out of scope for prefetch.
60
+ // `import type {…} from 'x'` (TypeScript) ← matched, but the resolver
61
+ // returns null on .d.ts-only
62
+ // specifiers and the walk no-ops.
63
+ //
64
+ // The middle group `[\w*${},\s{}]*` covers the practical identifier /
65
+ // destructuring shapes; alternation `(?:…)?` allows the `from` segment
66
+ // to be omitted (side-effect imports). String literal at the end is a
67
+ // single- or double-quoted spec.
68
+ //
69
+ // X.5-Z5 §3 (extended): leading anchor relaxed from (^|\n) to (^|[\n;}])
70
+ // AND the body widened to optionally allow no-whitespace `import{` /
71
+ // `export{` shapes. Same dual-relaxation as src/facet-manager.ts
72
+ // looksLikeEsm — minified ESM bundles (notably @tailwindcss/vite/dist/
73
+ // index.mjs) put the first `;import{...}from"..."` after a `;` on the
74
+ // same line, which the original anchor missed → prefetch walker silently
75
+ // failed to follow the transitive deps. See audit/sections/X5Z5-build-retro.md §3.
76
+ //
77
+ // Edge: a literal `\nimport x from 'y'` inside a multi-line string would
78
+ // false-positive. The walker no-ops on missed resolutions, so it's a
79
+ // minor wasted-work cost, not a correctness issue.
80
+ const IMPORT_RE = /(?:^|[\n;}])\s*(?:import|export)(?:[\s{][\w*${}\s,]*?\s*from)?\s*(['"])([^'"]+)\1/g;
81
+ const MAX_FILES = 4000;
82
+ const MAX_BYTES = 24 * 1024 * 1024; // 24 MiB raw — facet-manager re-caps on JSON-encoded size.
83
+ function strip(p) { return p.replace(/^\/+/, ''); }
84
+ function normalizePath(p) {
85
+ const segments = p.split('/');
86
+ const out = [];
87
+ for (const seg of segments) {
88
+ if (seg === '..' && out.length > 0)
89
+ out.pop();
90
+ else if (seg !== '.' && seg !== '')
91
+ out.push(seg);
92
+ }
93
+ return out.join('/');
94
+ }
95
+ /**
96
+ * Extension-list probe; mirrors node-shims.ts:__resolveFile so prefetch
97
+ * picks the same on-disk file the runtime require will pick.
98
+ *
99
+ * Mirrors Node's LOAD_AS_FILE + LOAD_AS_DIRECTORY (require_2 spec):
100
+ * 1. LOAD_AS_FILE: base, base.js, base.mjs, base.cjs, base.json.
101
+ * 2. LOAD_AS_DIRECTORY (if base resolves to a directory):
102
+ * a. <base>/package.json#main → recurse.
103
+ * b. <base>/index.{js,cjs,mjs,json}.
104
+ *
105
+ * Bug class C (audit 2026-05-11): step 2a was missing, so prefetch
106
+ * silently dropped any file reachable only via package.json#main from
107
+ * a directory-style require (e.g. `require('./mod')` where mod has
108
+ * main='entry.js' and no index.js).
109
+ */
110
+ function resolveFile(vfs, base) {
111
+ const fileExts = ['', '.js', '.mjs', '.cjs', '.json'];
112
+ for (const ext of fileExts) {
113
+ const p = normalizePath(base + ext);
114
+ if (vfs.exists(p) && !vfs.isDirectory(p))
115
+ return p;
116
+ }
117
+ // LOAD_AS_DIRECTORY: prefer package.json#main over index.*
118
+ const baseTrim = base.replace(/\/+$/, '');
119
+ const pkgJsonPath = normalizePath(baseTrim + '/package.json');
120
+ if (vfs.exists(pkgJsonPath) && !vfs.isDirectory(pkgJsonPath)) {
121
+ let pkg = null;
122
+ try {
123
+ pkg = JSON.parse(vfs.readFileString(pkgJsonPath));
124
+ }
125
+ catch { /* fall through */ }
126
+ if (pkg && typeof pkg.main === 'string' && pkg.main.length > 0) {
127
+ const mainStripped = pkg.main.replace(/^\.\/+/, '').replace(/^\/+/, '');
128
+ const mainBase = baseTrim + '/' + mainStripped;
129
+ // Guard against pkg.main === '.' or empty → would re-enter same base.
130
+ if (mainBase !== base && mainBase !== baseTrim) {
131
+ const resolved = resolveFile(vfs, mainBase);
132
+ if (resolved)
133
+ return resolved;
134
+ }
135
+ }
136
+ }
137
+ const indexExts = ['/index.js', '/index.cjs', '/index.mjs', '/index.json'];
138
+ for (const ext of indexExts) {
139
+ const p = normalizePath(base + ext);
140
+ if (vfs.exists(p) && !vfs.isDirectory(p))
141
+ return p;
142
+ }
143
+ return null;
144
+ }
145
+ /**
146
+ * Resolve a package's entry-point file via the SHARED resolver. The
147
+ * pre-W2.6a implementation here had a hand-rolled `pkg.exports['.']`
148
+ * lookup that ignored conditions, wildcards, and nested condition maps
149
+ * — diverging from runtime semantics. Now both use the same impl.
150
+ *
151
+ * Returns null when no resolution is possible.
152
+ */
153
+ /**
154
+ * X.5-L: extended resolver. Same semantics as the original
155
+ * resolvePkgSubpath (pre-X.5-L) for the common-case paths, plus a
156
+ * legacy-directory-subpath fallback that emits a synthetic stub.
157
+ *
158
+ * Resolution order:
159
+ * 1. `package.json#exports[<subpath>]` via shared resolver, condition=require.
160
+ * 2. For root subpath ('.'): `pkg.main` then `<pkgDir>/index.{js,…}`.
161
+ * 3. For non-root subpath: extension-probe `<pkgDir>/<subpath>` directly.
162
+ * 4. **NEW (X.5-L):** if `<pkgDir>/<subpath>` is a directory, look
163
+ * for a nested `package.json` and follow its `module`/`main`
164
+ * relative to the subpath dir. This is the legacy pre-`exports`
165
+ * convention used by react-remove-scroll-bar/constants and
166
+ * similar (verbatim shape: `<pkgDir>/<sub>/package.json` with
167
+ * `main: "../dist/sub.js"`). Emits a stub at `<pkgDir>/<subpath>.js`
168
+ * (and `<pkgDir>/<subpath>` no-ext) so the runtime resolver
169
+ * finds it through its extension-probe loop without needing
170
+ * a runtime-side fix.
171
+ */
172
+ function resolvePkgSubpathEx(vfs, pkgDir, subpath) {
173
+ const pkgJsonPath = pkgDir + '/package.json';
174
+ if (!vfs.exists(pkgJsonPath)) {
175
+ // No package.json — direct probe (matches node-shims fallback).
176
+ if (subpath === '.') {
177
+ const r = resolveFile(vfs, pkgDir + '/index');
178
+ return r ? { resolved: r } : null;
179
+ }
180
+ const r = resolveFile(vfs, pkgDir + '/' + subpath.replace(/^\.\//, ''));
181
+ if (r)
182
+ return { resolved: r };
183
+ // Even with no parent package.json, attempt the legacy nested-pkg
184
+ // fallback (consistent behaviour across the no-pkgjson branch).
185
+ return tryLegacyDirectorySubpath(vfs, pkgDir, subpath);
186
+ }
187
+ let pkg;
188
+ try {
189
+ pkg = JSON.parse(vfs.readFileString(pkgJsonPath));
190
+ }
191
+ catch {
192
+ const r = resolveFile(vfs, pkgDir + '/index');
193
+ return r ? { resolved: r } : null;
194
+ }
195
+ const entry = sharedResolvePackageEntry(pkg, subpath, DEFAULT_CJS_CONDITIONS);
196
+ if (entry != null) {
197
+ const resolved = resolveFile(vfs, pkgDir + '/' + entry.replace(/^\.\//, ''));
198
+ if (resolved)
199
+ return { resolved };
200
+ // W2.6a D2 (mirror of node-shims:__resolvePkgSubpath): exports/main
201
+ // yielded a path that doesn't exist on disk. Fall through to the
202
+ // direct-probe path so prefetch and runtime stay in lockstep on
203
+ // packages whose declared entry is unfindable.
204
+ }
205
+ if (subpath === '.') {
206
+ if (typeof pkg.main === 'string') {
207
+ const r = resolveFile(vfs, pkgDir + '/' + pkg.main.replace(/^\.\//, ''));
208
+ if (r)
209
+ return { resolved: r };
210
+ }
211
+ const idx = resolveFile(vfs, pkgDir + '/index');
212
+ return idx ? { resolved: idx } : null;
213
+ }
214
+ // Non-root subpath: extension-probe first (most common path).
215
+ const direct = resolveFile(vfs, pkgDir + '/' + subpath.replace(/^\.\//, ''));
216
+ if (direct)
217
+ return { resolved: direct };
218
+ // X.5-L: legacy directory-with-nested-package.json fallback. Only
219
+ // engaged when the standard probes have failed AND
220
+ // `<pkgDir>/<subpath>` exists as a directory.
221
+ return tryLegacyDirectorySubpath(vfs, pkgDir, subpath);
222
+ }
223
+ /**
224
+ * X.5-L: legacy pre-`exports`-field subpath convention.
225
+ *
226
+ * If `<pkgDir>/<subpath>` is a directory containing its own
227
+ * `package.json`, follow that nested package.json's `module`/`main`
228
+ * (in CJS-condition order: main → module) as a path relative to the
229
+ * **subpath directory** (so `main: "../dist/x.js"` resolves to
230
+ * `<pkgDir>/dist/x.js`).
231
+ *
232
+ * Returns the real resolved file plus a synthetic stub to inject at
233
+ * `<pkgDir>/<subpath>.js`. The stub is a CJS one-liner that
234
+ * re-exports the real target via a relative require — chosen over
235
+ * duplicating the file content so we don't double-apply the
236
+ * ESM→CJS transform in facet-manager.
237
+ *
238
+ * Returns null if there's no directory match or no readable nested
239
+ * package.json (caller falls through to its existing null return).
240
+ */
241
+ function tryLegacyDirectorySubpath(vfs, pkgDir, subpath) {
242
+ if (subpath === '.' || !subpath.startsWith('./'))
243
+ return null;
244
+ const subRelative = subpath.replace(/^\.\//, '');
245
+ const subDir = normalizePath(pkgDir + '/' + subRelative);
246
+ if (!vfs.exists(subDir) || !vfs.isDirectory(subDir))
247
+ return null;
248
+ const nestedPkgJson = subDir + '/package.json';
249
+ if (!vfs.exists(nestedPkgJson)) {
250
+ // Last-resort: probe `<subDir>/index.{js,…}`. This is already
251
+ // covered by `resolveFile(pkgDir + '/' + subRelative)`'s
252
+ // `/index.js` suffix probe, so reaching here means everything
253
+ // missed — return null.
254
+ return null;
255
+ }
256
+ let nested;
257
+ try {
258
+ nested = JSON.parse(vfs.readFileString(nestedPkgJson));
259
+ }
260
+ catch {
261
+ return null;
262
+ }
263
+ // Prefer `main` for CJS conditions; fall back to `module` if no main.
264
+ // (resolvePackageEntry would do the same prioritisation, but nested
265
+ // package.json files often only declare one of the two.)
266
+ const nestedEntry = (typeof nested.main === 'string' && nested.main) ||
267
+ (typeof nested.module === 'string' && nested.module) ||
268
+ null;
269
+ if (!nestedEntry)
270
+ return null;
271
+ // Resolve relative to the subpath dir; nestedEntry can be
272
+ // up-pointing (`../dist/x.js`) or relative-down (`./dist/x.js`).
273
+ const targetPath = normalizePath(subDir + '/' + nestedEntry.replace(/^\.\//, ''));
274
+ const resolved = resolveFile(vfs, targetPath);
275
+ if (!resolved)
276
+ return null;
277
+ // Build the stub. The stub lives at `<pkgDir>/<subRelative>.js`
278
+ // (matches the runtime resolver's `.js` extension probe). Its
279
+ // modDir is the directory of the stub path.
280
+ const stubPath = normalizePath(pkgDir + '/' + subRelative + '.js');
281
+ const stubDir = stubPath.includes('/') ? stubPath.substring(0, stubPath.lastIndexOf('/')) : '.';
282
+ const stubRelTarget = relativeFrom(stubDir, resolved);
283
+ const stubContent = `// X.5-L synthetic stub: re-export legacy directory-subpath target\n` +
284
+ `module.exports = require(${JSON.stringify('./' + stubRelTarget)});\n`;
285
+ return {
286
+ resolved,
287
+ stub: { path: stubPath, content: stubContent },
288
+ };
289
+ }
290
+ /**
291
+ * Compute a relative path from `fromDir` to `toPath`. Both are
292
+ * expected as VFS-style slash-separated paths with no leading slash.
293
+ * The result is a slash-separated relative path WITHOUT a leading
294
+ * `./` (caller adds the prefix if needed for require()).
295
+ *
296
+ * Examples:
297
+ * relativeFrom('a/b', 'a/c/d.js') → '../c/d.js'
298
+ * relativeFrom('a/b', 'a/b/c.js') → 'c.js'
299
+ * relativeFrom('a', 'a/b/c.js') → 'b/c.js'
300
+ */
301
+ function relativeFrom(fromDir, toPath) {
302
+ const f = fromDir.split('/').filter(s => s.length > 0);
303
+ const t = toPath.split('/').filter(s => s.length > 0);
304
+ let i = 0;
305
+ while (i < f.length && i < t.length && f[i] === t[i])
306
+ i++;
307
+ const ups = f.length - i;
308
+ const downs = t.slice(i);
309
+ const parts = [];
310
+ for (let k = 0; k < ups; k++)
311
+ parts.push('..');
312
+ for (const d of downs)
313
+ parts.push(d);
314
+ return parts.join('/') || '.';
315
+ }
316
+ /**
317
+ * X.5-L: extended bare-spec resolver that also returns any synthetic
318
+ * stub emitted by resolvePkgSubpathEx's legacy-directory branch.
319
+ */
320
+ function resolveNodeModuleEx(vfs, name, fromDir) {
321
+ let pkgName;
322
+ let subpath;
323
+ if (name.startsWith('@')) {
324
+ const parts = name.split('/');
325
+ if (parts.length < 2)
326
+ return null;
327
+ pkgName = parts.slice(0, 2).join('/');
328
+ subpath = parts.length > 2 ? './' + parts.slice(2).join('/') : '.';
329
+ }
330
+ else {
331
+ const slashIdx = name.indexOf('/');
332
+ if (slashIdx > 0) {
333
+ pkgName = name.substring(0, slashIdx);
334
+ subpath = './' + name.substring(slashIdx + 1);
335
+ }
336
+ else {
337
+ pkgName = name;
338
+ subpath = '.';
339
+ }
340
+ }
341
+ let dir = strip(fromDir);
342
+ const visited = new Set();
343
+ while (true) {
344
+ if (visited.has(dir))
345
+ break;
346
+ visited.add(dir);
347
+ const nmDir = (dir ? dir + '/' : '') + 'node_modules/' + pkgName;
348
+ if (vfs.exists(nmDir)) {
349
+ const r = resolvePkgSubpathEx(vfs, nmDir, subpath);
350
+ if (r)
351
+ return r;
352
+ }
353
+ if (!dir)
354
+ break;
355
+ const lastSlash = dir.lastIndexOf('/');
356
+ dir = lastSlash > 0 ? dir.substring(0, lastSlash) : '';
357
+ }
358
+ return null;
359
+ }
360
+ /**
361
+ * X.5-L: extended require-resolver that surfaces synthetic stubs.
362
+ * Used by `prefetchForRequire` to inject runtime-side stubs for
363
+ * the legacy directory-subpath pattern. Relative paths never need
364
+ * stubs, so for those we just return `{ resolved }` with no stub.
365
+ */
366
+ function resolveRequireEx(vfs, id, fromDir) {
367
+ if (id.startsWith('./') || id.startsWith('../') || id.startsWith('/')) {
368
+ const base = id.startsWith('/')
369
+ ? strip(id)
370
+ : normalizePath(strip(fromDir) + '/' + id);
371
+ const r = resolveFile(vfs, base);
372
+ return r ? { resolved: r } : null;
373
+ }
374
+ // package.json#imports field — `#name` specifiers resolved against
375
+ // the nearest enclosing package.json's `imports` map. Mirrors the
376
+ // runtime __resolveImportsField at node-shims.ts:2635. Without this
377
+ // branch, prefetch would fall through to resolveNodeModuleEx (which
378
+ // treats `#name` as a node_module name → never finds the file),
379
+ // and the imports-field target would never be shipped into the
380
+ // bundle. At runtime, __resolveImportsField would correctly compute
381
+ // the target path, but __resolveFile would then return null because
382
+ // the file wasn't bundled — surfacing as a misleading
383
+ // "Cannot find module '#name' (from ...)" error.
384
+ //
385
+ // See .seal-internal/2026-05-11-chalk-imports-field/audit.md.
386
+ if (id.startsWith('#')) {
387
+ const r = resolveImportsField(vfs, id, fromDir);
388
+ return r ? { resolved: r } : null;
389
+ }
390
+ return resolveNodeModuleEx(vfs, id, fromDir);
391
+ }
392
+ /**
393
+ * Resolve an imports-field specifier `#name` against the nearest
394
+ * enclosing package.json. Returns the resolved file path (or null
395
+ * if not found). Mirrors node-shims.ts:__resolveImportsField.
396
+ */
397
+ function resolveImportsField(vfs, name, fromDir) {
398
+ let dir = strip(fromDir);
399
+ while (true) {
400
+ const pkgJsonPath = (dir ? dir + '/' : '') + 'package.json';
401
+ if (vfs.exists(pkgJsonPath) && !vfs.isDirectory(pkgJsonPath)) {
402
+ let pkg = null;
403
+ try {
404
+ pkg = JSON.parse(vfs.readFileString(pkgJsonPath));
405
+ }
406
+ catch { /* malformed */ }
407
+ // First package.json wins (Node spec), even if no imports field.
408
+ if (pkg && pkg.imports) {
409
+ const target = sharedResolveExports(pkg.imports, name, DEFAULT_CJS_CONDITIONS);
410
+ if (target && typeof target === 'string') {
411
+ // imports targets are relative to the package root (`dir`).
412
+ if (target.startsWith('./')) {
413
+ const base = (dir ? dir + '/' : '') + target.slice(2);
414
+ return resolveFile(vfs, normalizePath(base));
415
+ }
416
+ if (target.startsWith('/')) {
417
+ return resolveFile(vfs, strip(target));
418
+ }
419
+ // Bare specifier — re-resolve as a node_module from `dir`.
420
+ const r = resolveNodeModuleEx(vfs, target, dir);
421
+ return r ? r.resolved : null;
422
+ }
423
+ }
424
+ return null;
425
+ }
426
+ if (!dir)
427
+ return null;
428
+ const lastSlash = dir.lastIndexOf('/');
429
+ dir = lastSlash > 0 ? dir.substring(0, lastSlash) : '';
430
+ }
431
+ }
432
+ /**
433
+ * Resolve the complete dependency graph starting from entry code.
434
+ * Returns Record<path, content> + the set of package directories
435
+ * referenced (for greedy oversampling).
436
+ */
437
+ export function prefetchForRequire(vfs, entryCode, cwd, entryFile) {
438
+ const bundle = {};
439
+ const visitedPkgDirs = new Set();
440
+ let totalBytes = 0;
441
+ let fileCount = 0;
442
+ let truncated = false;
443
+ const visited = new Set();
444
+ function trackPkgDir(vfsPath) {
445
+ if (!vfsPath.includes('node_modules/'))
446
+ return;
447
+ const parts = vfsPath.split('/');
448
+ const nmIdx = parts.lastIndexOf('node_modules');
449
+ if (nmIdx < 0)
450
+ return;
451
+ const pkgEnd = parts[nmIdx + 1]?.startsWith('@') ? nmIdx + 3 : nmIdx + 2;
452
+ if (pkgEnd > parts.length)
453
+ return;
454
+ visitedPkgDirs.add(parts.slice(0, pkgEnd).join('/'));
455
+ }
456
+ function addFile(vfsPath) {
457
+ if (visited.has(vfsPath))
458
+ return;
459
+ if (fileCount >= MAX_FILES || totalBytes >= MAX_BYTES) {
460
+ truncated = true;
461
+ return;
462
+ }
463
+ visited.add(vfsPath);
464
+ let content;
465
+ try {
466
+ content = vfs.readFileString(vfsPath);
467
+ }
468
+ catch {
469
+ return;
470
+ }
471
+ if (totalBytes + content.length > MAX_BYTES) {
472
+ truncated = true;
473
+ return;
474
+ }
475
+ bundle[vfsPath] = content;
476
+ totalBytes += content.length;
477
+ fileCount++;
478
+ trackPkgDir(vfsPath);
479
+ // Also add the package.json for the enclosing node_modules package
480
+ // so the runtime resolver can read the same exports/main field we
481
+ // walked here.
482
+ if (vfsPath.includes('node_modules/')) {
483
+ const parts = vfsPath.split('/');
484
+ const nmIdx = parts.lastIndexOf('node_modules');
485
+ if (nmIdx >= 0) {
486
+ const pkgEnd = parts[nmIdx + 1]?.startsWith('@') ? nmIdx + 3 : nmIdx + 2;
487
+ const pkgJsonPath = parts.slice(0, pkgEnd).join('/') + '/package.json';
488
+ if (!visited.has(pkgJsonPath) && vfs.exists(pkgJsonPath)) {
489
+ visited.add(pkgJsonPath);
490
+ try {
491
+ const pkgContent = vfs.readFileString(pkgJsonPath);
492
+ if (totalBytes + pkgContent.length <= MAX_BYTES) {
493
+ bundle[pkgJsonPath] = pkgContent;
494
+ totalBytes += pkgContent.length;
495
+ fileCount++;
496
+ }
497
+ }
498
+ catch { /* ignore */ }
499
+ }
500
+ }
501
+ }
502
+ // Bug class C (audit 2026-05-11): ship every ancestor package.json
503
+ // up to a node_modules boundary so the runtime __resolveFile pkg.main
504
+ // branch can read them. For a path like mod/lib/api.js (resolved
505
+ // via mod/package.json#main='lib/api.js'), the runtime resolver
506
+ // needs mod/package.json in the bundle even though api.js lives
507
+ // one level deeper. Walking up covers nested-main cases.
508
+ //
509
+ // Bound: stops at node_modules boundary (existing block above
510
+ // handles that case) or when we run out of parent dirs. Each step
511
+ // costs one vfs.exists() — typical project depth is 3-5 dirs.
512
+ if (!vfsPath.includes('node_modules/')) {
513
+ let dir = vfsPath;
514
+ while (true) {
515
+ const sl = dir.lastIndexOf('/');
516
+ if (sl <= 0)
517
+ break;
518
+ dir = dir.substring(0, sl);
519
+ const dirPkgJson = dir + '/package.json';
520
+ if (visited.has(dirPkgJson))
521
+ break; // already shipped, stop walking
522
+ if (vfs.exists(dirPkgJson) && !vfs.isDirectory(dirPkgJson)) {
523
+ visited.add(dirPkgJson);
524
+ try {
525
+ const pkgContent = vfs.readFileString(dirPkgJson);
526
+ if (totalBytes + pkgContent.length <= MAX_BYTES) {
527
+ bundle[dirPkgJson] = pkgContent;
528
+ totalBytes += pkgContent.length;
529
+ fileCount++;
530
+ }
531
+ }
532
+ catch { /* ignore */ }
533
+ }
534
+ }
535
+ }
536
+ // Recursively resolve require() calls in this file
537
+ if (vfsPath.endsWith('.js') || vfsPath.endsWith('.mjs') || vfsPath.endsWith('.cjs')) {
538
+ const fromDir = vfsPath.includes('/') ? vfsPath.substring(0, vfsPath.lastIndexOf('/')) : '.';
539
+ parseAndResolve(content, fromDir);
540
+ }
541
+ }
542
+ function parseAndResolve(code, fromDir) {
543
+ // esbuild-ast-rewrite (P3 decision: Option D): strip `//` and
544
+ // `/* */` comments before running IMPORT_RE / REQUIRE_RE so the
545
+ // regexes don't break on embedded comments. Real-world bite:
546
+ // chalk's `import { // eslint-disable-line\n a, b\n} from
547
+ // './utilities.js';` (lines 3-6 of chalk@5.x source/index.js)
548
+ // and its multi-line `export { ... // TODO ... } from
549
+ // './vendor/ansi-styles/index.js';` (lines 196-209) both fail
550
+ // IMPORT_RE's lazy character class because comment characters
551
+ // are not in `[\w*${}\s,]*?`. Stripping comments to whitespace
552
+ // (newline-preserved) makes the rest of the regex match
553
+ // correctly.
554
+ //
555
+ // Why Option D (regex + comment-strip) over Option A (full
556
+ // structured AST extraction via esbuild metafile):
557
+ // - Empirical 100-file session bootstrap with AST: ~553 ms
558
+ // (P2 measurement, /workspace/.seal-internal/2026-05-11-
559
+ // esbuild-ast-rewrite/measure-result.txt). Over the 500 ms
560
+ // decision gate, and that's local Node — workerd-wasm cost
561
+ // is 2-3× higher.
562
+ // - Regex (this preprocessor) per file: ~0.1 ms
563
+ // - Correctness gap closed: chalk's bug case now matches both
564
+ // specifiers AST found but regex missed.
565
+ // See `comment-strip.ts` header + the wave's verdict.md.
566
+ const stripped = stripCommentsForImports(code);
567
+ REQUIRE_RE.lastIndex = 0;
568
+ let match;
569
+ while ((match = REQUIRE_RE.exec(stripped)) !== null) {
570
+ const specifier = match[2];
571
+ if (isBuiltin(specifier))
572
+ continue;
573
+ const r = resolveRequireEx(vfs, specifier, fromDir);
574
+ if (r) {
575
+ addFile(r.resolved);
576
+ if (r.stub)
577
+ addStub(r.stub.path, r.stub.content);
578
+ }
579
+ }
580
+ // X.5-C Fix #1: also follow ESM `import`/`export … from` statements.
581
+ // Without this, packages whose `module` entry is ESM (react-remove-
582
+ // scroll, pathe, ESM nuxt deps, etc.) have their entry file in the
583
+ // bundle but none of the relative `import './x'` siblings — at
584
+ // runtime W3.5 Fix B's CJS rewrite calls require('./x') which then
585
+ // fails because `x` was never added.
586
+ IMPORT_RE.lastIndex = 0;
587
+ while ((match = IMPORT_RE.exec(stripped)) !== null) {
588
+ const specifier = match[2];
589
+ if (isBuiltin(specifier))
590
+ continue;
591
+ const r = resolveRequireEx(vfs, specifier, fromDir);
592
+ if (r) {
593
+ addFile(r.resolved);
594
+ if (r.stub)
595
+ addStub(r.stub.path, r.stub.content);
596
+ }
597
+ }
598
+ }
599
+ /**
600
+ * X.5-L: inject a synthetic stub into the bundle. Stubs are
601
+ * produced by resolvePkgSubpathEx's legacy-directory branch — they
602
+ * sit at the path the runtime resolver probes for (e.g.
603
+ * `<pkgDir>/<subpath>.js`) and re-export the real resolved file.
604
+ *
605
+ * We deliberately skip the recursion + package.json piggyback that
606
+ * `addFile` does: stubs are leaf one-liners with a single
607
+ * relative require, and the *real* target is added separately by
608
+ * `addFile(resolved)` with normal recursion.
609
+ */
610
+ function addStub(stubPath, content) {
611
+ if (visited.has(stubPath))
612
+ return;
613
+ if (fileCount >= MAX_FILES || totalBytes >= MAX_BYTES) {
614
+ truncated = true;
615
+ return;
616
+ }
617
+ if (totalBytes + content.length > MAX_BYTES) {
618
+ truncated = true;
619
+ return;
620
+ }
621
+ // Don't shadow a real on-disk file: if VFS already has something
622
+ // at this path, skip the stub. (Defence-in-depth — should never
623
+ // happen because the legacy-directory branch only fires when all
624
+ // extension probes missed.)
625
+ if (vfs.exists(stubPath) && !vfs.isDirectory(stubPath))
626
+ return;
627
+ visited.add(stubPath);
628
+ bundle[stubPath] = content;
629
+ totalBytes += content.length;
630
+ fileCount++;
631
+ trackPkgDir(stubPath);
632
+ }
633
+ // Start from entry code.
634
+ //
635
+ // Primitive #1 (primitives-extension wave): the relative-require
636
+ // resolution base is the ENTRY FILE's directory when the caller
637
+ // supplied one (bin shims under node_modules/.bin/, npx-launched
638
+ // scripts, etc.), NOT cwd. Pre-fix, `require('../lib/tsc.js')` from
639
+ // `node_modules/typescript/bin/tsc` resolved against the user's
640
+ // cwd, finding `<cwd>/../lib/tsc.js` which doesn't exist.
641
+ //
642
+ // Falling back to cwd preserves the legacy behaviour for naked
643
+ // entryCode (no file context) — covers the `node -e '<code>'`
644
+ // path where opts.filename is '<eval>'.
645
+ const cwdStripped = strip(cwd);
646
+ let entryFromDir = cwdStripped;
647
+ if (entryFile) {
648
+ const stripped = strip(entryFile);
649
+ const slash = stripped.lastIndexOf('/');
650
+ if (slash > 0)
651
+ entryFromDir = stripped.substring(0, slash);
652
+ }
653
+ parseAndResolve(entryCode, entryFromDir);
654
+ // If there's an entry file, add it (and recurse)
655
+ if (entryFile) {
656
+ const stripped = strip(entryFile);
657
+ addFile(stripped);
658
+ }
659
+ // Also add cwd package.json if it exists (for npm scripts, main field etc)
660
+ const cwdPkg = cwdStripped + '/package.json';
661
+ if (vfs.exists(cwdPkg) && !visited.has(cwdPkg)) {
662
+ try {
663
+ const c = vfs.readFileString(cwdPkg);
664
+ if (totalBytes + c.length <= MAX_BYTES) {
665
+ bundle[cwdPkg] = c;
666
+ totalBytes += c.length;
667
+ fileCount++;
668
+ visited.add(cwdPkg);
669
+ }
670
+ }
671
+ catch { /* ignore */ }
672
+ }
673
+ return { bundle, visitedPkgDirs, truncated };
674
+ }
675
+ const BUILTINS = new Set([
676
+ 'fs', 'path', 'os', 'events', 'stream', 'buffer', 'util', 'url', 'crypto',
677
+ 'assert', 'querystring', 'string_decoder', 'child_process', 'process',
678
+ 'console', 'http', 'https', 'http2', 'net', 'dns', 'tls', 'tty',
679
+ 'module', 'timers', 'zlib', 'readline', 'perf_hooks', 'worker_threads',
680
+ 'vm', 'v8', 'inspector', 'cluster', 'domain', 'punycode', 'wasi',
681
+ 'trace_events', 'dgram', 'sqlite', 'repl',
682
+ ]);
683
+ function isBuiltin(id) {
684
+ if (id.startsWith('node:'))
685
+ return true;
686
+ return BUILTINS.has(id);
687
+ }
688
+ // Note: the shared resolver helpers are imported directly from
689
+ // src/_shared/exports-resolver.js by every caller (W2.6a D6 — single
690
+ // source of truth). No re-export needed here.