@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,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rollup shim - Uses @rollup/browser for browser-compatible Rollup
|
|
3
|
+
*
|
|
4
|
+
* Vite uses Rollup for bundling. The native Rollup package doesn't work
|
|
5
|
+
* in browsers, so we need to use @rollup/browser instead.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { heldWork } from '../host-globals';
|
|
9
|
+
import * as acorn from 'acorn';
|
|
10
|
+
import { ROLLUP_BROWSER_CDN, ROLLUP_BROWSER_VERSION } from '../config/cdn';
|
|
11
|
+
|
|
12
|
+
/** What a rollup build is handed, and what it answers. */
|
|
13
|
+
export interface RollupBuildOptions { fs?: unknown; [key: string]: unknown }
|
|
14
|
+
export interface RollupBundle {
|
|
15
|
+
generate?: (...args: unknown[]) => Promise<unknown>;
|
|
16
|
+
write?: (...args: unknown[]) => Promise<unknown>;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare global {
|
|
21
|
+
// eslint-disable-next-line no-var
|
|
22
|
+
var __substrateCarried: (<T>(callback: T) => T) | undefined;
|
|
23
|
+
// eslint-disable-next-line no-var
|
|
24
|
+
var __browserRuntimeHeldWork: { count: number } | undefined;
|
|
25
|
+
// eslint-disable-next-line no-var
|
|
26
|
+
var __browserRuntimeRollupUrl: string | undefined;
|
|
27
|
+
// eslint-disable-next-line no-var
|
|
28
|
+
var __browserRuntimeRollupFs: unknown;
|
|
29
|
+
// eslint-disable-next-line no-var
|
|
30
|
+
var __browserRuntimeNativeSetTimeout: typeof setTimeout | undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Rollup instance loaded from CDN
|
|
34
|
+
let rollupInstance: unknown = null;
|
|
35
|
+
let loadPromise: Promise<unknown> | null = null;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Load Rollup from CDN
|
|
39
|
+
*/
|
|
40
|
+
async function loadRollup(): Promise<unknown> {
|
|
41
|
+
if (rollupInstance) return rollupInstance;
|
|
42
|
+
if (loadPromise) return loadPromise;
|
|
43
|
+
|
|
44
|
+
loadPromise = (async () => {
|
|
45
|
+
try {
|
|
46
|
+
// Load @rollup/browser from CDN
|
|
47
|
+
// The browser build comes from the page's own origin when the page says
|
|
48
|
+
// where, the CDN otherwise: a guest's egress refuses the CDN.
|
|
49
|
+
const rollup = await import(
|
|
50
|
+
/* @vite-ignore */
|
|
51
|
+
typeof globalThis.__browserRuntimeRollupUrl === 'string' ? globalThis.__browserRuntimeRollupUrl : ROLLUP_BROWSER_CDN
|
|
52
|
+
);
|
|
53
|
+
rollupInstance = rollup;
|
|
54
|
+
console.log('[rollup] Browser version loaded');
|
|
55
|
+
return rollup;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error('[rollup] Failed to load browser version:', error);
|
|
58
|
+
loadPromise = null;
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
})();
|
|
62
|
+
|
|
63
|
+
return loadPromise;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// For synchronous require(), we need a stub that works before async load
|
|
67
|
+
// This will be replaced when loadRollup() is called
|
|
68
|
+
|
|
69
|
+
export const VERSION = ROLLUP_BROWSER_VERSION;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A script is not finished while its build is running. Rollup's work is held
|
|
73
|
+
* so the process loop waits: the graph while `rollup()` builds it, the chunks
|
|
74
|
+
* while `generate` or `write` renders them. A React Router build is Vite's
|
|
75
|
+
* build, which is rollup's, and printed nothing for the half second the engine
|
|
76
|
+
* waited, so the Dockerfile stage moved on with no `build/`.
|
|
77
|
+
*/
|
|
78
|
+
export async function rollup(options: RollupBuildOptions): Promise<RollupBundle> {
|
|
79
|
+
const __held = heldWork();
|
|
80
|
+
__held.count += 1;
|
|
81
|
+
let bundle;
|
|
82
|
+
try {
|
|
83
|
+
const r = await loadRollup() as { rollup: (options: unknown) => Promise<RollupBundle> };
|
|
84
|
+
// The guest's tree, for what no plugin resolved or loaded.
|
|
85
|
+
const __fs = globalThis.__browserRuntimeRollupFs;
|
|
86
|
+
bundle = await r.rollup(__fs && !options.fs ? { ...options, fs: __fs } : options);
|
|
87
|
+
} finally {
|
|
88
|
+
__held.count -= 1;
|
|
89
|
+
}
|
|
90
|
+
for (const name of ['generate', 'write'] as const) {
|
|
91
|
+
if (typeof bundle[name] !== 'function') continue;
|
|
92
|
+
const original = bundle[name].bind(bundle);
|
|
93
|
+
bundle[name] = async (...args: unknown[]) => {
|
|
94
|
+
__held.count += 1;
|
|
95
|
+
try { return await original(...args); } finally { __held.count -= 1; }
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return bundle;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function watch(options: unknown): Promise<unknown> {
|
|
102
|
+
const r = await loadRollup() as { watch: (options: unknown) => unknown };
|
|
103
|
+
return r.watch(options);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Export a function to pre-load rollup
|
|
107
|
+
export { loadRollup };
|
|
108
|
+
|
|
109
|
+
// Define plugin context types that Vite expects
|
|
110
|
+
export interface Plugin {
|
|
111
|
+
name: string;
|
|
112
|
+
[key: string]: unknown;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface PluginContext {
|
|
116
|
+
meta: { rollupVersion: string };
|
|
117
|
+
parse: (code: string) => unknown;
|
|
118
|
+
[key: string]: unknown;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// parseAst/parseAstAsync — used by Vite's module system for ESM analysis
|
|
122
|
+
// Uses acorn as the parser (ESTree-compatible, like Rollup's native parser)
|
|
123
|
+
export function parseAst(input: string, options?: { allowReturnOutsideFunction?: boolean; jsx?: boolean }): unknown {
|
|
124
|
+
return acorn.parse(input, {
|
|
125
|
+
ecmaVersion: 'latest',
|
|
126
|
+
sourceType: 'module',
|
|
127
|
+
allowReturnOutsideFunction: options?.allowReturnOutsideFunction ?? false,
|
|
128
|
+
locations: true,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export async function parseAstAsync(input: string, options?: { allowReturnOutsideFunction?: boolean; jsx?: boolean; signal?: AbortSignal }): Promise<unknown> {
|
|
133
|
+
return parseAst(input, options);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Stub for native module detection - this prevents the "unsupported platform" error
|
|
137
|
+
export function getPackageBase(): string {
|
|
138
|
+
return '';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Export default that matches Rollup's API
|
|
142
|
+
export default {
|
|
143
|
+
VERSION,
|
|
144
|
+
rollup,
|
|
145
|
+
watch,
|
|
146
|
+
loadRollup,
|
|
147
|
+
parseAst,
|
|
148
|
+
parseAstAsync,
|
|
149
|
+
};
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's `string_decoder`, which is Node's own `lib/string_decoder.js`.
|
|
3
|
+
*
|
|
4
|
+
* The engine had a hand-written stub built in `runtime.ts`: it decoded each
|
|
5
|
+
* chunk on its own, so a multi-byte character split across two chunks came out
|
|
6
|
+
* as two replacement characters. Every protocol VS Code's workbench speaks to
|
|
7
|
+
* its extension host is UTF-8 over a socket, and a message that happened to be
|
|
8
|
+
* cut inside a character was corrupted; `Readable.setEncoding` had nothing to
|
|
9
|
+
* decode with at all.
|
|
10
|
+
*
|
|
11
|
+
* The method is Node's, transcribed over the engine's `Buffer`: a decoder holds
|
|
12
|
+
* back the bytes of an incomplete sequence in `lastChar` and completes it with
|
|
13
|
+
* the head of the next chunk. `lastChar`, `lastNeed` and `lastTotal` are Node's
|
|
14
|
+
* own undocumented fields, which Node's test reads.
|
|
15
|
+
*
|
|
16
|
+
* Two departures from `lib/string_decoder.js`, both named where they are: the
|
|
17
|
+
* held-back bytes are in a zeroed buffer rather than an uninitialised one, and
|
|
18
|
+
* a string too long for V8 is refused by the input's size rather than by
|
|
19
|
+
* building the string and failing.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { loadNodeLib } from '../node-lib/load';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Node's `Buffer`, read when a decoder is first used rather than when this
|
|
26
|
+
* module is evaluated. `buffer` is a vendored Node file that `node-lib`'s
|
|
27
|
+
* loader builds, and this shim is one of the public modules that loader
|
|
28
|
+
* resolves: taking the class at import time makes the two wait on each other
|
|
29
|
+
* and neither loads at all.
|
|
30
|
+
*/
|
|
31
|
+
interface BufferClass {
|
|
32
|
+
isBuffer(value: unknown): boolean;
|
|
33
|
+
from(value: unknown, offset?: unknown, length?: number): Buffer;
|
|
34
|
+
alloc(size: number): Buffer;
|
|
35
|
+
}
|
|
36
|
+
let bufferClass: BufferClass | undefined;
|
|
37
|
+
function Bytes(): BufferClass {
|
|
38
|
+
return bufferClass ??= (loadNodeLib('buffer') as { Buffer: BufferClass }).Buffer;
|
|
39
|
+
}
|
|
40
|
+
import {
|
|
41
|
+
ERR_INVALID_ARG_TYPE,
|
|
42
|
+
ERR_INVALID_THIS,
|
|
43
|
+
ERR_STRING_TOO_LONG,
|
|
44
|
+
ERR_UNKNOWN_ENCODING,
|
|
45
|
+
} from '../node-internals';
|
|
46
|
+
|
|
47
|
+
/** V8's longest string, which Node reports as ERR_STRING_TOO_LONG. */
|
|
48
|
+
const kStringMaxLength = 0x1fffffe8;
|
|
49
|
+
/** A marker the constructor leaves, so a prototype method knows its `this`. */
|
|
50
|
+
const kIsStringDecoder = Symbol('kIsStringDecoder');
|
|
51
|
+
|
|
52
|
+
export interface StringDecoder {
|
|
53
|
+
encoding: string;
|
|
54
|
+
lastChar: Buffer;
|
|
55
|
+
lastNeed: number;
|
|
56
|
+
lastTotal: number;
|
|
57
|
+
write(buffer: unknown): string;
|
|
58
|
+
end(buffer?: unknown): string;
|
|
59
|
+
text(buffer: Buffer, offset: number): string;
|
|
60
|
+
fillLast(buffer: Buffer): string | undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface StringDecoderConstructor {
|
|
64
|
+
new (encoding?: string): StringDecoder;
|
|
65
|
+
(this: unknown, encoding?: string): void;
|
|
66
|
+
prototype: StringDecoder;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** lib/internal/util.js normalizeEncoding, with Node's aliases. */
|
|
70
|
+
const kEncodingAliases: Record<string, string> = {
|
|
71
|
+
utf8: 'utf8', 'utf-8': 'utf8',
|
|
72
|
+
ucs2: 'utf16le', 'ucs-2': 'utf16le', utf16le: 'utf16le', 'utf-16le': 'utf16le',
|
|
73
|
+
latin1: 'latin1', binary: 'latin1',
|
|
74
|
+
base64: 'base64', base64url: 'base64url',
|
|
75
|
+
ascii: 'ascii',
|
|
76
|
+
hex: 'hex',
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function normalizeEncoding(encoding: unknown): string {
|
|
80
|
+
if (encoding === undefined || encoding === null || encoding === '') return 'utf8';
|
|
81
|
+
if (typeof encoding !== 'string') throw new ERR_UNKNOWN_ENCODING(encoding);
|
|
82
|
+
const normalized = kEncodingAliases[encoding.toLowerCase()];
|
|
83
|
+
if (normalized === undefined) throw new ERR_UNKNOWN_ENCODING(encoding);
|
|
84
|
+
return normalized;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The most characters one byte can decode to, per encoding. */
|
|
88
|
+
const kCharsPerByte: Record<string, number> = {
|
|
89
|
+
utf8: 1, utf16le: 0.5, latin1: 1, ascii: 1, hex: 2, base64: 2, base64url: 2,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Node's decoder takes a Buffer, a TypedArray of any width or a DataView, and
|
|
94
|
+
* refuses everything else. The engine works over the bytes either way.
|
|
95
|
+
*/
|
|
96
|
+
function decoderInput(self: StringDecoder, buffer: unknown): Buffer {
|
|
97
|
+
let bytes: Buffer;
|
|
98
|
+
if (Bytes().isBuffer(buffer)) {
|
|
99
|
+
bytes = buffer as Buffer;
|
|
100
|
+
} else if (ArrayBuffer.isView(buffer)) {
|
|
101
|
+
const view = buffer as ArrayBufferView;
|
|
102
|
+
bytes = Bytes().from(view.buffer as ArrayBuffer, view.byteOffset, view.byteLength);
|
|
103
|
+
} else {
|
|
104
|
+
throw new ERR_INVALID_ARG_TYPE('buf', ['Buffer', 'TypedArray', 'DataView'], buffer);
|
|
105
|
+
}
|
|
106
|
+
// Node builds the string and lets V8 refuse it; the engine asks first, from
|
|
107
|
+
// the widest a byte can decode to, so the refusal costs nothing.
|
|
108
|
+
const charsPerByte = kCharsPerByte[self.encoding] ?? 1;
|
|
109
|
+
if (bytes.length * charsPerByte > kStringMaxLength) throw new ERR_STRING_TOO_LONG(kStringMaxLength);
|
|
110
|
+
return bytes;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function assertDecoder(self: unknown): StringDecoder {
|
|
114
|
+
if (!self || !(self as Record<symbol, unknown>)[kIsStringDecoder]) {
|
|
115
|
+
throw new ERR_INVALID_THIS('StringDecoder');
|
|
116
|
+
}
|
|
117
|
+
return self as StringDecoder;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
// UTF-8
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
/** The width a UTF-8 byte leads: 0 for ASCII, -1 continuation, -2 invalid. */
|
|
125
|
+
function utf8CheckByte(byte: number): number {
|
|
126
|
+
if (byte <= 0x7f) return 0;
|
|
127
|
+
if (byte >> 5 === 0x06) return 2;
|
|
128
|
+
if (byte >> 4 === 0x0e) return 3;
|
|
129
|
+
if (byte >> 3 === 0x1e) return 4;
|
|
130
|
+
return byte >> 6 === 0x02 ? -1 : -2;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** The last three bytes of a chunk, for a character the chunk cut in half. */
|
|
134
|
+
function utf8CheckIncomplete(self: StringDecoder, buf: Buffer, i: number): number {
|
|
135
|
+
let j = buf.length - 1;
|
|
136
|
+
if (j < i) return 0;
|
|
137
|
+
let nb = utf8CheckByte(buf[j]);
|
|
138
|
+
if (nb >= 0) {
|
|
139
|
+
if (nb > 0) self.lastNeed = nb - 1;
|
|
140
|
+
return nb;
|
|
141
|
+
}
|
|
142
|
+
if (--j < i || nb === -2) return 0;
|
|
143
|
+
nb = utf8CheckByte(buf[j]);
|
|
144
|
+
if (nb >= 0) {
|
|
145
|
+
if (nb > 0) self.lastNeed = nb - 2;
|
|
146
|
+
return nb;
|
|
147
|
+
}
|
|
148
|
+
if (--j < i || nb === -2) return 0;
|
|
149
|
+
nb = utf8CheckByte(buf[j]);
|
|
150
|
+
if (nb >= 0) {
|
|
151
|
+
if (nb > 0) {
|
|
152
|
+
if (nb === 2) nb = 0;
|
|
153
|
+
else self.lastNeed = nb - 3;
|
|
154
|
+
}
|
|
155
|
+
return nb;
|
|
156
|
+
}
|
|
157
|
+
return 0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* A continuation byte where one is due, or V8's replacement character for the
|
|
162
|
+
* bytes already taken. The check is written out three times, as Node writes it.
|
|
163
|
+
*/
|
|
164
|
+
function utf8CheckExtraBytes(self: StringDecoder, buf: Buffer, p: number): string | undefined {
|
|
165
|
+
if ((buf[0] & 0xc0) !== 0x80) {
|
|
166
|
+
self.lastNeed = 0;
|
|
167
|
+
return utf8BrokenSequence(self, buf, p, 0);
|
|
168
|
+
}
|
|
169
|
+
if (self.lastNeed > 1 && buf.length > 1) {
|
|
170
|
+
if ((buf[1] & 0xc0) !== 0x80) {
|
|
171
|
+
self.lastNeed = 1;
|
|
172
|
+
return utf8BrokenSequence(self, buf, p, 1);
|
|
173
|
+
}
|
|
174
|
+
if (self.lastNeed > 2 && buf.length > 2) {
|
|
175
|
+
if ((buf[2] & 0xc0) !== 0x80) {
|
|
176
|
+
self.lastNeed = 2;
|
|
177
|
+
return utf8BrokenSequence(self, buf, p, 2);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* What a broken multi-byte sequence decodes to: the `p` bytes held back plus
|
|
186
|
+
* the `taken` continuation bytes that were good, handed to the platform's own
|
|
187
|
+
* UTF-8 decoder. V8 emits one replacement character per maximal ill-formed
|
|
188
|
+
* subpart, not one per byte -- `F0 B8` then `41` is one (F0 B8 is a good
|
|
189
|
+
* prefix), while `F6 9B` then `D1` is two (F6 leads nothing, 9B is stray) --
|
|
190
|
+
* so the count is read off a decode rather than guessed from a length.
|
|
191
|
+
*/
|
|
192
|
+
function utf8BrokenSequence(self: StringDecoder, buf: Buffer, p: number, taken: number): string {
|
|
193
|
+
const bytes = Bytes().alloc(p + taken) as unknown as Buffer;
|
|
194
|
+
self.lastChar.copy(bytes, 0, 0, p);
|
|
195
|
+
if (taken > 0) buf.copy(bytes, p, 0, taken);
|
|
196
|
+
return bytes.toString('utf8');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function utf8FillLast(this: StringDecoder, buf: Buffer): string | undefined {
|
|
200
|
+
const p = this.lastTotal - this.lastNeed;
|
|
201
|
+
// One replacement character per byte of the broken sequence already taken.
|
|
202
|
+
const r = utf8CheckExtraBytes(this, buf, p);
|
|
203
|
+
if (r !== undefined) return r;
|
|
204
|
+
if (this.lastNeed <= buf.length) {
|
|
205
|
+
buf.copy(this.lastChar, p, 0, this.lastNeed);
|
|
206
|
+
return this.lastChar.toString(this.encoding as BufferEncoding, 0, this.lastTotal);
|
|
207
|
+
}
|
|
208
|
+
buf.copy(this.lastChar, p, 0, buf.length);
|
|
209
|
+
this.lastNeed -= buf.length;
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function utf8Text(this: StringDecoder, buf: Buffer, i: number): string {
|
|
214
|
+
const total = utf8CheckIncomplete(this, buf, i);
|
|
215
|
+
if (!this.lastNeed) return buf.toString('utf8', i);
|
|
216
|
+
this.lastTotal = total;
|
|
217
|
+
const end = buf.length - (total - this.lastNeed);
|
|
218
|
+
buf.copy(this.lastChar, 0, end);
|
|
219
|
+
return buf.toString('utf8', i, end);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function utf8End(this: StringDecoder, buf?: unknown): string {
|
|
223
|
+
const r = buf !== undefined && buf !== null && (buf as Buffer).length ? this.write(buf) : '';
|
|
224
|
+
// Node's native decoder flushes its held-back bytes and forgets them, so a
|
|
225
|
+
// decoder reused after end() starts clean; the pure-JS file it came from did
|
|
226
|
+
// not, and the next write carried the last stream's broken tail into it.
|
|
227
|
+
// What the flush says is the decode of those bytes, not one replacement
|
|
228
|
+
// character: `F6 9B` left over is two, `E1 8B` is one, and the pure-JS file
|
|
229
|
+
// answered one for both, so a chunked decode and a whole-buffer decode of the
|
|
230
|
+
// same bytes disagreed.
|
|
231
|
+
if (this.lastNeed) {
|
|
232
|
+
const held = this.lastTotal - this.lastNeed;
|
|
233
|
+
this.lastNeed = 0;
|
|
234
|
+
this.lastTotal = 0;
|
|
235
|
+
return r + this.lastChar.toString('utf8', 0, held);
|
|
236
|
+
}
|
|
237
|
+
return r;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// ---------------------------------------------------------------------------
|
|
241
|
+
// UTF-16LE
|
|
242
|
+
// ---------------------------------------------------------------------------
|
|
243
|
+
|
|
244
|
+
function utf16Text(this: StringDecoder, buf: Buffer, i: number): string {
|
|
245
|
+
if ((buf.length - i) % 2 === 0) {
|
|
246
|
+
const r = buf.toString('utf16le', i);
|
|
247
|
+
if (r) {
|
|
248
|
+
const c = r.charCodeAt(r.length - 1);
|
|
249
|
+
// A lead surrogate at the end is half a character: its two bytes wait.
|
|
250
|
+
if (c >= 0xd800 && c <= 0xdbff) {
|
|
251
|
+
this.lastNeed = 2;
|
|
252
|
+
this.lastTotal = 4;
|
|
253
|
+
this.lastChar[0] = buf[buf.length - 2];
|
|
254
|
+
this.lastChar[1] = buf[buf.length - 1];
|
|
255
|
+
return r.slice(0, -1);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return r;
|
|
259
|
+
}
|
|
260
|
+
this.lastNeed = 1;
|
|
261
|
+
this.lastTotal = 2;
|
|
262
|
+
this.lastChar[0] = buf[buf.length - 1];
|
|
263
|
+
return buf.toString('utf16le', i, buf.length - 1);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function utf16End(this: StringDecoder, buf?: unknown): string {
|
|
267
|
+
const r = buf !== undefined && buf !== null && (buf as Buffer).length ? this.write(buf) : '';
|
|
268
|
+
if (this.lastNeed) {
|
|
269
|
+
const end = this.lastTotal - this.lastNeed;
|
|
270
|
+
this.lastNeed = 0;
|
|
271
|
+
this.lastTotal = 0;
|
|
272
|
+
return r + this.lastChar.toString('utf16le', 0, end);
|
|
273
|
+
}
|
|
274
|
+
return r;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// ---------------------------------------------------------------------------
|
|
278
|
+
// base64
|
|
279
|
+
// ---------------------------------------------------------------------------
|
|
280
|
+
|
|
281
|
+
function base64Text(this: StringDecoder, buf: Buffer, i: number): string {
|
|
282
|
+
const n = (buf.length - i) % 3;
|
|
283
|
+
// The decoder's own encoding, not 'base64': base64url writes no padding.
|
|
284
|
+
const enc = this.encoding as BufferEncoding;
|
|
285
|
+
if (n === 0) return buf.toString(enc, i);
|
|
286
|
+
this.lastNeed = 3 - n;
|
|
287
|
+
this.lastTotal = 3;
|
|
288
|
+
if (n === 1) {
|
|
289
|
+
this.lastChar[0] = buf[buf.length - 1];
|
|
290
|
+
} else {
|
|
291
|
+
this.lastChar[0] = buf[buf.length - 2];
|
|
292
|
+
this.lastChar[1] = buf[buf.length - 1];
|
|
293
|
+
}
|
|
294
|
+
return buf.toString(enc, i, buf.length - n);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function base64End(this: StringDecoder, buf?: unknown): string {
|
|
298
|
+
const r = buf !== undefined && buf !== null && (buf as Buffer).length ? this.write(buf) : '';
|
|
299
|
+
if (this.lastNeed) {
|
|
300
|
+
const taken = 3 - this.lastNeed;
|
|
301
|
+
this.lastNeed = 0;
|
|
302
|
+
this.lastTotal = 0;
|
|
303
|
+
return r + this.lastChar.toString(this.encoding as BufferEncoding, 0, taken);
|
|
304
|
+
}
|
|
305
|
+
return r;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// ---------------------------------------------------------------------------
|
|
309
|
+
// One byte per character: nothing is ever held back.
|
|
310
|
+
// ---------------------------------------------------------------------------
|
|
311
|
+
|
|
312
|
+
function simpleWrite(this: StringDecoder, buf: unknown): string {
|
|
313
|
+
return decoderInput(this, buf).toString(this.encoding as BufferEncoding);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function simpleEnd(this: StringDecoder, buf?: unknown): string {
|
|
317
|
+
return buf !== undefined && buf !== null && (buf as Buffer).length ? this.write(buf) : '';
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ---------------------------------------------------------------------------
|
|
321
|
+
|
|
322
|
+
function StringDecoderImpl(this: StringDecoder, encoding?: string): void {
|
|
323
|
+
this.encoding = normalizeEncoding(encoding);
|
|
324
|
+
Object.defineProperty(this, kIsStringDecoder, { value: true, enumerable: false });
|
|
325
|
+
let nb: number;
|
|
326
|
+
switch (this.encoding) {
|
|
327
|
+
case 'utf16le':
|
|
328
|
+
this.text = utf16Text;
|
|
329
|
+
this.end = utf16End;
|
|
330
|
+
nb = 4;
|
|
331
|
+
break;
|
|
332
|
+
case 'utf8':
|
|
333
|
+
this.fillLast = utf8FillLast;
|
|
334
|
+
nb = 4;
|
|
335
|
+
break;
|
|
336
|
+
case 'base64':
|
|
337
|
+
case 'base64url':
|
|
338
|
+
this.text = base64Text;
|
|
339
|
+
this.end = base64End;
|
|
340
|
+
nb = 3;
|
|
341
|
+
break;
|
|
342
|
+
default:
|
|
343
|
+
this.write = simpleWrite;
|
|
344
|
+
this.end = simpleEnd;
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
this.lastNeed = 0;
|
|
348
|
+
this.lastTotal = 0;
|
|
349
|
+
// Node's `Buffer.allocUnsafe(nb)`. Zeroed here, because Node's own test reads
|
|
350
|
+
// the bytes of `lastChar` that no write has reached yet and expects zeros.
|
|
351
|
+
this.lastChar = Bytes().alloc(nb) as unknown as Buffer;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const decoderPrototype = StringDecoderImpl.prototype as unknown as StringDecoder;
|
|
355
|
+
|
|
356
|
+
decoderPrototype.write = function write(this: unknown, buffer: unknown): string {
|
|
357
|
+
const self = assertDecoder(this);
|
|
358
|
+
const buf = decoderInput(self, buffer);
|
|
359
|
+
if (buf.length === 0) return '';
|
|
360
|
+
let r: string | undefined;
|
|
361
|
+
let i: number;
|
|
362
|
+
if (self.lastNeed) {
|
|
363
|
+
r = self.fillLast(buf);
|
|
364
|
+
if (r === undefined) return '';
|
|
365
|
+
i = self.lastNeed;
|
|
366
|
+
self.lastNeed = 0;
|
|
367
|
+
} else {
|
|
368
|
+
i = 0;
|
|
369
|
+
}
|
|
370
|
+
if (i < buf.length) return r ? r + self.text(buf, i) : self.text(buf, i);
|
|
371
|
+
return r || '';
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
decoderPrototype.end = function end(this: unknown, buffer?: unknown): string {
|
|
375
|
+
return utf8End.call(assertDecoder(this), buffer);
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
decoderPrototype.text = function text(this: unknown, buffer: Buffer, offset: number): string {
|
|
379
|
+
return utf8Text.call(assertDecoder(this), buffer, offset);
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
/** Node's generic fillLast, for every encoding but UTF-8, which has its own. */
|
|
383
|
+
decoderPrototype.fillLast = function fillLast(this: unknown, buf: Buffer): string | undefined {
|
|
384
|
+
const self = assertDecoder(this);
|
|
385
|
+
if (self.lastNeed <= buf.length) {
|
|
386
|
+
buf.copy(self.lastChar, self.lastTotal - self.lastNeed, 0, self.lastNeed);
|
|
387
|
+
return self.lastChar.toString(self.encoding as BufferEncoding, 0, self.lastTotal);
|
|
388
|
+
}
|
|
389
|
+
buf.copy(self.lastChar, self.lastTotal - self.lastNeed, 0, buf.length);
|
|
390
|
+
self.lastNeed -= buf.length;
|
|
391
|
+
return undefined;
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
export const StringDecoder = StringDecoderImpl as unknown as StringDecoderConstructor;
|
|
395
|
+
|
|
396
|
+
export default { StringDecoder };
|