visaljs 0.0.6 → 0.0.8
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/README.md +63 -2
- package/THIRD_PARTY_LICENSES +1216 -0
- package/cli.js +4414 -325
- package/node/include/js_node.h +57 -1
- package/node/include/js_uv.h +8 -1
- package/node/prelude/_stream_duplex.js +4 -0
- package/node/prelude/_stream_passthrough.js +4 -0
- package/node/prelude/_stream_readable.js +4 -0
- package/node/prelude/_stream_transform.js +4 -0
- package/node/prelude/_stream_writable.js +4 -0
- package/node/prelude/assert.js +1334 -0
- package/node/prelude/assert_strict.js +12 -0
- package/node/prelude/async_hooks.js +1 -1
- package/node/prelude/buffer.js +43 -3
- package/node/prelude/child_process.js +1098 -0
- package/node/prelude/cluster.js +52 -0
- package/node/prelude/console.js +328 -0
- package/node/prelude/constants.js +10 -0
- package/node/prelude/crypto.js +1 -1
- package/node/prelude/diagnostics_channel.js +1 -1
- package/node/prelude/dns.js +1 -1
- package/node/prelude/domain.js +115 -0
- package/node/prelude/events.js +144 -16
- package/node/prelude/fs.js +1138 -151
- package/node/prelude/fs_promises.js +117 -11
- package/node/prelude/http.js +104 -27
- package/node/prelude/http2.js +1 -1
- package/node/prelude/https.js +148 -0
- package/node/prelude/inspector.js +27 -0
- package/node/prelude/inspector_promises.js +4 -0
- package/node/prelude/internal/async_context.js +1 -1
- package/node/prelude/internal/buffer_transcode.js +44 -0
- package/node/prelude/internal/comparisons.js +916 -0
- package/node/prelude/internal/compression_streams.js +153 -0
- package/node/prelude/internal/crypto/asym.js +27 -14
- package/node/prelude/internal/crypto/cipher.js +16 -5
- package/node/prelude/internal/crypto/diffiehellman.js +3 -2
- package/node/prelude/internal/crypto/hash.js +2 -1
- package/node/prelude/internal/crypto/kdf.js +14 -9
- package/node/prelude/internal/crypto/keys.js +63 -50
- package/node/prelude/internal/crypto/random.js +2 -1
- package/node/prelude/internal/crypto/util.js +4 -4
- package/node/prelude/internal/dotenv.js +98 -0
- package/node/prelude/internal/errors.js +21 -5
- package/node/prelude/internal/events_extras.js +116 -0
- package/node/prelude/internal/events_on.js +100 -0
- package/node/prelude/internal/features.js +55 -0
- package/node/prelude/internal/fetch.js +364 -0
- package/node/prelude/internal/form_data.js +376 -0
- package/node/prelude/internal/fs_bigint_stats.js +41 -0
- package/node/prelude/internal/fs_blob.js +19 -0
- package/node/prelude/internal/fs_cp.js +709 -0
- package/node/prelude/internal/fs_dir.js +166 -0
- package/node/prelude/internal/fs_filehandle.js +287 -0
- package/node/prelude/internal/fs_glob.js +296 -0
- package/node/prelude/internal/fs_statfs.js +42 -0
- package/node/prelude/internal/fs_stats.js +89 -0
- package/node/prelude/internal/fs_streams.js +541 -0
- package/node/prelude/internal/fs_utils.js +286 -0
- package/node/prelude/internal/fs_watch.js +580 -0
- package/node/prelude/internal/http_agent.js +26 -0
- package/node/prelude/internal/mime.js +249 -0
- package/node/prelude/internal/net.js +1 -0
- package/node/prelude/internal/parse_args.js +288 -0
- package/node/prelude/internal/perf_histogram.js +435 -0
- package/node/prelude/internal/perf_observe.js +119 -0
- package/node/prelude/internal/performance_global.js +19 -0
- package/node/prelude/internal/process_events.js +49 -1
- package/node/prelude/internal/process_memory.js +14 -0
- package/node/prelude/internal/process_more.js +414 -0
- package/node/prelude/internal/process_signals.js +2 -1
- package/node/prelude/internal/process_stdin.js +52 -0
- package/node/prelude/internal/process_stdio.js +36 -0
- package/node/prelude/internal/querystring.js +0 -0
- package/node/prelude/internal/readline.js +338 -0
- package/node/prelude/internal/socketaddress.js +8 -4
- package/node/prelude/internal/source_map.js +122 -0
- package/node/prelude/internal/stream_compose.js +74 -0
- package/node/prelude/internal/stream_from.js +6 -0
- package/node/prelude/internal/stream_operators.js +23 -0
- package/node/prelude/internal/stream_pipeline.js +7 -0
- package/node/prelude/internal/stream_transform.js +10 -0
- package/node/prelude/internal/stream_web_adapters.js +143 -0
- package/node/prelude/internal/streams/add_abort_signal.js +58 -0
- package/node/prelude/internal/streams/compose.js +244 -0
- package/node/prelude/internal/streams/destroy.js +358 -0
- package/node/prelude/internal/streams/duplex.js +199 -0
- package/node/prelude/internal/streams/duplexify.js +378 -0
- package/node/prelude/internal/streams/end_of_stream.js +387 -0
- package/node/prelude/internal/streams/errors.js +216 -0
- package/node/prelude/internal/streams/from.js +211 -0
- package/node/prelude/internal/streams/legacy.js +120 -0
- package/node/prelude/internal/streams/operators.js +375 -0
- package/node/prelude/internal/streams/passthrough.js +45 -0
- package/node/prelude/internal/streams/pipeline.js +468 -0
- package/node/prelude/internal/streams/readable.js +1835 -0
- package/node/prelude/internal/streams/state.js +48 -0
- package/node/prelude/internal/streams/transform.js +203 -0
- package/node/prelude/internal/streams/utils.js +355 -0
- package/node/prelude/internal/streams/validators.js +108 -0
- package/node/prelude/internal/streams/writable.js +1160 -0
- package/node/prelude/internal/structured_clone.js +238 -0
- package/node/prelude/internal/system_errors.js +37 -0
- package/node/prelude/internal/test_runner/mock.js +431 -0
- package/node/prelude/internal/test_runner/reporters.js +404 -0
- package/node/prelude/internal/test_runner/test.js +1571 -0
- package/node/prelude/internal/timers.js +38 -7
- package/node/prelude/internal/timers_global.js +1 -1
- package/node/prelude/internal/tls/common.js +8 -2
- package/node/prelude/internal/tls/wrap.js +3 -15
- package/node/prelude/internal/tls/x509.js +1 -1
- package/node/prelude/internal/tty_read_stream.js +39 -0
- package/node/prelude/internal/tty_streams.js +3 -0
- package/node/prelude/internal/util_debuglog.js +68 -0
- package/node/prelude/internal/util_diff.js +63 -0
- package/node/prelude/internal/util_more.js +111 -0
- package/node/prelude/internal/util_styles.js +76 -0
- package/node/prelude/internal/zlib_engines.js +1 -1
- package/node/prelude/module.js +194 -7
- package/node/prelude/net.js +2 -1
- package/node/prelude/os.js +88 -11
- package/node/prelude/path.js +11 -7
- package/node/prelude/path_posix.js +1 -1
- package/node/prelude/path_win32.js +1 -1
- package/node/prelude/perf_hooks.js +147 -0
- package/node/prelude/process.js +36 -1
- package/node/prelude/punycode.js +188 -0
- package/node/prelude/querystring.js +1 -1
- package/node/prelude/readline.js +8 -0
- package/node/prelude/readline_promises.js +88 -0
- package/node/prelude/repl.js +38 -0
- package/node/prelude/sea.js +23 -0
- package/node/prelude/stream.js +70 -1332
- package/node/prelude/stream_consumers.js +34 -0
- package/node/prelude/stream_promises.js +1 -1
- package/node/prelude/stream_web.js +15 -2
- package/node/prelude/string_decoder.js +1 -1
- package/node/prelude/sys.js +7 -0
- package/node/prelude/test.js +56 -0
- package/node/prelude/test_reporters.js +269 -0
- package/node/prelude/timers.js +7 -84
- package/node/prelude/timers_promises.js +1 -1
- package/node/prelude/tls.js +2 -1
- package/node/prelude/trace_events.js +52 -0
- package/node/prelude/tty.js +10 -4
- package/node/prelude/url.js +88 -27
- package/node/prelude/util.js +121 -5
- package/node/prelude/util_types.js +4 -3
- package/node/prelude/v8.js +814 -0
- package/node/prelude/vm.js +86 -0
- package/node/prelude/wasi.js +10 -0
- package/node/prelude/worker_threads.js +56 -0
- package/node/prelude/zlib.js +58 -25
- package/node/src/host_brotli.c +59 -11
- package/node/src/host_fs.c +342 -11
- package/node/src/host_fswatch.c +170 -0
- package/node/src/host_http.c +143 -20
- package/node/src/host_loop.c +25 -2
- package/node/src/host_net.c +55 -7
- package/node/src/host_os.c +55 -1
- package/node/src/host_proc.c +291 -0
- package/node/src/host_process.c +488 -0
- package/node/src/host_sys.c +64 -2
- package/node/src/host_zlib.c +27 -7
- package/node/src/host_zstd.c +41 -6
- package/node/third_party/hdrhistogram/LICENSE +42 -0
- package/node/third_party/hdrhistogram/README.md +5 -0
- package/node/third_party/libuv/LICENSE +0 -0
- package/node/third_party/libuv/LICENSE-extra +36 -0
- package/node/third_party/libuv/include/uv/aix.h +0 -0
- package/node/third_party/libuv/include/uv/bsd.h +0 -0
- package/node/third_party/libuv/include/uv/darwin.h +0 -0
- package/node/third_party/libuv/include/uv/errno.h +0 -0
- package/node/third_party/libuv/include/uv/linux.h +0 -0
- package/node/third_party/libuv/include/uv/os390.h +0 -0
- package/node/third_party/libuv/include/uv/posix.h +0 -0
- package/node/third_party/libuv/include/uv/sunos.h +0 -0
- package/node/third_party/libuv/include/uv/threadpool.h +0 -0
- package/node/third_party/libuv/include/uv/tree.h +0 -0
- package/node/third_party/libuv/include/uv/unix.h +0 -0
- package/node/third_party/libuv/include/uv/version.h +0 -0
- package/node/third_party/libuv/include/uv/win.h +0 -0
- package/node/third_party/libuv/include/uv.h +0 -0
- package/node/third_party/libuv/src/fs-poll.c +0 -0
- package/node/third_party/libuv/src/heap-inl.h +0 -0
- package/node/third_party/libuv/src/idna.c +0 -0
- package/node/third_party/libuv/src/idna.h +0 -0
- package/node/third_party/libuv/src/inet.c +0 -0
- package/node/third_party/libuv/src/queue.h +0 -0
- package/node/third_party/libuv/src/random.c +0 -0
- package/node/third_party/libuv/src/strscpy.c +0 -0
- package/node/third_party/libuv/src/strscpy.h +0 -0
- package/node/third_party/libuv/src/strtok.c +0 -0
- package/node/third_party/libuv/src/strtok.h +0 -0
- package/node/third_party/libuv/src/thread-common.c +0 -0
- package/node/third_party/libuv/src/threadpool.c +0 -0
- package/node/third_party/libuv/src/timer.c +0 -0
- package/node/third_party/libuv/src/unix/async.c +0 -0
- package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +0 -0
- package/node/third_party/libuv/src/unix/core.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-stub.h +0 -0
- package/node/third_party/libuv/src/unix/darwin-syscalls.h +0 -0
- package/node/third_party/libuv/src/unix/darwin.c +0 -0
- package/node/third_party/libuv/src/unix/dl.c +0 -0
- package/node/third_party/libuv/src/unix/fs.c +0 -0
- package/node/third_party/libuv/src/unix/fsevents.c +0 -0
- package/node/third_party/libuv/src/unix/getaddrinfo.c +0 -0
- package/node/third_party/libuv/src/unix/getnameinfo.c +0 -0
- package/node/third_party/libuv/src/unix/internal.h +0 -0
- package/node/third_party/libuv/src/unix/kqueue.c +0 -0
- package/node/third_party/libuv/src/unix/linux.c +0 -0
- package/node/third_party/libuv/src/unix/loop-watcher.c +0 -0
- package/node/third_party/libuv/src/unix/loop.c +0 -0
- package/node/third_party/libuv/src/unix/pipe.c +0 -0
- package/node/third_party/libuv/src/unix/poll.c +0 -0
- package/node/third_party/libuv/src/unix/process.c +0 -0
- package/node/third_party/libuv/src/unix/procfs-exepath.c +0 -0
- package/node/third_party/libuv/src/unix/proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/random-devurandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-getentropy.c +0 -0
- package/node/third_party/libuv/src/unix/random-getrandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-sysctl-linux.c +0 -0
- package/node/third_party/libuv/src/unix/signal.c +0 -0
- package/node/third_party/libuv/src/unix/stream.c +0 -0
- package/node/third_party/libuv/src/unix/tcp.c +0 -0
- package/node/third_party/libuv/src/unix/thread.c +0 -0
- package/node/third_party/libuv/src/unix/tty.c +0 -0
- package/node/third_party/libuv/src/unix/udp.c +0 -0
- package/node/third_party/libuv/src/uv-common.c +0 -0
- package/node/third_party/libuv/src/uv-common.h +0 -0
- package/node/third_party/libuv/src/uv-data-getter-setters.c +0 -0
- package/node/third_party/libuv/src/version.c +0 -0
- package/node/third_party/llhttp/LICENSE +0 -0
- package/node/third_party/llhttp/api.c +0 -0
- package/node/third_party/llhttp/http.c +0 -0
- package/node/third_party/llhttp/llhttp.c +0 -0
- package/node/third_party/llhttp/llhttp.h +0 -0
- package/node/third_party/nodejs/LICENSE +47 -0
- package/node/third_party/nodejs/README.md +5 -0
- package/node/third_party/parseargs/LICENSE +21 -0
- package/node/third_party/parseargs/README.md +5 -0
- package/node/third_party/punycode/LICENSE +20 -0
- package/node/third_party/punycode/README.md +5 -0
- package/node/third_party/zlib/LICENSE.chromium +27 -0
- package/package.json +1 -5
- package/prebuilt/darwin-arm64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/darwin-arm64/brotli-7995bbdacc52e51c.a +0 -0
- package/prebuilt/darwin-arm64/uv-72ab666eae197cd8.a +0 -0
- package/prebuilt/darwin-arm64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/darwin-arm64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/darwin-x64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/darwin-x64/brotli-7995bbdacc52e51c.a +0 -0
- package/prebuilt/darwin-x64/uv-72ab666eae197cd8.a +0 -0
- package/prebuilt/darwin-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/darwin-x64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-arm64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-arm64/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-arm64/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-arm64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-arm64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-arm64-musl/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-arm64-musl/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-arm64-musl/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-arm64-musl/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-arm64-musl/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-x64/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-x64/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-x64/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-x64/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/linux-x64-musl/boringssl-4a47438eaf7e73ba.a +0 -0
- package/prebuilt/linux-x64-musl/brotli-65481ff838ce9def.a +0 -0
- package/prebuilt/linux-x64-musl/uv-f1353f50ff983f3c.a +0 -0
- package/prebuilt/linux-x64-musl/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/linux-x64-musl/zstd-015315ac7c784c73.a +0 -0
- package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
- package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
- package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
- package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
- package/runtime/include/js_atoms.gen.h +0 -0
- package/runtime/include/js_atoms.h +1 -1
- package/runtime/include/js_bigint.h +1 -1
- package/runtime/include/js_buffer.h +4 -4
- package/runtime/include/js_builtins.h +41 -3
- package/runtime/include/js_console.h +9 -4
- package/runtime/include/js_convert.h +1 -1
- package/runtime/include/js_core.def +5 -4
- package/runtime/include/js_crypto.h +1 -1
- package/runtime/include/js_error.h +1 -1
- package/runtime/include/js_exception.h +21 -1
- package/runtime/include/js_function.h +33 -9
- package/runtime/include/js_gc.h +172 -30
- package/runtime/include/js_generator.h +2 -2
- package/runtime/include/js_host.h +19 -1
- package/runtime/include/js_jobs.h +5 -5
- package/runtime/include/js_module.h +1 -1
- package/runtime/include/js_object.h +142 -15
- package/runtime/include/js_ops.h +107 -5
- package/runtime/include/js_promise.h +3 -3
- package/runtime/include/js_regexp.h +1 -1
- package/runtime/include/js_runtime.h +0 -0
- package/runtime/include/js_symbol.h +1 -1
- package/runtime/include/js_web.h +2 -1
- package/runtime/include/jscell.h +22 -15
- package/runtime/include/jscontext.h +74 -39
- package/runtime/include/jsnum.h +1 -1
- package/runtime/include/jsstring.h +19 -6
- package/runtime/include/jsvalue.h +7 -3
- package/runtime/src/arguments.c +2 -2
- package/runtime/src/array.c +4 -1
- package/runtime/src/arraybuffer.c +19 -7
- package/runtime/src/async_iter.c +4 -3
- package/runtime/src/atoms.c +1 -1
- package/runtime/src/base64.c +2 -2
- package/runtime/src/bigint.c +1 -1
- package/runtime/src/blob.c +22 -9
- package/runtime/src/boringssl_support.cc +1 -1
- package/runtime/src/buffer.c +299 -91
- package/runtime/src/builtin_table.c +1 -1
- package/runtime/src/builtins.c +30 -4
- package/runtime/src/builtins_util.h +0 -0
- package/runtime/src/collections.c +18 -3
- package/runtime/src/components.c +1 -1
- package/runtime/src/console.c +14 -7
- package/runtime/src/convert.c +0 -0
- package/runtime/src/core_all.c +1 -1
- package/runtime/src/crypto.c +1 -1
- package/runtime/src/crypto_asym.c +1 -1
- package/runtime/src/crypto_bn.c +1 -1
- package/runtime/src/crypto_cipher.c +10 -3
- package/runtime/src/crypto_hash.c +1 -1
- package/runtime/src/crypto_host.c +1 -1
- package/runtime/src/crypto_internal.h +1 -1
- package/runtime/src/crypto_kdf.c +1 -1
- package/runtime/src/crypto_key.c +14 -1
- package/runtime/src/crypto_pkey.c +1 -1
- package/runtime/src/crypto_subtle.c +142 -58
- package/runtime/src/crypto_tls.c +1 -1
- package/runtime/src/date.c +5 -2
- package/runtime/src/domexception.c +2 -2
- package/runtime/src/elements.c +56 -17
- package/runtime/src/elements.h +7 -2
- package/runtime/src/encoding.c +1 -1
- package/runtime/src/error.c +4 -4
- package/runtime/src/events.c +23 -14
- package/runtime/src/exception.c +1 -1
- package/runtime/src/fetch.c +241 -17
- package/runtime/src/function.c +31 -19
- package/runtime/src/gc.c +1716 -207
- package/runtime/src/gc_visit.h +87 -0
- package/runtime/src/generator.c +5 -3
- package/runtime/src/global.c +14 -6
- package/runtime/src/headers.c +10 -10
- package/runtime/src/inspect.c +76 -17
- package/runtime/src/internal.h +5 -2
- package/runtime/src/iterate.c +94 -2
- package/runtime/src/iterator.c +1 -1
- package/runtime/src/jobs.c +11 -5
- package/runtime/src/jsnum.c +2 -2
- package/runtime/src/json.c +1 -1
- package/runtime/src/math.c +9 -1
- package/runtime/src/module.c +3 -3
- package/runtime/src/number.c +0 -0
- package/runtime/src/object.c +107 -74
- package/runtime/src/ops.c +21 -3
- package/runtime/src/os.c +192 -1
- package/runtime/src/os.h +33 -2
- package/runtime/src/process.c +73 -8
- package/runtime/src/promise.c +4 -4
- package/runtime/src/proxy.c +1 -1
- package/runtime/src/reflect.c +1 -1
- package/runtime/src/regexp.c +134 -2
- package/runtime/src/regexp_anchor.h +1 -1
- package/runtime/src/regexp_message.h +1 -1
- package/runtime/src/shape.c +10 -19
- package/runtime/src/shape.h +0 -0
- package/runtime/src/streams.c +22 -8
- package/runtime/src/streams.h +0 -0
- package/runtime/src/string.c +64 -25
- package/runtime/src/string_builtins.c +7 -7
- package/runtime/src/symbol.c +2 -7
- package/runtime/src/test_host.c +3 -3
- package/runtime/src/tls_roots.gen.h +102 -620
- package/runtime/src/typedarray.c +8 -3
- package/runtime/src/tznames.gen.h +2 -1
- package/runtime/src/uri.c +1 -1
- package/runtime/src/url.c +42 -39
- package/runtime/src/weak.c +15 -12
- package/runtime/src/web.c +21 -3
- package/runtime/src/wrapper.c +0 -0
- package/runtime/src/writable.c +7 -6
- package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
- package/runtime/third_party/ada-idna/README.md +7 -7
- package/runtime/third_party/ada-idna/convert.mjs +89 -27
- package/runtime/third_party/ada-idna/idna.c +30 -31
- package/runtime/third_party/ada-idna/idna.h +0 -0
- package/runtime/third_party/ada-idna/idna_tables.h +2272 -1952
- package/runtime/third_party/boringssl/third_party/fiat/LICENSE +15 -0
- package/runtime/third_party/mozilla-ca/LICENSE +373 -0
- package/runtime/third_party/mozilla-ca/README.md +9 -0
- package/runtime/third_party/nodejs/LICENSE +47 -0
- package/runtime/third_party/nodejs/README.md +7 -0
- package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
- package/runtime/third_party/quickjs-dtoa/README.md +1 -1
- package/runtime/third_party/quickjs-dtoa/dtoa.c +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.h +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +0 -0
- package/runtime/third_party/quickjs-regexp/LICENSE +0 -0
- package/runtime/third_party/quickjs-regexp/README.md +2 -2
- package/runtime/third_party/quickjs-regexp/cutils.c +0 -0
- package/runtime/third_party/quickjs-regexp/cutils.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.c +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode-table.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.c +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.h +0 -0
- package/runtime/third_party/unicode/LICENSE +39 -0
- package/runtime/third_party/unicode/README.md +9 -0
- package/runtime/third_party/v8-ieee754/LICENSE +0 -0
- package/runtime/third_party/v8-ieee754/LICENSE.fdlibm +10 -0
- package/runtime/third_party/v8-ieee754/README.md +3 -2
- package/runtime/third_party/v8-ieee754/convert.py +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.c +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.h +0 -0
- package/runtime/tools/regexp_compile.c +2 -2
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// util.MIMEType and util.MIMEParams: Node's internal/mime.js (WHATWG MIME Sniffing's parsing):
|
|
2
|
+
// type and subtype lowercased, parameters parsed when first used, first of each name kept,
|
|
3
|
+
// values quoted when serialized if they need it. Linked into programs that name them
|
|
4
|
+
// (internal/features.js): util's MIMEType and MIMEParams build these classes.
|
|
5
|
+
// Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
|
|
6
|
+
import { MIMEParams as MIMEParamsWrapper, MIMEType as MIMETypeWrapper } from "../util.js";
|
|
7
|
+
import { codeError } from "./errors.js";
|
|
8
|
+
import { provideClass } from "./features.js";
|
|
9
|
+
|
|
10
|
+
const NOT_HTTP_TOKEN_CODE_POINT = /[^!#$%&'*+\-.^_`|~A-Za-z0-9]/g;
|
|
11
|
+
const NOT_HTTP_QUOTED_STRING_CODE_POINT = /[^\t -~\u0080-ÿ]/g;
|
|
12
|
+
const END_BEGINNING_WHITESPACE = /[^\r\n\t ]|$/;
|
|
13
|
+
const START_ENDING_WHITESPACE = /[\r\n\t ]*$/;
|
|
14
|
+
const EQUALS_SEMICOLON_OR_END = /[;=]|$/;
|
|
15
|
+
const QUOTED_VALUE_PATTERN = /^(?:([\\]$)|[\\][\s\S]|[^"])*(?:(")|$)/u;
|
|
16
|
+
|
|
17
|
+
function invalidMimeSyntax(production, str, invalidIndex) {
|
|
18
|
+
const at = invalidIndex !== -1 ? ` at ${invalidIndex}` : "";
|
|
19
|
+
return codeError(TypeError, "ERR_INVALID_MIME_SYNTAX", `The MIME syntax for a ${production} in "${str}" is invalid` + at);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function toASCIILower(str) {
|
|
23
|
+
let result = "";
|
|
24
|
+
for (let i = 0; i < str.length; i++) {
|
|
25
|
+
const char = str[i];
|
|
26
|
+
result += char >= "A" && char <= "Z" ? char.toLowerCase() : char;
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function parseTypeAndSubtype(str) {
|
|
32
|
+
let position = str.search(END_BEGINNING_WHITESPACE);
|
|
33
|
+
const typeEnd = str.indexOf("/", position);
|
|
34
|
+
const trimmedType = typeEnd === -1 ? str.slice(position) : str.slice(position, typeEnd);
|
|
35
|
+
const invalidTypeIndex = trimmedType.search(NOT_HTTP_TOKEN_CODE_POINT);
|
|
36
|
+
if (trimmedType === "" || invalidTypeIndex !== -1 || typeEnd === -1) throw invalidMimeSyntax("type", str, invalidTypeIndex);
|
|
37
|
+
position = typeEnd + 1;
|
|
38
|
+
const type = toASCIILower(trimmedType);
|
|
39
|
+
const subtypeEnd = str.indexOf(";", position);
|
|
40
|
+
const rawSubtype = subtypeEnd === -1 ? str.slice(position) : str.slice(position, subtypeEnd);
|
|
41
|
+
position += rawSubtype.length;
|
|
42
|
+
if (subtypeEnd !== -1) position += 1;
|
|
43
|
+
const trimmedSubtype = rawSubtype.slice(0, rawSubtype.search(START_ENDING_WHITESPACE));
|
|
44
|
+
const invalidSubtypeIndex = trimmedSubtype.search(NOT_HTTP_TOKEN_CODE_POINT);
|
|
45
|
+
if (trimmedSubtype === "" || invalidSubtypeIndex !== -1) throw invalidMimeSyntax("subtype", str, invalidSubtypeIndex);
|
|
46
|
+
return { type, subtype: toASCIILower(trimmedSubtype), parametersStringIndex: position };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function removeBackslashes(str) {
|
|
50
|
+
let ret = "";
|
|
51
|
+
let i;
|
|
52
|
+
for (i = 0; i < str.length - 1; i++) {
|
|
53
|
+
const c = str[i];
|
|
54
|
+
if (c === "\\") {
|
|
55
|
+
i++;
|
|
56
|
+
ret += str[i];
|
|
57
|
+
} else ret += c;
|
|
58
|
+
}
|
|
59
|
+
if (i === str.length - 1) ret += str[i];
|
|
60
|
+
return ret;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function escapeQuoteOrSolidus(str) {
|
|
64
|
+
let result = "";
|
|
65
|
+
for (let i = 0; i < str.length; i++) {
|
|
66
|
+
const char = str[i];
|
|
67
|
+
result += char === '"' || char === "\\" ? `\\${char}` : char;
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function encode(value) {
|
|
73
|
+
if (value.length === 0) return '""';
|
|
74
|
+
if (value.search(NOT_HTTP_TOKEN_CODE_POINT) === -1) return value;
|
|
75
|
+
return `"${escapeQuoteOrSolidus(value)}"`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let instantiateMimeParams;
|
|
79
|
+
|
|
80
|
+
class MIMEParams {
|
|
81
|
+
#data = new Map();
|
|
82
|
+
#processed = true; /* a MIMEType's are parsed when first used */
|
|
83
|
+
#string = null;
|
|
84
|
+
|
|
85
|
+
static {
|
|
86
|
+
instantiateMimeParams = (str) => {
|
|
87
|
+
const instance = new MIMEParams();
|
|
88
|
+
instance.#string = str;
|
|
89
|
+
instance.#processed = false;
|
|
90
|
+
return instance;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
delete(name) {
|
|
95
|
+
this.#parse();
|
|
96
|
+
this.#data.delete(name);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
get(name) {
|
|
100
|
+
this.#parse();
|
|
101
|
+
return this.#data.has(name) ? this.#data.get(name) : null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
has(name) {
|
|
105
|
+
this.#parse();
|
|
106
|
+
return this.#data.has(name);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
set(name, value) {
|
|
110
|
+
this.#parse();
|
|
111
|
+
name = `${name}`;
|
|
112
|
+
value = `${value}`;
|
|
113
|
+
const invalidNameIndex = name.search(NOT_HTTP_TOKEN_CODE_POINT);
|
|
114
|
+
if (name.length === 0 || invalidNameIndex !== -1) throw invalidMimeSyntax("parameter name", name, invalidNameIndex);
|
|
115
|
+
const invalidValueIndex = value.search(NOT_HTTP_QUOTED_STRING_CODE_POINT);
|
|
116
|
+
if (invalidValueIndex !== -1) throw invalidMimeSyntax("parameter value", value, invalidValueIndex);
|
|
117
|
+
this.#data.set(name, value);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
entries() {
|
|
121
|
+
this.#parse();
|
|
122
|
+
return this.#data.entries();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
keys() {
|
|
126
|
+
this.#parse();
|
|
127
|
+
return this.#data.keys();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
values() {
|
|
131
|
+
this.#parse();
|
|
132
|
+
return this.#data.values();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
toString() {
|
|
136
|
+
this.#parse();
|
|
137
|
+
let ret = "";
|
|
138
|
+
for (const [key, value] of this.#data) {
|
|
139
|
+
if (ret.length) ret += ";";
|
|
140
|
+
ret += `${key}=${encode(value)}`;
|
|
141
|
+
}
|
|
142
|
+
return ret;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
#parse() {
|
|
146
|
+
if (this.#processed) return;
|
|
147
|
+
const paramsMap = this.#data;
|
|
148
|
+
let position = 0;
|
|
149
|
+
const str = this.#string;
|
|
150
|
+
const endOfSource = str.slice(position).search(START_ENDING_WHITESPACE) + position;
|
|
151
|
+
while (position < endOfSource) {
|
|
152
|
+
position += str.slice(position).search(END_BEGINNING_WHITESPACE);
|
|
153
|
+
const afterParameterName = str.slice(position).search(EQUALS_SEMICOLON_OR_END) + position;
|
|
154
|
+
const parameterString = toASCIILower(str.slice(position, afterParameterName));
|
|
155
|
+
position = afterParameterName;
|
|
156
|
+
if (position < endOfSource) {
|
|
157
|
+
const char = str.charAt(position);
|
|
158
|
+
position += 1;
|
|
159
|
+
if (char === ";") continue; /* a parameter without a value */
|
|
160
|
+
}
|
|
161
|
+
if (position >= endOfSource) break;
|
|
162
|
+
const char = str.charAt(position);
|
|
163
|
+
let parameterValue;
|
|
164
|
+
if (char === '"') {
|
|
165
|
+
position += 1;
|
|
166
|
+
/* to the closing quote, or the end ($1: an unmatched backslash, $2: the closing quote) */
|
|
167
|
+
const insideMatch = QUOTED_VALUE_PATTERN.exec(str.slice(position));
|
|
168
|
+
position += insideMatch[0].length;
|
|
169
|
+
const inside = insideMatch[1] || insideMatch[2] ? insideMatch[0].slice(0, -1) : insideMatch[0];
|
|
170
|
+
parameterValue = removeBackslashes(inside);
|
|
171
|
+
if (insideMatch[1]) parameterValue += "\\";
|
|
172
|
+
} else {
|
|
173
|
+
const valueEnd = str.indexOf(";", position);
|
|
174
|
+
const rawValue = valueEnd === -1 ? str.slice(position) : str.slice(position, valueEnd);
|
|
175
|
+
position += rawValue.length;
|
|
176
|
+
const trimmedValue = rawValue.slice(0, rawValue.search(START_ENDING_WHITESPACE));
|
|
177
|
+
if (trimmedValue === "") continue;
|
|
178
|
+
parameterValue = trimmedValue;
|
|
179
|
+
}
|
|
180
|
+
if (parameterString !== "" && parameterString.search(NOT_HTTP_TOKEN_CODE_POINT) === -1 &&
|
|
181
|
+
parameterValue.search(NOT_HTTP_QUOTED_STRING_CODE_POINT) === -1 && !paramsMap.has(parameterString)) {
|
|
182
|
+
paramsMap.set(parameterString, parameterValue);
|
|
183
|
+
}
|
|
184
|
+
position++;
|
|
185
|
+
}
|
|
186
|
+
this.#data = paramsMap;
|
|
187
|
+
this.#processed = true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const stringifyParams = MIMEParams.prototype.toString;
|
|
192
|
+
Object.defineProperty(MIMEParams.prototype, Symbol.iterator, { configurable: true, value: MIMEParams.prototype.entries, writable: true });
|
|
193
|
+
Object.defineProperty(MIMEParams.prototype, "toJSON", { configurable: true, value: stringifyParams, writable: true });
|
|
194
|
+
|
|
195
|
+
export class MIMEType {
|
|
196
|
+
#type;
|
|
197
|
+
#subtype;
|
|
198
|
+
#parameters;
|
|
199
|
+
|
|
200
|
+
constructor(string) {
|
|
201
|
+
string = `${string}`;
|
|
202
|
+
const data = parseTypeAndSubtype(string);
|
|
203
|
+
this.#type = data.type;
|
|
204
|
+
this.#subtype = data.subtype;
|
|
205
|
+
this.#parameters = instantiateMimeParams(string.slice(data.parametersStringIndex));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
get type() {
|
|
209
|
+
return this.#type;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
set type(v) {
|
|
213
|
+
v = `${v}`;
|
|
214
|
+
const invalidTypeIndex = v.search(NOT_HTTP_TOKEN_CODE_POINT);
|
|
215
|
+
if (v.length === 0 || invalidTypeIndex !== -1) throw invalidMimeSyntax("type", v, invalidTypeIndex);
|
|
216
|
+
this.#type = toASCIILower(v);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
get subtype() {
|
|
220
|
+
return this.#subtype;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
set subtype(v) {
|
|
224
|
+
v = `${v}`;
|
|
225
|
+
const invalidSubtypeIndex = v.search(NOT_HTTP_TOKEN_CODE_POINT);
|
|
226
|
+
if (v.length === 0 || invalidSubtypeIndex !== -1) throw invalidMimeSyntax("subtype", v, invalidSubtypeIndex);
|
|
227
|
+
this.#subtype = toASCIILower(v);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
get essence() {
|
|
231
|
+
return `${this.#type}/${this.#subtype}`;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
get params() {
|
|
235
|
+
return this.#parameters;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
toString() {
|
|
239
|
+
let ret = `${this.#type}/${this.#subtype}`;
|
|
240
|
+
const paramStr = stringifyParams.call(this.#parameters);
|
|
241
|
+
if (paramStr.length) ret += `;${paramStr}`;
|
|
242
|
+
return ret;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
Object.defineProperty(MIMEType.prototype, "toJSON", { configurable: true, value: MIMEType.prototype.toString, writable: true });
|
|
247
|
+
|
|
248
|
+
provideClass(MIMEParamsWrapper, MIMEParams);
|
|
249
|
+
provideClass(MIMETypeWrapper, MIMEType);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// IP address checks (Node's lib/internal/net.js regexes), shared by node:net and node:dns.
|
|
2
|
+
// Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
|
|
2
3
|
|
|
3
4
|
// IPv4 Segment
|
|
4
5
|
const v4Seg = "(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])";
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// util.parseArgs: Node's internal/util/parse_args (from pkgjs/parseargs, MIT): command-line
|
|
2
|
+
// arguments against declared options (string or boolean, short aliases, multiple, defaults),
|
|
3
|
+
// strict about unknown options and positionals, with tokens on request. Linked into programs
|
|
4
|
+
// that name parseArgs (internal/features.js).
|
|
5
|
+
// Ported from Node.js and pkgjs/parseargs (MIT): node/third_party/nodejs/LICENSE and
|
|
6
|
+
// node/third_party/parseargs/LICENSE.
|
|
7
|
+
import { codeError, invalidArgType, invalidArgValue } from "./errors.js";
|
|
8
|
+
import { features } from "./features.js";
|
|
9
|
+
|
|
10
|
+
const isOptionValue = (value) => value != null; /* a value an option may take: anything not nullish */
|
|
11
|
+
|
|
12
|
+
/* `--foo=bar` and `-f` style */
|
|
13
|
+
const isLoneShortOption = (arg) => arg.length === 2 && arg[0] === "-" && arg[1] !== "-";
|
|
14
|
+
const isLoneLongOption = (arg) => arg.length > 2 && arg.startsWith("--") && !arg.includes("=", 3);
|
|
15
|
+
const isLongOptionAndValue = (arg) => arg.length > 2 && arg.startsWith("--") && arg.includes("=", 3);
|
|
16
|
+
const isShortOptionGroup = (arg, options) => {
|
|
17
|
+
if (arg.length <= 2 || arg[0] !== "-" || arg[1] === "-") return false;
|
|
18
|
+
const firstShort = arg[1];
|
|
19
|
+
const longOption = findLongOptionForShort(firstShort, options);
|
|
20
|
+
return options[longOption]?.type !== "string";
|
|
21
|
+
};
|
|
22
|
+
const isShortOptionAndValue = (arg, options) => {
|
|
23
|
+
if (arg.length <= 2 || arg[0] !== "-" || arg[1] === "-") return false;
|
|
24
|
+
const shortOption = arg[1];
|
|
25
|
+
const longOption = findLongOptionForShort(shortOption, options);
|
|
26
|
+
return options[longOption]?.type === "string";
|
|
27
|
+
};
|
|
28
|
+
/* the next argument may be an option's value: it isn't an option itself */
|
|
29
|
+
const isOptionLikeValue = (value) => value != null && value.length > 1 && value[0] === "-";
|
|
30
|
+
|
|
31
|
+
function findLongOptionForShort(shortOption, options) {
|
|
32
|
+
for (const [longOption, config] of Object.entries(options)) {
|
|
33
|
+
if (config.short === shortOption) return longOption;
|
|
34
|
+
}
|
|
35
|
+
return shortOption;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Whether a known option should be stored as an array. */
|
|
39
|
+
function useDefaultValueOption(longOption, optionConfig, values) {
|
|
40
|
+
return optionConfig.default !== undefined && values[longOption] === undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function validateString(value, name) {
|
|
44
|
+
if (typeof value !== "string") throw invalidArgType(name, "of type string", value);
|
|
45
|
+
}
|
|
46
|
+
function validateBoolean(value, name) {
|
|
47
|
+
if (typeof value !== "boolean") throw invalidArgType(name, "of type boolean", value);
|
|
48
|
+
}
|
|
49
|
+
function validateObject(value, name) {
|
|
50
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) throw invalidArgType(name, "of type object", value);
|
|
51
|
+
}
|
|
52
|
+
function validateArray(value, name) {
|
|
53
|
+
if (!Array.isArray(value)) throw invalidArgType(name, "an instance of Array", value);
|
|
54
|
+
}
|
|
55
|
+
function validateStringArray(value, name) {
|
|
56
|
+
validateArray(value, name);
|
|
57
|
+
for (let i = 0; i < value.length; i++) validateString(value[i], `${name}[${i}]`);
|
|
58
|
+
}
|
|
59
|
+
function validateBooleanArray(value, name) {
|
|
60
|
+
validateArray(value, name);
|
|
61
|
+
for (let i = 0; i < value.length; i++) validateBoolean(value[i], `${name}[${i}]`);
|
|
62
|
+
}
|
|
63
|
+
function validateUnion(value, name, union) {
|
|
64
|
+
if (!union.includes(value)) throw invalidArgType(name, `('${union.join("|")}')`, value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const parseArgsUnknownOption = (option, allowPositionals) => {
|
|
68
|
+
const suggestDashDash = allowPositionals ? `. To specify a positional argument starting with a '-', place it at the end of the command after '--', as in '-- ${JSON.stringify(option)}` : "";
|
|
69
|
+
return codeError(TypeError, "ERR_PARSE_ARGS_UNKNOWN_OPTION", `Unknown option '${option}'${suggestDashDash}`);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
function checkOptionLikeValue(token) {
|
|
73
|
+
if (!token.inlineValue && isOptionLikeValue(token.value)) {
|
|
74
|
+
const example = token.rawName.startsWith("--") ? `'${token.rawName}=-XYZ'` : `'--${token.name}=-XYZ' or '${token.rawName}-XYZ'`;
|
|
75
|
+
const errorMessage = `Option '${token.rawName}' argument is ambiguous.
|
|
76
|
+
Did you forget to specify the option argument for '${token.rawName}'?
|
|
77
|
+
To specify an option argument starting with a dash use ${example}.`;
|
|
78
|
+
throw codeError(TypeError, "ERR_PARSE_ARGS_INVALID_OPTION_VALUE", errorMessage);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function checkOptionUsage(config, token) {
|
|
83
|
+
if (!Object.hasOwn(config.options, token.name)) throw parseArgsUnknownOption(token.rawName, config.allowPositionals);
|
|
84
|
+
const short = config.options[token.name].short;
|
|
85
|
+
const shortAndLong = `${short ? `-${short}, ` : ""}--${token.name}`;
|
|
86
|
+
const type = config.options[token.name].type;
|
|
87
|
+
if (type === "string" && typeof token.value !== "string") {
|
|
88
|
+
throw codeError(TypeError, "ERR_PARSE_ARGS_INVALID_OPTION_VALUE", `Option '${shortAndLong} <value>' argument missing`);
|
|
89
|
+
}
|
|
90
|
+
if (type === "boolean" && token.value != null) {
|
|
91
|
+
throw codeError(TypeError, "ERR_PARSE_ARGS_INVALID_OPTION_VALUE", `Option '${shortAndLong}' does not take an argument`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function storeOption(longOption, optionValue, options, values) {
|
|
96
|
+
if (longOption === "__proto__") return; /* no prototype pollution */
|
|
97
|
+
const newValue = optionValue ?? true;
|
|
98
|
+
if (options[longOption]?.multiple) {
|
|
99
|
+
if (values[longOption] === undefined) values[longOption] = [newValue];
|
|
100
|
+
else values[longOption].push(newValue);
|
|
101
|
+
} else {
|
|
102
|
+
values[longOption] = newValue;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function storeDefaultOption(longOption, optionValue, values) {
|
|
107
|
+
if (longOption === "__proto__") return;
|
|
108
|
+
values[longOption] = optionValue;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The arguments as tokens: option, positional and option-terminator, with their indexes. */
|
|
112
|
+
function argsToTokens(args, options) {
|
|
113
|
+
const tokens = [];
|
|
114
|
+
let index = -1;
|
|
115
|
+
let groupCount = 0;
|
|
116
|
+
const remainingArgs = args.slice();
|
|
117
|
+
while (remainingArgs.length > 0) {
|
|
118
|
+
const arg = remainingArgs.shift();
|
|
119
|
+
const nextArg = remainingArgs[0];
|
|
120
|
+
if (groupCount > 0) groupCount--;
|
|
121
|
+
else index++;
|
|
122
|
+
|
|
123
|
+
/* everything after a bare `--` is a positional */
|
|
124
|
+
if (arg === "--") {
|
|
125
|
+
tokens.push({ kind: "option-terminator", index });
|
|
126
|
+
for (const a of remainingArgs) tokens.push({ kind: "positional", index: ++index, value: a });
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (isLoneShortOption(arg)) {
|
|
131
|
+
const shortOption = arg[1];
|
|
132
|
+
const longOption = findLongOptionForShort(shortOption, options);
|
|
133
|
+
let value;
|
|
134
|
+
let inlineValue;
|
|
135
|
+
if (options[longOption]?.type === "string" && isOptionValue(nextArg)) {
|
|
136
|
+
value = remainingArgs.shift();
|
|
137
|
+
inlineValue = false;
|
|
138
|
+
}
|
|
139
|
+
tokens.push({ kind: "option", name: longOption, rawName: arg, index, value, inlineValue });
|
|
140
|
+
if (value != null) ++index;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (isShortOptionGroup(arg, options)) {
|
|
145
|
+
/* `-abc`: each, the last of which may take the rest as its value */
|
|
146
|
+
const expanded = [];
|
|
147
|
+
for (let i = 1; i < arg.length; i++) {
|
|
148
|
+
const shortOption = arg[i];
|
|
149
|
+
const longOption = findLongOptionForShort(shortOption, options);
|
|
150
|
+
if (options[longOption]?.type !== "string" || i === arg.length - 1) {
|
|
151
|
+
expanded.push(`-${shortOption}`);
|
|
152
|
+
} else {
|
|
153
|
+
expanded.push(`-${arg.slice(i)}`);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
remainingArgs.unshift(...expanded);
|
|
158
|
+
groupCount = expanded.length;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (isShortOptionAndValue(arg, options)) {
|
|
163
|
+
const shortOption = arg[1];
|
|
164
|
+
const longOption = findLongOptionForShort(shortOption, options);
|
|
165
|
+
const value = arg.slice(2);
|
|
166
|
+
tokens.push({ kind: "option", name: longOption, rawName: `-${shortOption}`, index, value, inlineValue: true });
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (isLoneLongOption(arg)) {
|
|
171
|
+
const longOption = arg.slice(2);
|
|
172
|
+
let value;
|
|
173
|
+
let inlineValue;
|
|
174
|
+
if (options[longOption]?.type === "string" && isOptionValue(nextArg)) {
|
|
175
|
+
value = remainingArgs.shift();
|
|
176
|
+
inlineValue = false;
|
|
177
|
+
}
|
|
178
|
+
tokens.push({ kind: "option", name: longOption, rawName: arg, index, value, inlineValue });
|
|
179
|
+
if (value != null) ++index;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (isLongOptionAndValue(arg)) {
|
|
184
|
+
const equalIndex = arg.indexOf("=");
|
|
185
|
+
const longOption = arg.slice(2, equalIndex);
|
|
186
|
+
const value = arg.slice(equalIndex + 1);
|
|
187
|
+
tokens.push({ kind: "option", name: longOption, rawName: `--${longOption}`, index, value, inlineValue: true });
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
tokens.push({ kind: "positional", index, value: arg });
|
|
192
|
+
}
|
|
193
|
+
return tokens;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/* the arguments when none are given: the process's, after the executable (and the script, when
|
|
197
|
+
* it's Node's) */
|
|
198
|
+
function getMainArgs() {
|
|
199
|
+
const execArgv = process.execArgv ?? [];
|
|
200
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
201
|
+
return process.argv.slice(1);
|
|
202
|
+
}
|
|
203
|
+
return process.argv.slice(2);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** util.parseArgs({ args, options, strict, allowPositionals, allowNegative, tokens }). */
|
|
207
|
+
export function parseArgs(config = { __proto__: null }) {
|
|
208
|
+
const args = config.args ?? getMainArgs();
|
|
209
|
+
const strict = config.strict ?? true;
|
|
210
|
+
const allowPositionals = config.allowPositionals ?? !strict;
|
|
211
|
+
const returnTokens = config.tokens ?? false;
|
|
212
|
+
const allowNegative = config.allowNegative ?? false;
|
|
213
|
+
const options = config.options ?? { __proto__: null };
|
|
214
|
+
const parseConfig = { args, strict, options, allowPositionals, allowNegative };
|
|
215
|
+
|
|
216
|
+
validateArray(args, "args");
|
|
217
|
+
validateBoolean(strict, "strict");
|
|
218
|
+
validateBoolean(allowPositionals, "allowPositionals");
|
|
219
|
+
validateBoolean(returnTokens, "tokens");
|
|
220
|
+
validateBoolean(allowNegative, "allowNegative");
|
|
221
|
+
validateObject(options, "options");
|
|
222
|
+
for (const [longOption, optionConfig] of Object.entries(options)) {
|
|
223
|
+
validateObject(optionConfig, `options.${longOption}`);
|
|
224
|
+
validateUnion(optionConfig.type, `options.${longOption}.type`, ["string", "boolean"]);
|
|
225
|
+
if (Object.hasOwn(optionConfig, "short")) {
|
|
226
|
+
const shortOption = optionConfig.short;
|
|
227
|
+
validateString(shortOption, `options.${longOption}.short`);
|
|
228
|
+
if (shortOption.length !== 1) {
|
|
229
|
+
throw invalidArgValue(`options.${longOption}.short`, "must be a single character", shortOption);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const multipleOption = optionConfig.multiple;
|
|
233
|
+
if (Object.hasOwn(optionConfig, "multiple")) validateBoolean(multipleOption, `options.${longOption}.multiple`);
|
|
234
|
+
const defaultValue = optionConfig.default;
|
|
235
|
+
if (defaultValue !== undefined) {
|
|
236
|
+
let validator;
|
|
237
|
+
switch (optionConfig.type) {
|
|
238
|
+
case "string":
|
|
239
|
+
validator = multipleOption ? validateStringArray : validateString;
|
|
240
|
+
break;
|
|
241
|
+
case "boolean":
|
|
242
|
+
validator = multipleOption ? validateBooleanArray : validateBoolean;
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
validator(defaultValue, `options.${longOption}.default`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const tokens = argsToTokens(args, options);
|
|
250
|
+
const result = { values: { __proto__: null }, positionals: [] };
|
|
251
|
+
if (returnTokens) result.tokens = tokens;
|
|
252
|
+
|
|
253
|
+
for (const token of tokens) {
|
|
254
|
+
if (token.kind === "option") {
|
|
255
|
+
if (allowNegative && token.name.startsWith("no-")) {
|
|
256
|
+
/* --no-foo: foo false, when foo is a boolean option */
|
|
257
|
+
const longOption = token.name.slice(3);
|
|
258
|
+
const optionConfig = options[longOption];
|
|
259
|
+
if (optionConfig?.type === "boolean") {
|
|
260
|
+
if (token.value !== undefined) {
|
|
261
|
+
throw codeError(TypeError, "ERR_PARSE_ARGS_INVALID_OPTION_VALUE", `Option '--${longOption}' does not take an argument`);
|
|
262
|
+
}
|
|
263
|
+
storeOption(longOption, false, options, result.values);
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (strict) {
|
|
268
|
+
checkOptionUsage(parseConfig, token);
|
|
269
|
+
checkOptionLikeValue(token);
|
|
270
|
+
}
|
|
271
|
+
storeOption(token.name, token.value, options, result.values);
|
|
272
|
+
} else if (token.kind === "positional") {
|
|
273
|
+
if (!allowPositionals) {
|
|
274
|
+
throw codeError(TypeError, "ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL", `Unexpected argument '${token.value}'. This command does not take positional arguments`);
|
|
275
|
+
}
|
|
276
|
+
result.positionals.push(token.value);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
for (const [longOption, optionConfig] of Object.entries(options)) {
|
|
281
|
+
const mustSetDefault = useDefaultValueOption(longOption, optionConfig, result.values);
|
|
282
|
+
if (mustSetDefault) storeDefaultOption(longOption, optionConfig.default, result.values);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
features.parseArgs = parseArgs;
|