@volter/tabnode 0.2.14-volter.88

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 (429) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +78 -0
  3. package/THIRD-PARTY-NOTICES.md +12 -0
  4. package/dist/__sw__.js +526 -0
  5. package/dist/assets/runtime-worker-4MKaHFVb.js +75221 -0
  6. package/dist/assets/runtime-worker-4MKaHFVb.js.map +1 -0
  7. package/dist/code-transforms.d.ts +21 -0
  8. package/dist/code-transforms.d.ts.map +1 -0
  9. package/dist/config/cdn.d.ts +12 -0
  10. package/dist/config/cdn.d.ts.map +1 -0
  11. package/dist/create-runtime.d.ts +22 -0
  12. package/dist/create-runtime.d.ts.map +1 -0
  13. package/dist/host-globals.d.ts +62 -0
  14. package/dist/host-globals.d.ts.map +1 -0
  15. package/dist/index.cjs +36021 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.ts +127 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.mjs +36020 -0
  20. package/dist/index.mjs.map +1 -0
  21. package/dist/node-internals.d.ts +68 -0
  22. package/dist/node-internals.d.ts.map +1 -0
  23. package/dist/node-lib/binding/blob.d.ts +12 -0
  24. package/dist/node-lib/binding/blob.d.ts.map +1 -0
  25. package/dist/node-lib/binding/buffer.d.ts +144 -0
  26. package/dist/node-lib/binding/buffer.d.ts.map +1 -0
  27. package/dist/node-lib/binding/cares_wrap.d.ts +14 -0
  28. package/dist/node-lib/binding/cares_wrap.d.ts.map +1 -0
  29. package/dist/node-lib/binding/fds.d.ts +30 -0
  30. package/dist/node-lib/binding/fds.d.ts.map +1 -0
  31. package/dist/node-lib/binding/fs.d.ts +157 -0
  32. package/dist/node-lib/binding/fs.d.ts.map +1 -0
  33. package/dist/node-lib/binding/handles.d.ts +81 -0
  34. package/dist/node-lib/binding/handles.d.ts.map +1 -0
  35. package/dist/node-lib/binding/http_parser.d.ts +122 -0
  36. package/dist/node-lib/binding/http_parser.d.ts.map +1 -0
  37. package/dist/node-lib/binding/index.d.ts +3 -0
  38. package/dist/node-lib/binding/index.d.ts.map +1 -0
  39. package/dist/node-lib/binding/llhttp-wasm.d.ts +22 -0
  40. package/dist/node-lib/binding/llhttp-wasm.d.ts.map +1 -0
  41. package/dist/node-lib/binding/misc.d.ts +123 -0
  42. package/dist/node-lib/binding/misc.d.ts.map +1 -0
  43. package/dist/node-lib/binding/pipe_wrap.d.ts +84 -0
  44. package/dist/node-lib/binding/pipe_wrap.d.ts.map +1 -0
  45. package/dist/node-lib/binding/process_wrap.d.ts +173 -0
  46. package/dist/node-lib/binding/process_wrap.d.ts.map +1 -0
  47. package/dist/node-lib/binding/spawn_sync.d.ts +30 -0
  48. package/dist/node-lib/binding/spawn_sync.d.ts.map +1 -0
  49. package/dist/node-lib/binding/stream_wrap.d.ts +191 -0
  50. package/dist/node-lib/binding/stream_wrap.d.ts.map +1 -0
  51. package/dist/node-lib/binding/stubs.d.ts +23 -0
  52. package/dist/node-lib/binding/stubs.d.ts.map +1 -0
  53. package/dist/node-lib/binding/tcp_wrap.d.ts +98 -0
  54. package/dist/node-lib/binding/tcp_wrap.d.ts.map +1 -0
  55. package/dist/node-lib/binding/tty_wrap.d.ts +36 -0
  56. package/dist/node-lib/binding/tty_wrap.d.ts.map +1 -0
  57. package/dist/node-lib/binding/util.d.ts +126 -0
  58. package/dist/node-lib/binding/util.d.ts.map +1 -0
  59. package/dist/node-lib/binding/uv.d.ts +32 -0
  60. package/dist/node-lib/binding/uv.d.ts.map +1 -0
  61. package/dist/node-lib/binding/zlib-pako.d.ts +22 -0
  62. package/dist/node-lib/binding/zlib-pako.d.ts.map +1 -0
  63. package/dist/node-lib/binding/zlib.d.ts +38 -0
  64. package/dist/node-lib/binding/zlib.d.ts.map +1 -0
  65. package/dist/node-lib/buffer-module.d.ts +51 -0
  66. package/dist/node-lib/buffer-module.d.ts.map +1 -0
  67. package/dist/node-lib/child-process-module.d.ts +26 -0
  68. package/dist/node-lib/child-process-module.d.ts.map +1 -0
  69. package/dist/node-lib/events-module.d.ts +58 -0
  70. package/dist/node-lib/events-module.d.ts.map +1 -0
  71. package/dist/node-lib/fs-module.d.ts +5 -0
  72. package/dist/node-lib/fs-module.d.ts.map +1 -0
  73. package/dist/node-lib/http-bridge.d.ts +43 -0
  74. package/dist/node-lib/http-bridge.d.ts.map +1 -0
  75. package/dist/node-lib/http-module.d.ts +35 -0
  76. package/dist/node-lib/http-module.d.ts.map +1 -0
  77. package/dist/node-lib/internals/addresses.d.ts +40 -0
  78. package/dist/node-lib/internals/addresses.d.ts.map +1 -0
  79. package/dist/node-lib/internals/buffer-and-streams.d.ts +96 -0
  80. package/dist/node-lib/internals/buffer-and-streams.d.ts.map +1 -0
  81. package/dist/node-lib/internals/child-process.d.ts +27 -0
  82. package/dist/node-lib/internals/child-process.d.ts.map +1 -0
  83. package/dist/node-lib/internals/events-util.d.ts +83 -0
  84. package/dist/node-lib/internals/events-util.d.ts.map +1 -0
  85. package/dist/node-lib/internals/index.d.ts +2 -0
  86. package/dist/node-lib/internals/index.d.ts.map +1 -0
  87. package/dist/node-lib/internals/modules.d.ts +67 -0
  88. package/dist/node-lib/internals/modules.d.ts.map +1 -0
  89. package/dist/node-lib/internals/readline-access.d.ts +2 -0
  90. package/dist/node-lib/internals/readline-access.d.ts.map +1 -0
  91. package/dist/node-lib/internals/runtime.d.ts +150 -0
  92. package/dist/node-lib/internals/runtime.d.ts.map +1 -0
  93. package/dist/node-lib/internals/util.d.ts +33 -0
  94. package/dist/node-lib/internals/util.d.ts.map +1 -0
  95. package/dist/node-lib/lazy.d.ts +31 -0
  96. package/dist/node-lib/lazy.d.ts.map +1 -0
  97. package/dist/node-lib/load.d.ts +27 -0
  98. package/dist/node-lib/load.d.ts.map +1 -0
  99. package/dist/node-lib/module-hooks.d.ts +89 -0
  100. package/dist/node-lib/module-hooks.d.ts.map +1 -0
  101. package/dist/node-lib/net-module.d.ts +181 -0
  102. package/dist/node-lib/net-module.d.ts.map +1 -0
  103. package/dist/node-lib/node-versions.d.ts +27 -0
  104. package/dist/node-lib/node-versions.d.ts.map +1 -0
  105. package/dist/node-lib/public-modules.d.ts +2 -0
  106. package/dist/node-lib/public-modules.d.ts.map +1 -0
  107. package/dist/node-lib/require-hook.d.ts +15 -0
  108. package/dist/node-lib/require-hook.d.ts.map +1 -0
  109. package/dist/node-lib/small-modules.d.ts +16 -0
  110. package/dist/node-lib/small-modules.d.ts.map +1 -0
  111. package/dist/node-lib/sources.d.ts +4 -0
  112. package/dist/node-lib/sources.d.ts.map +1 -0
  113. package/dist/node-lib/stream-module.d.ts +77 -0
  114. package/dist/node-lib/stream-module.d.ts.map +1 -0
  115. package/dist/node-lib/timers.d.ts +19 -0
  116. package/dist/node-lib/timers.d.ts.map +1 -0
  117. package/dist/node-lib/util-module.d.ts +76 -0
  118. package/dist/node-lib/util-module.d.ts.map +1 -0
  119. package/dist/node-resolution.d.ts +50 -0
  120. package/dist/node-resolution.d.ts.map +1 -0
  121. package/dist/node-resolver.d.ts +7 -0
  122. package/dist/node-resolver.d.ts.map +1 -0
  123. package/dist/npm/index.d.ts +73 -0
  124. package/dist/npm/index.d.ts.map +1 -0
  125. package/dist/npm/registry.d.ts +111 -0
  126. package/dist/npm/registry.d.ts.map +1 -0
  127. package/dist/npm/resolver.d.ts +79 -0
  128. package/dist/npm/resolver.d.ts.map +1 -0
  129. package/dist/npm/tarball.d.ts +28 -0
  130. package/dist/npm/tarball.d.ts.map +1 -0
  131. package/dist/process-tokens.d.ts +77 -0
  132. package/dist/process-tokens.d.ts.map +1 -0
  133. package/dist/punycode-source.d.ts +3 -0
  134. package/dist/punycode-source.d.ts.map +1 -0
  135. package/dist/runtime-interface.d.ts +74 -0
  136. package/dist/runtime-interface.d.ts.map +1 -0
  137. package/dist/runtime.d.ts +144 -0
  138. package/dist/runtime.d.ts.map +1 -0
  139. package/dist/server-bridge.d.ts +147 -0
  140. package/dist/server-bridge.d.ts.map +1 -0
  141. package/dist/shims/async_hooks.d.ts +50 -0
  142. package/dist/shims/async_hooks.d.ts.map +1 -0
  143. package/dist/shims/child_process.d.ts +104 -0
  144. package/dist/shims/child_process.d.ts.map +1 -0
  145. package/dist/shims/cluster.d.ts +52 -0
  146. package/dist/shims/cluster.d.ts.map +1 -0
  147. package/dist/shims/command-line.d.ts +43 -0
  148. package/dist/shims/command-line.d.ts.map +1 -0
  149. package/dist/shims/constants.d.ts +222 -0
  150. package/dist/shims/constants.d.ts.map +1 -0
  151. package/dist/shims/crypto-constants.d.ts +12 -0
  152. package/dist/shims/crypto-constants.d.ts.map +1 -0
  153. package/dist/shims/crypto.d.ts +144 -0
  154. package/dist/shims/crypto.d.ts.map +1 -0
  155. package/dist/shims/dgram.d.ts +34 -0
  156. package/dist/shims/dgram.d.ts.map +1 -0
  157. package/dist/shims/dns.d.ts +91 -0
  158. package/dist/shims/dns.d.ts.map +1 -0
  159. package/dist/shims/domain.d.ts +25 -0
  160. package/dist/shims/domain.d.ts.map +1 -0
  161. package/dist/shims/esbuild.d.ts +205 -0
  162. package/dist/shims/esbuild.d.ts.map +1 -0
  163. package/dist/shims/fs.d.ts +25 -0
  164. package/dist/shims/fs.d.ts.map +1 -0
  165. package/dist/shims/http2.d.ts +81 -0
  166. package/dist/shims/http2.d.ts.map +1 -0
  167. package/dist/shims/inspector.d.ts +25 -0
  168. package/dist/shims/inspector.d.ts.map +1 -0
  169. package/dist/shims/module.d.ts +22 -0
  170. package/dist/shims/module.d.ts.map +1 -0
  171. package/dist/shims/os.d.ts +159 -0
  172. package/dist/shims/os.d.ts.map +1 -0
  173. package/dist/shims/path.d.ts +52 -0
  174. package/dist/shims/path.d.ts.map +1 -0
  175. package/dist/shims/perf_hooks.d.ts +50 -0
  176. package/dist/shims/perf_hooks.d.ts.map +1 -0
  177. package/dist/shims/process.d.ts +226 -0
  178. package/dist/shims/process.d.ts.map +1 -0
  179. package/dist/shims/rollup.d.ts +71 -0
  180. package/dist/shims/rollup.d.ts.map +1 -0
  181. package/dist/shims/string_decoder.d.ts +41 -0
  182. package/dist/shims/string_decoder.d.ts.map +1 -0
  183. package/dist/shims/sync-child.d.ts +64 -0
  184. package/dist/shims/sync-child.d.ts.map +1 -0
  185. package/dist/shims/tls.d.ts +53 -0
  186. package/dist/shims/tls.d.ts.map +1 -0
  187. package/dist/shims/url.d.ts +84 -0
  188. package/dist/shims/url.d.ts.map +1 -0
  189. package/dist/shims/v8.d.ts +73 -0
  190. package/dist/shims/v8.d.ts.map +1 -0
  191. package/dist/shims/vfs-adapter.d.ts +126 -0
  192. package/dist/shims/vfs-adapter.d.ts.map +1 -0
  193. package/dist/shims/vm.d.ts +52 -0
  194. package/dist/shims/vm.d.ts.map +1 -0
  195. package/dist/shims/wasi.d.ts +78 -0
  196. package/dist/shims/wasi.d.ts.map +1 -0
  197. package/dist/shims/worker_threads.d.ts +66 -0
  198. package/dist/shims/worker_threads.d.ts.map +1 -0
  199. package/dist/shims/zlib-constants.d.ts +66 -0
  200. package/dist/shims/zlib-constants.d.ts.map +1 -0
  201. package/dist/shims/zlib.d.ts +102 -0
  202. package/dist/shims/zlib.d.ts.map +1 -0
  203. package/dist/transform.d.ts +24 -0
  204. package/dist/transform.d.ts.map +1 -0
  205. package/dist/types/package-json.d.ts +18 -0
  206. package/dist/types/package-json.d.ts.map +1 -0
  207. package/dist/utils/binary-encoding.d.ts +13 -0
  208. package/dist/utils/binary-encoding.d.ts.map +1 -0
  209. package/dist/utils/glob.d.ts +19 -0
  210. package/dist/utils/glob.d.ts.map +1 -0
  211. package/dist/utils/hash.d.ts +6 -0
  212. package/dist/utils/hash.d.ts.map +1 -0
  213. package/dist/virtual-fs.d.ts +259 -0
  214. package/dist/virtual-fs.d.ts.map +1 -0
  215. package/dist/vite-plugin.cjs +50 -0
  216. package/dist/vite-plugin.cjs.map +1 -0
  217. package/dist/vite-plugin.d.ts +36 -0
  218. package/dist/vite-plugin.d.ts.map +1 -0
  219. package/dist/vite-plugin.mjs +31 -0
  220. package/dist/vite-plugin.mjs.map +1 -0
  221. package/dist/worker/runtime-worker.d.ts +8 -0
  222. package/dist/worker/runtime-worker.d.ts.map +1 -0
  223. package/dist/worker-runtime.d.ts +50 -0
  224. package/dist/worker-runtime.d.ts.map +1 -0
  225. package/package.json +88 -0
  226. package/src/code-transforms.ts +560 -0
  227. package/src/config/cdn.ts +13 -0
  228. package/src/create-runtime.ts +89 -0
  229. package/src/host-globals.ts +121 -0
  230. package/src/index.ts +235 -0
  231. package/src/node-internals.ts +283 -0
  232. package/src/node-lib/LICENSE +47 -0
  233. package/src/node-lib/_http_agent.js +547 -0
  234. package/src/node-lib/_http_client.js +996 -0
  235. package/src/node-lib/_http_common.js +269 -0
  236. package/src/node-lib/_http_incoming.js +453 -0
  237. package/src/node-lib/_http_outgoing.js +1262 -0
  238. package/src/node-lib/_http_server.js +1230 -0
  239. package/src/node-lib/assert/strict.js +3 -0
  240. package/src/node-lib/assert.js +844 -0
  241. package/src/node-lib/binding/blob.ts +35 -0
  242. package/src/node-lib/binding/buffer.ts +465 -0
  243. package/src/node-lib/binding/cares_wrap.ts +57 -0
  244. package/src/node-lib/binding/fds.ts +80 -0
  245. package/src/node-lib/binding/fs.ts +857 -0
  246. package/src/node-lib/binding/handles.ts +187 -0
  247. package/src/node-lib/binding/http_parser.ts +536 -0
  248. package/src/node-lib/binding/index.ts +77 -0
  249. package/src/node-lib/binding/llhttp-wasm.ts +670 -0
  250. package/src/node-lib/binding/misc.ts +252 -0
  251. package/src/node-lib/binding/pipe_wrap.ts +166 -0
  252. package/src/node-lib/binding/process_wrap.ts +371 -0
  253. package/src/node-lib/binding/spawn_sync.ts +141 -0
  254. package/src/node-lib/binding/stream_wrap.ts +413 -0
  255. package/src/node-lib/binding/stubs.ts +19 -0
  256. package/src/node-lib/binding/tcp_wrap.ts +254 -0
  257. package/src/node-lib/binding/tty_wrap.ts +56 -0
  258. package/src/node-lib/binding/util.ts +274 -0
  259. package/src/node-lib/binding/uv.ts +102 -0
  260. package/src/node-lib/binding/zlib-pako.ts +50 -0
  261. package/src/node-lib/binding/zlib.ts +259 -0
  262. package/src/node-lib/buffer-module.ts +70 -0
  263. package/src/node-lib/buffer.js +1373 -0
  264. package/src/node-lib/child-process-module.ts +58 -0
  265. package/src/node-lib/child_process.js +1046 -0
  266. package/src/node-lib/constants.js +41 -0
  267. package/src/node-lib/diagnostics_channel.js +438 -0
  268. package/src/node-lib/events-module.ts +80 -0
  269. package/src/node-lib/events.js +1223 -0
  270. package/src/node-lib/fs-module.ts +43 -0
  271. package/src/node-lib/fs.js +3377 -0
  272. package/src/node-lib/http-bridge.ts +299 -0
  273. package/src/node-lib/http-module.ts +53 -0
  274. package/src/node-lib/http.js +198 -0
  275. package/src/node-lib/https.js +429 -0
  276. package/src/node-lib/internal/assert/assertion_error.js +417 -0
  277. package/src/node-lib/internal/assert/calltracker.js +153 -0
  278. package/src/node-lib/internal/assert/myers_diff.js +177 -0
  279. package/src/node-lib/internal/assert/utils.js +278 -0
  280. package/src/node-lib/internal/buffer.js +1120 -0
  281. package/src/node-lib/internal/child_process/serialization.js +169 -0
  282. package/src/node-lib/internal/child_process.js +1135 -0
  283. package/src/node-lib/internal/constants.js +56 -0
  284. package/src/node-lib/internal/deps/minimatch/index.js +1628 -0
  285. package/src/node-lib/internal/errors.js +1912 -0
  286. package/src/node-lib/internal/events/abort_listener.js +54 -0
  287. package/src/node-lib/internal/events/symbols.js +11 -0
  288. package/src/node-lib/internal/fixed_queue.js +119 -0
  289. package/src/node-lib/internal/freelist.js +30 -0
  290. package/src/node-lib/internal/fs/cp/cp-sync.js +242 -0
  291. package/src/node-lib/internal/fs/cp/cp.js +382 -0
  292. package/src/node-lib/internal/fs/dir.js +369 -0
  293. package/src/node-lib/internal/fs/glob.js +763 -0
  294. package/src/node-lib/internal/fs/promises.js +1312 -0
  295. package/src/node-lib/internal/fs/read/context.js +129 -0
  296. package/src/node-lib/internal/fs/recursive_watch.js +275 -0
  297. package/src/node-lib/internal/fs/rimraf.js +311 -0
  298. package/src/node-lib/internal/fs/streams.js +571 -0
  299. package/src/node-lib/internal/fs/sync_write_stream.js +49 -0
  300. package/src/node-lib/internal/fs/utils.js +987 -0
  301. package/src/node-lib/internal/fs/watchers.js +418 -0
  302. package/src/node-lib/internal/http.js +62 -0
  303. package/src/node-lib/internal/mime.js +389 -0
  304. package/src/node-lib/internal/modules/customization_hooks.js +406 -0
  305. package/src/node-lib/internal/net.js +95 -0
  306. package/src/node-lib/internal/querystring.js +119 -0
  307. package/src/node-lib/internal/readline/callbacks.js +132 -0
  308. package/src/node-lib/internal/readline/emitKeypressEvents.js +99 -0
  309. package/src/node-lib/internal/readline/interface.js +1418 -0
  310. package/src/node-lib/internal/readline/promises.js +144 -0
  311. package/src/node-lib/internal/readline/utils.js +405 -0
  312. package/src/node-lib/internal/socket_list.js +108 -0
  313. package/src/node-lib/internal/stream_base_commons.js +280 -0
  314. package/src/node-lib/internal/streams/add-abort-signal.js +60 -0
  315. package/src/node-lib/internal/streams/compose.js +257 -0
  316. package/src/node-lib/internal/streams/destroy.js +361 -0
  317. package/src/node-lib/internal/streams/duplex.js +203 -0
  318. package/src/node-lib/internal/streams/duplexify.js +379 -0
  319. package/src/node-lib/internal/streams/duplexpair.js +62 -0
  320. package/src/node-lib/internal/streams/end-of-stream.js +331 -0
  321. package/src/node-lib/internal/streams/from.js +208 -0
  322. package/src/node-lib/internal/streams/lazy_transform.js +57 -0
  323. package/src/node-lib/internal/streams/legacy.js +125 -0
  324. package/src/node-lib/internal/streams/operators.js +436 -0
  325. package/src/node-lib/internal/streams/passthrough.js +47 -0
  326. package/src/node-lib/internal/streams/pipeline.js +465 -0
  327. package/src/node-lib/internal/streams/readable.js +1762 -0
  328. package/src/node-lib/internal/streams/state.js +51 -0
  329. package/src/node-lib/internal/streams/transform.js +204 -0
  330. package/src/node-lib/internal/streams/utils.js +363 -0
  331. package/src/node-lib/internal/streams/writable.js +1163 -0
  332. package/src/node-lib/internal/tty.js +260 -0
  333. package/src/node-lib/internal/util/colors.js +40 -0
  334. package/src/node-lib/internal/util/comparisons.js +1028 -0
  335. package/src/node-lib/internal/util/debuglog.js +524 -0
  336. package/src/node-lib/internal/util/inspect.js +2535 -0
  337. package/src/node-lib/internal/util/parse_args/parse_args.js +412 -0
  338. package/src/node-lib/internal/util/parse_args/utils.js +197 -0
  339. package/src/node-lib/internal/util.js +1003 -0
  340. package/src/node-lib/internal/validators.js +654 -0
  341. package/src/node-lib/internals/addresses.ts +159 -0
  342. package/src/node-lib/internals/buffer-and-streams.ts +224 -0
  343. package/src/node-lib/internals/child-process.ts +64 -0
  344. package/src/node-lib/internals/events-util.ts +105 -0
  345. package/src/node-lib/internals/index.ts +66 -0
  346. package/src/node-lib/internals/modules.ts +117 -0
  347. package/src/node-lib/internals/readline-access.ts +16 -0
  348. package/src/node-lib/internals/runtime.ts +277 -0
  349. package/src/node-lib/internals/util.ts +98 -0
  350. package/src/node-lib/lazy.ts +158 -0
  351. package/src/node-lib/load.ts +390 -0
  352. package/src/node-lib/module-hooks.ts +281 -0
  353. package/src/node-lib/net-module.ts +248 -0
  354. package/src/node-lib/net.js +2540 -0
  355. package/src/node-lib/node-versions.ts +34 -0
  356. package/src/node-lib/os.js +356 -0
  357. package/src/node-lib/path.js +1694 -0
  358. package/src/node-lib/primordials.js +743 -0
  359. package/src/node-lib/public-modules.ts +109 -0
  360. package/src/node-lib/punycode.js +455 -0
  361. package/src/node-lib/querystring.js +484 -0
  362. package/src/node-lib/readline/promises.js +73 -0
  363. package/src/node-lib/readline.js +523 -0
  364. package/src/node-lib/require-hook.ts +27 -0
  365. package/src/node-lib/small-modules.ts +35 -0
  366. package/src/node-lib/sources.ts +200 -0
  367. package/src/node-lib/stream/promises.js +44 -0
  368. package/src/node-lib/stream-module.ts +101 -0
  369. package/src/node-lib/stream.js +152 -0
  370. package/src/node-lib/timers.ts +33 -0
  371. package/src/node-lib/tty.js +168 -0
  372. package/src/node-lib/util-module.ts +104 -0
  373. package/src/node-lib/util.js +689 -0
  374. package/src/node-lib/wasi.js +179 -0
  375. package/src/node-lib/zlib.js +1036 -0
  376. package/src/node-resolution.ts +241 -0
  377. package/src/node-resolver.ts +33 -0
  378. package/src/npm/index.ts +425 -0
  379. package/src/npm/registry.ts +235 -0
  380. package/src/npm/resolver.ts +589 -0
  381. package/src/npm/tarball.ts +246 -0
  382. package/src/process-tokens.ts +156 -0
  383. package/src/punycode-source.ts +6 -0
  384. package/src/runtime-interface.ts +85 -0
  385. package/src/runtime.ts +3073 -0
  386. package/src/server-bridge.ts +971 -0
  387. package/src/shims/async_hooks.ts +181 -0
  388. package/src/shims/child_process.ts +1591 -0
  389. package/src/shims/cluster.ts +79 -0
  390. package/src/shims/command-line.ts +79 -0
  391. package/src/shims/constants.ts +68 -0
  392. package/src/shims/crypto-constants.ts +11 -0
  393. package/src/shims/crypto.ts +1061 -0
  394. package/src/shims/dgram.ts +47 -0
  395. package/src/shims/dns.ts +185 -0
  396. package/src/shims/domain.ts +58 -0
  397. package/src/shims/esbuild.ts +1638 -0
  398. package/src/shims/fs.ts +82 -0
  399. package/src/shims/http2.ts +96 -0
  400. package/src/shims/inspector.ts +30 -0
  401. package/src/shims/module.ts +86 -0
  402. package/src/shims/os.ts +195 -0
  403. package/src/shims/path.ts +246 -0
  404. package/src/shims/perf_hooks.ts +92 -0
  405. package/src/shims/process.ts +804 -0
  406. package/src/shims/rollup.ts +149 -0
  407. package/src/shims/string_decoder.ts +396 -0
  408. package/src/shims/sync-child.ts +469 -0
  409. package/src/shims/tls.ts +94 -0
  410. package/src/shims/url.ts +217 -0
  411. package/src/shims/v8.ts +113 -0
  412. package/src/shims/vfs-adapter.ts +408 -0
  413. package/src/shims/vm.ts +132 -0
  414. package/src/shims/wasi.ts +1440 -0
  415. package/src/shims/worker_threads.ts +114 -0
  416. package/src/shims/zlib-constants.ts +65 -0
  417. package/src/shims/zlib.ts +228 -0
  418. package/src/transform.ts +324 -0
  419. package/src/types/external.d.ts +55 -0
  420. package/src/types/package-json.ts +17 -0
  421. package/src/types/pako-zlib.d.ts +30 -0
  422. package/src/types/sha.js.d.ts +14 -0
  423. package/src/utils/binary-encoding.ts +43 -0
  424. package/src/utils/glob.ts +54 -0
  425. package/src/utils/hash.ts +12 -0
  426. package/src/virtual-fs.ts +1048 -0
  427. package/src/vite-plugin.ts +76 -0
  428. package/src/worker/runtime-worker.ts +128 -0
  429. package/src/worker-runtime.ts +145 -0
