@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,121 @@
1
+ /**
2
+ * The realm belongs to whoever owns the process.
3
+ *
4
+ * The engine corrects globals so that a guest behaves like Node: a timer that
5
+ * answers `unref`, a `Request` that keeps the headers it was built with, a
6
+ * `Proxy` `util.types.isProxy` can recognise, an AsyncLocalStorage store
7
+ * carried into every continuation. In a tab those corrections are right,
8
+ * because the realm exists to run guests and there is nobody else in it.
9
+ *
10
+ * Imported into a Node process the engine is a library, and the realm is the
11
+ * host's: its `setTimeout` is the one its own code scheduled on, its
12
+ * `Promise.prototype.then` is the one its own promises resolve through, and a
13
+ * channel the engine opened is a handle its loop counts. `node --test` over a
14
+ * file that only imported the engine never exited, because a module-scope
15
+ * `BroadcastChannel` held the loop open; the substrate's gate ran it with
16
+ * `--test-force-exit`.
17
+ *
18
+ * So the rule is: importing the engine changes nothing and opens nothing.
19
+ * A realm correction is registered here at load and installed by a `Runtime`
20
+ * — the act of asking for a guest — and every property it takes is
21
+ * remembered, so `restoreHostGlobals()` gives the realm back exactly as it
22
+ * was found.
23
+ */
24
+
25
+ type Undo = () => void;
26
+
27
+ const installers: Array<() => void> = [];
28
+ const undos: Undo[] = [];
29
+ let installed = false;
30
+
31
+ /**
32
+ * A correction a guest needs from the realm. It runs when a runtime exists,
33
+ * not when this module is loaded, and it must be idempotent: a later runtime
34
+ * runs it again. Registering after a runtime is already up installs at once,
35
+ * since the guest is already there.
36
+ */
37
+ export function forGuestRealm(install: () => void): void {
38
+ installers.push(install);
39
+ if (installed) install();
40
+ }
41
+
42
+ /**
43
+ * Replace a property of the realm for a guest, remembering what the host had
44
+ * under it. A name the host did not have is deleted on restore; one it had is
45
+ * put back with its own descriptor, flags and all.
46
+ */
47
+ export function takeFromHost(target: object, key: PropertyKey, value: unknown): void {
48
+ const previous = Object.getOwnPropertyDescriptor(target, key);
49
+ undos.push(() => {
50
+ if (previous) Object.defineProperty(target, key, previous);
51
+ else Reflect.deleteProperty(target, key);
52
+ });
53
+ Object.defineProperty(target, key, {
54
+ value,
55
+ writable: previous ? previous.writable !== false : true,
56
+ enumerable: previous ? previous.enumerable : false,
57
+ configurable: true,
58
+ });
59
+ }
60
+
61
+ /**
62
+ * Define a property of the realm for a guest with a descriptor of its own — a
63
+ * getter, or a flag the value form cannot carry — remembering the host's.
64
+ */
65
+ export function defineOnHost(target: object, key: PropertyKey, descriptor: PropertyDescriptor): void {
66
+ const previous = Object.getOwnPropertyDescriptor(target, key);
67
+ undos.push(() => {
68
+ if (previous) Object.defineProperty(target, key, previous);
69
+ else Reflect.deleteProperty(target, key);
70
+ });
71
+ Object.defineProperty(target, key, descriptor);
72
+ }
73
+
74
+ /**
75
+ * Install every registered correction. Called by each `Runtime`, because a
76
+ * realm a guest has been running in may have lost one — a guest that assigns
77
+ * to its own `globalThis` assigns to the realm — and every correction is
78
+ * written to notice its own work and do nothing the second time. Nothing here
79
+ * runs when this module is merely loaded.
80
+ */
81
+ export function installGuestRealm(): void {
82
+ installed = true;
83
+ for (const install of installers) install();
84
+ }
85
+
86
+ /** Whether the realm currently carries the engine's corrections. */
87
+ export function guestRealmInstalled(): boolean {
88
+ return installed;
89
+ }
90
+
91
+ /**
92
+ * Give the realm back. Every property the engine took returns to what the
93
+ * host had, newest first. A host that created a runtime inside its own
94
+ * process and is done with it gets its own globals back; a runtime created
95
+ * afterwards installs them again.
96
+ */
97
+ export function restoreHostGlobals(): void {
98
+ installed = false;
99
+ while (undos.length) {
100
+ const undo = undos.pop();
101
+ try { undo!(); } catch { /* a realm that refuses the restore keeps the patch */ }
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Work the host is doing on a guest's behalf, counted while it is in flight,
107
+ * so the run loop waits for a build that prints nothing. The engine's parts
108
+ * share the count through `globalThis` when more than one bundle is loaded in
109
+ * a realm; until a guest exists the count is this module's own object, so
110
+ * importing the engine adds no name to the host's global.
111
+ */
112
+ const ownHeldWork = { count: 0 };
113
+
114
+ export function heldWork(): { count: number } {
115
+ return (globalThis as { __browserRuntimeHeldWork?: { count: number } }).__browserRuntimeHeldWork ?? ownHeldWork;
116
+ }
117
+
118
+ forGuestRealm(() => {
119
+ const realm = globalThis as { __browserRuntimeHeldWork?: { count: number } };
120
+ if (!realm.__browserRuntimeHeldWork) takeFromHost(globalThis, '__browserRuntimeHeldWork', ownHeldWork);
121
+ });
package/src/index.ts ADDED
@@ -0,0 +1,235 @@
1
+ /**
2
+ * tabnode's public surface.
3
+ *
4
+ * The engine is a library the substrate embeds: a filesystem, a runtime, a
5
+ * container over the two, the npm client that fills the tree, the bridge a
6
+ * page's requests reach a guest's server through, and the resolver. What a
7
+ * guest requires is not here -- a guest reaches its builtins through the
8
+ * runtime's own module table, which is `runtime.ts`.
9
+ */
10
+
11
+ // Importing this module changes nothing in the realm it is loaded into and
12
+ // opens no handle in it; a `Runtime` installs what a guest needs, and this
13
+ // hands the host's own globals back. See `host-globals.ts`.
14
+ export { restoreHostGlobals, guestRealmInstalled } from './host-globals';
15
+ export { VirtualFS } from './virtual-fs';
16
+ export type { FSNode, Stats, FSWatcher, WatchListener, WatchEventType } from './virtual-fs';
17
+ export { Runtime, execute } from './runtime';
18
+ export type { Module, RuntimeOptions, RequireFunction } from './runtime';
19
+ export { createRuntime, WorkerRuntime } from './create-runtime';
20
+ export type { IRuntime, IExecuteResult, CreateRuntimeOptions, IRuntimeOptions, VFSSnapshot } from './runtime-interface';
21
+ export { createFsShim } from './shims/fs';
22
+ export type { FsShim } from './shims/fs';
23
+ export { createProcess } from './shims/process';
24
+ export type { Process, ProcessEnv } from './shims/process';
25
+ export * as path from './shims/path';
26
+ export { httpModule as http, httpsModule as https } from './node-lib/http-module';
27
+ import { __releaseOwnedServers, __ownedServerPorts } from './node-lib/net-module';
28
+ export { netModule as net } from './node-lib/net-module';
29
+ export { eventsModule as events } from './node-lib/events-module';
30
+ export { streamModule as stream } from './node-lib/stream-module';
31
+ export { bufferModule as buffer } from './node-lib/buffer-module';
32
+ export * as url from './shims/url';
33
+ export { utilModule as util } from './node-lib/util-module';
34
+ export * as npm from './npm';
35
+ export { PackageManager, install } from './npm';
36
+ export { ServerBridge, getServerBridge, resetServerBridge } from './server-bridge';
37
+ export type { InitServiceWorkerOptions } from './server-bridge';
38
+ /** What a page's request is answered with, the shape the bridge answers. */
39
+ export type { ResponseData } from './node-lib/http-bridge';
40
+ // The bundlers' own wasm builds, as doors: a host that builds outside a run
41
+ // (the substrate's rolldown pass) reaches them here rather than through a
42
+ // guest's `require`.
43
+ export * as esbuild from './shims/esbuild';
44
+ export * as rollup from './shims/rollup';
45
+ export * as module from './shims/module';
46
+ export * as perf_hooks from './shims/perf_hooks';
47
+ export * as worker_threads from './shims/worker_threads';
48
+
49
+ import { VirtualFS } from './virtual-fs';
50
+ import { Runtime, RuntimeOptions } from './runtime';
51
+ import { PackageManager } from './npm';
52
+ import { ServerBridge, getServerBridge } from './server-bridge';
53
+ import { runCommand, registerRunStreams, releaseRunStreams, sendStdin } from './shims/child_process';
54
+ import { Server as NetServer, __releaseOwnedHandles, type Socket as NetSocket } from './node-lib/net-module';
55
+
56
+ import { __currentProcessToken, __runFor, __stopOwnedProcess, runPid, processByPid } from './process-tokens';
57
+ export { runPid, processByPid };
58
+
59
+ export interface RunResult {
60
+ stdout: string;
61
+ stderr: string;
62
+ exitCode: number;
63
+ }
64
+
65
+ export interface RunOptions {
66
+ cwd?: string;
67
+ /** The environment the command runs in, as `child_process.exec` takes it. */
68
+ env?: Record<string, string>;
69
+ /** What the shell reads on stdin, so a builtin reads what was piped to it. */
70
+ stdin?: string;
71
+ /** Callback for streaming stdout chunks as they arrive (for long-running commands like vitest watch) */
72
+ onStdout?: (data: string) => void;
73
+ /** Callback for streaming stderr chunks as they arrive */
74
+ onStderr?: (data: string) => void;
75
+ /** AbortSignal to cancel long-running commands */
76
+ signal?: AbortSignal;
77
+ /**
78
+ * A name for this run. The `node` command records the guest process it
79
+ * creates under it for the run's lifetime, and the container answers
80
+ * `pendingTimers`, `processPorts` and `stopProcess` about that name.
81
+ */
82
+ processToken?: string;
83
+ /**
84
+ * The host keeps this run open (a watch or an interactive shell); a run that
85
+ * is not held ends when its loop has nothing left, as Node's does. A
86
+ * `signal` alone is an abort handle, not a hold.
87
+ */
88
+ held?: boolean;
89
+ }
90
+
91
+ /** Names for runs the caller did not name; a run's state is kept under its name. */
92
+ let __nextRunName = 1;
93
+
94
+ export interface ContainerOptions extends RuntimeOptions {
95
+ /** The filesystem the container runs on; one is built in memory when absent. */
96
+ vfs?: VirtualFS;
97
+ baseUrl?: string;
98
+ onServerReady?: (port: number, url: string) => void;
99
+ }
100
+
101
+ /**
102
+ * Create a new WebContainer-like environment
103
+ */
104
+ export function createContainer(options?: ContainerOptions): {
105
+ vfs: VirtualFS;
106
+ runtime: Runtime;
107
+ npm: PackageManager;
108
+ serverBridge: ServerBridge;
109
+ execute: (code: string, filename?: string) => { exports: unknown };
110
+ runFile: (filename: string) => { exports: unknown };
111
+ run: (command: string, options?: RunOptions) => Promise<RunResult>;
112
+ pendingTimers: (token: string) => number;
113
+ processPorts: (token: string) => number[];
114
+ stopProcess: (token: string) => boolean;
115
+ /**
116
+ * Input for one run's guest, by its process token; without a token, the most
117
+ * recently started held run, which is the prompt a person is typing to.
118
+ */
119
+ sendInput: (data: string, token?: string) => void;
120
+ /** The run whose guest code is executing, for a caller attributing a child. */
121
+ currentProcessToken: () => string | null;
122
+ /** The numbers a named run, or the current one, was started with. */
123
+ runPid: (token?: string | null) => { pid: number; ppid: number } | undefined;
124
+ /** The numbers a live process carries, looked up by its own pid. */
125
+ processByPid: (pid: number) => { pid: number; ppid: number } | undefined;
126
+ listenNet: (port: number, onConnection: (socket: NetSocket) => void) => () => void;
127
+ createREPL: () => { eval: (code: string) => unknown };
128
+ on: (event: string, listener: (...args: unknown[]) => void) => void;
129
+ } {
130
+ // A container takes the filesystem it is given. Building its own in memory
131
+ // with no way to hand it another left the worker that owns the origin's store
132
+ // unable to give it one that keeps the index in memory and the bytes in the
133
+ // pack.
134
+ const vfs = (options && options.vfs) || new VirtualFS();
135
+ const runtime = new Runtime(vfs, options);
136
+ const npmManager = new PackageManager(vfs);
137
+ // A container owns its servers. One process-wide bridge meant two runtimes in
138
+ // one page shared a port space: the second dev server to claim 5173 took the
139
+ // first one's requests, and a consumer that asked for two isolated runtimes
140
+ // got one. Each container holds its own bridge, and the page decides which of
141
+ // them a preview or a service worker is wired to.
142
+ const serverBridge = new ServerBridge({
143
+ baseUrl: options?.baseUrl,
144
+ onServerReady: options?.onServerReady,
145
+ });
146
+
147
+ return {
148
+ vfs,
149
+ runtime,
150
+ npm: npmManager,
151
+ serverBridge,
152
+ execute: (code: string, filename?: string) => runtime.execute(code, filename),
153
+ runFile: (filename: string) => runtime.runFile(filename),
154
+ run: (command: string, runOptions?: RunOptions): Promise<RunResult> => {
155
+ // If signal is already aborted, resolve immediately
156
+ if (runOptions?.signal?.aborted) {
157
+ return Promise.resolve({ stdout: '', stderr: '', exitCode: 130 });
158
+ }
159
+
160
+ // Every run has a name, because what the host gave this run — its
161
+ // streams, its signal, whether it is held — is kept under that name and
162
+ // not in a module global a child's run would overwrite.
163
+ const processToken = typeof runOptions?.processToken === 'string' && runOptions.processToken.length > 0
164
+ ? runOptions.processToken
165
+ : `run-${__nextRunName++}`;
166
+ registerRunStreams(processToken, {
167
+ onStdout: runOptions?.onStdout,
168
+ onStderr: runOptions?.onStderr,
169
+ signal: runOptions?.signal,
170
+ held: runOptions?.held === true,
171
+ });
172
+
173
+ return new Promise((resolve) => {
174
+ // `container.run("cat", { stdin })` used to reach the engine's shell
175
+ // without its stdin: the run dropped it before exec, and exec dropped
176
+ // it before the shell. Both forward it, so a builtin reads what was
177
+ // piped, as it does in a Node shell.
178
+ runCommand(command, { cwd: runOptions?.cwd, env: runOptions?.env, stdin: typeof runOptions?.stdin === 'string' ? runOptions.stdin : undefined, processToken, vfs }, (error, stdout, stderr) => {
179
+ releaseRunStreams(processToken);
180
+ resolve({
181
+ stdout: String(stdout),
182
+ stderr: String(stderr),
183
+ exitCode: error ? (error.code ?? 1) : 0,
184
+ });
185
+ });
186
+ });
187
+ },
188
+ // What a host that named a run can ask about it, and the one thing it can
189
+ // do to it. A run nobody named, and a name nothing runs under, answer as
190
+ // an absent process does: no timers, no ports, and a stop that does
191
+ // nothing.
192
+ /** The timers the named run's guest still holds, as Node's loop counts them. */
193
+ pendingTimers: (token: string): number => __runFor(token)?.pendingTimers() ?? 0,
194
+ /** The ports the servers the named run opened are listening on. */
195
+ processPorts: (token: string): number[] => __ownedServerPorts(token),
196
+ /** End the named run: its timers stop and its servers are released. */
197
+ stopProcess: (token: string): boolean => {
198
+ const known = __runFor(token) !== undefined || __ownedServerPorts(token).length > 0;
199
+ // The servers first, and their timers here rather than on a tick of
200
+ // their own: a caller that asks is told what it may then read back.
201
+ __releaseOwnedServers(token, false);
202
+ __releaseOwnedHandles(token);
203
+ __stopOwnedProcess(token);
204
+ return known;
205
+ },
206
+ /**
207
+ * Input for one run's guest, by its process token; without a token, the most
208
+ * recently started held run, which is the prompt a person is typing to.
209
+ */
210
+ sendInput: (data: string, token?: string) => sendStdin(data, token),
211
+ currentProcessToken: () => __currentProcessToken(),
212
+ runPid: (token) => runPid(token === undefined ? __currentProcessToken() : token),
213
+ processByPid,
214
+ // A door for a program of the page to listen on a loopback port with a
215
+ // socket handler of its own, so a guest's `net.connect` reaches it: the
216
+ // registry a connect consults is the `net` shim's, and a server of the
217
+ // shim's own class is what registers in it. The call answers a disposer.
218
+ listenNet: (port: number, onConnection: (socket: NetSocket) => void) => {
219
+ const server = new NetServer(onConnection);
220
+ server.listen(port);
221
+ return () => { server.close(); };
222
+ },
223
+ createREPL: () => runtime.createREPL(),
224
+ on: (event: string, listener: (...args: unknown[]) => void) => {
225
+ serverBridge.on(event, listener);
226
+ },
227
+ };
228
+ }
229
+
230
+ export default createContainer;
231
+
232
+ // Node's module resolution as a function over any filesystem, for a host
233
+ // that resolves the way the engine does (the substrate's stand-ins do).
234
+ export { createNodeResolver } from './node-resolution';
235
+ export type { ResolutionFs, ExportsResolver, NodeResolverOptions, NodeResolver } from './node-resolution';
@@ -0,0 +1,283 @@
1
+ /**
2
+ * The Node internals a vendored `lib/*.js` file asks its binding for:
3
+ * `internal/errors` codes and `internal/validators`, with Node's messages.
4
+ *
5
+ * A guest reads `err.code` and `err.message`, and Node's own tests read both
6
+ * (test-path-parse-format.js asserts the ERR_INVALID_ARG_TYPE text word for
7
+ * word; test-wasi-options-validation.js matches the property names), so each
8
+ * message is assembled the way lib/internal/errors.js assembles it. These
9
+ * began in `shims/path.ts`, the first Node file run on a binding; `shims/wasi.ts`
10
+ * is the second, and both bind here.
11
+ */
12
+
13
+ import { inspect } from './node-lib/util-module';
14
+
15
+ /** Node's util.inspect, for the primitives that reach an error message. */
16
+ export function inspectValue(value: unknown): string {
17
+ if (typeof value === 'string') {
18
+ const escaped = value.replace(/\n/g, '\\n');
19
+ if (!escaped.includes("'")) return `'${escaped}'`;
20
+ if (!escaped.includes('"')) return `"${escaped}"`;
21
+ return `\`${escaped}\``;
22
+ }
23
+ if (typeof value === 'bigint') return `${value}n`;
24
+ if (typeof value === 'symbol') return value.toString();
25
+ return String(value);
26
+ }
27
+
28
+ /**
29
+ * lib/internal/errors.js `determineSpecificType`, the "Received ..." tail of
30
+ * every ERR_INVALID_ARG_TYPE. Node switches on `typeof` and never inspects a
31
+ * function: a function is `function <name>`, and an anonymous one is
32
+ * `function ` with the empty name, not `type function (() => {\n})`. The engine
33
+ * inspected it, so every builtin that validated an argument printed a
34
+ * program's own source back at it where Node prints a name
35
+ * (`node:wasi`'s `new WASI(() => {})`, test-wasi-options-validation.js).
36
+ * Transcribed from Node 22's source, case for case.
37
+ */
38
+ export function determineSpecificType(value: unknown): string {
39
+ if (value === null) return 'null';
40
+ if (value === undefined) return 'undefined';
41
+
42
+ const type = typeof value;
43
+
44
+ switch (type) {
45
+ case 'bigint':
46
+ return `type bigint (${value}n)`;
47
+ case 'number': {
48
+ const number = value as number;
49
+ if (number === 0) return 1 / number === -Infinity ? 'type number (-0)' : 'type number (0)';
50
+ if (number !== number) return 'type number (NaN)';
51
+ if (number === Infinity) return 'type number (Infinity)';
52
+ if (number === -Infinity) return 'type number (-Infinity)';
53
+ return `type number (${number})`;
54
+ }
55
+ case 'boolean':
56
+ return value ? 'type boolean (true)' : 'type boolean (false)';
57
+ case 'symbol':
58
+ return `type symbol (${String(value)})`;
59
+ case 'function':
60
+ return `function ${(value as { name?: string }).name}`;
61
+ case 'object': {
62
+ const ctor = (value as { constructor?: object }).constructor;
63
+ if (ctor && 'name' in ctor) return `an instance of ${(ctor as { name?: string }).name}`;
64
+ // Node: inspect(value, { depth: -1 }). The engine's util.inspect answers
65
+ // `[Object]` where Node answers `[Object: null prototype]`; reached only
66
+ // by an object whose constructor is gone, which Node's tests do not.
67
+ return `${inspect(value, { depth: -1 })}`;
68
+ }
69
+ case 'string': {
70
+ let text = value as string;
71
+ if (text.length > 28) text = `${text.slice(0, 25)}...`;
72
+ if (text.indexOf("'") === -1) return `type string ('${text}')`;
73
+ return `type string (${JSON.stringify(text)})`;
74
+ }
75
+ default: {
76
+ let inspected = inspect(value, { colors: false });
77
+ if (inspected.length > 28) inspected = `${inspected.slice(0, 25)}...`;
78
+ return `type ${type} (${inspected})`;
79
+ }
80
+ }
81
+ }
82
+
83
+ const kTypes = [
84
+ 'string', 'function', 'number', 'object',
85
+ 'Function', 'Object', 'boolean', 'bigint', 'symbol',
86
+ ];
87
+ /** lib/internal/errors.js: an expectation spelled as a class name. */
88
+ const classRegExp = /^([A-Z][a-z0-9]*)+$/;
89
+
90
+ /**
91
+ * lib/internal/errors.js ERR_INVALID_ARG_TYPE. Node sorts each expectation
92
+ * into three buckets — a primitive `type`, a class `instance`, anything else —
93
+ * and the engine had only two, so every validator that expects a class said
94
+ * "must be an Array" where Node says "must be an instance of Array"
95
+ * (`node:wasi`'s `validateArray(options.args)`,
96
+ * test-wasi-options-validation.js).
97
+ */
98
+ export class ERR_INVALID_ARG_TYPE extends TypeError {
99
+ code = 'ERR_INVALID_ARG_TYPE';
100
+ constructor(name: string, expected: string | string[], actual: unknown) {
101
+ const expectations = Array.isArray(expected) ? [...expected] : [expected];
102
+ let message = 'The ';
103
+ if (name.endsWith(' argument')) {
104
+ message += `${name} `;
105
+ } else {
106
+ message += `"${name}" ${name.includes('.') ? 'property' : 'argument'} `;
107
+ }
108
+ message += 'must be ';
109
+
110
+ const types: string[] = [];
111
+ const instances: string[] = [];
112
+ const other: string[] = [];
113
+ for (const value of expectations) {
114
+ if (kTypes.includes(value)) types.push(value.toLowerCase());
115
+ else if (classRegExp.exec(value) !== null) instances.push(value);
116
+ else other.push(value);
117
+ }
118
+
119
+ // Node: where a class is also expected, plain `object` becomes `Object`,
120
+ // so the message tells the instances apart.
121
+ if (instances.length > 0) {
122
+ const pos = types.indexOf('object');
123
+ if (pos !== -1) {
124
+ types.splice(pos, 1);
125
+ instances.push('Object');
126
+ }
127
+ }
128
+
129
+ if (types.length > 0) {
130
+ if (types.length > 2) {
131
+ const last = types.pop();
132
+ message += `one of type ${types.join(', ')}, or ${last}`;
133
+ } else if (types.length === 2) {
134
+ message += `one of type ${types[0]} or ${types[1]}`;
135
+ } else {
136
+ message += `of type ${types[0]}`;
137
+ }
138
+ if (instances.length > 0 || other.length > 0) message += ' or ';
139
+ }
140
+
141
+ if (instances.length > 0) {
142
+ if (instances.length > 2) {
143
+ const last = instances.pop();
144
+ message += `an instance of ${instances.join(', ')}, or ${last}`;
145
+ } else {
146
+ message += `an instance of ${instances[0]}`;
147
+ if (instances.length === 2) message += ` or ${instances[1]}`;
148
+ }
149
+ if (other.length > 0) message += ' or ';
150
+ }
151
+
152
+ if (other.length > 0) {
153
+ if (other.length > 2) {
154
+ const last = other.pop();
155
+ message += `one of ${other.join(', ')}, or ${last}`;
156
+ } else if (other.length === 2) {
157
+ message += `one of ${other[0]} or ${other[1]}`;
158
+ } else {
159
+ if (other[0].toLowerCase() !== other[0]) message += 'an ';
160
+ message += `${other[0]}`;
161
+ }
162
+ }
163
+
164
+ message += `. Received ${determineSpecificType(actual)}`;
165
+ super(message);
166
+ // Node restores the built-in name and carries the code beside it, so a
167
+ // guest's `err instanceof TypeError` and `err.name === 'TypeError'` hold.
168
+ this.name = 'TypeError';
169
+ }
170
+ }
171
+
172
+ export class ERR_INVALID_ARG_VALUE extends TypeError {
173
+ code = 'ERR_INVALID_ARG_VALUE';
174
+ constructor(name: string, value: unknown, reason = 'is invalid') {
175
+ const type = name.includes('.') ? 'property' : 'argument';
176
+ super(`The ${type} '${name}' ${reason}. Received ${inspectValue(value)}`);
177
+ this.name = 'TypeError';
178
+ }
179
+ }
180
+
181
+ /**
182
+ * lib/internal/errors.js `addNumericSeparator`: Node groups a large integer's
183
+ * digits in an out-of-range message, so `281474976710656` is reported as
184
+ * `281_474_976_710_656` (test-crypto-random.js asserts that form for
185
+ * `crypto.randomInt`'s range). The engine printed the bare digits.
186
+ */
187
+ function addNumericSeparator(value: string): string {
188
+ let tail = '';
189
+ let index = value.length;
190
+ const start = value[0] === '-' ? 1 : 0;
191
+ for (; index >= start + 4; index -= 3) tail = `_${value.slice(index - 3, index)}${tail}`;
192
+ return `${value.slice(0, index)}${tail}`;
193
+ }
194
+
195
+ export class ERR_OUT_OF_RANGE extends RangeError {
196
+ code = 'ERR_OUT_OF_RANGE';
197
+ constructor(name: string, range: string, value: unknown) {
198
+ // Node separates the digits of an integer past 2**32, and of a bigint
199
+ // past the same, and inspects everything else.
200
+ let received: string;
201
+ if (typeof value === 'number' && Number.isInteger(value) && Math.abs(value) > 2 ** 32) {
202
+ received = addNumericSeparator(String(value));
203
+ } else if (typeof value === 'bigint') {
204
+ received = String(value);
205
+ if (value > 2n ** 32n || value < -(2n ** 32n)) received = addNumericSeparator(received);
206
+ received += 'n';
207
+ } else {
208
+ received = inspectValue(value);
209
+ }
210
+ super(`The value of "${name}" is out of range. It must be ${range}. Received ${received}`);
211
+ this.name = 'RangeError';
212
+ }
213
+ }
214
+
215
+ // ---------------------------------------------------------------------------
216
+ // internal/validators — the names path.js and wasi.js take from it.
217
+ // ---------------------------------------------------------------------------
218
+
219
+ export function validateString(value: unknown, name: string): void {
220
+ if (typeof value !== 'string') throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
221
+ }
222
+
223
+ export function validateObject(value: unknown, name: string): void {
224
+ if (value === null || Array.isArray(value) || typeof value !== 'object') {
225
+ throw new ERR_INVALID_ARG_TYPE(name, 'Object', value);
226
+ }
227
+ }
228
+
229
+ export function validateArray(value: unknown, name: string, minLength = 0): void {
230
+ if (!Array.isArray(value)) throw new ERR_INVALID_ARG_TYPE(name, 'Array', value);
231
+ if (value.length < minLength) {
232
+ throw new ERR_INVALID_ARG_VALUE(name, value, `must be longer than ${minLength}`);
233
+ }
234
+ }
235
+
236
+ export function validateBoolean(value: unknown, name: string): void {
237
+ if (typeof value !== 'boolean') throw new ERR_INVALID_ARG_TYPE(name, 'boolean', value);
238
+ }
239
+
240
+ export function validateFunction(value: unknown, name: string): void {
241
+ if (typeof value !== 'function') throw new ERR_INVALID_ARG_TYPE(name, 'Function', value);
242
+ }
243
+
244
+ /** lib/internal/errors.js ERR_UNKNOWN_ENCODING, as `new StringDecoder('x')` raises it. */
245
+ export class ERR_UNKNOWN_ENCODING extends TypeError {
246
+ code = 'ERR_UNKNOWN_ENCODING';
247
+ constructor(encoding: unknown) {
248
+ super(`Unknown encoding: ${String(encoding)}`);
249
+ this.name = 'TypeError';
250
+ }
251
+ }
252
+
253
+ /** lib/internal/errors.js ERR_INVALID_THIS: a prototype method called off an instance. */
254
+ export class ERR_INVALID_THIS extends TypeError {
255
+ code = 'ERR_INVALID_THIS';
256
+ constructor(type: string) {
257
+ super(`Value of "this" must be of type ${type}`);
258
+ this.name = 'TypeError';
259
+ }
260
+ }
261
+
262
+ /** lib/internal/errors.js ERR_STRING_TOO_LONG: past V8's longest string. */
263
+ export class ERR_STRING_TOO_LONG extends RangeError {
264
+ code = 'ERR_STRING_TOO_LONG';
265
+ constructor(max: number) {
266
+ super(`Cannot create a string longer than 0x${max.toString(16)} characters`);
267
+ this.name = 'RangeError';
268
+ }
269
+ }
270
+
271
+ export function validateNumber(value: unknown, name: string): void {
272
+ if (typeof value !== 'number') throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
273
+ }
274
+
275
+ export function validateUndefined(value: unknown, name: string): void {
276
+ if (value !== undefined) throw new ERR_INVALID_ARG_TYPE(name, 'undefined', value);
277
+ }
278
+
279
+ export function validateInt32(value: unknown, name: string, min = -2147483648, max = 2147483647): void {
280
+ if (typeof value !== 'number') throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
281
+ if (!Number.isInteger(value)) throw new ERR_OUT_OF_RANGE(name, 'an integer', value);
282
+ if (value < min || value > max) throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value);
283
+ }
@@ -0,0 +1,47 @@
1
+ Node.js is licensed for use as follows:
2
+
3
+ """
4
+ Copyright Node.js contributors. All rights reserved.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to
8
+ deal in the Software without restriction, including without limitation the
9
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ sell copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
+ IN THE SOFTWARE.
23
+ """
24
+
25
+ This license applies to parts of Node.js originating from the
26
+ https://github.com/joyent/node repository:
27
+
28
+ """
29
+ Copyright Joyent, Inc. and other Node contributors. All rights reserved.
30
+ Permission is hereby granted, free of charge, to any person obtaining a copy
31
+ of this software and associated documentation files (the "Software"), to
32
+ deal in the Software without restriction, including without limitation the
33
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
34
+ sell copies of the Software, and to permit persons to whom the Software is
35
+ furnished to do so, subject to the following conditions:
36
+
37
+ The above copyright notice and this permission notice shall be included in
38
+ all copies or substantial portions of the Software.
39
+
40
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
45
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
46
+ IN THE SOFTWARE.
47
+ """