@volter/tabnode 0.5.25 → 0.5.27
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/dist/assets/{runtime-worker-D6N3DujB.js → runtime-worker-DPvtXRd8.js} +248 -21
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +288 -599
- package/dist/port-bridge-CixAESwA.js +655 -0
- package/dist/port-bridge.d.ts +175 -0
- package/dist/port-bridge.mjs +6 -0
- package/dist/runtime.d.ts +13 -0
- package/dist/server-bridge.d.ts +9 -130
- package/package.json +5 -1
- package/src/index.ts +2 -1
- package/src/port-bridge.ts +791 -0
- package/src/runtime.ts +73 -38
- package/src/server-bridge.ts +22 -664
package/dist/index.mjs
CHANGED
|
@@ -18,6 +18,8 @@ var __privateWrapper = (obj, member, setter, getter) => ({
|
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
var _a, _b, _asyncId, _triggerAsyncId, _c, _d, _e, _f, _g, _h, _i, _j, _ptr, _type, _maxHeaderSize, _headerBytes, _headers, _field, _value, _readingValue, _url, _statusMessage, _headersSent, _paused, _buffer, _bufferPtr, _bufferSize, _connections, _HTTPParser_instances, reset_fn, copyIn_fn, pushHeader_fn, countHeaderBytes_fn, _parsers, _strm, _writeState, _callback, _level, _strategy, _windowBits, _memLevel, _dictionary, _ended, _Zlib_instances, inflating_get, windowFor_fn, start_fn, fail_fn, report_fn, run_fn, end_fn, _writeState2, _callback2, _input, _output, _outputAt, _BrotliDecoderHandle_instances, run_fn2, _k, _resolveChain, _loadChain, _initializing, _initializeFailure, _RunModuleHooks_instances, run_fn3;
|
|
21
|
+
import { u as uint8ToBase64, b as base64ToUint8, a as uint8ToBinaryString, c as uint8ToHex, P as PortBridge } from "./port-bridge-CixAESwA.js";
|
|
22
|
+
import { g } from "./port-bridge-CixAESwA.js";
|
|
21
23
|
import { defineCommand, Bash, getCommandNames } from "just-bash";
|
|
22
24
|
import { imports, resolve as resolve$3 } from "resolve.exports";
|
|
23
25
|
import { wrap, proxy } from "comlink";
|
|
@@ -94,36 +96,6 @@ forGuestRealm(() => {
|
|
|
94
96
|
const realm = globalThis;
|
|
95
97
|
if (!realm.__browserRuntimeHeldWork) takeFromHost(globalThis, "__browserRuntimeHeldWork", ownHeldWork);
|
|
96
98
|
});
|
|
97
|
-
const CHUNK = 8192;
|
|
98
|
-
function uint8ToBase64(bytes2) {
|
|
99
|
-
const parts = [];
|
|
100
|
-
for (let i2 = 0; i2 < bytes2.length; i2 += CHUNK) {
|
|
101
|
-
parts.push(String.fromCharCode.apply(null, Array.from(bytes2.subarray(i2, i2 + CHUNK))));
|
|
102
|
-
}
|
|
103
|
-
return btoa(parts.join(""));
|
|
104
|
-
}
|
|
105
|
-
function base64ToUint8(base642) {
|
|
106
|
-
const binary = atob(base642);
|
|
107
|
-
const bytes2 = new Uint8Array(binary.length);
|
|
108
|
-
for (let i2 = 0; i2 < binary.length; i2++) {
|
|
109
|
-
bytes2[i2] = binary.charCodeAt(i2);
|
|
110
|
-
}
|
|
111
|
-
return bytes2;
|
|
112
|
-
}
|
|
113
|
-
function uint8ToHex(bytes2) {
|
|
114
|
-
const hex = new Array(bytes2.length);
|
|
115
|
-
for (let i2 = 0; i2 < bytes2.length; i2++) {
|
|
116
|
-
hex[i2] = bytes2[i2].toString(16).padStart(2, "0");
|
|
117
|
-
}
|
|
118
|
-
return hex.join("");
|
|
119
|
-
}
|
|
120
|
-
function uint8ToBinaryString(bytes2) {
|
|
121
|
-
const parts = [];
|
|
122
|
-
for (let i2 = 0; i2 < bytes2.length; i2 += CHUNK) {
|
|
123
|
-
parts.push(String.fromCharCode.apply(null, Array.from(bytes2.subarray(i2, i2 + CHUNK))));
|
|
124
|
-
}
|
|
125
|
-
return parts.join("");
|
|
126
|
-
}
|
|
127
99
|
const PRIMORDIALS_SOURCE = "'use strict';\n\n/* eslint-disable node-core/prefer-primordials */\n\n// This file subclasses and stores the JS builtins that come from the VM\n// so that Node.js's builtin modules do not need to later look these up from\n// the global proxy, which can be mutated by users.\n\n// Use of primordials have sometimes a dramatic impact on performance, please\n// benchmark all changes made in performance-sensitive areas of the codebase.\n// See: https://github.com/nodejs/node/pull/38248\n\nconst {\n defineProperty: ReflectDefineProperty,\n getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,\n ownKeys: ReflectOwnKeys,\n} = Reflect;\n\n// `uncurryThis` is equivalent to `func => Function.prototype.call.bind(func)`.\n// It is using `bind.bind(call)` to avoid using `Function.prototype.bind`\n// and `Function.prototype.call` after it may have been mutated by users.\nconst { apply, bind, call } = Function.prototype;\nconst uncurryThis = bind.bind(call);\nprimordials.uncurryThis = uncurryThis;\n\n// `applyBind` is equivalent to `func => Function.prototype.apply.bind(func)`.\n// It is using `bind.bind(apply)` to avoid using `Function.prototype.bind`\n// and `Function.prototype.apply` after it may have been mutated by users.\nconst applyBind = bind.bind(apply);\nprimordials.applyBind = applyBind;\n\n// Methods that accept a variable number of arguments, and thus it's useful to\n// also create `${prefix}${key}Apply`, which uses `Function.prototype.apply`,\n// instead of `Function.prototype.call`, and thus doesn't require iterator\n// destructuring.\nconst varargsMethods = [\n // 'ArrayPrototypeConcat' is omitted, because it performs the spread\n // on its own for arrays and array-likes with a truthy\n // @@isConcatSpreadable symbol property.\n 'ArrayOf',\n 'ArrayPrototypePush',\n 'ArrayPrototypeUnshift',\n // 'FunctionPrototypeCall' is omitted, since there's 'ReflectApply'\n // and 'FunctionPrototypeApply'.\n 'MathHypot',\n 'MathMax',\n 'MathMin',\n 'StringFromCharCode',\n 'StringFromCodePoint',\n 'StringPrototypeConcat',\n 'TypedArrayOf',\n];\n\nfunction getNewKey(key) {\n return typeof key === 'symbol' ?\n `Symbol${key.description[7].toUpperCase()}${key.description.slice(8)}` :\n `${key[0].toUpperCase()}${key.slice(1)}`;\n}\n\nfunction copyAccessor(dest, prefix, key, { enumerable, get, set }) {\n ReflectDefineProperty(dest, `${prefix}Get${key}`, {\n __proto__: null,\n value: uncurryThis(get),\n enumerable,\n });\n if (set !== undefined) {\n ReflectDefineProperty(dest, `${prefix}Set${key}`, {\n __proto__: null,\n value: uncurryThis(set),\n enumerable,\n });\n }\n}\n\nfunction copyPropsRenamed(src, dest, prefix) {\n for (const key of ReflectOwnKeys(src)) {\n const newKey = getNewKey(key);\n const desc = ReflectGetOwnPropertyDescriptor(src, key);\n if ('get' in desc) {\n copyAccessor(dest, prefix, newKey, desc);\n } else {\n const name = `${prefix}${newKey}`;\n ReflectDefineProperty(dest, name, { __proto__: null, ...desc });\n if (varargsMethods.includes(name)) {\n ReflectDefineProperty(dest, `${name}Apply`, {\n __proto__: null,\n // `src` is bound as the `this` so that the static `this` points\n // to the object it was defined on,\n // e.g.: `ArrayOfApply` gets a `this` of `Array`:\n value: applyBind(desc.value, src),\n });\n }\n }\n }\n}\n\nfunction copyPropsRenamedBound(src, dest, prefix) {\n for (const key of ReflectOwnKeys(src)) {\n const newKey = getNewKey(key);\n const desc = ReflectGetOwnPropertyDescriptor(src, key);\n if ('get' in desc) {\n copyAccessor(dest, prefix, newKey, desc);\n } else {\n const { value } = desc;\n if (typeof value === 'function') {\n desc.value = value.bind(src);\n }\n\n const name = `${prefix}${newKey}`;\n ReflectDefineProperty(dest, name, { __proto__: null, ...desc });\n if (varargsMethods.includes(name)) {\n ReflectDefineProperty(dest, `${name}Apply`, {\n __proto__: null,\n value: applyBind(value, src),\n });\n }\n }\n }\n}\n\nfunction copyPrototype(src, dest, prefix) {\n for (const key of ReflectOwnKeys(src)) {\n const newKey = getNewKey(key);\n const desc = ReflectGetOwnPropertyDescriptor(src, key);\n if ('get' in desc) {\n copyAccessor(dest, prefix, newKey, desc);\n } else {\n const { value } = desc;\n if (typeof value === 'function') {\n desc.value = uncurryThis(value);\n }\n\n const name = `${prefix}${newKey}`;\n ReflectDefineProperty(dest, name, { __proto__: null, ...desc });\n if (varargsMethods.includes(name)) {\n ReflectDefineProperty(dest, `${name}Apply`, {\n __proto__: null,\n value: applyBind(value),\n });\n }\n }\n }\n}\n\n// Create copies of configurable value properties of the global object\n[\n 'Proxy',\n 'globalThis',\n].forEach((name) => {\n // eslint-disable-next-line no-restricted-globals\n primordials[name] = globalThis[name];\n});\n\n// Create copies of URI handling functions\n[\n decodeURI,\n decodeURIComponent,\n encodeURI,\n encodeURIComponent,\n].forEach((fn) => {\n primordials[fn.name] = fn;\n});\n\n// Create copies of legacy functions\n[\n escape,\n eval,\n unescape,\n].forEach((fn) => {\n primordials[fn.name] = fn;\n});\n\n// Create copies of the namespace objects\n[\n 'Atomics',\n 'JSON',\n 'Math',\n 'Proxy',\n 'Reflect',\n].forEach((name) => {\n // eslint-disable-next-line no-restricted-globals\n copyPropsRenamed(globalThis[name], primordials, name);\n});\n\n// Create copies of intrinsic objects\n[\n 'AggregateError',\n 'Array',\n 'ArrayBuffer',\n 'BigInt',\n 'BigInt64Array',\n 'BigUint64Array',\n 'Boolean',\n 'DataView',\n 'Date',\n 'Error',\n 'EvalError',\n 'FinalizationRegistry',\n 'Float32Array',\n 'Float64Array',\n 'Function',\n 'Int16Array',\n 'Int32Array',\n 'Int8Array',\n 'Map',\n 'Number',\n 'Object',\n 'RangeError',\n 'ReferenceError',\n 'RegExp',\n 'Set',\n 'String',\n 'Symbol',\n 'SyntaxError',\n 'TypeError',\n 'URIError',\n 'Uint16Array',\n 'Uint32Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'WeakMap',\n 'WeakRef',\n 'WeakSet',\n].forEach((name) => {\n // eslint-disable-next-line no-restricted-globals\n const original = globalThis[name];\n primordials[name] = original;\n copyPropsRenamed(original, primordials, name);\n copyPrototype(original.prototype, primordials, `${name}Prototype`);\n});\n\n\n// Create copies of intrinsic objects that require a valid `this` to call\n// static methods.\n// Refs: https://www.ecma-international.org/ecma-262/#sec-promise.all\n[\n 'Promise',\n].forEach((name) => {\n // eslint-disable-next-line no-restricted-globals\n const original = globalThis[name];\n primordials[name] = original;\n copyPropsRenamedBound(original, primordials, name);\n copyPrototype(original.prototype, primordials, `${name}Prototype`);\n});\n\n// Create copies of abstract intrinsic objects that are not directly exposed\n// on the global object.\n// Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object\n[\n { name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) },\n { name: 'ArrayIterator', original: {\n prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()),\n } },\n { name: 'StringIterator', original: {\n prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()),\n } },\n].forEach(({ name, original }) => {\n primordials[name] = original;\n // The static %TypedArray% methods require a valid `this`, but can't be bound,\n // as they need a subclass constructor as the receiver:\n copyPrototype(original, primordials, name);\n copyPrototype(original.prototype, primordials, `${name}Prototype`);\n});\n\nprimordials.IteratorPrototype = Reflect.getPrototypeOf(primordials.ArrayIteratorPrototype);\n\n/* eslint-enable node-core/prefer-primordials */\n\nconst {\n Array: ArrayConstructor,\n ArrayPrototypeForEach,\n ArrayPrototypeMap,\n FinalizationRegistry,\n FunctionPrototypeCall,\n Map,\n ObjectDefineProperties,\n ObjectDefineProperty,\n ObjectFreeze,\n ObjectSetPrototypeOf,\n Promise,\n PromisePrototypeThen,\n PromiseResolve,\n ReflectApply,\n ReflectConstruct,\n ReflectGet,\n ReflectSet,\n RegExp,\n RegExpPrototype,\n RegExpPrototypeExec,\n RegExpPrototypeGetDotAll,\n RegExpPrototypeGetFlags,\n RegExpPrototypeGetGlobal,\n RegExpPrototypeGetHasIndices,\n RegExpPrototypeGetIgnoreCase,\n RegExpPrototypeGetMultiline,\n RegExpPrototypeGetSource,\n RegExpPrototypeGetSticky,\n RegExpPrototypeGetUnicode,\n Set,\n SymbolIterator,\n SymbolMatch,\n SymbolMatchAll,\n SymbolReplace,\n SymbolSearch,\n SymbolSpecies,\n SymbolSplit,\n WeakMap,\n WeakRef,\n WeakSet,\n} = primordials;\n\n\n/**\n * Creates a class that can be safely iterated over.\n *\n * Because these functions are used by `makeSafe`, which is exposed on the\n * `primordials` object, it's important to use const references to the\n * primordials that they use.\n * @template {Iterable} T\n * @template {*} TReturn\n * @template {*} TNext\n * @param {(self: T) => IterableIterator<T>} factory\n * @param {(...args: [] | [TNext]) => IteratorResult<T, TReturn>} next\n * @returns {Iterator<T, TReturn, TNext>}\n */\nconst createSafeIterator = (factory, next) => {\n class SafeIterator {\n constructor(iterable) {\n this._iterator = factory(iterable);\n }\n next() {\n return next(this._iterator);\n }\n [SymbolIterator]() {\n return this;\n }\n }\n ObjectSetPrototypeOf(SafeIterator.prototype, null);\n ObjectFreeze(SafeIterator.prototype);\n ObjectFreeze(SafeIterator);\n return SafeIterator;\n};\n\nprimordials.SafeArrayIterator = createSafeIterator(\n primordials.ArrayPrototypeSymbolIterator,\n primordials.ArrayIteratorPrototypeNext,\n);\nprimordials.SafeStringIterator = createSafeIterator(\n primordials.StringPrototypeSymbolIterator,\n primordials.StringIteratorPrototypeNext,\n);\n\nconst copyProps = (src, dest) => {\n ArrayPrototypeForEach(ReflectOwnKeys(src), (key) => {\n if (!ReflectGetOwnPropertyDescriptor(dest, key)) {\n ReflectDefineProperty(\n dest,\n key,\n { __proto__: null, ...ReflectGetOwnPropertyDescriptor(src, key) });\n }\n });\n};\n\n/**\n * @type {typeof primordials.makeSafe}\n */\nconst makeSafe = (unsafe, safe) => {\n if (SymbolIterator in unsafe.prototype) {\n const dummy = new unsafe();\n let next; // We can reuse the same `next` method.\n\n ArrayPrototypeForEach(ReflectOwnKeys(unsafe.prototype), (key) => {\n if (!ReflectGetOwnPropertyDescriptor(safe.prototype, key)) {\n const desc = ReflectGetOwnPropertyDescriptor(unsafe.prototype, key);\n if (\n typeof desc.value === 'function' &&\n desc.value.length === 0 &&\n SymbolIterator in (FunctionPrototypeCall(desc.value, dummy) ?? {})\n ) {\n const createIterator = uncurryThis(desc.value);\n next ??= uncurryThis(createIterator(dummy).next);\n const SafeIterator = createSafeIterator(createIterator, next);\n desc.value = function() {\n return new SafeIterator(this);\n };\n }\n ReflectDefineProperty(safe.prototype, key, { __proto__: null, ...desc });\n }\n });\n } else {\n copyProps(unsafe.prototype, safe.prototype);\n }\n copyProps(unsafe, safe);\n\n ObjectSetPrototypeOf(safe.prototype, null);\n ObjectFreeze(safe.prototype);\n ObjectFreeze(safe);\n return safe;\n};\nprimordials.makeSafe = makeSafe;\n\n// Subclass the constructors because we need to use their prototype\n// methods later.\n// Defining the `constructor` is necessary here to avoid the default\n// constructor which uses the user-mutable `%ArrayIteratorPrototype%.next`.\nprimordials.SafeMap = makeSafe(\n Map,\n class SafeMap extends Map {\n constructor(i) { super(i); } // eslint-disable-line no-useless-constructor\n },\n);\nprimordials.SafeWeakMap = makeSafe(\n WeakMap,\n class SafeWeakMap extends WeakMap {\n constructor(i) { super(i); } // eslint-disable-line no-useless-constructor\n },\n);\n\nprimordials.SafeSet = makeSafe(\n Set,\n class SafeSet extends Set {\n constructor(i) { super(i); } // eslint-disable-line no-useless-constructor\n },\n);\nprimordials.SafeWeakSet = makeSafe(\n WeakSet,\n class SafeWeakSet extends WeakSet {\n constructor(i) { super(i); } // eslint-disable-line no-useless-constructor\n },\n);\n\nprimordials.SafeFinalizationRegistry = makeSafe(\n FinalizationRegistry,\n class SafeFinalizationRegistry extends FinalizationRegistry {\n // eslint-disable-next-line no-useless-constructor\n constructor(cleanupCallback) { super(cleanupCallback); }\n },\n);\nprimordials.SafeWeakRef = makeSafe(\n WeakRef,\n class SafeWeakRef extends WeakRef {\n // eslint-disable-next-line no-useless-constructor\n constructor(target) { super(target); }\n },\n);\n\nconst SafePromise = makeSafe(\n Promise,\n class SafePromise extends Promise {\n // eslint-disable-next-line no-useless-constructor\n constructor(executor) { super(executor); }\n },\n);\n\n/**\n * Attaches a callback that is invoked when the Promise is settled (fulfilled or\n * rejected). The resolved value cannot be modified from the callback.\n * Prefer using async functions when possible.\n * @param {Promise<any>} thisPromise\n * @param {(() => void) | undefined | null} onFinally The callback to execute\n * when the Promise is settled (fulfilled or rejected).\n * @returns {Promise} A Promise for the completion of the callback.\n */\nprimordials.SafePromisePrototypeFinally = (thisPromise, onFinally) =>\n // Wrapping on a new Promise is necessary to not expose the SafePromise\n // prototype to user-land.\n new Promise((a, b) =>\n new SafePromise((a, b) => PromisePrototypeThen(thisPromise, a, b))\n .finally(onFinally)\n .then(a, b),\n );\n\nprimordials.AsyncIteratorPrototype =\n primordials.ReflectGetPrototypeOf(\n primordials.ReflectGetPrototypeOf(\n async function* () {}).prototype);\n\nconst arrayToSafePromiseIterable = (promises, mapFn) =>\n new primordials.SafeArrayIterator(\n ArrayPrototypeMap(\n promises,\n (promise, i) =>\n new SafePromise((a, b) => PromisePrototypeThen(mapFn == null ? promise : mapFn(promise, i), a, b)),\n ),\n );\n\n/**\n * @template T,U\n * @param {Array<T | PromiseLike<T>>} promises\n * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]\n * @returns {Promise<Awaited<U>[]>}\n */\nprimordials.SafePromiseAll = (promises, mapFn) =>\n // Wrapping on a new Promise is necessary to not expose the SafePromise\n // prototype to user-land.\n new Promise((a, b) =>\n SafePromise.all(arrayToSafePromiseIterable(promises, mapFn)).then(a, b),\n );\n\n/**\n * Should only be used for internal functions, this would produce similar\n * results as `Promise.all` but without prototype pollution, and the return\n * value is not a genuine Array but an array-like object.\n * @template T,U\n * @param {ArrayLike<T | PromiseLike<T>>} promises\n * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]\n * @returns {Promise<ArrayLike<Awaited<U>>>}\n */\nprimordials.SafePromiseAllReturnArrayLike = (promises, mapFn) =>\n new Promise((resolve, reject) => {\n const { length } = promises;\n\n const returnVal = ArrayConstructor(length);\n ObjectSetPrototypeOf(returnVal, null);\n if (length === 0) resolve(returnVal);\n\n let pendingPromises = length;\n for (let i = 0; i < length; i++) {\n const promise = mapFn != null ? mapFn(promises[i], i) : promises[i];\n PromisePrototypeThen(PromiseResolve(promise), (result) => {\n returnVal[i] = result;\n if (--pendingPromises === 0) resolve(returnVal);\n }, reject);\n }\n });\n\n/**\n * Should only be used when we only care about waiting for all the promises to\n * resolve, not what value they resolve to.\n * @template T,U\n * @param {ArrayLike<T | PromiseLike<T>>} promises\n * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]\n * @returns {Promise<void>}\n */\nprimordials.SafePromiseAllReturnVoid = (promises, mapFn) =>\n new Promise((resolve, reject) => {\n let pendingPromises = promises.length;\n if (pendingPromises === 0) resolve();\n const onFulfilled = () => {\n if (--pendingPromises === 0) {\n resolve();\n }\n };\n for (let i = 0; i < promises.length; i++) {\n const promise = mapFn != null ? mapFn(promises[i], i) : promises[i];\n PromisePrototypeThen(PromiseResolve(promise), onFulfilled, reject);\n }\n });\n\n/**\n * @template T,U\n * @param {Array<T|PromiseLike<T>>} promises\n * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]\n * @returns {Promise<PromiseSettledResult<any>[]>}\n */\nprimordials.SafePromiseAllSettled = (promises, mapFn) =>\n // Wrapping on a new Promise is necessary to not expose the SafePromise\n // prototype to user-land.\n new Promise((a, b) =>\n SafePromise.allSettled(arrayToSafePromiseIterable(promises, mapFn)).then(a, b),\n );\n\n/**\n * Should only be used when we only care about waiting for all the promises to\n * settle, not what value they resolve or reject to.\n * @template T,U\n * @param {ArrayLike<T|PromiseLike<T>>} promises\n * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]\n * @returns {Promise<void>}\n */\nprimordials.SafePromiseAllSettledReturnVoid = (promises, mapFn) => new Promise((resolve) => {\n let pendingPromises = promises.length;\n if (pendingPromises === 0) resolve();\n const onSettle = () => {\n if (--pendingPromises === 0) resolve();\n };\n for (let i = 0; i < promises.length; i++) {\n const promise = mapFn != null ? mapFn(promises[i], i) : promises[i];\n PromisePrototypeThen(PromiseResolve(promise), onSettle, onSettle);\n }\n});\n\n/**\n * @template T,U\n * @param {Array<T|PromiseLike<T>>} promises\n * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]\n * @returns {Promise<Awaited<U>>}\n */\nprimordials.SafePromiseAny = (promises, mapFn) =>\n // Wrapping on a new Promise is necessary to not expose the SafePromise\n // prototype to user-land.\n new Promise((a, b) =>\n SafePromise.any(arrayToSafePromiseIterable(promises, mapFn)).then(a, b),\n );\n\n/**\n * @template T,U\n * @param {Array<T|PromiseLike<T>>} promises\n * @param {(v: T|PromiseLike<T>, k: number) => U|PromiseLike<U>} [mapFn]\n * @returns {Promise<Awaited<U>>}\n */\nprimordials.SafePromiseRace = (promises, mapFn) =>\n // Wrapping on a new Promise is necessary to not expose the SafePromise\n // prototype to user-land.\n new Promise((a, b) =>\n SafePromise.race(arrayToSafePromiseIterable(promises, mapFn)).then(a, b),\n );\n\n\nconst {\n exec: OriginalRegExpPrototypeExec,\n [SymbolMatch]: OriginalRegExpPrototypeSymbolMatch,\n [SymbolMatchAll]: OriginalRegExpPrototypeSymbolMatchAll,\n [SymbolReplace]: OriginalRegExpPrototypeSymbolReplace,\n [SymbolSearch]: OriginalRegExpPrototypeSymbolSearch,\n [SymbolSplit]: OriginalRegExpPrototypeSymbolSplit,\n} = RegExpPrototype;\n\nclass RegExpLikeForStringSplitting {\n #regex;\n constructor() {\n this.#regex = ReflectConstruct(RegExp, arguments);\n }\n\n get lastIndex() {\n return ReflectGet(this.#regex, 'lastIndex');\n }\n set lastIndex(value) {\n ReflectSet(this.#regex, 'lastIndex', value);\n }\n\n exec() {\n return ReflectApply(OriginalRegExpPrototypeExec, this.#regex, arguments);\n }\n}\nObjectSetPrototypeOf(RegExpLikeForStringSplitting.prototype, null);\n\n/**\n * @param {RegExp} pattern\n * @returns {RegExp}\n */\nprimordials.hardenRegExp = function hardenRegExp(pattern) {\n ObjectDefineProperties(pattern, {\n [SymbolMatch]: {\n __proto__: null,\n configurable: true,\n value: OriginalRegExpPrototypeSymbolMatch,\n },\n [SymbolMatchAll]: {\n __proto__: null,\n configurable: true,\n value: OriginalRegExpPrototypeSymbolMatchAll,\n },\n [SymbolReplace]: {\n __proto__: null,\n configurable: true,\n value: OriginalRegExpPrototypeSymbolReplace,\n },\n [SymbolSearch]: {\n __proto__: null,\n configurable: true,\n value: OriginalRegExpPrototypeSymbolSearch,\n },\n [SymbolSplit]: {\n __proto__: null,\n configurable: true,\n value: OriginalRegExpPrototypeSymbolSplit,\n },\n constructor: {\n __proto__: null,\n configurable: true,\n value: {\n [SymbolSpecies]: RegExpLikeForStringSplitting,\n },\n },\n dotAll: {\n __proto__: null,\n configurable: true,\n value: RegExpPrototypeGetDotAll(pattern),\n },\n exec: {\n __proto__: null,\n configurable: true,\n value: OriginalRegExpPrototypeExec,\n },\n global: {\n __proto__: null,\n configurable: true,\n value: RegExpPrototypeGetGlobal(pattern),\n },\n hasIndices: {\n __proto__: null,\n configurable: true,\n value: RegExpPrototypeGetHasIndices(pattern),\n },\n ignoreCase: {\n __proto__: null,\n configurable: true,\n value: RegExpPrototypeGetIgnoreCase(pattern),\n },\n multiline: {\n __proto__: null,\n configurable: true,\n value: RegExpPrototypeGetMultiline(pattern),\n },\n source: {\n __proto__: null,\n configurable: true,\n value: RegExpPrototypeGetSource(pattern),\n },\n sticky: {\n __proto__: null,\n configurable: true,\n value: RegExpPrototypeGetSticky(pattern),\n },\n unicode: {\n __proto__: null,\n configurable: true,\n value: RegExpPrototypeGetUnicode(pattern),\n },\n });\n ObjectDefineProperty(pattern, 'flags', {\n __proto__: null,\n configurable: true,\n value: RegExpPrototypeGetFlags(pattern),\n });\n return pattern;\n};\n\n\n/**\n * @param {string} str\n * @param {RegExp} regexp\n * @returns {number}\n */\nprimordials.SafeStringPrototypeSearch = (str, regexp) => {\n regexp.lastIndex = 0;\n const match = RegExpPrototypeExec(regexp, str);\n return match ? match.index : -1;\n};\n\nObjectSetPrototypeOf(primordials, null);\nObjectFreeze(primordials);\n";
|
|
128
100
|
const NAVIGATOR = "'use strict';\n\nconst {\n ObjectDefineProperties,\n ObjectFreeze,\n StringPrototypeIndexOf,\n StringPrototypeSlice,\n StringPrototypeToUpperCase,\n Symbol,\n} = primordials;\n\nconst {\n ERR_ILLEGAL_CONSTRUCTOR,\n} = require('internal/errors').codes;\n\nconst {\n kEnumerableProperty,\n} = require('internal/util');\n\nconst {\n getAvailableParallelism,\n} = internalBinding('os');\n\nconst kInitialize = Symbol('kInitialize');\n\nconst {\n platform,\n arch,\n version: nodeVersion,\n} = require('internal/process/per_thread');\n\nconst {\n getDefaultLocale,\n} = internalBinding('config');\n\n/**\n * @param {string} arch\n * @param {string} platform\n * @returns {string}\n */\nfunction getNavigatorPlatform(arch, platform) {\n if (platform === 'darwin') {\n // On macOS, modern browsers return 'MacIntel' even if running on Apple Silicon.\n return 'MacIntel';\n } else if (platform === 'win32') {\n // On Windows, modern browsers return 'Win32' even if running on a 64-bit version of Windows.\n // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform#usage_notes\n return 'Win32';\n } else if (platform === 'linux') {\n if (arch === 'ia32') {\n return 'Linux i686';\n } else if (arch === 'x64') {\n return 'Linux x86_64';\n }\n return `Linux ${arch}`;\n } else if (platform === 'freebsd') {\n if (arch === 'ia32') {\n return 'FreeBSD i386';\n } else if (arch === 'x64') {\n return 'FreeBSD amd64';\n }\n return `FreeBSD ${arch}`;\n } else if (platform === 'openbsd') {\n if (arch === 'ia32') {\n return 'OpenBSD i386';\n } else if (arch === 'x64') {\n return 'OpenBSD amd64';\n }\n return `OpenBSD ${arch}`;\n } else if (platform === 'sunos') {\n if (arch === 'ia32') {\n return 'SunOS i86pc';\n }\n return `SunOS ${arch}`;\n } else if (platform === 'aix') {\n return 'AIX';\n }\n return `${StringPrototypeToUpperCase(platform[0])}${StringPrototypeSlice(platform, 1)} ${arch}`;\n}\n\nclass Navigator {\n // Private properties are used to avoid brand validations.\n #availableParallelism;\n #userAgent;\n #platform;\n #languages;\n\n constructor() {\n if (arguments[0] === kInitialize) {\n return;\n }\n throw new ERR_ILLEGAL_CONSTRUCTOR();\n }\n\n /**\n * @return {number}\n */\n get hardwareConcurrency() {\n this.#availableParallelism ??= getAvailableParallelism();\n return this.#availableParallelism;\n }\n\n /**\n * @return {string}\n */\n get language() {\n // The default locale might be changed dynamically, so always invoke the\n // binding.\n return getDefaultLocale() || 'en-US';\n }\n\n /**\n * @return {Array<string>}\n */\n get languages() {\n this.#languages ??= ObjectFreeze([this.language]);\n return this.#languages;\n }\n\n /**\n * @return {string}\n */\n get userAgent() {\n this.#userAgent ??= `Node.js/${StringPrototypeSlice(nodeVersion, 1, StringPrototypeIndexOf(nodeVersion, '.'))}`;\n return this.#userAgent;\n }\n\n /**\n * @return {string}\n */\n get platform() {\n this.#platform ??= getNavigatorPlatform(arch, platform);\n return this.#platform;\n }\n}\n\nObjectDefineProperties(Navigator.prototype, {\n hardwareConcurrency: kEnumerableProperty,\n language: kEnumerableProperty,\n languages: kEnumerableProperty,\n userAgent: kEnumerableProperty,\n platform: kEnumerableProperty,\n});\n\nmodule.exports = {\n getNavigatorPlatform,\n navigator: new Navigator(kInitialize),\n Navigator,\n};\n";
|
|
129
101
|
const NODE_PATH_SOURCE = "// VENDORED, UNMODIFIED: Node.js lib/path.js\n//\n// version: v22.18.0\n// commit: d1b18258ce0d85253e4e44cede152e31363ef5db\n// source: https://raw.githubusercontent.com/nodejs/node/v22.18.0/lib/path.js\n// sha256: 3448e7d5a3a27f4ddc34e3d5278f39f1a0c560fd4cbbf55d07803113b720cda1\n//\n// Everything below this header is Node's own text, byte for byte; the sha256\n// above is of that text alone, so the vendoring is checkable with\n// tail -n +17 src/node-lib/path.js | shasum -a 256\n// Nothing here is edited. The free names the file expects of the Node runtime\n// -- `primordials`, `require` of `internal/constants`, `internal/validators`,\n// `internal/util` and `internal/deps/minimatch/index`, `module` and `process`\n// -- are supplied by the binding in src/shims/path.ts, which evaluates this\n// text. To move to a newer Node, replace this file and the header, and run\n// Node's own test/parallel/test-path-*.js against the build.\n// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\nconst {\n ArrayPrototypeIncludes,\n ArrayPrototypeJoin,\n ArrayPrototypeSlice,\n FunctionPrototypeBind,\n StringPrototypeCharCodeAt,\n StringPrototypeIncludes,\n StringPrototypeIndexOf,\n StringPrototypeLastIndexOf,\n StringPrototypeRepeat,\n StringPrototypeReplace,\n StringPrototypeSlice,\n StringPrototypeSplit,\n StringPrototypeToLowerCase,\n StringPrototypeToUpperCase,\n} = primordials;\n\nconst {\n CHAR_UPPERCASE_A,\n CHAR_LOWERCASE_A,\n CHAR_UPPERCASE_Z,\n CHAR_LOWERCASE_Z,\n CHAR_DOT,\n CHAR_FORWARD_SLASH,\n CHAR_BACKWARD_SLASH,\n CHAR_COLON,\n CHAR_QUESTION_MARK,\n} = require('internal/constants');\nconst {\n validateObject,\n validateString,\n} = require('internal/validators');\n\nconst {\n getLazy,\n isWindows,\n isMacOS,\n} = require('internal/util');\n\nconst lazyMinimatch = getLazy(() => require('internal/deps/minimatch/index'));\n\nfunction isPathSeparator(code) {\n return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;\n}\n\nfunction isPosixPathSeparator(code) {\n return code === CHAR_FORWARD_SLASH;\n}\n\nconst WINDOWS_RESERVED_NAMES = [\n 'CON', 'PRN', 'AUX', 'NUL',\n 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9',\n 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9',\n];\n\nfunction isWindowsReservedName(path, colonIndex) {\n const devicePart = StringPrototypeToUpperCase(StringPrototypeSlice(path, 0, colonIndex));\n return ArrayPrototypeIncludes(WINDOWS_RESERVED_NAMES, devicePart);\n}\n\nfunction isWindowsDeviceRoot(code) {\n return (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||\n (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z);\n}\n\n// Resolves . and .. elements in a path with directory names\nfunction normalizeString(path, allowAboveRoot, separator, isPathSeparator) {\n let res = '';\n let lastSegmentLength = 0;\n let lastSlash = -1;\n let dots = 0;\n let code = 0;\n for (let i = 0; i <= path.length; ++i) {\n if (i < path.length)\n code = StringPrototypeCharCodeAt(path, i);\n else if (isPathSeparator(code))\n break;\n else\n code = CHAR_FORWARD_SLASH;\n\n if (isPathSeparator(code)) {\n if (lastSlash === i - 1 || dots === 1) {\n // NOOP\n } else if (dots === 2) {\n if (res.length < 2 || lastSegmentLength !== 2 ||\n StringPrototypeCharCodeAt(res, res.length - 1) !== CHAR_DOT ||\n StringPrototypeCharCodeAt(res, res.length - 2) !== CHAR_DOT) {\n if (res.length > 2) {\n const lastSlashIndex = res.length - lastSegmentLength - 1;\n if (lastSlashIndex === -1) {\n res = '';\n lastSegmentLength = 0;\n } else {\n res = StringPrototypeSlice(res, 0, lastSlashIndex);\n lastSegmentLength =\n res.length - 1 - StringPrototypeLastIndexOf(res, separator);\n }\n lastSlash = i;\n dots = 0;\n continue;\n } else if (res.length !== 0) {\n res = '';\n lastSegmentLength = 0;\n lastSlash = i;\n dots = 0;\n continue;\n }\n }\n if (allowAboveRoot) {\n res += res.length > 0 ? `${separator}..` : '..';\n lastSegmentLength = 2;\n }\n } else {\n if (res.length > 0)\n res += `${separator}${StringPrototypeSlice(path, lastSlash + 1, i)}`;\n else\n res = StringPrototypeSlice(path, lastSlash + 1, i);\n lastSegmentLength = i - lastSlash - 1;\n }\n lastSlash = i;\n dots = 0;\n } else if (code === CHAR_DOT && dots !== -1) {\n ++dots;\n } else {\n dots = -1;\n }\n }\n return res;\n}\n\nfunction formatExt(ext) {\n return ext ? `${ext[0] === '.' ? '' : '.'}${ext}` : '';\n}\n\n/**\n * @param {string} sep\n * @param {{\n * dir?: string;\n * root?: string;\n * base?: string;\n * name?: string;\n * ext?: string;\n * }} pathObject\n * @returns {string}\n */\nfunction _format(sep, pathObject) {\n validateObject(pathObject, 'pathObject');\n const dir = pathObject.dir || pathObject.root;\n const base = pathObject.base ||\n `${pathObject.name || ''}${formatExt(pathObject.ext)}`;\n if (!dir) {\n return base;\n }\n return dir === pathObject.root ? `${dir}${base}` : `${dir}${sep}${base}`;\n}\n\nfunction glob(path, pattern, windows) {\n validateString(path, 'path');\n validateString(pattern, 'pattern');\n return lazyMinimatch().minimatch(path, pattern, {\n __proto__: null,\n nocase: isMacOS || isWindows,\n windowsPathsNoEscape: true,\n nonegate: true,\n nocomment: true,\n optimizationLevel: 2,\n platform: windows ? 'win32' : 'posix',\n nocaseMagicOnly: true,\n });\n}\nconst forwardSlashRegExp = /\\//g;\n\nconst win32 = {\n /**\n * path.resolve([from ...], to)\n * @param {...string} args\n * @returns {string}\n */\n resolve(...args) {\n let resolvedDevice = '';\n let resolvedTail = '';\n let resolvedAbsolute = false;\n\n for (let i = args.length - 1; i >= -1; i--) {\n let path;\n if (i >= 0) {\n path = args[i];\n validateString(path, `paths[${i}]`);\n\n // Skip empty entries\n if (path.length === 0) {\n continue;\n }\n } else if (resolvedDevice.length === 0) {\n path = process.cwd();\n // Fast path for current directory\n if (args.length === 0 || ((args.length === 1 && (args[0] === '' || args[0] === '.')) &&\n isPathSeparator(StringPrototypeCharCodeAt(path, 0)))) {\n if (!isWindows) {\n path = StringPrototypeReplace(path, forwardSlashRegExp, '\\\\');\n }\n return path;\n }\n } else {\n // Windows has the concept of drive-specific current working\n // directories. If we've resolved a drive letter but not yet an\n // absolute path, get cwd for that drive, or the process cwd if\n // the drive cwd is not available. We're sure the device is not\n // a UNC path at this points, because UNC paths are always absolute.\n path = process.env[`=${resolvedDevice}`] || process.cwd();\n\n // Verify that a cwd was found and that it actually points\n // to our drive. If not, default to the drive's root.\n if (path === undefined ||\n (StringPrototypeToLowerCase(StringPrototypeSlice(path, 0, 2)) !==\n StringPrototypeToLowerCase(resolvedDevice) &&\n StringPrototypeCharCodeAt(path, 2) === CHAR_BACKWARD_SLASH)) {\n path = `${resolvedDevice}\\\\`;\n }\n }\n\n const len = path.length;\n let rootEnd = 0;\n let device = '';\n let isAbsolute = false;\n const code = StringPrototypeCharCodeAt(path, 0);\n\n // Try to match a root\n if (len === 1) {\n if (isPathSeparator(code)) {\n // `path` contains just a path separator\n rootEnd = 1;\n isAbsolute = true;\n }\n } else if (isPathSeparator(code)) {\n // Possible UNC root\n\n // If we started with a separator, we know we at least have an\n // absolute path of some kind (UNC or otherwise)\n isAbsolute = true;\n\n if (isPathSeparator(StringPrototypeCharCodeAt(path, 1))) {\n // Matched double path separator at beginning\n let j = 2;\n let last = j;\n // Match 1 or more non-path separators\n while (j < len &&\n !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {\n j++;\n }\n if (j < len && j !== last) {\n const firstPart = StringPrototypeSlice(path, last, j);\n // Matched!\n last = j;\n // Match 1 or more path separators\n while (j < len &&\n isPathSeparator(StringPrototypeCharCodeAt(path, j))) {\n j++;\n }\n if (j < len && j !== last) {\n // Matched!\n last = j;\n // Match 1 or more non-path separators\n while (j < len &&\n !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {\n j++;\n }\n if (j === len || j !== last) {\n // We matched a UNC root\n device =\n `\\\\\\\\${firstPart}\\\\${StringPrototypeSlice(path, last, j)}`;\n rootEnd = j;\n }\n }\n }\n } else {\n rootEnd = 1;\n }\n } else if (isWindowsDeviceRoot(code) &&\n StringPrototypeCharCodeAt(path, 1) === CHAR_COLON) {\n // Possible device root\n device = StringPrototypeSlice(path, 0, 2);\n rootEnd = 2;\n if (len > 2 && isPathSeparator(StringPrototypeCharCodeAt(path, 2))) {\n // Treat separator following drive name as an absolute path\n // indicator\n isAbsolute = true;\n rootEnd = 3;\n }\n }\n\n if (device.length > 0) {\n if (resolvedDevice.length > 0) {\n if (StringPrototypeToLowerCase(device) !==\n StringPrototypeToLowerCase(resolvedDevice))\n // This path points to another device so it is not applicable\n continue;\n } else {\n resolvedDevice = device;\n }\n }\n\n if (resolvedAbsolute) {\n if (resolvedDevice.length > 0)\n break;\n } else {\n resolvedTail =\n `${StringPrototypeSlice(path, rootEnd)}\\\\${resolvedTail}`;\n resolvedAbsolute = isAbsolute;\n if (isAbsolute && resolvedDevice.length > 0) {\n break;\n }\n }\n }\n\n // At this point the path should be resolved to a full absolute path,\n // but handle relative paths to be safe (might happen when process.cwd()\n // fails)\n\n // Normalize the tail path\n resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\\\',\n isPathSeparator);\n\n return resolvedAbsolute ?\n `${resolvedDevice}\\\\${resolvedTail}` :\n `${resolvedDevice}${resolvedTail}` || '.';\n },\n\n /**\n * @param {string} path\n * @returns {string}\n */\n normalize(path) {\n validateString(path, 'path');\n const len = path.length;\n if (len === 0)\n return '.';\n let rootEnd = 0;\n let device;\n let isAbsolute = false;\n const code = StringPrototypeCharCodeAt(path, 0);\n\n // Try to match a root\n if (len === 1) {\n // `path` contains just a single char, exit early to avoid\n // unnecessary work\n return isPosixPathSeparator(code) ? '\\\\' : path;\n }\n if (isPathSeparator(code)) {\n // Possible UNC root\n\n // If we started with a separator, we know we at least have an absolute\n // path of some kind (UNC or otherwise)\n isAbsolute = true;\n\n if (isPathSeparator(StringPrototypeCharCodeAt(path, 1))) {\n // Matched double path separator at beginning\n let j = 2;\n let last = j;\n // Match 1 or more non-path separators\n while (j < len &&\n !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {\n j++;\n }\n if (j < len && j !== last) {\n const firstPart = StringPrototypeSlice(path, last, j);\n // Matched!\n last = j;\n // Match 1 or more path separators\n while (j < len &&\n isPathSeparator(StringPrototypeCharCodeAt(path, j))) {\n j++;\n }\n if (j < len && j !== last) {\n // Matched!\n last = j;\n // Match 1 or more non-path separators\n while (j < len &&\n !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {\n j++;\n }\n if (j === len) {\n // We matched a UNC root only\n // Return the normalized version of the UNC root since there\n // is nothing left to process\n return `\\\\\\\\${firstPart}\\\\${StringPrototypeSlice(path, last)}\\\\`;\n }\n if (j !== last) {\n // We matched a UNC root with leftovers\n device =\n `\\\\\\\\${firstPart}\\\\${StringPrototypeSlice(path, last, j)}`;\n rootEnd = j;\n }\n }\n }\n } else {\n rootEnd = 1;\n }\n } else {\n const colonIndex = StringPrototypeIndexOf(path, ':');\n if (colonIndex > 0) {\n if (isWindowsDeviceRoot(code) && colonIndex === 1) {\n device = StringPrototypeSlice(path, 0, 2);\n rootEnd = 2;\n if (len > 2 && isPathSeparator(StringPrototypeCharCodeAt(path, 2))) {\n isAbsolute = true;\n rootEnd = 3;\n }\n } else if (isWindowsReservedName(path, colonIndex)) {\n device = StringPrototypeSlice(path, 0, colonIndex + 1);\n rootEnd = colonIndex + 1;\n\n }\n }\n }\n\n let tail = rootEnd < len ?\n normalizeString(StringPrototypeSlice(path, rootEnd),\n !isAbsolute, '\\\\', isPathSeparator) :\n '';\n if (tail.length === 0 && !isAbsolute)\n tail = '.';\n if (tail.length > 0 &&\n isPathSeparator(StringPrototypeCharCodeAt(path, len - 1)))\n tail += '\\\\';\n if (!isAbsolute && device === undefined && StringPrototypeIncludes(path, ':')) {\n // If the original path was not absolute and if we have not been able to\n // resolve it relative to a particular device, we need to ensure that the\n // `tail` has not become something that Windows might interpret as an\n // absolute path. See CVE-2024-36139.\n if (tail.length >= 2 &&\n isWindowsDeviceRoot(StringPrototypeCharCodeAt(tail, 0)) &&\n StringPrototypeCharCodeAt(tail, 1) === CHAR_COLON) {\n return `.\\\\${tail}`;\n }\n let index = StringPrototypeIndexOf(path, ':');\n\n do {\n if (index === len - 1 || isPathSeparator(StringPrototypeCharCodeAt(path, index + 1))) {\n return `.\\\\${tail}`;\n }\n } while ((index = StringPrototypeIndexOf(path, ':', index + 1)) !== -1);\n }\n const colonIndex = StringPrototypeIndexOf(path, ':');\n if (isWindowsReservedName(path, colonIndex)) {\n return `.\\\\${device ?? ''}${tail}`;\n }\n if (device === undefined) {\n return isAbsolute ? `\\\\${tail}` : tail;\n }\n return isAbsolute ? `${device}\\\\${tail}` : `${device}${tail}`;\n },\n\n /**\n * @param {string} path\n * @returns {boolean}\n */\n isAbsolute(path) {\n validateString(path, 'path');\n const len = path.length;\n if (len === 0)\n return false;\n\n const code = StringPrototypeCharCodeAt(path, 0);\n return isPathSeparator(code) ||\n // Possible device root\n (len > 2 &&\n isWindowsDeviceRoot(code) &&\n StringPrototypeCharCodeAt(path, 1) === CHAR_COLON &&\n isPathSeparator(StringPrototypeCharCodeAt(path, 2)));\n },\n\n /**\n * @param {...string} args\n * @returns {string}\n */\n join(...args) {\n if (args.length === 0)\n return '.';\n\n let joined;\n let firstPart;\n for (let i = 0; i < args.length; ++i) {\n const arg = args[i];\n validateString(arg, 'path');\n if (arg.length > 0) {\n if (joined === undefined)\n joined = firstPart = arg;\n else\n joined += `\\\\${arg}`;\n }\n }\n\n if (joined === undefined)\n return '.';\n\n // Make sure that the joined path doesn't start with two slashes, because\n // normalize() will mistake it for a UNC path then.\n //\n // This step is skipped when it is very clear that the user actually\n // intended to point at a UNC path. This is assumed when the first\n // non-empty string arguments starts with exactly two slashes followed by\n // at least one more non-slash character.\n //\n // Note that for normalize() to treat a path as a UNC path it needs to\n // have at least 2 components, so we don't filter for that here.\n // This means that the user can use join to construct UNC paths from\n // a server name and a share name; for example:\n // path.join('//server', 'share') -> '\\\\\\\\server\\\\share\\\\')\n let needsReplace = true;\n let slashCount = 0;\n if (isPathSeparator(StringPrototypeCharCodeAt(firstPart, 0))) {\n ++slashCount;\n const firstLen = firstPart.length;\n if (firstLen > 1 &&\n isPathSeparator(StringPrototypeCharCodeAt(firstPart, 1))) {\n ++slashCount;\n if (firstLen > 2) {\n if (isPathSeparator(StringPrototypeCharCodeAt(firstPart, 2)))\n ++slashCount;\n else {\n // We matched a UNC path in the first part\n needsReplace = false;\n }\n }\n }\n }\n if (needsReplace) {\n // Find any more consecutive slashes we need to replace\n while (slashCount < joined.length &&\n isPathSeparator(StringPrototypeCharCodeAt(joined, slashCount))) {\n slashCount++;\n }\n\n // Replace the slashes if needed\n if (slashCount >= 2)\n joined = `\\\\${StringPrototypeSlice(joined, slashCount)}`;\n }\n\n return win32.normalize(joined);\n },\n\n /**\n * It will solve the relative path from `from` to `to`, for instance\n * from = 'C:\\\\orandea\\\\test\\\\aaa'\n * to = 'C:\\\\orandea\\\\impl\\\\bbb'\n * The output of the function should be: '..\\\\..\\\\impl\\\\bbb'\n * @param {string} from\n * @param {string} to\n * @returns {string}\n */\n relative(from, to) {\n validateString(from, 'from');\n validateString(to, 'to');\n\n if (from === to)\n return '';\n\n const fromOrig = win32.resolve(from);\n const toOrig = win32.resolve(to);\n\n if (fromOrig === toOrig)\n return '';\n\n from = StringPrototypeToLowerCase(fromOrig);\n to = StringPrototypeToLowerCase(toOrig);\n\n if (from === to)\n return '';\n\n if (fromOrig.length !== from.length || toOrig.length !== to.length) {\n const fromSplit = StringPrototypeSplit(fromOrig, '\\\\');\n const toSplit = StringPrototypeSplit(toOrig, '\\\\');\n if (fromSplit[fromSplit.length - 1] === '') {\n fromSplit.pop();\n }\n if (toSplit[toSplit.length - 1] === '') {\n toSplit.pop();\n }\n\n const fromLen = fromSplit.length;\n const toLen = toSplit.length;\n const length = fromLen < toLen ? fromLen : toLen;\n\n let i;\n for (i = 0; i < length; i++) {\n if (StringPrototypeToLowerCase(fromSplit[i]) !== StringPrototypeToLowerCase(toSplit[i])) {\n break;\n }\n }\n\n if (i === 0) {\n return toOrig;\n } else if (i === length) {\n if (toLen > length) {\n return ArrayPrototypeJoin(ArrayPrototypeSlice(toSplit, i), '\\\\');\n }\n if (fromLen > length) {\n return StringPrototypeRepeat('..\\\\', fromLen - 1 - i) + '..';\n }\n return '';\n }\n\n return StringPrototypeRepeat('..\\\\', fromLen - i) + ArrayPrototypeJoin(ArrayPrototypeSlice(toSplit, i), '\\\\');\n }\n\n // Trim any leading backslashes\n let fromStart = 0;\n while (fromStart < from.length &&\n StringPrototypeCharCodeAt(from, fromStart) === CHAR_BACKWARD_SLASH) {\n fromStart++;\n }\n // Trim trailing backslashes (applicable to UNC paths only)\n let fromEnd = from.length;\n while (\n fromEnd - 1 > fromStart &&\n StringPrototypeCharCodeAt(from, fromEnd - 1) === CHAR_BACKWARD_SLASH\n ) {\n fromEnd--;\n }\n const fromLen = fromEnd - fromStart;\n\n // Trim any leading backslashes\n let toStart = 0;\n while (toStart < to.length &&\n StringPrototypeCharCodeAt(to, toStart) === CHAR_BACKWARD_SLASH) {\n toStart++;\n }\n // Trim trailing backslashes (applicable to UNC paths only)\n let toEnd = to.length;\n while (toEnd - 1 > toStart &&\n StringPrototypeCharCodeAt(to, toEnd - 1) === CHAR_BACKWARD_SLASH) {\n toEnd--;\n }\n const toLen = toEnd - toStart;\n\n // Compare paths to find the longest common path from root\n const length = fromLen < toLen ? fromLen : toLen;\n let lastCommonSep = -1;\n let i = 0;\n for (; i < length; i++) {\n const fromCode = StringPrototypeCharCodeAt(from, fromStart + i);\n if (fromCode !== StringPrototypeCharCodeAt(to, toStart + i))\n break;\n else if (fromCode === CHAR_BACKWARD_SLASH)\n lastCommonSep = i;\n }\n\n // We found a mismatch before the first common path separator was seen, so\n // return the original `to`.\n if (i !== length) {\n if (lastCommonSep === -1)\n return toOrig;\n } else {\n if (toLen > length) {\n if (StringPrototypeCharCodeAt(to, toStart + i) ===\n CHAR_BACKWARD_SLASH) {\n // We get here if `from` is the exact base path for `to`.\n // For example: from='C:\\\\foo\\\\bar'; to='C:\\\\foo\\\\bar\\\\baz'\n return StringPrototypeSlice(toOrig, toStart + i + 1);\n }\n if (i === 2) {\n // We get here if `from` is the device root.\n // For example: from='C:\\\\'; to='C:\\\\foo'\n return StringPrototypeSlice(toOrig, toStart + i);\n }\n }\n if (fromLen > length) {\n if (StringPrototypeCharCodeAt(from, fromStart + i) ===\n CHAR_BACKWARD_SLASH) {\n // We get here if `to` is the exact base path for `from`.\n // For example: from='C:\\\\foo\\\\bar'; to='C:\\\\foo'\n lastCommonSep = i;\n } else if (i === 2) {\n // We get here if `to` is the device root.\n // For example: from='C:\\\\foo\\\\bar'; to='C:\\\\'\n lastCommonSep = 3;\n }\n }\n if (lastCommonSep === -1)\n lastCommonSep = 0;\n }\n\n let out = '';\n // Generate the relative path based on the path difference between `to` and\n // `from`\n for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {\n if (i === fromEnd ||\n StringPrototypeCharCodeAt(from, i) === CHAR_BACKWARD_SLASH) {\n out += out.length === 0 ? '..' : '\\\\..';\n }\n }\n\n toStart += lastCommonSep;\n\n // Lastly, append the rest of the destination (`to`) path that comes after\n // the common path parts\n if (out.length > 0)\n return `${out}${StringPrototypeSlice(toOrig, toStart, toEnd)}`;\n\n if (StringPrototypeCharCodeAt(toOrig, toStart) === CHAR_BACKWARD_SLASH)\n ++toStart;\n return StringPrototypeSlice(toOrig, toStart, toEnd);\n },\n\n /**\n * @param {string} path\n * @returns {string}\n */\n toNamespacedPath(path) {\n // Note: this will *probably* throw somewhere.\n if (typeof path !== 'string' || path.length === 0)\n return path;\n\n const resolvedPath = win32.resolve(path);\n\n if (resolvedPath.length <= 2)\n return path;\n\n if (StringPrototypeCharCodeAt(resolvedPath, 0) === CHAR_BACKWARD_SLASH) {\n // Possible UNC root\n if (StringPrototypeCharCodeAt(resolvedPath, 1) === CHAR_BACKWARD_SLASH) {\n const code = StringPrototypeCharCodeAt(resolvedPath, 2);\n if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {\n // Matched non-long UNC root, convert the path to a long UNC path\n return `\\\\\\\\?\\\\UNC\\\\${StringPrototypeSlice(resolvedPath, 2)}`;\n }\n }\n } else if (\n isWindowsDeviceRoot(StringPrototypeCharCodeAt(resolvedPath, 0)) &&\n StringPrototypeCharCodeAt(resolvedPath, 1) === CHAR_COLON &&\n StringPrototypeCharCodeAt(resolvedPath, 2) === CHAR_BACKWARD_SLASH\n ) {\n // Matched device root, convert the path to a long UNC path\n return `\\\\\\\\?\\\\${resolvedPath}`;\n }\n\n return resolvedPath;\n },\n\n /**\n * @param {string} path\n * @returns {string}\n */\n dirname(path) {\n validateString(path, 'path');\n const len = path.length;\n if (len === 0)\n return '.';\n let rootEnd = -1;\n let offset = 0;\n const code = StringPrototypeCharCodeAt(path, 0);\n\n if (len === 1) {\n // `path` contains just a path separator, exit early to avoid\n // unnecessary work or a dot.\n return isPathSeparator(code) ? path : '.';\n }\n\n // Try to match a root\n if (isPathSeparator(code)) {\n // Possible UNC root\n\n rootEnd = offset = 1;\n\n if (isPathSeparator(StringPrototypeCharCodeAt(path, 1))) {\n // Matched double path separator at beginning\n let j = 2;\n let last = j;\n // Match 1 or more non-path separators\n while (j < len &&\n !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {\n j++;\n }\n if (j < len && j !== last) {\n // Matched!\n last = j;\n // Match 1 or more path separators\n while (j < len &&\n isPathSeparator(StringPrototypeCharCodeAt(path, j))) {\n j++;\n }\n if (j < len && j !== last) {\n // Matched!\n last = j;\n // Match 1 or more non-path separators\n while (j < len &&\n !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {\n j++;\n }\n if (j === len) {\n // We matched a UNC root only\n return path;\n }\n if (j !== last) {\n // We matched a UNC root with leftovers\n\n // Offset by 1 to include the separator after the UNC root to\n // treat it as a \"normal root\" on top of a (UNC) root\n rootEnd = offset = j + 1;\n }\n }\n }\n }\n // Possible device root\n } else if (isWindowsDeviceRoot(code) &&\n StringPrototypeCharCodeAt(path, 1) === CHAR_COLON) {\n rootEnd =\n len > 2 && isPathSeparator(StringPrototypeCharCodeAt(path, 2)) ? 3 : 2;\n offset = rootEnd;\n }\n\n let end = -1;\n let matchedSlash = true;\n for (let i = len - 1; i >= offset; --i) {\n if (isPathSeparator(StringPrototypeCharCodeAt(path, i))) {\n if (!matchedSlash) {\n end = i;\n break;\n }\n } else {\n // We saw the first non-path separator\n matchedSlash = false;\n }\n }\n\n if (end === -1) {\n if (rootEnd === -1)\n return '.';\n\n end = rootEnd;\n }\n return StringPrototypeSlice(path, 0, end);\n },\n\n /**\n * @param {string} path\n * @param {string} [suffix]\n * @returns {string}\n */\n basename(path, suffix) {\n if (suffix !== undefined)\n validateString(suffix, 'suffix');\n validateString(path, 'path');\n let start = 0;\n let end = -1;\n let matchedSlash = true;\n\n // Check for a drive letter prefix so as not to mistake the following\n // path separator as an extra separator at the end of the path that can be\n // disregarded\n if (path.length >= 2 &&\n isWindowsDeviceRoot(StringPrototypeCharCodeAt(path, 0)) &&\n StringPrototypeCharCodeAt(path, 1) === CHAR_COLON) {\n start = 2;\n }\n\n if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {\n if (suffix === path)\n return '';\n let extIdx = suffix.length - 1;\n let firstNonSlashEnd = -1;\n for (let i = path.length - 1; i >= start; --i) {\n const code = StringPrototypeCharCodeAt(path, i);\n if (isPathSeparator(code)) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n start = i + 1;\n break;\n }\n } else {\n if (firstNonSlashEnd === -1) {\n // We saw the first non-path separator, remember this index in case\n // we need it if the extension ends up not matching\n matchedSlash = false;\n firstNonSlashEnd = i + 1;\n }\n if (extIdx >= 0) {\n // Try to match the explicit extension\n if (code === StringPrototypeCharCodeAt(suffix, extIdx)) {\n if (--extIdx === -1) {\n // We matched the extension, so mark this as the end of our path\n // component\n end = i;\n }\n } else {\n // Extension does not match, so our result is the entire path\n // component\n extIdx = -1;\n end = firstNonSlashEnd;\n }\n }\n }\n }\n\n if (start === end)\n end = firstNonSlashEnd;\n else if (end === -1)\n end = path.length;\n return StringPrototypeSlice(path, start, end);\n }\n for (let i = path.length - 1; i >= start; --i) {\n if (isPathSeparator(StringPrototypeCharCodeAt(path, i))) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n start = i + 1;\n break;\n }\n } else if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // path component\n matchedSlash = false;\n end = i + 1;\n }\n }\n\n if (end === -1)\n return '';\n return StringPrototypeSlice(path, start, end);\n },\n\n /**\n * @param {string} path\n * @returns {string}\n */\n extname(path) {\n validateString(path, 'path');\n let start = 0;\n let startDot = -1;\n let startPart = 0;\n let end = -1;\n let matchedSlash = true;\n // Track the state of characters (if any) we see before our first dot and\n // after any path separator we find\n let preDotState = 0;\n\n // Check for a drive letter prefix so as not to mistake the following\n // path separator as an extra separator at the end of the path that can be\n // disregarded\n\n if (path.length >= 2 &&\n StringPrototypeCharCodeAt(path, 1) === CHAR_COLON &&\n isWindowsDeviceRoot(StringPrototypeCharCodeAt(path, 0))) {\n start = startPart = 2;\n }\n\n for (let i = path.length - 1; i >= start; --i) {\n const code = StringPrototypeCharCodeAt(path, i);\n if (isPathSeparator(code)) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n startPart = i + 1;\n break;\n }\n continue;\n }\n if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // extension\n matchedSlash = false;\n end = i + 1;\n }\n if (code === CHAR_DOT) {\n // If this is our first dot, mark it as the start of our extension\n if (startDot === -1)\n startDot = i;\n else if (preDotState !== 1)\n preDotState = 1;\n } else if (startDot !== -1) {\n // We saw a non-dot and non-path separator before our dot, so we should\n // have a good chance at having a non-empty extension\n preDotState = -1;\n }\n }\n\n if (startDot === -1 ||\n end === -1 ||\n // We saw a non-dot character immediately before the dot\n preDotState === 0 ||\n // The (right-most) trimmed path component is exactly '..'\n (preDotState === 1 &&\n startDot === end - 1 &&\n startDot === startPart + 1)) {\n return '';\n }\n return StringPrototypeSlice(path, startDot, end);\n },\n\n format: FunctionPrototypeBind(_format, null, '\\\\'),\n\n /**\n * @param {string} path\n * @returns {{\n * dir: string;\n * root: string;\n * base: string;\n * name: string;\n * ext: string;\n * }}\n */\n parse(path) {\n validateString(path, 'path');\n\n const ret = { root: '', dir: '', base: '', ext: '', name: '' };\n if (path.length === 0)\n return ret;\n\n const len = path.length;\n let rootEnd = 0;\n let code = StringPrototypeCharCodeAt(path, 0);\n\n if (len === 1) {\n if (isPathSeparator(code)) {\n // `path` contains just a path separator, exit early to avoid\n // unnecessary work\n ret.root = ret.dir = path;\n return ret;\n }\n ret.base = ret.name = path;\n return ret;\n }\n // Try to match a root\n if (isPathSeparator(code)) {\n // Possible UNC root\n\n rootEnd = 1;\n if (isPathSeparator(StringPrototypeCharCodeAt(path, 1))) {\n // Matched double path separator at beginning\n let j = 2;\n let last = j;\n // Match 1 or more non-path separators\n while (j < len &&\n !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {\n j++;\n }\n if (j < len && j !== last) {\n // Matched!\n last = j;\n // Match 1 or more path separators\n while (j < len &&\n isPathSeparator(StringPrototypeCharCodeAt(path, j))) {\n j++;\n }\n if (j < len && j !== last) {\n // Matched!\n last = j;\n // Match 1 or more non-path separators\n while (j < len &&\n !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {\n j++;\n }\n if (j === len) {\n // We matched a UNC root only\n rootEnd = j;\n } else if (j !== last) {\n // We matched a UNC root with leftovers\n rootEnd = j + 1;\n }\n }\n }\n }\n } else if (isWindowsDeviceRoot(code) &&\n StringPrototypeCharCodeAt(path, 1) === CHAR_COLON) {\n // Possible device root\n if (len <= 2) {\n // `path` contains just a drive root, exit early to avoid\n // unnecessary work\n ret.root = ret.dir = path;\n return ret;\n }\n rootEnd = 2;\n if (isPathSeparator(StringPrototypeCharCodeAt(path, 2))) {\n if (len === 3) {\n // `path` contains just a drive root, exit early to avoid\n // unnecessary work\n ret.root = ret.dir = path;\n return ret;\n }\n rootEnd = 3;\n }\n }\n if (rootEnd > 0)\n ret.root = StringPrototypeSlice(path, 0, rootEnd);\n\n let startDot = -1;\n let startPart = rootEnd;\n let end = -1;\n let matchedSlash = true;\n let i = path.length - 1;\n\n // Track the state of characters (if any) we see before our first dot and\n // after any path separator we find\n let preDotState = 0;\n\n // Get non-dir info\n for (; i >= rootEnd; --i) {\n code = StringPrototypeCharCodeAt(path, i);\n if (isPathSeparator(code)) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n startPart = i + 1;\n break;\n }\n continue;\n }\n if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // extension\n matchedSlash = false;\n end = i + 1;\n }\n if (code === CHAR_DOT) {\n // If this is our first dot, mark it as the start of our extension\n if (startDot === -1)\n startDot = i;\n else if (preDotState !== 1)\n preDotState = 1;\n } else if (startDot !== -1) {\n // We saw a non-dot and non-path separator before our dot, so we should\n // have a good chance at having a non-empty extension\n preDotState = -1;\n }\n }\n\n if (end !== -1) {\n if (startDot === -1 ||\n // We saw a non-dot character immediately before the dot\n preDotState === 0 ||\n // The (right-most) trimmed path component is exactly '..'\n (preDotState === 1 &&\n startDot === end - 1 &&\n startDot === startPart + 1)) {\n ret.base = ret.name = StringPrototypeSlice(path, startPart, end);\n } else {\n ret.name = StringPrototypeSlice(path, startPart, startDot);\n ret.base = StringPrototypeSlice(path, startPart, end);\n ret.ext = StringPrototypeSlice(path, startDot, end);\n }\n }\n\n // If the directory is the root, use the entire root as the `dir` including\n // the trailing slash if any (`C:\\abc` -> `C:\\`). Otherwise, strip out the\n // trailing slash (`C:\\abc\\def` -> `C:\\abc`).\n if (startPart > 0 && startPart !== rootEnd)\n ret.dir = StringPrototypeSlice(path, 0, startPart - 1);\n else\n ret.dir = ret.root;\n\n return ret;\n },\n\n matchesGlob(path, pattern) {\n return glob(path, pattern, true);\n },\n\n sep: '\\\\',\n delimiter: ';',\n win32: null,\n posix: null,\n};\n\nconst posixCwd = (() => {\n if (isWindows) {\n // Converts Windows' backslash path separators to POSIX forward slashes\n // and truncates any drive indicator\n const regexp = /\\\\/g;\n return () => {\n const cwd = StringPrototypeReplace(process.cwd(), regexp, '/');\n return StringPrototypeSlice(cwd, StringPrototypeIndexOf(cwd, '/'));\n };\n }\n\n // We're already on POSIX, no need for any transformations\n return () => process.cwd();\n})();\n\nconst posix = {\n /**\n * path.resolve([from ...], to)\n * @param {...string} args\n * @returns {string}\n */\n resolve(...args) {\n if (args.length === 0 || (args.length === 1 && (args[0] === '' || args[0] === '.'))) {\n const cwd = posixCwd();\n if (StringPrototypeCharCodeAt(cwd, 0) === CHAR_FORWARD_SLASH) {\n return cwd;\n }\n }\n let resolvedPath = '';\n let resolvedAbsolute = false;\n\n for (let i = args.length - 1; i >= 0 && !resolvedAbsolute; i--) {\n const path = args[i];\n validateString(path, `paths[${i}]`);\n\n // Skip empty entries\n if (path.length === 0) {\n continue;\n }\n\n resolvedPath = `${path}/${resolvedPath}`;\n resolvedAbsolute =\n StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;\n }\n\n if (!resolvedAbsolute) {\n const cwd = posixCwd();\n resolvedPath = `${cwd}/${resolvedPath}`;\n resolvedAbsolute =\n StringPrototypeCharCodeAt(cwd, 0) === CHAR_FORWARD_SLASH;\n }\n\n // At this point the path should be resolved to a full absolute path, but\n // handle relative paths to be safe (might happen when process.cwd() fails)\n\n // Normalize the path\n resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/',\n isPosixPathSeparator);\n\n if (resolvedAbsolute) {\n return `/${resolvedPath}`;\n }\n return resolvedPath.length > 0 ? resolvedPath : '.';\n },\n\n /**\n * @param {string} path\n * @returns {string}\n */\n normalize(path) {\n validateString(path, 'path');\n\n if (path.length === 0)\n return '.';\n\n const isAbsolute =\n StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;\n const trailingSeparator =\n StringPrototypeCharCodeAt(path, path.length - 1) === CHAR_FORWARD_SLASH;\n\n // Normalize the path\n path = normalizeString(path, !isAbsolute, '/', isPosixPathSeparator);\n\n if (path.length === 0) {\n if (isAbsolute)\n return '/';\n return trailingSeparator ? './' : '.';\n }\n if (trailingSeparator)\n path += '/';\n\n return isAbsolute ? `/${path}` : path;\n },\n\n /**\n * @param {string} path\n * @returns {boolean}\n */\n isAbsolute(path) {\n validateString(path, 'path');\n return path.length > 0 &&\n StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;\n },\n\n /**\n * @param {...string} args\n * @returns {string}\n */\n join(...args) {\n if (args.length === 0)\n return '.';\n\n const path = [];\n for (let i = 0; i < args.length; ++i) {\n const arg = args[i];\n validateString(arg, 'path');\n if (arg.length > 0) {\n path.push(arg);\n }\n }\n\n if (path.length === 0)\n return '.';\n\n return posix.normalize(ArrayPrototypeJoin(path, '/'));\n },\n\n /**\n * @param {string} from\n * @param {string} to\n * @returns {string}\n */\n relative(from, to) {\n validateString(from, 'from');\n validateString(to, 'to');\n\n if (from === to)\n return '';\n\n // Trim leading forward slashes.\n from = posix.resolve(from);\n to = posix.resolve(to);\n\n if (from === to)\n return '';\n\n const fromStart = 1;\n const fromEnd = from.length;\n const fromLen = fromEnd - fromStart;\n const toStart = 1;\n const toLen = to.length - toStart;\n\n // Compare paths to find the longest common path from root\n const length = (fromLen < toLen ? fromLen : toLen);\n let lastCommonSep = -1;\n let i = 0;\n for (; i < length; i++) {\n const fromCode = StringPrototypeCharCodeAt(from, fromStart + i);\n if (fromCode !== StringPrototypeCharCodeAt(to, toStart + i))\n break;\n else if (fromCode === CHAR_FORWARD_SLASH)\n lastCommonSep = i;\n }\n if (i === length) {\n if (toLen > length) {\n if (StringPrototypeCharCodeAt(to, toStart + i) === CHAR_FORWARD_SLASH) {\n // We get here if `from` is the exact base path for `to`.\n // For example: from='/foo/bar'; to='/foo/bar/baz'\n return StringPrototypeSlice(to, toStart + i + 1);\n }\n if (i === 0) {\n // We get here if `from` is the root\n // For example: from='/'; to='/foo'\n return StringPrototypeSlice(to, toStart + i);\n }\n } else if (fromLen > length) {\n if (StringPrototypeCharCodeAt(from, fromStart + i) ===\n CHAR_FORWARD_SLASH) {\n // We get here if `to` is the exact base path for `from`.\n // For example: from='/foo/bar/baz'; to='/foo/bar'\n lastCommonSep = i;\n } else if (i === 0) {\n // We get here if `to` is the root.\n // For example: from='/foo/bar'; to='/'\n lastCommonSep = 0;\n }\n }\n }\n\n let out = '';\n // Generate the relative path based on the path difference between `to`\n // and `from`.\n for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {\n if (i === fromEnd ||\n StringPrototypeCharCodeAt(from, i) === CHAR_FORWARD_SLASH) {\n out += out.length === 0 ? '..' : '/..';\n }\n }\n\n // Lastly, append the rest of the destination (`to`) path that comes after\n // the common path parts.\n return `${out}${StringPrototypeSlice(to, toStart + lastCommonSep)}`;\n },\n\n /**\n * @param {string} path\n * @returns {string}\n */\n toNamespacedPath(path) {\n // Non-op on posix systems\n return path;\n },\n\n /**\n * @param {string} path\n * @returns {string}\n */\n dirname(path) {\n validateString(path, 'path');\n if (path.length === 0)\n return '.';\n const hasRoot = StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;\n let end = -1;\n let matchedSlash = true;\n for (let i = path.length - 1; i >= 1; --i) {\n if (StringPrototypeCharCodeAt(path, i) === CHAR_FORWARD_SLASH) {\n if (!matchedSlash) {\n end = i;\n break;\n }\n } else {\n // We saw the first non-path separator\n matchedSlash = false;\n }\n }\n\n if (end === -1)\n return hasRoot ? '/' : '.';\n if (hasRoot && end === 1)\n return '//';\n return StringPrototypeSlice(path, 0, end);\n },\n\n /**\n * @param {string} path\n * @param {string} [suffix]\n * @returns {string}\n */\n basename(path, suffix) {\n if (suffix !== undefined)\n validateString(suffix, 'suffix');\n validateString(path, 'path');\n\n let start = 0;\n let end = -1;\n let matchedSlash = true;\n\n if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {\n if (suffix === path)\n return '';\n let extIdx = suffix.length - 1;\n let firstNonSlashEnd = -1;\n for (let i = path.length - 1; i >= 0; --i) {\n const code = StringPrototypeCharCodeAt(path, i);\n if (code === CHAR_FORWARD_SLASH) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n start = i + 1;\n break;\n }\n } else {\n if (firstNonSlashEnd === -1) {\n // We saw the first non-path separator, remember this index in case\n // we need it if the extension ends up not matching\n matchedSlash = false;\n firstNonSlashEnd = i + 1;\n }\n if (extIdx >= 0) {\n // Try to match the explicit extension\n if (code === StringPrototypeCharCodeAt(suffix, extIdx)) {\n if (--extIdx === -1) {\n // We matched the extension, so mark this as the end of our path\n // component\n end = i;\n }\n } else {\n // Extension does not match, so our result is the entire path\n // component\n extIdx = -1;\n end = firstNonSlashEnd;\n }\n }\n }\n }\n\n if (start === end)\n end = firstNonSlashEnd;\n else if (end === -1)\n end = path.length;\n return StringPrototypeSlice(path, start, end);\n }\n for (let i = path.length - 1; i >= 0; --i) {\n if (StringPrototypeCharCodeAt(path, i) === CHAR_FORWARD_SLASH) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n start = i + 1;\n break;\n }\n } else if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // path component\n matchedSlash = false;\n end = i + 1;\n }\n }\n\n if (end === -1)\n return '';\n return StringPrototypeSlice(path, start, end);\n },\n\n /**\n * @param {string} path\n * @returns {string}\n */\n extname(path) {\n validateString(path, 'path');\n let startDot = -1;\n let startPart = 0;\n let end = -1;\n let matchedSlash = true;\n // Track the state of characters (if any) we see before our first dot and\n // after any path separator we find\n let preDotState = 0;\n for (let i = path.length - 1; i >= 0; --i) {\n const char = path[i];\n if (char === '/') {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n startPart = i + 1;\n break;\n }\n continue;\n }\n if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // extension\n matchedSlash = false;\n end = i + 1;\n }\n if (char === '.') {\n // If this is our first dot, mark it as the start of our extension\n if (startDot === -1)\n startDot = i;\n else if (preDotState !== 1)\n preDotState = 1;\n } else if (startDot !== -1) {\n // We saw a non-dot and non-path separator before our dot, so we should\n // have a good chance at having a non-empty extension\n preDotState = -1;\n }\n }\n\n if (startDot === -1 ||\n end === -1 ||\n // We saw a non-dot character immediately before the dot\n preDotState === 0 ||\n // The (right-most) trimmed path component is exactly '..'\n (preDotState === 1 &&\n startDot === end - 1 &&\n startDot === startPart + 1)) {\n return '';\n }\n return StringPrototypeSlice(path, startDot, end);\n },\n\n format: FunctionPrototypeBind(_format, null, '/'),\n\n /**\n * @param {string} path\n * @returns {{\n * dir: string;\n * root: string;\n * base: string;\n * name: string;\n * ext: string;\n * }}\n */\n parse(path) {\n validateString(path, 'path');\n\n const ret = { root: '', dir: '', base: '', ext: '', name: '' };\n if (path.length === 0)\n return ret;\n const isAbsolute =\n StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;\n let start;\n if (isAbsolute) {\n ret.root = '/';\n start = 1;\n } else {\n start = 0;\n }\n let startDot = -1;\n let startPart = 0;\n let end = -1;\n let matchedSlash = true;\n let i = path.length - 1;\n\n // Track the state of characters (if any) we see before our first dot and\n // after any path separator we find\n let preDotState = 0;\n\n // Get non-dir info\n for (; i >= start; --i) {\n const code = StringPrototypeCharCodeAt(path, i);\n if (code === CHAR_FORWARD_SLASH) {\n // If we reached a path separator that was not part of a set of path\n // separators at the end of the string, stop now\n if (!matchedSlash) {\n startPart = i + 1;\n break;\n }\n continue;\n }\n if (end === -1) {\n // We saw the first non-path separator, mark this as the end of our\n // extension\n matchedSlash = false;\n end = i + 1;\n }\n if (code === CHAR_DOT) {\n // If this is our first dot, mark it as the start of our extension\n if (startDot === -1)\n startDot = i;\n else if (preDotState !== 1)\n preDotState = 1;\n } else if (startDot !== -1) {\n // We saw a non-dot and non-path separator before our dot, so we should\n // have a good chance at having a non-empty extension\n preDotState = -1;\n }\n }\n\n if (end !== -1) {\n const start = startPart === 0 && isAbsolute ? 1 : startPart;\n if (startDot === -1 ||\n // We saw a non-dot character immediately before the dot\n preDotState === 0 ||\n // The (right-most) trimmed path component is exactly '..'\n (preDotState === 1 &&\n startDot === end - 1 &&\n startDot === startPart + 1)) {\n ret.base = ret.name = StringPrototypeSlice(path, start, end);\n } else {\n ret.name = StringPrototypeSlice(path, start, startDot);\n ret.base = StringPrototypeSlice(path, start, end);\n ret.ext = StringPrototypeSlice(path, startDot, end);\n }\n }\n\n if (startPart > 0)\n ret.dir = StringPrototypeSlice(path, 0, startPart - 1);\n else if (isAbsolute)\n ret.dir = '/';\n\n return ret;\n },\n\n matchesGlob(path, pattern) {\n return glob(path, pattern, false);\n },\n\n sep: '/',\n delimiter: ':',\n win32: null,\n posix: null,\n};\n\nposix.win32 = win32.win32 = win32;\nposix.posix = win32.posix = posix;\n\n// Legacy internal API, docs-only deprecated: DEP0080\nwin32._makeLong = win32.toNamespacedPath;\nposix._makeLong = posix.toNamespacedPath;\n\nmodule.exports = isWindows ? win32 : posix;\n";
|
|
@@ -7158,7 +7130,7 @@ class NativeStreamDriver {
|
|
|
7158
7130
|
if (failures.length) throw new AggregateError(failures, "Native stream shutdown callbacks failed.");
|
|
7159
7131
|
}
|
|
7160
7132
|
}
|
|
7161
|
-
function ownedBytes
|
|
7133
|
+
function ownedBytes(view) {
|
|
7162
7134
|
const copy2 = new Uint8Array(view.byteLength);
|
|
7163
7135
|
copy2.set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
|
|
7164
7136
|
return copy2;
|
|
@@ -7506,7 +7478,7 @@ class LibuvStreamWrap {
|
|
|
7506
7478
|
const peer = this.peer;
|
|
7507
7479
|
if (!peer || peer.closed) return 0;
|
|
7508
7480
|
if (length === 0) return 0;
|
|
7509
|
-
peer.receive(ownedBytes
|
|
7481
|
+
peer.receive(ownedBytes(buffer2), handle);
|
|
7510
7482
|
return 0;
|
|
7511
7483
|
}
|
|
7512
7484
|
/**
|
|
@@ -21951,11 +21923,11 @@ function requireAvailableTypedArrays() {
|
|
|
21951
21923
|
if (hasRequiredAvailableTypedArrays) return availableTypedArrays;
|
|
21952
21924
|
hasRequiredAvailableTypedArrays = 1;
|
|
21953
21925
|
var possibleNames = requirePossibleTypedArrayNames();
|
|
21954
|
-
var
|
|
21926
|
+
var g2 = typeof globalThis === "undefined" ? globalThis : globalThis;
|
|
21955
21927
|
availableTypedArrays = function availableTypedArrays2() {
|
|
21956
21928
|
var out = [];
|
|
21957
21929
|
for (var i2 = 0; i2 < possibleNames.length; i2++) {
|
|
21958
|
-
if (typeof
|
|
21930
|
+
if (typeof g2[possibleNames[i2]] === "function") {
|
|
21959
21931
|
out[out.length] = possibleNames[i2];
|
|
21960
21932
|
}
|
|
21961
21933
|
}
|
|
@@ -22150,7 +22122,7 @@ function requireWhichTypedArray() {
|
|
|
22150
22122
|
var getProto2 = requireGetProto();
|
|
22151
22123
|
var $toString = callBound2("Object.prototype.toString");
|
|
22152
22124
|
var hasToStringTag = requireShams()();
|
|
22153
|
-
var
|
|
22125
|
+
var g2 = typeof globalThis === "undefined" ? globalThis : globalThis;
|
|
22154
22126
|
var typedArrays = availableTypedArrays2();
|
|
22155
22127
|
var $slice = callBound2("String.prototype.slice");
|
|
22156
22128
|
var $indexOf2 = callBound2("Array.prototype.indexOf", true) || function indexOf(array, value) {
|
|
@@ -22164,7 +22136,7 @@ function requireWhichTypedArray() {
|
|
|
22164
22136
|
var cache2 = { __proto__: null };
|
|
22165
22137
|
if (hasToStringTag && gOPD2 && getProto2) {
|
|
22166
22138
|
forEach2(typedArrays, function(typedArray) {
|
|
22167
|
-
var arr = new
|
|
22139
|
+
var arr = new g2[typedArray]();
|
|
22168
22140
|
if (Symbol.toStringTag in arr && getProto2) {
|
|
22169
22141
|
var proto = getProto2(arr);
|
|
22170
22142
|
var descriptor = gOPD2(proto, Symbol.toStringTag);
|
|
@@ -22183,7 +22155,7 @@ function requireWhichTypedArray() {
|
|
|
22183
22155
|
});
|
|
22184
22156
|
} else {
|
|
22185
22157
|
forEach2(typedArrays, function(typedArray) {
|
|
22186
|
-
var arr = new
|
|
22158
|
+
var arr = new g2[typedArray]();
|
|
22187
22159
|
var fn = arr.slice || arr.set;
|
|
22188
22160
|
if (fn) {
|
|
22189
22161
|
var bound = (
|
|
@@ -22663,7 +22635,7 @@ Sha256$1.prototype._update = function(M) {
|
|
|
22663
22635
|
var d = this._d | 0;
|
|
22664
22636
|
var e = this._e | 0;
|
|
22665
22637
|
var f = this._f | 0;
|
|
22666
|
-
var
|
|
22638
|
+
var g2 = this._g | 0;
|
|
22667
22639
|
var h = this._h | 0;
|
|
22668
22640
|
for (var i2 = 0; i2 < 16; ++i2) {
|
|
22669
22641
|
w[i2] = M.readInt32BE(i2 * 4);
|
|
@@ -22672,10 +22644,10 @@ Sha256$1.prototype._update = function(M) {
|
|
|
22672
22644
|
w[i2] = gamma1(w[i2 - 2]) + w[i2 - 7] + gamma0(w[i2 - 15]) + w[i2 - 16] | 0;
|
|
22673
22645
|
}
|
|
22674
22646
|
for (var j = 0; j < 64; ++j) {
|
|
22675
|
-
var T1 = h + sigma1$1(e) + ch(e, f,
|
|
22647
|
+
var T1 = h + sigma1$1(e) + ch(e, f, g2) + K$2[j] + w[j] | 0;
|
|
22676
22648
|
var T2 = sigma0$1(a) + maj$1(a, b, c) | 0;
|
|
22677
|
-
h =
|
|
22678
|
-
|
|
22649
|
+
h = g2;
|
|
22650
|
+
g2 = f;
|
|
22679
22651
|
f = e;
|
|
22680
22652
|
e = d + T1 | 0;
|
|
22681
22653
|
d = c;
|
|
@@ -22689,7 +22661,7 @@ Sha256$1.prototype._update = function(M) {
|
|
|
22689
22661
|
this._d = d + this._d | 0;
|
|
22690
22662
|
this._e = e + this._e | 0;
|
|
22691
22663
|
this._f = f + this._f | 0;
|
|
22692
|
-
this._g =
|
|
22664
|
+
this._g = g2 + this._g | 0;
|
|
22693
22665
|
this._h = h + this._h | 0;
|
|
22694
22666
|
};
|
|
22695
22667
|
Sha256$1.prototype._hash = function() {
|
|
@@ -22704,9 +22676,9 @@ Sha256$1.prototype._hash = function() {
|
|
|
22704
22676
|
H.writeInt32BE(this._h, 28);
|
|
22705
22677
|
return H;
|
|
22706
22678
|
};
|
|
22707
|
-
var sha256 = Sha256$1;
|
|
22679
|
+
var sha256$1 = Sha256$1;
|
|
22708
22680
|
var inherits$2 = inherits_browserExports;
|
|
22709
|
-
var Sha256 = sha256;
|
|
22681
|
+
var Sha256 = sha256$1;
|
|
22710
22682
|
var Hash$2 = hash$1;
|
|
22711
22683
|
var Buffer$3 = safeBufferExports.Buffer;
|
|
22712
22684
|
var W$2 = new Array(64);
|
|
@@ -23132,7 +23104,7 @@ var sha384 = Sha384;
|
|
|
23132
23104
|
module.exports.sha = sha;
|
|
23133
23105
|
module.exports.sha1 = sha1;
|
|
23134
23106
|
module.exports.sha224 = sha224;
|
|
23135
|
-
module.exports.sha256 = sha256;
|
|
23107
|
+
module.exports.sha256 = sha256$1;
|
|
23136
23108
|
module.exports.sha384 = sha384;
|
|
23137
23109
|
module.exports.sha512 = sha512;
|
|
23138
23110
|
})(sha_js);
|
|
@@ -23186,9 +23158,27 @@ function clean(...arrays) {
|
|
|
23186
23158
|
function createView(arr) {
|
|
23187
23159
|
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
23188
23160
|
}
|
|
23161
|
+
function rotr(word, shift) {
|
|
23162
|
+
return word << 32 - shift | word >>> shift;
|
|
23163
|
+
}
|
|
23189
23164
|
function rotl(word, shift) {
|
|
23190
23165
|
return word << shift | word >>> 32 - shift >>> 0;
|
|
23191
23166
|
}
|
|
23167
|
+
const hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
23168
|
+
// @ts-ignore
|
|
23169
|
+
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
23170
|
+
))();
|
|
23171
|
+
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i2) => i2.toString(16).padStart(2, "0"));
|
|
23172
|
+
function bytesToHex(bytes2) {
|
|
23173
|
+
abytes(bytes2);
|
|
23174
|
+
if (hasHexBuiltin)
|
|
23175
|
+
return bytes2.toHex();
|
|
23176
|
+
let hex = "";
|
|
23177
|
+
for (let i2 = 0; i2 < bytes2.length; i2++) {
|
|
23178
|
+
hex += hexes[bytes2[i2]];
|
|
23179
|
+
}
|
|
23180
|
+
return hex;
|
|
23181
|
+
}
|
|
23192
23182
|
function checkOpts(defaults, opts, title = "opts") {
|
|
23193
23183
|
aobject(defaults, "defaults");
|
|
23194
23184
|
if (opts !== void 0)
|
|
@@ -23209,9 +23199,17 @@ function createHasher(hashCons, info = {}) {
|
|
|
23209
23199
|
Object.assign(hashC, info);
|
|
23210
23200
|
return Object.freeze(hashC);
|
|
23211
23201
|
}
|
|
23202
|
+
const oidNist = (suffix) => ({
|
|
23203
|
+
// Current NIST hashAlgs suffixes used here fit in one DER subidentifier octet.
|
|
23204
|
+
// Larger suffix values would need base-128 OID encoding and a different length byte.
|
|
23205
|
+
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
|
|
23206
|
+
});
|
|
23212
23207
|
function Chi(a, b, c) {
|
|
23213
23208
|
return a & b ^ ~a & c;
|
|
23214
23209
|
}
|
|
23210
|
+
function Maj(a, b, c) {
|
|
23211
|
+
return a & b ^ a & c ^ b & c;
|
|
23212
|
+
}
|
|
23215
23213
|
class HashMD {
|
|
23216
23214
|
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
23217
23215
|
__publicField(this, "blockLen");
|
|
@@ -23307,6 +23305,16 @@ class HashMD {
|
|
|
23307
23305
|
return this._cloneInto();
|
|
23308
23306
|
}
|
|
23309
23307
|
}
|
|
23308
|
+
const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
23309
|
+
1779033703,
|
|
23310
|
+
3144134277,
|
|
23311
|
+
1013904242,
|
|
23312
|
+
2773480762,
|
|
23313
|
+
1359893119,
|
|
23314
|
+
2600822924,
|
|
23315
|
+
528734635,
|
|
23316
|
+
1541459225
|
|
23317
|
+
]);
|
|
23310
23318
|
const SHA1_IV = /* @__PURE__ */ Uint32Array.from([
|
|
23311
23319
|
1732584193,
|
|
23312
23320
|
4023233417,
|
|
@@ -23354,21 +23362,21 @@ class _MD5 extends HashMD {
|
|
|
23354
23362
|
MD5_W[i2] = view.getUint32(offset2, true);
|
|
23355
23363
|
let { A, B, C, D } = this;
|
|
23356
23364
|
for (let i2 = 0; i2 < 64; i2++) {
|
|
23357
|
-
let F,
|
|
23365
|
+
let F, g2;
|
|
23358
23366
|
if (i2 < 16) {
|
|
23359
23367
|
F = Chi(B, C, D);
|
|
23360
|
-
|
|
23368
|
+
g2 = i2;
|
|
23361
23369
|
} else if (i2 < 32) {
|
|
23362
23370
|
F = Chi(D, B, C);
|
|
23363
|
-
|
|
23371
|
+
g2 = (5 * i2 + 1) % 16;
|
|
23364
23372
|
} else if (i2 < 48) {
|
|
23365
23373
|
F = B ^ C ^ D;
|
|
23366
|
-
|
|
23374
|
+
g2 = (3 * i2 + 5) % 16;
|
|
23367
23375
|
} else {
|
|
23368
23376
|
F = C ^ (B | ~D);
|
|
23369
|
-
|
|
23377
|
+
g2 = 7 * i2 % 16;
|
|
23370
23378
|
}
|
|
23371
|
-
F = F + A + K[i2] + MD5_W[
|
|
23379
|
+
F = F + A + K[i2] + MD5_W[g2];
|
|
23372
23380
|
A = D;
|
|
23373
23381
|
D = C;
|
|
23374
23382
|
C = B;
|
|
@@ -29873,12 +29881,12 @@ let Worker$1 = class Worker3 extends EventEmitter {
|
|
|
29873
29881
|
return Promise.resolve({});
|
|
29874
29882
|
}
|
|
29875
29883
|
};
|
|
29876
|
-
|
|
29884
|
+
class MessageChannel {
|
|
29877
29885
|
constructor() {
|
|
29878
29886
|
__publicField(this, "port1", new MessagePort());
|
|
29879
29887
|
__publicField(this, "port2", new MessagePort());
|
|
29880
29888
|
}
|
|
29881
|
-
}
|
|
29889
|
+
}
|
|
29882
29890
|
class MessagePort extends EventEmitter {
|
|
29883
29891
|
postMessage(value, transferList) {
|
|
29884
29892
|
}
|
|
@@ -29933,7 +29941,7 @@ const worker_threads = {
|
|
|
29933
29941
|
workerData,
|
|
29934
29942
|
threadId,
|
|
29935
29943
|
Worker: Worker$1,
|
|
29936
|
-
MessageChannel
|
|
29944
|
+
MessageChannel,
|
|
29937
29945
|
MessagePort,
|
|
29938
29946
|
BroadcastChannel: BroadcastChannel$1,
|
|
29939
29947
|
moveMessagePortToContext,
|
|
@@ -29948,7 +29956,7 @@ const worker_threads = {
|
|
|
29948
29956
|
const workerThreadsShim = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
29949
29957
|
__proto__: null,
|
|
29950
29958
|
BroadcastChannel: BroadcastChannel$1,
|
|
29951
|
-
MessageChannel
|
|
29959
|
+
MessageChannel,
|
|
29952
29960
|
MessagePort,
|
|
29953
29961
|
SHARE_ENV,
|
|
29954
29962
|
Worker: Worker$1,
|
|
@@ -32350,6 +32358,169 @@ function simpleHash(str) {
|
|
|
32350
32358
|
}
|
|
32351
32359
|
return hash2.toString(36);
|
|
32352
32360
|
}
|
|
32361
|
+
const SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
32362
|
+
1116352408,
|
|
32363
|
+
1899447441,
|
|
32364
|
+
3049323471,
|
|
32365
|
+
3921009573,
|
|
32366
|
+
961987163,
|
|
32367
|
+
1508970993,
|
|
32368
|
+
2453635748,
|
|
32369
|
+
2870763221,
|
|
32370
|
+
3624381080,
|
|
32371
|
+
310598401,
|
|
32372
|
+
607225278,
|
|
32373
|
+
1426881987,
|
|
32374
|
+
1925078388,
|
|
32375
|
+
2162078206,
|
|
32376
|
+
2614888103,
|
|
32377
|
+
3248222580,
|
|
32378
|
+
3835390401,
|
|
32379
|
+
4022224774,
|
|
32380
|
+
264347078,
|
|
32381
|
+
604807628,
|
|
32382
|
+
770255983,
|
|
32383
|
+
1249150122,
|
|
32384
|
+
1555081692,
|
|
32385
|
+
1996064986,
|
|
32386
|
+
2554220882,
|
|
32387
|
+
2821834349,
|
|
32388
|
+
2952996808,
|
|
32389
|
+
3210313671,
|
|
32390
|
+
3336571891,
|
|
32391
|
+
3584528711,
|
|
32392
|
+
113926993,
|
|
32393
|
+
338241895,
|
|
32394
|
+
666307205,
|
|
32395
|
+
773529912,
|
|
32396
|
+
1294757372,
|
|
32397
|
+
1396182291,
|
|
32398
|
+
1695183700,
|
|
32399
|
+
1986661051,
|
|
32400
|
+
2177026350,
|
|
32401
|
+
2456956037,
|
|
32402
|
+
2730485921,
|
|
32403
|
+
2820302411,
|
|
32404
|
+
3259730800,
|
|
32405
|
+
3345764771,
|
|
32406
|
+
3516065817,
|
|
32407
|
+
3600352804,
|
|
32408
|
+
4094571909,
|
|
32409
|
+
275423344,
|
|
32410
|
+
430227734,
|
|
32411
|
+
506948616,
|
|
32412
|
+
659060556,
|
|
32413
|
+
883997877,
|
|
32414
|
+
958139571,
|
|
32415
|
+
1322822218,
|
|
32416
|
+
1537002063,
|
|
32417
|
+
1747873779,
|
|
32418
|
+
1955562222,
|
|
32419
|
+
2024104815,
|
|
32420
|
+
2227730452,
|
|
32421
|
+
2361852424,
|
|
32422
|
+
2428436474,
|
|
32423
|
+
2756734187,
|
|
32424
|
+
3204031479,
|
|
32425
|
+
3329325298
|
|
32426
|
+
]);
|
|
32427
|
+
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
32428
|
+
class SHA2_32B extends HashMD {
|
|
32429
|
+
constructor(outputLen, IV) {
|
|
32430
|
+
super(64, outputLen, 8, false);
|
|
32431
|
+
// We cannot use array here since array allows indexing by variable
|
|
32432
|
+
// which means optimizer/compiler cannot use registers.
|
|
32433
|
+
// Numeric initializers matter: starting the fields as `undefined` changes
|
|
32434
|
+
// V8's field representation and makes sha256 3x slower (measured).
|
|
32435
|
+
__publicField(this, "A", 0);
|
|
32436
|
+
__publicField(this, "B", 0);
|
|
32437
|
+
__publicField(this, "C", 0);
|
|
32438
|
+
__publicField(this, "D", 0);
|
|
32439
|
+
__publicField(this, "E", 0);
|
|
32440
|
+
__publicField(this, "F", 0);
|
|
32441
|
+
__publicField(this, "G", 0);
|
|
32442
|
+
__publicField(this, "H", 0);
|
|
32443
|
+
this.A = IV[0] | 0;
|
|
32444
|
+
this.B = IV[1] | 0;
|
|
32445
|
+
this.C = IV[2] | 0;
|
|
32446
|
+
this.D = IV[3] | 0;
|
|
32447
|
+
this.E = IV[4] | 0;
|
|
32448
|
+
this.F = IV[5] | 0;
|
|
32449
|
+
this.G = IV[6] | 0;
|
|
32450
|
+
this.H = IV[7] | 0;
|
|
32451
|
+
}
|
|
32452
|
+
get() {
|
|
32453
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
32454
|
+
return [A, B, C, D, E, F, G, H];
|
|
32455
|
+
}
|
|
32456
|
+
// prettier-ignore
|
|
32457
|
+
set(A, B, C, D, E, F, G, H) {
|
|
32458
|
+
this.A = A | 0;
|
|
32459
|
+
this.B = B | 0;
|
|
32460
|
+
this.C = C | 0;
|
|
32461
|
+
this.D = D | 0;
|
|
32462
|
+
this.E = E | 0;
|
|
32463
|
+
this.F = F | 0;
|
|
32464
|
+
this.G = G | 0;
|
|
32465
|
+
this.H = H | 0;
|
|
32466
|
+
}
|
|
32467
|
+
_cloneInto(to) {
|
|
32468
|
+
(to || (to = new this.constructor())).set(...this.get());
|
|
32469
|
+
return this._cloneIntoMeta(to);
|
|
32470
|
+
}
|
|
32471
|
+
process(view, offset2) {
|
|
32472
|
+
for (let i2 = 0; i2 < 16; i2++, offset2 += 4)
|
|
32473
|
+
SHA256_W[i2] = view.getUint32(offset2, false);
|
|
32474
|
+
for (let i2 = 16; i2 < 64; i2++) {
|
|
32475
|
+
const W15 = SHA256_W[i2 - 15];
|
|
32476
|
+
const W2 = SHA256_W[i2 - 2];
|
|
32477
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
32478
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
32479
|
+
SHA256_W[i2] = s1 + SHA256_W[i2 - 7] + s0 + SHA256_W[i2 - 16] | 0;
|
|
32480
|
+
}
|
|
32481
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
32482
|
+
for (let i2 = 0; i2 < 64; i2++) {
|
|
32483
|
+
const sigma12 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
32484
|
+
const T1 = H + sigma12 + Chi(E, F, G) + SHA256_K[i2] + SHA256_W[i2] | 0;
|
|
32485
|
+
const sigma02 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
32486
|
+
const T2 = sigma02 + Maj(A, B, C) | 0;
|
|
32487
|
+
H = G;
|
|
32488
|
+
G = F;
|
|
32489
|
+
F = E;
|
|
32490
|
+
E = D + T1 | 0;
|
|
32491
|
+
D = C;
|
|
32492
|
+
C = B;
|
|
32493
|
+
B = A;
|
|
32494
|
+
A = T1 + T2 | 0;
|
|
32495
|
+
}
|
|
32496
|
+
A = A + this.A | 0;
|
|
32497
|
+
B = B + this.B | 0;
|
|
32498
|
+
C = C + this.C | 0;
|
|
32499
|
+
D = D + this.D | 0;
|
|
32500
|
+
E = E + this.E | 0;
|
|
32501
|
+
F = F + this.F | 0;
|
|
32502
|
+
G = G + this.G | 0;
|
|
32503
|
+
H = H + this.H | 0;
|
|
32504
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
32505
|
+
}
|
|
32506
|
+
roundClean() {
|
|
32507
|
+
clean(SHA256_W);
|
|
32508
|
+
}
|
|
32509
|
+
destroy() {
|
|
32510
|
+
this.destroyed = true;
|
|
32511
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
32512
|
+
clean(this.buffer);
|
|
32513
|
+
}
|
|
32514
|
+
}
|
|
32515
|
+
class _SHA256 extends SHA2_32B {
|
|
32516
|
+
constructor() {
|
|
32517
|
+
super(32, SHA256_IV);
|
|
32518
|
+
}
|
|
32519
|
+
}
|
|
32520
|
+
const sha256 = /* @__PURE__ */ createHasher(
|
|
32521
|
+
() => new _SHA256(),
|
|
32522
|
+
/* @__PURE__ */ oidNist(1)
|
|
32523
|
+
);
|
|
32353
32524
|
const fsModule = lazyModule("fs");
|
|
32354
32525
|
lazyModule("internal/fs/promises");
|
|
32355
32526
|
function fsModuleFor(process2) {
|
|
@@ -37988,6 +38159,33 @@ Object.defineProperty(globalThis, "__substrateEvalSource", {
|
|
|
37988
38159
|
configurable: true,
|
|
37989
38160
|
value: (source) => typeof source === "string" ? __substrateRewriteDynamicImportsInScript(source) : source
|
|
37990
38161
|
});
|
|
38162
|
+
function __substratePrepareBody(rawCode, resolvedPath, format2, process2) {
|
|
38163
|
+
let code2 = rawCode;
|
|
38164
|
+
if (code2.startsWith("#!")) {
|
|
38165
|
+
code2 = code2.slice(code2.indexOf("\n") + 1);
|
|
38166
|
+
}
|
|
38167
|
+
code2 = __substrateModuleTypes(code2, resolvedPath, format2, process2);
|
|
38168
|
+
const __commonjs = format2 === "commonjs" || format2 === "commonjs-typescript" ? true : format2 === "module" || format2 === "module-typescript" ? false : resolvedPath.endsWith(".cjs") || resolvedPath.endsWith(".cts");
|
|
38169
|
+
if (!__commonjs) {
|
|
38170
|
+
const lowered = transformEsmToCjs(code2, resolvedPath);
|
|
38171
|
+
code2 = lowered === code2 ? code2 : `${__substrateModuleMarker}"use strict";${lowered}`;
|
|
38172
|
+
} else {
|
|
38173
|
+
code2 = transformDynamicImportsRegex(code2);
|
|
38174
|
+
}
|
|
38175
|
+
return code2;
|
|
38176
|
+
}
|
|
38177
|
+
const PREPARED_MODULES_DIR = "/.tabnode/prepared";
|
|
38178
|
+
const PREPARED_MODULES_FORMAT = "tabnode-prepared-1";
|
|
38179
|
+
function preparedModuleKey(rawCode, resolvedPath) {
|
|
38180
|
+
var _a2;
|
|
38181
|
+
const extension = (_a2 = /\.(js|cjs|mjs)$/u.exec(resolvedPath)) == null ? void 0 : _a2[1];
|
|
38182
|
+
if (!extension) return void 0;
|
|
38183
|
+
const kind = extension === "cjs" ? "cjs" : "js";
|
|
38184
|
+
return bytesToHex(sha256(new TextEncoder().encode(`${PREPARED_MODULES_FORMAT}|${kind}|${rawCode}`)));
|
|
38185
|
+
}
|
|
38186
|
+
function prepareModuleForImage(rawCode, resolvedPath) {
|
|
38187
|
+
return __substrateScopeGlobalCalls(__substratePrepareBody(rawCode, resolvedPath, void 0, { execArgv: [], env: {} }));
|
|
38188
|
+
}
|
|
37991
38189
|
function transformEsmToCjs(code2, filename) {
|
|
37992
38190
|
const maybeEsm = __substrateHasEsmSyntax(code2);
|
|
37993
38191
|
if (!maybeEsm) return __substrateRewriteDynamicImportsInScript(code2);
|
|
@@ -39026,6 +39224,14 @@ function createRequire(vfs2, fsShim, process2, currentDir, moduleCache, options,
|
|
|
39026
39224
|
}
|
|
39027
39225
|
const rawCode = source === void 0 || source === null ? defaultSource() : String(source);
|
|
39028
39226
|
const dirname$1 = resolvedPath.startsWith("data:") ? currentDir : dirname(resolvedPath);
|
|
39227
|
+
if (format2 === void 0 && !transformsTypes(process2) && vfs2.existsSync(PREPARED_MODULES_DIR)) {
|
|
39228
|
+
const key = preparedModuleKey(rawCode, resolvedPath);
|
|
39229
|
+
const prepared = key ? `${PREPARED_MODULES_DIR}/${key}` : void 0;
|
|
39230
|
+
if (prepared && vfs2.existsSync(prepared)) {
|
|
39231
|
+
runModuleBody(module, vfs2.readFileSync(prepared, "utf8"), resolvedPath, dirname$1, true);
|
|
39232
|
+
return module;
|
|
39233
|
+
}
|
|
39234
|
+
}
|
|
39029
39235
|
runModuleBody(module, prepareModuleCode(rawCode, resolvedPath, format2), resolvedPath, dirname$1);
|
|
39030
39236
|
return module;
|
|
39031
39237
|
};
|
|
@@ -39033,23 +39239,12 @@ function createRequire(vfs2, fsShim, process2, currentDir, moduleCache, options,
|
|
|
39033
39239
|
const codeCacheKey = `${resolvedPath}|${format2 ?? ""}|${transformsTypes(process2) ? "transform-types|" : ""}${simpleHash(rawCode)}`;
|
|
39034
39240
|
let code2 = processedCodeCache == null ? void 0 : processedCodeCache.get(codeCacheKey);
|
|
39035
39241
|
if (!code2) {
|
|
39036
|
-
code2 = rawCode;
|
|
39037
|
-
if (code2.startsWith("#!")) {
|
|
39038
|
-
code2 = code2.slice(code2.indexOf("\n") + 1);
|
|
39039
|
-
}
|
|
39040
|
-
code2 = __substrateModuleTypes(code2, resolvedPath, format2, process2);
|
|
39041
|
-
const __commonjs = format2 === "commonjs" || format2 === "commonjs-typescript" ? true : format2 === "module" || format2 === "module-typescript" ? false : resolvedPath.endsWith(".cjs") || resolvedPath.endsWith(".cts");
|
|
39042
|
-
if (!__commonjs) {
|
|
39043
|
-
const lowered = transformEsmToCjs(code2, resolvedPath);
|
|
39044
|
-
code2 = lowered === code2 ? code2 : `${__substrateModuleMarker}"use strict";${lowered}`;
|
|
39045
|
-
} else {
|
|
39046
|
-
code2 = transformDynamicImportsRegex(code2);
|
|
39047
|
-
}
|
|
39242
|
+
code2 = __substratePrepareBody(rawCode, resolvedPath, format2, process2);
|
|
39048
39243
|
processedCodeCache == null ? void 0 : processedCodeCache.set(codeCacheKey, code2);
|
|
39049
39244
|
}
|
|
39050
39245
|
return code2;
|
|
39051
39246
|
};
|
|
39052
|
-
const runModuleBody = (module, prepared, resolvedPath, dirname2) => {
|
|
39247
|
+
const runModuleBody = (module, prepared, resolvedPath, dirname2, scoped = false) => {
|
|
39053
39248
|
let code2 = prepared;
|
|
39054
39249
|
const moduleRequire = createRequire(
|
|
39055
39250
|
vfs2,
|
|
@@ -39066,7 +39261,7 @@ function createRequire(vfs2, fsShim, process2, currentDir, moduleCache, options,
|
|
|
39066
39261
|
try {
|
|
39067
39262
|
const importMetaUrl = resolvedPath.startsWith("data:") ? resolvedPath : "file://" + resolvedPath;
|
|
39068
39263
|
const strictBody = code2.startsWith(__substrateModuleMarker);
|
|
39069
|
-
code2 = __substrateScopeGlobalCalls(code2);
|
|
39264
|
+
if (!scoped) code2 = __substrateScopeGlobalCalls(code2);
|
|
39070
39265
|
const wrappedCode = `(function($exports, $require, $module, $filename, $dirname, $process, $console, $importMeta, $dynamicImport, __substrateGuestGlobal, __substrateGuestConstructor) { var exports = $exports; var require = $require; var module = $module; var __filename = $filename; var __dirname = $dirname; var process = $process; var console = $console; var import_meta = $importMeta; var __dynamicImport = $dynamicImport; var document = void 0, window = void 0, location = void 0, self = void 0; var globalThis = __substrateGuestGlobal($process); var global = globalThis; var Buffer = globalThis.Buffer; var queueMicrotask = globalThis.queueMicrotask, atob = globalThis.atob, btoa = globalThis.btoa, structuredClone = globalThis.structuredClone, setTimeout = globalThis.setTimeout, clearTimeout = globalThis.clearTimeout, setInterval = globalThis.setInterval, clearInterval = globalThis.clearInterval; globalThis.process = $process; global.process = $process; with ({ __proto__: null, get navigator() { return globalThis.navigator; }, set navigator(value) { globalThis.navigator = value; }, get Navigator() { return globalThis.Navigator; }, set Navigator(value) { globalThis.Navigator = value; }, get Promise() { return globalThis.Promise; }, set Promise(value) { globalThis.Promise = value; }, get fetch() { return globalThis.fetch; }, set fetch(value) { globalThis.fetch = value; } }) { return (function() {${code2}
|
|
39071
39266
|
}).call(${strictBody ? "void 0" : "$module.exports"}); }
|
|
39072
39267
|
})${__substrateSourceURL(resolvedPath)}`;
|
|
@@ -39925,7 +40120,7 @@ class WorkerRuntime {
|
|
|
39925
40120
|
this.worker = new Worker(
|
|
39926
40121
|
new URL(
|
|
39927
40122
|
/* @vite-ignore */
|
|
39928
|
-
"/assets/runtime-worker-
|
|
40123
|
+
"/assets/runtime-worker-DPvtXRd8.js",
|
|
39929
40124
|
import.meta.url
|
|
39930
40125
|
),
|
|
39931
40126
|
{ type: "module" }
|
|
@@ -41591,14 +41786,6 @@ function __upgradeOverLoopback(port, method, url2, headers) {
|
|
|
41591
41786
|
});
|
|
41592
41787
|
}
|
|
41593
41788
|
const _encoder = new TextEncoder();
|
|
41594
|
-
const FLOW_MAX_REQUEST_BYTES = 64 * 1024 * 1024;
|
|
41595
|
-
const FLOW_MAX_CHUNK_BYTES = 65536;
|
|
41596
|
-
const FLOW_QUEUED_CHUNKS = 4;
|
|
41597
|
-
function ownedBytes(view) {
|
|
41598
|
-
const copy2 = new Uint8Array(view.byteLength);
|
|
41599
|
-
copy2.set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
|
|
41600
|
-
return copy2;
|
|
41601
|
-
}
|
|
41602
41789
|
function guestListeningServer(port, address) {
|
|
41603
41790
|
const hostname2 = address;
|
|
41604
41791
|
return {
|
|
@@ -41608,7 +41795,10 @@ function guestListeningServer(port, address) {
|
|
|
41608
41795
|
address: hostname2,
|
|
41609
41796
|
family: hostname2.includes(":") ? "IPv6" : "IPv4"
|
|
41610
41797
|
}),
|
|
41611
|
-
handleRequest: (method, url2, headers, body) =>
|
|
41798
|
+
handleRequest: (method, url2, headers, body) => (
|
|
41799
|
+
// this engine's bridge hands its servers a Buffer (`bodyOf`)
|
|
41800
|
+
__requestOverLoopback(port, method, url2, headers, typeof body === "string" ? Buffer$9.from(body) : body)
|
|
41801
|
+
)
|
|
41612
41802
|
};
|
|
41613
41803
|
}
|
|
41614
41804
|
const __substrateUpgradeSockets = /* @__PURE__ */ new Map();
|
|
@@ -41837,22 +42027,11 @@ function __substrateListenForUpgrades(bridge) {
|
|
|
41837
42027
|
});
|
|
41838
42028
|
return channel;
|
|
41839
42029
|
}
|
|
41840
|
-
|
|
42030
|
+
class ServerBridge extends PortBridge {
|
|
41841
42031
|
constructor(options = {}) {
|
|
41842
|
-
super();
|
|
41843
|
-
__publicField(this, "servers", /* @__PURE__ */ new Map());
|
|
41844
|
-
__publicField(this, "baseUrl");
|
|
41845
|
-
__publicField(this, "options");
|
|
41846
|
-
__publicField(this, "messageChannel", null);
|
|
42032
|
+
super(options);
|
|
41847
42033
|
/** The upgrade channel this bridge opened, held so it can be given back. */
|
|
41848
42034
|
__publicField(this, "upgradeChannel", null);
|
|
41849
|
-
__publicField(this, "serviceWorkerReady", false);
|
|
41850
|
-
__publicField(this, "keepaliveInterval", null);
|
|
41851
|
-
/**
|
|
41852
|
-
* Give back everything this bridge opened: the upgrade channel and the
|
|
41853
|
-
* service worker keepalive. A host that is done with a container calls it
|
|
41854
|
-
* and has its process back; calling it twice is nothing.
|
|
41855
|
-
*/
|
|
41856
42035
|
/**
|
|
41857
42036
|
* Every port a guest starts listening on becomes a server this bridge can
|
|
41858
42037
|
* answer for, and every port it stops listening on stops being one. The
|
|
@@ -41860,17 +42039,6 @@ const _ServerBridge = class _ServerBridge extends EventEmitter {
|
|
|
41860
42039
|
* the engine's `http` is Node's own file and knows nothing of a page.
|
|
41861
42040
|
*/
|
|
41862
42041
|
__publicField(this, "guestServers", /* @__PURE__ */ new WeakSet());
|
|
41863
|
-
/** The server the service worker answers at the origin's root, the preview's; null for none. */
|
|
41864
|
-
__publicField(this, "primaryPort", null);
|
|
41865
|
-
__publicField(this, "ownDocuments");
|
|
41866
|
-
/** Flow-controlled requests in flight: a pull is one chunk's credit, a cancel ends the upstream. */
|
|
41867
|
-
__publicField(this, "controlledStreams", /* @__PURE__ */ new Map());
|
|
41868
|
-
this.options = options;
|
|
41869
|
-
if (typeof location !== "undefined") {
|
|
41870
|
-
this.baseUrl = options.baseUrl || `${location.protocol}//${location.host}`;
|
|
41871
|
-
} else {
|
|
41872
|
-
this.baseUrl = options.baseUrl || "http://localhost";
|
|
41873
|
-
}
|
|
41874
42042
|
this.watchGuestPorts();
|
|
41875
42043
|
this.upgradeChannel = __substrateListenForUpgrades();
|
|
41876
42044
|
}
|
|
@@ -41900,507 +42068,23 @@ const _ServerBridge = class _ServerBridge extends EventEmitter {
|
|
|
41900
42068
|
}
|
|
41901
42069
|
this.upgradeChannel = null;
|
|
41902
42070
|
}
|
|
41903
|
-
|
|
41904
|
-
clearInterval(this.keepaliveInterval);
|
|
41905
|
-
this.keepaliveInterval = null;
|
|
41906
|
-
}
|
|
41907
|
-
}
|
|
41908
|
-
/**
|
|
41909
|
-
* Register a server on a port
|
|
41910
|
-
*/
|
|
41911
|
-
registerServer(server, port, hostname2 = "0.0.0.0") {
|
|
41912
|
-
this.servers.set(port, { server, port, hostname: hostname2 });
|
|
41913
|
-
const url2 = this.getServerUrl(port);
|
|
41914
|
-
this.emit("server-ready", port, url2);
|
|
41915
|
-
if (this.options.onServerReady) {
|
|
41916
|
-
this.options.onServerReady(port, url2);
|
|
41917
|
-
}
|
|
41918
|
-
this.notifyServiceWorker("server-registered", { port, hostname: hostname2, primary: port === this.primaryPort });
|
|
41919
|
-
}
|
|
41920
|
-
/**
|
|
41921
|
-
* Unregister a server
|
|
41922
|
-
*/
|
|
41923
|
-
unregisterServer(port) {
|
|
41924
|
-
this.servers.delete(port);
|
|
41925
|
-
if (this.primaryPort === port) this.primaryPort = null;
|
|
41926
|
-
this.notifyServiceWorker("server-unregistered", { port });
|
|
41927
|
-
}
|
|
41928
|
-
/**
|
|
41929
|
-
* Names the server the service worker serves at the origin's root, as an
|
|
41930
|
-
* app is served at its own origin's root: its documents read their routes
|
|
41931
|
-
* from `location.pathname`, which under /__virtual__/<port>/ is not the
|
|
41932
|
-
* path they expect. Told to the worker now and again whenever the worker
|
|
41933
|
-
* is (re)initialized, since a worker that restarted remembers nothing.
|
|
41934
|
-
*/
|
|
41935
|
-
setPrimaryPort(port) {
|
|
41936
|
-
const previous = this.primaryPort;
|
|
41937
|
-
this.primaryPort = port;
|
|
41938
|
-
if (previous !== null && previous !== port) {
|
|
41939
|
-
const entry = this.servers.get(previous);
|
|
41940
|
-
if (entry) this.notifyServiceWorker("server-registered", { port: previous, hostname: entry.hostname, primary: false });
|
|
41941
|
-
}
|
|
41942
|
-
if (port !== null) {
|
|
41943
|
-
const entry = this.servers.get(port);
|
|
41944
|
-
this.notifyServiceWorker("server-registered", { port, hostname: (entry == null ? void 0 : entry.hostname) ?? "0.0.0.0", primary: true });
|
|
41945
|
-
}
|
|
41946
|
-
}
|
|
41947
|
-
/** Every registration the worker should hold, sent again to a worker that was (re)initialized. */
|
|
41948
|
-
announceServers() {
|
|
41949
|
-
if (this.ownDocuments) this.notifyServiceWorker("own-documents", { paths: this.ownDocuments });
|
|
41950
|
-
for (const [port, entry] of this.servers) {
|
|
41951
|
-
this.notifyServiceWorker("server-registered", { port, hostname: entry.hostname, primary: port === this.primaryPort });
|
|
41952
|
-
}
|
|
41953
|
-
}
|
|
41954
|
-
/**
|
|
41955
|
-
* Get server URL for a port
|
|
41956
|
-
*/
|
|
41957
|
-
getServerUrl(port) {
|
|
41958
|
-
return `${this.baseUrl}/__virtual__/${port}`;
|
|
41959
|
-
}
|
|
41960
|
-
/**
|
|
41961
|
-
* Get all registered server ports
|
|
41962
|
-
*/
|
|
41963
|
-
getServerPorts() {
|
|
41964
|
-
return [...this.servers.keys()];
|
|
41965
|
-
}
|
|
41966
|
-
/**
|
|
41967
|
-
* Handle an incoming request from Service Worker
|
|
41968
|
-
*/
|
|
41969
|
-
async handleRequest(port, method, url2, headers, body) {
|
|
41970
|
-
const virtualServer = this.servers.get(port);
|
|
41971
|
-
if (!virtualServer) {
|
|
41972
|
-
return {
|
|
41973
|
-
statusCode: 503,
|
|
41974
|
-
statusMessage: "Service Unavailable",
|
|
41975
|
-
headers: { "Content-Type": "text/plain" },
|
|
41976
|
-
body: ownedBytes(Buffer$9.from(`No server listening on port ${port}`))
|
|
41977
|
-
};
|
|
41978
|
-
}
|
|
41979
|
-
try {
|
|
41980
|
-
const bodyBuffer = body ? Buffer$9.from(new Uint8Array(body)) : void 0;
|
|
41981
|
-
const named = Object.keys(headers).some((name) => name.toLowerCase() === "host");
|
|
41982
|
-
const authority = `${virtualServer.hostname && virtualServer.hostname !== "0.0.0.0" && virtualServer.hostname !== "::" ? virtualServer.hostname : "127.0.0.1"}:${port}`;
|
|
41983
|
-
const withHost = named ? headers : { ...headers, host: authority };
|
|
41984
|
-
if (virtualServer.server) return await virtualServer.server.handleRequest(method, url2, withHost, bodyBuffer);
|
|
41985
|
-
return await __requestOverLoopback(port, method, url2, withHost, bodyBuffer);
|
|
41986
|
-
} catch (error) {
|
|
41987
|
-
const message = error instanceof Error ? error.message : "Internal Server Error";
|
|
41988
|
-
return {
|
|
41989
|
-
statusCode: 500,
|
|
41990
|
-
statusMessage: "Internal Server Error",
|
|
41991
|
-
headers: { "Content-Type": "text/plain" },
|
|
41992
|
-
body: ownedBytes(Buffer$9.from(message))
|
|
41993
|
-
};
|
|
41994
|
-
}
|
|
41995
|
-
}
|
|
41996
|
-
/**
|
|
41997
|
-
* Initialize Service Worker communication
|
|
41998
|
-
* @param options - Configuration options for the service worker
|
|
41999
|
-
* @param options.swUrl - Custom URL path to the service worker file (default: '/__sw__.js')
|
|
42000
|
-
*/
|
|
42001
|
-
async initServiceWorker(options) {
|
|
42002
|
-
if (!("serviceWorker" in navigator)) {
|
|
42003
|
-
throw new Error("Service Workers not supported");
|
|
42004
|
-
}
|
|
42005
|
-
const swUrl = (options == null ? void 0 : options.swUrl) ?? "/__sw__.js";
|
|
42006
|
-
const controllerReady = navigator.serviceWorker.controller ? Promise.resolve() : new Promise((resolve2) => {
|
|
42007
|
-
navigator.serviceWorker.addEventListener("controllerchange", () => resolve2(), { once: true });
|
|
42008
|
-
});
|
|
42009
|
-
const registration = await navigator.serviceWorker.register(swUrl, {
|
|
42010
|
-
scope: "/"
|
|
42011
|
-
});
|
|
42012
|
-
const sw = registration.active || registration.waiting || registration.installing;
|
|
42013
|
-
if (!sw) {
|
|
42014
|
-
throw new Error("Service Worker registration failed");
|
|
42015
|
-
}
|
|
42016
|
-
await new Promise((resolve2) => {
|
|
42017
|
-
if (sw.state === "activated") {
|
|
42018
|
-
resolve2();
|
|
42019
|
-
} else {
|
|
42020
|
-
const handler = () => {
|
|
42021
|
-
if (sw.state === "activated") {
|
|
42022
|
-
sw.removeEventListener("statechange", handler);
|
|
42023
|
-
resolve2();
|
|
42024
|
-
}
|
|
42025
|
-
};
|
|
42026
|
-
sw.addEventListener("statechange", handler);
|
|
42027
|
-
}
|
|
42028
|
-
});
|
|
42029
|
-
this.messageChannel = new MessageChannel();
|
|
42030
|
-
this.messageChannel.port1.onmessage = this.handleServiceWorkerMessage.bind(this);
|
|
42031
|
-
this.ownDocuments = options == null ? void 0 : options.ownDocuments;
|
|
42032
|
-
sw.postMessage({ type: "init", port: this.messageChannel.port2, data: { ownDocuments: this.ownDocuments ?? [] } }, [
|
|
42033
|
-
this.messageChannel.port2
|
|
42034
|
-
]);
|
|
42035
|
-
await controllerReady;
|
|
42036
|
-
const reinit = () => {
|
|
42037
|
-
if (navigator.serviceWorker.controller) {
|
|
42038
|
-
for (const stream of [...this.controlledStreams.values()]) stream.cancel();
|
|
42039
|
-
this.messageChannel = new MessageChannel();
|
|
42040
|
-
this.messageChannel.port1.onmessage = this.handleServiceWorkerMessage.bind(this);
|
|
42041
|
-
navigator.serviceWorker.controller.postMessage(
|
|
42042
|
-
{ type: "init", port: this.messageChannel.port2, data: { ownDocuments: this.ownDocuments ?? [] } },
|
|
42043
|
-
[this.messageChannel.port2]
|
|
42044
|
-
);
|
|
42045
|
-
this.announceServers();
|
|
42046
|
-
}
|
|
42047
|
-
};
|
|
42048
|
-
navigator.serviceWorker.addEventListener("controllerchange", reinit);
|
|
42049
|
-
navigator.serviceWorker.addEventListener("message", (event) => {
|
|
42050
|
-
var _a2;
|
|
42051
|
-
if (((_a2 = event.data) == null ? void 0 : _a2.type) === "sw-needs-init") {
|
|
42052
|
-
reinit();
|
|
42053
|
-
}
|
|
42054
|
-
});
|
|
42055
|
-
this.keepaliveInterval = setInterval(() => {
|
|
42056
|
-
var _a2;
|
|
42057
|
-
(_a2 = this.messageChannel) == null ? void 0 : _a2.port1.postMessage({ type: "keepalive" });
|
|
42058
|
-
}, 2e4);
|
|
42059
|
-
this.serviceWorkerReady = true;
|
|
42060
|
-
this.announceServers();
|
|
42061
|
-
this.emit("sw-ready");
|
|
42062
|
-
}
|
|
42063
|
-
/**
|
|
42064
|
-
* Handle messages from Service Worker
|
|
42065
|
-
*/
|
|
42066
|
-
async handleServiceWorkerMessage(event) {
|
|
42067
|
-
var _a2, _b2, _c2;
|
|
42068
|
-
const { type: type2, id, data: data2 } = event.data;
|
|
42069
|
-
_ServerBridge.DEBUG && console.log("[ServerBridge] SW message:", type2, id, data2 == null ? void 0 : data2.url);
|
|
42070
|
-
if (type2 === "stream-pull" || type2 === "stream-cancel") {
|
|
42071
|
-
const stream = this.controlledStreams.get(id);
|
|
42072
|
-
if (type2 === "stream-pull") stream == null ? void 0 : stream.pull();
|
|
42073
|
-
else stream == null ? void 0 : stream.cancel();
|
|
42074
|
-
return;
|
|
42075
|
-
}
|
|
42076
|
-
if (type2 === "request" && (data2 == null ? void 0 : data2.flowControl) === 1) {
|
|
42077
|
-
const { port, method, url: url2, headers, body } = data2;
|
|
42078
|
-
await this.controlledStream(id, port, method, url2, headers, body);
|
|
42079
|
-
return;
|
|
42080
|
-
}
|
|
42081
|
-
if (type2 === "request") {
|
|
42082
|
-
const { port, method, url: url2, headers, body, streaming } = data2;
|
|
42083
|
-
_ServerBridge.DEBUG && console.log("[ServerBridge] Handling request:", port, method, url2, "streaming:", streaming);
|
|
42084
|
-
if (streaming) {
|
|
42085
|
-
_ServerBridge.DEBUG && console.log("[ServerBridge] 🔴 Will use streaming handler");
|
|
42086
|
-
}
|
|
42087
|
-
try {
|
|
42088
|
-
if (streaming) {
|
|
42089
|
-
await this.streamToServiceWorker(id, port, method, url2, headers, body);
|
|
42090
|
-
} else {
|
|
42091
|
-
const response = await this.handleRequest(port, method, url2, headers, body);
|
|
42092
|
-
_ServerBridge.DEBUG && console.log("[ServerBridge] Response:", response.statusCode, "body length:", (_a2 = response.body) == null ? void 0 : _a2.length);
|
|
42093
|
-
let bodyBase64 = "";
|
|
42094
|
-
if (response.body && response.body.length > 0) {
|
|
42095
|
-
const bytes2 = response.body instanceof Uint8Array ? response.body : new Uint8Array(0);
|
|
42096
|
-
bodyBase64 = uint8ToBase64(bytes2);
|
|
42097
|
-
}
|
|
42098
|
-
_ServerBridge.DEBUG && console.log("[ServerBridge] Sending response to SW, body base64 length:", bodyBase64.length);
|
|
42099
|
-
(_b2 = this.messageChannel) == null ? void 0 : _b2.port1.postMessage({
|
|
42100
|
-
type: "response",
|
|
42101
|
-
id,
|
|
42102
|
-
data: {
|
|
42103
|
-
statusCode: response.statusCode,
|
|
42104
|
-
statusMessage: response.statusMessage,
|
|
42105
|
-
headers: response.headers,
|
|
42106
|
-
bodyBase64
|
|
42107
|
-
}
|
|
42108
|
-
});
|
|
42109
|
-
}
|
|
42110
|
-
} catch (error) {
|
|
42111
|
-
(_c2 = this.messageChannel) == null ? void 0 : _c2.port1.postMessage({
|
|
42112
|
-
type: "response",
|
|
42113
|
-
id,
|
|
42114
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
42115
|
-
});
|
|
42116
|
-
}
|
|
42117
|
-
}
|
|
42118
|
-
}
|
|
42119
|
-
/**
|
|
42120
|
-
* Handle a streaming request - sends chunks as they arrive
|
|
42121
|
-
*/
|
|
42122
|
-
/**
|
|
42123
|
-
* A page-side request streamed to the caller as it arrives, the door a host
|
|
42124
|
-
* reads a guest's server through when it wants chunks rather than a body:
|
|
42125
|
-
* a guest's own server is reached over the loopback as any client reaches
|
|
42126
|
-
* it; a server the host registered answers through its own streaming
|
|
42127
|
-
* method where it has one, else its buffered answer is delivered whole.
|
|
42128
|
-
*/
|
|
42129
|
-
async handleStreamingRequest(port, method, url2, headers, body, callbacks, flow) {
|
|
42130
|
-
const virtualServer = this.servers.get(port);
|
|
42131
|
-
if (!virtualServer) return false;
|
|
42132
|
-
const bodyBuffer = body ? Buffer$9.from(new Uint8Array(body)) : void 0;
|
|
42133
|
-
if (virtualServer.server === null || this.guestServers.has(virtualServer.server)) {
|
|
42134
|
-
const named = Object.keys(headers).some((name) => name.toLowerCase() === "host");
|
|
42135
|
-
const authority = `${virtualServer.hostname && virtualServer.hostname !== "0.0.0.0" && virtualServer.hostname !== "::" ? virtualServer.hostname : "127.0.0.1"}:${port}`;
|
|
42136
|
-
await __streamOverLoopback(
|
|
42137
|
-
port,
|
|
42138
|
-
method,
|
|
42139
|
-
url2,
|
|
42140
|
-
named ? headers : { ...headers, host: authority },
|
|
42141
|
-
bodyBuffer,
|
|
42142
|
-
(statusCode, statusMessage, respHeaders) => callbacks.start(statusCode, statusMessage, respHeaders),
|
|
42143
|
-
(chunk) => callbacks.chunk(ownedBytes(chunk)),
|
|
42144
|
-
() => callbacks.end(),
|
|
42145
|
-
flow
|
|
42146
|
-
);
|
|
42147
|
-
return true;
|
|
42148
|
-
}
|
|
42149
|
-
const server = virtualServer.server;
|
|
42150
|
-
if (typeof server.handleStreamingRequest === "function") {
|
|
42151
|
-
await server.handleStreamingRequest(
|
|
42152
|
-
method,
|
|
42153
|
-
url2,
|
|
42154
|
-
headers,
|
|
42155
|
-
bodyBuffer,
|
|
42156
|
-
(statusCode, statusMessage, respHeaders) => callbacks.start(statusCode, statusMessage, respHeaders),
|
|
42157
|
-
(chunk) => callbacks.chunk(typeof chunk === "string" ? _encoder.encode(chunk) : ownedBytes(chunk)),
|
|
42158
|
-
() => callbacks.end(),
|
|
42159
|
-
flow
|
|
42160
|
-
);
|
|
42161
|
-
return true;
|
|
42162
|
-
}
|
|
42163
|
-
const response = await this.handleRequest(port, method, url2, headers, body);
|
|
42164
|
-
callbacks.start(response.statusCode, response.statusMessage ?? "", response.headers);
|
|
42165
|
-
if (response.body) {
|
|
42166
|
-
const body2 = typeof response.body === "string" ? _encoder.encode(response.body) : response.body;
|
|
42167
|
-
callbacks.chunk(ownedBytes(body2));
|
|
42168
|
-
}
|
|
42169
|
-
callbacks.end();
|
|
42170
|
-
return true;
|
|
42071
|
+
super.close();
|
|
42171
42072
|
}
|
|
42172
|
-
|
|
42173
|
-
|
|
42174
|
-
|
|
42175
|
-
if (!virtualServer) {
|
|
42176
|
-
(_a2 = this.messageChannel) == null ? void 0 : _a2.port1.postMessage({
|
|
42177
|
-
type: "stream-start",
|
|
42178
|
-
id,
|
|
42179
|
-
data: { statusCode: 503, statusMessage: "Service Unavailable", headers: {} }
|
|
42180
|
-
});
|
|
42181
|
-
(_b2 = this.messageChannel) == null ? void 0 : _b2.port1.postMessage({ type: "stream-end", id });
|
|
42182
|
-
return;
|
|
42183
|
-
}
|
|
42184
|
-
if (virtualServer.server === null || this.guestServers.has(virtualServer.server)) {
|
|
42185
|
-
const bodyBuffer = body ? Buffer$9.from(new Uint8Array(body)) : void 0;
|
|
42186
|
-
const named = Object.keys(headers).some((name) => name.toLowerCase() === "host");
|
|
42187
|
-
const authority = `${virtualServer.hostname && virtualServer.hostname !== "0.0.0.0" && virtualServer.hostname !== "::" ? virtualServer.hostname : "127.0.0.1"}:${port}`;
|
|
42188
|
-
await __streamOverLoopback(
|
|
42189
|
-
port,
|
|
42190
|
-
method,
|
|
42191
|
-
url2,
|
|
42192
|
-
named ? headers : { ...headers, host: authority },
|
|
42193
|
-
bodyBuffer,
|
|
42194
|
-
(statusCode, statusMessage, respHeaders) => {
|
|
42195
|
-
var _a3;
|
|
42196
|
-
(_a3 = this.messageChannel) == null ? void 0 : _a3.port1.postMessage({ type: "stream-start", id, data: { statusCode, statusMessage, headers: respHeaders } });
|
|
42197
|
-
},
|
|
42198
|
-
(chunk) => {
|
|
42199
|
-
var _a3;
|
|
42200
|
-
const copy2 = ownedBytes(chunk);
|
|
42201
|
-
(_a3 = this.messageChannel) == null ? void 0 : _a3.port1.postMessage({ type: "stream-chunk", id, data: copy2.buffer }, [copy2.buffer]);
|
|
42202
|
-
},
|
|
42203
|
-
() => {
|
|
42204
|
-
var _a3;
|
|
42205
|
-
(_a3 = this.messageChannel) == null ? void 0 : _a3.port1.postMessage({ type: "stream-end", id });
|
|
42206
|
-
}
|
|
42207
|
-
);
|
|
42208
|
-
return;
|
|
42209
|
-
}
|
|
42210
|
-
const server = virtualServer.server;
|
|
42211
|
-
if (typeof server.handleStreamingRequest === "function") {
|
|
42212
|
-
_ServerBridge.DEBUG && console.log("[ServerBridge] 🟢 Server has streaming support, calling handleStreamingRequest");
|
|
42213
|
-
const bodyBuffer = body ? Buffer$9.from(new Uint8Array(body)) : void 0;
|
|
42214
|
-
await server.handleStreamingRequest(
|
|
42215
|
-
method,
|
|
42216
|
-
url2,
|
|
42217
|
-
headers,
|
|
42218
|
-
bodyBuffer,
|
|
42219
|
-
// onStart - called with headers
|
|
42220
|
-
(statusCode, statusMessage, respHeaders) => {
|
|
42221
|
-
var _a3;
|
|
42222
|
-
_ServerBridge.DEBUG && console.log("[ServerBridge] 🟢 onStart called, sending stream-start");
|
|
42223
|
-
(_a3 = this.messageChannel) == null ? void 0 : _a3.port1.postMessage({
|
|
42224
|
-
type: "stream-start",
|
|
42225
|
-
id,
|
|
42226
|
-
data: { statusCode, statusMessage, headers: respHeaders }
|
|
42227
|
-
});
|
|
42228
|
-
},
|
|
42229
|
-
// onChunk - called for each chunk
|
|
42230
|
-
(chunk) => {
|
|
42231
|
-
var _a3;
|
|
42232
|
-
const bytes2 = typeof chunk === "string" ? _encoder.encode(chunk) : chunk;
|
|
42233
|
-
const chunkBase64 = uint8ToBase64(bytes2);
|
|
42234
|
-
_ServerBridge.DEBUG && console.log("[ServerBridge] 🟡 onChunk called, sending stream-chunk, size:", chunkBase64.length);
|
|
42235
|
-
(_a3 = this.messageChannel) == null ? void 0 : _a3.port1.postMessage({
|
|
42236
|
-
type: "stream-chunk",
|
|
42237
|
-
id,
|
|
42238
|
-
data: { chunkBase64 }
|
|
42239
|
-
});
|
|
42240
|
-
},
|
|
42241
|
-
// onEnd - called when response is complete
|
|
42242
|
-
() => {
|
|
42243
|
-
var _a3;
|
|
42244
|
-
_ServerBridge.DEBUG && console.log("[ServerBridge] 🟢 onEnd called, sending stream-end");
|
|
42245
|
-
(_a3 = this.messageChannel) == null ? void 0 : _a3.port1.postMessage({ type: "stream-end", id });
|
|
42246
|
-
}
|
|
42247
|
-
);
|
|
42248
|
-
} else {
|
|
42249
|
-
const bodyBuffer = body ? Buffer$9.from(new Uint8Array(body)) : void 0;
|
|
42250
|
-
const response = await virtualServer.server.handleRequest(method, url2, headers, bodyBuffer);
|
|
42251
|
-
(_c2 = this.messageChannel) == null ? void 0 : _c2.port1.postMessage({
|
|
42252
|
-
type: "stream-start",
|
|
42253
|
-
id,
|
|
42254
|
-
data: {
|
|
42255
|
-
statusCode: response.statusCode,
|
|
42256
|
-
statusMessage: response.statusMessage,
|
|
42257
|
-
headers: response.headers
|
|
42258
|
-
}
|
|
42259
|
-
});
|
|
42260
|
-
if (response.body && response.body.length > 0) {
|
|
42261
|
-
const bytes2 = response.body instanceof Uint8Array ? response.body : new Uint8Array(0);
|
|
42262
|
-
(_d2 = this.messageChannel) == null ? void 0 : _d2.port1.postMessage({
|
|
42263
|
-
type: "stream-chunk",
|
|
42264
|
-
id,
|
|
42265
|
-
data: { chunkBase64: uint8ToBase64(bytes2) }
|
|
42266
|
-
});
|
|
42267
|
-
}
|
|
42268
|
-
(_e2 = this.messageChannel) == null ? void 0 : _e2.port1.postMessage({ type: "stream-end", id });
|
|
42269
|
-
}
|
|
42073
|
+
/** A guest's listener (the old null sentinel, now a request adapter) is answered over the loopback. */
|
|
42074
|
+
isGuest(entry) {
|
|
42075
|
+
return entry.server === null || this.guestServers.has(entry.server);
|
|
42270
42076
|
}
|
|
42271
|
-
|
|
42272
|
-
|
|
42273
|
-
*/
|
|
42274
|
-
notifyServiceWorker(type2, data2) {
|
|
42275
|
-
if (this.serviceWorkerReady && this.messageChannel) {
|
|
42276
|
-
const flow = type2 === "server-registered" ? { flowControl: 1, maxRequestBytes: FLOW_MAX_REQUEST_BYTES, maxChunkBytes: FLOW_MAX_CHUNK_BYTES } : {};
|
|
42277
|
-
this.messageChannel.port1.postMessage({ type: type2, data: { ...data2, ...flow } });
|
|
42278
|
-
}
|
|
42077
|
+
requestGuest(port, method, url2, headers, body) {
|
|
42078
|
+
return __requestOverLoopback(port, method, url2, headers, body);
|
|
42279
42079
|
}
|
|
42280
|
-
|
|
42281
|
-
|
|
42282
|
-
* its head, then goes one chunk (at most FLOW_MAX_CHUNK_BYTES) for each
|
|
42283
|
-
* `stream-pull`, and ends with `stream-end` once the server finished and
|
|
42284
|
-
* every chunk went out. The upstream connection is paused while chunks wait
|
|
42285
|
-
* for credit, so a slow reader holds the server back; `stream-cancel` ends it.
|
|
42286
|
-
*/
|
|
42287
|
-
async controlledStream(id, port, method, url2, headers, body) {
|
|
42288
|
-
const channel = this.messageChannel;
|
|
42289
|
-
const post = (type2, data2) => {
|
|
42290
|
-
channel == null ? void 0 : channel.port1.postMessage({ type: type2, id, ...data2 === void 0 ? {} : { data: data2 } });
|
|
42291
|
-
};
|
|
42292
|
-
const queue = [];
|
|
42293
|
-
const abort = new AbortController();
|
|
42294
|
-
let credits = 0;
|
|
42295
|
-
let upstreamEnded = false;
|
|
42296
|
-
let finished = false;
|
|
42297
|
-
let paused = false;
|
|
42298
|
-
let pause = () => void 0;
|
|
42299
|
-
let resume = () => void 0;
|
|
42300
|
-
const finish = () => {
|
|
42301
|
-
finished = true;
|
|
42302
|
-
this.controlledStreams.delete(id);
|
|
42303
|
-
};
|
|
42304
|
-
const flush2 = () => {
|
|
42305
|
-
if (finished) return;
|
|
42306
|
-
while (credits > 0 && queue.length > 0) {
|
|
42307
|
-
credits -= 1;
|
|
42308
|
-
post("stream-chunk", { chunkBase64: uint8ToBase64(queue.shift()) });
|
|
42309
|
-
}
|
|
42310
|
-
if (upstreamEnded && queue.length === 0) {
|
|
42311
|
-
post("stream-end");
|
|
42312
|
-
finish();
|
|
42313
|
-
return;
|
|
42314
|
-
}
|
|
42315
|
-
if (queue.length >= FLOW_QUEUED_CHUNKS && !paused) {
|
|
42316
|
-
paused = true;
|
|
42317
|
-
pause();
|
|
42318
|
-
} else if (queue.length < FLOW_QUEUED_CHUNKS && paused) {
|
|
42319
|
-
paused = false;
|
|
42320
|
-
resume();
|
|
42321
|
-
}
|
|
42322
|
-
};
|
|
42323
|
-
this.controlledStreams.set(id, {
|
|
42324
|
-
pull: () => {
|
|
42325
|
-
credits += 1;
|
|
42326
|
-
flush2();
|
|
42327
|
-
},
|
|
42328
|
-
cancel: () => {
|
|
42329
|
-
if (finished) return;
|
|
42330
|
-
finish();
|
|
42331
|
-
queue.length = 0;
|
|
42332
|
-
abort.abort();
|
|
42333
|
-
}
|
|
42334
|
-
});
|
|
42335
|
-
try {
|
|
42336
|
-
const answered = await this.handleStreamingRequest(port, method, url2, headers, body, {
|
|
42337
|
-
start: (statusCode, statusMessage, respHeaders) => post("stream-start", { statusCode, statusMessage, headers: respHeaders }),
|
|
42338
|
-
chunk: (chunk) => {
|
|
42339
|
-
if (finished) return;
|
|
42340
|
-
for (let at2 = 0; at2 < chunk.byteLength; at2 += FLOW_MAX_CHUNK_BYTES) queue.push(chunk.slice(at2, at2 + FLOW_MAX_CHUNK_BYTES));
|
|
42341
|
-
flush2();
|
|
42342
|
-
},
|
|
42343
|
-
end: () => {
|
|
42344
|
-
upstreamEnded = true;
|
|
42345
|
-
flush2();
|
|
42346
|
-
}
|
|
42347
|
-
}, { signal: abort.signal, control: (p, r) => {
|
|
42348
|
-
pause = p;
|
|
42349
|
-
resume = r;
|
|
42350
|
-
} });
|
|
42351
|
-
if (!answered) {
|
|
42352
|
-
post("stream-start", { statusCode: 503, statusMessage: "Service Unavailable", headers: {} });
|
|
42353
|
-
post("stream-end");
|
|
42354
|
-
finish();
|
|
42355
|
-
}
|
|
42356
|
-
} catch (error) {
|
|
42357
|
-
if (!finished) {
|
|
42358
|
-
post("stream-error", { message: error instanceof Error ? error.message : String(error) });
|
|
42359
|
-
finish();
|
|
42360
|
-
}
|
|
42361
|
-
}
|
|
42080
|
+
streamGuest(port, method, url2, headers, body, onStart, onChunk, onEnd, flow) {
|
|
42081
|
+
return __streamOverLoopback(port, method, url2, headers, body, onStart, onChunk, onEnd, flow);
|
|
42362
42082
|
}
|
|
42363
|
-
/**
|
|
42364
|
-
|
|
42365
|
-
|
|
42366
|
-
createFetchHandler() {
|
|
42367
|
-
return async (request) => {
|
|
42368
|
-
const url2 = new URL(request.url);
|
|
42369
|
-
const match = url2.pathname.match(/^\/__virtual__\/(\d+)(\/.*)?$/);
|
|
42370
|
-
if (!match) {
|
|
42371
|
-
throw new Error("Not a virtual server request");
|
|
42372
|
-
}
|
|
42373
|
-
const port = parseInt(match[1], 10);
|
|
42374
|
-
const path2 = match[2] || "/";
|
|
42375
|
-
const headers = {};
|
|
42376
|
-
request.headers.forEach((value, key) => {
|
|
42377
|
-
headers[key] = value;
|
|
42378
|
-
});
|
|
42379
|
-
let body;
|
|
42380
|
-
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
42381
|
-
body = await request.arrayBuffer();
|
|
42382
|
-
}
|
|
42383
|
-
const response = await this.handleRequest(
|
|
42384
|
-
port,
|
|
42385
|
-
request.method,
|
|
42386
|
-
path2 + url2.search,
|
|
42387
|
-
headers,
|
|
42388
|
-
body
|
|
42389
|
-
);
|
|
42390
|
-
const answerHeaders = new Headers();
|
|
42391
|
-
for (const [name, value] of Object.entries(response.headers)) {
|
|
42392
|
-
for (const each of Array.isArray(value) ? value : [value]) answerHeaders.append(name, each);
|
|
42393
|
-
}
|
|
42394
|
-
return new Response(response.body, {
|
|
42395
|
-
status: response.statusCode,
|
|
42396
|
-
statusText: response.statusMessage ?? "",
|
|
42397
|
-
headers: answerHeaders
|
|
42398
|
-
});
|
|
42399
|
-
};
|
|
42083
|
+
/** A server of this engine reads a request's body as Node's Buffer. */
|
|
42084
|
+
bodyOf(bytes2) {
|
|
42085
|
+
return Buffer$9.from(bytes2);
|
|
42400
42086
|
}
|
|
42401
|
-
}
|
|
42402
|
-
__publicField(_ServerBridge, "DEBUG", false);
|
|
42403
|
-
let ServerBridge = _ServerBridge;
|
|
42087
|
+
}
|
|
42404
42088
|
let globalBridge = null;
|
|
42405
42089
|
function getServerBridge(options) {
|
|
42406
42090
|
if (!globalBridge) {
|
|
@@ -42842,7 +42526,9 @@ function createContainer(options) {
|
|
|
42842
42526
|
}
|
|
42843
42527
|
export {
|
|
42844
42528
|
NativeStreamScope,
|
|
42529
|
+
PREPARED_MODULES_DIR,
|
|
42845
42530
|
PackageManager,
|
|
42531
|
+
PortBridge,
|
|
42846
42532
|
Runtime,
|
|
42847
42533
|
ServerBridge,
|
|
42848
42534
|
VirtualFS,
|
|
@@ -42858,6 +42544,7 @@ export {
|
|
|
42858
42544
|
esbuildShim as esbuild,
|
|
42859
42545
|
eventsModule as events,
|
|
42860
42546
|
execute,
|
|
42547
|
+
g as getPortBridge,
|
|
42861
42548
|
getServerBridge,
|
|
42862
42549
|
guestRealmInstalled,
|
|
42863
42550
|
httpModule as http,
|
|
@@ -42877,6 +42564,8 @@ export {
|
|
|
42877
42564
|
ownerProcessTable,
|
|
42878
42565
|
path,
|
|
42879
42566
|
perfHooksShim as perf_hooks,
|
|
42567
|
+
prepareModuleForImage,
|
|
42568
|
+
preparedModuleKey,
|
|
42880
42569
|
processByPid,
|
|
42881
42570
|
requestHasStaticBody,
|
|
42882
42571
|
resetServerBridge,
|