@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,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `internalBinding('process_wrap')`: one run of the engine, seen as libuv sees
|
|
3
|
+
* a child process.
|
|
4
|
+
*
|
|
5
|
+
* libuv's `uv_spawn` starts a program with its descriptors already wired and
|
|
6
|
+
* answers through `onexit` when it ends; `uv_process_kill` ends it. That is
|
|
7
|
+
* the whole of what `internal/child_process.js` asks of a process, and it is
|
|
8
|
+
* the whole of this file. Nothing here knows about `ChildProcess`, `stdio`
|
|
9
|
+
* streams, `exec`'s buffering, `fork`'s IPC protocol or what a signal means:
|
|
10
|
+
* those are Node's own and are vendored.
|
|
11
|
+
*
|
|
12
|
+
* What the engine already did for a spawned command stays and becomes this
|
|
13
|
+
* file's implementation, through the one door the engine's process model
|
|
14
|
+
* installs below: the routing of a command to the engine's `node`, to a
|
|
15
|
+
* program the page registered, to a WALI pack, or to the shell. A `pipe`
|
|
16
|
+
* stdio entry is paired with an end of its own here, so the child's writes to
|
|
17
|
+
* fd 1 are reads on the parent's handle and the parent's writes to the stdin
|
|
18
|
+
* handle are the child's fd 0 -- which is what a `uv_stdio_container_t` with
|
|
19
|
+
* `UV_CREATE_PIPE` is.
|
|
20
|
+
*/
|
|
21
|
+
import {
|
|
22
|
+
LibuvStreamWrap, WriteWrap, streamBaseState, kReadBytesOrError, kArrayBufferOffset,
|
|
23
|
+
} from './stream_wrap';
|
|
24
|
+
import { Pipe, constants as pipeConstants } from './pipe_wrap';
|
|
25
|
+
import { UV_ENOENT, UV_ESRCH } from './uv';
|
|
26
|
+
import {
|
|
27
|
+
registerHandle, refHandle, unrefHandle, handleHasRef, releaseHandle, __adoptHandle,
|
|
28
|
+
type OwnedHandle,
|
|
29
|
+
} from './handles';
|
|
30
|
+
import type { ProcessToken } from '../../process-tokens';
|
|
31
|
+
|
|
32
|
+
/** One entry of Node's `options.stdio`, as `getValidStdio` builds it. */
|
|
33
|
+
export interface StdioEntry {
|
|
34
|
+
type: 'pipe' | 'overlapped' | 'ignore' | 'inherit' | 'fd' | 'wrap';
|
|
35
|
+
handle?: LibuvStreamWrap;
|
|
36
|
+
fd?: number;
|
|
37
|
+
ipc?: boolean;
|
|
38
|
+
readable?: boolean;
|
|
39
|
+
writable?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** What `ChildProcess.prototype.spawn` hands `Process.spawn`. */
|
|
43
|
+
export interface ProcessSpawnOptions {
|
|
44
|
+
file: string;
|
|
45
|
+
args?: string[];
|
|
46
|
+
cwd?: string;
|
|
47
|
+
envPairs?: string[];
|
|
48
|
+
stdio: StdioEntry[];
|
|
49
|
+
detached?: boolean;
|
|
50
|
+
windowsHide?: boolean;
|
|
51
|
+
uid?: number;
|
|
52
|
+
gid?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The channel a forked child is started with, at the descriptor it is told. */
|
|
56
|
+
export interface RunChannel {
|
|
57
|
+
/** The number the child's `NODE_CHANNEL_FD` names. */
|
|
58
|
+
fd: number;
|
|
59
|
+
/** The child's end of the channel, which its own `Pipe.open(fd)` finds. */
|
|
60
|
+
pipe: Pipe;
|
|
61
|
+
/** `json` or `advanced`, as `NODE_CHANNEL_SERIALIZATION_MODE` says. */
|
|
62
|
+
serialization: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** What the binding asks the engine's process model to run. */
|
|
66
|
+
export interface RunRequest {
|
|
67
|
+
/** The program, as the caller named it: a path, a name, or the shell. */
|
|
68
|
+
file: string;
|
|
69
|
+
/** argv, the file first, as Node builds it. */
|
|
70
|
+
args: string[];
|
|
71
|
+
cwd?: string;
|
|
72
|
+
env: Record<string, string>;
|
|
73
|
+
detached: boolean;
|
|
74
|
+
/** Where the child's fd 1 goes; null where nothing reads it. */
|
|
75
|
+
stdout: ((text: string) => void) | null;
|
|
76
|
+
/** Where the child's fd 2 goes; null where nothing reads it. */
|
|
77
|
+
stderr: ((text: string) => void) | null;
|
|
78
|
+
/**
|
|
79
|
+
* True when fd 2 is a pipe the parent holds. A run that ends uncaught or
|
|
80
|
+
* with a nonzero `process.exit` on that pipe writes one receipt to the
|
|
81
|
+
* host realm's console, because the parent may never read the pipe — the
|
|
82
|
+
* tab's extension host dies this way, its stderr going into `@vscode/spdlog`
|
|
83
|
+
* which does not load. Inherit and the host's own stdio are false.
|
|
84
|
+
*/
|
|
85
|
+
stderrIsPipe: boolean;
|
|
86
|
+
/** True when the child's fd 0 is a pipe whose writer has not closed. */
|
|
87
|
+
stdinIsPipe: boolean;
|
|
88
|
+
/** The IPC channel the child is started with, where it has one. */
|
|
89
|
+
channel?: RunChannel;
|
|
90
|
+
/** Called once, when the run has ended. */
|
|
91
|
+
exit(code: number, signal: string | null): void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** One run in flight, as the engine's process model hands it back. */
|
|
95
|
+
export interface StartedRun {
|
|
96
|
+
/** The run's own name, so a handle it holds is counted as its own. */
|
|
97
|
+
token: ProcessToken | null;
|
|
98
|
+
/** The run's process number, which is what its own `process.pid` reports. */
|
|
99
|
+
pid?: number;
|
|
100
|
+
/** libuv's `uv_process_kill`: 0, or `UV_ESRCH` for a run already over. */
|
|
101
|
+
kill(signal: string): number;
|
|
102
|
+
/** Bytes the parent wrote to the child's fd 0. */
|
|
103
|
+
writeStdin(bytes: Uint8Array): void;
|
|
104
|
+
/** The parent closed the child's fd 0. */
|
|
105
|
+
endStdin(): void;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The engine's process model, installed by `initChildProcess`. Until it is
|
|
110
|
+
* there is no engine to run anything, and a spawn answers `ENOENT`, which is
|
|
111
|
+
* what a machine carrying no such program answers.
|
|
112
|
+
*/
|
|
113
|
+
export interface ProcessRunner {
|
|
114
|
+
/** Whether the engine has a program under this name at all. */
|
|
115
|
+
resolves(request: RunRequest): boolean;
|
|
116
|
+
start(request: RunRequest): StartedRun;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let runner: ProcessRunner | null = null;
|
|
120
|
+
|
|
121
|
+
/** The engine's process model takes this door once, when the VFS is known. */
|
|
122
|
+
export function setProcessRunner(next: ProcessRunner): void {
|
|
123
|
+
runner = next;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let nextPid = 1001 + Math.floor(Math.random() * 30000);
|
|
127
|
+
let nextAsyncId = 1;
|
|
128
|
+
|
|
129
|
+
/** `envPairs` is `KEY=value` strings; the engine's shell takes a record. */
|
|
130
|
+
function environmentOf(envPairs: string[] | undefined): Record<string, string> {
|
|
131
|
+
const env: Record<string, string> = {};
|
|
132
|
+
for (const pair of envPairs ?? []) {
|
|
133
|
+
const at = pair.indexOf('=');
|
|
134
|
+
if (at <= 0) continue;
|
|
135
|
+
env[pair.slice(0, at)] = pair.slice(at + 1);
|
|
136
|
+
}
|
|
137
|
+
return env;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** A signal named by number, as the name libuv reports for it. */
|
|
141
|
+
const signalNames: Record<number, string> = {
|
|
142
|
+
1: 'SIGHUP', 2: 'SIGINT', 3: 'SIGQUIT', 6: 'SIGABRT', 9: 'SIGKILL',
|
|
143
|
+
10: 'SIGUSR1', 12: 'SIGUSR2', 13: 'SIGPIPE', 14: 'SIGALRM', 15: 'SIGTERM',
|
|
144
|
+
};
|
|
145
|
+
function signalNameOf(signal: number | string): string {
|
|
146
|
+
if (typeof signal === 'string') return signal;
|
|
147
|
+
return signalNames[signal] ?? 'SIGTERM';
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The directory a child starts in when the caller named none: its parent's.
|
|
152
|
+
* `execve` keeps the calling process's working directory, and Node's `fork`
|
|
153
|
+
* passes no `cwd` at all -- `fork('./child.js')` from a program running in
|
|
154
|
+
* `/work` means `/work/child.js`, and resolved against the engine's shell's
|
|
155
|
+
* own root it meant `/child.js` and a child that exited 1.
|
|
156
|
+
*/
|
|
157
|
+
function spawningDirectory(): string | undefined {
|
|
158
|
+
const realm = (globalThis as unknown as { process?: { cwd?: () => string } }).process;
|
|
159
|
+
if (typeof realm?.cwd !== 'function') return undefined;
|
|
160
|
+
try { return realm.cwd(); } catch { return undefined; }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Where an `inherit` entry's bytes go: the spawning program's own stream. */
|
|
164
|
+
function inheritedWriter(fd: number): ((text: string) => void) | null {
|
|
165
|
+
if (fd !== 1 && fd !== 2) return null;
|
|
166
|
+
const realm = (globalThis as unknown as {
|
|
167
|
+
process?: { stdout?: { write(text: string): unknown }; stderr?: { write(text: string): unknown } };
|
|
168
|
+
}).process;
|
|
169
|
+
const stream = fd === 1 ? realm?.stdout : realm?.stderr;
|
|
170
|
+
if (!stream || typeof stream.write !== 'function') return null;
|
|
171
|
+
return (text: string) => {
|
|
172
|
+
try { stream.write(text); } catch { /* a stream that refuses still lets the child run */ }
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* libuv's `uv_process_t`.
|
|
178
|
+
*
|
|
179
|
+
* The handle registers with the run that made it, as every handle here does,
|
|
180
|
+
* so a parent waiting on a child is not idle: Node's loop holds a process
|
|
181
|
+
* handle exactly that way, and `unref()` is how a program gives it up.
|
|
182
|
+
*/
|
|
183
|
+
export class Process implements OwnedHandle {
|
|
184
|
+
/** Set by `internal/child_process.js`; the only way an end is reported. */
|
|
185
|
+
onexit: ((exitCode: number, signalCode: string | null) => void) | null = null;
|
|
186
|
+
/**
|
|
187
|
+
* A process that never started has no pid, and `ChildProcess` copies this
|
|
188
|
+
* one straight onto itself: a child whose `spawn` answered `ENOENT` reports
|
|
189
|
+
* `pid === undefined`, as Node's does, rather than a number naming nothing.
|
|
190
|
+
*/
|
|
191
|
+
pid: number | undefined = undefined;
|
|
192
|
+
|
|
193
|
+
private run: StartedRun | null = null;
|
|
194
|
+
private ended = false;
|
|
195
|
+
private closed = false;
|
|
196
|
+
/** The stdio entries this run was started with, and their far ends. */
|
|
197
|
+
private stdio: StdioEntry[] = [];
|
|
198
|
+
private readonly asyncId = nextAsyncId++;
|
|
199
|
+
|
|
200
|
+
constructor() {
|
|
201
|
+
registerHandle(this);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
getAsyncId(): number {
|
|
205
|
+
return this.asyncId;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
ref(): void {
|
|
209
|
+
refHandle(this);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
unref(): void {
|
|
213
|
+
unrefHandle(this);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
hasRef(): boolean {
|
|
217
|
+
return handleHasRef(this);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* libuv's `uv_spawn`. Answers 0 for a run that started and a `UV_*` code for
|
|
222
|
+
* one that could not, which is what `ChildProcess.prototype.spawn` turns
|
|
223
|
+
* into an `error` event or a throw.
|
|
224
|
+
*/
|
|
225
|
+
spawn(options: ProcessSpawnOptions): number {
|
|
226
|
+
if (!runner) return UV_ENOENT;
|
|
227
|
+
const env = environmentOf(options.envPairs);
|
|
228
|
+
this.stdio = options.stdio ?? [];
|
|
229
|
+
|
|
230
|
+
const request: RunRequest = {
|
|
231
|
+
file: options.file,
|
|
232
|
+
args: options.args ?? [options.file],
|
|
233
|
+
cwd: options.cwd ?? spawningDirectory(),
|
|
234
|
+
env,
|
|
235
|
+
detached: options.detached === true,
|
|
236
|
+
stdout: null,
|
|
237
|
+
stderr: null,
|
|
238
|
+
stderrIsPipe: false,
|
|
239
|
+
stdinIsPipe: false,
|
|
240
|
+
exit: (code, signal) => { this.reportExit(code, signal); },
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
let stdinFar: Pipe | null = null;
|
|
244
|
+
for (let index = 0; index < this.stdio.length; index += 1) {
|
|
245
|
+
const entry = this.stdio[index];
|
|
246
|
+
if (!entry) continue;
|
|
247
|
+
const far = this.pairFarEnd(entry);
|
|
248
|
+
if (entry.ipc) {
|
|
249
|
+
if (far) {
|
|
250
|
+
request.channel = {
|
|
251
|
+
fd: index,
|
|
252
|
+
pipe: far,
|
|
253
|
+
serialization: env.NODE_CHANNEL_SERIALIZATION_MODE || 'json',
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (index === 0) {
|
|
259
|
+
stdinFar = far;
|
|
260
|
+
request.stdinIsPipe = far !== null;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (index !== 1 && index !== 2) continue;
|
|
264
|
+
if (far) {
|
|
265
|
+
const to = index;
|
|
266
|
+
const write = (text: string): void => { this.toPipe(to, text); };
|
|
267
|
+
if (index === 1) request.stdout = write;
|
|
268
|
+
else {
|
|
269
|
+
request.stderr = write;
|
|
270
|
+
request.stderrIsPipe = true;
|
|
271
|
+
}
|
|
272
|
+
} else if (entry.type === 'inherit' || entry.type === 'fd') {
|
|
273
|
+
const inherited = inheritedWriter(entry.fd ?? index);
|
|
274
|
+
if (index === 1) request.stdout = inherited;
|
|
275
|
+
else request.stderr = inherited;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (!runner.resolves(request)) {
|
|
280
|
+
this.closeFarEnds();
|
|
281
|
+
return UV_ENOENT;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
this.run = runner.start(request);
|
|
285
|
+
// The number the parent reads off the handle is the child's own
|
|
286
|
+
// `process.pid`, as it is in Node; a runner that names none is given one.
|
|
287
|
+
this.pid = this.run.pid ?? nextPid++;
|
|
288
|
+
if (stdinFar) this.readStdinFrom(stdinFar);
|
|
289
|
+
return 0;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* libuv's `uv_process_kill`: the run ends, or it was over already. Signal 0
|
|
294
|
+
* is the question "is it still there?", which kills nothing and answers 0
|
|
295
|
+
* for a run in flight and `ESRCH` for one that has ended.
|
|
296
|
+
*/
|
|
297
|
+
kill(signal: number | string): number {
|
|
298
|
+
if (this.ended || !this.run) return UV_ESRCH;
|
|
299
|
+
if (signal === 0) return 0;
|
|
300
|
+
return this.run.kill(signalNameOf(signal));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
close(callback?: () => void): void {
|
|
304
|
+
if (!this.closed) {
|
|
305
|
+
this.closed = true;
|
|
306
|
+
releaseHandle(this);
|
|
307
|
+
}
|
|
308
|
+
if (callback) queueMicrotask(callback);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* The other half of a `pipe` entry: the end the child holds. It belongs to
|
|
313
|
+
* no run -- the parent holds the handle Node gave it and the child holds the
|
|
314
|
+
* one it opens; this is the wire between them.
|
|
315
|
+
*/
|
|
316
|
+
private pairFarEnd(entry: StdioEntry): Pipe | null {
|
|
317
|
+
if (entry.type !== 'pipe' && entry.type !== 'overlapped') return null;
|
|
318
|
+
if (!entry.handle) return null;
|
|
319
|
+
const far = new Pipe(entry.ipc ? pipeConstants.IPC : pipeConstants.SOCKET);
|
|
320
|
+
__adoptHandle(far, null);
|
|
321
|
+
LibuvStreamWrap.pair(entry.handle, far);
|
|
322
|
+
return far;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** The far end of fd `index`, whoever holds it now. */
|
|
326
|
+
private farEndAt(index: number): LibuvStreamWrap | null {
|
|
327
|
+
return this.stdio[index]?.handle?.peer ?? null;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private closeFarEnds(): void {
|
|
331
|
+
for (let index = 0; index < this.stdio.length; index += 1) {
|
|
332
|
+
const far = this.farEndAt(index);
|
|
333
|
+
if (!far) continue;
|
|
334
|
+
try { far.close(); } catch { /* an end already closed is already given up */ }
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** The child wrote to fd `index`; the parent's handle reads it. */
|
|
339
|
+
private toPipe(index: number, text: string): void {
|
|
340
|
+
const far = this.farEndAt(index);
|
|
341
|
+
if (!far || far.closed) return;
|
|
342
|
+
far.writeUtf8String(new WriteWrap(), text);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** Bytes the parent writes reach the child's fd 0; the parent's EOF ends it. */
|
|
346
|
+
private readStdinFrom(far: Pipe): void {
|
|
347
|
+
far.onread = (arrayBuffer: ArrayBuffer | null): void => {
|
|
348
|
+
const length = streamBaseState[kReadBytesOrError];
|
|
349
|
+
if (length <= 0 || arrayBuffer === null) { this.run?.endStdin(); return; }
|
|
350
|
+
this.run?.writeStdin(new Uint8Array(arrayBuffer, streamBaseState[kArrayBufferOffset], length).slice());
|
|
351
|
+
};
|
|
352
|
+
far.readStart();
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* The run has ended. The child's ends of the pairings close, so the parent's
|
|
357
|
+
* streams read EOF as they do when a real child's descriptors go, and
|
|
358
|
+
* `onexit` fires once, after them: Node's `flushStdio` runs on the tick
|
|
359
|
+
* after `onexit` and must find the bytes already delivered.
|
|
360
|
+
*/
|
|
361
|
+
private reportExit(code: number, signal: string | null): void {
|
|
362
|
+
if (this.ended) return;
|
|
363
|
+
this.ended = true;
|
|
364
|
+
this.closeFarEnds();
|
|
365
|
+
const report = this.onexit;
|
|
366
|
+
this.run = null;
|
|
367
|
+
if (report) report(code, signal);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export default { Process };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `internalBinding('spawn_sync')`: a child run to its end before the call
|
|
3
|
+
* returns.
|
|
4
|
+
*
|
|
5
|
+
* libuv's `uv_spawn_sync` answers one record -- a status, a signal, the bytes
|
|
6
|
+
* each descriptor produced, and an error where the child never started -- and
|
|
7
|
+
* `internal/child_process.js`'s `spawnSync` is four lines over it. That
|
|
8
|
+
* record is what this file answers, over `src/shims/sync-child.ts`: a thread
|
|
9
|
+
* of its own running a second engine, with every filesystem call crossing
|
|
10
|
+
* back to the caller. Where a realm cannot block at all, the error is
|
|
11
|
+
* `UV_ENOSYS`, which is what Node reports for a child it could not start.
|
|
12
|
+
*/
|
|
13
|
+
import { libRequire } from '../require-hook';
|
|
14
|
+
import { UV_ENOSYS, UV_ENOENT, UV_EACCES, UV_ENOBUFS } from './uv';
|
|
15
|
+
import { runSyncChild, syncChildRefusal } from '../../shims/sync-child';
|
|
16
|
+
import { __substrateLineFor, __substrateShellLine } from '../../shims/command-line';
|
|
17
|
+
|
|
18
|
+
/** One entry of Node's `options.stdio`, as `getValidStdio(stdio, true)` builds it. */
|
|
19
|
+
interface SyncStdioEntry {
|
|
20
|
+
type: 'pipe' | 'overlapped' | 'ignore' | 'inherit' | 'fd' | 'wrap';
|
|
21
|
+
fd?: number;
|
|
22
|
+
input?: Uint8Array;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** What `child_process.js`'s `spawnSync` hands the binding. */
|
|
26
|
+
interface SyncSpawnOptions {
|
|
27
|
+
file: string;
|
|
28
|
+
args?: string[];
|
|
29
|
+
cwd?: string;
|
|
30
|
+
envPairs?: string[];
|
|
31
|
+
stdio?: SyncStdioEntry[];
|
|
32
|
+
maxBuffer?: number;
|
|
33
|
+
killSignal?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** What libuv answers for one synchronous child. */
|
|
37
|
+
interface SyncSpawnResult {
|
|
38
|
+
pid: number;
|
|
39
|
+
output: Array<Uint8Array | null> | null;
|
|
40
|
+
status: number | null;
|
|
41
|
+
signal: string | null;
|
|
42
|
+
error?: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let nextPid = 1001 + Math.floor(Math.random() * 30000);
|
|
46
|
+
|
|
47
|
+
function environmentOf(envPairs: string[] | undefined): Record<string, string> | undefined {
|
|
48
|
+
if (!envPairs) return undefined;
|
|
49
|
+
const env: Record<string, string> = {};
|
|
50
|
+
for (const pair of envPairs) {
|
|
51
|
+
const at = pair.indexOf('=');
|
|
52
|
+
if (at <= 0) continue;
|
|
53
|
+
env[pair.slice(0, at)] = pair.slice(at + 1);
|
|
54
|
+
}
|
|
55
|
+
return env;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The program a caller can still write to: the engine's own stdout and stderr. */
|
|
59
|
+
function inheritedWriter(fd: number): ((text: string) => void) | undefined {
|
|
60
|
+
const realm = (globalThis as unknown as {
|
|
61
|
+
process?: { stdout?: { write(text: string): unknown }; stderr?: { write(text: string): unknown } };
|
|
62
|
+
}).process;
|
|
63
|
+
const stream = fd === 1 ? realm?.stdout : realm?.stderr;
|
|
64
|
+
if (!stream || typeof stream.write !== 'function') return undefined;
|
|
65
|
+
return (text: string) => {
|
|
66
|
+
try { stream.write(text); } catch { /* a stream that refuses still lets the child run */ }
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* libuv's synchronous spawn. Everything above it -- the encoding of the
|
|
72
|
+
* output, the `Error` an `error` number becomes, `execSync`'s throw -- is
|
|
73
|
+
* Node's own and is vendored.
|
|
74
|
+
*/
|
|
75
|
+
/** Node's own `Buffer`, read when a child answers rather than when this loads. */
|
|
76
|
+
function bufferClass(): { from(value: unknown, encoding?: string): Uint8Array & { toString(encoding?: string): string } } {
|
|
77
|
+
return (libRequire('buffer') as { Buffer: { from(value: unknown, encoding?: string): Uint8Array & { toString(encoding?: string): string } } }).Buffer;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function spawn(options: SyncSpawnOptions): SyncSpawnResult {
|
|
81
|
+
const Buffer = bufferClass();
|
|
82
|
+
const pid = nextPid++;
|
|
83
|
+
const argv = options.args ?? [options.file];
|
|
84
|
+
const stdio = options.stdio ?? [];
|
|
85
|
+
const nothing = (error: number): SyncSpawnResult => ({ pid, output: null, status: null, signal: null, error });
|
|
86
|
+
|
|
87
|
+
if (syncChildRefusal() !== null) return nothing(UV_ENOSYS);
|
|
88
|
+
|
|
89
|
+
const input = stdio[0]?.input;
|
|
90
|
+
const realm = (globalThis as unknown as { process?: { cwd?: () => string; env?: Record<string, string> } }).process;
|
|
91
|
+
let answer;
|
|
92
|
+
try {
|
|
93
|
+
answer = runSyncChild({
|
|
94
|
+
command: __substrateLineFor(options.file, argv, options.cwd),
|
|
95
|
+
cwd: options.cwd ?? (typeof realm?.cwd === 'function' ? realm.cwd() : undefined),
|
|
96
|
+
env: environmentOf(options.envPairs) ?? (realm?.env ? { ...realm.env } : undefined),
|
|
97
|
+
input: input === undefined ? undefined : Buffer.from(input).toString('utf8'),
|
|
98
|
+
onStdout: stdio[1]?.type === 'inherit' ? inheritedWriter(1) : undefined,
|
|
99
|
+
onStderr: stdio[2]?.type === 'inherit' ? inheritedWriter(2) : undefined,
|
|
100
|
+
});
|
|
101
|
+
} catch {
|
|
102
|
+
return nothing(UV_ENOSYS);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// A program the shell has no command for is absent, as it is on a machine
|
|
106
|
+
// that does not carry that binary; a path that is there and is not a program
|
|
107
|
+
// is the shell's 126 and Node's EACCES. Only a caller that named a program
|
|
108
|
+
// can say so: a `-c` line is the shell's own, and its 127 is the line's.
|
|
109
|
+
const named = __substrateShellLine(options.file, argv) === null;
|
|
110
|
+
if (named && answer.status === 127 && /command not found|No such file or directory/u.test(answer.stderr)) {
|
|
111
|
+
return nothing(UV_ENOENT);
|
|
112
|
+
}
|
|
113
|
+
if (named && answer.status === 126 && /Permission denied|not executable/u.test(answer.stderr)) {
|
|
114
|
+
return nothing(UV_EACCES);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Past `maxBuffer` the child is reported as having failed, and the bytes it
|
|
118
|
+
// had already produced come back whole: libuv reads in blocks and hands
|
|
119
|
+
// over what it read, which is why Node's own test says "we can have buffers
|
|
120
|
+
// larger than maxBuffer".
|
|
121
|
+
const limit = typeof options.maxBuffer === 'number' && options.maxBuffer >= 0 ? options.maxBuffer : Infinity;
|
|
122
|
+
const stdout = Buffer.from(answer.stdout, 'utf8');
|
|
123
|
+
const stderr = Buffer.from(answer.stderr, 'utf8');
|
|
124
|
+
const overflowed = stdout.length > limit || stderr.length > limit;
|
|
125
|
+
const output: Array<Uint8Array | null> = [null];
|
|
126
|
+
for (let index = 1; index < Math.max(3, stdio.length); index += 1) {
|
|
127
|
+
const bytes = index === 1 ? stdout : index === 2 ? stderr : null;
|
|
128
|
+
const kind = stdio[index]?.type;
|
|
129
|
+
output.push(bytes === null || kind === 'ignore' || kind === 'inherit' ? null : bytes);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
pid,
|
|
134
|
+
output,
|
|
135
|
+
status: answer.status,
|
|
136
|
+
signal: answer.signal,
|
|
137
|
+
...(overflowed ? { error: UV_ENOBUFS } : {}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export default { spawn };
|