@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,1163 @@
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
+ // A bit simpler than readable streams.
23
+ // Implement an async ._write(chunk, encoding, cb), and it'll handle all
24
+ // the drain event emission and buffering.
25
+
26
+ 'use strict';
27
+
28
+ const {
29
+ ArrayPrototypeSlice,
30
+ Error,
31
+ FunctionPrototypeSymbolHasInstance,
32
+ ObjectDefineProperties,
33
+ ObjectDefineProperty,
34
+ ObjectSetPrototypeOf,
35
+ Promise,
36
+ StringPrototypeToLowerCase,
37
+ Symbol,
38
+ SymbolHasInstance,
39
+ } = primordials;
40
+
41
+ module.exports = Writable;
42
+ Writable.WritableState = WritableState;
43
+
44
+ const EE = require('events');
45
+ const Stream = require('internal/streams/legacy').Stream;
46
+ const { Buffer } = require('buffer');
47
+ const destroyImpl = require('internal/streams/destroy');
48
+ const eos = require('internal/streams/end-of-stream');
49
+ const {
50
+ SymbolAsyncDispose,
51
+ } = require('internal/util');
52
+
53
+ const {
54
+ addAbortSignal,
55
+ } = require('internal/streams/add-abort-signal');
56
+
57
+ const {
58
+ getHighWaterMark,
59
+ getDefaultHighWaterMark,
60
+ } = require('internal/streams/state');
61
+ const {
62
+ AbortError,
63
+ codes: {
64
+ ERR_INVALID_ARG_TYPE,
65
+ ERR_METHOD_NOT_IMPLEMENTED,
66
+ ERR_MULTIPLE_CALLBACK,
67
+ ERR_STREAM_ALREADY_FINISHED,
68
+ ERR_STREAM_CANNOT_PIPE,
69
+ ERR_STREAM_DESTROYED,
70
+ ERR_STREAM_NULL_VALUES,
71
+ ERR_STREAM_WRITE_AFTER_END,
72
+ ERR_UNKNOWN_ENCODING,
73
+ },
74
+ } = require('internal/errors');
75
+ const {
76
+ kState,
77
+ // bitfields
78
+ kObjectMode,
79
+ kErrorEmitted,
80
+ kAutoDestroy,
81
+ kEmitClose,
82
+ kDestroyed,
83
+ kClosed,
84
+ kCloseEmitted,
85
+ kErrored,
86
+ kConstructed,
87
+ kOnConstructed,
88
+ } = require('internal/streams/utils');
89
+
90
+ const { errorOrDestroy } = destroyImpl;
91
+
92
+ ObjectSetPrototypeOf(Writable.prototype, Stream.prototype);
93
+ ObjectSetPrototypeOf(Writable, Stream);
94
+
95
+ function nop() {}
96
+
97
+ const kOnFinishedValue = Symbol('kOnFinishedValue');
98
+ const kErroredValue = Symbol('kErroredValue');
99
+ const kDefaultEncodingValue = Symbol('kDefaultEncodingValue');
100
+ const kWriteCbValue = Symbol('kWriteCbValue');
101
+ const kAfterWriteTickInfoValue = Symbol('kAfterWriteTickInfoValue');
102
+ const kBufferedValue = Symbol('kBufferedValue');
103
+
104
+ const kSync = 1 << 9;
105
+ const kFinalCalled = 1 << 10;
106
+ const kNeedDrain = 1 << 11;
107
+ const kEnding = 1 << 12;
108
+ const kFinished = 1 << 13;
109
+ const kDecodeStrings = 1 << 14;
110
+ const kWriting = 1 << 15;
111
+ const kBufferProcessing = 1 << 16;
112
+ const kPrefinished = 1 << 17;
113
+ const kAllBuffers = 1 << 18;
114
+ const kAllNoop = 1 << 19;
115
+ const kOnFinished = 1 << 20;
116
+ const kHasWritable = 1 << 21;
117
+ const kWritable = 1 << 22;
118
+ const kCorked = 1 << 23;
119
+ const kDefaultUTF8Encoding = 1 << 24;
120
+ const kWriteCb = 1 << 25;
121
+ const kExpectWriteCb = 1 << 26;
122
+ const kAfterWriteTickInfo = 1 << 27;
123
+ const kAfterWritePending = 1 << 28;
124
+ const kBuffered = 1 << 29;
125
+ const kEnded = 1 << 30;
126
+
127
+ // TODO(benjamingr) it is likely slower to do it this way than with free functions
128
+ function makeBitMapDescriptor(bit) {
129
+ return {
130
+ enumerable: false,
131
+ get() { return (this[kState] & bit) !== 0; },
132
+ set(value) {
133
+ if (value) this[kState] |= bit;
134
+ else this[kState] &= ~bit;
135
+ },
136
+ };
137
+ }
138
+ ObjectDefineProperties(WritableState.prototype, {
139
+ // Object stream flag to indicate whether or not this stream
140
+ // contains buffers or objects.
141
+ objectMode: makeBitMapDescriptor(kObjectMode),
142
+
143
+ // if _final has been called.
144
+ finalCalled: makeBitMapDescriptor(kFinalCalled),
145
+
146
+ // drain event flag.
147
+ needDrain: makeBitMapDescriptor(kNeedDrain),
148
+
149
+ // At the start of calling end()
150
+ ending: makeBitMapDescriptor(kEnding),
151
+
152
+ // When end() has been called, and returned.
153
+ ended: makeBitMapDescriptor(kEnded),
154
+
155
+ // When 'finish' is emitted.
156
+ finished: makeBitMapDescriptor(kFinished),
157
+
158
+ // Has it been destroyed.
159
+ destroyed: makeBitMapDescriptor(kDestroyed),
160
+
161
+ // Should we decode strings into buffers before passing to _write?
162
+ // this is here so that some node-core streams can optimize string
163
+ // handling at a lower level.
164
+ decodeStrings: makeBitMapDescriptor(kDecodeStrings),
165
+
166
+ // A flag to see when we're in the middle of a write.
167
+ writing: makeBitMapDescriptor(kWriting),
168
+
169
+ // A flag to be able to tell if the onwrite cb is called immediately,
170
+ // or on a later tick. We set this to true at first, because any
171
+ // actions that shouldn't happen until "later" should generally also
172
+ // not happen before the first write call.
173
+ sync: makeBitMapDescriptor(kSync),
174
+
175
+ // A flag to know if we're processing previously buffered items, which
176
+ // may call the _write() callback in the same tick, so that we don't
177
+ // end up in an overlapped onwrite situation.
178
+ bufferProcessing: makeBitMapDescriptor(kBufferProcessing),
179
+
180
+ // Stream is still being constructed and cannot be
181
+ // destroyed until construction finished or failed.
182
+ // Async construction is opt in, therefore we start as
183
+ // constructed.
184
+ constructed: makeBitMapDescriptor(kConstructed),
185
+
186
+ // Emit prefinish if the only thing we're waiting for is _write cbs
187
+ // This is relevant for synchronous Transform streams.
188
+ prefinished: makeBitMapDescriptor(kPrefinished),
189
+
190
+ // True if the error was already emitted and should not be thrown again.
191
+ errorEmitted: makeBitMapDescriptor(kErrorEmitted),
192
+
193
+ // Should close be emitted on destroy. Defaults to true.
194
+ emitClose: makeBitMapDescriptor(kEmitClose),
195
+
196
+ // Should .destroy() be called after 'finish' (and potentially 'end').
197
+ autoDestroy: makeBitMapDescriptor(kAutoDestroy),
198
+
199
+ // Indicates whether the stream has finished destroying.
200
+ closed: makeBitMapDescriptor(kClosed),
201
+
202
+ // True if close has been emitted or would have been emitted
203
+ // depending on emitClose.
204
+ closeEmitted: makeBitMapDescriptor(kCloseEmitted),
205
+
206
+ allBuffers: makeBitMapDescriptor(kAllBuffers),
207
+ allNoop: makeBitMapDescriptor(kAllNoop),
208
+
209
+ // Indicates whether the stream has errored. When true all write() calls
210
+ // should return false. This is needed since when autoDestroy
211
+ // is disabled we need a way to tell whether the stream has failed.
212
+ // This is/should be a cold path.
213
+ errored: {
214
+ __proto__: null,
215
+ enumerable: false,
216
+ get() { return (this[kState] & kErrored) !== 0 ? this[kErroredValue] : null; },
217
+ set(value) {
218
+ if (value) {
219
+ this[kErroredValue] = value;
220
+ this[kState] |= kErrored;
221
+ } else {
222
+ this[kState] &= ~kErrored;
223
+ }
224
+ },
225
+ },
226
+
227
+ writable: {
228
+ __proto__: null,
229
+ enumerable: false,
230
+ get() { return (this[kState] & kHasWritable) !== 0 ? (this[kState] & kWritable) !== 0 : undefined; },
231
+ set(value) {
232
+ if (value == null) {
233
+ this[kState] &= ~(kHasWritable | kWritable);
234
+ } else if (value) {
235
+ this[kState] |= (kHasWritable | kWritable);
236
+ } else {
237
+ this[kState] |= kHasWritable;
238
+ this[kState] &= ~kWritable;
239
+ }
240
+ },
241
+ },
242
+
243
+ defaultEncoding: {
244
+ __proto__: null,
245
+ enumerable: false,
246
+ get() { return (this[kState] & kDefaultUTF8Encoding) !== 0 ? 'utf8' : this[kDefaultEncodingValue]; },
247
+ set(value) {
248
+ if (value === 'utf8' || value === 'utf-8') {
249
+ this[kState] |= kDefaultUTF8Encoding;
250
+ } else {
251
+ this[kState] &= ~kDefaultUTF8Encoding;
252
+ this[kDefaultEncodingValue] = value;
253
+ }
254
+ },
255
+ },
256
+
257
+ // The callback that the user supplies to write(chunk, encoding, cb).
258
+ writecb: {
259
+ __proto__: null,
260
+ enumerable: false,
261
+ get() { return (this[kState] & kWriteCb) !== 0 ? this[kWriteCbValue] : nop; },
262
+ set(value) {
263
+ this[kWriteCbValue] = value;
264
+ if (value) {
265
+ this[kState] |= kWriteCb;
266
+ } else {
267
+ this[kState] &= ~kWriteCb;
268
+ }
269
+ },
270
+ },
271
+
272
+ // Storage for data passed to the afterWrite() callback in case of
273
+ // synchronous _write() completion.
274
+ afterWriteTickInfo: {
275
+ __proto__: null,
276
+ enumerable: false,
277
+ get() { return (this[kState] & kAfterWriteTickInfo) !== 0 ? this[kAfterWriteTickInfoValue] : null; },
278
+ set(value) {
279
+ this[kAfterWriteTickInfoValue] = value;
280
+ if (value) {
281
+ this[kState] |= kAfterWriteTickInfo;
282
+ } else {
283
+ this[kState] &= ~kAfterWriteTickInfo;
284
+ }
285
+ },
286
+ },
287
+
288
+ buffered: {
289
+ __proto__: null,
290
+ enumerable: false,
291
+ get() { return (this[kState] & kBuffered) !== 0 ? this[kBufferedValue] : []; },
292
+ set(value) {
293
+ this[kBufferedValue] = value;
294
+ if (value) {
295
+ this[kState] |= kBuffered;
296
+ } else {
297
+ this[kState] &= ~kBuffered;
298
+ }
299
+ },
300
+ },
301
+
302
+ });
303
+
304
+ function WritableState(options, stream, isDuplex) {
305
+ // Bit map field to store WritableState more efficiently with 1 bit per field
306
+ // instead of a V8 slot per field.
307
+ this[kState] = kSync | kConstructed | kEmitClose | kAutoDestroy;
308
+
309
+ if (options?.objectMode)
310
+ this[kState] |= kObjectMode;
311
+
312
+ if (isDuplex && options?.writableObjectMode)
313
+ this[kState] |= kObjectMode;
314
+
315
+ // The point at which write() starts returning false
316
+ // Note: 0 is a valid value, means that we always return false if
317
+ // the entire buffer is not flushed immediately on write().
318
+ this.highWaterMark = options ?
319
+ getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex) :
320
+ getDefaultHighWaterMark(false);
321
+
322
+ if (!options || options.decodeStrings !== false) this[kState] |= kDecodeStrings;
323
+
324
+ // Should close be emitted on destroy. Defaults to true.
325
+ if (options && options.emitClose === false) this[kState] &= ~kEmitClose;
326
+
327
+ // Should .destroy() be called after 'end' (and potentially 'finish').
328
+ if (options && options.autoDestroy === false) this[kState] &= ~kAutoDestroy;
329
+
330
+ // Crypto is kind of old and crusty. Historically, its default string
331
+ // encoding is 'binary' so we have to make this configurable.
332
+ // Everything else in the universe uses 'utf8', though.
333
+ const defaultEncoding = options ? options.defaultEncoding : null;
334
+ if (defaultEncoding == null || defaultEncoding === 'utf8' || defaultEncoding === 'utf-8') {
335
+ this[kState] |= kDefaultUTF8Encoding;
336
+ } else if (Buffer.isEncoding(defaultEncoding)) {
337
+ this[kState] &= ~kDefaultUTF8Encoding;
338
+ this[kDefaultEncodingValue] = defaultEncoding;
339
+ } else {
340
+ throw new ERR_UNKNOWN_ENCODING(defaultEncoding);
341
+ }
342
+
343
+ // Not an actual buffer we keep track of, but a measurement
344
+ // of how much we're waiting to get pushed to some underlying
345
+ // socket or file.
346
+ this.length = 0;
347
+
348
+ // When true all writes will be buffered until .uncork() call.
349
+ this.corked = 0;
350
+
351
+ // The callback that's passed to _write(chunk, cb).
352
+ this.onwrite = onwrite.bind(undefined, stream);
353
+
354
+ // The amount that is being written when _write is called.
355
+ this.writelen = 0;
356
+
357
+ resetBuffer(this);
358
+
359
+ // Number of pending user-supplied write callbacks
360
+ // this must be 0 before 'finish' can be emitted.
361
+ this.pendingcb = 0;
362
+ }
363
+
364
+ function resetBuffer(state) {
365
+ state[kBufferedValue] = null;
366
+ state.bufferedIndex = 0;
367
+ state[kState] |= kAllBuffers | kAllNoop;
368
+ state[kState] &= ~kBuffered;
369
+ }
370
+
371
+ WritableState.prototype.getBuffer = function getBuffer() {
372
+ return (this[kState] & kBuffered) === 0 ? [] : ArrayPrototypeSlice(this.buffered, this.bufferedIndex);
373
+ };
374
+
375
+ ObjectDefineProperty(WritableState.prototype, 'bufferedRequestCount', {
376
+ __proto__: null,
377
+ get() {
378
+ return (this[kState] & kBuffered) === 0 ? 0 : this[kBufferedValue].length - this.bufferedIndex;
379
+ },
380
+ });
381
+
382
+ WritableState.prototype[kOnConstructed] = function onConstructed(stream) {
383
+ if ((this[kState] & kWriting) === 0) {
384
+ clearBuffer(stream, this);
385
+ }
386
+
387
+ if ((this[kState] & kEnding) !== 0) {
388
+ finishMaybe(stream, this);
389
+ }
390
+ };
391
+
392
+ function Writable(options) {
393
+ if (!(this instanceof Writable))
394
+ return new Writable(options);
395
+
396
+ this._events ??= {
397
+ close: undefined,
398
+ error: undefined,
399
+ prefinish: undefined,
400
+ finish: undefined,
401
+ drain: undefined,
402
+ // Skip uncommon events...
403
+ // [destroyImpl.kConstruct]: undefined,
404
+ // [destroyImpl.kDestroy]: undefined,
405
+ };
406
+
407
+ this._writableState = new WritableState(options, this, false);
408
+
409
+ if (options) {
410
+ if (typeof options.write === 'function')
411
+ this._write = options.write;
412
+
413
+ if (typeof options.writev === 'function')
414
+ this._writev = options.writev;
415
+
416
+ if (typeof options.destroy === 'function')
417
+ this._destroy = options.destroy;
418
+
419
+ if (typeof options.final === 'function')
420
+ this._final = options.final;
421
+
422
+ if (typeof options.construct === 'function')
423
+ this._construct = options.construct;
424
+
425
+ if (options.signal)
426
+ addAbortSignal(options.signal, this);
427
+ }
428
+
429
+ Stream.call(this, options);
430
+
431
+ if (this._construct != null) {
432
+ destroyImpl.construct(this, () => {
433
+ this._writableState[kOnConstructed](this);
434
+ });
435
+ }
436
+ }
437
+
438
+ ObjectDefineProperty(Writable, SymbolHasInstance, {
439
+ __proto__: null,
440
+ value: function(object) {
441
+ if (FunctionPrototypeSymbolHasInstance(this, object)) return true;
442
+ if (this !== Writable) return false;
443
+
444
+ return object && object._writableState instanceof WritableState;
445
+ },
446
+ });
447
+
448
+ // Otherwise people can pipe Writable streams, which is just wrong.
449
+ Writable.prototype.pipe = function() {
450
+ errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
451
+ };
452
+
453
+ function _write(stream, chunk, encoding, cb) {
454
+ const state = stream._writableState;
455
+
456
+ if (cb == null || typeof cb !== 'function') {
457
+ cb = nop;
458
+ }
459
+
460
+ if (chunk === null) {
461
+ throw new ERR_STREAM_NULL_VALUES();
462
+ }
463
+
464
+ if ((state[kState] & kObjectMode) === 0) {
465
+ if (!encoding) {
466
+ encoding = (state[kState] & kDefaultUTF8Encoding) !== 0 ? 'utf8' : state.defaultEncoding;
467
+ } else if (encoding !== 'buffer' && !Buffer.isEncoding(encoding)) {
468
+ throw new ERR_UNKNOWN_ENCODING(encoding);
469
+ }
470
+
471
+ if (typeof chunk === 'string') {
472
+ if ((state[kState] & kDecodeStrings) !== 0) {
473
+ chunk = Buffer.from(chunk, encoding);
474
+ encoding = 'buffer';
475
+ }
476
+ } else if (chunk instanceof Buffer) {
477
+ encoding = 'buffer';
478
+ } else if (Stream._isArrayBufferView(chunk)) {
479
+ chunk = Stream._uint8ArrayToBuffer(chunk);
480
+ encoding = 'buffer';
481
+ } else {
482
+ throw new ERR_INVALID_ARG_TYPE(
483
+ 'chunk', ['string', 'Buffer', 'TypedArray', 'DataView'], chunk);
484
+ }
485
+ }
486
+
487
+ let err;
488
+ if ((state[kState] & kEnding) !== 0) {
489
+ err = new ERR_STREAM_WRITE_AFTER_END();
490
+ } else if ((state[kState] & kDestroyed) !== 0) {
491
+ err = new ERR_STREAM_DESTROYED('write');
492
+ }
493
+
494
+ if (err) {
495
+ process.nextTick(cb, err);
496
+ errorOrDestroy(stream, err, true);
497
+ return err;
498
+ }
499
+
500
+ state.pendingcb++;
501
+ return writeOrBuffer(stream, state, chunk, encoding, cb);
502
+ }
503
+
504
+ Writable.prototype.write = function(chunk, encoding, cb) {
505
+ if (encoding != null && typeof encoding === 'function') {
506
+ cb = encoding;
507
+ encoding = null;
508
+ }
509
+
510
+ return _write(this, chunk, encoding, cb) === true;
511
+ };
512
+
513
+ Writable.prototype.cork = function() {
514
+ const state = this._writableState;
515
+
516
+ state[kState] |= kCorked;
517
+ state.corked++;
518
+ };
519
+
520
+ Writable.prototype.uncork = function() {
521
+ const state = this._writableState;
522
+
523
+ if (state.corked) {
524
+ state.corked--;
525
+
526
+ if (!state.corked) {
527
+ state[kState] &= ~kCorked;
528
+ }
529
+
530
+ if ((state[kState] & kWriting) === 0)
531
+ clearBuffer(this, state);
532
+ }
533
+ };
534
+
535
+ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
536
+ // node::ParseEncoding() requires lower case.
537
+ if (typeof encoding === 'string')
538
+ encoding = StringPrototypeToLowerCase(encoding);
539
+ if (!Buffer.isEncoding(encoding))
540
+ throw new ERR_UNKNOWN_ENCODING(encoding);
541
+ this._writableState.defaultEncoding = encoding;
542
+ return this;
543
+ };
544
+
545
+ // If we're already writing something, then just put this
546
+ // in the queue, and wait our turn. Otherwise, call _write
547
+ // If we return false, then we need a drain event, so set that flag.
548
+ function writeOrBuffer(stream, state, chunk, encoding, callback) {
549
+ const len = (state[kState] & kObjectMode) !== 0 ? 1 : chunk.length;
550
+
551
+ state.length += len;
552
+
553
+ if ((state[kState] & (kWriting | kErrored | kCorked | kConstructed)) !== kConstructed) {
554
+ if ((state[kState] & kBuffered) === 0) {
555
+ state[kState] |= kBuffered;
556
+ state[kBufferedValue] = [];
557
+ }
558
+
559
+ state[kBufferedValue].push({ chunk, encoding, callback });
560
+ if ((state[kState] & kAllBuffers) !== 0 && encoding !== 'buffer') {
561
+ state[kState] &= ~kAllBuffers;
562
+ }
563
+ if ((state[kState] & kAllNoop) !== 0 && callback !== nop) {
564
+ state[kState] &= ~kAllNoop;
565
+ }
566
+ } else {
567
+ state.writelen = len;
568
+ if (callback !== nop) {
569
+ state.writecb = callback;
570
+ }
571
+ state[kState] |= kWriting | kSync | kExpectWriteCb;
572
+ stream._write(chunk, encoding, state.onwrite);
573
+ state[kState] &= ~kSync;
574
+ }
575
+
576
+ const ret = state.length < state.highWaterMark || state.length === 0;
577
+
578
+ if (!ret) {
579
+ state[kState] |= kNeedDrain;
580
+ }
581
+
582
+ // Return false if errored or destroyed in order to break
583
+ // any synchronous while(stream.write(data)) loops.
584
+ return ret && (state[kState] & (kDestroyed | kErrored)) === 0;
585
+ }
586
+
587
+ function doWrite(stream, state, writev, len, chunk, encoding, cb) {
588
+ state.writelen = len;
589
+ if (cb !== nop) {
590
+ state.writecb = cb;
591
+ }
592
+ state[kState] |= kWriting | kSync | kExpectWriteCb;
593
+ if ((state[kState] & kDestroyed) !== 0)
594
+ state.onwrite(new ERR_STREAM_DESTROYED('write'));
595
+ else if (writev)
596
+ stream._writev(chunk, state.onwrite);
597
+ else
598
+ stream._write(chunk, encoding, state.onwrite);
599
+ state[kState] &= ~kSync;
600
+ }
601
+
602
+ function onwriteError(stream, state, er, cb) {
603
+ --state.pendingcb;
604
+
605
+ cb(er);
606
+ // Ensure callbacks are invoked even when autoDestroy is
607
+ // not enabled. Passing `er` here doesn't make sense since
608
+ // it's related to one specific write, not to the buffered
609
+ // writes.
610
+ errorBuffer(state);
611
+ // This can emit error, but error must always follow cb.
612
+ errorOrDestroy(stream, er);
613
+ }
614
+
615
+ function onwrite(stream, er) {
616
+ const state = stream._writableState;
617
+
618
+ if ((state[kState] & kExpectWriteCb) === 0) {
619
+ errorOrDestroy(stream, new ERR_MULTIPLE_CALLBACK());
620
+ return;
621
+ }
622
+
623
+ const sync = (state[kState] & kSync) !== 0;
624
+ const cb = (state[kState] & kWriteCb) !== 0 ? state[kWriteCbValue] : nop;
625
+
626
+ state.writecb = null;
627
+ state[kState] &= ~(kWriting | kExpectWriteCb);
628
+ state.length -= state.writelen;
629
+ state.writelen = 0;
630
+
631
+ if (er) {
632
+ // Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
633
+ er.stack; // eslint-disable-line no-unused-expressions
634
+
635
+ if ((state[kState] & kErrored) === 0) {
636
+ state[kErroredValue] = er;
637
+ state[kState] |= kErrored;
638
+ }
639
+
640
+ // In case of duplex streams we need to notify the readable side of the
641
+ // error.
642
+ if (stream._readableState && !stream._readableState.errored) {
643
+ stream._readableState.errored = er;
644
+ }
645
+
646
+ if (sync) {
647
+ process.nextTick(onwriteError, stream, state, er, cb);
648
+ } else {
649
+ onwriteError(stream, state, er, cb);
650
+ }
651
+ } else {
652
+ if ((state[kState] & kBuffered) !== 0) {
653
+ clearBuffer(stream, state);
654
+ }
655
+
656
+ if (sync) {
657
+ const needDrain = (state[kState] & kNeedDrain) !== 0 && state.length === 0;
658
+ const needTick = needDrain || (state[kState] & kDestroyed !== 0) || cb !== nop;
659
+
660
+ // It is a common case that the callback passed to .write() is always
661
+ // the same. In that case, we do not schedule a new nextTick(), but
662
+ // rather just increase a counter, to improve performance and avoid
663
+ // memory allocations.
664
+ if (cb === nop) {
665
+ if ((state[kState] & kAfterWritePending) === 0 && needTick) {
666
+ process.nextTick(afterWrite, stream, state, 1, cb);
667
+ state[kState] |= kAfterWritePending;
668
+ } else {
669
+ state.pendingcb--;
670
+ if ((state[kState] & kEnding) !== 0) {
671
+ finishMaybe(stream, state, true);
672
+ }
673
+ }
674
+ } else if ((state[kState] & kAfterWriteTickInfo) !== 0 &&
675
+ state[kAfterWriteTickInfoValue].cb === cb) {
676
+ state[kAfterWriteTickInfoValue].count++;
677
+ } else if (needTick) {
678
+ state[kAfterWriteTickInfoValue] = { count: 1, cb, stream, state };
679
+ process.nextTick(afterWriteTick, state[kAfterWriteTickInfoValue]);
680
+ state[kState] |= (kAfterWritePending | kAfterWriteTickInfo);
681
+ } else {
682
+ state.pendingcb--;
683
+ if ((state[kState] & kEnding) !== 0) {
684
+ finishMaybe(stream, state, true);
685
+ }
686
+ }
687
+ } else {
688
+ afterWrite(stream, state, 1, cb);
689
+ }
690
+ }
691
+ }
692
+
693
+ function afterWriteTick({ stream, state, count, cb }) {
694
+ state[kState] &= ~kAfterWriteTickInfo;
695
+ state[kAfterWriteTickInfoValue] = null;
696
+ return afterWrite(stream, state, count, cb);
697
+ }
698
+
699
+ function afterWrite(stream, state, count, cb) {
700
+ state[kState] &= ~kAfterWritePending;
701
+
702
+ const needDrain = (state[kState] & (kEnding | kNeedDrain | kDestroyed)) === kNeedDrain && state.length === 0;
703
+ if (needDrain) {
704
+ state[kState] &= ~kNeedDrain;
705
+ stream.emit('drain');
706
+ }
707
+
708
+ while (count-- > 0) {
709
+ state.pendingcb--;
710
+ cb(null);
711
+ }
712
+
713
+ if ((state[kState] & kDestroyed) !== 0) {
714
+ errorBuffer(state);
715
+ }
716
+
717
+ if ((state[kState] & kEnding) !== 0) {
718
+ finishMaybe(stream, state, true);
719
+ }
720
+ }
721
+
722
+ // If there's something in the buffer waiting, then invoke callbacks.
723
+ function errorBuffer(state) {
724
+ if ((state[kState] & kWriting) !== 0) {
725
+ return;
726
+ }
727
+
728
+ if ((state[kState] & kBuffered) !== 0) {
729
+ for (let n = state.bufferedIndex; n < state.buffered.length; ++n) {
730
+ const { chunk, callback } = state[kBufferedValue][n];
731
+ const len = (state[kState] & kObjectMode) !== 0 ? 1 : chunk.length;
732
+ state.length -= len;
733
+ callback(state.errored ?? new ERR_STREAM_DESTROYED('write'));
734
+ }
735
+ }
736
+
737
+
738
+ callFinishedCallbacks(state, state.errored ?? new ERR_STREAM_DESTROYED('end'));
739
+
740
+ resetBuffer(state);
741
+ }
742
+
743
+ // If there's something in the buffer waiting, then process it.
744
+ function clearBuffer(stream, state) {
745
+ if ((state[kState] & (kDestroyed | kBufferProcessing | kCorked | kBuffered | kConstructed)) !==
746
+ (kBuffered | kConstructed)) {
747
+ return;
748
+ }
749
+
750
+ const objectMode = (state[kState] & kObjectMode) !== 0;
751
+ const { [kBufferedValue]: buffered, bufferedIndex } = state;
752
+ const bufferedLength = buffered.length - bufferedIndex;
753
+
754
+ if (!bufferedLength) {
755
+ return;
756
+ }
757
+
758
+ let i = bufferedIndex;
759
+
760
+ state[kState] |= kBufferProcessing;
761
+ if (bufferedLength > 1 && stream._writev) {
762
+ state.pendingcb -= bufferedLength - 1;
763
+
764
+ const callback = (state[kState] & kAllNoop) !== 0 ? nop : (err) => {
765
+ for (let n = i; n < buffered.length; ++n) {
766
+ buffered[n].callback(err);
767
+ }
768
+ };
769
+ // Make a copy of `buffered` if it's going to be used by `callback` above,
770
+ // since `doWrite` will mutate the array.
771
+ const chunks = (state[kState] & kAllNoop) !== 0 && i === 0 ?
772
+ buffered : ArrayPrototypeSlice(buffered, i);
773
+ chunks.allBuffers = (state[kState] & kAllBuffers) !== 0;
774
+
775
+ doWrite(stream, state, true, state.length, chunks, '', callback);
776
+
777
+ resetBuffer(state);
778
+ } else {
779
+ do {
780
+ const { chunk, encoding, callback } = buffered[i];
781
+ buffered[i++] = null;
782
+ const len = objectMode ? 1 : chunk.length;
783
+ doWrite(stream, state, false, len, chunk, encoding, callback);
784
+ } while (i < buffered.length && (state[kState] & kWriting) === 0);
785
+
786
+ if (i === buffered.length) {
787
+ resetBuffer(state);
788
+ } else if (i > 256) {
789
+ buffered.splice(0, i);
790
+ state.bufferedIndex = 0;
791
+ } else {
792
+ state.bufferedIndex = i;
793
+ }
794
+ }
795
+ state[kState] &= ~kBufferProcessing;
796
+ }
797
+
798
+ Writable.prototype._write = function(chunk, encoding, cb) {
799
+ if (this._writev) {
800
+ this._writev([{ chunk, encoding }], cb);
801
+ } else {
802
+ throw new ERR_METHOD_NOT_IMPLEMENTED('_write()');
803
+ }
804
+ };
805
+
806
+ Writable.prototype._writev = null;
807
+
808
+ Writable.prototype.end = function(chunk, encoding, cb) {
809
+ const state = this._writableState;
810
+
811
+ if (typeof chunk === 'function') {
812
+ cb = chunk;
813
+ chunk = null;
814
+ encoding = null;
815
+ } else if (typeof encoding === 'function') {
816
+ cb = encoding;
817
+ encoding = null;
818
+ }
819
+
820
+ let err;
821
+
822
+ if (chunk != null) {
823
+ const ret = _write(this, chunk, encoding);
824
+ if (ret instanceof Error) {
825
+ err = ret;
826
+ }
827
+ }
828
+
829
+ // .end() fully uncorks.
830
+ if ((state[kState] & kCorked) !== 0) {
831
+ state.corked = 1;
832
+ this.uncork();
833
+ }
834
+
835
+ if (err) {
836
+ // Do nothing...
837
+ } else if ((state[kState] & (kEnding | kErrored)) === 0) {
838
+ // This is forgiving in terms of unnecessary calls to end() and can hide
839
+ // logic errors. However, usually such errors are harmless and causing a
840
+ // hard error can be disproportionately destructive. It is not always
841
+ // trivial for the user to determine whether end() needs to be called
842
+ // or not.
843
+
844
+ state[kState] |= kEnding;
845
+ finishMaybe(this, state, true);
846
+ state[kState] |= kEnded;
847
+ } else if ((state[kState] & kFinished) !== 0) {
848
+ err = new ERR_STREAM_ALREADY_FINISHED('end');
849
+ } else if ((state[kState] & kDestroyed) !== 0) {
850
+ err = new ERR_STREAM_DESTROYED('end');
851
+ }
852
+
853
+ if (typeof cb === 'function') {
854
+ if (err) {
855
+ process.nextTick(cb, err);
856
+ } else if ((state[kState] & kErrored) !== 0) {
857
+ process.nextTick(cb, state[kErroredValue]);
858
+ } else if ((state[kState] & kFinished) !== 0) {
859
+ process.nextTick(cb, null);
860
+ } else {
861
+ state[kState] |= kOnFinished;
862
+ state[kOnFinishedValue] ??= [];
863
+ state[kOnFinishedValue].push(cb);
864
+ }
865
+ }
866
+
867
+ return this;
868
+ };
869
+
870
+ function needFinish(state) {
871
+ return (
872
+ // State is ended && constructed but not destroyed, finished, writing, errorEmitted or closedEmitted
873
+ (state[kState] & (
874
+ kEnding |
875
+ kDestroyed |
876
+ kConstructed |
877
+ kFinished |
878
+ kWriting |
879
+ kErrorEmitted |
880
+ kCloseEmitted |
881
+ kErrored |
882
+ kBuffered
883
+ )) === (kEnding | kConstructed) && state.length === 0);
884
+ }
885
+
886
+ function onFinish(stream, state, err) {
887
+ if ((state[kState] & kPrefinished) !== 0) {
888
+ errorOrDestroy(stream, err ?? new ERR_MULTIPLE_CALLBACK());
889
+ return;
890
+ }
891
+ state.pendingcb--;
892
+ if (err) {
893
+ callFinishedCallbacks(state, err);
894
+ errorOrDestroy(stream, err, (state[kState] & kSync) !== 0);
895
+ } else if (needFinish(state)) {
896
+ state[kState] |= kPrefinished;
897
+ stream.emit('prefinish');
898
+ // Backwards compat. Don't check state.sync here.
899
+ // Some streams assume 'finish' will be emitted
900
+ // asynchronously relative to _final callback.
901
+ state.pendingcb++;
902
+ process.nextTick(finish, stream, state);
903
+ }
904
+ }
905
+
906
+ function prefinish(stream, state) {
907
+ if ((state[kState] & (kPrefinished | kFinalCalled)) !== 0) {
908
+ return;
909
+ }
910
+
911
+ if (typeof stream._final === 'function' && (state[kState] & kDestroyed) === 0) {
912
+ state[kState] |= kFinalCalled | kSync;
913
+ state.pendingcb++;
914
+
915
+ try {
916
+ stream._final((err) => onFinish(stream, state, err));
917
+ } catch (err) {
918
+ onFinish(stream, state, err);
919
+ }
920
+
921
+ state[kState] &= ~kSync;
922
+ } else {
923
+ state[kState] |= kFinalCalled | kPrefinished;
924
+ stream.emit('prefinish');
925
+ }
926
+ }
927
+
928
+ function finishMaybe(stream, state, sync) {
929
+ if (needFinish(state)) {
930
+ prefinish(stream, state);
931
+ if (state.pendingcb === 0) {
932
+ if (sync) {
933
+ state.pendingcb++;
934
+ process.nextTick((stream, state) => {
935
+ if (needFinish(state)) {
936
+ finish(stream, state);
937
+ } else {
938
+ state.pendingcb--;
939
+ }
940
+ }, stream, state);
941
+ } else if (needFinish(state)) {
942
+ state.pendingcb++;
943
+ finish(stream, state);
944
+ }
945
+ }
946
+ }
947
+ }
948
+
949
+ function finish(stream, state) {
950
+ state.pendingcb--;
951
+ state[kState] |= kFinished;
952
+
953
+ callFinishedCallbacks(state, null);
954
+
955
+ stream.emit('finish');
956
+
957
+ if ((state[kState] & kAutoDestroy) !== 0) {
958
+ // In case of duplex streams we need a way to detect
959
+ // if the readable side is ready for autoDestroy as well.
960
+ const rState = stream._readableState;
961
+ const autoDestroy = !rState || (
962
+ rState.autoDestroy &&
963
+ // We don't expect the readable to ever 'end'
964
+ // if readable is explicitly set to false.
965
+ (rState.endEmitted || rState.readable === false)
966
+ );
967
+ if (autoDestroy) {
968
+ stream.destroy();
969
+ }
970
+ }
971
+ }
972
+
973
+ function callFinishedCallbacks(state, err) {
974
+ if ((state[kState] & kOnFinished) === 0) {
975
+ return;
976
+ }
977
+
978
+ const onfinishCallbacks = state[kOnFinishedValue];
979
+ state[kOnFinishedValue] = null;
980
+ state[kState] &= ~kOnFinished;
981
+ for (let i = 0; i < onfinishCallbacks.length; i++) {
982
+ onfinishCallbacks[i](err);
983
+ }
984
+ }
985
+
986
+ ObjectDefineProperties(Writable.prototype, {
987
+ closed: {
988
+ __proto__: null,
989
+ get() {
990
+ return this._writableState ? (this._writableState[kState] & kClosed) !== 0 : false;
991
+ },
992
+ },
993
+
994
+ destroyed: {
995
+ __proto__: null,
996
+ get() {
997
+ return this._writableState ? (this._writableState[kState] & kDestroyed) !== 0 : false;
998
+ },
999
+ set(value) {
1000
+ // Backward compatibility, the user is explicitly managing destroyed.
1001
+ if (!this._writableState) return;
1002
+
1003
+ if (value) this._writableState[kState] |= kDestroyed;
1004
+ else this._writableState[kState] &= ~kDestroyed;
1005
+ },
1006
+ },
1007
+
1008
+ writable: {
1009
+ __proto__: null,
1010
+ get() {
1011
+ const w = this._writableState;
1012
+ // w.writable === false means that this is part of a Duplex stream
1013
+ // where the writable side was disabled upon construction.
1014
+ // Compat. The user might manually disable writable side through
1015
+ // deprecated setter.
1016
+ return !!w && w.writable !== false &&
1017
+ (w[kState] & (kEnding | kEnded | kDestroyed | kErrored)) === 0;
1018
+ },
1019
+ set(val) {
1020
+ // Backwards compatible.
1021
+ if (this._writableState) {
1022
+ this._writableState.writable = !!val;
1023
+ }
1024
+ },
1025
+ },
1026
+
1027
+ writableFinished: {
1028
+ __proto__: null,
1029
+ get() {
1030
+ const state = this._writableState;
1031
+ return state ? (state[kState] & kFinished) !== 0 : false;
1032
+ },
1033
+ },
1034
+
1035
+ writableObjectMode: {
1036
+ __proto__: null,
1037
+ get() {
1038
+ const state = this._writableState;
1039
+ return state ? (state[kState] & kObjectMode) !== 0 : false;
1040
+ },
1041
+ },
1042
+
1043
+ writableBuffer: {
1044
+ __proto__: null,
1045
+ get() {
1046
+ const state = this._writableState;
1047
+ return state && state.getBuffer();
1048
+ },
1049
+ },
1050
+
1051
+ writableEnded: {
1052
+ __proto__: null,
1053
+ get() {
1054
+ const state = this._writableState;
1055
+ return state ? (state[kState] & kEnding) !== 0 : false;
1056
+ },
1057
+ },
1058
+
1059
+ writableNeedDrain: {
1060
+ __proto__: null,
1061
+ get() {
1062
+ const state = this._writableState;
1063
+ return state ? (state[kState] & (kDestroyed | kEnding | kNeedDrain)) === kNeedDrain : false;
1064
+ },
1065
+ },
1066
+
1067
+ writableHighWaterMark: {
1068
+ __proto__: null,
1069
+ get() {
1070
+ const state = this._writableState;
1071
+ return state?.highWaterMark;
1072
+ },
1073
+ },
1074
+
1075
+ writableCorked: {
1076
+ __proto__: null,
1077
+ get() {
1078
+ const state = this._writableState;
1079
+ return state ? state.corked : 0;
1080
+ },
1081
+ },
1082
+
1083
+ writableLength: {
1084
+ __proto__: null,
1085
+ get() {
1086
+ const state = this._writableState;
1087
+ return state?.length;
1088
+ },
1089
+ },
1090
+
1091
+ errored: {
1092
+ __proto__: null,
1093
+ enumerable: false,
1094
+ get() {
1095
+ const state = this._writableState;
1096
+ return state ? state.errored : null;
1097
+ },
1098
+ },
1099
+
1100
+ writableAborted: {
1101
+ __proto__: null,
1102
+ get: function() {
1103
+ const state = this._writableState;
1104
+ return (
1105
+ (state[kState] & (kHasWritable | kWritable)) !== kHasWritable &&
1106
+ (state[kState] & (kDestroyed | kErrored)) !== 0 &&
1107
+ (state[kState] & kFinished) === 0
1108
+ );
1109
+ },
1110
+ },
1111
+ });
1112
+
1113
+ const destroy = destroyImpl.destroy;
1114
+ Writable.prototype.destroy = function(err, cb) {
1115
+ const state = this._writableState;
1116
+
1117
+ // Invoke pending callbacks.
1118
+ if ((state[kState] & (kBuffered | kOnFinished)) !== 0 && (state[kState] & kDestroyed) === 0) {
1119
+ process.nextTick(errorBuffer, state);
1120
+ }
1121
+
1122
+ destroy.call(this, err, cb);
1123
+ return this;
1124
+ };
1125
+
1126
+ Writable.prototype._undestroy = destroyImpl.undestroy;
1127
+ Writable.prototype._destroy = function(err, cb) {
1128
+ cb(err);
1129
+ };
1130
+
1131
+ Writable.prototype[EE.captureRejectionSymbol] = function(err) {
1132
+ this.destroy(err);
1133
+ };
1134
+
1135
+ let webStreamsAdapters;
1136
+
1137
+ // Lazy to avoid circular references
1138
+ function lazyWebStreams() {
1139
+ if (webStreamsAdapters === undefined)
1140
+ webStreamsAdapters = require('internal/webstreams/adapters');
1141
+ return webStreamsAdapters;
1142
+ }
1143
+
1144
+ Writable.fromWeb = function(writableStream, options) {
1145
+ return lazyWebStreams().newStreamWritableFromWritableStream(
1146
+ writableStream,
1147
+ options);
1148
+ };
1149
+
1150
+ Writable.toWeb = function(streamWritable) {
1151
+ return lazyWebStreams().newWritableStreamFromStreamWritable(streamWritable);
1152
+ };
1153
+
1154
+ Writable.prototype[SymbolAsyncDispose] = async function() {
1155
+ let error;
1156
+ if (!this.destroyed) {
1157
+ error = this.writableFinished ? null : new AbortError();
1158
+ this.destroy(error);
1159
+ }
1160
+ await new Promise((resolve, reject) =>
1161
+ eos(this, (err) => (err && err.name !== 'AbortError' ? reject(err) : resolve(null))),
1162
+ );
1163
+ };