@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,1046 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ 'use strict';
23
+
24
+ const {
25
+ ArrayIsArray,
26
+ ArrayPrototypeFilter,
27
+ ArrayPrototypeIncludes,
28
+ ArrayPrototypeJoin,
29
+ ArrayPrototypeLastIndexOf,
30
+ ArrayPrototypePush,
31
+ ArrayPrototypePushApply,
32
+ ArrayPrototypeSlice,
33
+ ArrayPrototypeSort,
34
+ ArrayPrototypeSplice,
35
+ ArrayPrototypeUnshift,
36
+ NumberIsInteger,
37
+ ObjectAssign,
38
+ ObjectDefineProperty,
39
+ ObjectPrototypeHasOwnProperty,
40
+ PromiseWithResolvers,
41
+ RegExpPrototypeExec,
42
+ SafeSet,
43
+ StringPrototypeIncludes,
44
+ StringPrototypeSlice,
45
+ StringPrototypeToUpperCase,
46
+ } = primordials;
47
+
48
+ const {
49
+ assignFunctionName,
50
+ convertToValidSignal,
51
+ getSystemErrorName,
52
+ kEmptyObject,
53
+ promisify,
54
+ SymbolDispose,
55
+ } = require('internal/util');
56
+ const { isArrayBufferView } = require('internal/util/types');
57
+ let debug = require('internal/util/debuglog').debuglog(
58
+ 'child_process',
59
+ (fn) => {
60
+ debug = fn;
61
+ },
62
+ );
63
+ const { Buffer } = require('buffer');
64
+ const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap');
65
+
66
+ const {
67
+ AbortError,
68
+ codes: {
69
+ ERR_CHILD_PROCESS_IPC_REQUIRED,
70
+ ERR_CHILD_PROCESS_STDIO_MAXBUFFER,
71
+ ERR_INVALID_ARG_TYPE,
72
+ ERR_INVALID_ARG_VALUE,
73
+ ERR_OUT_OF_RANGE,
74
+ },
75
+ genericNodeError,
76
+ } = require('internal/errors');
77
+ const { clearTimeout, setTimeout } = require('timers');
78
+ const { getValidatedPath } = require('internal/fs/utils');
79
+ const {
80
+ isInt32,
81
+ validateAbortSignal,
82
+ validateArray,
83
+ validateBoolean,
84
+ validateFunction,
85
+ validateObject,
86
+ validateString,
87
+ } = require('internal/validators');
88
+ const child_process = require('internal/child_process');
89
+ const {
90
+ getValidStdio,
91
+ setupChannel,
92
+ ChildProcess,
93
+ stdioStringToArray,
94
+ } = child_process;
95
+
96
+ const MAX_BUFFER = 1024 * 1024;
97
+
98
+ const permission = require('internal/process/permission');
99
+
100
+ const isZOS = process.platform === 'os390';
101
+ let addAbortListener;
102
+
103
+ /**
104
+ * Spawns a new Node.js process + fork.
105
+ * @param {string|URL} modulePath
106
+ * @param {string[]} [args]
107
+ * @param {{
108
+ * cwd?: string | URL;
109
+ * detached?: boolean;
110
+ * env?: Record<string, string>;
111
+ * execPath?: string;
112
+ * execArgv?: string[];
113
+ * gid?: number;
114
+ * serialization?: string;
115
+ * signal?: AbortSignal;
116
+ * killSignal?: string | number;
117
+ * silent?: boolean;
118
+ * stdio?: Array | string;
119
+ * uid?: number;
120
+ * windowsVerbatimArguments?: boolean;
121
+ * timeout?: number;
122
+ * }} [options]
123
+ * @returns {ChildProcess}
124
+ */
125
+ function fork(modulePath, args = [], options) {
126
+ modulePath = getValidatedPath(modulePath, 'modulePath');
127
+
128
+ // Get options and args arguments.
129
+ let execArgv;
130
+
131
+ if (args == null) {
132
+ args = [];
133
+ } else if (typeof args === 'object' && !ArrayIsArray(args)) {
134
+ options = args;
135
+ args = [];
136
+ } else {
137
+ validateArray(args, 'args');
138
+ }
139
+
140
+ if (options != null) {
141
+ validateObject(options, 'options');
142
+ }
143
+ options = { __proto__: null, ...options, shell: false };
144
+ options.execPath ||= process.execPath;
145
+ validateArgumentNullCheck(options.execPath, 'options.execPath');
146
+
147
+ // Prepare arguments for fork:
148
+ execArgv = options.execArgv || process.execArgv;
149
+ validateArgumentsNullCheck(execArgv, 'options.execArgv');
150
+
151
+ if (execArgv === process.execArgv && process._eval != null) {
152
+ const index = ArrayPrototypeLastIndexOf(execArgv, process._eval);
153
+ if (index > 0) {
154
+ // Remove the -e switch to avoid fork bombing ourselves.
155
+ execArgv = ArrayPrototypeSlice(execArgv);
156
+ ArrayPrototypeSplice(execArgv, index - 1, 2);
157
+ }
158
+ }
159
+
160
+ args = [...execArgv, modulePath, ...args];
161
+
162
+ if (typeof options.stdio === 'string') {
163
+ options.stdio = stdioStringToArray(options.stdio, 'ipc');
164
+ } else if (!ArrayIsArray(options.stdio)) {
165
+ // Use a separate fd=3 for the IPC channel. Inherit stdin, stdout,
166
+ // and stderr from the parent if silent isn't set.
167
+ options.stdio = stdioStringToArray(
168
+ options.silent ? 'pipe' : 'inherit',
169
+ 'ipc');
170
+ } else if (!ArrayPrototypeIncludes(options.stdio, 'ipc')) {
171
+ throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio');
172
+ }
173
+
174
+ return spawn(options.execPath, args, options);
175
+ }
176
+
177
+ function _forkChild(fd, serializationMode) {
178
+ // set process.send()
179
+ const p = new Pipe(PipeConstants.IPC);
180
+ p.open(fd);
181
+ p.unref();
182
+ const control = setupChannel(process, p, serializationMode);
183
+ process.on('newListener', function onNewListener(name) {
184
+ if (name === 'message' || name === 'disconnect') control.refCounted();
185
+ });
186
+ process.on('removeListener', function onRemoveListener(name) {
187
+ if (name === 'message' || name === 'disconnect') control.unrefCounted();
188
+ });
189
+ }
190
+
191
+ function normalizeExecArgs(command, options, callback) {
192
+ validateString(command, 'command');
193
+ validateArgumentNullCheck(command, 'command');
194
+
195
+ if (typeof options === 'function') {
196
+ callback = options;
197
+ options = undefined;
198
+ }
199
+
200
+ // Make a shallow copy so we don't clobber the user's options object.
201
+ options = { __proto__: null, ...options };
202
+ options.shell = typeof options.shell === 'string' ? options.shell : true;
203
+
204
+ return {
205
+ file: command,
206
+ options: options,
207
+ callback: callback,
208
+ };
209
+ }
210
+
211
+ /**
212
+ * Spawns a shell executing the given command.
213
+ * @param {string} command
214
+ * @param {{
215
+ * cmd?: string;
216
+ * env?: Record<string, string>;
217
+ * encoding?: string;
218
+ * shell?: string;
219
+ * signal?: AbortSignal;
220
+ * timeout?: number;
221
+ * maxBuffer?: number;
222
+ * killSignal?: string | number;
223
+ * uid?: number;
224
+ * gid?: number;
225
+ * windowsHide?: boolean;
226
+ * }} [options]
227
+ * @param {(
228
+ * error?: Error,
229
+ * stdout?: string | Buffer,
230
+ * stderr?: string | Buffer
231
+ * ) => any} [callback]
232
+ * @returns {ChildProcess}
233
+ */
234
+ function exec(command, options, callback) {
235
+ const opts = normalizeExecArgs(command, options, callback);
236
+ return module.exports.execFile(opts.file,
237
+ opts.options,
238
+ opts.callback);
239
+ }
240
+
241
+ const customPromiseExecFunction = (orig) => {
242
+ return assignFunctionName(orig.name, function(...args) {
243
+ const { promise, resolve, reject } = PromiseWithResolvers();
244
+
245
+ promise.child = orig(...args, (err, stdout, stderr) => {
246
+ if (err !== null) {
247
+ err.stdout = stdout;
248
+ err.stderr = stderr;
249
+ reject(err);
250
+ } else {
251
+ resolve({ stdout, stderr });
252
+ }
253
+ });
254
+
255
+ return promise;
256
+ });
257
+ };
258
+
259
+ ObjectDefineProperty(exec, promisify.custom, {
260
+ __proto__: null,
261
+ enumerable: false,
262
+ value: customPromiseExecFunction(exec),
263
+ });
264
+
265
+ function normalizeExecFileArgs(file, args, options, callback) {
266
+ if (ArrayIsArray(args)) {
267
+ args = ArrayPrototypeSlice(args);
268
+ } else if (args != null && typeof args === 'object') {
269
+ callback = options;
270
+ options = args;
271
+ args = null;
272
+ } else if (typeof args === 'function') {
273
+ callback = args;
274
+ options = null;
275
+ args = null;
276
+ }
277
+
278
+ args ??= [];
279
+
280
+ if (typeof options === 'function') {
281
+ callback = options;
282
+ } else if (options != null) {
283
+ validateObject(options, 'options');
284
+ }
285
+
286
+ options ??= kEmptyObject;
287
+
288
+ if (callback != null) {
289
+ validateFunction(callback, 'callback');
290
+ }
291
+
292
+ // Validate argv0, if present.
293
+ if (options.argv0 != null) {
294
+ validateString(options.argv0, 'options.argv0');
295
+ validateArgumentNullCheck(options.argv0, 'options.argv0');
296
+ }
297
+
298
+ return { file, args, options, callback };
299
+ }
300
+
301
+ /**
302
+ * Spawns the specified file as a shell.
303
+ * @param {string} file
304
+ * @param {string[]} [args]
305
+ * @param {{
306
+ * cwd?: string | URL;
307
+ * env?: Record<string, string>;
308
+ * encoding?: string;
309
+ * timeout?: number;
310
+ * maxBuffer?: number;
311
+ * killSignal?: string | number;
312
+ * uid?: number;
313
+ * gid?: number;
314
+ * windowsHide?: boolean;
315
+ * windowsVerbatimArguments?: boolean;
316
+ * shell?: boolean | string;
317
+ * signal?: AbortSignal;
318
+ * }} [options]
319
+ * @param {(
320
+ * error?: Error,
321
+ * stdout?: string | Buffer,
322
+ * stderr?: string | Buffer
323
+ * ) => any} [callback]
324
+ * @returns {ChildProcess}
325
+ */
326
+ function execFile(file, args, options, callback) {
327
+ ({ file, args, options, callback } = normalizeExecFileArgs(file, args, options, callback));
328
+
329
+ options = {
330
+ __proto__: null,
331
+ encoding: 'utf8',
332
+ timeout: 0,
333
+ maxBuffer: MAX_BUFFER,
334
+ killSignal: 'SIGTERM',
335
+ cwd: null,
336
+ env: null,
337
+ shell: false,
338
+ ...options,
339
+ };
340
+
341
+ // Validate the timeout, if present.
342
+ validateTimeout(options.timeout);
343
+
344
+ // Validate maxBuffer, if present.
345
+ validateMaxBuffer(options.maxBuffer);
346
+
347
+ options.killSignal = sanitizeKillSignal(options.killSignal);
348
+
349
+ const child = spawn(file, args, {
350
+ cwd: options.cwd,
351
+ env: options.env,
352
+ gid: options.gid,
353
+ shell: options.shell,
354
+ signal: options.signal,
355
+ uid: options.uid,
356
+ windowsHide: !!options.windowsHide,
357
+ windowsVerbatimArguments: !!options.windowsVerbatimArguments,
358
+ });
359
+
360
+ let encoding;
361
+ const _stdout = [];
362
+ const _stderr = [];
363
+ if (options.encoding !== 'buffer' && Buffer.isEncoding(options.encoding)) {
364
+ encoding = options.encoding;
365
+ } else {
366
+ encoding = null;
367
+ }
368
+ let stdoutLen = 0;
369
+ let stderrLen = 0;
370
+ let killed = false;
371
+ let exited = false;
372
+ let timeoutId;
373
+
374
+ let ex = null;
375
+
376
+ let cmd = file;
377
+
378
+ function exithandler(code, signal) {
379
+ if (exited) return;
380
+ exited = true;
381
+
382
+ if (timeoutId) {
383
+ clearTimeout(timeoutId);
384
+ timeoutId = null;
385
+ }
386
+
387
+ if (!callback) return;
388
+
389
+ // merge chunks
390
+ let stdout;
391
+ let stderr;
392
+ if (encoding ||
393
+ (
394
+ child.stdout?.readableEncoding
395
+ )) {
396
+ stdout = ArrayPrototypeJoin(_stdout, '');
397
+ } else {
398
+ stdout = Buffer.concat(_stdout);
399
+ }
400
+ if (encoding ||
401
+ (
402
+ child.stderr?.readableEncoding
403
+ )) {
404
+ stderr = ArrayPrototypeJoin(_stderr, '');
405
+ } else {
406
+ stderr = Buffer.concat(_stderr);
407
+ }
408
+
409
+ if (!ex && code === 0 && signal === null) {
410
+ callback(null, stdout, stderr);
411
+ return;
412
+ }
413
+
414
+ if (args?.length)
415
+ cmd += ` ${ArrayPrototypeJoin(args, ' ')}`;
416
+
417
+ ex ||= genericNodeError(`Command failed: ${cmd}\n${stderr}`, {
418
+ code: code < 0 ? getSystemErrorName(code) : code,
419
+ killed: child.killed || killed,
420
+ signal: signal,
421
+ });
422
+
423
+ ex.cmd = cmd;
424
+ callback(ex, stdout, stderr);
425
+ }
426
+
427
+ function errorhandler(e) {
428
+ ex = e;
429
+
430
+ if (child.stdout)
431
+ child.stdout.destroy();
432
+
433
+ if (child.stderr)
434
+ child.stderr.destroy();
435
+
436
+ exithandler();
437
+ }
438
+
439
+ function kill() {
440
+ if (child.stdout)
441
+ child.stdout.destroy();
442
+
443
+ if (child.stderr)
444
+ child.stderr.destroy();
445
+
446
+ killed = true;
447
+ try {
448
+ child.kill(options.killSignal);
449
+ } catch (e) {
450
+ ex = e;
451
+ exithandler();
452
+ }
453
+ }
454
+
455
+ if (options.timeout > 0) {
456
+ timeoutId = setTimeout(function delayedKill() {
457
+ kill();
458
+ timeoutId = null;
459
+ }, options.timeout);
460
+ }
461
+
462
+ if (child.stdout) {
463
+ if (encoding)
464
+ child.stdout.setEncoding(encoding);
465
+
466
+ child.stdout.on('data', function onChildStdout(chunk) {
467
+ // Do not need to count the length
468
+ if (options.maxBuffer === Infinity) {
469
+ ArrayPrototypePush(_stdout, chunk);
470
+ return;
471
+ }
472
+ const encoding = child.stdout.readableEncoding;
473
+ const length = encoding ?
474
+ Buffer.byteLength(chunk, encoding) :
475
+ chunk.length;
476
+ const slice = encoding ? StringPrototypeSlice :
477
+ (buf, ...args) => buf.slice(...args);
478
+ stdoutLen += length;
479
+
480
+ if (stdoutLen > options.maxBuffer) {
481
+ const truncatedLen = options.maxBuffer - (stdoutLen - length);
482
+ ArrayPrototypePush(_stdout, slice(chunk, 0, truncatedLen));
483
+
484
+ ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stdout');
485
+ kill();
486
+ } else {
487
+ ArrayPrototypePush(_stdout, chunk);
488
+ }
489
+ });
490
+ }
491
+
492
+ if (child.stderr) {
493
+ if (encoding)
494
+ child.stderr.setEncoding(encoding);
495
+
496
+ child.stderr.on('data', function onChildStderr(chunk) {
497
+ // Do not need to count the length
498
+ if (options.maxBuffer === Infinity) {
499
+ ArrayPrototypePush(_stderr, chunk);
500
+ return;
501
+ }
502
+ const encoding = child.stderr.readableEncoding;
503
+ const length = encoding ?
504
+ Buffer.byteLength(chunk, encoding) :
505
+ chunk.length;
506
+ stderrLen += length;
507
+
508
+ if (stderrLen > options.maxBuffer) {
509
+ const truncatedLen = options.maxBuffer - (stderrLen - length);
510
+ ArrayPrototypePush(_stderr,
511
+ chunk.slice(0, truncatedLen));
512
+
513
+ ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stderr');
514
+ kill();
515
+ } else {
516
+ ArrayPrototypePush(_stderr, chunk);
517
+ }
518
+ });
519
+ }
520
+
521
+ child.addListener('close', exithandler);
522
+ child.addListener('error', errorhandler);
523
+
524
+ return child;
525
+ }
526
+
527
+ ObjectDefineProperty(execFile, promisify.custom, {
528
+ __proto__: null,
529
+ enumerable: false,
530
+ value: customPromiseExecFunction(execFile),
531
+ });
532
+
533
+ function copyProcessEnvToEnv(env, name, optionEnv) {
534
+ if (process.env[name] &&
535
+ (!optionEnv ||
536
+ !ObjectPrototypeHasOwnProperty(optionEnv, name))) {
537
+ env[name] = process.env[name];
538
+ }
539
+ }
540
+
541
+ let permissionModelFlagsToCopy;
542
+
543
+ function getPermissionModelFlagsToCopy() {
544
+ if (permissionModelFlagsToCopy === undefined) {
545
+ permissionModelFlagsToCopy = [...permission.availableFlags(), '--permission'];
546
+ }
547
+ return permissionModelFlagsToCopy;
548
+ }
549
+
550
+ function copyPermissionModelFlagsToEnv(env, key, args) {
551
+ // Do not override if permission was already passed to file
552
+ if (args.includes('--permission') || (env[key] && env[key].indexOf('--permission') !== -1)) {
553
+ return;
554
+ }
555
+
556
+ const flagsToCopy = getPermissionModelFlagsToCopy();
557
+ for (const arg of process.execArgv) {
558
+ for (const flag of flagsToCopy) {
559
+ if (arg.startsWith(flag)) {
560
+ env[key] = `${env[key] ? env[key] + ' ' + arg : arg}`;
561
+ }
562
+ }
563
+ }
564
+ }
565
+
566
+ function normalizeSpawnArguments(file, args, options) {
567
+ validateString(file, 'file');
568
+ validateArgumentNullCheck(file, 'file');
569
+
570
+ if (file.length === 0)
571
+ throw new ERR_INVALID_ARG_VALUE('file', file, 'cannot be empty');
572
+
573
+ if (ArrayIsArray(args)) {
574
+ args = ArrayPrototypeSlice(args);
575
+ } else if (args == null) {
576
+ args = [];
577
+ } else if (typeof args !== 'object') {
578
+ throw new ERR_INVALID_ARG_TYPE('args', 'object', args);
579
+ } else {
580
+ options = args;
581
+ args = [];
582
+ }
583
+
584
+ validateArgumentsNullCheck(args, 'args');
585
+
586
+ if (options === undefined)
587
+ options = kEmptyObject;
588
+ else
589
+ validateObject(options, 'options');
590
+
591
+ options = { __proto__: null, ...options };
592
+ let cwd = options.cwd;
593
+
594
+ // Validate the cwd, if present.
595
+ if (cwd != null) {
596
+ cwd = getValidatedPath(cwd, 'options.cwd');
597
+ }
598
+
599
+ // Validate detached, if present.
600
+ if (options.detached != null) {
601
+ validateBoolean(options.detached, 'options.detached');
602
+ }
603
+
604
+ // Validate the uid, if present.
605
+ if (options.uid != null && !isInt32(options.uid)) {
606
+ throw new ERR_INVALID_ARG_TYPE('options.uid', 'int32', options.uid);
607
+ }
608
+
609
+ // Validate the gid, if present.
610
+ if (options.gid != null && !isInt32(options.gid)) {
611
+ throw new ERR_INVALID_ARG_TYPE('options.gid', 'int32', options.gid);
612
+ }
613
+
614
+ // Validate the shell, if present.
615
+ if (options.shell != null &&
616
+ typeof options.shell !== 'boolean' &&
617
+ typeof options.shell !== 'string') {
618
+ throw new ERR_INVALID_ARG_TYPE('options.shell',
619
+ ['boolean', 'string'], options.shell);
620
+ }
621
+
622
+ // Validate argv0, if present.
623
+ if (options.argv0 != null) {
624
+ validateString(options.argv0, 'options.argv0');
625
+ validateArgumentNullCheck(options.argv0, 'options.argv0');
626
+ }
627
+
628
+ // Validate windowsHide, if present.
629
+ if (options.windowsHide != null) {
630
+ validateBoolean(options.windowsHide, 'options.windowsHide');
631
+ }
632
+
633
+ // Validate windowsVerbatimArguments, if present.
634
+ let { windowsVerbatimArguments } = options;
635
+ if (windowsVerbatimArguments != null) {
636
+ validateBoolean(windowsVerbatimArguments,
637
+ 'options.windowsVerbatimArguments');
638
+ }
639
+
640
+ if (options.shell) {
641
+ validateArgumentNullCheck(options.shell, 'options.shell');
642
+ const command = ArrayPrototypeJoin([file, ...args], ' ');
643
+ // Set the shell, switches, and commands.
644
+ if (process.platform === 'win32') {
645
+ if (typeof options.shell === 'string')
646
+ file = options.shell;
647
+ else
648
+ file = process.env.comspec || 'cmd.exe';
649
+ // '/d /s /c' is used only for cmd.exe.
650
+ if (RegExpPrototypeExec(/^(?:.*\\)?cmd(?:\.exe)?$/i, file) !== null) {
651
+ args = ['/d', '/s', '/c', `"${command}"`];
652
+ windowsVerbatimArguments = true;
653
+ } else {
654
+ args = ['-c', command];
655
+ }
656
+ } else {
657
+ if (typeof options.shell === 'string')
658
+ file = options.shell;
659
+ else if (process.platform === 'android')
660
+ file = '/system/bin/sh';
661
+ else
662
+ file = '/bin/sh';
663
+ args = ['-c', command];
664
+ }
665
+ }
666
+
667
+ if (typeof options.argv0 === 'string') {
668
+ ArrayPrototypeUnshift(args, options.argv0);
669
+ } else {
670
+ ArrayPrototypeUnshift(args, file);
671
+ }
672
+
673
+ // Shallow copy to guarantee changes won't impact process.env
674
+ const env = options.env || { ...process.env };
675
+ const envPairs = [];
676
+
677
+ // process.env.NODE_V8_COVERAGE always propagates, making it possible to
678
+ // collect coverage for programs that spawn with white-listed environment.
679
+ copyProcessEnvToEnv(env, 'NODE_V8_COVERAGE', options.env);
680
+
681
+ if (isZOS) {
682
+ // The following environment variables must always propagate if set.
683
+ copyProcessEnvToEnv(env, '_BPXK_AUTOCVT', options.env);
684
+ copyProcessEnvToEnv(env, '_CEE_RUNOPTS', options.env);
685
+ copyProcessEnvToEnv(env, '_TAG_REDIR_ERR', options.env);
686
+ copyProcessEnvToEnv(env, '_TAG_REDIR_IN', options.env);
687
+ copyProcessEnvToEnv(env, '_TAG_REDIR_OUT', options.env);
688
+ copyProcessEnvToEnv(env, 'STEPLIB', options.env);
689
+ copyProcessEnvToEnv(env, 'LIBPATH', options.env);
690
+ copyProcessEnvToEnv(env, '_EDC_SIG_DFLT', options.env);
691
+ copyProcessEnvToEnv(env, '_EDC_SUSV3', options.env);
692
+ }
693
+
694
+ if (permission.isEnabled()) {
695
+ copyPermissionModelFlagsToEnv(env, 'NODE_OPTIONS', args);
696
+ }
697
+
698
+ let envKeys = [];
699
+ // Prototype values are intentionally included.
700
+ for (const key in env) {
701
+ ArrayPrototypePush(envKeys, key);
702
+ }
703
+
704
+ if (process.platform === 'win32') {
705
+ // On Windows env keys are case insensitive. Filter out duplicates,
706
+ // keeping only the first one (in lexicographic order)
707
+ const sawKey = new SafeSet();
708
+ envKeys = ArrayPrototypeFilter(
709
+ ArrayPrototypeSort(envKeys),
710
+ (key) => {
711
+ const uppercaseKey = StringPrototypeToUpperCase(key);
712
+ if (sawKey.has(uppercaseKey)) {
713
+ return false;
714
+ }
715
+ sawKey.add(uppercaseKey);
716
+ return true;
717
+ },
718
+ );
719
+ }
720
+
721
+ for (const key of envKeys) {
722
+ const value = env[key];
723
+ if (value !== undefined) {
724
+ validateArgumentNullCheck(key, `options.env['${key}']`);
725
+ validateArgumentNullCheck(value, `options.env['${key}']`);
726
+ ArrayPrototypePush(envPairs, `${key}=${value}`);
727
+ }
728
+ }
729
+
730
+ return {
731
+ // Make a shallow copy so we don't clobber the user's options object.
732
+ __proto__: null,
733
+ ...options,
734
+ args,
735
+ cwd,
736
+ detached: !!options.detached,
737
+ envPairs,
738
+ file,
739
+ windowsHide: !!options.windowsHide,
740
+ windowsVerbatimArguments: !!windowsVerbatimArguments,
741
+ };
742
+ }
743
+
744
+ function abortChildProcess(child, killSignal, reason) {
745
+ if (!child)
746
+ return;
747
+ try {
748
+ if (child.kill(killSignal)) {
749
+ child.emit('error', new AbortError(undefined, { cause: reason }));
750
+ }
751
+ } catch (err) {
752
+ child.emit('error', err);
753
+ }
754
+ }
755
+
756
+ /**
757
+ * Spawns a new process using the given `file`.
758
+ * @param {string} file
759
+ * @param {string[]} [args]
760
+ * @param {{
761
+ * cwd?: string | URL;
762
+ * env?: Record<string, string>;
763
+ * argv0?: string;
764
+ * stdio?: Array | string;
765
+ * detached?: boolean;
766
+ * uid?: number;
767
+ * gid?: number;
768
+ * serialization?: string;
769
+ * shell?: boolean | string;
770
+ * windowsVerbatimArguments?: boolean;
771
+ * windowsHide?: boolean;
772
+ * signal?: AbortSignal;
773
+ * timeout?: number;
774
+ * killSignal?: string | number;
775
+ * }} [options]
776
+ * @returns {ChildProcess}
777
+ */
778
+ function spawn(file, args, options) {
779
+ options = normalizeSpawnArguments(file, args, options);
780
+ validateTimeout(options.timeout);
781
+ validateAbortSignal(options.signal, 'options.signal');
782
+ const killSignal = sanitizeKillSignal(options.killSignal);
783
+ const child = new ChildProcess();
784
+
785
+ debug('spawn', options);
786
+ child.spawn(options);
787
+
788
+ if (options.timeout > 0) {
789
+ let timeoutId = setTimeout(() => {
790
+ if (timeoutId) {
791
+ try {
792
+ child.kill(killSignal);
793
+ } catch (err) {
794
+ child.emit('error', err);
795
+ }
796
+ timeoutId = null;
797
+ }
798
+ }, options.timeout);
799
+
800
+ child.once('exit', () => {
801
+ if (timeoutId) {
802
+ clearTimeout(timeoutId);
803
+ timeoutId = null;
804
+ }
805
+ });
806
+ }
807
+
808
+ if (options.signal) {
809
+ const signal = options.signal;
810
+ if (signal.aborted) {
811
+ process.nextTick(onAbortListener);
812
+ } else {
813
+ addAbortListener ??= require('internal/events/abort_listener').addAbortListener;
814
+ const disposable = addAbortListener(signal, onAbortListener);
815
+ child.once('exit', disposable[SymbolDispose]);
816
+ }
817
+
818
+ function onAbortListener() {
819
+ abortChildProcess(child, killSignal, options.signal.reason);
820
+ }
821
+ }
822
+
823
+ return child;
824
+ }
825
+
826
+ /**
827
+ * Spawns a new process synchronously using the given `file`.
828
+ * @param {string} file
829
+ * @param {string[]} [args]
830
+ * @param {{
831
+ * cwd?: string | URL;
832
+ * input?: string | Buffer | TypedArray | DataView;
833
+ * argv0?: string;
834
+ * stdio?: string | Array;
835
+ * env?: Record<string, string>;
836
+ * uid?: number;
837
+ * gid?: number;
838
+ * timeout?: number;
839
+ * killSignal?: string | number;
840
+ * maxBuffer?: number;
841
+ * encoding?: string;
842
+ * shell?: boolean | string;
843
+ * windowsVerbatimArguments?: boolean;
844
+ * windowsHide?: boolean;
845
+ * }} [options]
846
+ * @returns {{
847
+ * pid: number;
848
+ * output: Array;
849
+ * stdout: Buffer | string;
850
+ * stderr: Buffer | string;
851
+ * status: number | null;
852
+ * signal: string | null;
853
+ * error: Error;
854
+ * }}
855
+ */
856
+ function spawnSync(file, args, options) {
857
+ options = {
858
+ __proto__: null,
859
+ maxBuffer: MAX_BUFFER,
860
+ ...normalizeSpawnArguments(file, args, options),
861
+ };
862
+
863
+ debug('spawnSync', options);
864
+
865
+ // Validate the timeout, if present.
866
+ validateTimeout(options.timeout);
867
+
868
+ // Validate maxBuffer, if present.
869
+ validateMaxBuffer(options.maxBuffer);
870
+
871
+ // Validate and translate the kill signal, if present.
872
+ options.killSignal = sanitizeKillSignal(options.killSignal);
873
+
874
+ options.stdio = getValidStdio(options.stdio || 'pipe', true).stdio;
875
+
876
+ if (options.input) {
877
+ const stdin = options.stdio[0] = { ...options.stdio[0] };
878
+ stdin.input = options.input;
879
+ }
880
+
881
+ // We may want to pass data in on any given fd, ensure it is a valid buffer
882
+ for (let i = 0; i < options.stdio.length; i++) {
883
+ const input = options.stdio[i]?.input;
884
+ if (input != null) {
885
+ const pipe = options.stdio[i] = { ...options.stdio[i] };
886
+ if (isArrayBufferView(input)) {
887
+ pipe.input = input;
888
+ } else if (typeof input === 'string') {
889
+ pipe.input = Buffer.from(input, options.encoding);
890
+ } else {
891
+ throw new ERR_INVALID_ARG_TYPE(`options.stdio[${i}]`,
892
+ ['Buffer',
893
+ 'TypedArray',
894
+ 'DataView',
895
+ 'string'],
896
+ input);
897
+ }
898
+ }
899
+ }
900
+
901
+ return child_process.spawnSync(options);
902
+ }
903
+
904
+
905
+ function checkExecSyncError(ret, args, cmd) {
906
+ let err;
907
+ if (ret.error) {
908
+ err = ret.error;
909
+ ObjectAssign(err, ret);
910
+ } else if (ret.status !== 0) {
911
+ let msg = 'Command failed: ';
912
+ msg += cmd || ArrayPrototypeJoin(args, ' ');
913
+ if (ret.stderr && ret.stderr.length > 0)
914
+ msg += `\n${ret.stderr.toString()}`;
915
+ err = genericNodeError(msg, ret);
916
+ }
917
+ return err;
918
+ }
919
+
920
+ /**
921
+ * Spawns a file as a shell synchronously.
922
+ * @param {string} file
923
+ * @param {string[]} [args]
924
+ * @param {{
925
+ * cwd?: string | URL;
926
+ * input?: string | Buffer | TypedArray | DataView;
927
+ * stdio?: string | Array;
928
+ * env?: Record<string, string>;
929
+ * uid?: number;
930
+ * gid?: number;
931
+ * timeout?: number;
932
+ * killSignal?: string | number;
933
+ * maxBuffer?: number;
934
+ * encoding?: string;
935
+ * windowsHide?: boolean;
936
+ * shell?: boolean | string;
937
+ * }} [options]
938
+ * @returns {Buffer | string}
939
+ */
940
+ function execFileSync(file, args, options) {
941
+ ({ file, args, options } = normalizeExecFileArgs(file, args, options));
942
+
943
+ const inheritStderr = !options.stdio;
944
+ const ret = spawnSync(file, args, options);
945
+
946
+ if (inheritStderr && ret.stderr)
947
+ process.stderr.write(ret.stderr);
948
+
949
+ const errArgs = [options.argv0 || file];
950
+ ArrayPrototypePushApply(errArgs, args);
951
+ const err = checkExecSyncError(ret, errArgs);
952
+
953
+ if (err)
954
+ throw err;
955
+
956
+ return ret.stdout;
957
+ }
958
+
959
+ /**
960
+ * Spawns a shell executing the given `command` synchronously.
961
+ * @param {string} command
962
+ * @param {{
963
+ * cwd?: string | URL;
964
+ * input?: string | Buffer | TypedArray | DataView;
965
+ * stdio?: string | Array;
966
+ * env?: Record<string, string>;
967
+ * shell?: string;
968
+ * uid?: number;
969
+ * gid?: number;
970
+ * timeout?: number;
971
+ * killSignal?: string | number;
972
+ * maxBuffer?: number;
973
+ * encoding?: string;
974
+ * windowsHide?: boolean;
975
+ * }} [options]
976
+ * @returns {Buffer | string}
977
+ */
978
+ function execSync(command, options) {
979
+ const opts = normalizeExecArgs(command, options, null);
980
+ const inheritStderr = !opts.options.stdio;
981
+
982
+ const ret = spawnSync(opts.file, opts.options);
983
+
984
+ if (inheritStderr && ret.stderr)
985
+ process.stderr.write(ret.stderr);
986
+
987
+ const err = checkExecSyncError(ret, undefined, command);
988
+
989
+ if (err)
990
+ throw err;
991
+
992
+ return ret.stdout;
993
+ }
994
+
995
+
996
+ function validateArgumentNullCheck(arg, propName) {
997
+ if (typeof arg === 'string' && StringPrototypeIncludes(arg, '\u0000')) {
998
+ throw new ERR_INVALID_ARG_VALUE(propName, arg, 'must be a string without null bytes');
999
+ }
1000
+ }
1001
+
1002
+
1003
+ function validateArgumentsNullCheck(args, propName) {
1004
+ for (let i = 0; i < args.length; ++i) {
1005
+ validateArgumentNullCheck(args[i], `${propName}[${i}]`);
1006
+ }
1007
+ }
1008
+
1009
+
1010
+ function validateTimeout(timeout) {
1011
+ if (timeout != null && !(NumberIsInteger(timeout) && timeout >= 0)) {
1012
+ throw new ERR_OUT_OF_RANGE('timeout', 'an unsigned integer', timeout);
1013
+ }
1014
+ }
1015
+
1016
+
1017
+ function validateMaxBuffer(maxBuffer) {
1018
+ if (maxBuffer != null && !(typeof maxBuffer === 'number' && maxBuffer >= 0)) {
1019
+ throw new ERR_OUT_OF_RANGE('options.maxBuffer',
1020
+ 'a positive number',
1021
+ maxBuffer);
1022
+ }
1023
+ }
1024
+
1025
+
1026
+ function sanitizeKillSignal(killSignal) {
1027
+ if (typeof killSignal === 'string' || typeof killSignal === 'number') {
1028
+ return convertToValidSignal(killSignal);
1029
+ } else if (killSignal != null) {
1030
+ throw new ERR_INVALID_ARG_TYPE('options.killSignal',
1031
+ ['string', 'number'],
1032
+ killSignal);
1033
+ }
1034
+ }
1035
+
1036
+ module.exports = {
1037
+ _forkChild,
1038
+ ChildProcess,
1039
+ exec,
1040
+ execFile,
1041
+ execFileSync,
1042
+ execSync,
1043
+ fork,
1044
+ spawn,
1045
+ spawnSync,
1046
+ };