@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,1135 @@
1
+ 'use strict';
2
+
3
+ const {
4
+ ArrayIsArray,
5
+ ArrayPrototypePush,
6
+ ArrayPrototypeReduce,
7
+ ArrayPrototypeSlice,
8
+ FunctionPrototype,
9
+ FunctionPrototypeCall,
10
+ ObjectDefineProperty,
11
+ ObjectSetPrototypeOf,
12
+ ReflectApply,
13
+ StringPrototypeSlice,
14
+ Symbol,
15
+ Uint8Array,
16
+ } = primordials;
17
+
18
+ const {
19
+ ErrnoException,
20
+ codes: {
21
+ ERR_INVALID_ARG_TYPE,
22
+ ERR_INVALID_ARG_VALUE,
23
+ ERR_INVALID_HANDLE_TYPE,
24
+ ERR_INVALID_SYNC_FORK_INPUT,
25
+ ERR_IPC_CHANNEL_CLOSED,
26
+ ERR_IPC_DISCONNECTED,
27
+ ERR_IPC_ONE_PIPE,
28
+ ERR_IPC_SYNC_FORK,
29
+ ERR_MISSING_ARGS,
30
+ },
31
+ } = require('internal/errors');
32
+ const {
33
+ validateArray,
34
+ validateObject,
35
+ validateOneOf,
36
+ validateString,
37
+ } = require('internal/validators');
38
+ const EventEmitter = require('events');
39
+ const net = require('net');
40
+ const dgram = require('dgram');
41
+ const inspect = require('internal/util/inspect').inspect;
42
+ const assert = require('internal/assert');
43
+
44
+ const { Process } = internalBinding('process_wrap');
45
+ const {
46
+ WriteWrap,
47
+ kReadBytesOrError,
48
+ kArrayBufferOffset,
49
+ kLastWriteWasAsync,
50
+ streamBaseState,
51
+ } = internalBinding('stream_wrap');
52
+ const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap');
53
+ const { TCP } = internalBinding('tcp_wrap');
54
+ const { TTY } = internalBinding('tty_wrap');
55
+ const { UDP } = internalBinding('udp_wrap');
56
+ const SocketList = require('internal/socket_list');
57
+ const { owner_symbol } = require('internal/async_hooks').symbols;
58
+ const { convertToValidSignal, deprecate, SymbolDispose } = require('internal/util');
59
+ const { isArrayBufferView } = require('internal/util/types');
60
+ const spawn_sync = internalBinding('spawn_sync');
61
+ const { kStateSymbol } = require('internal/dgram');
62
+ const dc = require('diagnostics_channel');
63
+ const childProcessChannel = dc.channel('child_process');
64
+
65
+ const {
66
+ UV_EACCES,
67
+ UV_EAGAIN,
68
+ UV_EINVAL,
69
+ UV_EMFILE,
70
+ UV_ENFILE,
71
+ UV_ENOENT,
72
+ UV_ENOSYS,
73
+ UV_ESRCH,
74
+ } = internalBinding('uv');
75
+
76
+ const { SocketListSend, SocketListReceive } = SocketList;
77
+
78
+ // Lazy loaded for startup performance and to allow monkey patching of
79
+ // internalBinding('http_parser').HTTPParser.
80
+ let freeParser;
81
+ let HTTPParser;
82
+
83
+ const MAX_HANDLE_RETRANSMISSIONS = 3;
84
+ const kChannelHandle = Symbol('kChannelHandle');
85
+ const kIsUsedAsStdio = Symbol('kIsUsedAsStdio');
86
+ const kPendingMessages = Symbol('kPendingMessages');
87
+
88
+ // This object contain function to convert TCP objects to native handle objects
89
+ // and back again.
90
+ const handleConversion = {
91
+ 'net.Native': {
92
+ simultaneousAccepts: true,
93
+
94
+ send(message, handle, options) {
95
+ return handle;
96
+ },
97
+
98
+ got(message, handle, emit) {
99
+ emit(handle);
100
+ },
101
+ },
102
+
103
+ 'net.Server': {
104
+ simultaneousAccepts: true,
105
+
106
+ send(message, server, options) {
107
+ return server._handle;
108
+ },
109
+
110
+ got(message, handle, emit) {
111
+ const server = new net.Server();
112
+ server.listen(handle, () => {
113
+ emit(server);
114
+ });
115
+ },
116
+ },
117
+
118
+ 'net.Socket': {
119
+ send(message, socket, options) {
120
+ if (!socket._handle)
121
+ return;
122
+
123
+ // If the socket was created by net.Server
124
+ if (socket.server) {
125
+ // The worker should keep track of the socket
126
+ message.key = socket.server._connectionKey;
127
+
128
+ const firstTime = !this[kChannelHandle].sockets.send[message.key];
129
+ const socketList = getSocketList('send', this, message.key);
130
+
131
+ // The server should no longer expose a .connection property
132
+ // and when asked to close it should query the socket status from
133
+ // the workers
134
+ if (firstTime) socket.server._setupWorker(socketList);
135
+
136
+ // Act like socket is detached
137
+ if (!options.keepOpen)
138
+ socket.server._connections--;
139
+ }
140
+
141
+ const handle = socket._handle;
142
+
143
+ // Remove handle from socket object, it will be closed when the socket
144
+ // will be sent
145
+ if (!options.keepOpen) {
146
+ handle.onread = nop;
147
+ socket._handle = null;
148
+ socket.setTimeout(0);
149
+
150
+ if (freeParser === undefined)
151
+ freeParser = require('_http_common').freeParser;
152
+ if (HTTPParser === undefined)
153
+ HTTPParser = require('_http_common').HTTPParser;
154
+
155
+ // In case of an HTTP connection socket, release the associated
156
+ // resources
157
+ if (socket.parser && socket.parser instanceof HTTPParser) {
158
+ freeParser(socket.parser, null, socket);
159
+ if (socket._httpMessage)
160
+ socket._httpMessage.detachSocket(socket);
161
+ }
162
+ }
163
+
164
+ return handle;
165
+ },
166
+
167
+ postSend(message, handle, options, callback, target) {
168
+ // Store the handle after successfully sending it, so it can be closed
169
+ // when the NODE_HANDLE_ACK is received. If the handle could not be sent,
170
+ // just close it.
171
+ if (handle && !options.keepOpen) {
172
+ if (target) {
173
+ // There can only be one _pendingMessage as passing handles are
174
+ // processed one at a time: handles are stored in _handleQueue while
175
+ // waiting for the NODE_HANDLE_ACK of the current passing handle.
176
+ assert(!target._pendingMessage);
177
+ target._pendingMessage =
178
+ { callback, message, handle, options, retransmissions: 0 };
179
+ } else {
180
+ handle.close();
181
+ }
182
+ }
183
+ },
184
+
185
+ got(message, handle, emit) {
186
+ const socket = new net.Socket({
187
+ handle: handle,
188
+ readable: true,
189
+ writable: true,
190
+ });
191
+
192
+ // If the socket was created by net.Server we will track the socket
193
+ if (message.key) {
194
+
195
+ // Add socket to connections list
196
+ const socketList = getSocketList('got', this, message.key);
197
+ socketList.add({
198
+ socket: socket,
199
+ });
200
+ }
201
+
202
+ emit(socket);
203
+ },
204
+ },
205
+
206
+ 'dgram.Native': {
207
+ simultaneousAccepts: false,
208
+
209
+ send(message, handle, options) {
210
+ return handle;
211
+ },
212
+
213
+ got(message, handle, emit) {
214
+ emit(handle);
215
+ },
216
+ },
217
+
218
+ 'dgram.Socket': {
219
+ simultaneousAccepts: false,
220
+
221
+ send(message, socket, options) {
222
+ message.dgramType = socket.type;
223
+
224
+ return socket[kStateSymbol].handle;
225
+ },
226
+
227
+ got(message, handle, emit) {
228
+ const socket = new dgram.Socket(message.dgramType);
229
+
230
+ socket.bind(handle, () => {
231
+ emit(socket);
232
+ });
233
+ },
234
+ },
235
+ };
236
+
237
+ function stdioStringToArray(stdio, channel) {
238
+ const options = [];
239
+
240
+ switch (stdio) {
241
+ case 'ignore':
242
+ case 'overlapped':
243
+ case 'pipe': ArrayPrototypePush(options, stdio, stdio, stdio); break;
244
+ case 'inherit': ArrayPrototypePush(options, 0, 1, 2); break;
245
+ default:
246
+ throw new ERR_INVALID_ARG_VALUE('stdio', stdio);
247
+ }
248
+
249
+ if (channel) ArrayPrototypePush(options, channel);
250
+
251
+ return options;
252
+ }
253
+
254
+ function ChildProcess() {
255
+ FunctionPrototypeCall(EventEmitter, this);
256
+
257
+ this._closesNeeded = 1;
258
+ this._closesGot = 0;
259
+ this.connected = false;
260
+
261
+ this.signalCode = null;
262
+ this.exitCode = null;
263
+ this.killed = false;
264
+ this.spawnfile = null;
265
+
266
+ this._handle = new Process();
267
+ this._handle[owner_symbol] = this;
268
+
269
+ this._handle.onexit = (exitCode, signalCode) => {
270
+ if (signalCode) {
271
+ this.signalCode = signalCode;
272
+ } else {
273
+ this.exitCode = exitCode;
274
+ }
275
+
276
+ if (this.stdin) {
277
+ this.stdin.destroy();
278
+ }
279
+
280
+ this._handle.close();
281
+ this._handle = null;
282
+
283
+ if (exitCode < 0) {
284
+ const syscall = this.spawnfile ? 'spawn ' + this.spawnfile : 'spawn';
285
+ const err = new ErrnoException(exitCode, syscall);
286
+
287
+ if (this.spawnfile)
288
+ err.path = this.spawnfile;
289
+
290
+ err.spawnargs = ArrayPrototypeSlice(this.spawnargs, 1);
291
+ this.emit('error', err);
292
+ } else {
293
+ this.emit('exit', this.exitCode, this.signalCode);
294
+ }
295
+
296
+ // If any of the stdio streams have not been touched,
297
+ // then pull all the data through so that it can get the
298
+ // eof and emit a 'close' event.
299
+ // Do it on nextTick so that the user has one last chance
300
+ // to consume the output, if for example they only want to
301
+ // start reading the data once the process exits.
302
+ process.nextTick(flushStdio, this);
303
+
304
+ maybeClose(this);
305
+ };
306
+ if (childProcessChannel.hasSubscribers) {
307
+ childProcessChannel.publish({
308
+ process: this,
309
+ });
310
+ }
311
+ }
312
+ ObjectSetPrototypeOf(ChildProcess.prototype, EventEmitter.prototype);
313
+ ObjectSetPrototypeOf(ChildProcess, EventEmitter);
314
+
315
+
316
+ function flushStdio(subprocess) {
317
+ const stdio = subprocess.stdio;
318
+
319
+ if (stdio == null) return;
320
+
321
+ for (let i = 0; i < stdio.length; i++) {
322
+ const stream = stdio[i];
323
+ // TODO(addaleax): This doesn't necessarily account for all the ways in
324
+ // which data can be read from a stream, e.g. being consumed on the
325
+ // native layer directly as a StreamBase.
326
+ if (!stream || !stream.readable || stream[kIsUsedAsStdio]) {
327
+ continue;
328
+ }
329
+ stream.resume();
330
+ }
331
+ }
332
+
333
+
334
+ function createSocket(pipe, readable) {
335
+ return net.Socket({ handle: pipe, readable });
336
+ }
337
+
338
+
339
+ function getHandleWrapType(stream) {
340
+ if (stream instanceof Pipe) return 'pipe';
341
+ if (stream instanceof TTY) return 'tty';
342
+ if (stream instanceof TCP) return 'tcp';
343
+ if (stream instanceof UDP) return 'udp';
344
+
345
+ return false;
346
+ }
347
+
348
+ function closePendingHandle(target) {
349
+ target._pendingMessage.handle.close();
350
+ target._pendingMessage = null;
351
+ }
352
+
353
+
354
+ ChildProcess.prototype.spawn = function spawn(options) {
355
+ let i = 0;
356
+
357
+ validateObject(options, 'options');
358
+
359
+ // If no `stdio` option was given - use default
360
+ let stdio = options.stdio || 'pipe';
361
+
362
+ stdio = getValidStdio(stdio, false);
363
+
364
+ const ipc = stdio.ipc;
365
+ const ipcFd = stdio.ipcFd;
366
+ stdio = options.stdio = stdio.stdio;
367
+
368
+
369
+ validateOneOf(options.serialization, 'options.serialization',
370
+ [undefined, 'json', 'advanced']);
371
+ const serialization = options.serialization || 'json';
372
+
373
+ if (ipc !== undefined) {
374
+ // Let child process know about opened IPC channel
375
+ if (options.envPairs === undefined)
376
+ options.envPairs = [];
377
+ else
378
+ validateArray(options.envPairs, 'options.envPairs');
379
+
380
+ ArrayPrototypePush(options.envPairs, `NODE_CHANNEL_FD=${ipcFd}`);
381
+ ArrayPrototypePush(options.envPairs,
382
+ `NODE_CHANNEL_SERIALIZATION_MODE=${serialization}`);
383
+ }
384
+
385
+ validateString(options.file, 'options.file');
386
+ this.spawnfile = options.file;
387
+
388
+ if (options.args === undefined) {
389
+ this.spawnargs = [];
390
+ } else {
391
+ validateArray(options.args, 'options.args');
392
+ this.spawnargs = options.args;
393
+ }
394
+
395
+ const err = this._handle.spawn(options);
396
+
397
+ // Run-time errors should emit an error, not throw an exception.
398
+ if (err === UV_EACCES ||
399
+ err === UV_EAGAIN ||
400
+ err === UV_EMFILE ||
401
+ err === UV_ENFILE ||
402
+ err === UV_ENOENT) {
403
+ process.nextTick(onErrorNT, this, err);
404
+
405
+ // There is no point in continuing when we've hit EMFILE or ENFILE
406
+ // because we won't be able to set up the stdio file descriptors.
407
+ if (err === UV_EMFILE || err === UV_ENFILE)
408
+ return err;
409
+ } else if (err) {
410
+ // Close all opened fds on error
411
+ for (i = 0; i < stdio.length; i++) {
412
+ const stream = stdio[i];
413
+ if (stream.type === 'pipe') {
414
+ stream.handle.close();
415
+ }
416
+ }
417
+
418
+ this._handle.close();
419
+ this._handle = null;
420
+ throw new ErrnoException(err, 'spawn');
421
+ } else {
422
+ process.nextTick(onSpawnNT, this);
423
+ }
424
+
425
+ this.pid = this._handle.pid;
426
+
427
+ for (i = 0; i < stdio.length; i++) {
428
+ const stream = stdio[i];
429
+ if (stream.type === 'ignore') continue;
430
+
431
+ if (stream.ipc) {
432
+ this._closesNeeded++;
433
+ continue;
434
+ }
435
+
436
+ // The stream is already cloned and piped, thus stop its readable side,
437
+ // otherwise we might attempt to read from the stream when at the same time
438
+ // the child process does.
439
+ if (stream.type === 'wrap') {
440
+ stream.handle.reading = false;
441
+ stream.handle.readStop();
442
+ stream._stdio.pause();
443
+ stream._stdio.readableFlowing = false;
444
+ stream._stdio._readableState.reading = false;
445
+ stream._stdio[kIsUsedAsStdio] = true;
446
+ continue;
447
+ }
448
+
449
+ if (stream.handle) {
450
+ stream.socket = createSocket(this.pid !== 0 ?
451
+ stream.handle : null, i > 0);
452
+
453
+ if (i > 0 && this.pid !== 0) {
454
+ this._closesNeeded++;
455
+ stream.socket.on('close', () => {
456
+ maybeClose(this);
457
+ });
458
+ }
459
+ }
460
+ }
461
+
462
+ this.stdin = stdio.length >= 1 && stdio[0].socket !== undefined ?
463
+ stdio[0].socket : null;
464
+ this.stdout = stdio.length >= 2 && stdio[1].socket !== undefined ?
465
+ stdio[1].socket : null;
466
+ this.stderr = stdio.length >= 3 && stdio[2].socket !== undefined ?
467
+ stdio[2].socket : null;
468
+
469
+ this.stdio = [];
470
+
471
+ for (i = 0; i < stdio.length; i++)
472
+ ArrayPrototypePush(this.stdio,
473
+ stdio[i].socket === undefined ? null : stdio[i].socket);
474
+
475
+ // Add .send() method and start listening for IPC data
476
+ if (ipc !== undefined) setupChannel(this, ipc, serialization);
477
+
478
+ return err;
479
+ };
480
+
481
+
482
+ function onErrorNT(self, err) {
483
+ self._handle.onexit(err);
484
+ }
485
+
486
+
487
+ function onSpawnNT(self) {
488
+ self.emit('spawn');
489
+ }
490
+
491
+
492
+ ChildProcess.prototype.kill = function kill(sig) {
493
+
494
+ const signal = sig === 0 ? sig :
495
+ convertToValidSignal(sig === undefined ? 'SIGTERM' : sig);
496
+
497
+ if (this._handle) {
498
+ const err = this._handle.kill(signal);
499
+ if (err === 0) {
500
+ /* Success. */
501
+ this.killed = true;
502
+ return true;
503
+ }
504
+ if (err === UV_ESRCH) {
505
+ /* Already dead. */
506
+ } else if (err === UV_EINVAL || err === UV_ENOSYS) {
507
+ /* The underlying platform doesn't support this signal. */
508
+ throw new ErrnoException(err, 'kill');
509
+ } else {
510
+ /* Other error, almost certainly EPERM. */
511
+ this.emit('error', new ErrnoException(err, 'kill'));
512
+ }
513
+ }
514
+
515
+ /* Kill didn't succeed. */
516
+ return false;
517
+ };
518
+
519
+ ChildProcess.prototype[SymbolDispose] = function() {
520
+ if (!this.killed) {
521
+ this.kill();
522
+ }
523
+ };
524
+
525
+
526
+ ChildProcess.prototype.ref = function ref() {
527
+ if (this._handle) this._handle.ref();
528
+ };
529
+
530
+
531
+ ChildProcess.prototype.unref = function unref() {
532
+ if (this._handle) this._handle.unref();
533
+ };
534
+
535
+ class Control extends EventEmitter {
536
+ #channel = null;
537
+ #refs = 0;
538
+ #refExplicitlySet = false;
539
+
540
+ constructor(channel) {
541
+ super();
542
+ this.#channel = channel;
543
+ this[kPendingMessages] = [];
544
+ }
545
+
546
+ // The methods keeping track of the counter are being used to track the
547
+ // listener count on the child process object as well as when writes are
548
+ // in progress. Once the user has explicitly requested a certain state, these
549
+ // methods become no-ops in order to not interfere with the user's intentions.
550
+ refCounted() {
551
+ if (++this.#refs === 1 && !this.#refExplicitlySet) {
552
+ this.#channel.ref();
553
+ }
554
+ }
555
+
556
+ unrefCounted() {
557
+ if (--this.#refs === 0 && !this.#refExplicitlySet) {
558
+ this.#channel.unref();
559
+ this.emit('unref');
560
+ }
561
+ }
562
+
563
+ ref() {
564
+ this.#refExplicitlySet = true;
565
+ this.#channel.ref();
566
+ }
567
+
568
+ unref() {
569
+ this.#refExplicitlySet = true;
570
+ this.#channel.unref();
571
+ }
572
+
573
+ get fd() {
574
+ return this.#channel ? this.#channel.fd : undefined;
575
+ }
576
+ }
577
+
578
+ const channelDeprecationMsg = '_channel is deprecated. ' +
579
+ 'Use ChildProcess.channel instead.';
580
+
581
+ let serialization;
582
+ function setupChannel(target, channel, serializationMode) {
583
+ const control = new Control(channel);
584
+ target.channel = control;
585
+ target[kChannelHandle] = channel;
586
+
587
+ ObjectDefineProperty(target, '_channel', {
588
+ __proto__: null,
589
+ get: deprecate(() => {
590
+ return target.channel;
591
+ }, channelDeprecationMsg, 'DEP0129'),
592
+ set: deprecate((val) => {
593
+ target.channel = val;
594
+ }, channelDeprecationMsg, 'DEP0129'),
595
+ configurable: true,
596
+ enumerable: false,
597
+ });
598
+
599
+ target._handleQueue = null;
600
+ target._pendingMessage = null;
601
+
602
+ if (serialization === undefined)
603
+ serialization = require('internal/child_process/serialization');
604
+ const {
605
+ initMessageChannel,
606
+ parseChannelMessages,
607
+ writeChannelMessage,
608
+ } = serialization[serializationMode];
609
+
610
+ let pendingHandle = null;
611
+ initMessageChannel(channel);
612
+ channel.pendingHandle = null;
613
+ channel.onread = function(arrayBuffer) {
614
+ const recvHandle = channel.pendingHandle;
615
+ channel.pendingHandle = null;
616
+ if (arrayBuffer) {
617
+ const nread = streamBaseState[kReadBytesOrError];
618
+ const offset = streamBaseState[kArrayBufferOffset];
619
+ const pool = new Uint8Array(arrayBuffer, offset, nread);
620
+ if (recvHandle)
621
+ pendingHandle = recvHandle;
622
+
623
+ for (const message of parseChannelMessages(channel, pool)) {
624
+ // There will be at most one NODE_HANDLE message in every chunk we
625
+ // read because SCM_RIGHTS messages don't get coalesced. Make sure
626
+ // that we deliver the handle with the right message however.
627
+ if (isInternal(message)) {
628
+ if (message.cmd === 'NODE_HANDLE') {
629
+ handleMessage(message, pendingHandle, true);
630
+ pendingHandle = null;
631
+ } else {
632
+ handleMessage(message, undefined, true);
633
+ }
634
+ } else {
635
+ handleMessage(message, undefined, false);
636
+ }
637
+ }
638
+ } else {
639
+ this.buffering = false;
640
+ target.disconnect();
641
+ channel.onread = nop;
642
+ channel.close();
643
+ target.channel = null;
644
+ maybeClose(target);
645
+ }
646
+ };
647
+
648
+ // Object where socket lists will live
649
+ channel.sockets = { got: {}, send: {} };
650
+
651
+ // Handlers will go through this
652
+ target.on('internalMessage', function(message, handle) {
653
+ // Once acknowledged - continue sending handles.
654
+ if (message.cmd === 'NODE_HANDLE_ACK' ||
655
+ message.cmd === 'NODE_HANDLE_NACK') {
656
+
657
+ if (target._pendingMessage) {
658
+ if (message.cmd === 'NODE_HANDLE_ACK') {
659
+ closePendingHandle(target);
660
+ } else if (target._pendingMessage.retransmissions++ ===
661
+ MAX_HANDLE_RETRANSMISSIONS) {
662
+ closePendingHandle(target);
663
+ process.emitWarning('Handle did not reach the receiving process ' +
664
+ 'correctly', 'SentHandleNotReceivedWarning');
665
+ }
666
+ }
667
+
668
+ assert(ArrayIsArray(target._handleQueue));
669
+ const queue = target._handleQueue;
670
+ target._handleQueue = null;
671
+
672
+ if (target._pendingMessage) {
673
+ target._send(target._pendingMessage.message,
674
+ target._pendingMessage.handle,
675
+ target._pendingMessage.options,
676
+ target._pendingMessage.callback);
677
+ }
678
+
679
+ for (let i = 0; i < queue.length; i++) {
680
+ const args = queue[i];
681
+ target._send(args.message, args.handle, args.options, args.callback);
682
+ }
683
+
684
+ // Process a pending disconnect (if any).
685
+ if (!target.connected && target.channel && !target._handleQueue)
686
+ target._disconnect();
687
+
688
+ return;
689
+ }
690
+
691
+ if (message.cmd !== 'NODE_HANDLE') return;
692
+
693
+ // It is possible that the handle is not received because of some error on
694
+ // ancillary data reception such as MSG_CTRUNC. In this case, report the
695
+ // sender about it by sending a NODE_HANDLE_NACK message.
696
+ if (!handle)
697
+ return target._send({ cmd: 'NODE_HANDLE_NACK' }, null, true);
698
+
699
+ // Acknowledge handle receival. Don't emit error events (for example if
700
+ // the other side has disconnected) because this call to send() is not
701
+ // initiated by the user and it shouldn't be fatal to be unable to ACK
702
+ // a message.
703
+ target._send({ cmd: 'NODE_HANDLE_ACK' }, null, true);
704
+
705
+ const obj = handleConversion[message.type];
706
+
707
+ // Update simultaneous accepts on Windows
708
+ if (process.platform === 'win32') {
709
+ handle.setSimultaneousAccepts(false);
710
+ }
711
+
712
+ // Convert handle object
713
+ obj.got.call(this, message, handle, (handle) => {
714
+ handleMessage(message.msg, handle, isInternal(message.msg));
715
+ });
716
+ });
717
+
718
+ target.on('newListener', function() {
719
+
720
+ process.nextTick(() => {
721
+ if (!target.channel || !target.listenerCount('message'))
722
+ return;
723
+
724
+ const messages = target.channel[kPendingMessages];
725
+ const { length } = messages;
726
+ if (!length) return;
727
+
728
+ for (let i = 0; i < length; i++) {
729
+ ReflectApply(target.emit, target, messages[i]);
730
+ }
731
+
732
+ target.channel[kPendingMessages] = [];
733
+ });
734
+ });
735
+
736
+ target.send = function(message, handle, options, callback) {
737
+ if (typeof handle === 'function') {
738
+ callback = handle;
739
+ handle = undefined;
740
+ options = undefined;
741
+ } else if (typeof options === 'function') {
742
+ callback = options;
743
+ options = undefined;
744
+ } else if (options !== undefined) {
745
+ validateObject(options, 'options');
746
+ }
747
+
748
+ options = { swallowErrors: false, ...options };
749
+
750
+ if (this.connected) {
751
+ return this._send(message, handle, options, callback);
752
+ }
753
+ const ex = new ERR_IPC_CHANNEL_CLOSED();
754
+ if (typeof callback === 'function') {
755
+ process.nextTick(callback, ex);
756
+ } else {
757
+ process.nextTick(() => this.emit('error', ex));
758
+ }
759
+ return false;
760
+ };
761
+
762
+ target._send = function(message, handle, options, callback) {
763
+ assert(this.connected || this.channel);
764
+
765
+ if (message === undefined)
766
+ throw new ERR_MISSING_ARGS('message');
767
+
768
+ // Non-serializable messages should not reach the remote
769
+ // end point; as any failure in the stringification there
770
+ // will result in error message that is weakly consumable.
771
+ // So perform a final check on message prior to sending.
772
+ if (typeof message !== 'string' &&
773
+ typeof message !== 'object' &&
774
+ typeof message !== 'number' &&
775
+ typeof message !== 'boolean') {
776
+ throw new ERR_INVALID_ARG_TYPE(
777
+ 'message', ['string', 'object', 'number', 'boolean'], message);
778
+ }
779
+
780
+ // Support legacy function signature
781
+ if (typeof options === 'boolean') {
782
+ options = { swallowErrors: options };
783
+ }
784
+
785
+ let obj;
786
+
787
+ // Package messages with a handle object
788
+ if (handle) {
789
+ // This message will be handled by an internalMessage event handler
790
+ message = {
791
+ cmd: 'NODE_HANDLE',
792
+ type: null,
793
+ msg: message,
794
+ };
795
+
796
+ if (handle instanceof net.Socket) {
797
+ message.type = 'net.Socket';
798
+ } else if (handle instanceof net.Server) {
799
+ message.type = 'net.Server';
800
+ } else if (handle instanceof TCP || handle instanceof Pipe) {
801
+ message.type = 'net.Native';
802
+ } else if (handle instanceof dgram.Socket) {
803
+ message.type = 'dgram.Socket';
804
+ } else if (handle instanceof UDP) {
805
+ message.type = 'dgram.Native';
806
+ } else {
807
+ throw new ERR_INVALID_HANDLE_TYPE();
808
+ }
809
+
810
+ // Queue-up message and handle if we haven't received ACK yet.
811
+ if (this._handleQueue) {
812
+ ArrayPrototypePush(this._handleQueue, {
813
+ callback: callback,
814
+ handle: handle,
815
+ options: options,
816
+ message: message.msg,
817
+ });
818
+ return this._handleQueue.length === 1;
819
+ }
820
+
821
+ obj = handleConversion[message.type];
822
+
823
+ // convert TCP object to native handle object
824
+ handle = ReflectApply(handleConversion[message.type].send,
825
+ target, [message, handle, options]);
826
+
827
+ // If handle was sent twice, or it is impossible to get native handle
828
+ // out of it - just send a text without the handle.
829
+ if (!handle)
830
+ message = message.msg;
831
+
832
+ // Update simultaneous accepts on Windows
833
+ if (obj.simultaneousAccepts && process.platform === 'win32') {
834
+ handle.setSimultaneousAccepts(true);
835
+ }
836
+ } else if (this._handleQueue &&
837
+ !(message && (message.cmd === 'NODE_HANDLE_ACK' ||
838
+ message.cmd === 'NODE_HANDLE_NACK'))) {
839
+ // Queue request anyway to avoid out-of-order messages.
840
+ ArrayPrototypePush(this._handleQueue, {
841
+ callback: callback,
842
+ handle: null,
843
+ options: options,
844
+ message: message,
845
+ });
846
+ return this._handleQueue.length === 1;
847
+ }
848
+
849
+ const req = new WriteWrap();
850
+
851
+ const err = writeChannelMessage(channel, req, message, handle);
852
+ const wasAsyncWrite = streamBaseState[kLastWriteWasAsync];
853
+
854
+ if (err === 0) {
855
+ if (handle) {
856
+ this._handleQueue ||= [];
857
+ if (obj?.postSend)
858
+ obj.postSend(message, handle, options, callback, target);
859
+ }
860
+
861
+ if (wasAsyncWrite) {
862
+ req.oncomplete = () => {
863
+ control.unrefCounted();
864
+ if (typeof callback === 'function')
865
+ callback(null);
866
+ };
867
+ control.refCounted();
868
+ } else if (typeof callback === 'function') {
869
+ process.nextTick(callback, null);
870
+ }
871
+ } else {
872
+ // Cleanup handle on error
873
+ if (obj?.postSend)
874
+ obj.postSend(message, handle, options, callback);
875
+
876
+ if (!options.swallowErrors) {
877
+ const ex = new ErrnoException(err, 'write');
878
+ if (typeof callback === 'function') {
879
+ process.nextTick(callback, ex);
880
+ } else {
881
+ process.nextTick(() => this.emit('error', ex));
882
+ }
883
+ }
884
+ }
885
+
886
+ /* If the primary is > 2 read() calls behind, please stop sending. */
887
+ return channel.writeQueueSize < (65536 * 2);
888
+ };
889
+
890
+ // Connected will be set to false immediately when a disconnect() is
891
+ // requested, even though the channel might still be alive internally to
892
+ // process queued messages. The three states are distinguished as follows:
893
+ // - disconnect() never requested: channel is not null and connected
894
+ // is true
895
+ // - disconnect() requested, messages in the queue: channel is not null
896
+ // and connected is false
897
+ // - disconnect() requested, channel actually disconnected: channel is
898
+ // null and connected is false
899
+ target.connected = true;
900
+
901
+ target.disconnect = function() {
902
+ if (!this.connected) {
903
+ this.emit('error', new ERR_IPC_DISCONNECTED());
904
+ return;
905
+ }
906
+
907
+ // Do not allow any new messages to be written.
908
+ this.connected = false;
909
+
910
+ // If there are no queued messages, disconnect immediately. Otherwise,
911
+ // postpone the disconnect so that it happens internally after the
912
+ // queue is flushed.
913
+ if (!this._handleQueue)
914
+ this._disconnect();
915
+ };
916
+
917
+ target._disconnect = function() {
918
+ assert(this.channel);
919
+
920
+ // This marks the fact that the channel is actually disconnected.
921
+ this.channel = null;
922
+ this[kChannelHandle] = null;
923
+
924
+ if (this._pendingMessage)
925
+ closePendingHandle(this);
926
+
927
+ let fired = false;
928
+ function finish() {
929
+ if (fired) return;
930
+ fired = true;
931
+
932
+ channel.close();
933
+ target.emit('disconnect');
934
+ }
935
+
936
+ // If a message is being read, then wait for it to complete.
937
+ if (channel.buffering) {
938
+ this.once('message', finish);
939
+ this.once('internalMessage', finish);
940
+
941
+ return;
942
+ }
943
+
944
+ process.nextTick(finish);
945
+ };
946
+
947
+ function emit(event, message, handle) {
948
+ if ('internalMessage' === event || target.listenerCount('message')) {
949
+ target.emit(event, message, handle);
950
+ return;
951
+ }
952
+
953
+ ArrayPrototypePush(
954
+ target.channel[kPendingMessages],
955
+ [event, message, handle],
956
+ );
957
+ }
958
+
959
+ function handleMessage(message, handle, internal) {
960
+ if (!target.channel)
961
+ return;
962
+
963
+ const eventName = (internal ? 'internalMessage' : 'message');
964
+
965
+ process.nextTick(emit, eventName, message, handle);
966
+ }
967
+
968
+ channel.readStart();
969
+ return control;
970
+ }
971
+
972
+ const INTERNAL_PREFIX = 'NODE_';
973
+ function isInternal(message) {
974
+ return (message !== null &&
975
+ typeof message === 'object' &&
976
+ typeof message.cmd === 'string' &&
977
+ message.cmd.length > INTERNAL_PREFIX.length &&
978
+ StringPrototypeSlice(message.cmd, 0, INTERNAL_PREFIX.length) ===
979
+ INTERNAL_PREFIX);
980
+ }
981
+
982
+ const nop = FunctionPrototype;
983
+
984
+ function getValidStdio(stdio, sync) {
985
+ let ipc;
986
+ let ipcFd;
987
+
988
+ // Replace shortcut with an array
989
+ if (typeof stdio === 'string') {
990
+ stdio = stdioStringToArray(stdio);
991
+ } else if (!ArrayIsArray(stdio)) {
992
+ throw new ERR_INVALID_ARG_VALUE('stdio', stdio);
993
+ }
994
+
995
+ // At least 3 stdio will be created
996
+ // Don't concat() a new Array() because it would be sparse, and
997
+ // stdio.reduce() would skip the sparse elements of stdio.
998
+ // See https://stackoverflow.com/a/5501711/3561
999
+ while (stdio.length < 3) ArrayPrototypePush(stdio, undefined);
1000
+
1001
+ // Translate stdio into C++-readable form
1002
+ // (i.e. PipeWraps or fds)
1003
+ stdio = ArrayPrototypeReduce(stdio, (acc, stdio, i) => {
1004
+ function cleanup() {
1005
+ for (let i = 0; i < acc.length; i++) {
1006
+ if ((acc[i].type === 'pipe' || acc[i].type === 'ipc') && acc[i].handle)
1007
+ acc[i].handle.close();
1008
+ }
1009
+ }
1010
+
1011
+ // Defaults
1012
+ stdio ??= i < 3 ? 'pipe' : 'ignore';
1013
+
1014
+ if (stdio === 'ignore') {
1015
+ ArrayPrototypePush(acc, { type: 'ignore' });
1016
+ } else if (stdio === 'pipe' || stdio === 'overlapped' ||
1017
+ (typeof stdio === 'number' && stdio < 0)) {
1018
+ const a = {
1019
+ type: stdio === 'overlapped' ? 'overlapped' : 'pipe',
1020
+ readable: i === 0,
1021
+ writable: i !== 0,
1022
+ };
1023
+
1024
+ if (!sync)
1025
+ a.handle = new Pipe(PipeConstants.SOCKET);
1026
+
1027
+ ArrayPrototypePush(acc, a);
1028
+ } else if (stdio === 'ipc') {
1029
+ if (sync || ipc !== undefined) {
1030
+ // Cleanup previously created pipes
1031
+ cleanup();
1032
+ if (!sync)
1033
+ throw new ERR_IPC_ONE_PIPE();
1034
+ else
1035
+ throw new ERR_IPC_SYNC_FORK();
1036
+ }
1037
+
1038
+ ipc = new Pipe(PipeConstants.IPC);
1039
+ ipcFd = i;
1040
+
1041
+ ArrayPrototypePush(acc, {
1042
+ type: 'pipe',
1043
+ handle: ipc,
1044
+ ipc: true,
1045
+ });
1046
+ } else if (stdio === 'inherit') {
1047
+ ArrayPrototypePush(acc, {
1048
+ type: 'inherit',
1049
+ fd: i,
1050
+ });
1051
+ } else if (typeof stdio === 'number' || typeof stdio.fd === 'number') {
1052
+ ArrayPrototypePush(acc, {
1053
+ type: 'fd',
1054
+ fd: typeof stdio === 'number' ? stdio : stdio.fd,
1055
+ });
1056
+ } else if (getHandleWrapType(stdio) || getHandleWrapType(stdio.handle) ||
1057
+ getHandleWrapType(stdio._handle)) {
1058
+ const handle = getHandleWrapType(stdio) ?
1059
+ stdio :
1060
+ getHandleWrapType(stdio.handle) ? stdio.handle : stdio._handle;
1061
+
1062
+ ArrayPrototypePush(acc, {
1063
+ type: 'wrap',
1064
+ wrapType: getHandleWrapType(handle),
1065
+ handle: handle,
1066
+ _stdio: stdio,
1067
+ });
1068
+ } else if (isArrayBufferView(stdio) || typeof stdio === 'string') {
1069
+ if (!sync) {
1070
+ cleanup();
1071
+ throw new ERR_INVALID_SYNC_FORK_INPUT(inspect(stdio));
1072
+ }
1073
+ } else {
1074
+ // Cleanup
1075
+ cleanup();
1076
+ throw new ERR_INVALID_ARG_VALUE('stdio', stdio);
1077
+ }
1078
+
1079
+ return acc;
1080
+ }, []);
1081
+
1082
+ return { stdio, ipc, ipcFd };
1083
+ }
1084
+
1085
+
1086
+ function getSocketList(type, worker, key) {
1087
+ const sockets = worker[kChannelHandle].sockets[type];
1088
+ let socketList = sockets[key];
1089
+ if (!socketList) {
1090
+ const Construct = type === 'send' ? SocketListSend : SocketListReceive;
1091
+ socketList = sockets[key] = new Construct(worker, key);
1092
+ }
1093
+ return socketList;
1094
+ }
1095
+
1096
+
1097
+ function maybeClose(subprocess) {
1098
+ subprocess._closesGot++;
1099
+
1100
+ if (subprocess._closesGot === subprocess._closesNeeded) {
1101
+ subprocess.emit('close', subprocess.exitCode, subprocess.signalCode);
1102
+ }
1103
+ }
1104
+
1105
+ function spawnSync(options) {
1106
+ const result = spawn_sync.spawn(options);
1107
+
1108
+ if (result.output && options.encoding && options.encoding !== 'buffer') {
1109
+ for (let i = 0; i < result.output.length; i++) {
1110
+ if (!result.output[i])
1111
+ continue;
1112
+ result.output[i] = result.output[i].toString(options.encoding);
1113
+ }
1114
+ }
1115
+
1116
+ result.stdout = result.output?.[1];
1117
+ result.stderr = result.output?.[2];
1118
+
1119
+ if (result.error) {
1120
+ result.error = new ErrnoException(result.error, 'spawnSync ' + options.file);
1121
+ result.error.path = options.file;
1122
+ result.error.spawnargs = ArrayPrototypeSlice(options.args, 1);
1123
+ }
1124
+
1125
+ return result;
1126
+ }
1127
+
1128
+ module.exports = {
1129
+ ChildProcess,
1130
+ kChannelHandle,
1131
+ setupChannel,
1132
+ getValidStdio,
1133
+ stdioStringToArray,
1134
+ spawnSync,
1135
+ };