@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,412 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
ArrayPrototypeForEach,
|
|
5
|
+
ArrayPrototypeIncludes,
|
|
6
|
+
ArrayPrototypeMap,
|
|
7
|
+
ArrayPrototypePush,
|
|
8
|
+
ArrayPrototypePushApply,
|
|
9
|
+
ArrayPrototypeShift,
|
|
10
|
+
ArrayPrototypeSlice,
|
|
11
|
+
ArrayPrototypeUnshiftApply,
|
|
12
|
+
ObjectEntries,
|
|
13
|
+
ObjectPrototypeHasOwnProperty: ObjectHasOwn,
|
|
14
|
+
StringPrototypeCharAt,
|
|
15
|
+
StringPrototypeIndexOf,
|
|
16
|
+
StringPrototypeSlice,
|
|
17
|
+
StringPrototypeStartsWith,
|
|
18
|
+
} = primordials;
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
validateArray,
|
|
22
|
+
validateBoolean,
|
|
23
|
+
validateBooleanArray,
|
|
24
|
+
validateObject,
|
|
25
|
+
validateString,
|
|
26
|
+
validateStringArray,
|
|
27
|
+
validateUnion,
|
|
28
|
+
} = require('internal/validators');
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
findLongOptionForShort,
|
|
32
|
+
isLoneLongOption,
|
|
33
|
+
isLoneShortOption,
|
|
34
|
+
isLongOptionAndValue,
|
|
35
|
+
isOptionValue,
|
|
36
|
+
isOptionLikeValue,
|
|
37
|
+
isShortOptionAndValue,
|
|
38
|
+
isShortOptionGroup,
|
|
39
|
+
useDefaultValueOption,
|
|
40
|
+
objectGetOwn,
|
|
41
|
+
optionsGetOwn,
|
|
42
|
+
} = require('internal/util/parse_args/utils');
|
|
43
|
+
|
|
44
|
+
const {
|
|
45
|
+
codes: {
|
|
46
|
+
ERR_INVALID_ARG_VALUE,
|
|
47
|
+
ERR_PARSE_ARGS_INVALID_OPTION_VALUE,
|
|
48
|
+
ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL,
|
|
49
|
+
ERR_PARSE_ARGS_UNKNOWN_OPTION,
|
|
50
|
+
},
|
|
51
|
+
} = require('internal/errors');
|
|
52
|
+
|
|
53
|
+
const {
|
|
54
|
+
kEmptyObject,
|
|
55
|
+
} = require('internal/util');
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
function getMainArgs() {
|
|
59
|
+
// Work out where to slice process.argv for user supplied arguments.
|
|
60
|
+
|
|
61
|
+
// Check node options for scenarios where user CLI args follow executable.
|
|
62
|
+
const execArgv = process.execArgv;
|
|
63
|
+
if (ArrayPrototypeIncludes(execArgv, '-e') ||
|
|
64
|
+
ArrayPrototypeIncludes(execArgv, '--eval') ||
|
|
65
|
+
ArrayPrototypeIncludes(execArgv, '-p') ||
|
|
66
|
+
ArrayPrototypeIncludes(execArgv, '--print')) {
|
|
67
|
+
return ArrayPrototypeSlice(process.argv, 1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Normally first two arguments are executable and script, then CLI arguments
|
|
71
|
+
return ArrayPrototypeSlice(process.argv, 2);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* In strict mode, throw for possible usage errors like --foo --bar
|
|
76
|
+
* @param {object} token - from tokens as available from parseArgs
|
|
77
|
+
*/
|
|
78
|
+
function checkOptionLikeValue(token) {
|
|
79
|
+
if (!token.inlineValue && isOptionLikeValue(token.value)) {
|
|
80
|
+
// Only show short example if user used short option.
|
|
81
|
+
const example = StringPrototypeStartsWith(token.rawName, '--') ?
|
|
82
|
+
`'${token.rawName}=-XYZ'` :
|
|
83
|
+
`'--${token.name}=-XYZ' or '${token.rawName}-XYZ'`;
|
|
84
|
+
const errorMessage = `Option '${token.rawName}' argument is ambiguous.
|
|
85
|
+
Did you forget to specify the option argument for '${token.rawName}'?
|
|
86
|
+
To specify an option argument starting with a dash use ${example}.`;
|
|
87
|
+
throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(errorMessage);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* In strict mode, throw for usage errors.
|
|
93
|
+
* @param {object} config - from config passed to parseArgs
|
|
94
|
+
* @param {object} token - from tokens as available from parseArgs
|
|
95
|
+
*/
|
|
96
|
+
function checkOptionUsage(config, token) {
|
|
97
|
+
let tokenName = token.name;
|
|
98
|
+
if (!ObjectHasOwn(config.options, tokenName)) {
|
|
99
|
+
// Check for negated boolean option.
|
|
100
|
+
if (config.allowNegative && StringPrototypeStartsWith(tokenName, 'no-')) {
|
|
101
|
+
tokenName = StringPrototypeSlice(tokenName, 3);
|
|
102
|
+
if (!ObjectHasOwn(config.options, tokenName) || optionsGetOwn(config.options, tokenName, 'type') !== 'boolean') {
|
|
103
|
+
throw new ERR_PARSE_ARGS_UNKNOWN_OPTION(
|
|
104
|
+
token.rawName, config.allowPositionals);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
throw new ERR_PARSE_ARGS_UNKNOWN_OPTION(
|
|
108
|
+
token.rawName, config.allowPositionals);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const short = optionsGetOwn(config.options, tokenName, 'short');
|
|
113
|
+
const shortAndLong = `${short ? `-${short}, ` : ''}--${tokenName}`;
|
|
114
|
+
const type = optionsGetOwn(config.options, tokenName, 'type');
|
|
115
|
+
if (type === 'string' && typeof token.value !== 'string') {
|
|
116
|
+
throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(`Option '${shortAndLong} <value>' argument missing`);
|
|
117
|
+
}
|
|
118
|
+
// (Idiomatic test for undefined||null, expecting undefined.)
|
|
119
|
+
if (type === 'boolean' && token.value != null) {
|
|
120
|
+
throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(`Option '${shortAndLong}' does not take an argument`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Store the option value in `values`.
|
|
127
|
+
* @param {object} token - from tokens as available from parseArgs
|
|
128
|
+
* @param {object} options - option configs, from parseArgs({ options })
|
|
129
|
+
* @param {object} values - option values returned in `values` by parseArgs
|
|
130
|
+
* @param {boolean} allowNegative - allow negative optinons if true
|
|
131
|
+
*/
|
|
132
|
+
function storeOption(token, options, values, allowNegative) {
|
|
133
|
+
let longOption = token.name;
|
|
134
|
+
let optionValue = token.value;
|
|
135
|
+
if (longOption === '__proto__') {
|
|
136
|
+
return; // No. Just no.
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (allowNegative && StringPrototypeStartsWith(longOption, 'no-') && optionValue === undefined) {
|
|
140
|
+
// Boolean option negation: --no-foo
|
|
141
|
+
longOption = StringPrototypeSlice(longOption, 3);
|
|
142
|
+
token.name = longOption;
|
|
143
|
+
optionValue = false;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// We store based on the option value rather than option type,
|
|
147
|
+
// preserving the users intent for author to deal with.
|
|
148
|
+
const newValue = optionValue ?? true;
|
|
149
|
+
if (optionsGetOwn(options, longOption, 'multiple')) {
|
|
150
|
+
// Always store value in array, including for boolean.
|
|
151
|
+
// values[longOption] starts out not present,
|
|
152
|
+
// first value is added as new array [newValue],
|
|
153
|
+
// subsequent values are pushed to existing array.
|
|
154
|
+
// (note: values has null prototype, so simpler usage)
|
|
155
|
+
if (values[longOption]) {
|
|
156
|
+
ArrayPrototypePush(values[longOption], newValue);
|
|
157
|
+
} else {
|
|
158
|
+
values[longOption] = [newValue];
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
values[longOption] = newValue;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Store the default option value in `values`.
|
|
167
|
+
* @param {string} longOption - long option name e.g. 'foo'
|
|
168
|
+
* @param {string
|
|
169
|
+
* | boolean
|
|
170
|
+
* | string[]
|
|
171
|
+
* | boolean[]} optionValue - default value from option config
|
|
172
|
+
* @param {object} values - option values returned in `values` by parseArgs
|
|
173
|
+
*/
|
|
174
|
+
function storeDefaultOption(longOption, optionValue, values) {
|
|
175
|
+
if (longOption === '__proto__') {
|
|
176
|
+
return; // No. Just no.
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
values[longOption] = optionValue;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Process args and turn into identified tokens:
|
|
184
|
+
* - option (along with value, if any)
|
|
185
|
+
* - positional
|
|
186
|
+
* - option-terminator
|
|
187
|
+
* @param {string[]} args - from parseArgs({ args }) or mainArgs
|
|
188
|
+
* @param {object} options - option configs, from parseArgs({ options })
|
|
189
|
+
*/
|
|
190
|
+
function argsToTokens(args, options) {
|
|
191
|
+
const tokens = [];
|
|
192
|
+
let index = -1;
|
|
193
|
+
let groupCount = 0;
|
|
194
|
+
|
|
195
|
+
const remainingArgs = ArrayPrototypeSlice(args);
|
|
196
|
+
while (remainingArgs.length > 0) {
|
|
197
|
+
const arg = ArrayPrototypeShift(remainingArgs);
|
|
198
|
+
const nextArg = remainingArgs[0];
|
|
199
|
+
if (groupCount > 0)
|
|
200
|
+
groupCount--;
|
|
201
|
+
else
|
|
202
|
+
index++;
|
|
203
|
+
|
|
204
|
+
// Check if `arg` is an options terminator.
|
|
205
|
+
// Guideline 10 in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
|
|
206
|
+
if (arg === '--') {
|
|
207
|
+
// Everything after a bare '--' is considered a positional argument.
|
|
208
|
+
ArrayPrototypePush(tokens, { kind: 'option-terminator', index });
|
|
209
|
+
ArrayPrototypePushApply(
|
|
210
|
+
tokens, ArrayPrototypeMap(remainingArgs, (arg) => {
|
|
211
|
+
return { kind: 'positional', index: ++index, value: arg };
|
|
212
|
+
}),
|
|
213
|
+
);
|
|
214
|
+
break; // Finished processing args, leave while loop.
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (isLoneShortOption(arg)) {
|
|
218
|
+
// e.g. '-f'
|
|
219
|
+
const shortOption = StringPrototypeCharAt(arg, 1);
|
|
220
|
+
const longOption = findLongOptionForShort(shortOption, options);
|
|
221
|
+
let value;
|
|
222
|
+
let inlineValue;
|
|
223
|
+
if (optionsGetOwn(options, longOption, 'type') === 'string' &&
|
|
224
|
+
isOptionValue(nextArg)) {
|
|
225
|
+
// e.g. '-f', 'bar'
|
|
226
|
+
value = ArrayPrototypeShift(remainingArgs);
|
|
227
|
+
inlineValue = false;
|
|
228
|
+
}
|
|
229
|
+
ArrayPrototypePush(
|
|
230
|
+
tokens,
|
|
231
|
+
{ kind: 'option', name: longOption, rawName: arg,
|
|
232
|
+
index, value, inlineValue });
|
|
233
|
+
if (value != null) ++index;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (isShortOptionGroup(arg, options)) {
|
|
238
|
+
// Expand -fXzy to -f -X -z -y
|
|
239
|
+
const expanded = [];
|
|
240
|
+
for (let index = 1; index < arg.length; index++) {
|
|
241
|
+
const shortOption = StringPrototypeCharAt(arg, index);
|
|
242
|
+
const longOption = findLongOptionForShort(shortOption, options);
|
|
243
|
+
if (optionsGetOwn(options, longOption, 'type') !== 'string' ||
|
|
244
|
+
index === arg.length - 1) {
|
|
245
|
+
// Boolean option, or last short in group. Well formed.
|
|
246
|
+
ArrayPrototypePush(expanded, `-${shortOption}`);
|
|
247
|
+
} else {
|
|
248
|
+
// String option in middle. Yuck.
|
|
249
|
+
// Expand -abfFILE to -a -b -fFILE
|
|
250
|
+
ArrayPrototypePush(expanded, `-${StringPrototypeSlice(arg, index)}`);
|
|
251
|
+
break; // finished short group
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
ArrayPrototypeUnshiftApply(remainingArgs, expanded);
|
|
255
|
+
groupCount = expanded.length;
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (isShortOptionAndValue(arg, options)) {
|
|
260
|
+
// e.g. -fFILE
|
|
261
|
+
const shortOption = StringPrototypeCharAt(arg, 1);
|
|
262
|
+
const longOption = findLongOptionForShort(shortOption, options);
|
|
263
|
+
const value = StringPrototypeSlice(arg, 2);
|
|
264
|
+
ArrayPrototypePush(
|
|
265
|
+
tokens,
|
|
266
|
+
{ kind: 'option', name: longOption, rawName: `-${shortOption}`,
|
|
267
|
+
index, value, inlineValue: true });
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (isLoneLongOption(arg)) {
|
|
272
|
+
// e.g. '--foo'
|
|
273
|
+
const longOption = StringPrototypeSlice(arg, 2);
|
|
274
|
+
let value;
|
|
275
|
+
let inlineValue;
|
|
276
|
+
if (optionsGetOwn(options, longOption, 'type') === 'string' &&
|
|
277
|
+
isOptionValue(nextArg)) {
|
|
278
|
+
// e.g. '--foo', 'bar'
|
|
279
|
+
value = ArrayPrototypeShift(remainingArgs);
|
|
280
|
+
inlineValue = false;
|
|
281
|
+
}
|
|
282
|
+
ArrayPrototypePush(
|
|
283
|
+
tokens,
|
|
284
|
+
{ kind: 'option', name: longOption, rawName: arg,
|
|
285
|
+
index, value, inlineValue });
|
|
286
|
+
if (value != null) ++index;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (isLongOptionAndValue(arg)) {
|
|
291
|
+
// e.g. --foo=bar
|
|
292
|
+
const equalIndex = StringPrototypeIndexOf(arg, '=');
|
|
293
|
+
const longOption = StringPrototypeSlice(arg, 2, equalIndex);
|
|
294
|
+
const value = StringPrototypeSlice(arg, equalIndex + 1);
|
|
295
|
+
ArrayPrototypePush(
|
|
296
|
+
tokens,
|
|
297
|
+
{ kind: 'option', name: longOption, rawName: `--${longOption}`,
|
|
298
|
+
index, value, inlineValue: true });
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
ArrayPrototypePush(tokens, { kind: 'positional', index, value: arg });
|
|
303
|
+
}
|
|
304
|
+
return tokens;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const parseArgs = (config = kEmptyObject) => {
|
|
308
|
+
const args = objectGetOwn(config, 'args') ?? getMainArgs();
|
|
309
|
+
const strict = objectGetOwn(config, 'strict') ?? true;
|
|
310
|
+
const allowPositionals = objectGetOwn(config, 'allowPositionals') ?? !strict;
|
|
311
|
+
const returnTokens = objectGetOwn(config, 'tokens') ?? false;
|
|
312
|
+
const allowNegative = objectGetOwn(config, 'allowNegative') ?? false;
|
|
313
|
+
const options = objectGetOwn(config, 'options') ?? { __proto__: null };
|
|
314
|
+
// Bundle these up for passing to strict-mode checks.
|
|
315
|
+
const parseConfig = { args, strict, options, allowPositionals, allowNegative };
|
|
316
|
+
|
|
317
|
+
// Validate input configuration.
|
|
318
|
+
validateArray(args, 'args');
|
|
319
|
+
validateBoolean(strict, 'strict');
|
|
320
|
+
validateBoolean(allowPositionals, 'allowPositionals');
|
|
321
|
+
validateBoolean(returnTokens, 'tokens');
|
|
322
|
+
validateBoolean(allowNegative, 'allowNegative');
|
|
323
|
+
validateObject(options, 'options');
|
|
324
|
+
ArrayPrototypeForEach(
|
|
325
|
+
ObjectEntries(options),
|
|
326
|
+
({ 0: longOption, 1: optionConfig }) => {
|
|
327
|
+
validateObject(optionConfig, `options.${longOption}`);
|
|
328
|
+
|
|
329
|
+
// type is required
|
|
330
|
+
const optionType = objectGetOwn(optionConfig, 'type');
|
|
331
|
+
validateUnion(optionType, `options.${longOption}.type`, ['string', 'boolean']);
|
|
332
|
+
|
|
333
|
+
if (ObjectHasOwn(optionConfig, 'short')) {
|
|
334
|
+
const shortOption = optionConfig.short;
|
|
335
|
+
validateString(shortOption, `options.${longOption}.short`);
|
|
336
|
+
if (shortOption.length !== 1) {
|
|
337
|
+
throw new ERR_INVALID_ARG_VALUE(
|
|
338
|
+
`options.${longOption}.short`,
|
|
339
|
+
shortOption,
|
|
340
|
+
'must be a single character',
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const multipleOption = objectGetOwn(optionConfig, 'multiple');
|
|
346
|
+
if (ObjectHasOwn(optionConfig, 'multiple')) {
|
|
347
|
+
validateBoolean(multipleOption, `options.${longOption}.multiple`);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const defaultValue = objectGetOwn(optionConfig, 'default');
|
|
351
|
+
if (defaultValue !== undefined) {
|
|
352
|
+
let validator;
|
|
353
|
+
switch (optionType) {
|
|
354
|
+
case 'string':
|
|
355
|
+
validator = multipleOption ? validateStringArray : validateString;
|
|
356
|
+
break;
|
|
357
|
+
|
|
358
|
+
case 'boolean':
|
|
359
|
+
validator = multipleOption ? validateBooleanArray : validateBoolean;
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
validator(defaultValue, `options.${longOption}.default`);
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
// Phase 1: identify tokens
|
|
368
|
+
const tokens = argsToTokens(args, options);
|
|
369
|
+
|
|
370
|
+
// Phase 2: process tokens into parsed option values and positionals
|
|
371
|
+
const result = {
|
|
372
|
+
values: { __proto__: null },
|
|
373
|
+
positionals: [],
|
|
374
|
+
};
|
|
375
|
+
if (returnTokens) {
|
|
376
|
+
result.tokens = tokens;
|
|
377
|
+
}
|
|
378
|
+
ArrayPrototypeForEach(tokens, (token) => {
|
|
379
|
+
if (token.kind === 'option') {
|
|
380
|
+
if (strict) {
|
|
381
|
+
checkOptionUsage(parseConfig, token);
|
|
382
|
+
checkOptionLikeValue(token);
|
|
383
|
+
}
|
|
384
|
+
storeOption(token, options, result.values, parseConfig.allowNegative);
|
|
385
|
+
} else if (token.kind === 'positional') {
|
|
386
|
+
if (!allowPositionals) {
|
|
387
|
+
throw new ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL(token.value);
|
|
388
|
+
}
|
|
389
|
+
ArrayPrototypePush(result.positionals, token.value);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// Phase 3: fill in default values for missing args
|
|
394
|
+
ArrayPrototypeForEach(ObjectEntries(options), ({ 0: longOption,
|
|
395
|
+
1: optionConfig }) => {
|
|
396
|
+
const mustSetDefault = useDefaultValueOption(longOption,
|
|
397
|
+
optionConfig,
|
|
398
|
+
result.values);
|
|
399
|
+
if (mustSetDefault) {
|
|
400
|
+
storeDefaultOption(longOption,
|
|
401
|
+
objectGetOwn(optionConfig, 'default'),
|
|
402
|
+
result.values);
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
return result;
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
module.exports = {
|
|
411
|
+
parseArgs,
|
|
412
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
ArrayPrototypeFind,
|
|
5
|
+
ObjectEntries,
|
|
6
|
+
ObjectPrototypeHasOwnProperty: ObjectHasOwn,
|
|
7
|
+
StringPrototypeCharAt,
|
|
8
|
+
StringPrototypeIncludes,
|
|
9
|
+
StringPrototypeStartsWith,
|
|
10
|
+
} = primordials;
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
validateObject,
|
|
14
|
+
} = require('internal/validators');
|
|
15
|
+
|
|
16
|
+
// These are internal utilities to make the parsing logic easier to read, and
|
|
17
|
+
// add lots of detail for the curious. They are in a separate file to allow
|
|
18
|
+
// unit testing, although that is not essential (this could be rolled into
|
|
19
|
+
// main file and just tested implicitly via API).
|
|
20
|
+
//
|
|
21
|
+
// These routines are for internal use, not for export to client.
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Return the named property, but only if it is an own property.
|
|
25
|
+
*/
|
|
26
|
+
function objectGetOwn(obj, prop) {
|
|
27
|
+
if (ObjectHasOwn(obj, prop))
|
|
28
|
+
return obj[prop];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Return the named options property, but only if it is an own property.
|
|
33
|
+
*/
|
|
34
|
+
function optionsGetOwn(options, longOption, prop) {
|
|
35
|
+
if (ObjectHasOwn(options, longOption))
|
|
36
|
+
return objectGetOwn(options[longOption], prop);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Determines if the argument may be used as an option value.
|
|
41
|
+
* @example
|
|
42
|
+
* isOptionValue('V') // returns true
|
|
43
|
+
* isOptionValue('-v') // returns true (greedy)
|
|
44
|
+
* isOptionValue('--foo') // returns true (greedy)
|
|
45
|
+
* isOptionValue(undefined) // returns false
|
|
46
|
+
*/
|
|
47
|
+
function isOptionValue(value) {
|
|
48
|
+
if (value == null) return false;
|
|
49
|
+
|
|
50
|
+
// Open Group Utility Conventions are that an option-argument
|
|
51
|
+
// is the argument after the option, and may start with a dash.
|
|
52
|
+
return true; // greedy!
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Detect whether there is possible confusion and user may have omitted
|
|
57
|
+
* the option argument, like `--port --verbose` when `port` of type:string.
|
|
58
|
+
* In strict mode we throw errors if value is option-like.
|
|
59
|
+
*/
|
|
60
|
+
function isOptionLikeValue(value) {
|
|
61
|
+
if (value == null) return false;
|
|
62
|
+
|
|
63
|
+
return value.length > 1 && StringPrototypeCharAt(value, 0) === '-';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Determines if `arg` is just a short option.
|
|
68
|
+
* @example '-f'
|
|
69
|
+
*/
|
|
70
|
+
function isLoneShortOption(arg) {
|
|
71
|
+
return arg.length === 2 &&
|
|
72
|
+
StringPrototypeCharAt(arg, 0) === '-' &&
|
|
73
|
+
StringPrototypeCharAt(arg, 1) !== '-';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Determines if `arg` is a lone long option.
|
|
78
|
+
* @example
|
|
79
|
+
* isLoneLongOption('a') // returns false
|
|
80
|
+
* isLoneLongOption('-a') // returns false
|
|
81
|
+
* isLoneLongOption('--foo') // returns true
|
|
82
|
+
* isLoneLongOption('--foo=bar') // returns false
|
|
83
|
+
*/
|
|
84
|
+
function isLoneLongOption(arg) {
|
|
85
|
+
return arg.length > 2 &&
|
|
86
|
+
StringPrototypeStartsWith(arg, '--') &&
|
|
87
|
+
!StringPrototypeIncludes(arg, '=', 3);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Determines if `arg` is a long option and value in the same argument.
|
|
92
|
+
* @example
|
|
93
|
+
* isLongOptionAndValue('--foo') // returns false
|
|
94
|
+
* isLongOptionAndValue('--foo=bar') // returns true
|
|
95
|
+
*/
|
|
96
|
+
function isLongOptionAndValue(arg) {
|
|
97
|
+
return arg.length > 2 &&
|
|
98
|
+
StringPrototypeStartsWith(arg, '--') &&
|
|
99
|
+
StringPrototypeIncludes(arg, '=', 3);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Determines if `arg` is a short option group.
|
|
104
|
+
*
|
|
105
|
+
* See Guideline 5 of the [Open Group Utility Conventions](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html).
|
|
106
|
+
* One or more options without option-arguments, followed by at most one
|
|
107
|
+
* option that takes an option-argument, should be accepted when grouped
|
|
108
|
+
* behind one '-' delimiter.
|
|
109
|
+
* @example
|
|
110
|
+
* isShortOptionGroup('-a', {}) // returns false
|
|
111
|
+
* isShortOptionGroup('-ab', {}) // returns true
|
|
112
|
+
* // -fb is an option and a value, not a short option group
|
|
113
|
+
* isShortOptionGroup('-fb', {
|
|
114
|
+
* options: { f: { type: 'string' } }
|
|
115
|
+
* }) // returns false
|
|
116
|
+
* isShortOptionGroup('-bf', {
|
|
117
|
+
* options: { f: { type: 'string' } }
|
|
118
|
+
* }) // returns true
|
|
119
|
+
* // -bfb is an edge case, return true and caller sorts it out
|
|
120
|
+
* isShortOptionGroup('-bfb', {
|
|
121
|
+
* options: { f: { type: 'string' } }
|
|
122
|
+
* }) // returns true
|
|
123
|
+
*/
|
|
124
|
+
function isShortOptionGroup(arg, options) {
|
|
125
|
+
if (arg.length <= 2) return false;
|
|
126
|
+
if (StringPrototypeCharAt(arg, 0) !== '-') return false;
|
|
127
|
+
if (StringPrototypeCharAt(arg, 1) === '-') return false;
|
|
128
|
+
|
|
129
|
+
const firstShort = StringPrototypeCharAt(arg, 1);
|
|
130
|
+
const longOption = findLongOptionForShort(firstShort, options);
|
|
131
|
+
return optionsGetOwn(options, longOption, 'type') !== 'string';
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Determine if arg is a short string option followed by its value.
|
|
136
|
+
* @example
|
|
137
|
+
* isShortOptionAndValue('-a', {}); // returns false
|
|
138
|
+
* isShortOptionAndValue('-ab', {}); // returns false
|
|
139
|
+
* isShortOptionAndValue('-fFILE', {
|
|
140
|
+
* options: { foo: { short: 'f', type: 'string' }}
|
|
141
|
+
* }) // returns true
|
|
142
|
+
*/
|
|
143
|
+
function isShortOptionAndValue(arg, options) {
|
|
144
|
+
validateObject(options, 'options');
|
|
145
|
+
|
|
146
|
+
if (arg.length <= 2) return false;
|
|
147
|
+
if (StringPrototypeCharAt(arg, 0) !== '-') return false;
|
|
148
|
+
if (StringPrototypeCharAt(arg, 1) === '-') return false;
|
|
149
|
+
|
|
150
|
+
const shortOption = StringPrototypeCharAt(arg, 1);
|
|
151
|
+
const longOption = findLongOptionForShort(shortOption, options);
|
|
152
|
+
return optionsGetOwn(options, longOption, 'type') === 'string';
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Find the long option associated with a short option. Looks for a configured
|
|
157
|
+
* `short` and returns the short option itself if a long option is not found.
|
|
158
|
+
* @example
|
|
159
|
+
* findLongOptionForShort('a', {}) // returns 'a'
|
|
160
|
+
* findLongOptionForShort('b', {
|
|
161
|
+
* options: { bar: { short: 'b' } }
|
|
162
|
+
* }) // returns 'bar'
|
|
163
|
+
*/
|
|
164
|
+
function findLongOptionForShort(shortOption, options) {
|
|
165
|
+
validateObject(options, 'options');
|
|
166
|
+
const longOptionEntry = ArrayPrototypeFind(
|
|
167
|
+
ObjectEntries(options),
|
|
168
|
+
({ 1: optionConfig }) => objectGetOwn(optionConfig, 'short') === shortOption,
|
|
169
|
+
);
|
|
170
|
+
return longOptionEntry?.[0] ?? shortOption;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Check if the given option includes a default value
|
|
175
|
+
* and that option has not been set by the input args.
|
|
176
|
+
* @param {string} longOption - long option name e.g. 'foo'
|
|
177
|
+
* @param {object} optionConfig - the option configuration properties
|
|
178
|
+
* @param {object} values - option values returned in `values` by parseArgs
|
|
179
|
+
*/
|
|
180
|
+
function useDefaultValueOption(longOption, optionConfig, values) {
|
|
181
|
+
return objectGetOwn(optionConfig, 'default') !== undefined &&
|
|
182
|
+
values[longOption] === undefined;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
module.exports = {
|
|
186
|
+
findLongOptionForShort,
|
|
187
|
+
isLoneLongOption,
|
|
188
|
+
isLoneShortOption,
|
|
189
|
+
isLongOptionAndValue,
|
|
190
|
+
isOptionValue,
|
|
191
|
+
isOptionLikeValue,
|
|
192
|
+
isShortOptionAndValue,
|
|
193
|
+
isShortOptionGroup,
|
|
194
|
+
useDefaultValueOption,
|
|
195
|
+
objectGetOwn,
|
|
196
|
+
optionsGetOwn,
|
|
197
|
+
};
|