visaljs 0.0.7 → 0.0.9
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 +68 -4
- package/THIRD_PARTY_LICENSES +1216 -0
- package/cli.js +4461 -321
- package/node/include/js_node.h +57 -1
- package/node/include/js_uv.h +8 -1
- package/node/prelude/_http_agent.js +5 -0
- package/node/prelude/_http_server.js +7 -0
- 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 +8 -2
- package/node/prelude/domain.js +115 -0
- package/node/prelude/events.js +148 -16
- package/node/prelude/fs.js +1138 -151
- package/node/prelude/fs_promises.js +117 -11
- package/node/prelude/http.js +784 -301
- package/node/prelude/http2.js +1 -1
- package/node/prelude/https.js +159 -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 +113 -0
- package/node/prelude/internal/events_on.js +100 -0
- package/node/prelude/internal/features.js +72 -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 +114 -2
- package/node/prelude/internal/http_symbols.js +3 -0
- package/node/prelude/internal/mime.js +249 -0
- package/node/prelude/internal/net.js +1 -0
- package/node/prelude/internal/net_bound.js +123 -0
- package/node/prelude/internal/net_onread.js +73 -0
- package/node/prelude/internal/net_tos.js +54 -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 +125 -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 +5 -16
- 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 +219 -8
- package/node/prelude/net.js +197 -49
- 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 +151 -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 +292 -39
- package/node/src/host_loop.c +25 -2
- package/node/src/host_net.c +130 -16
- 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 -1
- 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 +5 -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 +5 -1
- package/runtime/include/jscell.h +22 -15
- package/runtime/include/jscontext.h +82 -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 +38 -4
- 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 +42 -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 +1720 -211
- 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 +9 -6
- 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 +700 -11
- package/runtime/src/regexp_anchor.h +1 -1
- package/runtime/src/regexp_message.h +1 -1
- package/runtime/src/shape.c +78 -20
- 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 +110 -36
- 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,709 @@
|
|
|
1
|
+
// fs.cp, cpSync and fs/promises' cp, as Node's: cp is lib/internal/fs/cp/cp.js on node:fs/promises'
|
|
2
|
+
// calls, cpSync lib/internal/fs/cp/cp-sync.js, with its C++ helpers (src/node_file.cc's
|
|
3
|
+
// CpSyncCheckPaths, CpSyncOverrideFile and CpSyncCopyDir) here in JS, their checks and errors
|
|
4
|
+
// kept: cp's errors are SystemErrors, cpSync's the C++ helpers' plain ones. Linked into programs
|
|
5
|
+
// that name them (internal/features.js).
|
|
6
|
+
// Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
|
|
7
|
+
import { errnoMessage, errnoName, fsRealpath, fsStat } from "visaljs:host";
|
|
8
|
+
import {
|
|
9
|
+
chmodSync, copyFileSync, lstatSync, mkdirSync, readdirSync, readlinkSync, statSync, symlinkSync, unlinkSync, utimesSync,
|
|
10
|
+
} from "../fs.js";
|
|
11
|
+
import promises from "../fs_promises.js";
|
|
12
|
+
import { dirname, isAbsolute, join, parse, resolve, sep } from "../path.js";
|
|
13
|
+
import { isPromise } from "../util_types.js";
|
|
14
|
+
import { codeError } from "./errors.js";
|
|
15
|
+
import { features } from "./features.js";
|
|
16
|
+
import { getValidatedPath, getValidMode, validateCpOptions } from "./fs_utils.js";
|
|
17
|
+
import { fsSystemError } from "./streams/errors.js";
|
|
18
|
+
import { validateFunction } from "./streams/validators.js";
|
|
19
|
+
|
|
20
|
+
/* the errno numbers of Node's cp errors: the same on Linux, macOS and Windows */
|
|
21
|
+
const EEXIST = 17, EINVAL = 22, EISDIR = 21, ENOTDIR = 20;
|
|
22
|
+
|
|
23
|
+
/* Node's SystemError of cp.js: "<prefix>: cp returned <code> (<message>) <path>" */
|
|
24
|
+
const PREFIXES = {
|
|
25
|
+
ERR_FS_CP_DIR_TO_NON_DIR: "Cannot overwrite non-directory with directory",
|
|
26
|
+
ERR_FS_CP_EEXIST: "Target already exists",
|
|
27
|
+
ERR_FS_CP_EINVAL: "Invalid src or dest",
|
|
28
|
+
ERR_FS_CP_FIFO_PIPE: "Cannot copy a FIFO pipe",
|
|
29
|
+
ERR_FS_CP_NON_DIR_TO_DIR: "Cannot overwrite directory with non-directory",
|
|
30
|
+
ERR_FS_CP_SOCKET: "Cannot copy a socket file",
|
|
31
|
+
ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY: "Cannot overwrite symlink in subdirectory of self",
|
|
32
|
+
ERR_FS_CP_UNKNOWN: "Cannot copy an unknown file type",
|
|
33
|
+
ERR_FS_EISDIR: "Path is a directory",
|
|
34
|
+
};
|
|
35
|
+
const cpError = (key, context) => fsSystemError(key, PREFIXES[key], context);
|
|
36
|
+
|
|
37
|
+
/* ---- cp: lib/internal/fs/cp/cp.js ------------------------------------------------------- */
|
|
38
|
+
|
|
39
|
+
const { chmod, copyFile, lstat, mkdir, readlink, stat, symlink, unlink, utimes } = promises;
|
|
40
|
+
|
|
41
|
+
async function cpFn(src, dest, opts) {
|
|
42
|
+
// Warn about using preserveTimestamps on 32-bit node
|
|
43
|
+
if (opts.preserveTimestamps && process.arch === "ia32") {
|
|
44
|
+
process.emitWarning("Using the preserveTimestamps option in 32-bit node is not recommended", "TimestampPrecisionWarning");
|
|
45
|
+
}
|
|
46
|
+
const stats = await checkPaths(src, dest, opts);
|
|
47
|
+
const { srcStat, destStat, skipped } = stats;
|
|
48
|
+
if (skipped) return;
|
|
49
|
+
await checkParentPaths(src, srcStat, dest);
|
|
50
|
+
return checkParentDir(destStat, src, dest, opts);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function checkPaths(src, dest, opts) {
|
|
54
|
+
if (opts.filter && !(await opts.filter(src, dest))) {
|
|
55
|
+
return { __proto__: null, skipped: true };
|
|
56
|
+
}
|
|
57
|
+
const { 0: srcStat, 1: destStat } = await getStats(src, dest, opts);
|
|
58
|
+
if (destStat) {
|
|
59
|
+
if (areIdentical(srcStat, destStat)) {
|
|
60
|
+
throw cpError("ERR_FS_CP_EINVAL", { message: "src and dest cannot be the same", path: dest, syscall: "cp", errno: EINVAL, code: "EINVAL" });
|
|
61
|
+
}
|
|
62
|
+
if (srcStat.isDirectory() && !destStat.isDirectory()) {
|
|
63
|
+
throw cpError("ERR_FS_CP_DIR_TO_NON_DIR", {
|
|
64
|
+
message: `cannot overwrite non-directory ${dest} with directory ${src}`, path: dest, syscall: "cp", errno: EISDIR, code: "EISDIR",
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (!srcStat.isDirectory() && destStat.isDirectory()) {
|
|
68
|
+
throw cpError("ERR_FS_CP_NON_DIR_TO_DIR", {
|
|
69
|
+
message: `cannot overwrite directory ${dest} with non-directory ${src}`, path: dest, syscall: "cp", errno: ENOTDIR, code: "ENOTDIR",
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
|
|
75
|
+
throw cpError("ERR_FS_CP_EINVAL", {
|
|
76
|
+
message: `cannot copy ${src} to a subdirectory of self ${dest}`, path: dest, syscall: "cp", errno: EINVAL, code: "EINVAL",
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return { __proto__: null, srcStat, destStat, skipped: false };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function areIdentical(srcStat, destStat) {
|
|
83
|
+
return destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* (Node's take bigint stats: an inode number past 2^53 is rare, and BigIntStats links BigInt) */
|
|
87
|
+
function getStats(src, dest, opts) {
|
|
88
|
+
const statFunc = opts.dereference ? (file) => stat(file) : (file) => lstat(file);
|
|
89
|
+
return Promise.all([
|
|
90
|
+
statFunc(src),
|
|
91
|
+
statFunc(dest).then(undefined, (err) => {
|
|
92
|
+
if (err.code === "ENOENT") return null;
|
|
93
|
+
throw err;
|
|
94
|
+
}),
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function checkParentDir(destStat, src, dest, opts) {
|
|
99
|
+
const destParent = dirname(dest);
|
|
100
|
+
const dirExists = await pathExists(destParent);
|
|
101
|
+
if (dirExists) return getStatsForCopy(destStat, src, dest, opts);
|
|
102
|
+
await mkdir(destParent, { recursive: true });
|
|
103
|
+
return getStatsForCopy(destStat, src, dest, opts);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function pathExists(dest) {
|
|
107
|
+
return stat(dest).then(() => true, (err) => (err.code === "ENOENT" ? false : Promise.reject(err)));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Recursively check if dest parent is a subdirectory of src.
|
|
111
|
+
// It works for all file types including symlinks since it
|
|
112
|
+
// checks the src and dest inodes. It starts from the deepest
|
|
113
|
+
// parent and stops once it reaches the src parent or the root path.
|
|
114
|
+
async function checkParentPaths(src, srcStat, dest) {
|
|
115
|
+
const srcParent = resolve(dirname(src));
|
|
116
|
+
const destParent = resolve(dirname(dest));
|
|
117
|
+
if (destParent === srcParent || destParent === parse(destParent).root) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
let destStat;
|
|
121
|
+
try {
|
|
122
|
+
destStat = await stat(destParent);
|
|
123
|
+
} catch (err) {
|
|
124
|
+
if (err.code === "ENOENT") return;
|
|
125
|
+
throw err;
|
|
126
|
+
}
|
|
127
|
+
if (areIdentical(srcStat, destStat)) {
|
|
128
|
+
throw cpError("ERR_FS_CP_EINVAL", {
|
|
129
|
+
message: `cannot copy ${src} to a subdirectory of self ${dest}`, path: dest, syscall: "cp", errno: EINVAL, code: "EINVAL",
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return checkParentPaths(src, srcStat, destParent);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const normalizePathToArray = (path) => resolve(path).split(sep).filter(Boolean);
|
|
136
|
+
|
|
137
|
+
// Return true if dest is a subdir of src, otherwise false.
|
|
138
|
+
// It only checks the path strings.
|
|
139
|
+
function isSrcSubdir(src, dest) {
|
|
140
|
+
const srcArr = normalizePathToArray(src);
|
|
141
|
+
const destArr = normalizePathToArray(dest);
|
|
142
|
+
return srcArr.every((cur, i) => destArr[i] === cur);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function getStatsForCopy(destStat, src, dest, opts) {
|
|
146
|
+
const statFn = opts.dereference ? stat : lstat;
|
|
147
|
+
const srcStat = await statFn(src);
|
|
148
|
+
if (srcStat.isDirectory() && opts.recursive) {
|
|
149
|
+
return onDir(srcStat, destStat, src, dest, opts);
|
|
150
|
+
} else if (srcStat.isDirectory()) {
|
|
151
|
+
throw cpError("ERR_FS_EISDIR", { message: `${src} is a directory (not copied)`, path: src, syscall: "cp", errno: EISDIR, code: "EISDIR" });
|
|
152
|
+
} else if (srcStat.isFile() || srcStat.isCharacterDevice() || srcStat.isBlockDevice()) {
|
|
153
|
+
return onFile(srcStat, destStat, src, dest, opts);
|
|
154
|
+
} else if (srcStat.isSymbolicLink()) {
|
|
155
|
+
return onLink(destStat, src, dest, opts);
|
|
156
|
+
} else if (srcStat.isSocket()) {
|
|
157
|
+
throw cpError("ERR_FS_CP_SOCKET", { message: `cannot copy a socket file: ${dest}`, path: dest, syscall: "cp", errno: EINVAL, code: "EINVAL" });
|
|
158
|
+
} else if (srcStat.isFIFO()) {
|
|
159
|
+
throw cpError("ERR_FS_CP_FIFO_PIPE", { message: `cannot copy a FIFO pipe: ${dest}`, path: dest, syscall: "cp", errno: EINVAL, code: "EINVAL" });
|
|
160
|
+
}
|
|
161
|
+
throw cpError("ERR_FS_CP_UNKNOWN", {
|
|
162
|
+
message: `cannot copy an unknown file type: ${dest}`, path: dest, syscall: "cp", errno: EINVAL, code: "EINVAL",
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function onFile(srcStat, destStat, src, dest, opts) {
|
|
167
|
+
if (!destStat) return _copyFile(srcStat, src, dest, opts);
|
|
168
|
+
return mayCopyFile(srcStat, src, dest, opts);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function mayCopyFile(srcStat, src, dest, opts) {
|
|
172
|
+
if (opts.force) {
|
|
173
|
+
await unlink(dest);
|
|
174
|
+
return _copyFile(srcStat, src, dest, opts);
|
|
175
|
+
} else if (opts.errorOnExist) {
|
|
176
|
+
throw cpError("ERR_FS_CP_EEXIST", { message: `${dest} already exists`, path: dest, syscall: "cp", errno: EEXIST, code: "EEXIST" });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function _copyFile(srcStat, src, dest, opts) {
|
|
181
|
+
await copyFile(src, dest, opts.mode);
|
|
182
|
+
if (opts.preserveTimestamps) {
|
|
183
|
+
return handleTimestampsAndMode(srcStat.mode, src, dest);
|
|
184
|
+
}
|
|
185
|
+
return setDestMode(dest, srcStat.mode);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function handleTimestampsAndMode(srcMode, src, dest) {
|
|
189
|
+
// Make sure the file is writable before setting the timestamp
|
|
190
|
+
// otherwise open fails with EPERM when invoked with 'r+'
|
|
191
|
+
// (through utimes call)
|
|
192
|
+
if (fileIsNotWritable(srcMode)) {
|
|
193
|
+
await makeFileWritable(dest, srcMode);
|
|
194
|
+
}
|
|
195
|
+
return setDestTimestampsAndMode(srcMode, src, dest);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function fileIsNotWritable(srcMode) {
|
|
199
|
+
return (srcMode & 0o200) === 0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function makeFileWritable(dest, srcMode) {
|
|
203
|
+
return setDestMode(dest, srcMode | 0o200);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async function setDestTimestampsAndMode(srcMode, src, dest) {
|
|
207
|
+
await setDestTimestamps(src, dest);
|
|
208
|
+
return setDestMode(dest, srcMode);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function setDestMode(dest, srcMode) {
|
|
212
|
+
return chmod(dest, srcMode);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function setDestTimestamps(src, dest) {
|
|
216
|
+
// The initial srcStat.atime cannot be trusted
|
|
217
|
+
// because it is modified by the read(2) system call
|
|
218
|
+
// (See https://nodejs.org/api/fs.html#fs_stat_time_values)
|
|
219
|
+
const updatedSrcStat = await stat(src);
|
|
220
|
+
return utimes(dest, updatedSrcStat.atime, updatedSrcStat.mtime);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async function onDir(srcStat, destStat, src, dest, opts) {
|
|
224
|
+
if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts);
|
|
225
|
+
if (opts.errorOnExist && !opts.force) {
|
|
226
|
+
throw cpError("ERR_FS_CP_EEXIST", { message: `${dest} already exists`, path: dest, syscall: "cp", errno: EEXIST, code: "EEXIST" });
|
|
227
|
+
}
|
|
228
|
+
return copyDir(src, dest, opts);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function mkDirAndCopy(srcMode, src, dest, opts) {
|
|
232
|
+
await mkdir(dest);
|
|
233
|
+
await copyDir(src, dest, opts);
|
|
234
|
+
return setDestMode(dest, srcMode);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/* (Node's reads the directory with opendir: the same entries, in the same order) */
|
|
238
|
+
async function copyDir(src, dest, opts) {
|
|
239
|
+
for (const name of readdirSync(src)) {
|
|
240
|
+
const srcItem = join(src, name);
|
|
241
|
+
const destItem = join(dest, name);
|
|
242
|
+
const { destStat, skipped } = await checkPaths(srcItem, destItem, opts);
|
|
243
|
+
if (!skipped) await getStatsForCopy(destStat, srcItem, destItem, opts);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/* binding.internalModuleStat(path) === 1: a directory, links followed */
|
|
248
|
+
function isDirectoryPath(path) {
|
|
249
|
+
const st = fsStat(path, true);
|
|
250
|
+
return Array.isArray(st) && (st[0] & 0o170000) === 0o040000;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async function onLink(destStat, src, dest, opts) {
|
|
254
|
+
let resolvedSrc = await readlink(src);
|
|
255
|
+
if (!opts.verbatimSymlinks && !isAbsolute(resolvedSrc)) {
|
|
256
|
+
resolvedSrc = resolve(dirname(src), resolvedSrc);
|
|
257
|
+
}
|
|
258
|
+
const srcIsDir = isDirectoryPath(src);
|
|
259
|
+
const symlinkType = srcIsDir ? "dir" : "file";
|
|
260
|
+
if (!destStat) {
|
|
261
|
+
return symlink(resolvedSrc, dest, symlinkType);
|
|
262
|
+
}
|
|
263
|
+
let resolvedDest;
|
|
264
|
+
try {
|
|
265
|
+
resolvedDest = await readlink(dest);
|
|
266
|
+
} catch (err) {
|
|
267
|
+
// Dest exists and is a regular file or directory,
|
|
268
|
+
// Windows may throw UNKNOWN error. If dest already exists,
|
|
269
|
+
// fs throws error anyway, so no need to guard against it here.
|
|
270
|
+
if (err.code === "EINVAL" || err.code === "UNKNOWN") {
|
|
271
|
+
return symlink(resolvedSrc, dest, symlinkType);
|
|
272
|
+
}
|
|
273
|
+
throw err;
|
|
274
|
+
}
|
|
275
|
+
if (!isAbsolute(resolvedDest)) {
|
|
276
|
+
resolvedDest = resolve(dirname(dest), resolvedDest);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (srcIsDir && isSrcSubdir(resolvedSrc, resolvedDest)) {
|
|
280
|
+
throw cpError("ERR_FS_CP_EINVAL", {
|
|
281
|
+
message: `cannot copy ${resolvedSrc} to a subdirectory of self ${resolvedDest}`, path: dest, syscall: "cp", errno: EINVAL, code: "EINVAL",
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
// Do not copy if src is a subdir of dest since unlinking
|
|
285
|
+
// dest in this case would result in removing src contents
|
|
286
|
+
// and therefore a broken symlink would be created.
|
|
287
|
+
const srcStat = await stat(src);
|
|
288
|
+
if (srcStat.isDirectory() && isSrcSubdir(resolvedDest, resolvedSrc)) {
|
|
289
|
+
throw cpError("ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY", {
|
|
290
|
+
message: `cannot overwrite ${resolvedDest} with ${resolvedSrc}`, path: dest, syscall: "cp", errno: EINVAL, code: "EINVAL",
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
return copyLink(resolvedSrc, dest, symlinkType);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
async function copyLink(resolvedSrc, dest, symlinkType) {
|
|
297
|
+
await unlink(dest);
|
|
298
|
+
return symlink(resolvedSrc, dest, symlinkType);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/* ---- Node's C++ helpers for cpSync (src/node_file.cc), in JS ------------------------------ */
|
|
302
|
+
|
|
303
|
+
/* a plain error with a code, as the C++ THROW_ERR_* make */
|
|
304
|
+
const cppError = (code, message) => codeError(Error, code, message);
|
|
305
|
+
|
|
306
|
+
/* ErrnoException (a std::error_code's): "EEXIST, File exists '<path>'", errno positive; from a
|
|
307
|
+
* caught fs error (its errno, libuv's, negative) or a code and its number */
|
|
308
|
+
function errnoError(codeOrError, syscall, path, number) {
|
|
309
|
+
const code = typeof codeOrError === "string" ? codeOrError : codeOrError.code;
|
|
310
|
+
const errno = typeof codeOrError === "string" ? number : -codeOrError.errno;
|
|
311
|
+
const text = errnoMessage(-errno);
|
|
312
|
+
const e = new Error(`${code}, ${text.charAt(0).toUpperCase()}${text.slice(1)}${path === undefined ? "" : ` '${path}'`}`);
|
|
313
|
+
e.errno = errno;
|
|
314
|
+
e.code = code;
|
|
315
|
+
if (path !== undefined) e.path = path;
|
|
316
|
+
e.syscall = syscall;
|
|
317
|
+
return e;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/* a path's file type, as std::filesystem's status (links followed) or symlink_status */
|
|
321
|
+
const S_IFMT = 0o170000;
|
|
322
|
+
const TYPES = { 0o100000: "regular", 0o040000: "directory", 0o120000: "symlink", 0o010000: "fifo", 0o140000: "socket", 0o020000: "character", 0o060000: "block" };
|
|
323
|
+
function status(path, follow) {
|
|
324
|
+
const st = fsStat(path, follow);
|
|
325
|
+
if (typeof st === "number") return { type: errnoName(st) === "ENOENT" ? "not_found" : "error", errno: st, st: null };
|
|
326
|
+
return { type: TYPES[st[0] & S_IFMT] ?? "unknown", st };
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/* std::filesystem::equivalent: the same file, links followed; false (an error) when either is missing */
|
|
330
|
+
function equivalent(a, b) {
|
|
331
|
+
const sa = fsStat(a, true), sb = fsStat(b, true);
|
|
332
|
+
if (!Array.isArray(sa) || !Array.isArray(sb)) return null;
|
|
333
|
+
return sa[6] === sb[6] && sa[7] === sb[7]; /* ino, dev */
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/* std::filesystem::path's parent_path ("a" → "", "/a" → "/", "/" → "/") */
|
|
337
|
+
function parentPath(p) {
|
|
338
|
+
const i = p.lastIndexOf("/");
|
|
339
|
+
if (i < 0) return "";
|
|
340
|
+
if (i === 0) return "/";
|
|
341
|
+
return p.slice(0, i);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function createDirectories(path) {
|
|
345
|
+
if (path === "") return;
|
|
346
|
+
try {
|
|
347
|
+
mkdirSync(path, { recursive: true });
|
|
348
|
+
} catch {
|
|
349
|
+
/* (Node's ignores the error: the copy reports it) */
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/* CpSyncCheckPaths. As Node's: without dereference src's status follows links and dest's doesn't,
|
|
354
|
+
* and the other way round with it */
|
|
355
|
+
function cpSyncCheckPaths(src, dest, dereference, recursive) {
|
|
356
|
+
const srcStatus = status(src, !dereference);
|
|
357
|
+
if (srcStatus.st === null) throw codeErrorOfStat(srcStatus.errno, dereference ? "stat" : "lstat", src);
|
|
358
|
+
const destStatus = status(dest, dereference);
|
|
359
|
+
const destExists = destStatus.st !== null;
|
|
360
|
+
const srcIsDir = srcStatus.type === "directory" || (dereference && srcStatus.type === "symlink");
|
|
361
|
+
|
|
362
|
+
if (destExists) {
|
|
363
|
+
if (equivalent(src, dest)) throw cppError("ERR_FS_CP_EINVAL", `src and dest cannot be the same ${dest}`);
|
|
364
|
+
const destIsDir = destStatus.type === "directory";
|
|
365
|
+
if (srcIsDir && !destIsDir) throw cppError("ERR_FS_CP_DIR_TO_NON_DIR", `Cannot overwrite non-directory ${dest} with directory ${src}`);
|
|
366
|
+
if (!srcIsDir && destIsDir) throw cppError("ERR_FS_CP_NON_DIR_TO_DIR", `Cannot overwrite directory ${dest} with non-directory ${src}`);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const srcWithSep = src.endsWith(sep) ? src : src + sep;
|
|
370
|
+
// Check if dest_path is a subdirectory of src_path.
|
|
371
|
+
if (srcIsDir && dest.startsWith(srcWithSep)) throw cppError("ERR_FS_CP_EINVAL", `Cannot copy ${srcWithSep} to a subdirectory of self ${dest}`);
|
|
372
|
+
|
|
373
|
+
// (Node's compares src with dest's parent each time, while the walk lasts)
|
|
374
|
+
let destParent = parentPath(dest);
|
|
375
|
+
while (parentPath(src) !== destParent && parentPath(destParent) !== "" && parentPath(destParent) !== destParent) {
|
|
376
|
+
const same = equivalent(src, parentPath(dest));
|
|
377
|
+
if (same) throw cppError("ERR_FS_CP_EINVAL", `Cannot copy ${srcWithSep} to a subdirectory of self ${dest}`);
|
|
378
|
+
// If equivalent fails, it's highly likely that dest_parent does not exist
|
|
379
|
+
if (same === null) break;
|
|
380
|
+
destParent = parentPath(destParent);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (srcIsDir && !recursive) throw cppError("ERR_FS_EISDIR", `Recursive option not enabled, cannot copy a directory: ${srcWithSep}`);
|
|
384
|
+
|
|
385
|
+
if (srcStatus.type === "socket") throw cppError("ERR_FS_CP_SOCKET", `Cannot copy a socket file: ${dest}`);
|
|
386
|
+
if (srcStatus.type === "fifo") throw cppError("ERR_FS_CP_FIFO_PIPE", `Cannot copy a FIFO pipe: ${dest}`);
|
|
387
|
+
if (srcStatus.type === "unknown") throw cppError("ERR_FS_CP_UNKNOWN", `Cannot copy an unknown file type: ${dest}`);
|
|
388
|
+
|
|
389
|
+
if (!destExists || status(parentPath(dest), true).st === null) createDirectories(parentPath(dest));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/* ThrowUVException's: "ENOENT: no such file or directory, lstat '<path>'" */
|
|
393
|
+
function codeErrorOfStat(errno, syscall, path) {
|
|
394
|
+
const code = errnoName(errno);
|
|
395
|
+
const e = new Error(`${code}: ${errnoMessage(errno)}, ${syscall} '${path}'`);
|
|
396
|
+
Object.assign(e, { errno, code, syscall, path });
|
|
397
|
+
return e;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/* CopyUtimes: src's times on dest */
|
|
401
|
+
function copyUtimes(src, dest) {
|
|
402
|
+
const st = statSync(src);
|
|
403
|
+
utimesSync(dest, st.atime, st.mtime);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/* CpSyncOverrideFile: dest removed, src copied over it */
|
|
407
|
+
function cpSyncOverrideFile(src, dest, mode, preserveTimestamps) {
|
|
408
|
+
mode = getValidMode(mode, "copyFile");
|
|
409
|
+
try {
|
|
410
|
+
unlinkSync(dest);
|
|
411
|
+
} catch (e) {
|
|
412
|
+
throw errnoError(e, "unlink", dest);
|
|
413
|
+
}
|
|
414
|
+
try {
|
|
415
|
+
copyFileSync(src, dest, mode);
|
|
416
|
+
} catch (e) {
|
|
417
|
+
if (mode === 0) throw errnoError(e, "cp", dest);
|
|
418
|
+
throw e.syscall === "copyfile" ? Object.assign(e, { syscall: "cp", message: e.message.replace(", copyfile ", ", cp ") }) : e;
|
|
419
|
+
}
|
|
420
|
+
if (preserveTimestamps) copyUtimes(src, dest);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/* std::filesystem::weakly_canonical: the existing part of the path made canonical, the rest
|
|
424
|
+
* normalized onto it */
|
|
425
|
+
function weaklyCanonical(path) {
|
|
426
|
+
path = resolve(path);
|
|
427
|
+
const rest = [];
|
|
428
|
+
for (let head = path; ; head = dirname(head)) {
|
|
429
|
+
const real = fsRealpath(head);
|
|
430
|
+
if (typeof real === "string") return rest.length ? join(real, ...rest.reverse()) : real;
|
|
431
|
+
if (dirname(head) === head) return path;
|
|
432
|
+
rest.push(head.slice(dirname(head).length).replace(/^\//, ""));
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/* isInsideDir: src's parts a prefix of dest's (absolute) */
|
|
437
|
+
function isInsideDir(src, dest) {
|
|
438
|
+
const srcArr = normalizePathToArray(src);
|
|
439
|
+
const destArr = normalizePathToArray(dest);
|
|
440
|
+
if (srcArr.length > destArr.length) return false;
|
|
441
|
+
return srcArr.every((cur, i) => destArr[i] === cur);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const existsPath = (p) => Array.isArray(fsStat(p, true));
|
|
445
|
+
const isSymlinkPath = (p) => status(p, false).type === "symlink";
|
|
446
|
+
const isRegularPath = (p) => status(p, true).type === "regular";
|
|
447
|
+
|
|
448
|
+
/* CpSyncCopyDir: a directory's contents copied, recursively, as std::filesystem copies them */
|
|
449
|
+
function cpSyncCopyDir(src, dest, force, dereference, errorOnExist, verbatimSymlinks, preserveTimestamps) {
|
|
450
|
+
try {
|
|
451
|
+
mkdirSync(dest, { recursive: true });
|
|
452
|
+
} catch (e) {
|
|
453
|
+
throw errnoError(e, "cp", dest);
|
|
454
|
+
}
|
|
455
|
+
const copyDirContents = (src, dest) => {
|
|
456
|
+
for (const name of readdirSync(src)) {
|
|
457
|
+
const entryPath = join(src, name);
|
|
458
|
+
const destFilePath = join(dest, name);
|
|
459
|
+
const entry = status(entryPath, false);
|
|
460
|
+
if (entry.type === "symlink") {
|
|
461
|
+
if (verbatimSymlinks) {
|
|
462
|
+
try {
|
|
463
|
+
symlinkSync(readlinkSync(entryPath), destFilePath);
|
|
464
|
+
} catch (e) {
|
|
465
|
+
throw errnoError(e, "cp", dest);
|
|
466
|
+
}
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
let symlinkTarget;
|
|
470
|
+
try {
|
|
471
|
+
symlinkTarget = readlinkSync(entryPath);
|
|
472
|
+
} catch (e) {
|
|
473
|
+
throw errnoError(e, "cp", dest);
|
|
474
|
+
}
|
|
475
|
+
if (existsPath(destFilePath)) {
|
|
476
|
+
if (isSymlinkPath(destFilePath)) {
|
|
477
|
+
let currentDestSymlinkTarget;
|
|
478
|
+
try {
|
|
479
|
+
currentDestSymlinkTarget = readlinkSync(destFilePath);
|
|
480
|
+
} catch (e) {
|
|
481
|
+
throw errnoError(e, "cp", dest);
|
|
482
|
+
}
|
|
483
|
+
/* (Node's tests the target as written, relative to the working directory) */
|
|
484
|
+
if (!dereference && status(symlinkTarget, true).type === "directory" && isInsideDir(symlinkTarget, currentDestSymlinkTarget)) {
|
|
485
|
+
throw cppError("ERR_FS_CP_EINVAL", `Cannot copy ${symlinkTarget} to a subdirectory of self ${currentDestSymlinkTarget}`);
|
|
486
|
+
}
|
|
487
|
+
// Prevent copy if src is a subdir of dest since unlinking
|
|
488
|
+
// dest in this case would result in removing src contents
|
|
489
|
+
// and therefore a broken symlink would be created.
|
|
490
|
+
if (status(destFilePath, true).type === "directory" && isInsideDir(currentDestSymlinkTarget, symlinkTarget)) {
|
|
491
|
+
throw cppError("ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY", `cannot overwrite ${currentDestSymlinkTarget} with ${symlinkTarget}`);
|
|
492
|
+
}
|
|
493
|
+
// symlinks get overridden by cp even if force: false
|
|
494
|
+
try {
|
|
495
|
+
unlinkSync(destFilePath);
|
|
496
|
+
} catch (e) {
|
|
497
|
+
throw errnoError(e, "cp", dest);
|
|
498
|
+
}
|
|
499
|
+
} else if (isRegularPath(destFilePath)) {
|
|
500
|
+
if (!dereference || (!force && errorOnExist)) throw errnoError("EEXIST", "cp", destFilePath, EEXIST);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
const symlinkTargetAbsolute = weaklyCanonical(isAbsolute(symlinkTarget) ? symlinkTarget : join(src, symlinkTarget));
|
|
504
|
+
try {
|
|
505
|
+
symlinkSync(symlinkTargetAbsolute, destFilePath, isDirectoryPath(entryPath) ? "dir" : "file");
|
|
506
|
+
} catch (e) {
|
|
507
|
+
throw errnoError(e, "cp", dest);
|
|
508
|
+
}
|
|
509
|
+
} else if (entry.type === "directory") {
|
|
510
|
+
try {
|
|
511
|
+
mkdirSync(destFilePath);
|
|
512
|
+
} catch {
|
|
513
|
+
/* (std::filesystem::create_directory: an existing one is fine) */
|
|
514
|
+
}
|
|
515
|
+
copyDirContents(entryPath, destFilePath);
|
|
516
|
+
} else if (entry.type === "regular") {
|
|
517
|
+
const exists = existsPath(destFilePath);
|
|
518
|
+
if (exists && !force) {
|
|
519
|
+
if (errorOnExist) {
|
|
520
|
+
throw cppError("ERR_FS_CP_EEXIST", `[ERR_FS_CP_EEXIST]: Target already exists: cp returned EEXIST (${destFilePath} already exists)`);
|
|
521
|
+
}
|
|
522
|
+
continue; /* skip_existing */
|
|
523
|
+
}
|
|
524
|
+
try {
|
|
525
|
+
copyFileSync(entryPath, destFilePath);
|
|
526
|
+
} catch (e) {
|
|
527
|
+
throw errnoError(e, "cp", dest);
|
|
528
|
+
}
|
|
529
|
+
if (preserveTimestamps) copyUtimes(entryPath, destFilePath);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
copyDirContents(src, dest);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/* ---- cpSync: lib/internal/fs/cp/cp-sync.js ------------------------------------------------- */
|
|
537
|
+
|
|
538
|
+
function cpSyncFn(src, dest, opts) {
|
|
539
|
+
// Warn about using preserveTimestamps on 32-bit node
|
|
540
|
+
if (opts.preserveTimestamps && process.arch === "ia32") {
|
|
541
|
+
process.emitWarning("Using the preserveTimestamps option in 32-bit node is not recommended", "TimestampPrecisionWarning");
|
|
542
|
+
}
|
|
543
|
+
if (opts.filter) {
|
|
544
|
+
const shouldCopy = opts.filter(src, dest);
|
|
545
|
+
if (isPromise(shouldCopy)) throw invalidReturnValue(shouldCopy);
|
|
546
|
+
if (!shouldCopy) return;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
cpSyncCheckPaths(src, dest, opts.dereference, opts.recursive);
|
|
550
|
+
|
|
551
|
+
return getStatsSync(src, dest, opts);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/* ERR_INVALID_RETURN_VALUE, for a filter returning a promise */
|
|
555
|
+
const invalidReturnValue = () =>
|
|
556
|
+
codeError(TypeError, "ERR_INVALID_RETURN_VALUE", 'Expected boolean to be returned from the "filter" function but got an instance of Promise.');
|
|
557
|
+
|
|
558
|
+
function getStatsSync(src, dest, opts) {
|
|
559
|
+
const statSyncFn = opts.dereference ? statSync : lstatSync;
|
|
560
|
+
const srcStat = statSyncFn(src);
|
|
561
|
+
const destStat = statSyncFn(dest, { throwIfNoEntry: false });
|
|
562
|
+
|
|
563
|
+
if (srcStat.isDirectory() && opts.recursive) {
|
|
564
|
+
return onDirSync(srcStat, destStat, src, dest, opts);
|
|
565
|
+
} else if (srcStat.isFile() || srcStat.isCharacterDevice() || srcStat.isBlockDevice()) {
|
|
566
|
+
return onFileSync(srcStat, destStat, src, dest, opts);
|
|
567
|
+
} else if (srcStat.isSymbolicLink()) {
|
|
568
|
+
return onLinkSync(destStat, src, dest, opts.verbatimSymlinks);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
function onFileSync(srcStat, destStat, src, dest, opts) {
|
|
573
|
+
if (!destStat) return copyFileSyncFn(srcStat, src, dest, opts);
|
|
574
|
+
|
|
575
|
+
if (opts.force) {
|
|
576
|
+
return cpSyncOverrideFile(src, dest, opts.mode, opts.preserveTimestamps);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
if (opts.errorOnExist) {
|
|
580
|
+
throw cpError("ERR_FS_CP_EEXIST", { message: `${dest} already exists`, path: dest, syscall: "cp", errno: EEXIST, code: "EEXIST" });
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function copyFileSyncFn(srcStat, src, dest, opts) {
|
|
585
|
+
copyFileSync(src, dest, opts.mode);
|
|
586
|
+
if (opts.preserveTimestamps) handleTimestampsSync(srcStat.mode, src, dest);
|
|
587
|
+
return chmodSync(dest, srcStat.mode);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function handleTimestampsSync(srcMode, src, dest) {
|
|
591
|
+
// Make sure the file is writable before setting the timestamp
|
|
592
|
+
// otherwise open fails with EPERM when invoked with 'r+'
|
|
593
|
+
// (through utimes call)
|
|
594
|
+
if (fileIsNotWritable(srcMode)) chmodSync(dest, srcMode | 0o200);
|
|
595
|
+
const updatedSrcStat = statSync(src);
|
|
596
|
+
return utimesSync(dest, updatedSrcStat.atime, updatedSrcStat.mtime);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function onDirSync(srcStat, destStat, src, dest, opts) {
|
|
600
|
+
if (!destStat) return copyDirSync(src, dest, opts, true, srcStat.mode);
|
|
601
|
+
return copyDirSync(src, dest, opts);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function copyDirSync(src, dest, opts, mkDir, srcMode) {
|
|
605
|
+
if (!opts.filter) {
|
|
606
|
+
// The caller didn't provide a js filter function, in this case
|
|
607
|
+
// we can run the whole function faster in C++
|
|
608
|
+
return cpSyncCopyDir(src, dest, opts.force, opts.dereference, opts.errorOnExist, opts.verbatimSymlinks, opts.preserveTimestamps);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
if (mkDir) {
|
|
612
|
+
mkdirSync(dest);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
try {
|
|
616
|
+
for (const name of readdirSync(src)) {
|
|
617
|
+
const srcItem = join(src, name);
|
|
618
|
+
const destItem = join(dest, name);
|
|
619
|
+
let shouldCopy = true;
|
|
620
|
+
|
|
621
|
+
if (opts.filter) {
|
|
622
|
+
shouldCopy = opts.filter(srcItem, destItem);
|
|
623
|
+
if (isPromise(shouldCopy)) throw invalidReturnValue(shouldCopy);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
if (shouldCopy) {
|
|
627
|
+
getStatsSync(srcItem, destItem, opts);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
} finally {
|
|
631
|
+
if (srcMode !== undefined) {
|
|
632
|
+
chmodSync(dest, srcMode);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function onLinkSync(destStat, src, dest, verbatimSymlinks) {
|
|
638
|
+
let resolvedSrc = readlinkSync(src);
|
|
639
|
+
if (!verbatimSymlinks && !isAbsolute(resolvedSrc)) {
|
|
640
|
+
resolvedSrc = resolve(dirname(src), resolvedSrc);
|
|
641
|
+
}
|
|
642
|
+
const srcIsDir = isDirectoryPath(src);
|
|
643
|
+
const symlinkType = srcIsDir ? "dir" : "file";
|
|
644
|
+
if (!destStat) {
|
|
645
|
+
return symlinkSync(resolvedSrc, dest, symlinkType);
|
|
646
|
+
}
|
|
647
|
+
let resolvedDest;
|
|
648
|
+
try {
|
|
649
|
+
resolvedDest = readlinkSync(dest);
|
|
650
|
+
} catch (err) {
|
|
651
|
+
// Dest exists and is a regular file or directory,
|
|
652
|
+
// Windows may throw UNKNOWN error. If dest already exists,
|
|
653
|
+
// fs throws error anyway, so no need to guard against it here.
|
|
654
|
+
if (err.code === "EINVAL" || err.code === "UNKNOWN") {
|
|
655
|
+
return symlinkSync(resolvedSrc, dest, symlinkType);
|
|
656
|
+
}
|
|
657
|
+
throw err;
|
|
658
|
+
}
|
|
659
|
+
if (!isAbsolute(resolvedDest)) {
|
|
660
|
+
resolvedDest = resolve(dirname(dest), resolvedDest);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
if (srcIsDir && isSrcSubdir(resolvedSrc, resolvedDest)) {
|
|
664
|
+
throw cpError("ERR_FS_CP_EINVAL", {
|
|
665
|
+
message: `cannot copy ${resolvedSrc} to a subdirectory of self ${resolvedDest}`, path: dest, syscall: "cp", errno: EINVAL, code: "EINVAL",
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
// Prevent copy if src is a subdir of dest since unlinking
|
|
669
|
+
// dest in this case would result in removing src contents
|
|
670
|
+
// and therefore a broken symlink would be created.
|
|
671
|
+
if (statSync(dest).isDirectory() && isSrcSubdir(resolvedDest, resolvedSrc)) {
|
|
672
|
+
throw cpError("ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY", {
|
|
673
|
+
message: `cannot overwrite ${resolvedDest} with ${resolvedSrc}`, path: dest, syscall: "cp", errno: EINVAL, code: "EINVAL",
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
unlinkSync(dest);
|
|
677
|
+
return symlinkSync(resolvedSrc, dest, symlinkType);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/* ---- the entry points: lib/fs.js's and lib/internal/fs/promises.js' ------------------------- */
|
|
681
|
+
|
|
682
|
+
function cpSync(src, dest, options) {
|
|
683
|
+
options = validateCpOptions(options);
|
|
684
|
+
src = getValidatedPath(src, "src");
|
|
685
|
+
dest = getValidatedPath(dest, "dest");
|
|
686
|
+
cpSyncFn(src, dest, options);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/* (callbackify(cpFn), as Node's) */
|
|
690
|
+
function cp(src, dest, options, callback) {
|
|
691
|
+
if (typeof options === "function") {
|
|
692
|
+
callback = options;
|
|
693
|
+
options = undefined;
|
|
694
|
+
}
|
|
695
|
+
validateFunction(callback, "cb");
|
|
696
|
+
options = validateCpOptions(options);
|
|
697
|
+
src = getValidatedPath(src, "src");
|
|
698
|
+
dest = getValidatedPath(dest, "dest");
|
|
699
|
+
cpFn(src, dest, options).then((value) => process.nextTick(callback, null, value), (err) => process.nextTick(callback, err));
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
async function cpPromise(src, dest, options) {
|
|
703
|
+
options = validateCpOptions(options);
|
|
704
|
+
src = getValidatedPath(src, "src");
|
|
705
|
+
dest = getValidatedPath(dest, "dest");
|
|
706
|
+
return cpFn(src, dest, options);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
Object.assign(features, { cpSync, cp, cpPromise });
|