@volter/tabnode 0.2.14-volter.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +78 -0
- package/THIRD-PARTY-NOTICES.md +12 -0
- package/dist/__sw__.js +526 -0
- package/dist/assets/runtime-worker-4MKaHFVb.js +75221 -0
- package/dist/assets/runtime-worker-4MKaHFVb.js.map +1 -0
- package/dist/code-transforms.d.ts +21 -0
- package/dist/code-transforms.d.ts.map +1 -0
- package/dist/config/cdn.d.ts +12 -0
- package/dist/config/cdn.d.ts.map +1 -0
- package/dist/create-runtime.d.ts +22 -0
- package/dist/create-runtime.d.ts.map +1 -0
- package/dist/host-globals.d.ts +62 -0
- package/dist/host-globals.d.ts.map +1 -0
- package/dist/index.cjs +36021 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +127 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +36020 -0
- package/dist/index.mjs.map +1 -0
- package/dist/node-internals.d.ts +68 -0
- package/dist/node-internals.d.ts.map +1 -0
- package/dist/node-lib/binding/blob.d.ts +12 -0
- package/dist/node-lib/binding/blob.d.ts.map +1 -0
- package/dist/node-lib/binding/buffer.d.ts +144 -0
- package/dist/node-lib/binding/buffer.d.ts.map +1 -0
- package/dist/node-lib/binding/cares_wrap.d.ts +14 -0
- package/dist/node-lib/binding/cares_wrap.d.ts.map +1 -0
- package/dist/node-lib/binding/fds.d.ts +30 -0
- package/dist/node-lib/binding/fds.d.ts.map +1 -0
- package/dist/node-lib/binding/fs.d.ts +157 -0
- package/dist/node-lib/binding/fs.d.ts.map +1 -0
- package/dist/node-lib/binding/handles.d.ts +81 -0
- package/dist/node-lib/binding/handles.d.ts.map +1 -0
- package/dist/node-lib/binding/http_parser.d.ts +122 -0
- package/dist/node-lib/binding/http_parser.d.ts.map +1 -0
- package/dist/node-lib/binding/index.d.ts +3 -0
- package/dist/node-lib/binding/index.d.ts.map +1 -0
- package/dist/node-lib/binding/llhttp-wasm.d.ts +22 -0
- package/dist/node-lib/binding/llhttp-wasm.d.ts.map +1 -0
- package/dist/node-lib/binding/misc.d.ts +123 -0
- package/dist/node-lib/binding/misc.d.ts.map +1 -0
- package/dist/node-lib/binding/pipe_wrap.d.ts +84 -0
- package/dist/node-lib/binding/pipe_wrap.d.ts.map +1 -0
- package/dist/node-lib/binding/process_wrap.d.ts +173 -0
- package/dist/node-lib/binding/process_wrap.d.ts.map +1 -0
- package/dist/node-lib/binding/spawn_sync.d.ts +30 -0
- package/dist/node-lib/binding/spawn_sync.d.ts.map +1 -0
- package/dist/node-lib/binding/stream_wrap.d.ts +191 -0
- package/dist/node-lib/binding/stream_wrap.d.ts.map +1 -0
- package/dist/node-lib/binding/stubs.d.ts +23 -0
- package/dist/node-lib/binding/stubs.d.ts.map +1 -0
- package/dist/node-lib/binding/tcp_wrap.d.ts +98 -0
- package/dist/node-lib/binding/tcp_wrap.d.ts.map +1 -0
- package/dist/node-lib/binding/tty_wrap.d.ts +36 -0
- package/dist/node-lib/binding/tty_wrap.d.ts.map +1 -0
- package/dist/node-lib/binding/util.d.ts +126 -0
- package/dist/node-lib/binding/util.d.ts.map +1 -0
- package/dist/node-lib/binding/uv.d.ts +32 -0
- package/dist/node-lib/binding/uv.d.ts.map +1 -0
- package/dist/node-lib/binding/zlib-pako.d.ts +22 -0
- package/dist/node-lib/binding/zlib-pako.d.ts.map +1 -0
- package/dist/node-lib/binding/zlib.d.ts +38 -0
- package/dist/node-lib/binding/zlib.d.ts.map +1 -0
- package/dist/node-lib/buffer-module.d.ts +51 -0
- package/dist/node-lib/buffer-module.d.ts.map +1 -0
- package/dist/node-lib/child-process-module.d.ts +26 -0
- package/dist/node-lib/child-process-module.d.ts.map +1 -0
- package/dist/node-lib/events-module.d.ts +58 -0
- package/dist/node-lib/events-module.d.ts.map +1 -0
- package/dist/node-lib/fs-module.d.ts +5 -0
- package/dist/node-lib/fs-module.d.ts.map +1 -0
- package/dist/node-lib/http-bridge.d.ts +43 -0
- package/dist/node-lib/http-bridge.d.ts.map +1 -0
- package/dist/node-lib/http-module.d.ts +35 -0
- package/dist/node-lib/http-module.d.ts.map +1 -0
- package/dist/node-lib/internals/addresses.d.ts +40 -0
- package/dist/node-lib/internals/addresses.d.ts.map +1 -0
- package/dist/node-lib/internals/buffer-and-streams.d.ts +96 -0
- package/dist/node-lib/internals/buffer-and-streams.d.ts.map +1 -0
- package/dist/node-lib/internals/child-process.d.ts +27 -0
- package/dist/node-lib/internals/child-process.d.ts.map +1 -0
- package/dist/node-lib/internals/events-util.d.ts +83 -0
- package/dist/node-lib/internals/events-util.d.ts.map +1 -0
- package/dist/node-lib/internals/index.d.ts +2 -0
- package/dist/node-lib/internals/index.d.ts.map +1 -0
- package/dist/node-lib/internals/modules.d.ts +67 -0
- package/dist/node-lib/internals/modules.d.ts.map +1 -0
- package/dist/node-lib/internals/readline-access.d.ts +2 -0
- package/dist/node-lib/internals/readline-access.d.ts.map +1 -0
- package/dist/node-lib/internals/runtime.d.ts +150 -0
- package/dist/node-lib/internals/runtime.d.ts.map +1 -0
- package/dist/node-lib/internals/util.d.ts +33 -0
- package/dist/node-lib/internals/util.d.ts.map +1 -0
- package/dist/node-lib/lazy.d.ts +31 -0
- package/dist/node-lib/lazy.d.ts.map +1 -0
- package/dist/node-lib/load.d.ts +27 -0
- package/dist/node-lib/load.d.ts.map +1 -0
- package/dist/node-lib/module-hooks.d.ts +89 -0
- package/dist/node-lib/module-hooks.d.ts.map +1 -0
- package/dist/node-lib/net-module.d.ts +181 -0
- package/dist/node-lib/net-module.d.ts.map +1 -0
- package/dist/node-lib/node-versions.d.ts +27 -0
- package/dist/node-lib/node-versions.d.ts.map +1 -0
- package/dist/node-lib/public-modules.d.ts +2 -0
- package/dist/node-lib/public-modules.d.ts.map +1 -0
- package/dist/node-lib/require-hook.d.ts +15 -0
- package/dist/node-lib/require-hook.d.ts.map +1 -0
- package/dist/node-lib/small-modules.d.ts +16 -0
- package/dist/node-lib/small-modules.d.ts.map +1 -0
- package/dist/node-lib/sources.d.ts +4 -0
- package/dist/node-lib/sources.d.ts.map +1 -0
- package/dist/node-lib/stream-module.d.ts +77 -0
- package/dist/node-lib/stream-module.d.ts.map +1 -0
- package/dist/node-lib/timers.d.ts +19 -0
- package/dist/node-lib/timers.d.ts.map +1 -0
- package/dist/node-lib/util-module.d.ts +76 -0
- package/dist/node-lib/util-module.d.ts.map +1 -0
- package/dist/node-resolution.d.ts +50 -0
- package/dist/node-resolution.d.ts.map +1 -0
- package/dist/node-resolver.d.ts +7 -0
- package/dist/node-resolver.d.ts.map +1 -0
- package/dist/npm/index.d.ts +73 -0
- package/dist/npm/index.d.ts.map +1 -0
- package/dist/npm/registry.d.ts +111 -0
- package/dist/npm/registry.d.ts.map +1 -0
- package/dist/npm/resolver.d.ts +79 -0
- package/dist/npm/resolver.d.ts.map +1 -0
- package/dist/npm/tarball.d.ts +28 -0
- package/dist/npm/tarball.d.ts.map +1 -0
- package/dist/process-tokens.d.ts +77 -0
- package/dist/process-tokens.d.ts.map +1 -0
- package/dist/punycode-source.d.ts +3 -0
- package/dist/punycode-source.d.ts.map +1 -0
- package/dist/runtime-interface.d.ts +74 -0
- package/dist/runtime-interface.d.ts.map +1 -0
- package/dist/runtime.d.ts +144 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/server-bridge.d.ts +147 -0
- package/dist/server-bridge.d.ts.map +1 -0
- package/dist/shims/async_hooks.d.ts +50 -0
- package/dist/shims/async_hooks.d.ts.map +1 -0
- package/dist/shims/child_process.d.ts +104 -0
- package/dist/shims/child_process.d.ts.map +1 -0
- package/dist/shims/cluster.d.ts +52 -0
- package/dist/shims/cluster.d.ts.map +1 -0
- package/dist/shims/command-line.d.ts +43 -0
- package/dist/shims/command-line.d.ts.map +1 -0
- package/dist/shims/constants.d.ts +222 -0
- package/dist/shims/constants.d.ts.map +1 -0
- package/dist/shims/crypto-constants.d.ts +12 -0
- package/dist/shims/crypto-constants.d.ts.map +1 -0
- package/dist/shims/crypto.d.ts +144 -0
- package/dist/shims/crypto.d.ts.map +1 -0
- package/dist/shims/dgram.d.ts +34 -0
- package/dist/shims/dgram.d.ts.map +1 -0
- package/dist/shims/dns.d.ts +91 -0
- package/dist/shims/dns.d.ts.map +1 -0
- package/dist/shims/domain.d.ts +25 -0
- package/dist/shims/domain.d.ts.map +1 -0
- package/dist/shims/esbuild.d.ts +205 -0
- package/dist/shims/esbuild.d.ts.map +1 -0
- package/dist/shims/fs.d.ts +25 -0
- package/dist/shims/fs.d.ts.map +1 -0
- package/dist/shims/http2.d.ts +81 -0
- package/dist/shims/http2.d.ts.map +1 -0
- package/dist/shims/inspector.d.ts +25 -0
- package/dist/shims/inspector.d.ts.map +1 -0
- package/dist/shims/module.d.ts +22 -0
- package/dist/shims/module.d.ts.map +1 -0
- package/dist/shims/os.d.ts +159 -0
- package/dist/shims/os.d.ts.map +1 -0
- package/dist/shims/path.d.ts +52 -0
- package/dist/shims/path.d.ts.map +1 -0
- package/dist/shims/perf_hooks.d.ts +50 -0
- package/dist/shims/perf_hooks.d.ts.map +1 -0
- package/dist/shims/process.d.ts +226 -0
- package/dist/shims/process.d.ts.map +1 -0
- package/dist/shims/rollup.d.ts +71 -0
- package/dist/shims/rollup.d.ts.map +1 -0
- package/dist/shims/string_decoder.d.ts +41 -0
- package/dist/shims/string_decoder.d.ts.map +1 -0
- package/dist/shims/sync-child.d.ts +64 -0
- package/dist/shims/sync-child.d.ts.map +1 -0
- package/dist/shims/tls.d.ts +53 -0
- package/dist/shims/tls.d.ts.map +1 -0
- package/dist/shims/url.d.ts +84 -0
- package/dist/shims/url.d.ts.map +1 -0
- package/dist/shims/v8.d.ts +73 -0
- package/dist/shims/v8.d.ts.map +1 -0
- package/dist/shims/vfs-adapter.d.ts +126 -0
- package/dist/shims/vfs-adapter.d.ts.map +1 -0
- package/dist/shims/vm.d.ts +52 -0
- package/dist/shims/vm.d.ts.map +1 -0
- package/dist/shims/wasi.d.ts +78 -0
- package/dist/shims/wasi.d.ts.map +1 -0
- package/dist/shims/worker_threads.d.ts +66 -0
- package/dist/shims/worker_threads.d.ts.map +1 -0
- package/dist/shims/zlib-constants.d.ts +66 -0
- package/dist/shims/zlib-constants.d.ts.map +1 -0
- package/dist/shims/zlib.d.ts +102 -0
- package/dist/shims/zlib.d.ts.map +1 -0
- package/dist/transform.d.ts +24 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/types/package-json.d.ts +18 -0
- package/dist/types/package-json.d.ts.map +1 -0
- package/dist/utils/binary-encoding.d.ts +13 -0
- package/dist/utils/binary-encoding.d.ts.map +1 -0
- package/dist/utils/glob.d.ts +19 -0
- package/dist/utils/glob.d.ts.map +1 -0
- package/dist/utils/hash.d.ts +6 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/virtual-fs.d.ts +259 -0
- package/dist/virtual-fs.d.ts.map +1 -0
- package/dist/vite-plugin.cjs +50 -0
- package/dist/vite-plugin.cjs.map +1 -0
- package/dist/vite-plugin.d.ts +36 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.mjs +31 -0
- package/dist/vite-plugin.mjs.map +1 -0
- package/dist/worker/runtime-worker.d.ts +8 -0
- package/dist/worker/runtime-worker.d.ts.map +1 -0
- package/dist/worker-runtime.d.ts +50 -0
- package/dist/worker-runtime.d.ts.map +1 -0
- package/package.json +88 -0
- package/src/code-transforms.ts +560 -0
- package/src/config/cdn.ts +13 -0
- package/src/create-runtime.ts +89 -0
- package/src/host-globals.ts +121 -0
- package/src/index.ts +235 -0
- package/src/node-internals.ts +283 -0
- package/src/node-lib/LICENSE +47 -0
- package/src/node-lib/_http_agent.js +547 -0
- package/src/node-lib/_http_client.js +996 -0
- package/src/node-lib/_http_common.js +269 -0
- package/src/node-lib/_http_incoming.js +453 -0
- package/src/node-lib/_http_outgoing.js +1262 -0
- package/src/node-lib/_http_server.js +1230 -0
- package/src/node-lib/assert/strict.js +3 -0
- package/src/node-lib/assert.js +844 -0
- package/src/node-lib/binding/blob.ts +35 -0
- package/src/node-lib/binding/buffer.ts +465 -0
- package/src/node-lib/binding/cares_wrap.ts +57 -0
- package/src/node-lib/binding/fds.ts +80 -0
- package/src/node-lib/binding/fs.ts +857 -0
- package/src/node-lib/binding/handles.ts +187 -0
- package/src/node-lib/binding/http_parser.ts +536 -0
- package/src/node-lib/binding/index.ts +77 -0
- package/src/node-lib/binding/llhttp-wasm.ts +670 -0
- package/src/node-lib/binding/misc.ts +252 -0
- package/src/node-lib/binding/pipe_wrap.ts +166 -0
- package/src/node-lib/binding/process_wrap.ts +371 -0
- package/src/node-lib/binding/spawn_sync.ts +141 -0
- package/src/node-lib/binding/stream_wrap.ts +413 -0
- package/src/node-lib/binding/stubs.ts +19 -0
- package/src/node-lib/binding/tcp_wrap.ts +254 -0
- package/src/node-lib/binding/tty_wrap.ts +56 -0
- package/src/node-lib/binding/util.ts +274 -0
- package/src/node-lib/binding/uv.ts +102 -0
- package/src/node-lib/binding/zlib-pako.ts +50 -0
- package/src/node-lib/binding/zlib.ts +259 -0
- package/src/node-lib/buffer-module.ts +70 -0
- package/src/node-lib/buffer.js +1373 -0
- package/src/node-lib/child-process-module.ts +58 -0
- package/src/node-lib/child_process.js +1046 -0
- package/src/node-lib/constants.js +41 -0
- package/src/node-lib/diagnostics_channel.js +438 -0
- package/src/node-lib/events-module.ts +80 -0
- package/src/node-lib/events.js +1223 -0
- package/src/node-lib/fs-module.ts +43 -0
- package/src/node-lib/fs.js +3377 -0
- package/src/node-lib/http-bridge.ts +299 -0
- package/src/node-lib/http-module.ts +53 -0
- package/src/node-lib/http.js +198 -0
- package/src/node-lib/https.js +429 -0
- package/src/node-lib/internal/assert/assertion_error.js +417 -0
- package/src/node-lib/internal/assert/calltracker.js +153 -0
- package/src/node-lib/internal/assert/myers_diff.js +177 -0
- package/src/node-lib/internal/assert/utils.js +278 -0
- package/src/node-lib/internal/buffer.js +1120 -0
- package/src/node-lib/internal/child_process/serialization.js +169 -0
- package/src/node-lib/internal/child_process.js +1135 -0
- package/src/node-lib/internal/constants.js +56 -0
- package/src/node-lib/internal/deps/minimatch/index.js +1628 -0
- package/src/node-lib/internal/errors.js +1912 -0
- package/src/node-lib/internal/events/abort_listener.js +54 -0
- package/src/node-lib/internal/events/symbols.js +11 -0
- package/src/node-lib/internal/fixed_queue.js +119 -0
- package/src/node-lib/internal/freelist.js +30 -0
- package/src/node-lib/internal/fs/cp/cp-sync.js +242 -0
- package/src/node-lib/internal/fs/cp/cp.js +382 -0
- package/src/node-lib/internal/fs/dir.js +369 -0
- package/src/node-lib/internal/fs/glob.js +763 -0
- package/src/node-lib/internal/fs/promises.js +1312 -0
- package/src/node-lib/internal/fs/read/context.js +129 -0
- package/src/node-lib/internal/fs/recursive_watch.js +275 -0
- package/src/node-lib/internal/fs/rimraf.js +311 -0
- package/src/node-lib/internal/fs/streams.js +571 -0
- package/src/node-lib/internal/fs/sync_write_stream.js +49 -0
- package/src/node-lib/internal/fs/utils.js +987 -0
- package/src/node-lib/internal/fs/watchers.js +418 -0
- package/src/node-lib/internal/http.js +62 -0
- package/src/node-lib/internal/mime.js +389 -0
- package/src/node-lib/internal/modules/customization_hooks.js +406 -0
- package/src/node-lib/internal/net.js +95 -0
- package/src/node-lib/internal/querystring.js +119 -0
- package/src/node-lib/internal/readline/callbacks.js +132 -0
- package/src/node-lib/internal/readline/emitKeypressEvents.js +99 -0
- package/src/node-lib/internal/readline/interface.js +1418 -0
- package/src/node-lib/internal/readline/promises.js +144 -0
- package/src/node-lib/internal/readline/utils.js +405 -0
- package/src/node-lib/internal/socket_list.js +108 -0
- package/src/node-lib/internal/stream_base_commons.js +280 -0
- package/src/node-lib/internal/streams/add-abort-signal.js +60 -0
- package/src/node-lib/internal/streams/compose.js +257 -0
- package/src/node-lib/internal/streams/destroy.js +361 -0
- package/src/node-lib/internal/streams/duplex.js +203 -0
- package/src/node-lib/internal/streams/duplexify.js +379 -0
- package/src/node-lib/internal/streams/duplexpair.js +62 -0
- package/src/node-lib/internal/streams/end-of-stream.js +331 -0
- package/src/node-lib/internal/streams/from.js +208 -0
- package/src/node-lib/internal/streams/lazy_transform.js +57 -0
- package/src/node-lib/internal/streams/legacy.js +125 -0
- package/src/node-lib/internal/streams/operators.js +436 -0
- package/src/node-lib/internal/streams/passthrough.js +47 -0
- package/src/node-lib/internal/streams/pipeline.js +465 -0
- package/src/node-lib/internal/streams/readable.js +1762 -0
- package/src/node-lib/internal/streams/state.js +51 -0
- package/src/node-lib/internal/streams/transform.js +204 -0
- package/src/node-lib/internal/streams/utils.js +363 -0
- package/src/node-lib/internal/streams/writable.js +1163 -0
- package/src/node-lib/internal/tty.js +260 -0
- package/src/node-lib/internal/util/colors.js +40 -0
- package/src/node-lib/internal/util/comparisons.js +1028 -0
- package/src/node-lib/internal/util/debuglog.js +524 -0
- package/src/node-lib/internal/util/inspect.js +2535 -0
- package/src/node-lib/internal/util/parse_args/parse_args.js +412 -0
- package/src/node-lib/internal/util/parse_args/utils.js +197 -0
- package/src/node-lib/internal/util.js +1003 -0
- package/src/node-lib/internal/validators.js +654 -0
- package/src/node-lib/internals/addresses.ts +159 -0
- package/src/node-lib/internals/buffer-and-streams.ts +224 -0
- package/src/node-lib/internals/child-process.ts +64 -0
- package/src/node-lib/internals/events-util.ts +105 -0
- package/src/node-lib/internals/index.ts +66 -0
- package/src/node-lib/internals/modules.ts +117 -0
- package/src/node-lib/internals/readline-access.ts +16 -0
- package/src/node-lib/internals/runtime.ts +277 -0
- package/src/node-lib/internals/util.ts +98 -0
- package/src/node-lib/lazy.ts +158 -0
- package/src/node-lib/load.ts +390 -0
- package/src/node-lib/module-hooks.ts +281 -0
- package/src/node-lib/net-module.ts +248 -0
- package/src/node-lib/net.js +2540 -0
- package/src/node-lib/node-versions.ts +34 -0
- package/src/node-lib/os.js +356 -0
- package/src/node-lib/path.js +1694 -0
- package/src/node-lib/primordials.js +743 -0
- package/src/node-lib/public-modules.ts +109 -0
- package/src/node-lib/punycode.js +455 -0
- package/src/node-lib/querystring.js +484 -0
- package/src/node-lib/readline/promises.js +73 -0
- package/src/node-lib/readline.js +523 -0
- package/src/node-lib/require-hook.ts +27 -0
- package/src/node-lib/small-modules.ts +35 -0
- package/src/node-lib/sources.ts +200 -0
- package/src/node-lib/stream/promises.js +44 -0
- package/src/node-lib/stream-module.ts +101 -0
- package/src/node-lib/stream.js +152 -0
- package/src/node-lib/timers.ts +33 -0
- package/src/node-lib/tty.js +168 -0
- package/src/node-lib/util-module.ts +104 -0
- package/src/node-lib/util.js +689 -0
- package/src/node-lib/wasi.js +179 -0
- package/src/node-lib/zlib.js +1036 -0
- package/src/node-resolution.ts +241 -0
- package/src/node-resolver.ts +33 -0
- package/src/npm/index.ts +425 -0
- package/src/npm/registry.ts +235 -0
- package/src/npm/resolver.ts +589 -0
- package/src/npm/tarball.ts +246 -0
- package/src/process-tokens.ts +156 -0
- package/src/punycode-source.ts +6 -0
- package/src/runtime-interface.ts +85 -0
- package/src/runtime.ts +3073 -0
- package/src/server-bridge.ts +971 -0
- package/src/shims/async_hooks.ts +181 -0
- package/src/shims/child_process.ts +1591 -0
- package/src/shims/cluster.ts +79 -0
- package/src/shims/command-line.ts +79 -0
- package/src/shims/constants.ts +68 -0
- package/src/shims/crypto-constants.ts +11 -0
- package/src/shims/crypto.ts +1061 -0
- package/src/shims/dgram.ts +47 -0
- package/src/shims/dns.ts +185 -0
- package/src/shims/domain.ts +58 -0
- package/src/shims/esbuild.ts +1638 -0
- package/src/shims/fs.ts +82 -0
- package/src/shims/http2.ts +96 -0
- package/src/shims/inspector.ts +30 -0
- package/src/shims/module.ts +86 -0
- package/src/shims/os.ts +195 -0
- package/src/shims/path.ts +246 -0
- package/src/shims/perf_hooks.ts +92 -0
- package/src/shims/process.ts +804 -0
- package/src/shims/rollup.ts +149 -0
- package/src/shims/string_decoder.ts +396 -0
- package/src/shims/sync-child.ts +469 -0
- package/src/shims/tls.ts +94 -0
- package/src/shims/url.ts +217 -0
- package/src/shims/v8.ts +113 -0
- package/src/shims/vfs-adapter.ts +408 -0
- package/src/shims/vm.ts +132 -0
- package/src/shims/wasi.ts +1440 -0
- package/src/shims/worker_threads.ts +114 -0
- package/src/shims/zlib-constants.ts +65 -0
- package/src/shims/zlib.ts +228 -0
- package/src/transform.ts +324 -0
- package/src/types/external.d.ts +55 -0
- package/src/types/package-json.ts +17 -0
- package/src/types/pako-zlib.d.ts +30 -0
- package/src/types/sha.js.d.ts +14 -0
- package/src/utils/binary-encoding.ts +43 -0
- package/src/utils/glob.ts +54 -0
- package/src/utils/hash.ts +12 -0
- package/src/virtual-fs.ts +1048 -0
- package/src/vite-plugin.ts +76 -0
- package/src/worker/runtime-worker.ts +128 -0
- package/src/worker-runtime.ts +145 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
ArrayPrototypeJoin,
|
|
5
|
+
ArrayPrototypePop,
|
|
6
|
+
ArrayPrototypeSlice,
|
|
7
|
+
Error,
|
|
8
|
+
ErrorCaptureStackTrace,
|
|
9
|
+
ObjectAssign,
|
|
10
|
+
ObjectDefineProperty,
|
|
11
|
+
ObjectGetPrototypeOf,
|
|
12
|
+
ObjectPrototypeHasOwnProperty,
|
|
13
|
+
String,
|
|
14
|
+
StringPrototypeRepeat,
|
|
15
|
+
StringPrototypeSlice,
|
|
16
|
+
StringPrototypeSplit,
|
|
17
|
+
} = primordials;
|
|
18
|
+
|
|
19
|
+
const { isError } = require('internal/util');
|
|
20
|
+
|
|
21
|
+
const { inspect } = require('internal/util/inspect');
|
|
22
|
+
const colors = require('internal/util/colors');
|
|
23
|
+
const { validateObject } = require('internal/validators');
|
|
24
|
+
const { isErrorStackTraceLimitWritable } = require('internal/errors');
|
|
25
|
+
const { myersDiff, printMyersDiff, printSimpleMyersDiff } = require('internal/assert/myers_diff');
|
|
26
|
+
|
|
27
|
+
const kReadableOperator = {
|
|
28
|
+
deepStrictEqual: 'Expected values to be strictly deep-equal:',
|
|
29
|
+
partialDeepStrictEqual: 'Expected values to be partially and strictly deep-equal:',
|
|
30
|
+
strictEqual: 'Expected values to be strictly equal:',
|
|
31
|
+
strictEqualObject: 'Expected "actual" to be reference-equal to "expected":',
|
|
32
|
+
deepEqual: 'Expected values to be loosely deep-equal:',
|
|
33
|
+
notDeepStrictEqual: 'Expected "actual" not to be strictly deep-equal to:',
|
|
34
|
+
notStrictEqual: 'Expected "actual" to be strictly unequal to:',
|
|
35
|
+
notStrictEqualObject:
|
|
36
|
+
'Expected "actual" not to be reference-equal to "expected":',
|
|
37
|
+
notDeepEqual: 'Expected "actual" not to be loosely deep-equal to:',
|
|
38
|
+
notIdentical: 'Values have same structure but are not reference-equal:',
|
|
39
|
+
notDeepEqualUnequal: 'Expected values not to be loosely deep-equal:',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const kMaxShortStringLength = 12;
|
|
43
|
+
const kMaxLongStringLength = 512;
|
|
44
|
+
|
|
45
|
+
const kMethodsWithCustomMessageDiff = ['deepStrictEqual', 'strictEqual', 'partialDeepStrictEqual'];
|
|
46
|
+
|
|
47
|
+
function copyError(source) {
|
|
48
|
+
const target = ObjectAssign(
|
|
49
|
+
{ __proto__: ObjectGetPrototypeOf(source) },
|
|
50
|
+
source,
|
|
51
|
+
);
|
|
52
|
+
ObjectDefineProperty(target, 'message', {
|
|
53
|
+
__proto__: null,
|
|
54
|
+
value: source.message,
|
|
55
|
+
});
|
|
56
|
+
if (ObjectPrototypeHasOwnProperty(source, 'cause')) {
|
|
57
|
+
let { cause } = source;
|
|
58
|
+
|
|
59
|
+
if (isError(cause)) {
|
|
60
|
+
cause = copyError(cause);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
ObjectDefineProperty(target, 'cause', { __proto__: null, value: cause });
|
|
64
|
+
}
|
|
65
|
+
return target;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function inspectValue(val) {
|
|
69
|
+
// The util.inspect default values could be changed. This makes sure the
|
|
70
|
+
// error messages contain the necessary information nevertheless.
|
|
71
|
+
return inspect(val, {
|
|
72
|
+
compact: false,
|
|
73
|
+
customInspect: false,
|
|
74
|
+
depth: 1000,
|
|
75
|
+
maxArrayLength: Infinity,
|
|
76
|
+
// Assert compares only enumerable properties (with a few exceptions).
|
|
77
|
+
showHidden: false,
|
|
78
|
+
// Assert does not detect proxies currently.
|
|
79
|
+
showProxy: false,
|
|
80
|
+
sorted: true,
|
|
81
|
+
// Inspect getters as we also check them when comparing entries.
|
|
82
|
+
getters: true,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getErrorMessage(operator, message) {
|
|
87
|
+
return message || kReadableOperator[operator];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function checkOperator(actual, expected, operator) {
|
|
91
|
+
// In case both values are objects or functions explicitly mark them as not
|
|
92
|
+
// reference equal for the `strictEqual` operator.
|
|
93
|
+
if (
|
|
94
|
+
operator === 'strictEqual' &&
|
|
95
|
+
((typeof actual === 'object' &&
|
|
96
|
+
actual !== null &&
|
|
97
|
+
typeof expected === 'object' &&
|
|
98
|
+
expected !== null) ||
|
|
99
|
+
(typeof actual === 'function' && typeof expected === 'function'))
|
|
100
|
+
) {
|
|
101
|
+
operator = 'strictEqualObject';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return operator;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function getColoredMyersDiff(actual, expected) {
|
|
108
|
+
const header = `${colors.green}actual${colors.white} ${colors.red}expected${colors.white}`;
|
|
109
|
+
const skipped = false;
|
|
110
|
+
|
|
111
|
+
const diff = myersDiff(StringPrototypeSplit(actual, ''), StringPrototypeSplit(expected, ''));
|
|
112
|
+
let message = printSimpleMyersDiff(diff);
|
|
113
|
+
|
|
114
|
+
if (skipped) {
|
|
115
|
+
message += '...';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return { message, header, skipped };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function getStackedDiff(actual, expected) {
|
|
122
|
+
const isStringComparison = typeof actual === 'string' && typeof expected === 'string';
|
|
123
|
+
|
|
124
|
+
let message = `\n${colors.green}+${colors.white} ${actual}\n${colors.red}- ${colors.white}${expected}`;
|
|
125
|
+
const stringsLen = actual.length + expected.length;
|
|
126
|
+
const maxTerminalLength = process.stderr.isTTY ? process.stderr.columns : 80;
|
|
127
|
+
const showIndicator = isStringComparison && (stringsLen <= maxTerminalLength);
|
|
128
|
+
|
|
129
|
+
if (showIndicator) {
|
|
130
|
+
let indicatorIdx = -1;
|
|
131
|
+
|
|
132
|
+
for (let i = 0; i < actual.length; i++) {
|
|
133
|
+
if (actual[i] !== expected[i]) {
|
|
134
|
+
// Skip the indicator for the first 2 characters because the diff is immediately apparent
|
|
135
|
+
// It is 3 instead of 2 to account for the quotes
|
|
136
|
+
if (i >= 3) {
|
|
137
|
+
indicatorIdx = i;
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (indicatorIdx !== -1) {
|
|
144
|
+
message += `\n${StringPrototypeRepeat(' ', indicatorIdx + 2)}^`;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return { message };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function getSimpleDiff(originalActual, actual, originalExpected, expected) {
|
|
152
|
+
let stringsLen = actual.length + expected.length;
|
|
153
|
+
// Accounting for the quotes wrapping strings
|
|
154
|
+
if (typeof originalActual === 'string') {
|
|
155
|
+
stringsLen -= 2;
|
|
156
|
+
}
|
|
157
|
+
if (typeof originalExpected === 'string') {
|
|
158
|
+
stringsLen -= 2;
|
|
159
|
+
}
|
|
160
|
+
if (stringsLen <= kMaxShortStringLength && (originalActual !== 0 || originalExpected !== 0)) {
|
|
161
|
+
return { message: `${actual} !== ${expected}`, header: '' };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const isStringComparison = typeof originalActual === 'string' && typeof originalExpected === 'string';
|
|
165
|
+
// colored myers diff
|
|
166
|
+
if (isStringComparison && colors.hasColors) {
|
|
167
|
+
return getColoredMyersDiff(actual, expected);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return getStackedDiff(actual, expected);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function isSimpleDiff(actual, inspectedActual, expected, inspectedExpected) {
|
|
174
|
+
if (inspectedActual.length > 1 || inspectedExpected.length > 1) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return typeof actual !== 'object' || actual === null || typeof expected !== 'object' || expected === null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function createErrDiff(actual, expected, operator, customMessage) {
|
|
182
|
+
operator = checkOperator(actual, expected, operator);
|
|
183
|
+
|
|
184
|
+
let skipped = false;
|
|
185
|
+
let message = '';
|
|
186
|
+
const inspectedActual = inspectValue(actual);
|
|
187
|
+
const inspectedExpected = inspectValue(expected);
|
|
188
|
+
const inspectedSplitActual = StringPrototypeSplit(inspectedActual, '\n');
|
|
189
|
+
const inspectedSplitExpected = StringPrototypeSplit(inspectedExpected, '\n');
|
|
190
|
+
const showSimpleDiff = isSimpleDiff(actual, inspectedSplitActual, expected, inspectedSplitExpected);
|
|
191
|
+
let header = `${colors.green}+ actual${colors.white} ${colors.red}- expected${colors.white}`;
|
|
192
|
+
|
|
193
|
+
if (showSimpleDiff) {
|
|
194
|
+
const simpleDiff = getSimpleDiff(actual, inspectedSplitActual[0], expected, inspectedSplitExpected[0]);
|
|
195
|
+
message = simpleDiff.message;
|
|
196
|
+
if (typeof simpleDiff.header !== 'undefined') {
|
|
197
|
+
header = simpleDiff.header;
|
|
198
|
+
}
|
|
199
|
+
if (simpleDiff.skipped) {
|
|
200
|
+
skipped = true;
|
|
201
|
+
}
|
|
202
|
+
} else if (inspectedActual === inspectedExpected) {
|
|
203
|
+
// Handles the case where the objects are structurally the same but different references
|
|
204
|
+
operator = 'notIdentical';
|
|
205
|
+
if (inspectedSplitActual.length > 50) {
|
|
206
|
+
message = `${ArrayPrototypeJoin(ArrayPrototypeSlice(inspectedSplitActual, 0, 50), '\n')}\n...}`;
|
|
207
|
+
skipped = true;
|
|
208
|
+
} else {
|
|
209
|
+
message = ArrayPrototypeJoin(inspectedSplitActual, '\n');
|
|
210
|
+
}
|
|
211
|
+
header = '';
|
|
212
|
+
} else {
|
|
213
|
+
const checkCommaDisparity = actual != null && typeof actual === 'object';
|
|
214
|
+
const diff = myersDiff(inspectedSplitActual, inspectedSplitExpected, checkCommaDisparity);
|
|
215
|
+
|
|
216
|
+
const myersDiffMessage = printMyersDiff(diff, operator);
|
|
217
|
+
message = myersDiffMessage.message;
|
|
218
|
+
|
|
219
|
+
if (operator === 'partialDeepStrictEqual') {
|
|
220
|
+
header = `${colors.gray}${colors.hasColors ? '' : '+ '}actual${colors.white} ${colors.red}- expected${colors.white}`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (myersDiffMessage.skipped) {
|
|
224
|
+
skipped = true;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const headerMessage = `${getErrorMessage(operator, customMessage)}\n${header}`;
|
|
229
|
+
const skippedMessage = skipped ? '\n... Skipped lines' : '';
|
|
230
|
+
|
|
231
|
+
return `${headerMessage}${skippedMessage}\n${message}\n`;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function addEllipsis(string) {
|
|
235
|
+
const lines = StringPrototypeSplit(string, '\n', 11);
|
|
236
|
+
if (lines.length > 10) {
|
|
237
|
+
lines.length = 10;
|
|
238
|
+
return `${ArrayPrototypeJoin(lines, '\n')}\n...`;
|
|
239
|
+
} else if (string.length > kMaxLongStringLength) {
|
|
240
|
+
return `${StringPrototypeSlice(string, kMaxLongStringLength)}...`;
|
|
241
|
+
}
|
|
242
|
+
return string;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
class AssertionError extends Error {
|
|
246
|
+
constructor(options) {
|
|
247
|
+
validateObject(options, 'options');
|
|
248
|
+
const {
|
|
249
|
+
message,
|
|
250
|
+
operator,
|
|
251
|
+
stackStartFn,
|
|
252
|
+
details,
|
|
253
|
+
// Compatibility with older versions.
|
|
254
|
+
stackStartFunction,
|
|
255
|
+
} = options;
|
|
256
|
+
let {
|
|
257
|
+
actual,
|
|
258
|
+
expected,
|
|
259
|
+
} = options;
|
|
260
|
+
|
|
261
|
+
const limit = Error.stackTraceLimit;
|
|
262
|
+
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
|
|
263
|
+
|
|
264
|
+
if (message != null) {
|
|
265
|
+
if (kMethodsWithCustomMessageDiff.includes(operator)) {
|
|
266
|
+
super(createErrDiff(actual, expected, operator, message));
|
|
267
|
+
} else {
|
|
268
|
+
super(String(message));
|
|
269
|
+
}
|
|
270
|
+
} else {
|
|
271
|
+
// Reset colors on each call to make sure we handle dynamically set environment
|
|
272
|
+
// variables correct.
|
|
273
|
+
colors.refresh();
|
|
274
|
+
// Prevent the error stack from being visible by duplicating the error
|
|
275
|
+
// in a very close way to the original in case both sides are actually
|
|
276
|
+
// instances of Error.
|
|
277
|
+
if (typeof actual === 'object' && actual !== null &&
|
|
278
|
+
typeof expected === 'object' && expected !== null &&
|
|
279
|
+
'stack' in actual && actual instanceof Error &&
|
|
280
|
+
'stack' in expected && expected instanceof Error) {
|
|
281
|
+
actual = copyError(actual);
|
|
282
|
+
expected = copyError(expected);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (kMethodsWithCustomMessageDiff.includes(operator)) {
|
|
286
|
+
super(createErrDiff(actual, expected, operator, message));
|
|
287
|
+
} else if (operator === 'notDeepStrictEqual' ||
|
|
288
|
+
operator === 'notStrictEqual') {
|
|
289
|
+
// In case the objects are equal but the operator requires unequal, show
|
|
290
|
+
// the first object and say A equals B
|
|
291
|
+
let base = kReadableOperator[operator];
|
|
292
|
+
const res = StringPrototypeSplit(inspectValue(actual), '\n');
|
|
293
|
+
|
|
294
|
+
// In case "actual" is an object or a function, it should not be
|
|
295
|
+
// reference equal.
|
|
296
|
+
if (operator === 'notStrictEqual' &&
|
|
297
|
+
((typeof actual === 'object' && actual !== null) ||
|
|
298
|
+
typeof actual === 'function')) {
|
|
299
|
+
base = kReadableOperator.notStrictEqualObject;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Only remove lines in case it makes sense to collapse those.
|
|
303
|
+
// TODO: Accept env to always show the full error.
|
|
304
|
+
if (res.length > 50) {
|
|
305
|
+
res[46] = `${colors.blue}...${colors.white}`;
|
|
306
|
+
while (res.length > 47) {
|
|
307
|
+
ArrayPrototypePop(res);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Only print a single input.
|
|
312
|
+
if (res.length === 1) {
|
|
313
|
+
super(`${base}${res[0].length > 5 ? '\n\n' : ' '}${res[0]}`);
|
|
314
|
+
} else {
|
|
315
|
+
super(`${base}\n\n${ArrayPrototypeJoin(res, '\n')}\n`);
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
let res = inspectValue(actual);
|
|
319
|
+
let other = inspectValue(expected);
|
|
320
|
+
const knownOperator = kReadableOperator[operator];
|
|
321
|
+
if (operator === 'notDeepEqual' && res === other) {
|
|
322
|
+
res = `${knownOperator}\n\n${res}`;
|
|
323
|
+
if (res.length > 1024) {
|
|
324
|
+
res = `${StringPrototypeSlice(res, 0, 1021)}...`;
|
|
325
|
+
}
|
|
326
|
+
super(res);
|
|
327
|
+
} else {
|
|
328
|
+
if (res.length > kMaxLongStringLength) {
|
|
329
|
+
res = `${StringPrototypeSlice(res, 0, 509)}...`;
|
|
330
|
+
}
|
|
331
|
+
if (other.length > kMaxLongStringLength) {
|
|
332
|
+
other = `${StringPrototypeSlice(other, 0, 509)}...`;
|
|
333
|
+
}
|
|
334
|
+
if (operator === 'deepEqual') {
|
|
335
|
+
res = `${knownOperator}\n\n${res}\n\nshould loosely deep-equal\n\n`;
|
|
336
|
+
} else {
|
|
337
|
+
const newOp = kReadableOperator[`${operator}Unequal`];
|
|
338
|
+
if (newOp) {
|
|
339
|
+
res = `${newOp}\n\n${res}\n\nshould not loosely deep-equal\n\n`;
|
|
340
|
+
} else {
|
|
341
|
+
other = ` ${operator} ${other}`;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
super(`${res}${other}`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
|
|
350
|
+
|
|
351
|
+
this.generatedMessage = !message;
|
|
352
|
+
ObjectDefineProperty(this, 'name', {
|
|
353
|
+
__proto__: null,
|
|
354
|
+
value: 'AssertionError [ERR_ASSERTION]',
|
|
355
|
+
enumerable: false,
|
|
356
|
+
writable: true,
|
|
357
|
+
configurable: true,
|
|
358
|
+
});
|
|
359
|
+
this.code = 'ERR_ASSERTION';
|
|
360
|
+
if (details) {
|
|
361
|
+
this.actual = undefined;
|
|
362
|
+
this.expected = undefined;
|
|
363
|
+
this.operator = undefined;
|
|
364
|
+
for (let i = 0; i < details.length; i++) {
|
|
365
|
+
this['message ' + i] = details[i].message;
|
|
366
|
+
this['actual ' + i] = details[i].actual;
|
|
367
|
+
this['expected ' + i] = details[i].expected;
|
|
368
|
+
this['operator ' + i] = details[i].operator;
|
|
369
|
+
this['stack trace ' + i] = details[i].stack;
|
|
370
|
+
}
|
|
371
|
+
} else {
|
|
372
|
+
this.actual = actual;
|
|
373
|
+
this.expected = expected;
|
|
374
|
+
this.operator = operator;
|
|
375
|
+
}
|
|
376
|
+
ErrorCaptureStackTrace(this, stackStartFn || stackStartFunction);
|
|
377
|
+
// Create error message including the error code in the name.
|
|
378
|
+
this.stack; // eslint-disable-line no-unused-expressions
|
|
379
|
+
// Reset the name.
|
|
380
|
+
this.name = 'AssertionError';
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
toString() {
|
|
384
|
+
return `${this.name} [${this.code}]: ${this.message}`;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
[inspect.custom](recurseTimes, ctx) {
|
|
388
|
+
// Long strings should not be fully inspected.
|
|
389
|
+
const tmpActual = this.actual;
|
|
390
|
+
const tmpExpected = this.expected;
|
|
391
|
+
|
|
392
|
+
if (typeof this.actual === 'string') {
|
|
393
|
+
this.actual = addEllipsis(this.actual);
|
|
394
|
+
}
|
|
395
|
+
if (typeof this.expected === 'string') {
|
|
396
|
+
this.expected = addEllipsis(this.expected);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// This limits the `actual` and `expected` property default inspection to
|
|
400
|
+
// the minimum depth. Otherwise those values would be too verbose compared
|
|
401
|
+
// to the actual error message which contains a combined view of these two
|
|
402
|
+
// input values.
|
|
403
|
+
const result = inspect(this, {
|
|
404
|
+
...ctx,
|
|
405
|
+
customInspect: false,
|
|
406
|
+
depth: 0,
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
// Reset the properties after inspection.
|
|
410
|
+
this.actual = tmpActual;
|
|
411
|
+
this.expected = tmpExpected;
|
|
412
|
+
|
|
413
|
+
return result;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
module.exports = AssertionError;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
ArrayPrototypePush,
|
|
5
|
+
ArrayPrototypeSlice,
|
|
6
|
+
Error,
|
|
7
|
+
FunctionPrototype,
|
|
8
|
+
ObjectFreeze,
|
|
9
|
+
Proxy,
|
|
10
|
+
ReflectApply,
|
|
11
|
+
SafeSet,
|
|
12
|
+
SafeWeakMap,
|
|
13
|
+
} = primordials;
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
codes: {
|
|
17
|
+
ERR_INVALID_ARG_VALUE,
|
|
18
|
+
ERR_UNAVAILABLE_DURING_EXIT,
|
|
19
|
+
},
|
|
20
|
+
} = require('internal/errors');
|
|
21
|
+
const AssertionError = require('internal/assert/assertion_error');
|
|
22
|
+
const {
|
|
23
|
+
validateUint32,
|
|
24
|
+
} = require('internal/validators');
|
|
25
|
+
|
|
26
|
+
const noop = FunctionPrototype;
|
|
27
|
+
|
|
28
|
+
class CallTrackerContext {
|
|
29
|
+
#expected;
|
|
30
|
+
#calls;
|
|
31
|
+
#name;
|
|
32
|
+
#stackTrace;
|
|
33
|
+
constructor({ expected, stackTrace, name }) {
|
|
34
|
+
this.#calls = [];
|
|
35
|
+
this.#expected = expected;
|
|
36
|
+
this.#stackTrace = stackTrace;
|
|
37
|
+
this.#name = name;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
track(thisArg, args) {
|
|
41
|
+
const argsClone = ObjectFreeze(ArrayPrototypeSlice(args));
|
|
42
|
+
ArrayPrototypePush(this.#calls, ObjectFreeze({ thisArg, arguments: argsClone }));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get delta() {
|
|
46
|
+
return this.#calls.length - this.#expected;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
reset() {
|
|
50
|
+
this.#calls = [];
|
|
51
|
+
}
|
|
52
|
+
getCalls() {
|
|
53
|
+
return ObjectFreeze(ArrayPrototypeSlice(this.#calls));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
report() {
|
|
57
|
+
if (this.delta !== 0) {
|
|
58
|
+
const message = `Expected the ${this.#name} function to be ` +
|
|
59
|
+
`executed ${this.#expected} time(s) but was ` +
|
|
60
|
+
`executed ${this.#calls.length} time(s).`;
|
|
61
|
+
return {
|
|
62
|
+
message,
|
|
63
|
+
actual: this.#calls.length,
|
|
64
|
+
expected: this.#expected,
|
|
65
|
+
operator: this.#name,
|
|
66
|
+
stack: this.#stackTrace,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
class CallTracker {
|
|
73
|
+
|
|
74
|
+
#callChecks = new SafeSet();
|
|
75
|
+
#trackedFunctions = new SafeWeakMap();
|
|
76
|
+
|
|
77
|
+
#getTrackedFunction(tracked) {
|
|
78
|
+
if (!this.#trackedFunctions.has(tracked)) {
|
|
79
|
+
throw new ERR_INVALID_ARG_VALUE('tracked', tracked, 'is not a tracked function');
|
|
80
|
+
}
|
|
81
|
+
return this.#trackedFunctions.get(tracked);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
reset(tracked) {
|
|
85
|
+
if (tracked === undefined) {
|
|
86
|
+
this.#callChecks.forEach((check) => check.reset());
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.#getTrackedFunction(tracked).reset();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getCalls(tracked) {
|
|
94
|
+
return this.#getTrackedFunction(tracked).getCalls();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
calls(fn, expected = 1) {
|
|
98
|
+
if (process._exiting)
|
|
99
|
+
throw new ERR_UNAVAILABLE_DURING_EXIT();
|
|
100
|
+
if (typeof fn === 'number') {
|
|
101
|
+
expected = fn;
|
|
102
|
+
fn = noop;
|
|
103
|
+
} else if (fn === undefined) {
|
|
104
|
+
fn = noop;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
validateUint32(expected, 'expected', true);
|
|
108
|
+
|
|
109
|
+
const context = new CallTrackerContext({
|
|
110
|
+
expected,
|
|
111
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
112
|
+
stackTrace: new Error(),
|
|
113
|
+
name: fn.name || 'calls',
|
|
114
|
+
});
|
|
115
|
+
const tracked = new Proxy(fn, {
|
|
116
|
+
__proto__: null,
|
|
117
|
+
apply(fn, thisArg, argList) {
|
|
118
|
+
context.track(thisArg, argList);
|
|
119
|
+
return ReflectApply(fn, thisArg, argList);
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
this.#callChecks.add(context);
|
|
123
|
+
this.#trackedFunctions.set(tracked, context);
|
|
124
|
+
return tracked;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
report() {
|
|
128
|
+
const errors = [];
|
|
129
|
+
for (const context of this.#callChecks) {
|
|
130
|
+
const message = context.report();
|
|
131
|
+
if (message !== undefined) {
|
|
132
|
+
ArrayPrototypePush(errors, message);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return errors;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
verify() {
|
|
139
|
+
const errors = this.report();
|
|
140
|
+
if (errors.length === 0) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const message = errors.length === 1 ?
|
|
144
|
+
errors[0].message :
|
|
145
|
+
'Functions were not called the expected number of times';
|
|
146
|
+
throw new AssertionError({
|
|
147
|
+
message,
|
|
148
|
+
details: errors,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
module.exports = CallTracker;
|