@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
package/src/transform.ts
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ESM to CJS Transformer using esbuild-wasm
|
|
3
|
+
*
|
|
4
|
+
* Transforms ES modules to CommonJS format during npm install,
|
|
5
|
+
* so require() can work synchronously.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { VirtualFS } from './virtual-fs';
|
|
9
|
+
import { ESBUILD_WASM_ESM_CDN, ESBUILD_WASM_BINARY_CDN } from './config/cdn';
|
|
10
|
+
// The dev servers and this transformer took a realm without a window for no
|
|
11
|
+
// browser at all and served a file untransformed. A realm with an esbuild
|
|
12
|
+
// host installed, the engine's worker among them, transforms through it
|
|
13
|
+
// wherever it is.
|
|
14
|
+
import { getEsbuildInstance } from './shims/esbuild';
|
|
15
|
+
|
|
16
|
+
// Check if we're in a browser environment
|
|
17
|
+
const isBrowser = typeof window !== 'undefined';
|
|
18
|
+
|
|
19
|
+
// Window.__esbuild type is declared in src/types/external.d.ts
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Node's builtin specifiers, for the dynamic imports the transformer lowers.
|
|
23
|
+
*
|
|
24
|
+
* A CommonJS module's `import("fs/promises")` reaches the browser's own import
|
|
25
|
+
* and fails on the bare specifier, so the subpath builtins are on this list
|
|
26
|
+
* too. `stream/web` is the web streams the worker already has as globals,
|
|
27
|
+
* which file-type, on Dub's middleware path, could not find; and `constants`
|
|
28
|
+
* is Node's old flat table of fs, os and signal numbers, which graceful-fs
|
|
29
|
+
* still requires on its way into every React Router build.
|
|
30
|
+
*
|
|
31
|
+
* There was one of these lists per lowering path and they drifted: the path
|
|
32
|
+
* for a package that is already CommonJS carried only the twenty-nine
|
|
33
|
+
* top-level names, so a pre-bundled package's `import("fs/promises")`,
|
|
34
|
+
* `import("stream/web")` or `import("constants")` went to the browser
|
|
35
|
+
* untouched and the import rejected. One list serves both.
|
|
36
|
+
*/
|
|
37
|
+
const NODE_DYNAMIC_IMPORT_BUILTINS = [
|
|
38
|
+
'stream/web', 'fs/promises', 'stream/promises', 'stream/consumers',
|
|
39
|
+
'timers/promises', 'dns/promises', 'readline/promises', 'path/posix',
|
|
40
|
+
'path/win32', 'util/types', 'assert/strict',
|
|
41
|
+
'assert', 'buffer', 'constants', 'child_process', 'cluster', 'crypto', 'dgram', 'dns',
|
|
42
|
+
'events', 'fs', 'http', 'http2', 'https', 'net', 'os', 'path', 'perf_hooks',
|
|
43
|
+
'querystring', 'readline', 'stream', 'string_decoder', 'timers', 'tls',
|
|
44
|
+
'url', 'util', 'v8', 'vm', 'worker_threads', 'zlib', 'async_hooks', 'inspector', 'module',
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
/** `import("node:x")` and `import("x")` for a builtin, lowered to `require`. */
|
|
48
|
+
function lowerDynamicBuiltinImports(code: string): string {
|
|
49
|
+
// The browser fetches `node:http` as a URL, so the prefixed form goes first.
|
|
50
|
+
let lowered = code.replace(
|
|
51
|
+
/\bimport\s*\(\s*["']node:([^"']+)["']\s*\)/g,
|
|
52
|
+
'Promise.resolve(require("node:$1"))'
|
|
53
|
+
);
|
|
54
|
+
for (const builtin of NODE_DYNAMIC_IMPORT_BUILTINS) {
|
|
55
|
+
// Match import("fs") or import('fs') but not import("fs-extra") etc
|
|
56
|
+
const pattern = new RegExp(`\\bimport\\s*\\(\\s*["']${builtin}["']\\s*\\)`, 'g');
|
|
57
|
+
lowered = lowered.replace(pattern, `Promise.resolve(require("${builtin}"))`);
|
|
58
|
+
}
|
|
59
|
+
return lowered;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Initialize esbuild-wasm (reuses existing instance if already initialized)
|
|
64
|
+
*/
|
|
65
|
+
export async function initTransformer(): Promise<void> {
|
|
66
|
+
if (getEsbuildInstance()) return;
|
|
67
|
+
// Skip in non-browser environments (tests)
|
|
68
|
+
if (!isBrowser) {
|
|
69
|
+
console.log('[transform] Skipping esbuild init (not in browser)');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Reuse existing esbuild instance from window (may have been initialized by next-dev-server)
|
|
74
|
+
if (window.__esbuild) {
|
|
75
|
+
console.log('[transform] Reusing existing esbuild instance');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// If another init is in progress, wait for it
|
|
80
|
+
if (window.__esbuildInitPromise) {
|
|
81
|
+
return window.__esbuildInitPromise;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
window.__esbuildInitPromise = (async () => {
|
|
85
|
+
try {
|
|
86
|
+
console.log('[transform] Loading esbuild-wasm...');
|
|
87
|
+
|
|
88
|
+
// Load esbuild-wasm from CDN
|
|
89
|
+
const mod = await import(
|
|
90
|
+
/* @vite-ignore */
|
|
91
|
+
ESBUILD_WASM_ESM_CDN
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// esm.sh wraps the module - get the actual esbuild object
|
|
95
|
+
const esbuildMod = mod.default || mod;
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
await esbuildMod.initialize({
|
|
99
|
+
wasmURL: ESBUILD_WASM_BINARY_CDN,
|
|
100
|
+
});
|
|
101
|
+
console.log('[transform] esbuild-wasm initialized');
|
|
102
|
+
} catch (initError) {
|
|
103
|
+
// Handle "already initialized" error gracefully
|
|
104
|
+
if (initError instanceof Error && initError.message.includes('Cannot call "initialize" more than once')) {
|
|
105
|
+
console.log('[transform] esbuild-wasm already initialized, reusing');
|
|
106
|
+
} else {
|
|
107
|
+
throw initError;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
window.__esbuild = esbuildMod;
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error('[transform] Failed to initialize esbuild:', error);
|
|
114
|
+
window.__esbuildInitPromise = undefined;
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
})();
|
|
118
|
+
|
|
119
|
+
return window.__esbuildInitPromise;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Check if transformer is ready
|
|
124
|
+
*/
|
|
125
|
+
export function isTransformerReady(): boolean {
|
|
126
|
+
if (getEsbuildInstance()) return true;
|
|
127
|
+
// In non-browser, we skip transformation
|
|
128
|
+
if (!isBrowser) return true;
|
|
129
|
+
return window.__esbuild !== undefined;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Transform a single file from ESM to CJS
|
|
134
|
+
*/
|
|
135
|
+
export async function transformFile(
|
|
136
|
+
code: string,
|
|
137
|
+
filename: string
|
|
138
|
+
): Promise<string> {
|
|
139
|
+
// Skip in non-browser environments
|
|
140
|
+
if (!getEsbuildInstance() && !isBrowser) {
|
|
141
|
+
return code;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!getEsbuildInstance() && !window.__esbuild) {
|
|
145
|
+
await initTransformer();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const esbuild = getEsbuildInstance() ?? window.__esbuild;
|
|
149
|
+
if (!esbuild) {
|
|
150
|
+
throw new Error('esbuild not initialized');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Determine loader based on file extension
|
|
154
|
+
let loader: 'js' | 'jsx' | 'ts' | 'tsx' = 'js';
|
|
155
|
+
if (filename.endsWith('.jsx')) loader = 'jsx';
|
|
156
|
+
else if (filename.endsWith('.ts')) loader = 'ts';
|
|
157
|
+
else if (filename.endsWith('.tsx')) loader = 'tsx';
|
|
158
|
+
else if (filename.endsWith('.mjs')) loader = 'js';
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
const result = await esbuild.transform(code, {
|
|
162
|
+
loader,
|
|
163
|
+
format: 'cjs',
|
|
164
|
+
target: 'esnext',
|
|
165
|
+
platform: 'neutral',
|
|
166
|
+
// Replace import.meta with our runtime-provided variable
|
|
167
|
+
// This is the proper esbuild way to handle import.meta in CJS
|
|
168
|
+
define: {
|
|
169
|
+
'import.meta.url': 'import_meta.url',
|
|
170
|
+
'import.meta.dirname': 'import_meta.dirname',
|
|
171
|
+
'import.meta.filename': 'import_meta.filename',
|
|
172
|
+
'import.meta': 'import_meta',
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Dynamic imports of Node's builtins are lowered to `require`, the
|
|
177
|
+
// prefixed and bare forms alike; the list and the rewrite are shared with
|
|
178
|
+
// the already-CommonJS path below.
|
|
179
|
+
const transformed = lowerDynamicBuiltinImports(result.code);
|
|
180
|
+
|
|
181
|
+
return transformed;
|
|
182
|
+
} catch (error: unknown) {
|
|
183
|
+
// Check if it's a top-level await error - these files are usually CLI entry points
|
|
184
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
185
|
+
if (errorMsg.includes('Top-level await')) {
|
|
186
|
+
console.log(`[transform] Skipping ${filename} (has top-level await, likely CLI entry point)`);
|
|
187
|
+
// Return original code - it won't be require()'d directly anyway
|
|
188
|
+
return code;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
console.warn(`[transform] Failed to transform ${filename}:`, error);
|
|
192
|
+
// Return original code if transform fails
|
|
193
|
+
return code;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Check if a file needs ESM to CJS transformation
|
|
199
|
+
*/
|
|
200
|
+
function needsTransform(filename: string, code: string): boolean {
|
|
201
|
+
// .mjs files are always ESM
|
|
202
|
+
if (filename.endsWith('.mjs')) {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// .cjs files are always CJS
|
|
207
|
+
if (filename.endsWith('.cjs')) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Check for ESM syntax
|
|
212
|
+
const hasImport = /\bimport\s+[\w{*'"]/m.test(code);
|
|
213
|
+
const hasExport = /\bexport\s+(?:default|const|let|var|function|class|{|\*)/m.test(code);
|
|
214
|
+
const hasImportMeta = /\bimport\.meta\b/.test(code);
|
|
215
|
+
|
|
216
|
+
return hasImport || hasExport || hasImportMeta;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Check if a file has dynamic imports that need patching
|
|
221
|
+
*/
|
|
222
|
+
function hasDynamicNodeImports(code: string): boolean {
|
|
223
|
+
// Check for import("node:...") or import('node:...')
|
|
224
|
+
if (/\bimport\s*\(\s*["']node:/.test(code)) {
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
// Any builtin the lowering knows, not the eleven names this test used to
|
|
228
|
+
// carry: a package whose only dynamic builtin import was `child_process` or
|
|
229
|
+
// `fs/promises` was never offered to the lowering at all.
|
|
230
|
+
const names = NODE_DYNAMIC_IMPORT_BUILTINS.map((name) => name.replace('/', '\\/')).join('|');
|
|
231
|
+
return new RegExp(`\\bimport\\s*\\(\\s*["'](?:${names})["']\\s*\\)`).test(code);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Patch dynamic imports in already-CJS code (e.g., pre-bundled packages)
|
|
236
|
+
*/
|
|
237
|
+
function patchDynamicImports(code: string): string {
|
|
238
|
+
return lowerDynamicBuiltinImports(code);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Transform all ESM files in a package directory to CJS
|
|
243
|
+
*/
|
|
244
|
+
export async function transformPackage(
|
|
245
|
+
vfs: VirtualFS,
|
|
246
|
+
pkgPath: string,
|
|
247
|
+
onProgress?: (msg: string) => void
|
|
248
|
+
): Promise<number> {
|
|
249
|
+
let transformedCount = 0;
|
|
250
|
+
|
|
251
|
+
// Find all JS files in the package
|
|
252
|
+
const jsFiles = findJsFiles(vfs, pkgPath);
|
|
253
|
+
|
|
254
|
+
onProgress?.(` Transforming ${jsFiles.length} files in ${pkgPath}...`);
|
|
255
|
+
|
|
256
|
+
// Transform files in batches
|
|
257
|
+
const BATCH_SIZE = 10;
|
|
258
|
+
for (let i = 0; i < jsFiles.length; i += BATCH_SIZE) {
|
|
259
|
+
const batch = jsFiles.slice(i, i + BATCH_SIZE);
|
|
260
|
+
|
|
261
|
+
await Promise.all(
|
|
262
|
+
batch.map(async (filePath) => {
|
|
263
|
+
try {
|
|
264
|
+
const code = vfs.readFileSync(filePath, 'utf8');
|
|
265
|
+
|
|
266
|
+
if (needsTransform(filePath, code)) {
|
|
267
|
+
// Full ESM to CJS transformation
|
|
268
|
+
const transformed = await transformFile(code, filePath);
|
|
269
|
+
vfs.writeFileSync(filePath, transformed);
|
|
270
|
+
transformedCount++;
|
|
271
|
+
} else if (hasDynamicNodeImports(code)) {
|
|
272
|
+
// Just patch dynamic imports in already-CJS code
|
|
273
|
+
const patched = patchDynamicImports(code);
|
|
274
|
+
vfs.writeFileSync(filePath, patched);
|
|
275
|
+
transformedCount++;
|
|
276
|
+
}
|
|
277
|
+
} catch (error) {
|
|
278
|
+
// Skip files that can't be read/transformed
|
|
279
|
+
console.warn(`[transform] Skipping ${filePath}:`, error);
|
|
280
|
+
}
|
|
281
|
+
})
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return transformedCount;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Find all JavaScript files in a directory recursively
|
|
290
|
+
*/
|
|
291
|
+
function findJsFiles(vfs: VirtualFS, dir: string): string[] {
|
|
292
|
+
const files: string[] = [];
|
|
293
|
+
|
|
294
|
+
try {
|
|
295
|
+
const entries = vfs.readdirSync(dir);
|
|
296
|
+
|
|
297
|
+
for (const entry of entries) {
|
|
298
|
+
const fullPath = dir + '/' + entry;
|
|
299
|
+
|
|
300
|
+
try {
|
|
301
|
+
const stat = vfs.statSync(fullPath);
|
|
302
|
+
|
|
303
|
+
if (stat.isDirectory()) {
|
|
304
|
+
// Skip node_modules inside packages (nested deps)
|
|
305
|
+
if (entry !== 'node_modules') {
|
|
306
|
+
files.push(...findJsFiles(vfs, fullPath));
|
|
307
|
+
}
|
|
308
|
+
} else if (
|
|
309
|
+
entry.endsWith('.js') ||
|
|
310
|
+
entry.endsWith('.mjs') ||
|
|
311
|
+
entry.endsWith('.jsx')
|
|
312
|
+
) {
|
|
313
|
+
files.push(fullPath);
|
|
314
|
+
}
|
|
315
|
+
} catch {
|
|
316
|
+
// Skip files we can't stat
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
} catch {
|
|
320
|
+
// Skip directories we can't read
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return files;
|
|
324
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for CDN-loaded modules
|
|
3
|
+
*
|
|
4
|
+
* Dynamic imports use variable URLs from src/config/cdn.ts, so we declare
|
|
5
|
+
* types on the base module names. TypeScript resolves them via the
|
|
6
|
+
* `esbuild-wasm` and `@rollup/browser` module declarations below.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Type declarations for esbuild-wasm to support dynamic import from CDN
|
|
10
|
+
interface EsbuildTransformOptions {
|
|
11
|
+
loader?: string;
|
|
12
|
+
jsx?: string;
|
|
13
|
+
jsxFactory?: string;
|
|
14
|
+
jsxFragment?: string;
|
|
15
|
+
jsxImportSource?: string;
|
|
16
|
+
sourcemap?: boolean | 'inline' | 'external' | 'both';
|
|
17
|
+
sourcefile?: string;
|
|
18
|
+
target?: string | string[];
|
|
19
|
+
format?: 'iife' | 'cjs' | 'esm';
|
|
20
|
+
minify?: boolean;
|
|
21
|
+
tsconfigRaw?: string | object;
|
|
22
|
+
platform?: 'browser' | 'node' | 'neutral';
|
|
23
|
+
define?: Record<string, string>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface EsbuildTransformResult {
|
|
27
|
+
code: string;
|
|
28
|
+
map: string;
|
|
29
|
+
warnings: unknown[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Declare the esbuild-wasm module for type-only imports
|
|
33
|
+
declare module 'esbuild-wasm' {
|
|
34
|
+
export function initialize(options?: { wasmURL?: string; worker?: boolean }): Promise<void>;
|
|
35
|
+
export function transform(input: string, options?: EsbuildTransformOptions): Promise<EsbuildTransformResult>;
|
|
36
|
+
export function build(options: unknown): Promise<unknown>;
|
|
37
|
+
export function formatMessages(messages: unknown[], options: unknown): Promise<string[]>;
|
|
38
|
+
export const version: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Centralized Window interface augmentation for esbuild
|
|
42
|
+
interface Window {
|
|
43
|
+
__esbuild?: typeof import('esbuild-wasm');
|
|
44
|
+
__esbuildInitPromise?: Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Vite's `?raw` import: the file's text, as a string. The engine uses it to
|
|
49
|
+
* carry Node's own vendored library sources (src/node-lib/*.js) into the
|
|
50
|
+
* bundle unmodified, to be evaluated on a binding.
|
|
51
|
+
*/
|
|
52
|
+
declare module '*?raw' {
|
|
53
|
+
const content: string;
|
|
54
|
+
export default content;
|
|
55
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definition for package.json files
|
|
3
|
+
*/
|
|
4
|
+
export interface PackageJson {
|
|
5
|
+
name?: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
main?: string;
|
|
8
|
+
module?: string;
|
|
9
|
+
browser?: string | Record<string, string | false>;
|
|
10
|
+
types?: string;
|
|
11
|
+
exports?: Record<string, unknown> | string;
|
|
12
|
+
dependencies?: Record<string, string>;
|
|
13
|
+
devDependencies?: Record<string, string>;
|
|
14
|
+
peerDependencies?: Record<string, string>;
|
|
15
|
+
scripts?: Record<string, string>;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pako's zlib layer has no types of its own: it is zlib's C ported to
|
|
3
|
+
* JavaScript, and DefinitelyTyped describes only pako's public API. The
|
|
4
|
+
* shapes the engine relies on are stated where they are used, in
|
|
5
|
+
* `src/node-lib/binding/zlib-pako.ts`; this says the modules exist.
|
|
6
|
+
*/
|
|
7
|
+
declare module 'pako/lib/zlib/zstream.js' {
|
|
8
|
+
const ZStream: new () => Record<string, unknown>;
|
|
9
|
+
export default ZStream;
|
|
10
|
+
}
|
|
11
|
+
declare module 'pako/lib/zlib/inflate.js' {
|
|
12
|
+
const value: Record<string, unknown>;
|
|
13
|
+
export = value;
|
|
14
|
+
}
|
|
15
|
+
declare module 'pako/lib/zlib/deflate.js' {
|
|
16
|
+
const value: Record<string, unknown>;
|
|
17
|
+
export = value;
|
|
18
|
+
}
|
|
19
|
+
declare module 'pako/lib/zlib/constants.js' {
|
|
20
|
+
const value: Record<string, number>;
|
|
21
|
+
export default value;
|
|
22
|
+
}
|
|
23
|
+
declare module 'pako/lib/zlib/crc32.js' {
|
|
24
|
+
const value: (crc: number, buffer: Uint8Array, length: number, position: number) => number;
|
|
25
|
+
export default value;
|
|
26
|
+
}
|
|
27
|
+
declare module 'pako/lib/zlib/messages.js' {
|
|
28
|
+
const value: Record<number, string>;
|
|
29
|
+
export default value;
|
|
30
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sha.js ships no types. It is a CommonJS factory: SHA(algorithm) returns a
|
|
3
|
+
* streaming hash whose state lives in own fields, which crypto.ts copies by
|
|
4
|
+
* value for Hash.copy() because sha.js has no clone.
|
|
5
|
+
*/
|
|
6
|
+
declare module 'sha.js' {
|
|
7
|
+
interface ShaHash {
|
|
8
|
+
update(data: Uint8Array | string, encoding?: string): ShaHash;
|
|
9
|
+
digest(): Uint8Array;
|
|
10
|
+
[field: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
function SHA(algorithm: string): ShaHash;
|
|
13
|
+
export = SHA;
|
|
14
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared binary encoding utilities.
|
|
3
|
+
* Replaces O(n²) string concatenation patterns used throughout the codebase.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const CHUNK = 8192;
|
|
7
|
+
|
|
8
|
+
/** Convert Uint8Array to base64 string */
|
|
9
|
+
export function uint8ToBase64(bytes: Uint8Array): string {
|
|
10
|
+
const parts: string[] = [];
|
|
11
|
+
for (let i = 0; i < bytes.length; i += CHUNK) {
|
|
12
|
+
parts.push(String.fromCharCode.apply(null, Array.from(bytes.subarray(i, i + CHUNK))));
|
|
13
|
+
}
|
|
14
|
+
return btoa(parts.join(''));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Convert base64 string to Uint8Array */
|
|
18
|
+
export function base64ToUint8(base64: string): Uint8Array {
|
|
19
|
+
const binary = atob(base64);
|
|
20
|
+
const bytes = new Uint8Array(binary.length);
|
|
21
|
+
for (let i = 0; i < binary.length; i++) {
|
|
22
|
+
bytes[i] = binary.charCodeAt(i);
|
|
23
|
+
}
|
|
24
|
+
return bytes;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Convert Uint8Array to hex string */
|
|
28
|
+
export function uint8ToHex(bytes: Uint8Array): string {
|
|
29
|
+
const hex = new Array(bytes.length);
|
|
30
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
31
|
+
hex[i] = bytes[i].toString(16).padStart(2, '0');
|
|
32
|
+
}
|
|
33
|
+
return hex.join('');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Convert Uint8Array to binary (latin1) string */
|
|
37
|
+
export function uint8ToBinaryString(bytes: Uint8Array): string {
|
|
38
|
+
const parts: string[] = [];
|
|
39
|
+
for (let i = 0; i < bytes.length; i += CHUNK) {
|
|
40
|
+
parts.push(String.fromCharCode.apply(null, Array.from(bytes.subarray(i, i + CHUNK))));
|
|
41
|
+
}
|
|
42
|
+
return parts.join('');
|
|
43
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's glob, for `path.matchesGlob` and for `fs.glob`: `**` crosses
|
|
3
|
+
* separators, `*` and `?` do not, `[...]` is a character class and `{a,b}` is
|
|
4
|
+
* an alternation, and the whole path is matched.
|
|
5
|
+
*
|
|
6
|
+
* It lives here because both the builtin table in `runtime.ts` and the fs
|
|
7
|
+
* shim's `globSync` need it. It used to be a function declared in
|
|
8
|
+
* `runtime.ts` and merely `declare`d in `src/shims/fs.ts`, on the belief that
|
|
9
|
+
* the bundle gives every module one shared scope; it does not, so a guest
|
|
10
|
+
* that called `fs.globSync` — the vitest and Prisma CLIs glob for their own
|
|
11
|
+
* files — died on `__browserRuntimeNodeGlob is not defined`. A module both
|
|
12
|
+
* import is the same helper in either build.
|
|
13
|
+
*
|
|
14
|
+
* This is not npm's package.json glob, which anchors a pattern without a
|
|
15
|
+
* separator at any segment; that one stays with the installer, since each
|
|
16
|
+
* source system keeps its own semantics.
|
|
17
|
+
*/
|
|
18
|
+
export function globToRegExp(glob: string, nocase = false): RegExp {
|
|
19
|
+
return new RegExp("^" + globBody(glob) + "$", nocase ? "i" : "");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function globBody(glob: string): string {
|
|
23
|
+
let out = "";
|
|
24
|
+
for (let i = 0; i < glob.length; i++) {
|
|
25
|
+
const ch = glob[i];
|
|
26
|
+
if (ch === "*") {
|
|
27
|
+
if (glob[i + 1] === "*") {
|
|
28
|
+
i++;
|
|
29
|
+
if (glob[i + 1] === "/") { i++; out += "(?:[^/]*\\/)*"; } else out += ".*";
|
|
30
|
+
} else out += "[^/]*";
|
|
31
|
+
} else if (ch === "?") {
|
|
32
|
+
out += "[^/]";
|
|
33
|
+
} else if (ch === "[") {
|
|
34
|
+
let end = i + 1;
|
|
35
|
+
let body = "";
|
|
36
|
+
if (glob[end] === "!" || glob[end] === "^") { body += "^"; end++; }
|
|
37
|
+
for (; end < glob.length && glob[end] !== "]"; end++) body += glob[end] === "\\" ? "\\\\" : glob[end];
|
|
38
|
+
if (end >= glob.length) out += "\\["; else { out += "[" + body + "]"; i = end; }
|
|
39
|
+
} else if (ch === "{") {
|
|
40
|
+
let depth = 1;
|
|
41
|
+
let end = i + 1;
|
|
42
|
+
let body = "";
|
|
43
|
+
for (; end < glob.length; end++) {
|
|
44
|
+
if (glob[end] === "{") depth++;
|
|
45
|
+
else if (glob[end] === "}") { depth--; if (depth === 0) break; }
|
|
46
|
+
body += glob[end];
|
|
47
|
+
}
|
|
48
|
+
if (depth !== 0) out += "\\{"; else { out += "(?:" + body.split(",").map(globBody).join("|") + ")"; i = end; }
|
|
49
|
+
} else {
|
|
50
|
+
out += ch.replace(/[.+^$()|\]}\\]/g, "\\$&");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple hash function for content-based cache invalidation.
|
|
3
|
+
* Uses djb2-style hashing for fast string hashing.
|
|
4
|
+
*/
|
|
5
|
+
export function simpleHash(str: string): string {
|
|
6
|
+
let hash = 0;
|
|
7
|
+
for (let i = 0; i < str.length; i++) {
|
|
8
|
+
hash = ((hash << 5) - hash) + str.charCodeAt(i);
|
|
9
|
+
hash |= 0;
|
|
10
|
+
}
|
|
11
|
+
return hash.toString(36);
|
|
12
|
+
}
|