@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,117 @@
1
+ /**
2
+ * The internals Node's `internal/modules/customization_hooks.js` names.
3
+ *
4
+ * Each object holds exactly the names that file destructures from it. Node's
5
+ * real `internal/bootstrap/realm` is the builtin loader of a Node process --
6
+ * a snapshot, a compile cache and every `lib/` file -- and what the hooks file
7
+ * takes from it is two questions about a name: is this something a program can
8
+ * require, and what is its canonical id. The engine answers both from the same
9
+ * list its `module.builtinModules` reports, so a hook that reads `node:fs`
10
+ * reads the name the guest's own `module.isBuiltin` agrees with.
11
+ */
12
+ import * as moduleShim from '../../shims/module';
13
+ import { fileURLToPath, pathToFileURL } from '../../shims/url';
14
+
15
+ /**
16
+ * `internal/bootstrap/realm`'s `BuiltinModule`, the two class methods the
17
+ * hooks file calls to turn a CommonJS filename into a URL and back.
18
+ */
19
+ export const internalBootstrapRealm = {
20
+ BuiltinModule: {
21
+ /**
22
+ * Whether a normalized id (no `node:`) is a builtin a program may require.
23
+ * Node asks this of a filename to decide whether it is `node:<id>` rather
24
+ * than a path; a name the engine does not answer is a path or nothing.
25
+ */
26
+ canBeRequiredByUsers(id: string): boolean {
27
+ return moduleShim.builtinModules.includes(id);
28
+ },
29
+ /**
30
+ * The canonical id of a requirable builtin, `node:` prefix or not, and
31
+ * undefined for anything else -- a `file:` URL, a path, a bare package
32
+ * name. Node returns undefined rather than throwing, and the hooks file
33
+ * tests the result rather than catching.
34
+ */
35
+ normalizeRequirableId(id: string): string | undefined {
36
+ if (typeof id !== 'string') return void 0;
37
+ const name = id.startsWith('node:') ? id.slice(5) : id;
38
+ return moduleShim.builtinModules.includes(name) ? name : void 0;
39
+ },
40
+ /**
41
+ * Whether `id` is a compiled builtin, which `internal/util/inspect`
42
+ * asks of every `node:` stack frame when it colorizes an Error. Node's
43
+ * class answers from the realm's module map; the engine answers from
44
+ * the same list `canBeRequiredByUsers` reads, plus `internal/` files
45
+ * inspect also greys. The method was missing, so a pipe child that
46
+ * still had FORCE_COLOR threw `exists is not a function` while printing
47
+ * an assertion and the test exited 1.
48
+ */
49
+ exists(id: string): boolean {
50
+ if (typeof id !== 'string') return false;
51
+ const name = id.startsWith('node:') ? id.slice(5) : id;
52
+ return name.startsWith('internal/') || moduleShim.builtinModules.includes(name);
53
+ },
54
+ },
55
+ };
56
+
57
+ /**
58
+ * `internal/url`: the conversions between a path and a URL that the hooks
59
+ * file makes, and the three names `_http_client.js` and `https.js` take to
60
+ * turn a URL into the options a request is made from.
61
+ */
62
+ export const internalUrl = {
63
+ fileURLToPath,
64
+ pathToFileURL,
65
+ /**
66
+ * Node's `toPathIfFileURL`: `fs` takes a path or a `file:` URL for every
67
+ * one of its calls, and this is the one line that turns the second into
68
+ * the first. Anything else is handed on untouched, for `fs` to validate.
69
+ */
70
+ toPathIfFileURL: (value: unknown): unknown => {
71
+ if (value instanceof URL) return fileURLToPath(value);
72
+ if (typeof value === 'string' && value.startsWith('file://')) return fileURLToPath(value);
73
+ return value;
74
+ },
75
+ get URL() { return (globalThis as unknown as { URL: unknown }).URL; },
76
+ /** Node's `isURL`: a `URL` of this realm, or one shaped like it. */
77
+ isURL: (value: unknown): boolean =>
78
+ value instanceof URL ||
79
+ (value !== null && typeof value === 'object' &&
80
+ typeof (value as { href?: unknown }).href === 'string' &&
81
+ typeof (value as { origin?: unknown }).origin === 'string' &&
82
+ typeof (value as { protocol?: unknown }).protocol === 'string'),
83
+ /**
84
+ * Node's `urlToHttpOptions`: the request options a `URL` stands for. The
85
+ * rules are Node's own -- an IPv6 host loses its brackets, the path is the
86
+ * pathname and the search together, and a password without a user is still
87
+ * an auth pair.
88
+ */
89
+ urlToHttpOptions: (url: URL): Record<string, unknown> => {
90
+ const options: Record<string, unknown> = {
91
+ protocol: url.protocol,
92
+ hostname: typeof url.hostname === 'string' && url.hostname.startsWith('[')
93
+ ? url.hostname.slice(1, -1)
94
+ : url.hostname,
95
+ hash: url.hash,
96
+ search: url.search,
97
+ pathname: url.pathname,
98
+ path: `${url.pathname || ''}${url.search || ''}`,
99
+ href: url.href,
100
+ };
101
+ if (url.port !== '') options.port = Number(url.port);
102
+ if (url.username || url.password) {
103
+ options.auth = `${decodeURIComponent(url.username)}:${decodeURIComponent(url.password)}`;
104
+ }
105
+ return options;
106
+ },
107
+ };
108
+
109
+ /**
110
+ * `internal/encoding`: the realm's own `TextDecoder`. The hooks file decodes
111
+ * an `ArrayBuffer` or a typed array a load hook returned into the source
112
+ * string the loader compiles.
113
+ */
114
+ export const internalEncoding = {
115
+ get TextDecoder() { return (globalThis as unknown as { TextDecoder: unknown }).TextDecoder; },
116
+ get TextEncoder() { return (globalThis as unknown as { TextEncoder: unknown }).TextEncoder; },
117
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The engine's `readline`, read on the first ask.
3
+ *
4
+ * `internal/fs/promises.js` takes `Interface` from `internal/readline/
5
+ * interface` at its top, so every use of `fs/promises` needs the class.
6
+ * `readline`'s own `Interface` extends the vendored `EventEmitter`, and this
7
+ * file is on the loader's path, so the name is read when it is wanted rather
8
+ * than when this module is evaluated -- the rule `../lazy.ts` states.
9
+ */
10
+ import { nodeLibInternalRequire } from '../load';
11
+
12
+ export function readlineModule(): Record<string, unknown> {
13
+ // Node's own `internal/readline/interface` is vendored now, so the name
14
+ // resolves to that file rather than to the engine's shim.
15
+ return nodeLibInternalRequire('internal/readline/interface') as Record<string, unknown>;
16
+ }
@@ -0,0 +1,277 @@
1
+ /**
2
+ * The internals Node's `net` names that are neither vendored nor a binding:
3
+ * async ids, timers, stream defaults, the option table, and the three
4
+ * one-line answers (`assert`, `hasObserver`, `isBuildingSnapshot`).
5
+ *
6
+ * Each object holds exactly the names the vendored files destructure.
7
+ */
8
+
9
+ /**
10
+ * `internal/async_hooks`. The engine has no async-hooks graph, so an id is a
11
+ * number nobody follows and a trigger scope is the call itself. The two
12
+ * symbols matter and are real: `owner_symbol` is how a handle finds its
13
+ * stream — `onStreamRead` reads `this[owner_symbol]` on every chunk — and
14
+ * `async_id_symbol` is where `net.js` keeps a socket's id.
15
+ */
16
+ let nextAsyncId = 1;
17
+ const symbols = {
18
+ async_id_symbol: Symbol('async_id_symbol'),
19
+ trigger_async_id_symbol: Symbol('trigger_async_id_symbol'),
20
+ owner_symbol: Symbol('owner_symbol'),
21
+ init_symbol: Symbol('init_symbol'),
22
+ destroy_symbol: Symbol('destroy_symbol'),
23
+ async_id_fields: Symbol('async_id_fields'),
24
+ };
25
+
26
+ export const internalAsyncHooks = {
27
+ symbols,
28
+ newAsyncId: (): number => nextAsyncId++,
29
+ /**
30
+ * Node's `getOrSetAsyncId`: the id an object already carries, or a new one
31
+ * put on it. `_http_server.js` asks it of every socket it accepts, to name
32
+ * the scope the connection listener runs in.
33
+ */
34
+ getOrSetAsyncId: (object: Record<symbol, unknown>): number => {
35
+ const key = symbols.async_id_symbol;
36
+ if (Object.prototype.hasOwnProperty.call(object, key)) return object[key] as number;
37
+ object[key] = nextAsyncId++;
38
+ return object[key] as number;
39
+ },
40
+ getDefaultTriggerAsyncId: (): number => 0,
41
+ defaultTriggerAsyncIdScope: <A extends unknown[], R>(
42
+ _triggerAsyncId: number, block: (...args: A) => R, ...args: A
43
+ ): R => block(...args),
44
+ initHooksExist: (): boolean => false,
45
+ afterHooksExist: (): boolean => false,
46
+ destroyHooksExist: (): boolean => false,
47
+ emitInit: (): void => {},
48
+ emitBefore: (): void => {},
49
+ emitAfter: (): void => {},
50
+ emitDestroy: (): void => {},
51
+ hasAsyncIdStack: (): boolean => false,
52
+ registerDestroyHook: (): void => {},
53
+ };
54
+
55
+ /**
56
+ * Node's `AsyncResource`, which `events.js` extends to build
57
+ * `EventEmitterAsyncResource`. A tab has no async-hooks graph, so an id is a
58
+ * number nobody follows -- but it is a real positive id, because a program
59
+ * that asks `asyncId` of a resource, as Node's own tests do, must see one.
60
+ * Served through `require('async_hooks')` so the vendored file can extend it;
61
+ * the class lives here, never in that file.
62
+ */
63
+ let nextAsyncResourceId = 1;
64
+ export class AsyncResource {
65
+ #asyncId: number;
66
+ #triggerAsyncId: number;
67
+
68
+ constructor(_type: string, options?: { triggerAsyncId?: number; requireManualDestroy?: boolean }) {
69
+ this.#asyncId = nextAsyncResourceId++;
70
+ this.#triggerAsyncId = options?.triggerAsyncId ?? 0;
71
+ }
72
+
73
+ runInAsyncScope<T>(fn: (...args: never[]) => T, thisArg?: unknown, ...args: never[]): T {
74
+ return fn.apply(thisArg, args);
75
+ }
76
+
77
+ emitDestroy(): this { return this; }
78
+ asyncId(): number { return this.#asyncId; }
79
+ triggerAsyncId(): number { return this.#triggerAsyncId; }
80
+
81
+ static bind<T extends (...args: never[]) => unknown>(fn: T, _type?: string): T {
82
+ return fn;
83
+ }
84
+ }
85
+
86
+ /**
87
+ * `internal/timers`. Only `setStreamTimeout` in
88
+ * `internal/stream_base_commons.js` uses it, for `socket.setTimeout`, and
89
+ * Node's timer for that is unref'd: a socket's idle timeout never holds a
90
+ * process open. The engine counts a guest's own timers to decide whether a
91
+ * program is still working, and a timer made here is made with the realm's
92
+ * own `setTimeout` rather than the guest's view of it, so it is not counted —
93
+ * which is exactly what unref'd means.
94
+ */
95
+ const kTimeout = Symbol('timeout');
96
+
97
+ /** The realm's own timer, never the guest's counted one. */
98
+ function realmSetTimeout(fn: () => void, ms: number): unknown {
99
+ const realm = globalThis as unknown as {
100
+ __browserRuntimeNativeSetTimeout?: (fn: () => void, ms: number) => unknown;
101
+ };
102
+ return (realm.__browserRuntimeNativeSetTimeout ?? globalThis.setTimeout).call(globalThis, fn, ms);
103
+ }
104
+ function realmClearTimeout(id: unknown): void {
105
+ const realm = globalThis as unknown as {
106
+ __browserRuntimeNativeClearTimeout?: (id: unknown) => void;
107
+ };
108
+ (realm.__browserRuntimeNativeClearTimeout ?? globalThis.clearTimeout).call(globalThis, id as number);
109
+ }
110
+
111
+ /**
112
+ * What `setUnrefTimeout` answers: a timer that can be refreshed in place, as
113
+ * Node's `Timeout` can, and that `timers.clearTimeout` here knows how to stop.
114
+ */
115
+ export class UnrefTimeout {
116
+ private id: unknown = null;
117
+ private readonly onTimeout: () => void;
118
+ private readonly msecs: number;
119
+
120
+ constructor(onTimeout: () => void, msecs: number) {
121
+ this.onTimeout = onTimeout;
122
+ this.msecs = msecs;
123
+ this.id = realmSetTimeout(() => { this.id = null; this.onTimeout(); }, msecs);
124
+ }
125
+
126
+ refresh(): this {
127
+ if (this.id !== null) realmClearTimeout(this.id);
128
+ this.id = realmSetTimeout(() => { this.id = null; this.onTimeout(); }, this.msecs);
129
+ return this;
130
+ }
131
+
132
+ stop(): void {
133
+ if (this.id !== null) realmClearTimeout(this.id);
134
+ this.id = null;
135
+ }
136
+
137
+ ref(): this { return this; }
138
+ unref(): this { return this; }
139
+ hasRef(): boolean { return false; }
140
+ }
141
+
142
+ export const TIMEOUT_MAX = 2 ** 31 - 1;
143
+
144
+ export const internalTimers = {
145
+ kTimeout,
146
+ TIMEOUT_MAX,
147
+ setUnrefTimeout: (fn: () => void, msecs: number): UnrefTimeout => new UnrefTimeout(fn, msecs),
148
+ /** Node's `getTimerDuration`: a number in range, and 1 for anything under it. */
149
+ getTimerDuration(msecs: unknown, name: string): number {
150
+ if (typeof msecs !== 'number') {
151
+ throw Object.assign(new TypeError(`The "${name}" argument must be of type number. Received ${typeof msecs}`), { code: 'ERR_INVALID_ARG_TYPE' });
152
+ }
153
+ if (msecs < 0 || !Number.isFinite(msecs)) {
154
+ throw Object.assign(new RangeError(`The value of "${name}" is out of range. It must be a non-negative finite number. Received ${msecs}`), { code: 'ERR_OUT_OF_RANGE' });
155
+ }
156
+ if (msecs === 0) return 0;
157
+ if (msecs > TIMEOUT_MAX) return 1;
158
+ return msecs < 1 ? 1 : msecs;
159
+ },
160
+ };
161
+
162
+ /** `internal/streams/state`: Node's default high-water marks. */
163
+ export const internalStreamsState = {
164
+ getDefaultHighWaterMark: (objectMode?: boolean): number => (objectMode ? 16 : 65536),
165
+ setDefaultHighWaterMark: (): void => {},
166
+ };
167
+
168
+ /** `internal/process/task_queues`: the realm's own microtask queue. */
169
+ export const internalTaskQueues = {
170
+ queueMicrotask: (fn: () => void): void => queueMicrotask(fn),
171
+ setHasTickScheduled: (): void => {},
172
+ runNextTicks: (): void => {},
173
+ };
174
+
175
+ /** `internal/event_target`: the one symbol `abort_listener.js` reads. */
176
+ // Registry symbols, not unique ones: the engine's bundle can be evaluated
177
+ // more than once in a realm -- a page's copy and a worker's -- and each
178
+ // evaluation would otherwise mint its own key. The default below was defined
179
+ // under one key and `events.js` read another, so a fresh `EventTarget`
180
+ // answered nothing while one that had been set answered fine.
181
+ const kEventsSymbol = Symbol.for('nodejs.event_target.events');
182
+ // Every `EventTarget` answers the symbol above with an empty map, for the
183
+ // reason given on `kEvents` below. One getter on the prototype, installed
184
+ // where the binding is defined rather than inside a guest's realm, because
185
+ // `events.js` reads it off whatever target it was handed.
186
+ if (typeof EventTarget === 'function' && !(kEventsSymbol in EventTarget.prototype)) {
187
+ const empty = new Map<unknown, unknown>();
188
+ Object.defineProperty(EventTarget.prototype, kEventsSymbol, { get: () => empty, configurable: true });
189
+ }
190
+
191
+ export const internalEventTarget = {
192
+ kResistStopPropagation: Symbol('kResistStopPropagation'),
193
+ /** `internal/streams/operators.js` marks its abort listener weak with this. */
194
+ kWeakHandler: Symbol('kWeakHandler'),
195
+ /**
196
+ * Whether a thing is an `EventTarget`. `events.js` asks before it treats a
197
+ * value as one -- `once`, `on`, `getEventListeners` and `setMaxListeners`
198
+ * all take either an emitter or a target. Node's own `EventTarget` is a
199
+ * class in `internal/event_target.js`; the engine's is the realm's, which
200
+ * is where that class comes from in the first place.
201
+ */
202
+ isEventTarget: (value: unknown): boolean =>
203
+ typeof EventTarget === 'function' && value instanceof EventTarget,
204
+ /**
205
+ * The map Node keeps its own EventTarget's listeners in.
206
+ *
207
+ * THE LOSS, named: the realm's `EventTarget` keeps its listeners where no
208
+ * JavaScript can reach them. The DOM has no way to ask what is listening --
209
+ * `addEventListener` is a door in, and there is no door out -- so
210
+ * `events.getEventListeners(target)` cannot answer for one. It reads this
211
+ * map unguarded, so every target answers with an empty one: the call
212
+ * reports no listeners rather than throwing at a program that asked a fair
213
+ * question. An `EventEmitter` is unaffected; it answers from its own
214
+ * `listeners()`, which is the branch above this one in `events.js`.
215
+ */
216
+ kEvents: kEventsSymbol,
217
+ kNewListener: Symbol('kNewListener'),
218
+ kRemoveListener: Symbol('kRemoveListener'),
219
+ };
220
+
221
+ /**
222
+ * `internal/options`: the command-line options Node's `net` reads. The engine
223
+ * takes no command line of its own, so each is Node's own default.
224
+ */
225
+ const optionValues: Record<string, unknown> = {
226
+ '--network-family-autoselection': true,
227
+ '--network-family-autoselection-attempt-timeout': 250,
228
+ '--no-deprecation': false,
229
+ '--throw-deprecation': false,
230
+ '--trace-deprecation': false,
231
+ '--pending-deprecation': false,
232
+ '--report-uncaught-exception': false,
233
+ '--experimental-print-required-tla': false,
234
+ };
235
+
236
+ export const internalOptions = {
237
+ getOptionValue: (name: string): unknown => optionValues[name],
238
+ getEmbedderOptions: () => ({ shouldNotRegisterESMLoader: false, noGlobalSearchPaths: false, noBrowserGlobals: false }),
239
+ };
240
+
241
+ /** `internal/perf/observe`: nothing observes `net` in the engine. */
242
+ export const internalPerfObserve = {
243
+ hasObserver: (): boolean => false,
244
+ startPerf: (): void => {},
245
+ stopPerf: (): void => {},
246
+ };
247
+
248
+ /** `internal/assert`: Node's internal assertion, which no program should ever see. */
249
+ export function internalAssert(value: unknown, message?: string): asserts value {
250
+ if (!value) throw new Error(`Internal assertion failed${message ? `: ${message}` : ''}`);
251
+ }
252
+ internalAssert.fail = (message?: string): never => {
253
+ throw new Error(`Internal assertion failed${message ? `: ${message}` : ''}`);
254
+ };
255
+ internalAssert.ok = internalAssert;
256
+
257
+ /** `internal/v8/startup_snapshot`: the engine never builds one. */
258
+ export const internalStartupSnapshot = {
259
+ namespace: {
260
+ isBuildingSnapshot: (): boolean => false,
261
+ addSerializeCallback: (): void => {},
262
+ addDeserializeCallback: (): void => {},
263
+ setDeserializeMainFunction: (): void => {},
264
+ },
265
+ runDeserializeCallbacks: (): void => {},
266
+ };
267
+
268
+ /**
269
+ * `internal/process/permission`: the engine runs no permission model, so
270
+ * nothing is denied and there are no flags for `child_process.js` to copy
271
+ * into a child's `NODE_OPTIONS`.
272
+ */
273
+ export const internalPermission = {
274
+ isEnabled: (): boolean => false,
275
+ has: (): boolean => true,
276
+ availableFlags: (): string[] => [],
277
+ };
@@ -0,0 +1,98 @@
1
+ /**
2
+ * `internal/util/types`, bound by hand -- which is also `util.types`, because
3
+ * Node's `util.types` IS this module.
4
+ *
5
+ * Node's own is `internalBinding('types')`, V8 asking a value what it is from
6
+ * the outside. The engine asks the one question a tab can ask: the value's
7
+ * own `Object.prototype.toString` tag, which V8 fills in from the same
8
+ * internal type and which a program cannot forge without saying so. A
9
+ * `Symbol.toStringTag` a program sets IS such a statement, and Node's answer
10
+ * and this one differ only for an object that has lied about itself.
11
+ *
12
+ * Two exceptions, each for a reason a tab cannot get around:
13
+ *
14
+ * A `Proxy` shows the tag of the thing it wraps, by design, so no tag can
15
+ * find one. The engine's realm records every proxy it makes -- `runtime.ts`
16
+ * replaces the realm's `Proxy` for a guest -- and `isProxy` answers from that
17
+ * record. undici's `Headers` guard asks it of every init it converts, and a
18
+ * proxy the host made before the guest's realm existed is not in the record.
19
+ *
20
+ * `isExternal` is always false: nothing in a tab is a native handle.
21
+ *
22
+ * `internal/util` itself is no longer here: it is Node's own file now, and
23
+ * every name the vendored files used to take from a hand-bound object is
24
+ * Node's own code, on the bindings under `../binding/`.
25
+ */
26
+
27
+ /**
28
+ * Every proxy a guest's realm has made. `runtime.ts` fills it, from the
29
+ * `Proxy` it installs for a guest; this module reads it.
30
+ */
31
+ export const recordedProxies = new WeakSet<object>();
32
+
33
+ const tagOf = (value: unknown): string => Object.prototype.toString.call(value);
34
+
35
+ /** The `size` getters, which need a real Map or Set behind `this`. */
36
+ const mapSize = Object.getOwnPropertyDescriptor(Map.prototype, 'size')?.get as () => number;
37
+ const setSize = Object.getOwnPropertyDescriptor(Set.prototype, 'size')?.get as () => number;
38
+
39
+ /**
40
+ * Whether a value carries the internal slot a built-in method needs. Calling
41
+ * the method is the only test of a slot JavaScript has, and a value without
42
+ * one throws rather than answering -- which is the answer.
43
+ */
44
+ function hasSlot(value: unknown, method: (...args: never[]) => unknown, args: unknown[] = []): boolean {
45
+ if (value === null || (typeof value !== 'object' && typeof value !== 'function')) return false;
46
+ try { (method as (...a: unknown[]) => unknown).apply(value, args); return true; } catch { return false; }
47
+ }
48
+ const taggedAs = (tag: string) => (value: unknown): boolean => tagOf(value) === tag;
49
+
50
+ /** `internal/util/types`, which is `util.types`. */
51
+ export const internalUtilTypes: Record<string, (value: unknown) => boolean> = {
52
+ isArgumentsObject: taggedAs('[object Arguments]'),
53
+ isArrayBuffer: taggedAs('[object ArrayBuffer]'),
54
+ isSharedArrayBuffer: taggedAs('[object SharedArrayBuffer]'),
55
+ isAnyArrayBuffer: (value) => tagOf(value) === '[object ArrayBuffer]' || tagOf(value) === '[object SharedArrayBuffer]',
56
+ isArrayBufferView: (value) => ArrayBuffer.isView(value),
57
+ isDataView: taggedAs('[object DataView]'),
58
+ isTypedArray: (value) => ArrayBuffer.isView(value) && tagOf(value) !== '[object DataView]',
59
+ isUint8Array: taggedAs('[object Uint8Array]'),
60
+ isAsyncFunction: taggedAs('[object AsyncFunction]'),
61
+ isGeneratorFunction: (value) => tagOf(value) === '[object GeneratorFunction]' || tagOf(value) === '[object AsyncGeneratorFunction]',
62
+ isGeneratorObject: (value) => tagOf(value) === '[object Generator]' || tagOf(value) === '[object AsyncGenerator]',
63
+ isRegExp: taggedAs('[object RegExp]'),
64
+ isMapIterator: taggedAs('[object Map Iterator]'),
65
+ isSetIterator: taggedAs('[object Set Iterator]'),
66
+ isModuleNamespaceObject: taggedAs('[object Module]'),
67
+ isPromise: taggedAs('[object Promise]'),
68
+ isNativeError: (value) => value instanceof Error && tagOf(value) === '[object Error]',
69
+ // A boxed primitive is asked the one question only a real one can answer:
70
+ // its own prototype's `valueOf` needs the internal slot and throws without
71
+ // it. A tag would say yes to `Object.create(String.prototype)`, which has
72
+ // no slot at all, and `isDeepStrictEqual` then compared it as a string and
73
+ // threw where Node answered.
74
+ isBooleanObject: (value) => hasSlot(value, Boolean.prototype.valueOf),
75
+ isNumberObject: (value) => hasSlot(value, Number.prototype.valueOf),
76
+ isStringObject: (value) => hasSlot(value, String.prototype.valueOf),
77
+ isSymbolObject: (value) => hasSlot(value, Symbol.prototype.valueOf),
78
+ isBigIntObject: (value) => hasSlot(value, BigInt.prototype.valueOf),
79
+ isDate: (value) => hasSlot(value, Date.prototype.valueOf),
80
+ isMap: (value) => hasSlot(value, mapSize),
81
+ isSet: (value) => hasSlot(value, setSize),
82
+ isWeakMap: (value) => hasSlot(value, WeakMap.prototype.has, ['x']),
83
+ isWeakSet: (value) => hasSlot(value, WeakSet.prototype.has, ['x']),
84
+ isKeyObject: () => false,
85
+ isCryptoKey: (value) => typeof CryptoKey !== 'undefined' && value instanceof CryptoKey,
86
+ isExternal: () => false,
87
+ isProxy: (value) => (typeof value === 'object' || typeof value === 'function') && value !== null && recordedProxies.has(value as object),
88
+ };
89
+
90
+ internalUtilTypes.isBoxedPrimitive = (value) =>
91
+ internalUtilTypes.isBooleanObject(value) || internalUtilTypes.isNumberObject(value) ||
92
+ internalUtilTypes.isStringObject(value) || internalUtilTypes.isSymbolObject(value) ||
93
+ internalUtilTypes.isBigIntObject(value);
94
+
95
+ for (const name of ['Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'Int8Array', 'Int16Array',
96
+ 'Int32Array', 'Float16Array', 'Float32Array', 'Float64Array', 'BigInt64Array', 'BigUint64Array']) {
97
+ internalUtilTypes[`is${name}`] = taggedAs(`[object ${name}]`);
98
+ }
@@ -0,0 +1,158 @@
1
+ /**
2
+ * A vendored Node module, and a class out of one, named before the loader can
3
+ * build it.
4
+ *
5
+ * The engine's own TypeScript imports `Buffer` and `Readable` the way any
6
+ * program does -- as values, at the top of a file. But `buffer` and `stream`
7
+ * are vendored Node files that `./load.ts` builds out of the binding and the
8
+ * internals, and several of the engine's own shims are what that loader
9
+ * resolves a public name to: the two sit in one import cycle, and which side a
10
+ * bundler evaluates first is its own decision, not a thing the source can
11
+ * state. Taking the class at import time therefore failed to load the engine
12
+ * at all, differently on each build.
13
+ *
14
+ * So a name here stands for the thing rather than being it, until the first
15
+ * time anyone touches it. `Buffer.from(…)` is one property read through a
16
+ * proxy and then the real call; `x instanceof Buffer` reads the real class's
17
+ * `Symbol.hasInstance`; `new Readable()` constructs the real one. Node's own
18
+ * files never go through this -- they `require('buffer')` and get the class.
19
+ */
20
+ // The loader itself, not the hook a binding uses: importing it is what puts
21
+ // it in the graph at all, so a program that only ever touches `Readable`
22
+ // still has a loader to build it with.
23
+ import { nodeLibInternalRequire } from './load';
24
+
25
+
26
+ /** The module a name stands for, loaded once, on the first property read. */
27
+ function loadedModule(name: string, cache: { value?: Record<string, unknown> }): Record<string, unknown> {
28
+ return cache.value ??= nodeLibInternalRequire(name) as Record<string, unknown>;
29
+ }
30
+
31
+ /**
32
+ * A vendored module object, whose properties are read when they are asked for.
33
+ *
34
+ * A module object is a program's to write on, and packages do: `graceful-fs`
35
+ * -- which half of npm loads, openvscode-server through `fs-extra` and
36
+ * `@vscode/deviceid` -- defines `Symbol.for('graceful-fs.queue')` on `fs` with
37
+ * `Object.defineProperty` and then clones the module, which walks its keys.
38
+ * Every trap here read the loaded module and none read the proxy's own target,
39
+ * where a define with no trap of its own lands: the read came back
40
+ * `undefined`, `key in fs` answered false, and `Reflect.ownKeys(fs)` threw
41
+ * `'ownKeys' on proxy: trap result did not include
42
+ * 'Symbol(graceful-fs.queue)'` -- a proxy may neither hide nor deny a
43
+ * non-configurable own key of its target. graceful-fs threw out of its own
44
+ * module load, so every program that loads it died there: in the substrate's
45
+ * tab, openvscode-server's server at boot and its extension host, which exited
46
+ * 1 without a word because a forked host's console goes to its parent over IPC
47
+ * and the server drops those messages.
48
+ *
49
+ * So a define lands on the module, as it would in Node, and a
50
+ * non-configurable one lands on the target as well because the proxy has to
51
+ * report it from there; every read answers the target first and the module
52
+ * after. This is the shape the guest global's proxy in `src/runtime.ts` uses,
53
+ * for the same reason.
54
+ */
55
+ export function lazyModule<T extends object>(name: string): T {
56
+ const cache: { value?: Record<string, unknown> } = {};
57
+ const own = (target: object, key: PropertyKey): boolean =>
58
+ Reflect.getOwnPropertyDescriptor(target, key) !== undefined;
59
+ return new Proxy({} as T, {
60
+ get: (target, key, receiver) => (own(target, key)
61
+ ? Reflect.get(target, key, receiver)
62
+ : Reflect.get(loadedModule(name, cache), key)),
63
+ set: (target, key, value, receiver) => (own(target, key)
64
+ ? Reflect.set(target, key, value, receiver)
65
+ : Reflect.set(loadedModule(name, cache), key, value)),
66
+ has: (target, key) => own(target, key) || Reflect.has(loadedModule(name, cache), key),
67
+ defineProperty: (target, key, descriptor) => {
68
+ const module = loadedModule(name, cache);
69
+ if (descriptor.configurable === false) {
70
+ if (!Reflect.defineProperty(target, key, descriptor)) return false;
71
+ Reflect.defineProperty(module, key, { ...descriptor, configurable: true });
72
+ return true;
73
+ }
74
+ return Reflect.defineProperty(module, key, descriptor)
75
+ || Reflect.defineProperty(target, key, descriptor);
76
+ },
77
+ deleteProperty: (target, key) => {
78
+ if (own(target, key) && !Reflect.deleteProperty(target, key)) return false;
79
+ return Reflect.deleteProperty(loadedModule(name, cache), key);
80
+ },
81
+ ownKeys: (target) => {
82
+ const keys = Reflect.ownKeys(target);
83
+ for (const key of Reflect.ownKeys(loadedModule(name, cache))) if (!keys.includes(key)) keys.push(key);
84
+ return keys;
85
+ },
86
+ getOwnPropertyDescriptor: (target, key) => {
87
+ const mine = Reflect.getOwnPropertyDescriptor(target, key);
88
+ if (mine !== undefined) return mine;
89
+ const descriptor = Reflect.getOwnPropertyDescriptor(loadedModule(name, cache), key);
90
+ return descriptor === undefined ? undefined : { ...descriptor, configurable: true };
91
+ },
92
+ }) as T;
93
+ }
94
+
95
+ /**
96
+ * One export of a vendored module that is a class or a function: callable,
97
+ * constructible, and the same object to `instanceof` as the real one.
98
+ */
99
+ export function lazyExport<T>(name: string, key: string): T {
100
+ const cache: { value?: Record<string, unknown> } = {};
101
+ // The prototype a subclass takes when it is DEFINED. `class Socket extends
102
+ // EventEmitter` reads `EventEmitter.prototype` at the moment the class is
103
+ // written, which is while the bundle is still evaluating -- before the
104
+ // loader, its bindings, or the shims those bindings read have run their own
105
+ // bodies, and several of them are in one import cycle with this file (the
106
+ // `constants` binding reads the `crypto` shim, which is an EventEmitter).
107
+ // Loading there is not late, it is impossible. So a class defined that early
108
+ // is given this empty object as its parent prototype, and the first time the
109
+ // real class is built the object is grafted onto the real prototype: the
110
+ // subclass's chain becomes `Subclass.prototype -> stand -> EventEmitter.
111
+ // prototype`, so every method resolves and `instanceof` holds. After the
112
+ // graft the real prototype is what is handed out, so an instance Node's own
113
+ // code made is an instance of the same class to everyone.
114
+ const stand = Object.create(null) as object;
115
+ let grafted = false;
116
+ const real = (): object => {
117
+ const value = loadedModule(name, cache)[key] as object;
118
+ if (!grafted) {
119
+ grafted = true;
120
+ const prototype = (value as { prototype?: object }).prototype;
121
+ if (prototype) Object.setPrototypeOf(stand, prototype);
122
+ }
123
+ return value;
124
+ };
125
+ // A plain function is the target because it is the one thing that is both
126
+ // callable and constructible; nothing of it is ever read.
127
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
128
+ const target = function stand() {} as unknown as object;
129
+ return new Proxy(target, {
130
+ get: (_t, propertyKey, receiver) => {
131
+ // Before the real class exists, `prototype` is the stand-in above; from
132
+ // the first load on it is the real one.
133
+ if (propertyKey === 'prototype' && !grafted && !cache.value) return stand;
134
+ return Reflect.get(real(), propertyKey, receiver);
135
+ },
136
+ set: (_t, propertyKey, value) => Reflect.set(real(), propertyKey, value),
137
+ has: (_t, propertyKey) => Reflect.has(real(), propertyKey),
138
+ getPrototypeOf: () => Reflect.getPrototypeOf(real()),
139
+ // A module whose exports IS this function -- `require("events")` is
140
+ // Node's `EventEmitter` -- is read as a module too: destructured,
141
+ // enumerated, asked for its own keys. The target's own `prototype`,
142
+ // `length` and `name` are non-configurable and must be reported as the
143
+ // target has them, so they are answered from the target and everything
144
+ // else from the real class.
145
+ ownKeys: () => {
146
+ const own = Reflect.ownKeys(target);
147
+ return [...Reflect.ownKeys(real()).filter((key) => !own.includes(key)), ...own];
148
+ },
149
+ getOwnPropertyDescriptor: (_t, propertyKey) => {
150
+ const fromTarget = Reflect.getOwnPropertyDescriptor(target, propertyKey);
151
+ if (fromTarget !== undefined) return fromTarget;
152
+ const own = Reflect.getOwnPropertyDescriptor(real(), propertyKey);
153
+ return own === undefined ? undefined : { ...own, configurable: true };
154
+ },
155
+ apply: (_t, thisArg, args) => Reflect.apply(real() as (...a: unknown[]) => unknown, thisArg, args as unknown[]),
156
+ construct: (_t, args, newTarget) => Reflect.construct(real() as new (...a: unknown[]) => object, args as unknown[], newTarget === target ? (real() as new (...a: unknown[]) => object) : newTarget),
157
+ }) as T;
158
+ }