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