@@ -0,0 +1,560 @@
1
+ /**
2
+ * The ESM-to-CommonJS lowering the runtime applies to a module it loads:
3
+ * `import` and `export` declarations rewritten over acorn's AST, with a
4
+ * regex lowering behind it for a file acorn cannot parse.
5
+ */
6
+
7
+ import { forGuestRealm, takeFromHost } from './host-globals';
8
+ import * as acorn from 'acorn';
9
+
10
+ /**
11
+ * A module's lowered exports go to the module's exports whatever the module
12
+ * names. An ES module is lowered to a function body that writes `exports.x = …`,
13
+ * and a module that declares its own top-level `exports`, as Vite's Node chunk
14
+ * does for a CommonJS dependency rollup lifted into it, hoists that declaration
15
+ * over the wrapper's: the lowering's first write, `__esModule`, hit an
16
+ * undefined, and vue3-ssr's server died creating its Vite server; the same chunk
17
+ * declares its own `require`, a const, and the lowered imports above it read it
18
+ * in its dead zone. For the Node loader's lowering the writes and the requires
19
+ * name the wrapper's own parameters, `$exports`, `$module` and `$require`, which
20
+ * a module cannot declare over; the dev server's lowering of a browser module
21
+ * keeps its names. A default import of a module the lowering marked as an ES
22
+ * module takes its `default`, as Node does.
23
+ */
24
+ let __nodeLowering = false;
25
+ const __cjsExports = () => __nodeLowering ? "$exports" : "exports";
26
+ const __cjsModule = () => __nodeLowering ? "$module" : "module";
27
+ const __cjsRequire = () => __nodeLowering ? "$require" : "require";
28
+ const __cjsDefault = (expression: string) => __nodeLowering ? "__browserRuntimeInteropDefault(" + expression + ")" : expression;
29
+ // The helper lowered code calls by bare name. It is a name on the realm, so
30
+ // it goes up when a guest first exists, not when this module is loaded.
31
+ forGuestRealm(() => {
32
+ if ((globalThis as Record<string, unknown>).__browserRuntimeInteropDefault) return;
33
+ takeFromHost(globalThis, '__browserRuntimeInteropDefault', (imported: any) => imported && imported.__esModule && "default" in imported ? imported.default : imported);
34
+ });
35
+ export const setNodeLowering = (value: boolean): void => { __nodeLowering = value; };
36
+ export { __cjsExports };
37
+
38
+ /**
39
+ * Whether a module is ESM is a fact of its syntax, not of its text. Asking
40
+ * whether the words `import` or `export` appear anywhere in the file lowered a
41
+ * CommonJS module whose doc comment shows an `import` line (`date-fns/format`
42
+ * does, in an @example) as ESM: its `exports` rewritten, `format` no longer a
43
+ * function, and concurrently, which formats its log prefixes with it, dead
44
+ * before its first command. The words are a prefilter; the answer is whether the
45
+ * parsed module has an import or export declaration at its top level. A file the
46
+ * parser cannot read as a module is judged by the words, as before.
47
+ */
48
+ export function __substrateHasEsmSyntax(code: string): boolean {
49
+ if (!/\bimport\b|\bexport\b/.test(code)) return false;
50
+ let ast;
51
+ try {
52
+ ast = acorn.parse(code, { ecmaVersion: 'latest', sourceType: 'module', allowHashBang: true });
53
+ } catch {
54
+ return true;
55
+ }
56
+ for (const node of ast.body) {
57
+ const type = node.type;
58
+ if (type === "ImportDeclaration" || type === "ExportNamedDeclaration" || type === "ExportDefaultDeclaration" || type === "ExportAllDeclaration") return true;
59
+ }
60
+ return false;
61
+ }
62
+
63
+ export function transformEsmToCjsSimple(code: string): string {
64
+ try {
65
+ return transformEsmToCjsAst(code);
66
+ } catch {
67
+ return transformEsmToCjsRegex(code);
68
+ }
69
+ }
70
+
71
+ /**
72
+ * A named import is a live binding, not a copy. The loader lowered `import { f }
73
+ * from "./b.js"` to `const { f } = require("./b.js")`, which takes the value the
74
+ * exports object holds at the moment the import runs. Inside a cycle that moment
75
+ * is before the other module has assigned anything, so the copy stayed
76
+ * `undefined` for the life of the program: world-core's `ancestry.js` and
77
+ * `storage.js` import each other, and entering the cycle from `ancestry.js` left
78
+ * `stateDirName` undefined, so `volter world up` died with "stateDirName is not
79
+ * a function" while a plain import of the package answered `typeof stateDirName
80
+ * === "function"`.
81
+ *
82
+ * The lowering does what esbuild does: one namespace binding per source,
83
+ * `const __substrateImport1 = require("./b.js")`, and every reference to an
84
+ * imported local rewritten to a property read on it, so the read happens at use.
85
+ * A function declared in the other module is hoisted and callable mid-cycle, and
86
+ * a `let` the other module assigns later shows through. This is the import side
87
+ * of the rule the named-export lowering states for exports.
88
+ *
89
+ * References are found on the same acorn AST the lowering already parses, with a
90
+ * scope chain so an inner `function g(a) {}` keeps its own `a`. An imported local
91
+ * is never rewritten where it is written to (`a = 1`, `a++`, a destructuring
92
+ * target), so assigning to an import stays the TypeError Node raises. Each local
93
+ * also keeps a module-scope `const` of its eagerly read value, wrapped so a
94
+ * getter that throws mid-cycle cannot stop the module: a reference the scope walk
95
+ * declines to rewrite then reads the value the old lowering gave it instead of an
96
+ * undeclared name. That const is also what makes an assignment throw.
97
+ *
98
+ * The parser here is acorn without the JSX plugin, so a file with JSX in it never
99
+ * reaches this transform — its parse throws and the lowering falls back to the
100
+ * regular-expression path.
101
+ */
102
+ const __substrateImportName = /^[A-Za-z_$][A-Za-z0-9_$]*$/u;
103
+ const __substrateSkipKeys = new Set(["type", "start", "end", "loc", "range"]);
104
+
105
+ function __substrateImportRead(namespace: any, name: any) {
106
+ return __substrateImportName.test(name) ? namespace + "." + name : namespace + "[" + JSON.stringify(name) + "]";
107
+ }
108
+
109
+ function __substrateBindingNames(pattern: any, names: any) {
110
+ if (!pattern || typeof pattern !== "object") return;
111
+ if (pattern.type === "Identifier") names.add(pattern.name);
112
+ else if (pattern.type === "ObjectPattern") for (const property of pattern.properties) __substrateBindingNames(property.type === "RestElement" ? property.argument : property.value, names);
113
+ else if (pattern.type === "ArrayPattern") for (const element of pattern.elements) __substrateBindingNames(element, names);
114
+ else if (pattern.type === "AssignmentPattern") __substrateBindingNames(pattern.left, names);
115
+ else if (pattern.type === "RestElement") __substrateBindingNames(pattern.argument, names);
116
+ }
117
+
118
+ /** The let, const, class and function names a block introduces. */
119
+ function __substrateLexicalNames(statements: any, names: any) {
120
+ for (const statement of statements || []) {
121
+ if (!statement || typeof statement !== "object") continue;
122
+ if (statement.type === "VariableDeclaration" && statement.kind !== "var") for (const declarator of statement.declarations) __substrateBindingNames(declarator.id, names);
123
+ else if ((statement.type === "FunctionDeclaration" || statement.type === "ClassDeclaration") && statement.id) names.add(statement.id.name);
124
+ }
125
+ }
126
+
127
+ /** The var and function names hoisted to a function's own scope, not crossing into a nested function. */
128
+ function __substrateVarNames(node: any, names: any) {
129
+ if (!node || typeof node !== "object") return;
130
+ if (Array.isArray(node)) { for (const item of node) __substrateVarNames(item, names); return; }
131
+ if (typeof node.type !== "string") return;
132
+ if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") { if (node.id) names.add(node.id.name); return; }
133
+ if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" || node.type === "ClassExpression") return;
134
+ if (node.type === "VariableDeclaration") {
135
+ if (node.kind === "var") for (const declarator of node.declarations) __substrateBindingNames(declarator.id, names);
136
+ return;
137
+ }
138
+ for (const key of Object.keys(node)) {
139
+ if (__substrateSkipKeys.has(key)) continue;
140
+ __substrateVarNames(node[key], names);
141
+ }
142
+ }
143
+
144
+ function __substrateShadow(visible: any, names: any) {
145
+ let narrowed = visible;
146
+ for (const name of names) {
147
+ if (!narrowed.has(name)) continue;
148
+ if (narrowed === visible) narrowed = new Set(visible);
149
+ narrowed.delete(name);
150
+ }
151
+ return narrowed;
152
+ }
153
+
154
+ function __substrateLiveImportBindings(code: any) {
155
+ if (!/\bimport\b/u.test(code)) return code;
156
+ let ast;
157
+ try { ast = acorn.parse(code, { ecmaVersion: "latest", sourceType: "module" }); } catch { return code; }
158
+ const declarations = ast.body.filter((node) => node.type === "ImportDeclaration" && node.specifiers.length > 0);
159
+ if (declarations.length === 0) return code;
160
+ let prefix = "__substrateImport";
161
+ while (code.includes(prefix)) prefix += "_";
162
+ const reads = new Map<string, string>();
163
+ const namespaces = new Map<string, string>();
164
+ const edits: Array<[number, number, string]> = [];
165
+ for (const declaration of declarations as any[]) {
166
+ const specifier = declaration.source.value;
167
+ let namespace = namespaces.get(specifier);
168
+ const parts: string[] = [];
169
+ if (namespace === void 0) {
170
+ namespace = prefix + (namespaces.size + 1);
171
+ namespaces.set(specifier, namespace);
172
+ parts.push("const " + namespace + " = " + __cjsRequire() + "(" + JSON.stringify(specifier) + ");");
173
+ // The imported module may still be settling, a top-level `await` in it
174
+ // or in what it imports; an importer waits for it, as a module graph
175
+ // evaluates in order. The marker becomes `await` when the loader runs
176
+ // this body as an async function, and reads nothing otherwise.
177
+ parts.push("/*__substrate_await__*/(" + namespace + " && " + namespace + "[Symbol.for(\"substrate.pending\")]);");
178
+ }
179
+ for (const imported of declaration.specifiers) {
180
+ const read = imported.type === "ImportDefaultSpecifier" ? __cjsDefault(namespace)
181
+ : imported.type === "ImportNamespaceSpecifier" ? namespace
182
+ : __substrateImportRead(namespace, imported.imported.type === "Identifier" ? imported.imported.name : imported.imported.value);
183
+ reads.set(imported.local.name, read);
184
+ parts.push("const " + imported.local.name + " = (() => { try { return " + read + "; } catch { return void 0; } })();");
185
+ }
186
+ edits.push([declaration.start, declaration.end, parts.join(" ")]);
187
+ }
188
+
189
+ const visitTarget = (node: any, visible: any) => {
190
+ if (!node || typeof node !== "object") return;
191
+ if (node.type === "Identifier") return;
192
+ if (node.type === "ObjectPattern") {
193
+ for (const property of node.properties) {
194
+ if (property.type === "RestElement") { visitTarget(property.argument, visible); continue; }
195
+ if (property.computed) visit(property.key, visible);
196
+ visitTarget(property.value, visible);
197
+ }
198
+ return;
199
+ }
200
+ if (node.type === "ArrayPattern") { for (const element of node.elements) visitTarget(element, visible); return; }
201
+ if (node.type === "AssignmentPattern") { visitTarget(node.left, visible); visit(node.right, visible); return; }
202
+ if (node.type === "RestElement") { visitTarget(node.argument, visible); return; }
203
+ visit(node, visible);
204
+ };
205
+
206
+ const visit = (node: any, visible: any, asNewCallee = false) => {
207
+ if (!node || typeof node !== "object") return;
208
+ if (Array.isArray(node)) { for (const item of node) visit(item, visible); return; }
209
+ if (typeof node.type !== "string") return;
210
+ switch (node.type) {
211
+ case "ImportDeclaration": case "ImportSpecifier": case "ImportDefaultSpecifier":
212
+ case "ImportNamespaceSpecifier": case "ExportSpecifier": case "MetaProperty":
213
+ case "BreakStatement": case "ContinueStatement": case "PrivateIdentifier":
214
+ return;
215
+ case "Identifier":
216
+ // A read is an expression, not a name. Bare as a `new X()` callee it
217
+ // re-associates: the default read is a call, so `new
218
+ // __browserRuntimeInteropDefault(ns)()` constructed the interop helper,
219
+ // an arrow function, and called its result (github-slugger's `new
220
+ // Slugger()` under remark-toc died "is not a constructor"). Node
221
+ // constructs the imported class; parentheses keep the read one
222
+ // operand there. Anywhere else the read stands bare: a read that
223
+ // opens with `(` after a line the source ended without a semicolon
224
+ // is a call of that line's last word (import-meta-resolve's
225
+ // `const {parentURL} = context` followed by `assert(...)`, lowered,
226
+ // died "context is not a function" under vite-plugin-fake-server),
227
+ // where the read's own first token, a name, ends the line as the
228
+ // source's did.
229
+ if (visible.has(node.name)) edits.push([node.start, node.end, asNewCallee ? `(${reads.get(node.name)!})` : reads.get(node.name)!]);
230
+ return;
231
+ case "NewExpression":
232
+ visit(node.callee, visible, true);
233
+ visit(node.arguments, visible);
234
+ return;
235
+ case "MemberExpression":
236
+ visit(node.object, visible, asNewCallee);
237
+ if (node.computed) visit(node.property, visible);
238
+ return;
239
+ case "Property": {
240
+ if (node.computed) visit(node.key, visible);
241
+ const value = node.value;
242
+ // A shorthand property carries the import, so it grows its key.
243
+ if (node.shorthand && value && value.type === "Identifier" && visible.has(value.name)) {
244
+ edits.push([value.start, value.end, value.name + ": " + reads.get(value.name)]);
245
+ return;
246
+ }
247
+ visit(value, visible);
248
+ return;
249
+ }
250
+ case "MethodDefinition": case "PropertyDefinition":
251
+ if (node.computed) visit(node.key, visible);
252
+ visit(node.value, visible);
253
+ return;
254
+ case "LabeledStatement": visit(node.body, visible); return;
255
+ case "VariableDeclarator": visit(node.init, visible); return;
256
+ case "AssignmentExpression":
257
+ visitTarget(node.left, visible);
258
+ visit(node.right, visible);
259
+ return;
260
+ case "UpdateExpression":
261
+ if (node.argument && node.argument.type !== "Identifier") visit(node.argument, visible);
262
+ return;
263
+ case "FunctionDeclaration": case "FunctionExpression": case "ArrowFunctionExpression": {
264
+ const names = new Set();
265
+ if (node.id) names.add(node.id.name);
266
+ for (const parameter of node.params) __substrateBindingNames(parameter, names);
267
+ __substrateVarNames(node.body, names);
268
+ if (node.body && node.body.type === "BlockStatement") __substrateLexicalNames(node.body.body, names);
269
+ const inner = __substrateShadow(visible, names);
270
+ for (const parameter of node.params) visitTarget(parameter, inner);
271
+ if (node.body && node.body.type === "BlockStatement") for (const statement of node.body.body) visit(statement, inner);
272
+ else visit(node.body, inner);
273
+ return;
274
+ }
275
+ case "BlockStatement": case "StaticBlock": {
276
+ const names = new Set();
277
+ __substrateLexicalNames(node.body, names);
278
+ const inner = __substrateShadow(visible, names);
279
+ for (const statement of node.body) visit(statement, inner);
280
+ return;
281
+ }
282
+ case "ClassDeclaration": case "ClassExpression": {
283
+ const names = new Set();
284
+ if (node.id) names.add(node.id.name);
285
+ const inner = __substrateShadow(visible, names);
286
+ visit(node.superClass, inner);
287
+ visit(node.body, inner);
288
+ return;
289
+ }
290
+ case "CatchClause": {
291
+ const names = new Set();
292
+ __substrateBindingNames(node.param, names);
293
+ __substrateLexicalNames(node.body.body, names);
294
+ const inner = __substrateShadow(visible, names);
295
+ if (node.param) visitTarget(node.param, inner);
296
+ for (const statement of node.body.body) visit(statement, inner);
297
+ return;
298
+ }
299
+ case "ForStatement": {
300
+ const names = new Set();
301
+ if (node.init && node.init.type === "VariableDeclaration" && node.init.kind !== "var") for (const declarator of node.init.declarations) __substrateBindingNames(declarator.id, names);
302
+ const inner = __substrateShadow(visible, names);
303
+ visit(node.init, inner); visit(node.test, inner); visit(node.update, inner); visit(node.body, inner);
304
+ return;
305
+ }
306
+ case "ForInStatement": case "ForOfStatement": {
307
+ const names = new Set();
308
+ if (node.left && node.left.type === "VariableDeclaration" && node.left.kind !== "var") for (const declarator of node.left.declarations) __substrateBindingNames(declarator.id, names);
309
+ const inner = __substrateShadow(visible, names);
310
+ if (node.left && node.left.type === "VariableDeclaration") visit(node.left, inner);
311
+ else visitTarget(node.left, inner);
312
+ visit(node.right, inner);
313
+ visit(node.body, inner);
314
+ return;
315
+ }
316
+ case "SwitchStatement": {
317
+ visit(node.discriminant, visible);
318
+ const names = new Set();
319
+ for (const switchCase of node.cases) __substrateLexicalNames(switchCase.consequent, names);
320
+ const inner = __substrateShadow(visible, names);
321
+ for (const switchCase of node.cases) {
322
+ visit(switchCase.test, inner);
323
+ for (const statement of switchCase.consequent) visit(statement, inner);
324
+ }
325
+ return;
326
+ }
327
+ default:
328
+ for (const key of Object.keys(node)) {
329
+ if (__substrateSkipKeys.has(key)) continue;
330
+ visit(node[key], visible);
331
+ }
332
+ return;
333
+ }
334
+ };
335
+
336
+ visit(ast, new Set(reads.keys()));
337
+ edits.sort((a, b) => b[0] - a[0]);
338
+ let result = code;
339
+ for (const [start, end, text] of edits) result = result.slice(0, start) + text + result.slice(end);
340
+ return result;
341
+ }
342
+
343
+ /** AST-based ESM→CJS transform using acorn. */
344
+ function transformEsmToCjsAst(code: string): string {
345
+ code = __substrateLiveImportBindings(code);
346
+ const ast = acorn.parse(code, { ecmaVersion: 'latest', sourceType: 'module' });
347
+
348
+ // Collect replacements as [start, end, replacement] sorted by start descending
349
+ const replacements: Array<[number, number, string]> = [];
350
+ // An exported function declaration's export is installed before the module
351
+ // body runs, because a function declaration is hoisted and Node initializes
352
+ // its export binding before evaluation. Installed where the declaration
353
+ // stands, a module reached through a cycle from above its own imports saw
354
+ // nothing: b.js imports a.js, a.js imports f back from b.js and calls it
355
+ // while b.js is still evaluating a.js, and the call found undefined though f
356
+ // is declared. The getters go first, on the module's first line so every
357
+ // later line keeps its number.
358
+ const hoisted: string[] = [];
359
+ let sideEffectImports = 0;
360
+
361
+ for (const node of (ast as any).body) {
362
+ if (node.type === 'ImportDeclaration') {
363
+ const source = node.source.value;
364
+ const specs = node.specifiers;
365
+
366
+ if (specs.length === 0) {
367
+ // Side-effect import: import './polyfill'. The module may still be
368
+ // settling, a top-level `await` in it; the importer waits for it as
369
+ // for any import (the marker becomes `await` in an async body).
370
+ sideEffectImports += 1;
371
+ const namespace = `__substrateImportSide${sideEffectImports}`;
372
+ replacements.push([node.start, node.end, `const ${namespace} = ${__cjsRequire()}(${JSON.stringify(source)}); /*__substrate_await__*/(${namespace} && ${namespace}[Symbol.for("substrate.pending")]);`]);
373
+ } else {
374
+ const defaultSpec = specs.find((s: any) => s.type === 'ImportDefaultSpecifier');
375
+ const nsSpec = specs.find((s: any) => s.type === 'ImportNamespaceSpecifier');
376
+ const namedSpecs = specs.filter((s: any) => s.type === 'ImportSpecifier');
377
+
378
+ const parts: string[] = [];
379
+ if (defaultSpec) {
380
+ parts.push(`const ${defaultSpec.local.name} = ${__cjsDefault(__cjsRequire() + "(" + JSON.stringify(source) + ")")}`);
381
+ }
382
+ if (nsSpec) {
383
+ parts.push(`const ${nsSpec.local.name} = ${__cjsRequire()}(${JSON.stringify(source)})`);
384
+ }
385
+ if (namedSpecs.length > 0) {
386
+ const bindings = namedSpecs.map((s: any) => {
387
+ if (s.imported.name === s.local.name) return s.local.name;
388
+ return `${s.imported.name}: ${s.local.name}`;
389
+ }).join(', ');
390
+ if (defaultSpec) {
391
+ // Mixed: import React, { useState } from 'react'
392
+ // Default already handled, just destructure from same require
393
+ parts.push(`const { ${bindings} } = ${__cjsRequire()}(${JSON.stringify(source)})`);
394
+ } else {
395
+ parts.push(`const { ${bindings} } = ${__cjsRequire()}(${JSON.stringify(source)})`);
396
+ }
397
+ }
398
+ replacements.push([node.start, node.end, parts.join(';\n')]);
399
+ }
400
+ } else if (node.type === 'ExportDefaultDeclaration') {
401
+ const decl = node.declaration;
402
+ // The default export is the `default` name of the module's exports, as
403
+ // Node's interop has it: a CJS require of an ES module gets the
404
+ // namespace, `default` among its names. It was lowered to
405
+ // `module.exports = X`, which threw away every named export defined
406
+ // before it (readdirp exports `readdirp` by name and as the default;
407
+ // chokidar imports the name and found the module was the function).
408
+ const defineDefault = (value: string): string => `Object.defineProperty(${__cjsExports()}, "default", { enumerable: true, configurable: true, get: function () { return ${value}; } });`;
409
+ if (decl.type === 'FunctionDeclaration') {
410
+ const funcCode = code.slice(decl.start, node.end);
411
+ replacements.push([node.start, node.end, decl.id ? `${funcCode}\n${defineDefault(decl.id.name)}` : `${defineDefault(`(${funcCode})`)}`]);
412
+ } else if (decl.type === 'ClassDeclaration') {
413
+ const classCode = code.slice(decl.start, node.end);
414
+ replacements.push([node.start, node.end, decl.id ? `${classCode}\n${defineDefault(decl.id.name)}` : `const __default_${node.start} = ${classCode};\n${defineDefault(`__default_${node.start}`)}`]);
415
+ } else {
416
+ // export default <expression>: evaluated here, in order, once.
417
+ const exprCode = code.slice(decl.start, node.end).replace(/;\s*$/u, '');
418
+ replacements.push([node.start, node.end, `const __default_${node.start} = (${exprCode});\n${defineDefault(`__default_${node.start}`)}`]);
419
+ }
420
+ } else if (node.type === 'ExportNamedDeclaration') {
421
+ if (node.declaration) {
422
+ const decl = node.declaration;
423
+ if (decl.type === 'FunctionDeclaration') {
424
+ const name = decl.id.name;
425
+ const funcCode = code.slice(decl.start, node.end);
426
+ replacements.push([node.start, node.end, funcCode]);
427
+ hoisted.push(`Object.defineProperty(${__cjsExports()}, "${name}", { enumerable: true, get: function () { return ${name}; } });`);
428
+ } else if (decl.type === 'ClassDeclaration') {
429
+ const name = decl.id.name;
430
+ const classCode = code.slice(decl.start, node.end);
431
+ replacements.push([node.start, node.end, `${classCode}\nObject.defineProperty(${__cjsExports()}, "${name}", { enumerable: true, get: function () { return ${name}; } });`]);
432
+ } else if (decl.type === 'VariableDeclaration') {
433
+ // The declaration stays as written, so the module keeps a binding of
434
+ // its own; what follows is an export that reads that binding when
435
+ // asked, the way esbuild lowers the same thing, so an assignment made
436
+ // later shows through. Every emitted statement ends in a semicolon: an
437
+ // unterminated `exports.X = X` before sucrase's enum IIFE made it a
438
+ // call on X.
439
+ const parts: string[] = [code.slice(decl.start, node.end).replace(/;?\s*$/u, ';')];
440
+ const names: string[] = [];
441
+ const collect = (pattern: any) => {
442
+ if (!pattern) return;
443
+ if (pattern.type === 'Identifier') names.push(pattern.name);
444
+ else if (pattern.type === 'ObjectPattern') for (const property of pattern.properties) collect(property.type === 'RestElement' ? property.argument : property.value);
445
+ else if (pattern.type === 'ArrayPattern') for (const element of pattern.elements) collect(element);
446
+ else if (pattern.type === 'AssignmentPattern') collect(pattern.left);
447
+ else if (pattern.type === 'RestElement') collect(pattern.argument);
448
+ };
449
+ for (const declarator of decl.declarations) collect(declarator.id);
450
+ for (const name of names) parts.push(`Object.defineProperty(${__cjsExports()}, "${name}", { enumerable: true, get: function () { return ${name}; } });`);
451
+ replacements.push([node.start, node.end, parts.join('\n')]);
452
+ }
453
+ } else if (node.source) {
454
+ // Re-export: export { X } from './module'
455
+ const source = node.source.value;
456
+ // A named re-export is a live binding to the other module's export,
457
+ // and an explicit export wins over a name a star export brought in
458
+ // before it, as the language says: defined as a configurable getter,
459
+ // it replaces the star's getter where an assignment threw on it (zod
460
+ // 4.6 re-exports `toZod` by name after `export *` of a module that
461
+ // has it).
462
+ const parts: string[] = [];
463
+ const tmpVar = `__reexport_${node.start}`;
464
+ parts.push(`const ${tmpVar} = ${__cjsRequire()}(${JSON.stringify(source)})`);
465
+ // The re-exported module may still be settling; wait for it as for an import.
466
+ parts.push(`/*__substrate_await__*/(${tmpVar} && ${tmpVar}[Symbol.for("substrate.pending")])`);
467
+ for (const spec of node.specifiers) {
468
+ parts.push(`Object.defineProperty(${__cjsExports()}, "${spec.exported.name}", { enumerable: true, configurable: true, get: function () { return ${tmpVar}.${spec.local.name}; } })`);
469
+ }
470
+ replacements.push([node.start, node.end, parts.join(';\n')]);
471
+ } else {
472
+ // Local re-export: export { foo, bar }, a live binding to the local, and
473
+ // an explicit export that replaces a star's getter of the same name.
474
+ const parts: string[] = [];
475
+ for (const spec of node.specifiers) {
476
+ parts.push(`Object.defineProperty(${__cjsExports()}, "${spec.exported.name}", { enumerable: true, configurable: true, get: function () { return ${spec.local.name}; } })`);
477
+ }
478
+ replacements.push([node.start, node.end, parts.join(';\n')]);
479
+ }
480
+ } else if (node.type === 'ExportAllDeclaration' && node.exported) {
481
+ // export * as util from './util.js': one export, the module's namespace,
482
+ // a live binding to the module object as a namespace import is. It was
483
+ // lowered as a bare star, every name of the module spread over this one
484
+ // and no `util` at all (zod 4.6's classic schemas read `util.derived`
485
+ // through its core's `export * as util`).
486
+ const source = node.source.value;
487
+ const name = node.exported.type === 'Identifier' ? node.exported.name : node.exported.value;
488
+ const tmpVar = `__reexport_${node.start}`;
489
+ replacements.push([node.start, node.end, `const ${tmpVar} = ${__cjsRequire()}(${JSON.stringify(source)}); /*__substrate_await__*/(${tmpVar} && ${tmpVar}[Symbol.for("substrate.pending")]); Object.defineProperty(${__cjsExports()}, ${JSON.stringify(name)}, { enumerable: true, configurable: true, get: function () { return ${tmpVar}; } })`]);
490
+ } else if (node.type === 'ExportAllDeclaration') {
491
+ // export * from './helpers'
492
+ const source = node.source.value;
493
+ // `export * from "./core.js"` was lowered to an `Object.assign` of the
494
+ // required module onto the exports: a copy of each value at that moment
495
+ // rather than a live binding, and an assignment that throws where the
496
+ // module exports a name of its own, since that export is a getter
497
+ // (strtok3's index re-exports its core and exports its own `fromStream`
498
+ // over it). The star defines a live, configurable getter per name the
499
+ // module does not already export; a local export shadows a star's, as the
500
+ // language says.
501
+ const tmpVar = `__reexport_${node.start}`;
502
+ replacements.push([node.start, node.end, `const ${tmpVar} = ${__cjsRequire()}(${JSON.stringify(source)}); /*__substrate_await__*/(${tmpVar} && ${tmpVar}[Symbol.for("substrate.pending")]); (function (__from, __into) { for (const __key of Object.keys(__from)) { if (__key === "default" || __key === "__esModule" || Object.prototype.hasOwnProperty.call(__into, __key)) continue; Object.defineProperty(__into, __key, { enumerable: true, configurable: true, get: function () { return __from[__key]; } }); } })(${tmpVar}, ${__cjsExports()})`]);
503
+ }
504
+ }
505
+
506
+ // Apply replacements from end to start to preserve positions
507
+ let result = code;
508
+ replacements.sort((a, b) => b[0] - a[0]);
509
+ for (const [start, end, replacement] of replacements) {
510
+ // A minified module puts its imports on one line,
511
+ // `;import{...}from"a";import{...}from"b"`, and each declaration's span takes
512
+ // its own semicolon with it: the rewrite glued `require("a")const {...} =
513
+ // require("b")` together, and V8 read an unexpected `const` in
514
+ // @tailwindcss/vite's plugin. A replaced statement that ended in a semicolon
515
+ // ends in one still.
516
+ result = result.slice(0, start) + replacement + (result.charAt(end - 1) === ';' ? ';' : '') + result.slice(end);
517
+ }
518
+
519
+ return hoisted.join(' ') + result;
520
+ }
521
+
522
+ /** Regex-based ESM→CJS fallback for code acorn can't parse. */
523
+ function transformEsmToCjsRegex(code: string): string {
524
+ let transformed = code;
525
+
526
+ transformed = transformed.replace(
527
+ /import\s+(\w+)\s+from\s+['"]([^'"]+)['"]/g,
528
+ `const $1 = ${__cjsDefault(__cjsRequire() + '("$2")')}`,
529
+ );
530
+ transformed = transformed.replace(
531
+ /import\s+\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g,
532
+ `const {$1} = ${__cjsRequire()}("$2")`,
533
+ );
534
+ transformed = transformed.replace(
535
+ /export\s+default\s+function\s+(\w+)/g,
536
+ `${__cjsExports()}.default = function $1`,
537
+ );
538
+ transformed = transformed.replace(
539
+ /export\s+default\s+function\s*\(/g,
540
+ `${__cjsExports()}.default = function(`,
541
+ );
542
+ transformed = transformed.replace(
543
+ /export\s+default\s+/g,
544
+ `${__cjsExports()}.default = `,
545
+ );
546
+ transformed = transformed.replace(
547
+ /export\s+async\s+function\s+(\w+)/g,
548
+ `${__cjsExports()}.$1 = async function $1`,
549
+ );
550
+ transformed = transformed.replace(
551
+ /export\s+function\s+(\w+)/g,
552
+ `${__cjsExports()}.$1 = function $1`,
553
+ );
554
+ transformed = transformed.replace(
555
+ /export\s+const\s+(\w+)\s*=/g,
556
+ `${__cjsExports()}.$1 =`,
557
+ );
558
+
559
+ return transformed;
560
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Where the bundlers' own wasm builds are fetched from when a host names no
3
+ * other place: the versions the engine's `esbuild` and `rollup` doors are
4
+ * written against.
5
+ */
6
+
7
+ export const ESBUILD_WASM_VERSION = '0.20.0';
8
+ export const ROLLUP_BROWSER_VERSION = '4.63.1';
9
+
10
+ export const ESBUILD_WASM_ESM_CDN = `https://esm.sh/esbuild-wasm@${ESBUILD_WASM_VERSION}`;
11
+ export const ESBUILD_WASM_BINARY_CDN = `https://unpkg.com/esbuild-wasm@${ESBUILD_WASM_VERSION}/esbuild.wasm`;
12
+ export const ESBUILD_WASM_BROWSER_CDN = `https://unpkg.com/esbuild-wasm@${ESBUILD_WASM_VERSION}/esm/browser.min.js`;
13
+ export const ROLLUP_BROWSER_CDN = `https://esm.sh/@rollup/browser@${ROLLUP_BROWSER_VERSION}`;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * A runtime, on the thread the caller asks for.
3
+ *
4
+ * The engine runs a guest on the page's own thread or on a worker of its
5
+ * own; which one is the embedder's call, and both answer the same interface.
6
+ * Isolation is the embedder's to place -- the substrate gives a run its own
7
+ * origin through a worker it serves itself -- so nothing here decides it.
8
+ */
9
+
10
+ import { Runtime } from './runtime';
11
+ import { WorkerRuntime } from './worker-runtime';
12
+ import type { VirtualFS } from './virtual-fs';
13
+ import type { IRuntime, IExecuteResult, CreateRuntimeOptions, IRuntimeOptions } from './runtime-interface';
14
+
15
+ /**
16
+ * Check if Web Workers are available in the current environment
17
+ */
18
+ function isWorkerAvailable(): boolean {
19
+ return typeof Worker !== 'undefined';
20
+ }
21
+
22
+ /**
23
+ * Wrapper that makes the synchronous Runtime conform to the async IRuntime interface
24
+ */
25
+ class AsyncRuntimeWrapper implements IRuntime {
26
+ private runtime: Runtime;
27
+
28
+ constructor(vfs: VirtualFS, options: IRuntimeOptions = {}) {
29
+ this.runtime = new Runtime(vfs, options);
30
+ }
31
+
32
+ async execute(code: string, filename?: string): Promise<IExecuteResult> {
33
+ return Promise.resolve(this.runtime.execute(code, filename));
34
+ }
35
+
36
+ async runFile(filename: string): Promise<IExecuteResult> {
37
+ return Promise.resolve(this.runtime.runFile(filename));
38
+ }
39
+
40
+ clearCache(): void {
41
+ this.runtime.clearCache();
42
+ }
43
+
44
+ getVFS(): VirtualFS {
45
+ return this.runtime.getVFS();
46
+ }
47
+
48
+ /**
49
+ * Get the underlying sync Runtime for direct access to sync methods
50
+ */
51
+ getSyncRuntime(): Runtime {
52
+ return this.runtime;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Create a runtime on the thread the options name.
58
+ *
59
+ * `useWorker` puts the guest on a worker of the engine's own, `'auto'` does
60
+ * so where the realm has workers, and the default runs it on the caller's
61
+ * thread behind the same asynchronous interface.
62
+ */
63
+ export async function createRuntime(
64
+ vfs: VirtualFS,
65
+ options: CreateRuntimeOptions = {}
66
+ ): Promise<IRuntime> {
67
+ const { useWorker = false, ...runtimeOptions } = options;
68
+
69
+ const shouldUseWorker = useWorker === true || useWorker === 'auto' ? isWorkerAvailable() : false;
70
+
71
+ if (shouldUseWorker) {
72
+ const workerRuntime = new WorkerRuntime(vfs, runtimeOptions);
73
+ // The worker answers once it has booted; a first execute is that answer.
74
+ await workerRuntime.execute('/* worker ready check */', '/__worker_init__.js');
75
+ return workerRuntime;
76
+ }
77
+
78
+ return new AsyncRuntimeWrapper(vfs, runtimeOptions);
79
+ }
80
+
81
+ export { Runtime } from './runtime';
82
+ export { WorkerRuntime } from './worker-runtime';
83
+ export type {
84
+ IRuntime,
85
+ IExecuteResult,
86
+ IRuntimeOptions,
87
+ CreateRuntimeOptions,
88
+ VFSSnapshot,
89
+ } from './runtime-interface';