Release rolling / release (push) Successful in 11m16s
Bump published pins (compact-encoding 3, bare-fetch/tls/https/ws 3, bare-subprocess 6, bare-signals 5, corestore 7.12, protomux 3.11, hypercore-crypto 3.7, bare-runtime 1.31) and regenerate catalogs, manifests, and kernel/seeder bundles. Adapt call sites to the new APIs: - Corestore: explicit session flush before suspend(); treeCache ctor opts - bare-crypto: KeyObject.export() instead of removed ._key - Protomux 3.11: wait for fullyOpened()/fullyClosed() on chat channels - bare-fetch: surface response.type and Headers.getSetCookie - host snapshots: bare-os 3.9 / bare-posix / bare-fs.statfs frsize - bare-subprocess 6: optional IPC channel + json serialization Keep catalog sync from wiping curated pearEntries. Teach the Node test shim to stub bare-thread/bare-worker (ESM absolute paths) and chain Bare.on so bare-timers can load. Booter 479, protocol 34, seeder 14.
10911 lines
388 KiB
JavaScript
10911 lines
388 KiB
JavaScript
var __bare_os_bundle_exports__ = (() => {
|
|
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
}) : x)(function(x) {
|
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
});
|
|
var __commonJS = (cb, mod) => function __require2() {
|
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
};
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
// file that has been converted to a CommonJS file using a Babel-
|
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
mod
|
|
));
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// ../../node_modules/bare-path/binding.js
|
|
var require_binding = __commonJS({
|
|
"../../node_modules/bare-path/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-path/lib/constants.js
|
|
var require_constants = __commonJS({
|
|
"../../node_modules/bare-path/lib/constants.js"(exports, module) {
|
|
module.exports = {
|
|
CHAR_UPPERCASE_A: 65,
|
|
CHAR_LOWERCASE_A: 97,
|
|
CHAR_UPPERCASE_Z: 90,
|
|
CHAR_LOWERCASE_Z: 122,
|
|
CHAR_DOT: 46,
|
|
CHAR_FORWARD_SLASH: 47,
|
|
CHAR_BACKWARD_SLASH: 92,
|
|
CHAR_COLON: 58,
|
|
CHAR_QUESTION_MARK: 63
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-path/lib/shared.js
|
|
var require_shared = __commonJS({
|
|
"../../node_modules/bare-path/lib/shared.js"(exports) {
|
|
var { CHAR_DOT, CHAR_FORWARD_SLASH } = require_constants();
|
|
exports.validateString = function validateString(value, name) {
|
|
if (typeof value !== "string") {
|
|
throw new TypeError(
|
|
`The "${name}" argument must be of type string. Received type ${typeof value}`
|
|
);
|
|
}
|
|
};
|
|
exports.normalizeString = function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
|
|
let res = "";
|
|
let lastSegmentLength = 0;
|
|
let lastSlash = -1;
|
|
let dots = 0;
|
|
let code = 0;
|
|
for (let i = 0; i <= path.length; ++i) {
|
|
if (i < path.length) {
|
|
code = path.charCodeAt(i);
|
|
} else if (isPathSeparator(code)) {
|
|
break;
|
|
} else {
|
|
code = CHAR_FORWARD_SLASH;
|
|
}
|
|
if (isPathSeparator(code)) {
|
|
if (lastSlash === i - 1 || dots === 1) ;
|
|
else if (dots === 2) {
|
|
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== CHAR_DOT || res.charCodeAt(res.length - 2) !== CHAR_DOT) {
|
|
if (res.length > 2) {
|
|
const lastSlashIndex = res.lastIndexOf(separator);
|
|
if (lastSlashIndex === -1) {
|
|
res = "";
|
|
lastSegmentLength = 0;
|
|
} else {
|
|
res = res.substring(0, lastSlashIndex);
|
|
lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
|
|
}
|
|
lastSlash = i;
|
|
dots = 0;
|
|
continue;
|
|
} else if (res.length !== 0) {
|
|
res = "";
|
|
lastSegmentLength = 0;
|
|
lastSlash = i;
|
|
dots = 0;
|
|
continue;
|
|
}
|
|
}
|
|
if (allowAboveRoot) {
|
|
res += res.length > 0 ? `${separator}..` : "..";
|
|
lastSegmentLength = 2;
|
|
}
|
|
} else {
|
|
if (res.length > 0) {
|
|
res += `${separator}${path.substring(lastSlash + 1, i)}`;
|
|
} else {
|
|
res = path.substring(lastSlash + 1, i);
|
|
}
|
|
lastSegmentLength = i - lastSlash - 1;
|
|
}
|
|
lastSlash = i;
|
|
dots = 0;
|
|
} else if (code === CHAR_DOT && dots !== -1) {
|
|
++dots;
|
|
} else {
|
|
dots = -1;
|
|
}
|
|
}
|
|
return res;
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-path/lib/posix.js
|
|
var require_posix = __commonJS({
|
|
"../../node_modules/bare-path/lib/posix.js"(exports) {
|
|
var binding = require_binding();
|
|
var { normalizeString, validateString } = require_shared();
|
|
var { CHAR_DOT, CHAR_FORWARD_SLASH } = require_constants();
|
|
function isPosixPathSeparator(code) {
|
|
return code === CHAR_FORWARD_SLASH;
|
|
}
|
|
exports.win32 = require_win32();
|
|
exports.posix = exports;
|
|
exports.sep = "/";
|
|
exports.delimiter = ":";
|
|
exports.resolve = function resolve(...args) {
|
|
let resolvedPath = "";
|
|
let resolvedAbsolute = false;
|
|
for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
const path = i >= 0 ? args[i] : binding.cwd();
|
|
if (i >= 0) validateString(path, `paths[${i}]`);
|
|
if (path.length === 0) {
|
|
continue;
|
|
}
|
|
resolvedPath = `${path}/${resolvedPath}`;
|
|
resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
}
|
|
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, "/", isPosixPathSeparator);
|
|
if (resolvedAbsolute) {
|
|
return `/${resolvedPath}`;
|
|
}
|
|
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
};
|
|
exports.normalize = function normalize(path) {
|
|
validateString(path, "path");
|
|
if (path.length === 0) return ".";
|
|
const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
const trailingSeparator = path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH;
|
|
path = normalizeString(path, !isAbsolute, "/", isPosixPathSeparator);
|
|
if (path.length === 0) {
|
|
if (isAbsolute) return "/";
|
|
return trailingSeparator ? "./" : ".";
|
|
}
|
|
if (trailingSeparator) path += "/";
|
|
return isAbsolute ? `/${path}` : path;
|
|
};
|
|
exports.isAbsolute = function isAbsolute(path) {
|
|
validateString(path, "path");
|
|
return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
};
|
|
exports.join = function join(...args) {
|
|
if (args.length === 0) return ".";
|
|
let joined;
|
|
for (let i = 0; i < args.length; ++i) {
|
|
const arg = args[i];
|
|
validateString(arg, "path");
|
|
if (arg.length > 0) {
|
|
if (joined === void 0) joined = arg;
|
|
else joined += `/${arg}`;
|
|
}
|
|
}
|
|
if (joined === void 0) return ".";
|
|
return exports.normalize(joined);
|
|
};
|
|
exports.relative = function relative(from, to) {
|
|
validateString(from, "from");
|
|
validateString(to, "to");
|
|
if (from === to) return "";
|
|
from = exports.resolve(from);
|
|
to = exports.resolve(to);
|
|
if (from === to) return "";
|
|
const fromStart = 1;
|
|
const fromEnd = from.length;
|
|
const fromLen = fromEnd - fromStart;
|
|
const toStart = 1;
|
|
const toLen = to.length - toStart;
|
|
const length = fromLen < toLen ? fromLen : toLen;
|
|
let lastCommonSep = -1;
|
|
let i = 0;
|
|
for (; i < length; i++) {
|
|
const fromCode = from.charCodeAt(fromStart + i);
|
|
if (fromCode !== to.charCodeAt(toStart + i)) {
|
|
break;
|
|
} else if (fromCode === CHAR_FORWARD_SLASH) {
|
|
lastCommonSep = i;
|
|
}
|
|
}
|
|
if (i === length) {
|
|
if (toLen > length) {
|
|
if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
|
|
return to.substring(toStart + i + 1);
|
|
}
|
|
if (i === 0) {
|
|
return to.substring(toStart + i);
|
|
}
|
|
} else if (fromLen > length) {
|
|
if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
|
|
lastCommonSep = i;
|
|
} else if (i === 0) {
|
|
lastCommonSep = 0;
|
|
}
|
|
}
|
|
}
|
|
let out = "";
|
|
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
|
|
out += out.length === 0 ? ".." : "/..";
|
|
}
|
|
}
|
|
return `${out}${to.substring(toStart + lastCommonSep)}`;
|
|
};
|
|
exports.toNamespacedPath = function toNamespacedPath(path) {
|
|
return path;
|
|
};
|
|
exports.dirname = function dirname(path) {
|
|
validateString(path, "path");
|
|
if (path.length === 0) return ".";
|
|
const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
let end = -1;
|
|
let matchedSlash = true;
|
|
for (let i = path.length - 1; i >= 1; --i) {
|
|
if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
|
|
if (!matchedSlash) {
|
|
end = i;
|
|
break;
|
|
}
|
|
} else {
|
|
matchedSlash = false;
|
|
}
|
|
}
|
|
if (end === -1) return hasRoot ? "/" : ".";
|
|
if (hasRoot && end === 1) return "//";
|
|
return path.substring(0, end);
|
|
};
|
|
exports.basename = function basename(path, suffix) {
|
|
if (suffix !== void 0) validateString(suffix, "suffix");
|
|
validateString(path, "path");
|
|
let start = 0;
|
|
let end = -1;
|
|
let matchedSlash = true;
|
|
if (suffix !== void 0 && suffix.length > 0 && suffix.length <= path.length) {
|
|
if (suffix === path) {
|
|
return "";
|
|
}
|
|
let extIdx = suffix.length - 1;
|
|
let firstNonSlashEnd = -1;
|
|
for (let i = path.length - 1; i >= 0; --i) {
|
|
const code = path.charCodeAt(i);
|
|
if (code === CHAR_FORWARD_SLASH) {
|
|
if (!matchedSlash) {
|
|
start = i + 1;
|
|
break;
|
|
}
|
|
} else {
|
|
if (firstNonSlashEnd === -1) {
|
|
matchedSlash = false;
|
|
firstNonSlashEnd = i + 1;
|
|
}
|
|
if (extIdx >= 0) {
|
|
if (code === suffix.charCodeAt(extIdx)) {
|
|
if (--extIdx === -1) {
|
|
end = i;
|
|
}
|
|
} else {
|
|
extIdx = -1;
|
|
end = firstNonSlashEnd;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (start === end) end = firstNonSlashEnd;
|
|
else if (end === -1) end = path.length;
|
|
return path.substring(start, end);
|
|
}
|
|
for (let i = path.length - 1; i >= 0; --i) {
|
|
if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
|
|
if (!matchedSlash) {
|
|
start = i + 1;
|
|
break;
|
|
}
|
|
} else if (end === -1) {
|
|
matchedSlash = false;
|
|
end = i + 1;
|
|
}
|
|
}
|
|
if (end === -1) return "";
|
|
return path.substring(start, end);
|
|
};
|
|
exports.extname = function extname(path) {
|
|
validateString(path, "path");
|
|
let startDot = -1;
|
|
let startPart = 0;
|
|
let end = -1;
|
|
let matchedSlash = true;
|
|
let preDotState = 0;
|
|
for (let i = path.length - 1; i >= 0; --i) {
|
|
const code = path.charCodeAt(i);
|
|
if (code === CHAR_FORWARD_SLASH) {
|
|
if (!matchedSlash) {
|
|
startPart = i + 1;
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
if (end === -1) {
|
|
matchedSlash = false;
|
|
end = i + 1;
|
|
}
|
|
if (code === CHAR_DOT) {
|
|
if (startDot === -1) startDot = i;
|
|
else if (preDotState !== 1) preDotState = 1;
|
|
} else if (startDot !== -1) {
|
|
preDotState = -1;
|
|
}
|
|
}
|
|
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
return "";
|
|
}
|
|
return path.substring(startDot, end);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-path/lib/win32.js
|
|
var require_win32 = __commonJS({
|
|
"../../node_modules/bare-path/lib/win32.js"(exports) {
|
|
var binding = require_binding();
|
|
var { normalizeString, validateString } = require_shared();
|
|
var {
|
|
CHAR_UPPERCASE_A,
|
|
CHAR_LOWERCASE_A,
|
|
CHAR_UPPERCASE_Z,
|
|
CHAR_LOWERCASE_Z,
|
|
CHAR_DOT,
|
|
CHAR_FORWARD_SLASH,
|
|
CHAR_BACKWARD_SLASH,
|
|
CHAR_COLON,
|
|
CHAR_QUESTION_MARK
|
|
} = require_constants();
|
|
function isWindowsPathSeparator(code) {
|
|
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
}
|
|
function isWindowsDeviceRoot(code) {
|
|
return code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z || code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z;
|
|
}
|
|
exports.posix = require_posix();
|
|
exports.win32 = exports;
|
|
exports.sep = "\\";
|
|
exports.delimiter = ";";
|
|
exports.resolve = function resolve(...args) {
|
|
let resolvedDevice = "";
|
|
let resolvedTail = "";
|
|
let resolvedAbsolute = false;
|
|
for (let i = args.length - 1; i >= -1; i--) {
|
|
let path;
|
|
if (i >= 0) {
|
|
path = args[i];
|
|
validateString(path, `paths[${i}]`);
|
|
if (path.length === 0) continue;
|
|
} else if (resolvedDevice.length === 0) {
|
|
path = binding.cwd();
|
|
} else {
|
|
path = binding.cwd(resolvedDevice);
|
|
if (path === void 0 || path.substring(0, 2).toLowerCase() !== resolvedDevice.toLowerCase() && path.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
|
|
path = `${resolvedDevice}\\`;
|
|
}
|
|
}
|
|
const len = path.length;
|
|
let rootEnd = 0;
|
|
let device = "";
|
|
let isAbsolute = false;
|
|
const code = path.charCodeAt(0);
|
|
if (len === 1) {
|
|
if (isWindowsPathSeparator(code)) {
|
|
rootEnd = 1;
|
|
isAbsolute = true;
|
|
}
|
|
} else if (isWindowsPathSeparator(code)) {
|
|
isAbsolute = true;
|
|
if (isWindowsPathSeparator(path.charCodeAt(1))) {
|
|
let j = 2;
|
|
let last = j;
|
|
while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j < len && j !== last) {
|
|
const firstPart = path.substring(last, j);
|
|
last = j;
|
|
while (j < len && isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j < len && j !== last) {
|
|
last = j;
|
|
while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j === len || j !== last) {
|
|
device = `\\\\${firstPart}\\${path.substring(last, j)}`;
|
|
rootEnd = j;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
rootEnd = 1;
|
|
}
|
|
} else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
|
|
device = path.substring(0, 2);
|
|
rootEnd = 2;
|
|
if (len > 2 && isWindowsPathSeparator(path.charCodeAt(2))) {
|
|
isAbsolute = true;
|
|
rootEnd = 3;
|
|
}
|
|
}
|
|
if (device.length > 0) {
|
|
if (resolvedDevice.length > 0) {
|
|
if (device.toLowerCase() !== resolvedDevice.toLowerCase()) {
|
|
continue;
|
|
}
|
|
} else {
|
|
resolvedDevice = device;
|
|
}
|
|
}
|
|
if (resolvedAbsolute) {
|
|
if (resolvedDevice.length > 0) {
|
|
break;
|
|
}
|
|
} else {
|
|
resolvedTail = `${path.substring(rootEnd)}\\${resolvedTail}`;
|
|
resolvedAbsolute = isAbsolute;
|
|
if (isAbsolute && resolvedDevice.length > 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, "\\", isWindowsPathSeparator);
|
|
return resolvedAbsolute ? `${resolvedDevice}\\${resolvedTail}` : `${resolvedDevice}${resolvedTail}` || ".";
|
|
};
|
|
exports.normalize = function normalize(path) {
|
|
validateString(path, "path");
|
|
const len = path.length;
|
|
if (len === 0) return ".";
|
|
let rootEnd = 0;
|
|
let device;
|
|
let isAbsolute = false;
|
|
const code = path.charCodeAt(0);
|
|
if (len === 1) {
|
|
return code === CHAR_FORWARD_SLASH ? "\\" : path;
|
|
}
|
|
if (isWindowsPathSeparator(code)) {
|
|
isAbsolute = true;
|
|
if (isWindowsPathSeparator(path.charCodeAt(1))) {
|
|
let j = 2;
|
|
let last = j;
|
|
while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j < len && j !== last) {
|
|
const firstPart = path.substring(last, j);
|
|
last = j;
|
|
while (j < len && isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j < len && j !== last) {
|
|
last = j;
|
|
while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j === len) {
|
|
return `\\\\${firstPart}\\${path.substring(last)}\\`;
|
|
}
|
|
if (j !== last) {
|
|
device = `\\\\${firstPart}\\${path.substring(last, j)}`;
|
|
rootEnd = j;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
rootEnd = 1;
|
|
}
|
|
} else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
|
|
device = path.substring(0, 2);
|
|
rootEnd = 2;
|
|
if (len > 2 && isWindowsPathSeparator(path.charCodeAt(2))) {
|
|
isAbsolute = true;
|
|
rootEnd = 3;
|
|
}
|
|
}
|
|
let tail = rootEnd < len ? normalizeString(path.substring(rootEnd), !isAbsolute, "\\", isWindowsPathSeparator) : "";
|
|
if (tail.length === 0 && !isAbsolute) {
|
|
tail = ".";
|
|
}
|
|
if (tail.length > 0 && isWindowsPathSeparator(path.charCodeAt(len - 1))) {
|
|
tail += "\\";
|
|
}
|
|
if (device === void 0) {
|
|
return isAbsolute ? `\\${tail}` : tail;
|
|
}
|
|
return isAbsolute ? `${device}\\${tail}` : `${device}${tail}`;
|
|
};
|
|
exports.isAbsolute = function isAbsolute(path) {
|
|
validateString(path, "path");
|
|
const len = path.length;
|
|
if (len === 0) return false;
|
|
const code = path.charCodeAt(0);
|
|
return isWindowsPathSeparator(code) || len > 2 && isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON && isWindowsPathSeparator(path.charCodeAt(2));
|
|
};
|
|
exports.join = function join(...args) {
|
|
if (args.length === 0) return ".";
|
|
let joined;
|
|
let firstPart;
|
|
for (let i = 0; i < args.length; ++i) {
|
|
const arg = args[i];
|
|
validateString(arg, "path");
|
|
if (arg.length > 0) {
|
|
if (joined === void 0) joined = firstPart = arg;
|
|
else joined += `\\${arg}`;
|
|
}
|
|
}
|
|
if (joined === void 0) return ".";
|
|
let needsReplace = true;
|
|
let slashCount = 0;
|
|
if (isWindowsPathSeparator(firstPart.charCodeAt(0))) {
|
|
++slashCount;
|
|
const firstLen = firstPart.length;
|
|
if (firstLen > 1 && isWindowsPathSeparator(firstPart.charCodeAt(1))) {
|
|
++slashCount;
|
|
if (firstLen > 2) {
|
|
if (isWindowsPathSeparator(firstPart.charCodeAt(2))) {
|
|
++slashCount;
|
|
} else {
|
|
needsReplace = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (needsReplace) {
|
|
while (slashCount < joined.length && isWindowsPathSeparator(joined.charCodeAt(slashCount))) {
|
|
slashCount++;
|
|
}
|
|
if (slashCount >= 2) {
|
|
joined = `\\${joined.substring(slashCount)}`;
|
|
}
|
|
}
|
|
return exports.normalize(joined);
|
|
};
|
|
exports.relative = function relative(from, to) {
|
|
validateString(from, "from");
|
|
validateString(to, "to");
|
|
if (from === to) return "";
|
|
const fromOrig = exports.resolve(from);
|
|
const toOrig = exports.resolve(to);
|
|
if (fromOrig === toOrig) return "";
|
|
from = fromOrig.toLowerCase();
|
|
to = toOrig.toLowerCase();
|
|
if (from === to) return "";
|
|
let fromStart = 0;
|
|
while (fromStart < from.length && from.charCodeAt(fromStart) === CHAR_BACKWARD_SLASH) {
|
|
fromStart++;
|
|
}
|
|
let fromEnd = from.length;
|
|
while (fromEnd - 1 > fromStart && from.charCodeAt(fromEnd - 1) === CHAR_BACKWARD_SLASH) {
|
|
fromEnd--;
|
|
}
|
|
const fromLen = fromEnd - fromStart;
|
|
let toStart = 0;
|
|
while (toStart < to.length && to.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
|
|
toStart++;
|
|
}
|
|
let toEnd = to.length;
|
|
while (toEnd - 1 > toStart && to.charCodeAt(toEnd - 1) === CHAR_BACKWARD_SLASH) {
|
|
toEnd--;
|
|
}
|
|
const toLen = toEnd - toStart;
|
|
const length = fromLen < toLen ? fromLen : toLen;
|
|
let lastCommonSep = -1;
|
|
let i = 0;
|
|
for (; i < length; i++) {
|
|
const fromCode = from.charCodeAt(fromStart + i);
|
|
if (fromCode !== to.charCodeAt(toStart + i)) {
|
|
break;
|
|
} else if (fromCode === CHAR_BACKWARD_SLASH) {
|
|
lastCommonSep = i;
|
|
}
|
|
}
|
|
if (i !== length) {
|
|
if (lastCommonSep === -1) return toOrig;
|
|
} else {
|
|
if (toLen > length) {
|
|
if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
|
|
return toOrig.substring(toStart + i + 1);
|
|
}
|
|
if (i === 2) {
|
|
return toOrig.substring(toStart + i);
|
|
}
|
|
}
|
|
if (fromLen > length) {
|
|
if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) {
|
|
lastCommonSep = i;
|
|
} else if (i === 2) {
|
|
lastCommonSep = 3;
|
|
}
|
|
}
|
|
if (lastCommonSep === -1) lastCommonSep = 0;
|
|
}
|
|
let out = "";
|
|
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
|
|
out += out.length === 0 ? ".." : "\\..";
|
|
}
|
|
}
|
|
toStart += lastCommonSep;
|
|
if (out.length > 0) {
|
|
return `${out}${toOrig.substring(toStart, toEnd)}`;
|
|
}
|
|
if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
|
|
++toStart;
|
|
}
|
|
return toOrig.substring(toStart, toEnd);
|
|
};
|
|
exports.toNamespacedPath = function toNamespacedPath(path) {
|
|
if (typeof path !== "string" || path.length === 0) return path;
|
|
const resolvedPath = exports.resolve(path);
|
|
if (resolvedPath.length <= 2) return path;
|
|
if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) {
|
|
if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
|
|
const code = resolvedPath.charCodeAt(2);
|
|
if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
|
|
return `\\\\?\\UNC\\${resolvedPath.substring(2)}`;
|
|
}
|
|
}
|
|
} else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0)) && resolvedPath.charCodeAt(1) === CHAR_COLON && resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
|
|
return `\\\\?\\${resolvedPath}`;
|
|
}
|
|
return path;
|
|
};
|
|
exports.dirname = function dirname(path) {
|
|
validateString(path, "path");
|
|
const len = path.length;
|
|
if (len === 0) return ".";
|
|
let rootEnd = -1;
|
|
let offset = 0;
|
|
const code = path.charCodeAt(0);
|
|
if (len === 1) {
|
|
return isWindowsPathSeparator(code) ? path : ".";
|
|
}
|
|
if (isWindowsPathSeparator(code)) {
|
|
rootEnd = offset = 1;
|
|
if (isWindowsPathSeparator(path.charCodeAt(1))) {
|
|
let j = 2;
|
|
let last = j;
|
|
while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j < len && j !== last) {
|
|
last = j;
|
|
while (j < len && isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j < len && j !== last) {
|
|
last = j;
|
|
while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j === len) {
|
|
return path;
|
|
}
|
|
if (j !== last) {
|
|
rootEnd = offset = j + 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
|
|
rootEnd = len > 2 && isWindowsPathSeparator(path.charCodeAt(2)) ? 3 : 2;
|
|
offset = rootEnd;
|
|
}
|
|
let end = -1;
|
|
let matchedSlash = true;
|
|
for (let i = len - 1; i >= offset; --i) {
|
|
if (isWindowsPathSeparator(path.charCodeAt(i))) {
|
|
if (!matchedSlash) {
|
|
end = i;
|
|
break;
|
|
}
|
|
} else {
|
|
matchedSlash = false;
|
|
}
|
|
}
|
|
if (end === -1) {
|
|
if (rootEnd === -1) return ".";
|
|
end = rootEnd;
|
|
}
|
|
return path.substring(0, end);
|
|
};
|
|
exports.basename = function basename(path, suffix) {
|
|
if (suffix !== void 0) validateString(suffix, "suffix");
|
|
validateString(path, "path");
|
|
let start = 0;
|
|
let end = -1;
|
|
let matchedSlash = true;
|
|
if (path.length >= 2 && isWindowsDeviceRoot(path.charCodeAt(0)) && path.charCodeAt(1) === CHAR_COLON) {
|
|
start = 2;
|
|
}
|
|
if (suffix !== void 0 && suffix.length > 0 && suffix.length <= path.length) {
|
|
if (suffix === path) return "";
|
|
let extIdx = suffix.length - 1;
|
|
let firstNonSlashEnd = -1;
|
|
for (let i = path.length - 1; i >= start; --i) {
|
|
const code = path.charCodeAt(i);
|
|
if (isWindowsPathSeparator(code)) {
|
|
if (!matchedSlash) {
|
|
start = i + 1;
|
|
break;
|
|
}
|
|
} else {
|
|
if (firstNonSlashEnd === -1) {
|
|
matchedSlash = false;
|
|
firstNonSlashEnd = i + 1;
|
|
}
|
|
if (extIdx >= 0) {
|
|
if (code === suffix.charCodeAt(extIdx)) {
|
|
if (--extIdx === -1) {
|
|
end = i;
|
|
}
|
|
} else {
|
|
extIdx = -1;
|
|
end = firstNonSlashEnd;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (start === end) end = firstNonSlashEnd;
|
|
else if (end === -1) end = path.length;
|
|
return path.substring(start, end);
|
|
}
|
|
for (let i = path.length - 1; i >= start; --i) {
|
|
if (isWindowsPathSeparator(path.charCodeAt(i))) {
|
|
if (!matchedSlash) {
|
|
start = i + 1;
|
|
break;
|
|
}
|
|
} else if (end === -1) {
|
|
matchedSlash = false;
|
|
end = i + 1;
|
|
}
|
|
}
|
|
if (end === -1) return "";
|
|
return path.substring(start, end);
|
|
};
|
|
exports.extname = function extname(path) {
|
|
validateString(path, "path");
|
|
let start = 0;
|
|
let startDot = -1;
|
|
let startPart = 0;
|
|
let end = -1;
|
|
let matchedSlash = true;
|
|
let preDotState = 0;
|
|
if (path.length >= 2 && path.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path.charCodeAt(0))) {
|
|
start = startPart = 2;
|
|
}
|
|
for (let i = path.length - 1; i >= start; --i) {
|
|
const code = path.charCodeAt(i);
|
|
if (isWindowsPathSeparator(code)) {
|
|
if (!matchedSlash) {
|
|
startPart = i + 1;
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
if (end === -1) {
|
|
matchedSlash = false;
|
|
end = i + 1;
|
|
}
|
|
if (code === CHAR_DOT) {
|
|
if (startDot === -1) startDot = i;
|
|
else if (preDotState !== 1) preDotState = 1;
|
|
} else if (startDot !== -1) {
|
|
preDotState = -1;
|
|
}
|
|
}
|
|
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
return "";
|
|
}
|
|
return path.substring(startDot, end);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-path/index.js
|
|
var require_bare_path = __commonJS({
|
|
"../../node_modules/bare-path/index.js"(exports, module) {
|
|
if (Bare.platform === "win32") {
|
|
module.exports = require_win32();
|
|
} else {
|
|
module.exports = require_posix();
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-url/binding.js
|
|
var require_binding2 = __commonJS({
|
|
"../../node_modules/bare-url/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-url/lib/errors.js
|
|
var require_errors = __commonJS({
|
|
"../../node_modules/bare-url/lib/errors.js"(exports, module) {
|
|
module.exports = class URLError extends Error {
|
|
constructor(msg, fn = URLError, code = fn.name) {
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) Error.captureStackTrace(this, fn);
|
|
}
|
|
get name() {
|
|
return "URLError";
|
|
}
|
|
static INVALID_URL(msg, input) {
|
|
const err = new URLError(msg, URLError.INVALID_URL);
|
|
err.input = input;
|
|
return err;
|
|
}
|
|
static INVALID_URL_SCHEME(msg = "Invalid URL") {
|
|
return new URLError(msg, URLError.INVALID_URL_SCHEME);
|
|
}
|
|
static INVALID_FILE_URL_HOST(msg = "Invalid file: URL host") {
|
|
return new URLError(msg, URLError.INVALID_FILE_URL_HOST);
|
|
}
|
|
static INVALID_FILE_URL_PATH(msg = "Invalid file: URL path") {
|
|
return new URLError(msg, URLError.INVALID_FILE_URL_PATH);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-url/lib/url-search-params.js
|
|
var require_url_search_params = __commonJS({
|
|
"../../node_modules/bare-url/lib/url-search-params.js"(exports, module) {
|
|
var kind = Symbol.for("bare.url.search-params.kind");
|
|
var URLSearchParams = class _URLSearchParams {
|
|
static _urls = /* @__PURE__ */ new WeakMap();
|
|
static get [kind]() {
|
|
return 0;
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams
|
|
constructor(init, url = null) {
|
|
this._params = null;
|
|
if (url) _URLSearchParams._urls.set(this, url);
|
|
if (typeof init === "string") {
|
|
this._parse(init);
|
|
} else {
|
|
this._params = /* @__PURE__ */ new Map();
|
|
if (init) {
|
|
for (const [name, value] of typeof init[Symbol.iterator] === "function" ? init : Object.entries(init)) {
|
|
this.append(name, value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
get [kind]() {
|
|
return _URLSearchParams[kind];
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-size
|
|
get size() {
|
|
let size = 0;
|
|
for (const values of this._params.values()) size += values.length;
|
|
return size;
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-append
|
|
append(name, value = null) {
|
|
if (value === null) return;
|
|
let list = this._params.get(name);
|
|
if (list === void 0) {
|
|
list = [];
|
|
this._params.set(name, list);
|
|
}
|
|
list.push(value);
|
|
this._update();
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-delete
|
|
delete(name, value = null) {
|
|
if (value === null) this._params.delete(name);
|
|
else {
|
|
let list = this._params.get(name);
|
|
if (list === void 0) return;
|
|
list = list.filter((found) => found !== value);
|
|
if (list.length === 0) this._params.delete(name);
|
|
else this._params.set(name, list);
|
|
}
|
|
this._update();
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-get
|
|
get(name) {
|
|
const list = this._params.get(name);
|
|
if (list === void 0) return null;
|
|
return list[0];
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-getall
|
|
getAll(name) {
|
|
const list = this._params.get(name);
|
|
if (list === void 0) return [];
|
|
return Array.from(list);
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-has
|
|
has(name, value = null) {
|
|
const list = this._params.get(name);
|
|
if (list === void 0) return false;
|
|
if (value === null) return true;
|
|
return list.includes(value);
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-set
|
|
set(name, value = null) {
|
|
if (value === null) this._params.delete(name);
|
|
else this._params.set(name, [value]);
|
|
this._update();
|
|
}
|
|
toString() {
|
|
return this._serialize();
|
|
}
|
|
toJSON() {
|
|
return [...this];
|
|
}
|
|
*[Symbol.iterator]() {
|
|
for (const [name, values] of this._params) {
|
|
for (const value of values) yield [name, value];
|
|
}
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
const object = {
|
|
__proto__: { constructor: _URLSearchParams }
|
|
};
|
|
for (const [name, values] of this._params) {
|
|
if (values.length === 1) object[name] = values[0];
|
|
else object[name] = values;
|
|
}
|
|
return object;
|
|
}
|
|
// https://url.spec.whatwg.org/#concept-urlsearchparams-update
|
|
_update() {
|
|
const url = _URLSearchParams._urls.get(this);
|
|
if (url === void 0) return;
|
|
url.search = this._serialize();
|
|
}
|
|
// https://url.spec.whatwg.org/#concept-urlencoded-parser
|
|
_parse(input) {
|
|
const params = /* @__PURE__ */ new Map();
|
|
this._params = params;
|
|
const len = input.length;
|
|
let start = input.charCodeAt(0) === 63 ? 1 : 0;
|
|
while (start < len) {
|
|
let end = input.indexOf("&", start);
|
|
if (end === -1) end = len;
|
|
if (end !== start) {
|
|
let split = input.indexOf("=", start);
|
|
if (split === -1 || split > end) split = end;
|
|
const name = decode(input.slice(start, split));
|
|
const value = split === end ? "" : decode(input.slice(split + 1, end));
|
|
const list = params.get(name);
|
|
if (list === void 0) params.set(name, [value]);
|
|
else list.push(value);
|
|
}
|
|
start = end + 1;
|
|
}
|
|
}
|
|
// https://url.spec.whatwg.org/#concept-urlencoded-serializer
|
|
_serialize() {
|
|
let result = "";
|
|
let separator = "";
|
|
for (const [name, values] of this._params) {
|
|
const encoded = encode(String(name));
|
|
for (const value of values) {
|
|
result += separator + encoded + "=" + encode(String(value));
|
|
separator = "&";
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
};
|
|
module.exports = exports = URLSearchParams;
|
|
exports.isURLSearchParams = function isURLSearchParams(value) {
|
|
if (value instanceof URLSearchParams) return true;
|
|
return typeof value === "object" && value !== null && value[kind] === URLSearchParams[kind];
|
|
};
|
|
var unencoded = /^[\w*.-]*$/;
|
|
var spaced = /^[\w*. -]*$/;
|
|
var extra = /[!'()~]/;
|
|
var extraAll = /[!'()~]/g;
|
|
var escapes = {
|
|
"!": "%21",
|
|
"'": "%27",
|
|
"(": "%28",
|
|
")": "%29",
|
|
"~": "%7E"
|
|
};
|
|
var lone = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g;
|
|
function encode(component) {
|
|
if (unencoded.test(component)) return component;
|
|
if (spaced.test(component)) return component.replaceAll(" ", "+");
|
|
let encoded;
|
|
try {
|
|
encoded = encodeURIComponent(component);
|
|
} catch {
|
|
encoded = encodeURIComponent(component.replace(lone, "\uFFFD"));
|
|
}
|
|
if (encoded.includes("%20")) encoded = encoded.replaceAll("%20", "+");
|
|
if (extra.test(encoded)) encoded = encoded.replace(extraAll, (match) => escapes[match]);
|
|
return encoded;
|
|
}
|
|
function decode(component) {
|
|
if (component.indexOf("+") !== -1) component = component.replaceAll("+", " ");
|
|
if (component.indexOf("%") === -1) return component;
|
|
return decodeURIComponent(component);
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-url/index.js
|
|
var require_bare_url = __commonJS({
|
|
"../../node_modules/bare-url/index.js"(exports, module) {
|
|
var path = require_bare_path();
|
|
var binding = require_binding2();
|
|
var errors = require_errors();
|
|
var URLSearchParams = require_url_search_params();
|
|
var kind = Symbol.for("bare.url.kind");
|
|
var isWindows = Bare.platform === "win32";
|
|
var components = new Uint32Array(8);
|
|
var unset = 4294967295;
|
|
var reserved = isWindows ? /[%#?\n\r\t]/ : /[%#?\n\r\t\\]/;
|
|
var URL2 = class _URL {
|
|
static get [kind]() {
|
|
return 0;
|
|
}
|
|
constructor(input, base, opts = {}) {
|
|
if (arguments.length === 0) throw errors.INVALID_URL();
|
|
input = String(input);
|
|
if (base !== void 0) base = String(base);
|
|
this._href = void 0;
|
|
this._schemeEnd = 0;
|
|
this._usernameEnd = 0;
|
|
this._hostStart = 0;
|
|
this._hostEnd = 0;
|
|
this._pathStart = 0;
|
|
this._queryStart = 0;
|
|
this._fragmentStart = 0;
|
|
this._params = null;
|
|
this._parse(input, base, opts.throw !== false);
|
|
}
|
|
get [kind]() {
|
|
return _URL[kind];
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-href
|
|
get href() {
|
|
return this._href;
|
|
}
|
|
set href(value) {
|
|
this._update(value);
|
|
if (this._params) this._params._parse(this.search);
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-protocol
|
|
get protocol() {
|
|
return this._slice(0, this._schemeEnd) + ":";
|
|
}
|
|
set protocol(value) {
|
|
this._update(this._replace(value.replace(/:+$/, ""), 0, this._schemeEnd));
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-username
|
|
get username() {
|
|
return this._slice(this._schemeEnd + 3, this._usernameEnd);
|
|
}
|
|
set username(value) {
|
|
if (cannotHaveCredentialsOrPort(this)) {
|
|
return;
|
|
}
|
|
if (this.username === "") value += "@";
|
|
this._update(this._replace(value, this._schemeEnd + 3, this._usernameEnd));
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-password
|
|
get password() {
|
|
return this._href.slice(
|
|
this._usernameEnd + 1,
|
|
this._hostStart - 1
|
|
/* @ */
|
|
);
|
|
}
|
|
set password(value) {
|
|
if (cannotHaveCredentialsOrPort(this)) {
|
|
return;
|
|
}
|
|
let start = this._usernameEnd + 1;
|
|
let end = this._hostStart - 1;
|
|
if (this.password === "") {
|
|
value = ":" + value;
|
|
start--;
|
|
}
|
|
if (this.username === "") {
|
|
value += "@";
|
|
end++;
|
|
}
|
|
this._update(this._replace(value, start, end));
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-host
|
|
get host() {
|
|
return this._slice(this._hostStart, this._pathStart);
|
|
}
|
|
set host(value) {
|
|
if (hasOpaquePath(this)) {
|
|
return;
|
|
}
|
|
this._update(
|
|
this._replace(value, this._hostStart, value.includes(":") ? this._pathStart : this._hostEnd)
|
|
);
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-hostname
|
|
get hostname() {
|
|
return this._slice(this._hostStart, this._hostEnd);
|
|
}
|
|
set hostname(value) {
|
|
if (hasOpaquePath(this)) {
|
|
return;
|
|
}
|
|
this._update(this._replace(value, this._hostStart, this._hostEnd));
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-port
|
|
get port() {
|
|
return this._slice(this._hostEnd + 1, this._pathStart);
|
|
}
|
|
set port(value) {
|
|
if (cannotHaveCredentialsOrPort(this)) {
|
|
return;
|
|
}
|
|
let start = this._hostEnd + 1;
|
|
if (this.port === "") {
|
|
value = ":" + value;
|
|
start--;
|
|
}
|
|
this._update(this._replace(value, start, this._pathStart));
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-pathname
|
|
get pathname() {
|
|
return this._slice(
|
|
this._pathStart,
|
|
this._queryStart - 1
|
|
/* ? */
|
|
);
|
|
}
|
|
set pathname(value) {
|
|
if (hasOpaquePath(this)) {
|
|
return;
|
|
}
|
|
if (value[0] !== "/" && value[0] !== "\\") {
|
|
value = "/" + value;
|
|
}
|
|
this._update(this._replace(
|
|
value,
|
|
this._pathStart,
|
|
this._queryStart - 1
|
|
/* ? */
|
|
));
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-search
|
|
get search() {
|
|
return this._slice(
|
|
this._queryStart - 1,
|
|
this._fragmentStart - 1
|
|
/* # */
|
|
);
|
|
}
|
|
set search(value) {
|
|
if (value && value[0] !== "?") value = "?" + value;
|
|
this._update(
|
|
this._replace(
|
|
value,
|
|
this._queryStart - 1,
|
|
this._fragmentStart - 1
|
|
/* # */
|
|
)
|
|
);
|
|
if (this._params) this._params._parse(this.search);
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-searchparams
|
|
get searchParams() {
|
|
if (this._params === null) {
|
|
this._params = new URLSearchParams(this.search, this);
|
|
}
|
|
return this._params;
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-hash
|
|
get hash() {
|
|
return this._slice(
|
|
this._fragmentStart - 1
|
|
/* # */
|
|
);
|
|
}
|
|
set hash(value) {
|
|
if (value && value[0] !== "#") value = "#" + value;
|
|
this._update(this._replace(
|
|
value,
|
|
this._fragmentStart - 1
|
|
/* # */
|
|
));
|
|
}
|
|
toString() {
|
|
return this._href;
|
|
}
|
|
toJSON() {
|
|
return this._href;
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return {
|
|
__proto__: { constructor: _URL },
|
|
href: this.href,
|
|
protocol: this.protocol,
|
|
username: this.username,
|
|
password: this.password,
|
|
host: this.host,
|
|
hostname: this.hostname,
|
|
port: this.port,
|
|
pathname: this.pathname,
|
|
search: this.search,
|
|
searchParams: this.searchParams,
|
|
hash: this.hash
|
|
};
|
|
}
|
|
_slice(start, end = this._href.length) {
|
|
return this._href.slice(start, end);
|
|
}
|
|
_replace(replacement, start, end = this._href.length) {
|
|
return this._slice(0, start) + replacement + this._slice(end);
|
|
}
|
|
_parse(input, base, shouldThrow) {
|
|
let href;
|
|
try {
|
|
href = binding.parse(input, base || null, components, shouldThrow);
|
|
} catch (err) {
|
|
if (err instanceof TypeError) throw err;
|
|
throw errors.INVALID_URL(`Invalid URL '${input}'`, input);
|
|
}
|
|
if (href === void 0) return;
|
|
this._href = href;
|
|
this._schemeEnd = components[0];
|
|
this._usernameEnd = components[1];
|
|
this._hostStart = components[2];
|
|
this._hostEnd = components[3];
|
|
this._pathStart = components[5];
|
|
const queryStart = components[6];
|
|
const fragmentStart = components[7];
|
|
const end = href.length + 1;
|
|
this._queryStart = queryStart === unset ? end : queryStart;
|
|
this._fragmentStart = fragmentStart === unset ? end : fragmentStart;
|
|
}
|
|
_update(input) {
|
|
try {
|
|
this._parse(input, null, true);
|
|
} catch (err) {
|
|
if (err instanceof TypeError) throw err;
|
|
}
|
|
}
|
|
};
|
|
module.exports = exports = URL2;
|
|
function hasOpaquePath(url) {
|
|
return url.pathname[0] !== "/";
|
|
}
|
|
function cannotHaveCredentialsOrPort(url) {
|
|
return url.hostname === "" || url.protocol === "file:";
|
|
}
|
|
exports.URL = URL2;
|
|
exports.URLSearchParams = URLSearchParams;
|
|
exports.errors = errors;
|
|
exports.isURL = function isURL(value) {
|
|
if (value instanceof URL2) return true;
|
|
return typeof value === "object" && value !== null && value[kind] === URL2[kind];
|
|
};
|
|
exports.isURLSearchParams = URLSearchParams.isURLSearchParams;
|
|
exports.parse = function parse(input, base) {
|
|
const url = new URL2(input, base, { throw: false });
|
|
return url._href ? url : null;
|
|
};
|
|
exports.canParse = function canParse(input, base) {
|
|
return binding.canParse(String(input), base ? String(base) : null);
|
|
};
|
|
exports.fileURLToPath = function fileURLToPath(url) {
|
|
if (typeof url === "string") {
|
|
url = new URL2(url);
|
|
}
|
|
if (url.protocol !== "file:") {
|
|
throw errors.INVALID_URL_SCHEME("The URL must use the file: protocol");
|
|
}
|
|
if (!isWindows && url.hostname) {
|
|
throw errors.INVALID_FILE_URL_HOST("The file: URL host must be 'localhost' or empty");
|
|
}
|
|
const encoded = url.pathname;
|
|
const hasEncoded = encoded.includes("%");
|
|
if (hasEncoded) {
|
|
if (isWindows) {
|
|
if (/%2f|%5c/i.test(encoded)) {
|
|
throw errors.INVALID_FILE_URL_PATH(
|
|
"The file: URL path must not include encoded \\ or / characters"
|
|
);
|
|
}
|
|
} else if (/%2f/i.test(encoded)) {
|
|
throw errors.INVALID_FILE_URL_PATH("The file: URL path must not include encoded / characters");
|
|
}
|
|
if (/%00/i.test(encoded)) {
|
|
throw errors.INVALID_FILE_URL_PATH(
|
|
"The file: URL path must not include encoded NUL characters"
|
|
);
|
|
}
|
|
}
|
|
const pathname = path.normalize(hasEncoded ? decodeURIComponent(encoded) : encoded);
|
|
if (isWindows) {
|
|
if (url.hostname) return "\\\\" + url.hostname + pathname;
|
|
const letter = pathname.charCodeAt(1) | 32;
|
|
if (letter < 97 || letter > 122 || pathname.charCodeAt(2) !== 58) {
|
|
throw errors.INVALID_FILE_URL_PATH("The file: URL path must be absolute");
|
|
}
|
|
return pathname.slice(1);
|
|
}
|
|
return pathname;
|
|
};
|
|
exports.pathToFileURL = function pathToFileURL(pathname) {
|
|
let resolved = path.resolve(pathname);
|
|
if (pathname[pathname.length - 1] === "/") {
|
|
resolved += "/";
|
|
} else if (isWindows && pathname[pathname.length - 1] === "\\") {
|
|
resolved += "\\";
|
|
}
|
|
if (reserved.test(resolved)) {
|
|
resolved = resolved.replaceAll("%", "%25").replaceAll("#", "%23").replaceAll("?", "%3f").replaceAll("\n", "%0a").replaceAll("\r", "%0d").replaceAll(" ", "%09");
|
|
if (!isWindows) {
|
|
resolved = resolved.replaceAll("\\", "%5c");
|
|
}
|
|
}
|
|
return new URL2("file:" + resolved);
|
|
};
|
|
exports.format = function format(parts) {
|
|
const { protocol, auth, host, hostname, port, pathname, search, query, hash, slashes } = parts;
|
|
let result = "";
|
|
if (typeof protocol === "string") {
|
|
result += protocol;
|
|
if (protocol[protocol.length - 1] !== ":") {
|
|
result += ":";
|
|
}
|
|
if (slashes === true || /https?|ftp|gopher|file/.test(protocol)) {
|
|
result += "//";
|
|
}
|
|
}
|
|
if (typeof auth === "string") {
|
|
if (host || hostname) result += auth + "@";
|
|
}
|
|
if (typeof host === "string") result += host;
|
|
else {
|
|
result += hostname;
|
|
if (port) result += ":" + port;
|
|
}
|
|
if (typeof pathname === "string" && pathname !== "") {
|
|
if (pathname[0] !== "/") result += "/";
|
|
result += pathname;
|
|
}
|
|
if (typeof search === "string") {
|
|
if (search[0] !== "?") result += "?";
|
|
result += search;
|
|
} else if (typeof query === "object" && query !== null) {
|
|
result += "?" + new URLSearchParams(query);
|
|
}
|
|
if (typeof hash === "string") {
|
|
if (hash[0] !== "#") result += "#";
|
|
result += hash;
|
|
}
|
|
return result;
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-events/lib/errors.js
|
|
var require_errors2 = __commonJS({
|
|
"../../node_modules/bare-events/lib/errors.js"(exports, module) {
|
|
module.exports = class EventEmitterError extends Error {
|
|
constructor(msg, code, fn = EventEmitterError, opts) {
|
|
super(`${code}: ${msg}`, opts);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "EventEmitterError";
|
|
}
|
|
static OPERATION_ABORTED(cause, msg = "Operation aborted") {
|
|
return new EventEmitterError(msg, "OPERATION_ABORTED", EventEmitterError.OPERATION_ABORTED, {
|
|
cause
|
|
});
|
|
}
|
|
static UNHANDLED_ERROR(cause, msg = "Unhandled error") {
|
|
return new EventEmitterError(msg, "UNHANDLED_ERROR", EventEmitterError.UNHANDLED_ERROR, {
|
|
cause
|
|
});
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-events/index.js
|
|
var require_bare_events = __commonJS({
|
|
"../../node_modules/bare-events/index.js"(exports, module) {
|
|
var errors = require_errors2();
|
|
var EventListener = class {
|
|
constructor() {
|
|
this.list = [];
|
|
this.count = 0;
|
|
}
|
|
append(ctx, name, fn, once) {
|
|
this.count++;
|
|
ctx.emit("newListener", name, fn);
|
|
this.list.push([fn, once]);
|
|
}
|
|
prepend(ctx, name, fn, once) {
|
|
this.count++;
|
|
ctx.emit("newListener", name, fn);
|
|
this.list.unshift([fn, once]);
|
|
}
|
|
remove(ctx, name, fn) {
|
|
for (let i = 0, n = this.list.length; i < n; i++) {
|
|
const l = this.list[i];
|
|
if (l[0] === fn) {
|
|
this.list.splice(i, 1);
|
|
if (this.count === 1) delete ctx._events[name];
|
|
ctx.emit("removeListener", name, fn);
|
|
this.count--;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
removeAll(ctx, name) {
|
|
const list = [...this.list];
|
|
this.list = [];
|
|
if (this.count === list.length) delete ctx._events[name];
|
|
for (let i = list.length - 1; i >= 0; i--) {
|
|
ctx.emit("removeListener", name, list[i][0]);
|
|
}
|
|
this.count -= list.length;
|
|
}
|
|
emit(ctx, name, ...args) {
|
|
const list = [...this.list];
|
|
for (let i = 0, n = list.length; i < n; i++) {
|
|
const l = list[i];
|
|
if (l[1] === true) this.remove(ctx, name, l[0]);
|
|
Reflect.apply(l[0], ctx, args);
|
|
}
|
|
return list.length > 0;
|
|
}
|
|
};
|
|
function appendListener(ctx, name, fn, once) {
|
|
if (ctx._events === void 0) ctx._events = /* @__PURE__ */ Object.create(null);
|
|
const e = ctx._events[name] || (ctx._events[name] = new EventListener());
|
|
e.append(ctx, name, fn, once);
|
|
return ctx;
|
|
}
|
|
function prependListener(ctx, name, fn, once) {
|
|
if (ctx._events === void 0) ctx._events = /* @__PURE__ */ Object.create(null);
|
|
const e = ctx._events[name] || (ctx._events[name] = new EventListener());
|
|
e.prepend(ctx, name, fn, once);
|
|
return ctx;
|
|
}
|
|
function removeListener(ctx, name, fn) {
|
|
if (ctx._events === void 0) return ctx;
|
|
const e = ctx._events[name];
|
|
if (e !== void 0) e.remove(ctx, name, fn);
|
|
return ctx;
|
|
}
|
|
function throwUnhandledError(...args) {
|
|
let err;
|
|
if (args.length > 0) err = args[0];
|
|
if (err instanceof Error === false) err = errors.UNHANDLED_ERROR(err);
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(err, exports.prototype.emit);
|
|
}
|
|
queueMicrotask(() => {
|
|
throw err;
|
|
});
|
|
}
|
|
module.exports = exports = class EventEmitter {
|
|
constructor() {
|
|
this._events = /* @__PURE__ */ Object.create(null);
|
|
}
|
|
addListener(name, fn) {
|
|
return appendListener(this, name, fn, false);
|
|
}
|
|
addOnceListener(name, fn) {
|
|
return appendListener(this, name, fn, true);
|
|
}
|
|
prependListener(name, fn) {
|
|
return prependListener(this, name, fn, false);
|
|
}
|
|
prependOnceListener(name, fn) {
|
|
return prependListener(this, name, fn, true);
|
|
}
|
|
removeListener(name, fn) {
|
|
return removeListener(this, name, fn);
|
|
}
|
|
on(name, fn) {
|
|
return appendListener(this, name, fn, false);
|
|
}
|
|
once(name, fn) {
|
|
return appendListener(this, name, fn, true);
|
|
}
|
|
off(name, fn) {
|
|
return removeListener(this, name, fn);
|
|
}
|
|
emit(name, ...args) {
|
|
if (name === "error" && this._events !== void 0 && this._events.error === void 0) {
|
|
throwUnhandledError(...args);
|
|
}
|
|
if (this._events === void 0) return false;
|
|
const e = this._events[name];
|
|
return e === void 0 ? false : e.emit(this, name, ...args);
|
|
}
|
|
listeners(name) {
|
|
if (this._events === void 0) return [];
|
|
const e = this._events[name];
|
|
return e === void 0 ? [] : [...e.list];
|
|
}
|
|
rawListeners(name) {
|
|
if (this._events === void 0) return [];
|
|
const e = this._events[name];
|
|
return e === void 0 ? [] : e.list.map((l) => l[0]);
|
|
}
|
|
eventNames() {
|
|
if (this._events === void 0) return [];
|
|
return Reflect.ownKeys(this._events);
|
|
}
|
|
listenerCount(name) {
|
|
if (this._events === void 0) return 0;
|
|
const e = this._events[name];
|
|
return e === void 0 ? 0 : e.list.length;
|
|
}
|
|
getMaxListeners() {
|
|
return EventEmitter.defaultMaxListeners;
|
|
}
|
|
setMaxListeners(n) {
|
|
}
|
|
removeAllListeners(name) {
|
|
if (arguments.length === 0) {
|
|
for (const key of Reflect.ownKeys(this._events)) {
|
|
if (key === "removeListener") continue;
|
|
this.removeAllListeners(key);
|
|
}
|
|
this.removeAllListeners("removeListener");
|
|
} else {
|
|
const e = this._events[name];
|
|
if (e !== void 0) e.removeAll(this, name);
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
exports.EventEmitter = exports;
|
|
exports.errors = errors;
|
|
exports.defaultMaxListeners = 10;
|
|
exports.on = function on(emitter, name, opts = {}) {
|
|
const { signal } = opts;
|
|
if (signal && signal.aborted) {
|
|
throw errors.OPERATION_ABORTED(signal.reason);
|
|
}
|
|
let error = null;
|
|
let done = false;
|
|
const events = [];
|
|
const promises = [];
|
|
if (name !== "error") emitter.on("error", onerror);
|
|
if (signal) signal.addEventListener("abort", onabort);
|
|
emitter.on(name, onevent);
|
|
return {
|
|
next() {
|
|
if (events.length) {
|
|
return Promise.resolve({ value: events.shift(), done: false });
|
|
}
|
|
if (error) {
|
|
const err = error;
|
|
error = null;
|
|
return Promise.reject(err);
|
|
}
|
|
if (done) return onclose();
|
|
return new Promise((resolve, reject) => promises.push({ resolve, reject }));
|
|
},
|
|
return() {
|
|
return onclose();
|
|
},
|
|
throw(err) {
|
|
return onerror(err);
|
|
},
|
|
[Symbol.asyncIterator]() {
|
|
return this;
|
|
}
|
|
};
|
|
function onevent(...args) {
|
|
if (promises.length) {
|
|
promises.shift().resolve({ value: args, done: false });
|
|
} else {
|
|
events.push(args);
|
|
}
|
|
}
|
|
function onerror(err) {
|
|
emitter.off(name, onevent).off("error", onerror);
|
|
if (promises.length) {
|
|
promises.shift().reject(err);
|
|
} else {
|
|
error = err;
|
|
}
|
|
return Promise.resolve({ done: true });
|
|
}
|
|
function onabort() {
|
|
signal.removeEventListener("abort", onabort);
|
|
onerror(errors.OPERATION_ABORTED(signal.reason));
|
|
}
|
|
function onclose() {
|
|
emitter.off(name, onevent);
|
|
if (name !== "error") emitter.off("error", onerror);
|
|
if (signal) signal.removeEventListener("abort", onabort);
|
|
done = true;
|
|
if (promises.length) promises.shift().resolve({ done: true });
|
|
return Promise.resolve({ done: true });
|
|
}
|
|
};
|
|
exports.once = function once(emitter, name, opts = {}) {
|
|
const { signal } = opts;
|
|
if (signal && signal.aborted) {
|
|
return Promise.reject(errors.OPERATION_ABORTED(signal.reason));
|
|
}
|
|
return new Promise((resolve, reject) => {
|
|
if (name !== "error") emitter.on("error", onerror);
|
|
if (signal) signal.addEventListener("abort", onabort);
|
|
emitter.once(name, onevent);
|
|
function onevent(...args) {
|
|
if (name !== "error") emitter.off("error", onerror);
|
|
if (signal) signal.removeEventListener("abort", onabort);
|
|
resolve(args);
|
|
}
|
|
function onerror(err) {
|
|
emitter.off(name, onevent);
|
|
if (name !== "error") emitter.off("error", onerror);
|
|
reject(err);
|
|
}
|
|
function onabort() {
|
|
signal.removeEventListener("abort", onabort);
|
|
onerror(errors.OPERATION_ABORTED(signal.reason));
|
|
}
|
|
});
|
|
};
|
|
exports.forward = function forward(from, to, names, opts = {}) {
|
|
if (typeof names === "string") names = [names];
|
|
const { emit = to.emit.bind(to) } = opts;
|
|
const listeners = names.map(
|
|
(name) => function onevent(...args) {
|
|
emit(name, ...args);
|
|
}
|
|
);
|
|
to.on("newListener", (name) => {
|
|
const i = names.indexOf(name);
|
|
if (i !== -1 && to.listenerCount(name) === 0) {
|
|
from.on(name, listeners[i]);
|
|
}
|
|
}).on("removeListener", (name) => {
|
|
const i = names.indexOf(name);
|
|
if (i !== -1 && to.listenerCount(name) === 0) {
|
|
from.off(name, listeners[i]);
|
|
}
|
|
});
|
|
};
|
|
exports.listenerCount = function listenerCount(emitter, name) {
|
|
return emitter.listenerCount(name);
|
|
};
|
|
exports.getMaxListeners = function getMaxListeners(emitter) {
|
|
if (typeof emitter.getMaxListeners === "function") {
|
|
return emitter.getMaxListeners();
|
|
}
|
|
return exports.defaultMaxListeners;
|
|
};
|
|
exports.setMaxListeners = function setMaxListeners(n, ...emitters) {
|
|
if (emitters.length === 0) exports.defaultMaxListeners = n;
|
|
else {
|
|
for (const emitter of emitters) {
|
|
if (typeof emitter.setMaxListeners === "function") {
|
|
emitter.setMaxListeners(n);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/fast-fifo/fixed-size.js
|
|
var require_fixed_size = __commonJS({
|
|
"../../node_modules/fast-fifo/fixed-size.js"(exports, module) {
|
|
module.exports = class FixedFIFO {
|
|
constructor(hwm) {
|
|
if (!(hwm > 0) || (hwm - 1 & hwm) !== 0) throw new Error("Max size for a FixedFIFO should be a power of two");
|
|
this.buffer = new Array(hwm);
|
|
this.mask = hwm - 1;
|
|
this.top = 0;
|
|
this.btm = 0;
|
|
this.next = null;
|
|
}
|
|
clear() {
|
|
this.top = this.btm = 0;
|
|
this.next = null;
|
|
this.buffer.fill(void 0);
|
|
}
|
|
push(data) {
|
|
if (this.buffer[this.top] !== void 0) return false;
|
|
this.buffer[this.top] = data;
|
|
this.top = this.top + 1 & this.mask;
|
|
return true;
|
|
}
|
|
shift() {
|
|
const last = this.buffer[this.btm];
|
|
if (last === void 0) return void 0;
|
|
this.buffer[this.btm] = void 0;
|
|
this.btm = this.btm + 1 & this.mask;
|
|
return last;
|
|
}
|
|
peek() {
|
|
return this.buffer[this.btm];
|
|
}
|
|
isEmpty() {
|
|
return this.buffer[this.btm] === void 0;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/fast-fifo/index.js
|
|
var require_fast_fifo = __commonJS({
|
|
"../../node_modules/fast-fifo/index.js"(exports, module) {
|
|
var FixedFIFO = require_fixed_size();
|
|
module.exports = class FastFIFO {
|
|
constructor(hwm) {
|
|
this.hwm = hwm || 16;
|
|
this.head = new FixedFIFO(this.hwm);
|
|
this.tail = this.head;
|
|
this.length = 0;
|
|
}
|
|
clear() {
|
|
this.head = this.tail;
|
|
this.head.clear();
|
|
this.length = 0;
|
|
}
|
|
push(val) {
|
|
this.length++;
|
|
if (!this.head.push(val)) {
|
|
const prev = this.head;
|
|
this.head = prev.next = new FixedFIFO(2 * this.head.buffer.length);
|
|
this.head.push(val);
|
|
}
|
|
}
|
|
shift() {
|
|
if (this.length !== 0) this.length--;
|
|
const val = this.tail.shift();
|
|
if (val === void 0 && this.tail.next) {
|
|
const next = this.tail.next;
|
|
this.tail.next = null;
|
|
this.tail = next;
|
|
return this.tail.shift();
|
|
}
|
|
return val;
|
|
}
|
|
peek() {
|
|
const val = this.tail.peek();
|
|
if (val === void 0 && this.tail.next) return this.tail.next.peek();
|
|
return val;
|
|
}
|
|
isEmpty() {
|
|
return this.length === 0;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/b4a/index.js
|
|
var require_b4a = __commonJS({
|
|
"../../node_modules/b4a/index.js"(exports, module) {
|
|
function isBuffer(value) {
|
|
return Buffer.isBuffer(value) || value instanceof Uint8Array;
|
|
}
|
|
function isEncoding(encoding) {
|
|
return Buffer.isEncoding(encoding);
|
|
}
|
|
function alloc(size, fill2, encoding) {
|
|
return Buffer.alloc(size, fill2, encoding);
|
|
}
|
|
function allocUnsafe(size) {
|
|
return Buffer.allocUnsafe(size);
|
|
}
|
|
function allocUnsafeSlow(size) {
|
|
return Buffer.allocUnsafeSlow(size);
|
|
}
|
|
function byteLength(string, encoding) {
|
|
return Buffer.byteLength(string, encoding);
|
|
}
|
|
function compare(a, b) {
|
|
return Buffer.compare(a, b);
|
|
}
|
|
function concat(buffers, totalLength) {
|
|
return Buffer.concat(buffers, totalLength);
|
|
}
|
|
function copy(source, target, targetStart, start, end) {
|
|
return toBuffer(source).copy(target, targetStart, start, end);
|
|
}
|
|
function equals(a, b) {
|
|
return toBuffer(a).equals(b);
|
|
}
|
|
function fill(buffer, value, offset, end, encoding) {
|
|
return toBuffer(buffer).fill(value, offset, end, encoding);
|
|
}
|
|
function from(value, encodingOrOffset, length) {
|
|
return Buffer.from(value, encodingOrOffset, length);
|
|
}
|
|
function includes(buffer, value, byteOffset, encoding) {
|
|
return toBuffer(buffer).includes(value, byteOffset, encoding);
|
|
}
|
|
function indexOf(buffer, value, byfeOffset, encoding) {
|
|
return toBuffer(buffer).indexOf(value, byfeOffset, encoding);
|
|
}
|
|
function lastIndexOf(buffer, value, byteOffset, encoding) {
|
|
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding);
|
|
}
|
|
function swap16(buffer) {
|
|
return toBuffer(buffer).swap16();
|
|
}
|
|
function swap32(buffer) {
|
|
return toBuffer(buffer).swap32();
|
|
}
|
|
function swap64(buffer) {
|
|
return toBuffer(buffer).swap64();
|
|
}
|
|
function toBuffer(buffer) {
|
|
if (Buffer.isBuffer(buffer)) return buffer;
|
|
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
}
|
|
function toString(buffer, encoding, start, end) {
|
|
return toBuffer(buffer).toString(encoding, start, end);
|
|
}
|
|
function write(buffer, string, offset, length, encoding) {
|
|
return toBuffer(buffer).write(string, offset, length, encoding);
|
|
}
|
|
function readDoubleBE(buffer, offset) {
|
|
return toBuffer(buffer).readDoubleBE(offset);
|
|
}
|
|
function readDoubleLE(buffer, offset) {
|
|
return toBuffer(buffer).readDoubleLE(offset);
|
|
}
|
|
function readFloatBE(buffer, offset) {
|
|
return toBuffer(buffer).readFloatBE(offset);
|
|
}
|
|
function readFloatLE(buffer, offset) {
|
|
return toBuffer(buffer).readFloatLE(offset);
|
|
}
|
|
function readInt32BE(buffer, offset) {
|
|
return toBuffer(buffer).readInt32BE(offset);
|
|
}
|
|
function readInt32LE(buffer, offset) {
|
|
return toBuffer(buffer).readInt32LE(offset);
|
|
}
|
|
function readUInt32BE(buffer, offset) {
|
|
return toBuffer(buffer).readUInt32BE(offset);
|
|
}
|
|
function readUInt32LE(buffer, offset) {
|
|
return toBuffer(buffer).readUInt32LE(offset);
|
|
}
|
|
function writeDoubleBE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeDoubleBE(value, offset);
|
|
}
|
|
function writeDoubleLE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeDoubleLE(value, offset);
|
|
}
|
|
function writeFloatBE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeFloatBE(value, offset);
|
|
}
|
|
function writeFloatLE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeFloatLE(value, offset);
|
|
}
|
|
function writeInt32BE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeInt32BE(value, offset);
|
|
}
|
|
function writeInt32LE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeInt32LE(value, offset);
|
|
}
|
|
function writeUInt32BE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeUInt32BE(value, offset);
|
|
}
|
|
function writeUInt32LE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeUInt32LE(value, offset);
|
|
}
|
|
module.exports = {
|
|
isBuffer,
|
|
isEncoding,
|
|
alloc,
|
|
allocUnsafe,
|
|
allocUnsafeSlow,
|
|
byteLength,
|
|
compare,
|
|
concat,
|
|
copy,
|
|
equals,
|
|
fill,
|
|
from,
|
|
includes,
|
|
indexOf,
|
|
lastIndexOf,
|
|
swap16,
|
|
swap32,
|
|
swap64,
|
|
toBuffer,
|
|
toString,
|
|
write,
|
|
readDoubleBE,
|
|
readDoubleLE,
|
|
readFloatBE,
|
|
readFloatLE,
|
|
readInt32BE,
|
|
readInt32LE,
|
|
readUInt32BE,
|
|
readUInt32LE,
|
|
writeDoubleBE,
|
|
writeDoubleLE,
|
|
writeFloatBE,
|
|
writeFloatLE,
|
|
writeInt32BE,
|
|
writeInt32LE,
|
|
writeUInt32BE,
|
|
writeUInt32LE
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../bare-os-openssh/vendor/bare-node-shims/bare-node-events/index.js
|
|
var require_bare_node_events = __commonJS({
|
|
"../bare-os-openssh/vendor/bare-node-shims/bare-node-events/index.js"(exports, module) {
|
|
module.exports = require_bare_events();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/events-universal/default.js
|
|
var require_default = __commonJS({
|
|
"../../node_modules/events-universal/default.js"(exports, module) {
|
|
module.exports = require_bare_node_events();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/text-decoder/lib/pass-through-decoder.js
|
|
var require_pass_through_decoder = __commonJS({
|
|
"../../node_modules/text-decoder/lib/pass-through-decoder.js"(exports, module) {
|
|
var b4a = require_b4a();
|
|
module.exports = class PassThroughDecoder {
|
|
constructor(encoding) {
|
|
this.encoding = encoding;
|
|
}
|
|
get remaining() {
|
|
return 0;
|
|
}
|
|
decode(data) {
|
|
return b4a.toString(data, this.encoding);
|
|
}
|
|
flush() {
|
|
return "";
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/text-decoder/lib/utf8-decoder.js
|
|
var require_utf8_decoder = __commonJS({
|
|
"../../node_modules/text-decoder/lib/utf8-decoder.js"(exports, module) {
|
|
var b4a = require_b4a();
|
|
module.exports = class UTF8Decoder {
|
|
constructor() {
|
|
this._reset();
|
|
}
|
|
get remaining() {
|
|
return this.bytesSeen;
|
|
}
|
|
decode(data) {
|
|
if (data.byteLength === 0) return "";
|
|
if (this.bytesNeeded === 0 && trailingIncomplete(data, 0) === 0) {
|
|
this.bytesSeen = trailingBytesSeen(data);
|
|
return b4a.toString(data, "utf8");
|
|
}
|
|
let result = "";
|
|
let start = 0;
|
|
if (this.bytesNeeded > 0) {
|
|
while (start < data.byteLength) {
|
|
const byte = data[start];
|
|
if (byte < this.lowerBoundary || byte > this.upperBoundary) {
|
|
result += "\uFFFD";
|
|
this._reset();
|
|
break;
|
|
}
|
|
this.lowerBoundary = 128;
|
|
this.upperBoundary = 191;
|
|
this.codePoint = this.codePoint << 6 | byte & 63;
|
|
this.bytesSeen++;
|
|
start++;
|
|
if (this.bytesSeen === this.bytesNeeded) {
|
|
result += String.fromCodePoint(this.codePoint);
|
|
this._reset();
|
|
break;
|
|
}
|
|
}
|
|
if (this.bytesNeeded > 0) return result;
|
|
}
|
|
const trailing = trailingIncomplete(data, start);
|
|
const end = data.byteLength - trailing;
|
|
if (end > start) result += b4a.toString(data, "utf8", start, end);
|
|
for (let i = end; i < data.byteLength; i++) {
|
|
const byte = data[i];
|
|
if (this.bytesNeeded === 0) {
|
|
if (byte <= 127) {
|
|
this.bytesSeen = 0;
|
|
result += String.fromCharCode(byte);
|
|
} else if (byte >= 194 && byte <= 223) {
|
|
this.bytesNeeded = 2;
|
|
this.bytesSeen = 1;
|
|
this.codePoint = byte & 31;
|
|
} else if (byte >= 224 && byte <= 239) {
|
|
if (byte === 224) this.lowerBoundary = 160;
|
|
else if (byte === 237) this.upperBoundary = 159;
|
|
this.bytesNeeded = 3;
|
|
this.bytesSeen = 1;
|
|
this.codePoint = byte & 15;
|
|
} else if (byte >= 240 && byte <= 244) {
|
|
if (byte === 240) this.lowerBoundary = 144;
|
|
else if (byte === 244) this.upperBoundary = 143;
|
|
this.bytesNeeded = 4;
|
|
this.bytesSeen = 1;
|
|
this.codePoint = byte & 7;
|
|
} else {
|
|
this.bytesSeen = 1;
|
|
result += "\uFFFD";
|
|
}
|
|
continue;
|
|
}
|
|
if (byte < this.lowerBoundary || byte > this.upperBoundary) {
|
|
result += "\uFFFD";
|
|
i--;
|
|
this._reset();
|
|
continue;
|
|
}
|
|
this.lowerBoundary = 128;
|
|
this.upperBoundary = 191;
|
|
this.codePoint = this.codePoint << 6 | byte & 63;
|
|
this.bytesSeen++;
|
|
if (this.bytesSeen === this.bytesNeeded) {
|
|
result += String.fromCodePoint(this.codePoint);
|
|
this._reset();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
flush() {
|
|
const result = this.bytesNeeded > 0 ? "\uFFFD" : "";
|
|
this._reset();
|
|
return result;
|
|
}
|
|
_reset() {
|
|
this.codePoint = 0;
|
|
this.bytesNeeded = 0;
|
|
this.bytesSeen = 0;
|
|
this.lowerBoundary = 128;
|
|
this.upperBoundary = 191;
|
|
}
|
|
};
|
|
function trailingIncomplete(data, start) {
|
|
const len = data.byteLength;
|
|
if (len <= start) return 0;
|
|
const limit = Math.max(start, len - 4);
|
|
let i = len - 1;
|
|
while (i > limit && (data[i] & 192) === 128) i--;
|
|
if (i < start) return 0;
|
|
const byte = data[i];
|
|
let needed;
|
|
if (byte <= 127) return 0;
|
|
if (byte >= 194 && byte <= 223) needed = 2;
|
|
else if (byte >= 224 && byte <= 239) needed = 3;
|
|
else if (byte >= 240 && byte <= 244) needed = 4;
|
|
else return 0;
|
|
const available = len - i;
|
|
return available < needed ? available : 0;
|
|
}
|
|
function trailingBytesSeen(data) {
|
|
const len = data.byteLength;
|
|
if (len === 0) return 0;
|
|
const last = data[len - 1];
|
|
if (last <= 127) return 0;
|
|
if ((last & 192) !== 128) return 1;
|
|
const limit = Math.max(0, len - 4);
|
|
let i = len - 2;
|
|
while (i >= limit && (data[i] & 192) === 128) i--;
|
|
if (i < 0) return 1;
|
|
const first = data[i];
|
|
let needed;
|
|
if (first >= 194 && first <= 223) needed = 2;
|
|
else if (first >= 224 && first <= 239) needed = 3;
|
|
else if (first >= 240 && first <= 244) needed = 4;
|
|
else return 1;
|
|
if (len - i !== needed) return 1;
|
|
if (needed >= 3) {
|
|
const second = data[i + 1];
|
|
if (first === 224 && second < 160) return 1;
|
|
if (first === 237 && second > 159) return 1;
|
|
if (first === 240 && second < 144) return 1;
|
|
if (first === 244 && second > 143) return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/text-decoder/index.js
|
|
var require_text_decoder = __commonJS({
|
|
"../../node_modules/text-decoder/index.js"(exports, module) {
|
|
var PassThroughDecoder = require_pass_through_decoder();
|
|
var UTF8Decoder = require_utf8_decoder();
|
|
module.exports = class TextDecoder {
|
|
constructor(encoding = "utf8") {
|
|
this.encoding = normalizeEncoding(encoding);
|
|
switch (this.encoding) {
|
|
case "utf8":
|
|
this.decoder = new UTF8Decoder();
|
|
break;
|
|
case "utf16le":
|
|
case "base64":
|
|
throw new Error("Unsupported encoding: " + this.encoding);
|
|
default:
|
|
this.decoder = new PassThroughDecoder(this.encoding);
|
|
}
|
|
}
|
|
get remaining() {
|
|
return this.decoder.remaining;
|
|
}
|
|
push(data) {
|
|
if (typeof data === "string") return data;
|
|
return this.decoder.decode(data);
|
|
}
|
|
// For Node.js compatibility
|
|
write(data) {
|
|
return this.push(data);
|
|
}
|
|
end(data) {
|
|
let result = "";
|
|
if (data) result = this.push(data);
|
|
result += this.decoder.flush();
|
|
return result;
|
|
}
|
|
};
|
|
function normalizeEncoding(encoding) {
|
|
encoding = encoding.toLowerCase();
|
|
switch (encoding) {
|
|
case "utf8":
|
|
case "utf-8":
|
|
return "utf8";
|
|
case "ucs2":
|
|
case "ucs-2":
|
|
case "utf16le":
|
|
case "utf-16le":
|
|
return "utf16le";
|
|
case "latin1":
|
|
case "binary":
|
|
return "latin1";
|
|
case "base64":
|
|
case "ascii":
|
|
case "hex":
|
|
return encoding;
|
|
default:
|
|
throw new Error("Unknown encoding: " + encoding);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/streamx/lib/errors.js
|
|
var require_errors3 = __commonJS({
|
|
"../../node_modules/streamx/lib/errors.js"(exports, module) {
|
|
module.exports = class StreamError extends Error {
|
|
constructor(msg, code, fn = StreamError) {
|
|
super(msg);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
static isStreamDestroyed(err) {
|
|
return err && err.code === "STREAM_DESTROYED";
|
|
}
|
|
static isPrematureClose(err) {
|
|
return err && err.code === "PREMATURE_CLOSE";
|
|
}
|
|
static isAborted(err) {
|
|
return err && err.code === "ABORTED";
|
|
}
|
|
static isBadArgument(err) {
|
|
return err && err.code === "BAD_ARGUMENT";
|
|
}
|
|
get name() {
|
|
return "StreamError";
|
|
}
|
|
static STREAM_DESTROYED() {
|
|
return new StreamError("Stream was destroyed", "STREAM_DESTROYED", StreamError.STREAM_DESTROYED);
|
|
}
|
|
static PREMATURE_CLOSE(msg = "Premature close") {
|
|
return new StreamError(msg, "PREMATURE_CLOSE", StreamError.PREMATURE_CLOSE);
|
|
}
|
|
static ABORTED() {
|
|
return new StreamError("Stream aborted", "ABORTED", StreamError.ABORTED);
|
|
}
|
|
static BAD_ARGUMENT(msg = "Bad argument") {
|
|
return new StreamError(msg, "BAD_ARGUMENT", StreamError.BAD_ARGUMENT);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/streamx/index.js
|
|
var require_streamx = __commonJS({
|
|
"../../node_modules/streamx/index.js"(exports, module) {
|
|
var { EventEmitter } = require_default();
|
|
var FIFO = require_fast_fifo();
|
|
var TextDecoder = require_text_decoder();
|
|
var StreamError = require_errors3();
|
|
var qmt = typeof queueMicrotask === "undefined" ? (fn) => global.process.nextTick(fn) : queueMicrotask;
|
|
var MAX = (1 << 29) - 1;
|
|
var OPENING = 1;
|
|
var PREDESTROYING = 2;
|
|
var DESTROYING = 4;
|
|
var DESTROYED = 8;
|
|
var NOT_OPENING = MAX ^ OPENING;
|
|
var NOT_PREDESTROYING = MAX ^ PREDESTROYING;
|
|
var READ_ACTIVE = 1 << 4;
|
|
var READ_UPDATING = 2 << 4;
|
|
var READ_PRIMARY = 4 << 4;
|
|
var READ_QUEUED = 8 << 4;
|
|
var READ_RESUMED = 16 << 4;
|
|
var READ_PIPE_DRAINED = 32 << 4;
|
|
var READ_ENDING = 64 << 4;
|
|
var READ_EMIT_DATA = 128 << 4;
|
|
var READ_EMIT_READABLE = 256 << 4;
|
|
var READ_EMITTED_READABLE = 512 << 4;
|
|
var READ_DONE = 1024 << 4;
|
|
var READ_NEXT_TICK = 2048 << 4;
|
|
var READ_NEEDS_PUSH = 4096 << 4;
|
|
var READ_READ_AHEAD = 8192 << 4;
|
|
var READ_FLOWING = READ_RESUMED | READ_PIPE_DRAINED;
|
|
var READ_ACTIVE_AND_NEEDS_PUSH = READ_ACTIVE | READ_NEEDS_PUSH;
|
|
var READ_PRIMARY_AND_ACTIVE = READ_PRIMARY | READ_ACTIVE;
|
|
var READ_EMIT_READABLE_AND_QUEUED = READ_EMIT_READABLE | READ_QUEUED;
|
|
var READ_RESUMED_READ_AHEAD = READ_RESUMED | READ_READ_AHEAD;
|
|
var READ_NOT_ACTIVE = MAX ^ READ_ACTIVE;
|
|
var READ_NON_PRIMARY = MAX ^ READ_PRIMARY;
|
|
var READ_NON_PRIMARY_AND_PUSHED = MAX ^ (READ_PRIMARY | READ_NEEDS_PUSH);
|
|
var READ_PUSHED = MAX ^ READ_NEEDS_PUSH;
|
|
var READ_PAUSED = MAX ^ READ_RESUMED;
|
|
var READ_NOT_QUEUED = MAX ^ (READ_QUEUED | READ_EMITTED_READABLE);
|
|
var READ_NOT_ENDING = MAX ^ READ_ENDING;
|
|
var READ_PIPE_NOT_DRAINED = MAX ^ READ_FLOWING;
|
|
var READ_NOT_NEXT_TICK = MAX ^ READ_NEXT_TICK;
|
|
var READ_NOT_UPDATING = MAX ^ READ_UPDATING;
|
|
var READ_NO_READ_AHEAD = MAX ^ READ_READ_AHEAD;
|
|
var READ_PAUSED_NO_READ_AHEAD = MAX ^ READ_RESUMED_READ_AHEAD;
|
|
var WRITE_ACTIVE = 1 << 18;
|
|
var WRITE_UPDATING = 2 << 18;
|
|
var WRITE_PRIMARY = 4 << 18;
|
|
var WRITE_QUEUED = 8 << 18;
|
|
var WRITE_UNDRAINED = 16 << 18;
|
|
var WRITE_DONE = 32 << 18;
|
|
var WRITE_EMIT_DRAIN = 64 << 18;
|
|
var WRITE_NEXT_TICK = 128 << 18;
|
|
var WRITE_WRITING = 256 << 18;
|
|
var WRITE_FINISHING = 512 << 18;
|
|
var WRITE_CORKED = 1024 << 18;
|
|
var WRITE_NOT_ACTIVE = MAX ^ (WRITE_ACTIVE | WRITE_WRITING);
|
|
var WRITE_NON_PRIMARY = MAX ^ WRITE_PRIMARY;
|
|
var WRITE_NOT_FINISHING = MAX ^ (WRITE_ACTIVE | WRITE_FINISHING);
|
|
var WRITE_DRAINED = MAX ^ WRITE_UNDRAINED;
|
|
var WRITE_NOT_QUEUED = MAX ^ WRITE_QUEUED;
|
|
var WRITE_NOT_NEXT_TICK = MAX ^ WRITE_NEXT_TICK;
|
|
var WRITE_NOT_UPDATING = MAX ^ WRITE_UPDATING;
|
|
var WRITE_NOT_CORKED = MAX ^ WRITE_CORKED;
|
|
var ACTIVE = READ_ACTIVE | WRITE_ACTIVE;
|
|
var NOT_ACTIVE = MAX ^ ACTIVE;
|
|
var DONE = READ_DONE | WRITE_DONE;
|
|
var DESTROY_STATUS = DESTROYING | DESTROYED | PREDESTROYING;
|
|
var OPEN_STATUS = DESTROY_STATUS | OPENING;
|
|
var AUTO_DESTROY = DESTROY_STATUS | DONE;
|
|
var NON_PRIMARY = WRITE_NON_PRIMARY & READ_NON_PRIMARY;
|
|
var ACTIVE_OR_TICKING = WRITE_NEXT_TICK | READ_NEXT_TICK;
|
|
var TICKING = ACTIVE_OR_TICKING & NOT_ACTIVE;
|
|
var IS_OPENING = OPEN_STATUS | TICKING;
|
|
var READ_PRIMARY_STATUS = OPEN_STATUS | READ_ENDING | READ_DONE;
|
|
var READ_STATUS = OPEN_STATUS | READ_DONE | READ_QUEUED;
|
|
var READ_ENDING_STATUS = OPEN_STATUS | READ_ENDING | READ_QUEUED;
|
|
var READ_READABLE_STATUS = OPEN_STATUS | READ_EMIT_READABLE | READ_QUEUED | READ_EMITTED_READABLE;
|
|
var SHOULD_NOT_READ = OPEN_STATUS | READ_ACTIVE | READ_ENDING | READ_DONE | READ_NEEDS_PUSH | READ_READ_AHEAD;
|
|
var READ_BACKPRESSURE_STATUS = DESTROY_STATUS | READ_ENDING | READ_DONE;
|
|
var READ_UPDATE_SYNC_STATUS = READ_UPDATING | OPEN_STATUS | READ_NEXT_TICK | READ_PRIMARY;
|
|
var READ_NEXT_TICK_OR_OPENING = READ_NEXT_TICK | OPENING;
|
|
var WRITE_PRIMARY_STATUS = OPEN_STATUS | WRITE_FINISHING | WRITE_DONE;
|
|
var WRITE_QUEUED_AND_UNDRAINED = WRITE_QUEUED | WRITE_UNDRAINED;
|
|
var WRITE_QUEUED_AND_ACTIVE = WRITE_QUEUED | WRITE_ACTIVE;
|
|
var WRITE_DRAIN_STATUS = WRITE_QUEUED | WRITE_UNDRAINED | OPEN_STATUS | WRITE_ACTIVE;
|
|
var WRITE_STATUS = OPEN_STATUS | WRITE_ACTIVE | WRITE_QUEUED | WRITE_CORKED;
|
|
var WRITE_PRIMARY_AND_ACTIVE = WRITE_PRIMARY | WRITE_ACTIVE;
|
|
var WRITE_ACTIVE_AND_WRITING = WRITE_ACTIVE | WRITE_WRITING;
|
|
var WRITE_FINISHING_STATUS = OPEN_STATUS | WRITE_FINISHING | WRITE_QUEUED_AND_ACTIVE | WRITE_DONE;
|
|
var WRITE_BACKPRESSURE_STATUS = WRITE_UNDRAINED | DESTROY_STATUS | WRITE_FINISHING | WRITE_DONE;
|
|
var WRITE_UPDATE_SYNC_STATUS = WRITE_UPDATING | OPEN_STATUS | WRITE_NEXT_TICK | WRITE_PRIMARY;
|
|
var WRITE_DROP_DATA = WRITE_FINISHING | WRITE_DONE | DESTROY_STATUS;
|
|
var asyncIterator = Symbol.asyncIterator || Symbol("asyncIterator");
|
|
var WritableState = class {
|
|
constructor(stream, { highWaterMark = 16384, map = null, mapWritable, byteLength, byteLengthWritable } = {}) {
|
|
this.stream = stream;
|
|
this.queue = new FIFO();
|
|
this.highWaterMark = highWaterMark;
|
|
this.buffered = 0;
|
|
this.error = null;
|
|
this.pipeline = null;
|
|
this.drains = null;
|
|
this.byteLength = byteLengthWritable || byteLength || defaultByteLength;
|
|
this.map = mapWritable || map;
|
|
this.afterWrite = afterWrite.bind(this);
|
|
this.afterUpdateNextTick = updateWriteNT.bind(this);
|
|
}
|
|
get ending() {
|
|
return (this.stream._duplexState & WRITE_FINISHING) !== 0;
|
|
}
|
|
get ended() {
|
|
return (this.stream._duplexState & WRITE_DONE) !== 0;
|
|
}
|
|
push(data) {
|
|
if ((this.stream._duplexState & WRITE_DROP_DATA) !== 0) return false;
|
|
if (this.map !== null) data = this.map(data);
|
|
this.buffered += this.byteLength(data);
|
|
this.queue.push(data);
|
|
if (this.buffered < this.highWaterMark) {
|
|
this.stream._duplexState |= WRITE_QUEUED;
|
|
return true;
|
|
}
|
|
this.stream._duplexState |= WRITE_QUEUED_AND_UNDRAINED;
|
|
return false;
|
|
}
|
|
shift() {
|
|
const data = this.queue.shift();
|
|
this.buffered -= this.byteLength(data);
|
|
if (this.buffered === 0) this.stream._duplexState &= WRITE_NOT_QUEUED;
|
|
return data;
|
|
}
|
|
end(data) {
|
|
if (typeof data === "function") {
|
|
this.stream.once("finish", data);
|
|
} else if (data !== void 0 && data !== null) {
|
|
this.push(data);
|
|
}
|
|
this.stream._duplexState = (this.stream._duplexState | WRITE_FINISHING) & WRITE_NON_PRIMARY;
|
|
}
|
|
autoBatch(data, cb) {
|
|
const buffer = [];
|
|
const stream = this.stream;
|
|
buffer.push(data);
|
|
while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED_AND_ACTIVE) {
|
|
buffer.push(stream._writableState.shift());
|
|
}
|
|
if ((stream._duplexState & OPEN_STATUS) !== 0) return cb(null);
|
|
stream._writev(buffer, cb);
|
|
}
|
|
update() {
|
|
const stream = this.stream;
|
|
stream._duplexState |= WRITE_UPDATING;
|
|
do {
|
|
while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED) {
|
|
const data = this.shift();
|
|
stream._duplexState |= WRITE_ACTIVE_AND_WRITING;
|
|
stream._write(data, this.afterWrite);
|
|
}
|
|
if ((stream._duplexState & WRITE_PRIMARY_AND_ACTIVE) === 0) this.updateNonPrimary();
|
|
} while (this.continueUpdate() === true);
|
|
stream._duplexState &= WRITE_NOT_UPDATING;
|
|
}
|
|
updateNonPrimary() {
|
|
const stream = this.stream;
|
|
if ((stream._duplexState & WRITE_FINISHING_STATUS) === WRITE_FINISHING) {
|
|
stream._duplexState = stream._duplexState | WRITE_ACTIVE;
|
|
stream._final(afterFinal.bind(this));
|
|
return;
|
|
}
|
|
if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) {
|
|
if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) {
|
|
stream._duplexState |= ACTIVE;
|
|
stream._destroy(afterDestroy.bind(this));
|
|
}
|
|
return;
|
|
}
|
|
if ((stream._duplexState & IS_OPENING) === OPENING) {
|
|
stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING;
|
|
stream._open(afterOpen.bind(this));
|
|
}
|
|
}
|
|
continueUpdate() {
|
|
if ((this.stream._duplexState & WRITE_NEXT_TICK) === 0) return false;
|
|
this.stream._duplexState &= WRITE_NOT_NEXT_TICK;
|
|
return true;
|
|
}
|
|
updateCallback() {
|
|
if ((this.stream._duplexState & WRITE_UPDATE_SYNC_STATUS) === WRITE_PRIMARY) {
|
|
this.update();
|
|
} else {
|
|
this.updateNextTick();
|
|
}
|
|
}
|
|
updateNextTick() {
|
|
if ((this.stream._duplexState & WRITE_NEXT_TICK) !== 0) return;
|
|
this.stream._duplexState |= WRITE_NEXT_TICK;
|
|
if ((this.stream._duplexState & WRITE_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
}
|
|
};
|
|
var ReadableState = class {
|
|
constructor(stream, { highWaterMark = 16384, map = null, mapReadable, byteLength, byteLengthReadable } = {}) {
|
|
this.stream = stream;
|
|
this.queue = new FIFO();
|
|
this.highWaterMark = highWaterMark === 0 ? 1 : highWaterMark;
|
|
this.buffered = 0;
|
|
this.readAhead = highWaterMark > 0;
|
|
this.error = null;
|
|
this.pipeline = null;
|
|
this.byteLength = byteLengthReadable || byteLength || defaultByteLength;
|
|
this.map = mapReadable || map;
|
|
this.pipeTo = null;
|
|
this.afterRead = afterRead.bind(this);
|
|
this.afterUpdateNextTick = updateReadNT.bind(this);
|
|
}
|
|
get ending() {
|
|
return (this.stream._duplexState & READ_ENDING) !== 0;
|
|
}
|
|
get ended() {
|
|
return (this.stream._duplexState & READ_DONE) !== 0;
|
|
}
|
|
pipe(pipeTo, cb) {
|
|
if (this.pipeTo !== null) throw StreamError.BAD_ARGUMENT("Can only pipe to one destination");
|
|
if (typeof cb !== "function") cb = null;
|
|
this.stream._duplexState |= READ_PIPE_DRAINED;
|
|
this.pipeTo = pipeTo;
|
|
this.pipeline = new Pipeline(this.stream, pipeTo, cb);
|
|
if (cb) this.stream.on("error", noop);
|
|
if (isStreamx(pipeTo)) {
|
|
pipeTo._writableState.pipeline = this.pipeline;
|
|
if (cb) pipeTo.on("error", noop);
|
|
pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline));
|
|
} else {
|
|
const onerror = this.pipeline.done.bind(this.pipeline, pipeTo);
|
|
const onclose = this.pipeline.done.bind(this.pipeline, pipeTo, null);
|
|
pipeTo.on("error", onerror);
|
|
pipeTo.on("close", onclose);
|
|
pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline));
|
|
}
|
|
pipeTo.on("drain", afterDrain.bind(this));
|
|
this.stream.emit("piping", pipeTo);
|
|
pipeTo.emit("pipe", this.stream);
|
|
}
|
|
push(data) {
|
|
const stream = this.stream;
|
|
if (data === null) {
|
|
this.highWaterMark = 0;
|
|
stream._duplexState = (stream._duplexState | READ_ENDING) & READ_NON_PRIMARY_AND_PUSHED;
|
|
return false;
|
|
}
|
|
if (this.map !== null) {
|
|
data = this.map(data);
|
|
if (data === null) {
|
|
stream._duplexState &= READ_PUSHED;
|
|
return this.buffered < this.highWaterMark;
|
|
}
|
|
}
|
|
this.buffered += this.byteLength(data);
|
|
this.queue.push(data);
|
|
stream._duplexState = (stream._duplexState | READ_QUEUED) & READ_PUSHED;
|
|
return this.buffered < this.highWaterMark;
|
|
}
|
|
shift() {
|
|
const data = this.queue.shift();
|
|
this.buffered -= this.byteLength(data);
|
|
if (this.buffered === 0) {
|
|
this.stream._duplexState &= READ_NOT_QUEUED;
|
|
}
|
|
return data;
|
|
}
|
|
unshift(data) {
|
|
const pending = [this.map !== null ? this.map(data) : data];
|
|
while (this.buffered > 0) pending.push(this.shift());
|
|
for (let i = 0; i < pending.length - 1; i++) {
|
|
const data2 = pending[i];
|
|
this.buffered += this.byteLength(data2);
|
|
this.queue.push(data2);
|
|
}
|
|
this.push(pending[pending.length - 1]);
|
|
}
|
|
read() {
|
|
const stream = this.stream;
|
|
if ((stream._duplexState & READ_STATUS) === READ_QUEUED) {
|
|
const data = this.shift();
|
|
if (this.pipeTo !== null && this.pipeTo.write(data) === false) {
|
|
stream._duplexState &= READ_PIPE_NOT_DRAINED;
|
|
}
|
|
if ((stream._duplexState & READ_EMIT_DATA) !== 0) {
|
|
stream.emit("data", data);
|
|
}
|
|
return data;
|
|
}
|
|
if (this.readAhead === false) {
|
|
stream._duplexState |= READ_READ_AHEAD;
|
|
this.updateNextTick();
|
|
}
|
|
return null;
|
|
}
|
|
drain() {
|
|
const stream = this.stream;
|
|
while ((stream._duplexState & READ_STATUS) === READ_QUEUED && (stream._duplexState & READ_FLOWING) !== 0) {
|
|
const data = this.shift();
|
|
if (this.pipeTo !== null && this.pipeTo.write(data) === false) {
|
|
stream._duplexState &= READ_PIPE_NOT_DRAINED;
|
|
}
|
|
if ((stream._duplexState & READ_EMIT_DATA) !== 0) {
|
|
stream.emit("data", data);
|
|
}
|
|
}
|
|
}
|
|
update() {
|
|
const stream = this.stream;
|
|
stream._duplexState |= READ_UPDATING;
|
|
do {
|
|
this.drain();
|
|
while (this.buffered < this.highWaterMark && (stream._duplexState & SHOULD_NOT_READ) === READ_READ_AHEAD) {
|
|
stream._duplexState |= READ_ACTIVE_AND_NEEDS_PUSH;
|
|
stream._read(this.afterRead);
|
|
this.drain();
|
|
}
|
|
if ((stream._duplexState & READ_READABLE_STATUS) === READ_EMIT_READABLE_AND_QUEUED) {
|
|
stream._duplexState |= READ_EMITTED_READABLE;
|
|
stream.emit("readable");
|
|
}
|
|
if ((stream._duplexState & READ_PRIMARY_AND_ACTIVE) === 0) {
|
|
this.updateNonPrimary();
|
|
}
|
|
} while (this.continueUpdate() === true);
|
|
stream._duplexState &= READ_NOT_UPDATING;
|
|
}
|
|
updateNonPrimary() {
|
|
const stream = this.stream;
|
|
if ((stream._duplexState & READ_ENDING_STATUS) === READ_ENDING) {
|
|
stream._duplexState = (stream._duplexState | READ_DONE) & READ_NOT_ENDING;
|
|
stream.emit("end");
|
|
if ((stream._duplexState & AUTO_DESTROY) === DONE) {
|
|
stream._duplexState |= DESTROYING;
|
|
}
|
|
if (this.pipeTo !== null) {
|
|
this.pipeTo.end();
|
|
}
|
|
}
|
|
if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) {
|
|
if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) {
|
|
stream._duplexState |= ACTIVE;
|
|
stream._destroy(afterDestroy.bind(this));
|
|
}
|
|
return;
|
|
}
|
|
if ((stream._duplexState & IS_OPENING) === OPENING) {
|
|
stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING;
|
|
stream._open(afterOpen.bind(this));
|
|
}
|
|
}
|
|
continueUpdate() {
|
|
if ((this.stream._duplexState & READ_NEXT_TICK) === 0) return false;
|
|
this.stream._duplexState &= READ_NOT_NEXT_TICK;
|
|
return true;
|
|
}
|
|
updateCallback() {
|
|
if ((this.stream._duplexState & READ_UPDATE_SYNC_STATUS) === READ_PRIMARY) {
|
|
this.update();
|
|
} else {
|
|
this.updateNextTick();
|
|
}
|
|
}
|
|
updateNextTickIfOpen() {
|
|
if ((this.stream._duplexState & READ_NEXT_TICK_OR_OPENING) !== 0) return;
|
|
this.stream._duplexState |= READ_NEXT_TICK;
|
|
if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
}
|
|
updateNextTick() {
|
|
if ((this.stream._duplexState & READ_NEXT_TICK) !== 0) return;
|
|
this.stream._duplexState |= READ_NEXT_TICK;
|
|
if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
}
|
|
};
|
|
var TransformState = class {
|
|
constructor(stream) {
|
|
this.data = null;
|
|
this.afterTransform = afterTransform.bind(stream);
|
|
this.afterFinal = null;
|
|
}
|
|
};
|
|
var Pipeline = class {
|
|
constructor(src, dst, cb) {
|
|
this.from = src;
|
|
this.to = dst;
|
|
this.afterPipe = cb;
|
|
this.error = null;
|
|
this.pipeToFinished = false;
|
|
}
|
|
finished() {
|
|
this.pipeToFinished = true;
|
|
}
|
|
done(stream, err) {
|
|
if (err) this.error = err;
|
|
if (stream === this.to) {
|
|
this.to = null;
|
|
if (this.from !== null) {
|
|
if ((this.from._duplexState & READ_DONE) === 0 || !this.pipeToFinished) {
|
|
this.from.destroy(this.error || StreamError.PREMATURE_CLOSE("Writable stream closed"));
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
if (stream === this.from) {
|
|
this.from = null;
|
|
if (this.to !== null) {
|
|
if ((stream._duplexState & READ_DONE) === 0) {
|
|
this.to.destroy(this.error || StreamError.PREMATURE_CLOSE("Readable stream closed"));
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
if (this.afterPipe !== null) this.afterPipe(this.error);
|
|
this.to = this.from = this.afterPipe = null;
|
|
}
|
|
};
|
|
function afterDrain() {
|
|
this.stream._duplexState |= READ_PIPE_DRAINED;
|
|
this.updateCallback();
|
|
}
|
|
function afterFinal(err) {
|
|
const stream = this.stream;
|
|
if (err) stream.destroy(err);
|
|
if ((stream._duplexState & DESTROY_STATUS) === 0) {
|
|
stream._duplexState |= WRITE_DONE;
|
|
stream.emit("finish");
|
|
}
|
|
if ((stream._duplexState & AUTO_DESTROY) === DONE) {
|
|
stream._duplexState |= DESTROYING;
|
|
}
|
|
stream._duplexState &= WRITE_NOT_FINISHING;
|
|
if ((stream._duplexState & WRITE_UPDATING) === 0) {
|
|
this.update();
|
|
} else {
|
|
this.updateNextTick();
|
|
}
|
|
}
|
|
function afterDestroy(err) {
|
|
const stream = this.stream;
|
|
if (!err && !StreamError.isStreamDestroyed(this.error)) err = this.error;
|
|
if (err) stream.emit("error", err);
|
|
stream._duplexState |= DESTROYED;
|
|
stream.emit("close");
|
|
const rs = stream._readableState;
|
|
const ws = stream._writableState;
|
|
if (rs !== null && rs.pipeline !== null) {
|
|
rs.pipeline.done(stream, err);
|
|
}
|
|
if (ws !== null) {
|
|
while (ws.drains !== null && ws.drains.length > 0) {
|
|
ws.drains.shift().resolve(false);
|
|
}
|
|
if (ws.pipeline !== null) {
|
|
ws.pipeline.done(stream, err);
|
|
}
|
|
}
|
|
}
|
|
function afterWrite(err) {
|
|
const stream = this.stream;
|
|
if (err) stream.destroy(err);
|
|
stream._duplexState &= WRITE_NOT_ACTIVE;
|
|
if (this.drains !== null) tickDrains(this.drains);
|
|
if ((stream._duplexState & WRITE_DRAIN_STATUS) === WRITE_UNDRAINED) {
|
|
stream._duplexState &= WRITE_DRAINED;
|
|
if ((stream._duplexState & WRITE_EMIT_DRAIN) === WRITE_EMIT_DRAIN) {
|
|
stream.emit("drain");
|
|
}
|
|
}
|
|
this.updateCallback();
|
|
}
|
|
function afterRead(err) {
|
|
if (err) this.stream.destroy(err);
|
|
this.stream._duplexState &= READ_NOT_ACTIVE;
|
|
if (this.readAhead === false && (this.stream._duplexState & READ_RESUMED) === 0) {
|
|
this.stream._duplexState &= READ_NO_READ_AHEAD;
|
|
}
|
|
this.updateCallback();
|
|
}
|
|
function updateReadNT() {
|
|
if ((this.stream._duplexState & READ_UPDATING) === 0) {
|
|
this.stream._duplexState &= READ_NOT_NEXT_TICK;
|
|
this.update();
|
|
}
|
|
}
|
|
function updateWriteNT() {
|
|
if ((this.stream._duplexState & WRITE_UPDATING) === 0) {
|
|
this.stream._duplexState &= WRITE_NOT_NEXT_TICK;
|
|
this.update();
|
|
}
|
|
}
|
|
function tickDrains(drains) {
|
|
for (let i = 0; i < drains.length; i++) {
|
|
if (--drains[i].writes === 0) {
|
|
drains.shift().resolve(true);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
function afterOpen(err) {
|
|
const stream = this.stream;
|
|
if (err) stream.destroy(err);
|
|
if ((stream._duplexState & DESTROYING) === 0) {
|
|
if ((stream._duplexState & READ_PRIMARY_STATUS) === 0) {
|
|
stream._duplexState |= READ_PRIMARY;
|
|
}
|
|
if ((stream._duplexState & WRITE_PRIMARY_STATUS) === 0) {
|
|
stream._duplexState |= WRITE_PRIMARY;
|
|
}
|
|
stream.emit("open");
|
|
}
|
|
stream._duplexState &= NOT_ACTIVE;
|
|
if (stream._writableState !== null) {
|
|
stream._writableState.updateCallback();
|
|
}
|
|
if (stream._readableState !== null) {
|
|
stream._readableState.updateCallback();
|
|
}
|
|
}
|
|
function afterTransform(err, data) {
|
|
if (data !== void 0 && data !== null) this.push(data);
|
|
this._writableState.afterWrite(err);
|
|
}
|
|
function newListener(name) {
|
|
if (this._readableState !== null) {
|
|
if (name === "data") {
|
|
this._duplexState |= READ_EMIT_DATA | READ_RESUMED_READ_AHEAD;
|
|
this._readableState.updateNextTick();
|
|
}
|
|
if (name === "readable") {
|
|
this._duplexState |= READ_EMIT_READABLE;
|
|
this._readableState.updateNextTick();
|
|
}
|
|
}
|
|
if (this._writableState !== null) {
|
|
if (name === "drain") {
|
|
this._duplexState |= WRITE_EMIT_DRAIN;
|
|
this._writableState.updateNextTick();
|
|
}
|
|
}
|
|
}
|
|
var Stream = class extends EventEmitter {
|
|
constructor(opts) {
|
|
super();
|
|
this._duplexState = 0;
|
|
this._readableState = null;
|
|
this._writableState = null;
|
|
if (opts) {
|
|
if (opts.open) this._open = opts.open;
|
|
if (opts.destroy) this._destroy = opts.destroy;
|
|
if (opts.predestroy) this._predestroy = opts.predestroy;
|
|
if (opts.signal) opts.signal.addEventListener("abort", abort.bind(this));
|
|
}
|
|
this.on("newListener", newListener);
|
|
}
|
|
_open(cb) {
|
|
cb(null);
|
|
}
|
|
_destroy(cb) {
|
|
cb(null);
|
|
}
|
|
_predestroy() {
|
|
}
|
|
get readable() {
|
|
return this._readableState !== null ? true : void 0;
|
|
}
|
|
get writable() {
|
|
return this._writableState !== null ? true : void 0;
|
|
}
|
|
get destroyed() {
|
|
return (this._duplexState & DESTROYED) !== 0;
|
|
}
|
|
get destroying() {
|
|
return (this._duplexState & DESTROY_STATUS) !== 0;
|
|
}
|
|
destroy(err) {
|
|
if ((this._duplexState & DESTROY_STATUS) === 0) {
|
|
if (!err) err = StreamError.STREAM_DESTROYED();
|
|
this._duplexState = (this._duplexState | DESTROYING) & NON_PRIMARY;
|
|
if (this._readableState !== null) {
|
|
this._readableState.highWaterMark = 0;
|
|
this._readableState.error = err;
|
|
}
|
|
if (this._writableState !== null) {
|
|
this._writableState.highWaterMark = 0;
|
|
this._writableState.error = err;
|
|
}
|
|
this._duplexState |= PREDESTROYING;
|
|
this._predestroy();
|
|
this._duplexState &= NOT_PREDESTROYING;
|
|
if (this._readableState !== null) {
|
|
this._readableState.updateNextTick();
|
|
}
|
|
if (this._writableState !== null) {
|
|
this._writableState.updateNextTick();
|
|
}
|
|
}
|
|
}
|
|
};
|
|
var Readable = class _Readable extends Stream {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._duplexState |= OPENING | WRITE_DONE | READ_READ_AHEAD;
|
|
this._readableState = new ReadableState(this, opts);
|
|
if (opts) {
|
|
if (this._readableState.readAhead === false) this._duplexState &= READ_NO_READ_AHEAD;
|
|
if (opts.read) this._read = opts.read;
|
|
if (opts.eagerOpen) this._readableState.updateNextTick();
|
|
if (opts.encoding) this.setEncoding(opts.encoding);
|
|
}
|
|
}
|
|
static deferred(fn, opts) {
|
|
const out = new PassThrough(opts);
|
|
fn().then((src) => {
|
|
if (src === null) return out.end();
|
|
if (out.destroying) return;
|
|
pipeline(src, out, noop);
|
|
}).catch((err) => out.destroy(err));
|
|
return out;
|
|
}
|
|
setEncoding(encoding) {
|
|
const dec = new TextDecoder(encoding);
|
|
const map = this._readableState.map || echo;
|
|
this._readableState.map = mapOrSkip;
|
|
return this;
|
|
function mapOrSkip(data) {
|
|
const next = dec.push(data);
|
|
return next === "" && (data.byteLength !== 0 || dec.remaining > 0) ? null : map(next);
|
|
}
|
|
}
|
|
_read(cb) {
|
|
cb(null);
|
|
}
|
|
pipe(dest, cb) {
|
|
this._readableState.updateNextTick();
|
|
this._readableState.pipe(dest, cb);
|
|
return dest;
|
|
}
|
|
read() {
|
|
this._readableState.updateNextTick();
|
|
return this._readableState.read();
|
|
}
|
|
push(data) {
|
|
this._readableState.updateNextTickIfOpen();
|
|
return this._readableState.push(data);
|
|
}
|
|
unshift(data) {
|
|
this._readableState.updateNextTickIfOpen();
|
|
return this._readableState.unshift(data);
|
|
}
|
|
resume() {
|
|
this._duplexState |= READ_RESUMED_READ_AHEAD;
|
|
this._readableState.updateNextTick();
|
|
return this;
|
|
}
|
|
pause() {
|
|
this._duplexState &= this._readableState.readAhead === false ? READ_PAUSED_NO_READ_AHEAD : READ_PAUSED;
|
|
return this;
|
|
}
|
|
static _fromAsyncIterator(ite, opts) {
|
|
let destroy;
|
|
const rs = new _Readable({
|
|
...opts,
|
|
read(cb) {
|
|
ite.next().then(push).then(cb.bind(null, null)).catch(cb);
|
|
},
|
|
predestroy() {
|
|
destroy = ite.return();
|
|
},
|
|
destroy(cb) {
|
|
if (!destroy) return cb(null);
|
|
destroy.then(cb.bind(null, null)).catch(cb);
|
|
}
|
|
});
|
|
return rs;
|
|
function push(data) {
|
|
if (data.done) rs.push(null);
|
|
else rs.push(data.value);
|
|
}
|
|
}
|
|
static from(data, opts) {
|
|
if (isReadStreamx(data)) return data;
|
|
if (data[asyncIterator]) return this._fromAsyncIterator(data[asyncIterator](), opts);
|
|
if (!Array.isArray(data)) data = data === void 0 ? [] : [data];
|
|
let i = 0;
|
|
return new _Readable({
|
|
...opts,
|
|
read(cb) {
|
|
this.push(i === data.length ? null : data[i++]);
|
|
cb(null);
|
|
}
|
|
});
|
|
}
|
|
static isBackpressured(rs) {
|
|
return (rs._duplexState & READ_BACKPRESSURE_STATUS) !== 0 || rs._readableState.buffered >= rs._readableState.highWaterMark;
|
|
}
|
|
static isPaused(rs) {
|
|
return (rs._duplexState & READ_RESUMED) === 0;
|
|
}
|
|
[asyncIterator]() {
|
|
const stream = this;
|
|
let error = null;
|
|
let promiseResolve = null;
|
|
let promiseReject = null;
|
|
this.on("error", (err) => {
|
|
error = err;
|
|
});
|
|
this.on("readable", onreadable);
|
|
this.on("close", onclose);
|
|
return {
|
|
[asyncIterator]() {
|
|
return this;
|
|
},
|
|
next() {
|
|
return new Promise(function(resolve, reject) {
|
|
promiseResolve = resolve;
|
|
promiseReject = reject;
|
|
const data = stream.read();
|
|
if (data !== null) ondata(data);
|
|
else if ((stream._duplexState & DESTROYED) !== 0) ondata(null);
|
|
});
|
|
},
|
|
return() {
|
|
return destroy(null);
|
|
},
|
|
throw(err) {
|
|
return destroy(err);
|
|
}
|
|
};
|
|
function onreadable() {
|
|
if (promiseResolve !== null) ondata(stream.read());
|
|
}
|
|
function onclose() {
|
|
if (promiseResolve !== null) ondata(null);
|
|
}
|
|
function ondata(data) {
|
|
if (promiseReject === null) return;
|
|
if (error) {
|
|
promiseReject(error);
|
|
} else if (data === null && (stream._duplexState & READ_DONE) === 0) {
|
|
promiseReject(StreamError.STREAM_DESTROYED());
|
|
} else {
|
|
promiseResolve({ value: data, done: data === null });
|
|
}
|
|
promiseReject = promiseResolve = null;
|
|
}
|
|
function destroy(err) {
|
|
stream.destroy(err);
|
|
return new Promise((resolve, reject) => {
|
|
if (stream._duplexState & DESTROYED) return resolve({ value: void 0, done: true });
|
|
stream.once("close", function() {
|
|
if (err) reject(err);
|
|
else resolve({ value: void 0, done: true });
|
|
});
|
|
});
|
|
}
|
|
}
|
|
};
|
|
var Writable = class extends Stream {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._duplexState |= OPENING | READ_DONE;
|
|
this._writableState = new WritableState(this, opts);
|
|
if (opts) {
|
|
if (opts.writev) this._writev = opts.writev;
|
|
if (opts.write) this._write = opts.write;
|
|
if (opts.final) this._final = opts.final;
|
|
if (opts.eagerOpen) this._writableState.updateNextTick();
|
|
}
|
|
}
|
|
cork() {
|
|
this._duplexState |= WRITE_CORKED;
|
|
}
|
|
uncork() {
|
|
this._duplexState &= WRITE_NOT_CORKED;
|
|
this._writableState.updateNextTick();
|
|
}
|
|
_writev(batch, cb) {
|
|
cb(null);
|
|
}
|
|
_write(data, cb) {
|
|
this._writableState.autoBatch(data, cb);
|
|
}
|
|
_final(cb) {
|
|
cb(null);
|
|
}
|
|
static isBackpressured(ws) {
|
|
return (ws._duplexState & WRITE_BACKPRESSURE_STATUS) !== 0;
|
|
}
|
|
static drained(ws) {
|
|
if (ws.destroyed) return Promise.resolve(false);
|
|
const state = ws._writableState;
|
|
const pending = isWritev(ws) ? Math.min(1, state.queue.length) : state.queue.length;
|
|
const writes = pending + (ws._duplexState & WRITE_WRITING ? 1 : 0);
|
|
if (writes === 0) return Promise.resolve(true);
|
|
if (state.drains === null) state.drains = [];
|
|
return new Promise((resolve) => {
|
|
state.drains.push({ writes, resolve });
|
|
});
|
|
}
|
|
write(data) {
|
|
this._writableState.updateNextTick();
|
|
return this._writableState.push(data);
|
|
}
|
|
end(data) {
|
|
this._writableState.updateNextTick();
|
|
this._writableState.end(data);
|
|
return this;
|
|
}
|
|
};
|
|
var Duplex = class extends Readable {
|
|
// and Writable
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._duplexState = OPENING | this._duplexState & READ_READ_AHEAD;
|
|
this._writableState = new WritableState(this, opts);
|
|
if (opts) {
|
|
if (opts.writev) this._writev = opts.writev;
|
|
if (opts.write) this._write = opts.write;
|
|
if (opts.final) this._final = opts.final;
|
|
}
|
|
}
|
|
cork() {
|
|
this._duplexState |= WRITE_CORKED;
|
|
}
|
|
uncork() {
|
|
this._duplexState &= WRITE_NOT_CORKED;
|
|
this._writableState.updateNextTick();
|
|
}
|
|
_writev(batch, cb) {
|
|
cb(null);
|
|
}
|
|
_write(data, cb) {
|
|
this._writableState.autoBatch(data, cb);
|
|
}
|
|
_final(cb) {
|
|
cb(null);
|
|
}
|
|
write(data) {
|
|
this._writableState.updateNextTick();
|
|
return this._writableState.push(data);
|
|
}
|
|
end(data) {
|
|
this._writableState.updateNextTick();
|
|
this._writableState.end(data);
|
|
return this;
|
|
}
|
|
};
|
|
var Transform = class extends Duplex {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._transformState = new TransformState(this);
|
|
if (opts) {
|
|
if (opts.transform) this._transform = opts.transform;
|
|
if (opts.flush) this._flush = opts.flush;
|
|
}
|
|
}
|
|
_write(data, cb) {
|
|
if (this._readableState.buffered >= this._readableState.highWaterMark) {
|
|
this._transformState.data = data;
|
|
} else {
|
|
this._transform(data, this._transformState.afterTransform);
|
|
}
|
|
}
|
|
_read(cb) {
|
|
if (this._transformState.data !== null) {
|
|
const data = this._transformState.data;
|
|
this._transformState.data = null;
|
|
cb(null);
|
|
this._transform(data, this._transformState.afterTransform);
|
|
} else {
|
|
cb(null);
|
|
}
|
|
}
|
|
destroy(err) {
|
|
super.destroy(err);
|
|
if (this._transformState.data !== null) {
|
|
this._transformState.data = null;
|
|
this._transformState.afterTransform();
|
|
}
|
|
}
|
|
_transform(data, cb) {
|
|
cb(null, data);
|
|
}
|
|
_flush(cb) {
|
|
cb(null);
|
|
}
|
|
_final(cb) {
|
|
this._transformState.afterFinal = cb;
|
|
this._flush(transformAfterFlush.bind(this));
|
|
}
|
|
};
|
|
var PassThrough = class extends Transform {
|
|
};
|
|
function transformAfterFlush(err, data) {
|
|
const cb = this._transformState.afterFinal;
|
|
if (err) return cb(err);
|
|
if (data !== null && data !== void 0) this.push(data);
|
|
this.push(null);
|
|
cb(null);
|
|
}
|
|
function pipelinePromise(...streams) {
|
|
return new Promise((resolve, reject) => {
|
|
return pipeline(...streams, (err) => {
|
|
if (err) return reject(err);
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
function pipeline(stream, ...streams) {
|
|
const all = Array.isArray(stream) ? [...stream, ...streams] : [stream, ...streams];
|
|
const done = all.length && typeof all[all.length - 1] === "function" ? all.pop() : null;
|
|
if (all.length < 2) throw StreamError.BAD_ARGUMENT("Pipeline requires at least 2 streams");
|
|
let src = all[0];
|
|
let dest = null;
|
|
let error = null;
|
|
for (let i = 1; i < all.length; i++) {
|
|
dest = all[i];
|
|
if (isStreamx(src)) {
|
|
src.pipe(dest, onerror);
|
|
} else {
|
|
errorHandle(src, true, i > 1, onerror);
|
|
src.pipe(dest);
|
|
}
|
|
src = dest;
|
|
}
|
|
if (done) {
|
|
let fin = false;
|
|
const autoDestroy = isStreamx(dest) || !!(dest._writableState && dest._writableState.autoDestroy);
|
|
dest.on("error", (err) => {
|
|
if (error === null) error = err;
|
|
});
|
|
dest.on("finish", () => {
|
|
fin = true;
|
|
if (!autoDestroy) done(error);
|
|
});
|
|
if (autoDestroy) {
|
|
dest.on("close", () => done(error || (fin ? null : StreamError.PREMATURE_CLOSE())));
|
|
}
|
|
}
|
|
return dest;
|
|
function errorHandle(s, rd, wr, onerror2) {
|
|
s.on("error", onerror2);
|
|
s.on("close", onclose);
|
|
function onclose() {
|
|
if (rd && s._readableState && !s._readableState.ended) {
|
|
return onerror2(StreamError.PREMATURE_CLOSE());
|
|
}
|
|
if (wr && s._writableState && !s._writableState.ended) {
|
|
return onerror2(StreamError.PREMATURE_CLOSE());
|
|
}
|
|
}
|
|
}
|
|
function onerror(err) {
|
|
if (!err || error) return;
|
|
error = err;
|
|
for (const s of all) {
|
|
s.destroy(err);
|
|
}
|
|
}
|
|
}
|
|
function echo(s) {
|
|
return s;
|
|
}
|
|
function isStream(stream) {
|
|
return !!stream._readableState || !!stream._writableState;
|
|
}
|
|
function isStreamx(stream) {
|
|
return typeof stream._duplexState === "number" && isStream(stream);
|
|
}
|
|
function isEnding(stream) {
|
|
return !!stream._readableState && stream._readableState.ending;
|
|
}
|
|
function isEnded(stream) {
|
|
return !!stream._readableState && stream._readableState.ended;
|
|
}
|
|
function isFinishing(stream) {
|
|
return !!stream._writableState && stream._writableState.ending;
|
|
}
|
|
function isFinished(stream) {
|
|
return !!stream._writableState && stream._writableState.ended;
|
|
}
|
|
function getStreamError(stream, opts = {}) {
|
|
const err = stream._readableState && stream._readableState.error || stream._writableState && stream._writableState.error;
|
|
return !opts.all && StreamError.isStreamDestroyed(err) ? null : err;
|
|
}
|
|
function isReadStreamx(stream) {
|
|
return isStreamx(stream) && stream.readable;
|
|
}
|
|
function isDisturbed(stream) {
|
|
return (stream._duplexState & OPENING) !== OPENING || (stream._duplexState & DESTROYING) === DESTROYING || (stream._duplexState & ACTIVE_OR_TICKING) !== 0;
|
|
}
|
|
function isTypedArray(data) {
|
|
return typeof data === "object" && data !== null && typeof data.byteLength === "number";
|
|
}
|
|
function defaultByteLength(data) {
|
|
return isTypedArray(data) ? data.byteLength : 1024;
|
|
}
|
|
function noop() {
|
|
}
|
|
function abort() {
|
|
this.destroy(StreamError.ABORTED());
|
|
}
|
|
function isWritev(s) {
|
|
return s._writev !== Writable.prototype._writev && s._writev !== Duplex.prototype._writev;
|
|
}
|
|
module.exports = {
|
|
pipeline,
|
|
pipelinePromise,
|
|
isStream,
|
|
isStreamx,
|
|
isEnding,
|
|
isEnded,
|
|
isFinishing,
|
|
isFinished,
|
|
isDisturbed,
|
|
getStreamError,
|
|
Stream,
|
|
Writable,
|
|
Readable,
|
|
Duplex,
|
|
Transform,
|
|
// Export PassThrough for compatibility with Node.js core's stream module
|
|
PassThrough
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/teex/index.js
|
|
var require_teex = __commonJS({
|
|
"../../node_modules/teex/index.js"(exports, module) {
|
|
var { Readable } = require_streamx();
|
|
module.exports = function(s, forks = 2) {
|
|
const streams = new Array(forks);
|
|
const status = new Array(forks).fill(true);
|
|
let ended = false;
|
|
for (let i = 0; i < forks; i++) {
|
|
streams[i] = new Readable({
|
|
read(cb) {
|
|
const check = !status[i];
|
|
status[i] = true;
|
|
if (check && allReadable()) s.resume();
|
|
cb(null);
|
|
}
|
|
});
|
|
}
|
|
s.on("end", function() {
|
|
ended = true;
|
|
for (const stream of streams) stream.push(null);
|
|
});
|
|
s.on("error", function(err) {
|
|
for (const stream of streams) stream.destroy(err);
|
|
});
|
|
s.on("close", function() {
|
|
if (ended) return;
|
|
for (const stream of streams) stream.destroy();
|
|
});
|
|
s.on("data", function(data) {
|
|
let needsPause = false;
|
|
for (let i = 0; i < streams.length; i++) {
|
|
if (!(status[i] = streams[i].push(data))) {
|
|
needsPause = true;
|
|
}
|
|
}
|
|
if (needsPause) s.pause();
|
|
});
|
|
return streams;
|
|
function allReadable() {
|
|
for (let j = 0; j < status.length; j++) {
|
|
if (!status[j]) return false;
|
|
}
|
|
return true;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-stream/web.js
|
|
var require_web = __commonJS({
|
|
"../../node_modules/bare-stream/web.js"(exports) {
|
|
var { Readable, Writable, Transform, getStreamError, isStreamx, isDisturbed } = require_streamx();
|
|
var tee = require_teex();
|
|
var readableKind = Symbol.for("bare.stream.readable.kind");
|
|
var writableKind = Symbol.for("bare.stream.writable.kind");
|
|
var transformKind = Symbol.for("bare.stream.transform.kind");
|
|
exports.ReadableStreamDefaultReader = class ReadableStreamDefaultReader {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
this._stream._stream.once("close", onclose).once("error", onerror);
|
|
const closed = Promise.withResolvers();
|
|
closed.promise.catch(noop);
|
|
this._closed = closed;
|
|
function onclose() {
|
|
closed.resolve();
|
|
}
|
|
function onerror(err) {
|
|
closed.reject(err);
|
|
}
|
|
}
|
|
get closed() {
|
|
return this._closed.promise;
|
|
}
|
|
read() {
|
|
const stream = this._stream._stream;
|
|
return new Promise((resolve, reject) => {
|
|
const err = getStreamError(stream);
|
|
if (err) return reject(err);
|
|
if (stream.destroyed) {
|
|
return resolve({ value: void 0, done: true });
|
|
}
|
|
const value = stream.read();
|
|
if (value !== null) {
|
|
return resolve({ value, done: false });
|
|
}
|
|
stream.once("readable", onreadable).once("close", onclose).once("error", onerror);
|
|
function onreadable() {
|
|
const value2 = stream.read();
|
|
ondone(null, value2 === null ? { value: void 0, done: true } : { value: value2, done: false });
|
|
}
|
|
function onclose() {
|
|
ondone(null, { value: void 0, done: true });
|
|
}
|
|
function onerror(err2) {
|
|
ondone(err2, null);
|
|
}
|
|
function ondone(err2, value2) {
|
|
stream.off("readable", onreadable).off("close", onclose).off("error", onerror);
|
|
if (err2) reject(err2);
|
|
else resolve(value2);
|
|
}
|
|
});
|
|
}
|
|
releaseLock() {
|
|
this._closed.reject(new TypeError("Reader was released"));
|
|
this._stream._releaseLock();
|
|
this._stream = null;
|
|
}
|
|
cancel(reason = new TypeError("Stream was cancelled")) {
|
|
const stream = this._stream._stream;
|
|
if (stream.destroyed) return Promise.resolve();
|
|
return new Promise(
|
|
(resolve) => stream.once("close", resolve).once("error", noop).destroy(reason)
|
|
);
|
|
}
|
|
};
|
|
exports.ReadableStreamDefaultController = class ReadableStreamDefaultController {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
}
|
|
get desiredSize() {
|
|
const stream = this._stream._stream;
|
|
return stream._readableState.highWaterMark - stream._readableState.buffered;
|
|
}
|
|
enqueue(data) {
|
|
this._stream._stream.push(data);
|
|
}
|
|
close() {
|
|
this._stream._stream.push(null);
|
|
}
|
|
error(err) {
|
|
this._stream._stream.destroy(err);
|
|
}
|
|
};
|
|
var ReadableStream = class _ReadableStream {
|
|
static get [readableKind]() {
|
|
return 0;
|
|
}
|
|
static from(iterable) {
|
|
return new _ReadableStream(Readable.from(iterable));
|
|
}
|
|
constructor(underlyingSource = {}, queuingStrategy) {
|
|
if (isStreamx(underlyingSource)) {
|
|
this._stream = underlyingSource;
|
|
} else {
|
|
if (queuingStrategy === void 0) {
|
|
queuingStrategy = new exports.CountQueuingStrategy();
|
|
}
|
|
const { start, pull, cancel } = underlyingSource;
|
|
const { highWaterMark = 1, size = defaultSize } = queuingStrategy;
|
|
this._stream = new Readable({ highWaterMark, byteLength: size });
|
|
const controller = new exports.ReadableStreamDefaultController(this);
|
|
try {
|
|
let starting = Promise.resolve();
|
|
if (start) starting = forwardError(start.call(this, controller), controller);
|
|
if (pull) {
|
|
this._stream._read = this._read.bind(this, starting, pull.bind(this, controller));
|
|
}
|
|
if (cancel) {
|
|
this._stream.once("error", cancel.bind(this));
|
|
}
|
|
} catch (err) {
|
|
controller.error(err);
|
|
}
|
|
}
|
|
this._reader = null;
|
|
}
|
|
get [readableKind]() {
|
|
return _ReadableStream[readableKind];
|
|
}
|
|
get locked() {
|
|
return this._reader !== null;
|
|
}
|
|
getReader() {
|
|
if (this.locked) throw new TypeError("Stream is locked");
|
|
this._reader = new exports.ReadableStreamDefaultReader(this);
|
|
return this._reader;
|
|
}
|
|
cancel(reason = new TypeError("Stream was cancelled")) {
|
|
const stream = this._stream;
|
|
if (stream.destroyed) return Promise.resolve();
|
|
if (this.locked) return Promise.reject(new TypeError("Stream is locked"));
|
|
return new Promise(
|
|
(resolve) => stream.once("close", resolve).once("error", noop).destroy(reason)
|
|
);
|
|
}
|
|
tee() {
|
|
const [a, b] = tee(this._stream);
|
|
return [new _ReadableStream(a), new _ReadableStream(b)];
|
|
}
|
|
pipeTo(destination) {
|
|
return new Promise(
|
|
(resolve, reject) => this._stream.pipe(destination._stream, (err) => {
|
|
err ? reject(err) : resolve();
|
|
})
|
|
);
|
|
}
|
|
[Symbol.asyncIterator]() {
|
|
return this._stream[Symbol.asyncIterator]();
|
|
}
|
|
_releaseLock() {
|
|
this._reader = null;
|
|
}
|
|
async _read(starting, pull, cb) {
|
|
await starting;
|
|
let err = null;
|
|
try {
|
|
await pull();
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
};
|
|
function defaultSize() {
|
|
return 1;
|
|
}
|
|
exports.ReadableStream = ReadableStream;
|
|
exports.CountQueuingStrategy = class CountQueuingStrategy {
|
|
constructor(opts = {}) {
|
|
const { highWaterMark = 1 } = opts;
|
|
this.highWaterMark = highWaterMark;
|
|
}
|
|
size(chunk) {
|
|
return 1;
|
|
}
|
|
};
|
|
exports.ByteLengthQueuingStrategy = class ByteLengthQueuingStrategy {
|
|
constructor(opts = {}) {
|
|
const { highWaterMark = 16384 } = opts;
|
|
this.highWaterMark = highWaterMark;
|
|
}
|
|
size(chunk) {
|
|
return chunk.byteLength;
|
|
}
|
|
};
|
|
exports.isReadableStream = function isReadableStream(value) {
|
|
if (value instanceof ReadableStream) return true;
|
|
return typeof value === "object" && value !== null && value[readableKind] === ReadableStream[readableKind];
|
|
};
|
|
exports.isReadableStreamErrored = function isReadableStreamErrored(stream) {
|
|
return getStreamError(stream._stream) !== null;
|
|
};
|
|
exports.isReadableStreamDisturbed = function isReadableStreamDisturbed(stream) {
|
|
return isDisturbed(stream._stream);
|
|
};
|
|
exports.WritableStreamDefaultWriter = class WritableStreamDefaultWriter {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
this._stream._stream.once("close", onclose).once("error", onerror);
|
|
const closed = Promise.withResolvers();
|
|
closed.promise.catch(noop);
|
|
this._closed = closed;
|
|
function onclose() {
|
|
closed.resolve();
|
|
}
|
|
function onerror(err) {
|
|
closed.reject(err);
|
|
}
|
|
}
|
|
get desiredSize() {
|
|
const stream = this._stream._stream;
|
|
return stream._writableState.highWaterMark - stream._writableState.buffered;
|
|
}
|
|
get closed() {
|
|
return this._closed.promise;
|
|
}
|
|
get ready() {
|
|
const stream = this._stream._stream;
|
|
if (getStreamError(stream)) return Promise.reject();
|
|
return Writable.drained(stream).then();
|
|
}
|
|
async write(chunk) {
|
|
const stream = this._stream._stream;
|
|
let err = getStreamError(stream);
|
|
if (err) return Promise.reject(err);
|
|
stream.write(chunk);
|
|
await Writable.drained(stream);
|
|
err = getStreamError(stream);
|
|
if (err) return Promise.reject(err);
|
|
}
|
|
releaseLock() {
|
|
this._closed.reject(new TypeError("Writer was released"));
|
|
this._stream._releaseLock();
|
|
this._stream = null;
|
|
}
|
|
close() {
|
|
const stream = this._stream._stream;
|
|
if (stream.destroyed) return Promise.resolve();
|
|
return new Promise((resolve) => stream.once("close", resolve).end());
|
|
}
|
|
abort(reason = new TypeError("Stream was aborted")) {
|
|
const stream = this._stream._stream;
|
|
if (stream.destroyed) return Promise.resolve();
|
|
return new Promise((resolve) => stream.once("close", resolve).destroy(reason));
|
|
}
|
|
};
|
|
exports.WritableStreamDefaultController = class WritableStreamDefaultController {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
}
|
|
error(err) {
|
|
this._stream._stream.destroy(err);
|
|
}
|
|
};
|
|
var WritableStream = class _WritableStream {
|
|
static get [writableKind]() {
|
|
return 0;
|
|
}
|
|
constructor(underlyingSink = {}, queuingStrategy = {}) {
|
|
if (isStreamx(underlyingSink)) {
|
|
this._stream = underlyingSink;
|
|
} else {
|
|
if (queuingStrategy === void 0) {
|
|
queuingStrategy = new exports.CountQueuingStrategy();
|
|
}
|
|
const { start, write, close, abort } = underlyingSink;
|
|
const { highWaterMark = 1, size = defaultSize } = queuingStrategy;
|
|
this._stream = new Writable({ highWaterMark, byteLength: size });
|
|
const controller = new exports.WritableStreamDefaultController(this);
|
|
this._controller = controller;
|
|
try {
|
|
let starting = Promise.resolve();
|
|
if (start) starting = forwardError(start.call(this, controller), controller);
|
|
if (write) {
|
|
this._stream._write = this._write.bind(this, starting, write.bind(this));
|
|
}
|
|
if (close) {
|
|
this._stream._destroy = this._destroy.bind(this, close.call(this));
|
|
}
|
|
if (abort) {
|
|
this._stream.once("error", abort.bind(this));
|
|
}
|
|
} catch (err) {
|
|
controller.error(err);
|
|
}
|
|
}
|
|
this._writer = null;
|
|
}
|
|
get [writableKind]() {
|
|
return _WritableStream[writableKind];
|
|
}
|
|
get locked() {
|
|
return this._writer !== null;
|
|
}
|
|
getWriter() {
|
|
if (this.locked) throw new TypeError("Stream is locked");
|
|
this._writer = new exports.WritableStreamDefaultWriter(this);
|
|
return this._writer;
|
|
}
|
|
abort(reason = new TypeError("Stream was aborted")) {
|
|
if (this._stream.destroyed) return Promise.resolve();
|
|
if (this.locked) return Promise.reject(new TypeError("Stream is locked"));
|
|
return new Promise((resolve) => this._stream.once("close", resolve).destroy(reason));
|
|
}
|
|
close() {
|
|
if (this._stream.destroyed) return Promise.resolve();
|
|
if (this.locked) return Promise.reject(new TypeError("Stream is locked"));
|
|
return new Promise((resolve) => this._stream.once("close", resolve).end());
|
|
}
|
|
_releaseLock() {
|
|
this._writer = null;
|
|
}
|
|
async _write(starting, write, data, cb) {
|
|
await starting;
|
|
let err = null;
|
|
try {
|
|
await write(data, this._controller);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _destroy(closing, cb) {
|
|
let err = null;
|
|
try {
|
|
await closing;
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
};
|
|
exports.WritableStream = WritableStream;
|
|
exports.isWritableStream = function isWritableStream(value) {
|
|
if (value instanceof WritableStream) return true;
|
|
return typeof value === "object" && value !== null && value[writableKind] === WritableStream[writableKind];
|
|
};
|
|
exports.TransformStreamDefaultController = class TransformStreamDefaultController {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
}
|
|
get desiredSize() {
|
|
const stream = this._stream._stream;
|
|
return stream._readableState.highWaterMark - stream._readableState.buffered;
|
|
}
|
|
enqueue(data) {
|
|
this._stream._stream.push(data);
|
|
}
|
|
error(err) {
|
|
this._stream._stream.destroy(err);
|
|
}
|
|
terminate() {
|
|
const stream = this._stream._stream;
|
|
stream.push(null);
|
|
stream.destroy(new TypeError("Stream has been terminated"));
|
|
}
|
|
};
|
|
var TransformStream = class _TransformStream {
|
|
static get [transformKind]() {
|
|
return 0;
|
|
}
|
|
constructor(transformer = {}, writableStrategy = {}, readableStrategy = {}) {
|
|
if (isStreamx(transformer)) {
|
|
this._stream = transformer;
|
|
} else {
|
|
const { start, transform, flush } = transformer;
|
|
this._stream = new Transform({ ...writableStrategy, ...readableStrategy });
|
|
const controller = new exports.TransformStreamDefaultController(this);
|
|
this._controller = controller;
|
|
try {
|
|
let starting = Promise.resolve();
|
|
if (start) starting = forwardError(start.call(this, controller), controller);
|
|
if (transform) {
|
|
this._stream._transform = this._transform.bind(this, starting, transform.bind(this));
|
|
}
|
|
if (flush) {
|
|
this._stream._flush = this._flush.bind(this, flush.call(this, this._controller));
|
|
}
|
|
} catch (err) {
|
|
controller.error(err);
|
|
}
|
|
}
|
|
this._writable = new WritableStream(this._stream);
|
|
this._readable = new ReadableStream(this._stream);
|
|
}
|
|
get [transformKind]() {
|
|
return _TransformStream[transformKind];
|
|
}
|
|
get writable() {
|
|
return this._writable;
|
|
}
|
|
get readable() {
|
|
return this._readable;
|
|
}
|
|
async _transform(starting, transform, data, cb) {
|
|
await starting;
|
|
let err = null;
|
|
try {
|
|
await transform(data, this._controller);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _flush(flush, cb) {
|
|
let err = null;
|
|
try {
|
|
await flush;
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
};
|
|
exports.TransformStream = TransformStream;
|
|
exports.isTransformStream = function isTransformStream(value) {
|
|
if (value instanceof TransformStream) return true;
|
|
return typeof value === "object" && value !== null && value[transformKind] === TransformStream[transformKind];
|
|
};
|
|
async function forwardError(promise, controller) {
|
|
try {
|
|
await promise;
|
|
} catch (err) {
|
|
controller.error(err);
|
|
}
|
|
}
|
|
function noop() {
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-stream/index.js
|
|
var require_bare_stream = __commonJS({
|
|
"../../node_modules/bare-stream/index.js"(exports, module) {
|
|
var b4a = require_b4a();
|
|
var stream = require_streamx();
|
|
var { ReadableStream, WritableStream } = require_web();
|
|
var defaultEncoding = "utf8";
|
|
module.exports = exports = stream.Stream;
|
|
exports.pipeline = stream.pipeline;
|
|
exports.isStream = stream.isStream;
|
|
exports.isEnding = stream.isEnding;
|
|
exports.isEnded = stream.isEnded;
|
|
exports.isFinishing = stream.isFinishing;
|
|
exports.isFinished = stream.isFinished;
|
|
exports.isDisturbed = stream.isDisturbed;
|
|
exports.isErrored = function isErrored(stream2) {
|
|
return exports.getStreamError(stream2) !== null;
|
|
};
|
|
exports.isReadable = function isReadable(stream2) {
|
|
return stream2.readable && !stream2.destroying && !exports.isEnded(stream2);
|
|
};
|
|
exports.isWritable = function isWritable(stream2) {
|
|
return stream2.writable && !stream2.destroying && !exports.isFinishing(stream2);
|
|
};
|
|
exports.getStreamError = stream.getStreamError;
|
|
exports.addAbortSignal = function addAbortSignal(signal, stream2) {
|
|
function onAbort() {
|
|
stream2.destroy(signal.reason);
|
|
}
|
|
if (signal.aborted) onAbort();
|
|
else signal.addEventListener("abort", onAbort);
|
|
return stream2;
|
|
};
|
|
exports.Stream = exports;
|
|
exports.Readable = class Readable extends stream.Readable {
|
|
constructor(opts = {}) {
|
|
super({
|
|
...opts,
|
|
byteLength: null,
|
|
byteLengthReadable: null,
|
|
map: null,
|
|
mapReadable: null
|
|
});
|
|
if (this._construct) this._open = this._construct;
|
|
if (this._read !== stream.Readable.prototype._read) {
|
|
this._read = read.bind(this, this._read);
|
|
}
|
|
if (this._destroy !== stream.Stream.prototype._destroy) {
|
|
this._destroy = destroy.bind(this, this._destroy);
|
|
}
|
|
}
|
|
get closed() {
|
|
return !exports.isReadable(this);
|
|
}
|
|
get errored() {
|
|
return stream.getStreamError(this);
|
|
}
|
|
push(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = b4a.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
return super.push(chunk);
|
|
}
|
|
unshift(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = b4a.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
super.unshift(chunk);
|
|
}
|
|
static fromWeb(readableStream, opts = {}) {
|
|
const stream2 = readableStream._stream;
|
|
if (opts.encoding) stream2.setEncoding(opts.encoding);
|
|
if (opts.signal) exports.addAbortSignal(opts.signal, stream2);
|
|
return stream2;
|
|
}
|
|
static toWeb(readable, opts = {}) {
|
|
return new ReadableStream(readable, opts.strategy);
|
|
}
|
|
async [Symbol.asyncDispose]() {
|
|
if (!this.destroyed) this.destroy();
|
|
await new Promise((resolve) => exports.finished(this, resolve));
|
|
}
|
|
};
|
|
exports.Writable = class Writable extends stream.Writable {
|
|
constructor(opts = {}) {
|
|
super({
|
|
...opts,
|
|
byteLength: null,
|
|
byteLengthWritable,
|
|
map: null,
|
|
mapWritable: null
|
|
});
|
|
if (this._construct) this._open = this._construct;
|
|
if (this._write !== stream.Writable.prototype._write) {
|
|
this._write = write.bind(this, this._write);
|
|
}
|
|
if (this._destroy !== stream.Stream.prototype._destroy) {
|
|
this._destroy = destroy.bind(this, this._destroy);
|
|
}
|
|
}
|
|
get closed() {
|
|
return !exports.isWritable(this);
|
|
}
|
|
get errored() {
|
|
return stream.getStreamError(this);
|
|
}
|
|
write(chunk, encoding, cb) {
|
|
if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = b4a.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = super.write({ chunk, encoding });
|
|
if (cb) stream.Writable.drained(this).then(() => cb(null), cb);
|
|
return result;
|
|
}
|
|
end(chunk, encoding, cb) {
|
|
if (typeof chunk === "function") {
|
|
cb = chunk;
|
|
chunk = null;
|
|
} else if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = b4a.from(chunk, encoding || defaultEncoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = chunk !== void 0 && chunk !== null ? super.end({ chunk, encoding }) : super.end();
|
|
if (cb) this.once("finish", () => cb(null));
|
|
return result;
|
|
}
|
|
static fromWeb(writableStream, opts = {}) {
|
|
const stream2 = writableStream._stream;
|
|
if (opts.signal) exports.addAbortSignal(opts.signal, stream2);
|
|
return stream2;
|
|
}
|
|
static toWeb(writable) {
|
|
return new WritableStream(writable);
|
|
}
|
|
async [Symbol.asyncDispose]() {
|
|
if (!this.destroyed) this.destroy();
|
|
await new Promise((resolve) => exports.finished(this, resolve));
|
|
}
|
|
};
|
|
exports.Duplex = class Duplex extends stream.Duplex {
|
|
constructor(opts = {}) {
|
|
super({
|
|
...opts,
|
|
byteLength: null,
|
|
byteLengthReadable: null,
|
|
byteLengthWritable,
|
|
map: null,
|
|
mapReadable: null,
|
|
mapWritable: null
|
|
});
|
|
if (this._construct) this._open = this._construct;
|
|
if (this._read !== stream.Readable.prototype._read) {
|
|
this._read = read.bind(this, this._read);
|
|
}
|
|
if (this._write !== stream.Duplex.prototype._write) {
|
|
this._write = write.bind(this, this._write);
|
|
}
|
|
if (this._destroy !== stream.Stream.prototype._destroy) {
|
|
this._destroy = destroy.bind(this, this._destroy);
|
|
}
|
|
}
|
|
push(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = b4a.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
return super.push(chunk);
|
|
}
|
|
unshift(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = b4a.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
super.unshift(chunk);
|
|
}
|
|
write(chunk, encoding, cb) {
|
|
if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = b4a.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = super.write({ chunk, encoding });
|
|
if (cb) stream.Writable.drained(this).then(() => cb(null), cb);
|
|
return result;
|
|
}
|
|
end(chunk, encoding, cb) {
|
|
if (typeof chunk === "function") {
|
|
cb = chunk;
|
|
chunk = null;
|
|
} else if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = b4a.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = chunk !== void 0 && chunk !== null ? super.end({ chunk, encoding }) : super.end();
|
|
if (cb) this.once("finish", () => cb(null));
|
|
return result;
|
|
}
|
|
static fromWeb({ readable: readableStream, writable: writableStream }, opts) {
|
|
const readable = exports.Readable.fromWeb(readableStream, opts);
|
|
const writable = exports.Writable.fromWeb(writableStream, opts);
|
|
const duplex = new exports.Duplex({
|
|
write(data, encoding, cb) {
|
|
writable.write(data, encoding, cb);
|
|
}
|
|
});
|
|
readable.on("data", (data) => duplex.push(data)).on("end", () => duplex.push(null)).on("error", (err) => duplex.destroy(err));
|
|
writable.on("finish", () => duplex.end()).on("error", (err) => duplex.destroy(err));
|
|
return duplex;
|
|
}
|
|
static toWeb(duplex) {
|
|
const readableStream = exports.Readable.toWeb(duplex);
|
|
const writableStream = exports.Writable.toWeb(duplex);
|
|
return { readable: readableStream, writable: writableStream };
|
|
}
|
|
};
|
|
var DuplexSide = class extends exports.Duplex {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._otherSide = null;
|
|
this._cb = null;
|
|
}
|
|
_read() {
|
|
const cb = this._cb;
|
|
if (!cb) return;
|
|
this._cb = null;
|
|
cb();
|
|
}
|
|
_write(chunk, encoding, cb) {
|
|
this._otherSide.push(chunk, encoding);
|
|
this._otherSide._cb = cb;
|
|
}
|
|
_final(cb) {
|
|
this._otherSide.on("end", cb);
|
|
this._otherSide.push(null);
|
|
}
|
|
};
|
|
exports.duplexPair = function duplexPair(opts) {
|
|
const sideA = new DuplexSide(opts);
|
|
const sideB = new DuplexSide(opts);
|
|
sideA._otherSide = sideB;
|
|
sideB._otherSide = sideA;
|
|
return [sideA, sideB];
|
|
};
|
|
exports.Transform = class Transform extends stream.Transform {
|
|
constructor(opts = {}) {
|
|
super({
|
|
...opts,
|
|
byteLength: null,
|
|
byteLengthReadable: null,
|
|
byteLengthWritable,
|
|
map: null,
|
|
mapReadable: null,
|
|
mapWritable: null
|
|
});
|
|
if (this._transform !== stream.Transform.prototype._transform) {
|
|
this._transform = transform.bind(this, this._transform);
|
|
} else {
|
|
this._transform = passthrough;
|
|
}
|
|
}
|
|
push(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = b4a.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
return super.push(chunk);
|
|
}
|
|
unshift(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = b4a.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
super.unshift(chunk);
|
|
}
|
|
write(chunk, encoding, cb) {
|
|
if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = b4a.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = super.write({ chunk, encoding });
|
|
if (cb) stream.Writable.drained(this).then(() => cb(null), cb);
|
|
return result;
|
|
}
|
|
end(chunk, encoding, cb) {
|
|
if (typeof chunk === "function") {
|
|
cb = chunk;
|
|
chunk = null;
|
|
} else if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = b4a.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = chunk !== void 0 && chunk !== null ? super.end({ chunk, encoding }) : super.end();
|
|
if (cb) this.once("finish", () => cb(null));
|
|
return result;
|
|
}
|
|
};
|
|
exports.PassThrough = class PassThrough extends exports.Transform {
|
|
};
|
|
exports.finished = function finished(stream2, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (!opts) opts = {};
|
|
const { cleanup = false } = opts;
|
|
const done = () => {
|
|
cb(exports.getStreamError(stream2, { all: true }));
|
|
if (cleanup) detach();
|
|
};
|
|
const detach = () => {
|
|
stream2.off("close", done);
|
|
stream2.off("error", noop);
|
|
};
|
|
if (stream2.destroyed) {
|
|
done();
|
|
} else {
|
|
stream2.on("close", done);
|
|
stream2.on("error", noop);
|
|
}
|
|
return detach;
|
|
};
|
|
function read(read2, cb) {
|
|
read2.call(this, 65536);
|
|
cb(null);
|
|
}
|
|
function write(write2, data, cb) {
|
|
write2.call(this, data.chunk, data.encoding, cb);
|
|
}
|
|
function transform(transform2, data, cb) {
|
|
transform2.call(this, data.chunk, data.encoding, cb);
|
|
}
|
|
function destroy(destroy2, cb) {
|
|
destroy2.call(this, exports.getStreamError(this), cb);
|
|
}
|
|
function passthrough(data, cb) {
|
|
cb(null, data.chunk);
|
|
}
|
|
function byteLengthWritable(data) {
|
|
return data.chunk.byteLength;
|
|
}
|
|
function noop() {
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-fs/binding.js
|
|
var require_binding3 = __commonJS({
|
|
"../../node_modules/bare-fs/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-fs/lib/constants.js
|
|
var require_constants2 = __commonJS({
|
|
"../../node_modules/bare-fs/lib/constants.js"(exports, module) {
|
|
var binding = require_binding3();
|
|
module.exports = {
|
|
O_RDWR: binding.O_RDWR,
|
|
O_RDONLY: binding.O_RDONLY,
|
|
O_WRONLY: binding.O_WRONLY,
|
|
O_CREAT: binding.O_CREAT,
|
|
O_TRUNC: binding.O_TRUNC,
|
|
O_APPEND: binding.O_APPEND,
|
|
F_OK: binding.F_OK || 0,
|
|
R_OK: binding.R_OK || 0,
|
|
W_OK: binding.W_OK || 0,
|
|
X_OK: binding.X_OK || 0,
|
|
S_IFMT: binding.S_IFMT,
|
|
S_IFREG: binding.S_IFREG,
|
|
S_IFDIR: binding.S_IFDIR,
|
|
S_IFCHR: binding.S_IFCHR,
|
|
S_IFLNK: binding.S_IFLNK,
|
|
S_IFBLK: binding.S_IFBLK || 0,
|
|
S_IFIFO: binding.S_IFIFO || 0,
|
|
S_IFSOCK: binding.S_IFSOCK || 0,
|
|
S_IRUSR: binding.S_IRUSR || 0,
|
|
S_IWUSR: binding.S_IWUSR || 0,
|
|
S_IXUSR: binding.S_IXUSR || 0,
|
|
S_IRGRP: binding.S_IRGRP || 0,
|
|
S_IWGRP: binding.S_IWGRP || 0,
|
|
S_IXGRP: binding.S_IXGRP || 0,
|
|
S_IROTH: binding.S_IROTH || 0,
|
|
S_IWOTH: binding.S_IWOTH || 0,
|
|
S_IXOTH: binding.S_IXOTH || 0,
|
|
UV_DIRENT_UNKNOWN: binding.UV_DIRENT_UNKNOWN,
|
|
UV_DIRENT_FILE: binding.UV_DIRENT_FILE,
|
|
UV_DIRENT_DIR: binding.UV_DIRENT_DIR,
|
|
UV_DIRENT_LINK: binding.UV_DIRENT_LINK,
|
|
UV_DIRENT_FIFO: binding.UV_DIRENT_FIFO,
|
|
UV_DIRENT_SOCKET: binding.UV_DIRENT_SOCKET,
|
|
UV_DIRENT_CHAR: binding.UV_DIRENT_CHAR,
|
|
UV_DIRENT_BLOCK: binding.UV_DIRENT_BLOCK,
|
|
COPYFILE_EXCL: binding.UV_FS_COPYFILE_EXCL,
|
|
COPYFILE_FICLONE: binding.UV_FS_COPYFILE_FICLONE,
|
|
COPYFILE_FICLONE_FORCE: binding.UV_FS_COPYFILE_FICLONE_FORCE,
|
|
UV_FS_SYMLINK_DIR: binding.UV_FS_SYMLINK_DIR,
|
|
UV_FS_SYMLINK_JUNCTION: binding.UV_FS_SYMLINK_JUNCTION
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-fs/lib/errors.js
|
|
var require_errors4 = __commonJS({
|
|
"../../node_modules/bare-fs/lib/errors.js"(exports, module) {
|
|
var binding = require_binding3();
|
|
module.exports = class FileError extends Error {
|
|
constructor(msg, opts = {}) {
|
|
const { code, operation = null, path = null, destination = null, fd = -1 } = opts;
|
|
if (operation !== null) msg += describe(operation, opts);
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (operation !== null) this.operation = operation;
|
|
if (path !== null) this.path = path;
|
|
if (destination !== null) this.destination = destination;
|
|
if (fd !== -1) this.fd = fd;
|
|
}
|
|
get name() {
|
|
return "FileError";
|
|
}
|
|
// For Node.js compatibility
|
|
get errno() {
|
|
return binding.errnos[this.code];
|
|
}
|
|
// For Node.js compatibility
|
|
get syscall() {
|
|
return this.operation;
|
|
}
|
|
// For Node.js compatibility
|
|
get dest() {
|
|
return this.destination;
|
|
}
|
|
};
|
|
function describe(operation, opts) {
|
|
const { path = null, destination = null, fd = -1 } = opts;
|
|
let result = `, ${operation}`;
|
|
if (path !== null) {
|
|
result += ` ${JSON.stringify(path)}`;
|
|
if (destination !== null) {
|
|
result += ` -> ${JSON.stringify(destination)}`;
|
|
}
|
|
} else if (fd !== -1) {
|
|
result += ` ${fd}`;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-fs/index.js
|
|
var require_bare_fs = __commonJS({
|
|
"../../node_modules/bare-fs/index.js"(exports) {
|
|
var FIFO = require_fast_fifo();
|
|
var EventEmitter = require_bare_events();
|
|
var path = require_bare_path();
|
|
var { isURL, fileURLToPath } = require_bare_url();
|
|
var { Readable, Writable } = require_bare_stream();
|
|
var binding = require_binding3();
|
|
var constants = require_constants2();
|
|
var FileError = require_errors4();
|
|
var isWindows = Bare.platform === "win32";
|
|
exports.constants = constants;
|
|
var FileRequest = class _FileRequest {
|
|
static borrow() {
|
|
if (this._free.length > 0) return this._free.pop();
|
|
return new _FileRequest();
|
|
}
|
|
static return(req) {
|
|
if (this._free.length < 32) this._free.push(req.reset());
|
|
else req.destroy();
|
|
}
|
|
constructor() {
|
|
this._reset();
|
|
this._handle = binding.requestInit(this, this._onresult);
|
|
}
|
|
get handle() {
|
|
return this._handle;
|
|
}
|
|
retain(value) {
|
|
this._retain = value;
|
|
}
|
|
reset() {
|
|
if (this._handle === null) return this;
|
|
binding.requestReset(this._handle);
|
|
this._reset();
|
|
return this;
|
|
}
|
|
destroy() {
|
|
if (this._handle === null) return this;
|
|
binding.requestDestroy(this._handle);
|
|
this._reset();
|
|
this._handle = null;
|
|
return this;
|
|
}
|
|
then(resolve, reject) {
|
|
return this._promise.then(resolve, reject);
|
|
}
|
|
return() {
|
|
if (this._handle === null) return this;
|
|
_FileRequest.return(this);
|
|
return this;
|
|
}
|
|
_reset() {
|
|
this._promise = new Promise((resolve, reject) => {
|
|
this._resolve = resolve;
|
|
this._reject = reject;
|
|
});
|
|
this._retain = null;
|
|
}
|
|
_onresult(err, status) {
|
|
if (err) this._reject(err);
|
|
else this._resolve(status);
|
|
}
|
|
};
|
|
FileRequest._free = [];
|
|
function ok(result, cb) {
|
|
if (typeof result === "function") {
|
|
cb = result;
|
|
result = void 0;
|
|
}
|
|
if (cb) cb(null, result);
|
|
else return result;
|
|
}
|
|
function fail(err, cb) {
|
|
if (cb) cb(err);
|
|
else throw err;
|
|
}
|
|
function done(err, result, cb) {
|
|
if (typeof result === "function") {
|
|
cb = result;
|
|
result = void 0;
|
|
}
|
|
if (err) fail(err, cb);
|
|
else return ok(result, cb);
|
|
}
|
|
async function open(filepath, flags = "r", mode = 438, cb) {
|
|
if (typeof flags === "function") {
|
|
cb = flags;
|
|
flags = "r";
|
|
mode = 438;
|
|
} else if (typeof mode === "function") {
|
|
cb = mode;
|
|
mode = 438;
|
|
}
|
|
if (typeof flags === "string") flags = toFlags(flags);
|
|
if (typeof mode === "string") mode = toMode(mode);
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let fd;
|
|
let err = null;
|
|
try {
|
|
binding.open(req.handle, filepath, flags, mode);
|
|
fd = await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "open",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, fd, cb);
|
|
}
|
|
function openSync(filepath, flags = "r", mode = 438) {
|
|
if (typeof flags === "string") flags = toFlags(flags);
|
|
if (typeof mode === "string") mode = toMode(mode);
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
return binding.openSync(req.handle, filepath, flags, mode);
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "open",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function close(fd, cb) {
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.close(req.handle, fd);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "close", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function closeSync(fd) {
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.closeSync(req.handle, fd);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "close", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function access(filepath, mode = constants.F_OK, cb) {
|
|
if (typeof mode === "function") {
|
|
cb = mode;
|
|
mode = constants.F_OK;
|
|
}
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.access(req.handle, filepath, mode);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "access",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function accessSync(filepath, mode = constants.F_OK) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.accessSync(req.handle, filepath, mode);
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "access",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function exists(filepath, cb) {
|
|
let ok2 = true;
|
|
try {
|
|
await access(filepath);
|
|
} catch {
|
|
ok2 = false;
|
|
}
|
|
return done(null, ok2, cb);
|
|
}
|
|
function existsSync(filepath) {
|
|
try {
|
|
accessSync(filepath);
|
|
} catch {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
async function read(fd, buffer, offset = 0, len = buffer.byteLength - offset, pos = -1, cb) {
|
|
if (typeof offset === "function") {
|
|
cb = offset;
|
|
offset = 0;
|
|
len = buffer.byteLength;
|
|
pos = -1;
|
|
} else if (typeof len === "function") {
|
|
cb = len;
|
|
len = buffer.byteLength - offset;
|
|
pos = -1;
|
|
} else if (typeof pos === "function") {
|
|
cb = pos;
|
|
pos = -1;
|
|
}
|
|
if (typeof pos !== "number") pos = -1;
|
|
const req = FileRequest.borrow();
|
|
let bytes;
|
|
let err = null;
|
|
try {
|
|
binding.read(req.handle, fd, buffer, offset, len, pos);
|
|
req.retain(buffer);
|
|
bytes = await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "read", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, bytes, cb);
|
|
}
|
|
function readSync(fd, buffer, offset = 0, len = buffer.byteLength - offset, pos = -1) {
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
return binding.readSync(req.handle, fd, buffer, offset, len, pos);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "read", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function readv(fd, buffers, pos = -1, cb) {
|
|
if (typeof pos === "function") {
|
|
cb = pos;
|
|
pos = -1;
|
|
}
|
|
if (typeof pos !== "number") pos = -1;
|
|
const req = FileRequest.borrow();
|
|
let bytes;
|
|
let err = null;
|
|
try {
|
|
binding.readv(req.handle, fd, buffers, pos);
|
|
req.retain(buffers);
|
|
bytes = await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "readv", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, bytes, cb);
|
|
}
|
|
function readvSync(fd, buffers, pos = -1) {
|
|
if (typeof pos !== "number") pos = -1;
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
return binding.readvSync(req.handle, fd, buffers, pos);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "readv", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function write(fd, data, offset, len, pos = -1, cb) {
|
|
if (typeof data === "string") {
|
|
let encoding = len;
|
|
cb = pos;
|
|
pos = offset;
|
|
if (typeof pos === "function") {
|
|
cb = pos;
|
|
pos = -1;
|
|
encoding = "utf8";
|
|
} else if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = "utf8";
|
|
}
|
|
if (typeof pos === "string") {
|
|
encoding = pos;
|
|
pos = -1;
|
|
}
|
|
data = Buffer.from(data, encoding);
|
|
offset = 0;
|
|
len = data.byteLength;
|
|
} else if (typeof offset === "function") {
|
|
cb = offset;
|
|
offset = 0;
|
|
len = data.byteLength;
|
|
pos = -1;
|
|
} else if (typeof len === "function") {
|
|
cb = len;
|
|
len = data.byteLength - offset;
|
|
pos = -1;
|
|
} else if (typeof pos === "function") {
|
|
cb = pos;
|
|
pos = -1;
|
|
}
|
|
if (typeof offset !== "number") offset = 0;
|
|
if (typeof len !== "number") len = data.byteLength - offset;
|
|
if (typeof pos !== "number") pos = -1;
|
|
const req = FileRequest.borrow();
|
|
let bytes;
|
|
let err = null;
|
|
try {
|
|
binding.write(req.handle, fd, data, offset, len, pos);
|
|
req.retain(data);
|
|
bytes = await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "write", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, bytes, cb);
|
|
}
|
|
function writeSync(fd, data, offset, len, pos = -1) {
|
|
if (typeof data === "string") {
|
|
let encoding = len;
|
|
pos = offset;
|
|
if (typeof pos === "string") {
|
|
encoding = pos;
|
|
pos = -1;
|
|
}
|
|
data = Buffer.from(data, encoding);
|
|
offset = 0;
|
|
len = data.byteLength;
|
|
}
|
|
if (typeof offset !== "number") offset = 0;
|
|
if (typeof len !== "number") len = data.byteLength - offset;
|
|
if (typeof pos !== "number") pos = -1;
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
return binding.writeSync(req.handle, fd, data, offset, len, pos);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "write", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function writev(fd, buffers, pos = -1, cb) {
|
|
if (typeof pos === "function") {
|
|
cb = pos;
|
|
pos = -1;
|
|
}
|
|
if (typeof pos !== "number") pos = -1;
|
|
const req = FileRequest.borrow();
|
|
let bytes;
|
|
let err = null;
|
|
try {
|
|
binding.writev(req.handle, fd, buffers, pos);
|
|
req.retain(buffers);
|
|
bytes = await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "writev", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, bytes, cb);
|
|
}
|
|
function writevSync(fd, buffers, pos = -1) {
|
|
if (typeof pos !== "number") pos = -1;
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
return binding.writevSync(req.handle, fd, buffers, pos);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "writev", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function stat(filepath, cb) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let st;
|
|
let err = null;
|
|
try {
|
|
binding.stat(req.handle, filepath);
|
|
await req;
|
|
st = new Stats(...binding.requestResultStat(req.handle));
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "stat", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, st, cb);
|
|
}
|
|
function statSync(filepath) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.statSync(req.handle, filepath);
|
|
return new Stats(...binding.requestResultStat(req.handle));
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "stat", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function lstat(filepath, cb) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let st;
|
|
let err = null;
|
|
try {
|
|
binding.lstat(req.handle, filepath);
|
|
await req;
|
|
st = new Stats(...binding.requestResultStat(req.handle));
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "lstat", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, st, cb);
|
|
}
|
|
function lstatSync(filepath) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.lstatSync(req.handle, filepath);
|
|
return new Stats(...binding.requestResultStat(req.handle));
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "lstat", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function fstat(fd, cb) {
|
|
const req = FileRequest.borrow();
|
|
let st;
|
|
let err = null;
|
|
try {
|
|
binding.fstat(req.handle, fd);
|
|
await req;
|
|
st = new Stats(...binding.requestResultStat(req.handle));
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "fstat", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, st, cb);
|
|
}
|
|
function fstatSync(fd) {
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.fstatSync(req.handle, fd);
|
|
return new Stats(...binding.requestResultStat(req.handle));
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "fstat", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function statfs(filepath, cb) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let st;
|
|
let err = null;
|
|
try {
|
|
binding.statfs(req.handle, filepath);
|
|
await req;
|
|
st = new StatFs(...binding.requestResultStatfs(req.handle));
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "statfs", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, st, cb);
|
|
}
|
|
function statfsSync(filepath) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.statfsSync(req.handle, filepath);
|
|
return new StatFs(...binding.requestResultStatfs(req.handle));
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "statfs", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function ftruncate(fd, len = 0, cb) {
|
|
if (typeof len === "function") {
|
|
cb = len;
|
|
len = 0;
|
|
}
|
|
if (typeof len !== "number") len = 0;
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.ftruncate(req.handle, fd, len);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "ftruncate", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function ftruncateSync(fd, len = 0) {
|
|
if (typeof len !== "number") len = 0;
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.ftruncateSync(req.handle, fd, len);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "ftruncate", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function truncate(filepath, len, cb) {
|
|
let fd = -1;
|
|
let err;
|
|
try {
|
|
fd = await open(filepath, "r+");
|
|
await ftruncate(fd, len);
|
|
} catch (e) {
|
|
err = e;
|
|
} finally {
|
|
if (fd !== -1) await close(fd);
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function truncateSync(filepath, len) {
|
|
let fd = -1;
|
|
let err;
|
|
try {
|
|
fd = openSync(filepath, "r+");
|
|
ftruncateSync(fd, len);
|
|
} catch (e) {
|
|
err = e;
|
|
} finally {
|
|
if (fd !== -1) closeSync(fd);
|
|
}
|
|
}
|
|
async function chmod(filepath, mode, cb) {
|
|
if (typeof mode === "string") mode = toMode(mode);
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.chmod(req.handle, filepath, mode);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "chmod",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function chmodSync(filepath, mode) {
|
|
if (typeof mode === "string") mode = toMode(mode);
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.chmodSync(req.handle, filepath, mode);
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "chmod",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function fchmod(fd, mode, cb) {
|
|
if (typeof mode === "string") mode = toMode(mode);
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.fchmod(req.handle, fd, mode);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "fchmod", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function fchmodSync(fd, mode) {
|
|
if (typeof mode === "string") mode = toMode(mode);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.fchmodSync(req.handle, fd, mode);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "fchmod", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function chown(filepath, uid, gid, cb) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.chown(req.handle, filepath, uid, gid);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "chown", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function chownSync(filepath, uid, gid) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.chownSync(req.handle, filepath, uid, gid);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "chownSync", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function lchown(filepath, uid, gid, cb) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.lchown(req.handle, filepath, uid, gid);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "lchown", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function lchownSync(filepath, uid, gid) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.lchownSync(req.handle, filepath, uid, gid);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "lchownSync", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function fchown(fd, uid, gid, cb) {
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.fchown(req.handle, fd, uid, gid);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "fchown", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function fchownSync(fd, uid, gid) {
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.fchownSync(req.handle, fd, uid, gid);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "fchownSync", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function utimes(filepath, atime, mtime, cb) {
|
|
if (typeof atime !== "number") atime = atime.getTime() / 1e3;
|
|
if (typeof mtime !== "number") mtime = mtime.getTime() / 1e3;
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.utimes(req.handle, filepath, atime, mtime);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "utimes", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function utimesSync(filepath, atime, mtime) {
|
|
if (typeof atime !== "number") atime = atime.getTime() / 1e3;
|
|
if (typeof mtime !== "number") mtime = mtime.getTime() / 1e3;
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.utimesSync(req.handle, filepath, atime, mtime);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "utimes", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function lutimes(filepath, atime, mtime, cb) {
|
|
if (typeof atime !== "number") atime = atime.getTime() / 1e3;
|
|
if (typeof mtime !== "number") mtime = mtime.getTime() / 1e3;
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.lutimes(req.handle, filepath, atime, mtime);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "lutimes", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function lutimesSync(filepath, atime, mtime) {
|
|
if (typeof atime !== "number") atime = atime.getTime() / 1e3;
|
|
if (typeof mtime !== "number") mtime = mtime.getTime() / 1e3;
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.lutimesSync(req.handle, filepath, atime, mtime);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "lutimes", code: e.code, path: filepath });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function futimes(fd, atime, mtime, cb) {
|
|
if (typeof atime !== "number") atime = atime.getTime() / 1e3;
|
|
if (typeof mtime !== "number") mtime = mtime.getTime() / 1e3;
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.futimes(req.handle, fd, atime, mtime);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "futimes", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function futimesSync(fd, atime, mtime) {
|
|
if (typeof atime !== "number") atime = atime.getTime() / 1e3;
|
|
if (typeof mtime !== "number") mtime = mtime.getTime() / 1e3;
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.futimesSync(req.handle, fd, atime, mtime);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "futimesSync", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function link(src, dst, cb) {
|
|
src = toNamespacedPath(src);
|
|
dst = toNamespacedPath(dst);
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.link(req.handle, src, dst);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "link", code: e.code, path: src, destination: dst });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function linkSync(src, dst) {
|
|
src = toNamespacedPath(src);
|
|
dst = toNamespacedPath(dst);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.linkSync(req.handle, src, dst);
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "linkSync",
|
|
code: e.code,
|
|
path: src,
|
|
destination: dst
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function mkdir(filepath, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = { mode: 511 };
|
|
}
|
|
if (typeof opts === "number") opts = { mode: opts };
|
|
else if (!opts) opts = {};
|
|
const mode = typeof opts.mode === "number" ? opts.mode : 511;
|
|
filepath = toNamespacedPath(filepath);
|
|
if (opts.recursive) {
|
|
let err2 = null;
|
|
try {
|
|
try {
|
|
await mkdir(filepath, { mode });
|
|
} catch (err3) {
|
|
if (err3.code !== "ENOENT") {
|
|
if (!(await stat(filepath)).isDirectory()) throw err3;
|
|
} else {
|
|
while (filepath.endsWith(path.sep)) filepath = filepath.slice(0, -1);
|
|
const i = filepath.lastIndexOf(path.sep);
|
|
if (i <= 0) throw err3;
|
|
await mkdir(filepath.slice(0, i), { mode, recursive: true });
|
|
try {
|
|
await mkdir(filepath, { mode });
|
|
} catch (err4) {
|
|
if (!(await stat(filepath)).isDirectory()) throw err4;
|
|
}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
err2 = e;
|
|
}
|
|
return done(err2, cb);
|
|
}
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.mkdir(req.handle, filepath, mode);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "mkdir",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function mkdirSync(filepath, opts) {
|
|
if (typeof opts === "number") opts = { mode: opts };
|
|
else if (!opts) opts = {};
|
|
const mode = typeof opts.mode === "number" ? opts.mode : 511;
|
|
filepath = toNamespacedPath(filepath);
|
|
if (opts.recursive) {
|
|
try {
|
|
mkdirSync(filepath, { mode });
|
|
} catch (err) {
|
|
if (err.code !== "ENOENT") {
|
|
if (!statSync(filepath).isDirectory()) throw err;
|
|
} else {
|
|
while (filepath.endsWith(path.sep)) filepath = filepath.slice(0, -1);
|
|
const i = filepath.lastIndexOf(path.sep);
|
|
if (i <= 0) throw err;
|
|
mkdirSync(filepath.slice(0, i), { mode, recursive: true });
|
|
try {
|
|
mkdirSync(filepath, { mode });
|
|
} catch (err2) {
|
|
if (!statSync(filepath).isDirectory()) throw err2;
|
|
}
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.mkdirSync(req.handle, filepath, mode);
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "mkdir",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function mkdtemp(prefix, cb) {
|
|
prefix = toNamespacedPath(prefix);
|
|
const req = FileRequest.borrow();
|
|
let res;
|
|
let err = null;
|
|
try {
|
|
binding.mkdtemp(req.handle, prefix + "XXXXXX");
|
|
await req;
|
|
res = binding.requestResultPath(req.handle);
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "mkdtemp", code: e.code, path: prefix });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, res, cb);
|
|
}
|
|
function mkdtempSync(prefix) {
|
|
prefix = toNamespacedPath(prefix);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.mkdtempSync(req.handle, prefix + "XXXXXX");
|
|
return binding.requestResultPath(req.handle);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "mkdtempSync", code: e.code, path: prefix });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function rmdir(filepath, cb) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.rmdir(req.handle, filepath);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "rmdir",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function rmdirSync(filepath) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.rmdirSync(req.handle, filepath);
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "rmdir",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function rm(filepath, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (!opts) opts = {};
|
|
filepath = toNamespacedPath(filepath);
|
|
let err = null;
|
|
try {
|
|
const st = await lstat(filepath);
|
|
if (st.isDirectory()) {
|
|
if (opts.recursive) {
|
|
try {
|
|
await rmdir(filepath);
|
|
} catch (err2) {
|
|
if (err2.code !== "ENOTEMPTY") throw err2;
|
|
const files = await readdir(filepath);
|
|
for (const file of files) {
|
|
await rm(filepath + path.sep + file, opts);
|
|
}
|
|
await rmdir(filepath);
|
|
}
|
|
} else {
|
|
throw new FileError("is a directory", {
|
|
operation: "rm",
|
|
code: "EISDIR",
|
|
path: filepath
|
|
});
|
|
}
|
|
} else {
|
|
await unlink(filepath);
|
|
}
|
|
} catch (e) {
|
|
if (e.code !== "ENOENT" || !opts.force) err = e;
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function rmSync(filepath, opts) {
|
|
if (!opts) opts = {};
|
|
filepath = toNamespacedPath(filepath);
|
|
try {
|
|
const st = lstatSync(filepath);
|
|
if (st.isDirectory()) {
|
|
if (opts.recursive) {
|
|
try {
|
|
rmdirSync(filepath);
|
|
} catch (err) {
|
|
if (err.code !== "ENOTEMPTY") throw err;
|
|
const files = readdirSync(filepath);
|
|
for (const file of files) {
|
|
rmSync(filepath + path.sep + file, opts);
|
|
}
|
|
rmdirSync(filepath);
|
|
}
|
|
} else {
|
|
throw new FileError("is a directory", {
|
|
operation: "rm",
|
|
code: "EISDIR",
|
|
path: filepath
|
|
});
|
|
}
|
|
} else {
|
|
unlinkSync(filepath);
|
|
}
|
|
} catch (err) {
|
|
if (err.code !== "ENOENT" || !opts.force) throw err;
|
|
}
|
|
}
|
|
async function unlink(filepath, cb) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.unlink(req.handle, filepath);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "unlink",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function unlinkSync(filepath) {
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.unlinkSync(req.handle, filepath);
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "unlink",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function rename(src, dst, cb) {
|
|
src = toNamespacedPath(src);
|
|
dst = toNamespacedPath(dst);
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.rename(req.handle, src, dst);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "rename",
|
|
code: e.code,
|
|
path: src,
|
|
destination: dst
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function renameSync(src, dst) {
|
|
src = toNamespacedPath(src);
|
|
dst = toNamespacedPath(dst);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.renameSync(req.handle, src, dst);
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "rename",
|
|
code: e.code,
|
|
path: src,
|
|
destination: dst
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function copyFile(src, dst, mode = 0, cb) {
|
|
if (typeof mode === "function") {
|
|
cb = mode;
|
|
mode = 0;
|
|
}
|
|
src = toNamespacedPath(src);
|
|
dst = toNamespacedPath(dst);
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.copyfile(req.handle, src, dst, mode);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "copyfile",
|
|
code: e.code,
|
|
path: src,
|
|
destination: dst
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function copyFileSync(src, dst, mode = 0) {
|
|
src = toNamespacedPath(src);
|
|
dst = toNamespacedPath(dst);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.copyfileSync(req.handle, src, dst, mode);
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "copyfile",
|
|
code: e.code,
|
|
path: src,
|
|
destination: dst
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function cp(src, dst, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (!opts) opts = {};
|
|
src = toNamespacedPath(src);
|
|
dst = toNamespacedPath(dst);
|
|
let err = null;
|
|
try {
|
|
const st = await lstat(src);
|
|
if (st.isDirectory()) {
|
|
if (opts.recursive !== true) {
|
|
throw new FileError("is a directory", { operation: "cp", code: "EISDIR", path: src });
|
|
}
|
|
try {
|
|
await lstat(dst);
|
|
} catch (e) {
|
|
if (e.code !== "ENOENT") throw e;
|
|
await mkdir(dst, { mode: st.mode, recursive: true });
|
|
}
|
|
const dir = await opendir(src);
|
|
for await (const { name } of dir) {
|
|
await cp(path.join(src, name), path.join(dst, name), opts);
|
|
}
|
|
} else if (st.isFile()) {
|
|
await copyFile(src, dst);
|
|
await chmod(dst, st.mode);
|
|
}
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function cpSync(src, dst, opts = {}) {
|
|
src = toNamespacedPath(src);
|
|
dst = toNamespacedPath(dst);
|
|
const st = lstatSync(src);
|
|
if (st.isDirectory()) {
|
|
if (opts.recursive !== true) {
|
|
throw new FileError("is a directory", { operation: "cp", code: "EISDIR", path: src });
|
|
}
|
|
try {
|
|
lstatSync(dst);
|
|
} catch (e) {
|
|
if (e.code !== "ENOENT") throw e;
|
|
mkdirSync(dst, { mode: st.mode, recursive: true });
|
|
}
|
|
const dir = opendirSync(src);
|
|
for (const { name } of dir) {
|
|
cpSync(path.join(src, name), path.join(dst, name), opts);
|
|
}
|
|
} else if (st.isFile()) {
|
|
copyFileSync(src, dst);
|
|
chmodSync(dst, st.mode);
|
|
}
|
|
}
|
|
async function realpath(filepath, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
const { encoding = "utf8" } = opts;
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let res;
|
|
let err = null;
|
|
try {
|
|
binding.realpath(req.handle, filepath);
|
|
await req;
|
|
res = Buffer.from(binding.requestResultString(req.handle));
|
|
if (encoding !== "buffer") res = res.toString(encoding);
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "realpath",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, res, cb);
|
|
}
|
|
function realpathSync(filepath, opts) {
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
const { encoding = "utf8" } = opts;
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.realpathSync(req.handle, filepath);
|
|
let res = Buffer.from(binding.requestResultString(req.handle));
|
|
if (encoding !== "buffer") res = res.toString(encoding);
|
|
return res;
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "realpath",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function readlink(filepath, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
const { encoding = "utf8" } = opts;
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let res;
|
|
let err = null;
|
|
try {
|
|
binding.readlink(req.handle, filepath);
|
|
await req;
|
|
res = Buffer.from(binding.requestResultString(req.handle));
|
|
if (encoding !== "buffer") res = res.toString(encoding);
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "readlink",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, res, cb);
|
|
}
|
|
function readlinkSync(filepath, opts) {
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
const { encoding = "utf8" } = opts;
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.readlinkSync(req.handle, filepath);
|
|
let res = Buffer.from(binding.requestResultString(req.handle));
|
|
if (encoding !== "buffer") res = res.toString(encoding);
|
|
return res;
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "readlink",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function fsync(fd, cb) {
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.fsync(req.handle, fd);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "fsync", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function fsyncSync(fd) {
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.fsyncSync(req.handle, fd);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "fsyncSync", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function fdatasync(fd, cb) {
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.fdatasync(req.handle, fd);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, { operation: "fdatasync", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function fdatasyncSync(fd) {
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.fdatasyncSync(req.handle, fd);
|
|
} catch (e) {
|
|
throw new FileError(e.message, { operation: "fdatasyncSync", code: e.code, fd });
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
function normalizeSymlinkTarget(target, type, filepath) {
|
|
if (isWindows) {
|
|
if (type === constants.UV_FS_SYMLINK_JUNCTION) target = path.resolve(filepath, "..", target);
|
|
if (path.isAbsolute(target)) return path.toNamespacedPath(target);
|
|
return target.replace(/\//g, path.sep);
|
|
}
|
|
return target;
|
|
}
|
|
async function symlink(target, filepath, type, cb) {
|
|
if (typeof type === "function") {
|
|
cb = type;
|
|
type = null;
|
|
}
|
|
filepath = toNamespacedPath(filepath);
|
|
if (typeof type === "string") {
|
|
switch (type) {
|
|
case "dir":
|
|
type = constants.UV_FS_SYMLINK_DIR;
|
|
break;
|
|
case "junction":
|
|
type = constants.UV_FS_SYMLINK_JUNCTION;
|
|
break;
|
|
case "file":
|
|
default:
|
|
type = 0;
|
|
break;
|
|
}
|
|
} else if (typeof type !== "number") {
|
|
if (isWindows) {
|
|
target = path.resolve(filepath, "..", target);
|
|
try {
|
|
type = (await stat(target)).isDirectory() ? constants.UV_FS_SYMLINK_DIR : constants.UV_FS_SYMLINK_JUNCTION;
|
|
} catch {
|
|
type = 0;
|
|
}
|
|
} else {
|
|
type = 0;
|
|
}
|
|
}
|
|
target = normalizeSymlinkTarget(target, type, filepath);
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.symlink(req.handle, target, filepath, type);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "symlink",
|
|
code: e.code,
|
|
path: target,
|
|
destination: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, cb);
|
|
}
|
|
function symlinkSync(target, filepath, type) {
|
|
filepath = toNamespacedPath(filepath);
|
|
if (typeof type === "string") {
|
|
switch (type) {
|
|
case "dir":
|
|
type = constants.UV_FS_SYMLINK_DIR;
|
|
break;
|
|
case "junction":
|
|
type = constants.UV_FS_SYMLINK_JUNCTION;
|
|
break;
|
|
case "file":
|
|
default:
|
|
type = 0;
|
|
break;
|
|
}
|
|
} else if (typeof type !== "number") {
|
|
if (isWindows) {
|
|
target = path.resolve(filepath, "..", target);
|
|
try {
|
|
type = statSync(target).isDirectory() ? constants.UV_FS_SYMLINK_DIR : constants.UV_FS_SYMLINK_JUNCTION;
|
|
} catch {
|
|
type = 0;
|
|
}
|
|
} else {
|
|
type = 0;
|
|
}
|
|
}
|
|
target = normalizeSymlinkTarget(target, type, filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.symlinkSync(req.handle, target, filepath, type);
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "symlink",
|
|
code: e.code,
|
|
path: target,
|
|
destination: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function opendir(filepath, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
let dir;
|
|
let err = null;
|
|
try {
|
|
binding.opendir(req.handle, filepath);
|
|
await req;
|
|
dir = new Dir(filepath, binding.requestResultDir(req.handle), opts);
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "opendir",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
return done(err, dir, cb);
|
|
}
|
|
function opendirSync(filepath, opts) {
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
filepath = toNamespacedPath(filepath);
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.opendirSync(req.handle, filepath);
|
|
return new Dir(filepath, binding.requestResultDir(req.handle), opts);
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "opendir",
|
|
code: e.code,
|
|
path: filepath
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
}
|
|
async function readdir(filepath, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
const { withFileTypes = false, recursive = false } = opts;
|
|
filepath = toNamespacedPath(filepath);
|
|
const queue = [filepath];
|
|
let result = [];
|
|
let err = null;
|
|
try {
|
|
while (queue.length !== 0) {
|
|
const dir = await opendir(queue.pop());
|
|
for await (const entry of dir) {
|
|
const entryPath = path.join(entry.parentPath, entry.name);
|
|
if (withFileTypes) {
|
|
result.push(entry);
|
|
} else {
|
|
result.push(path.relative(filepath, entryPath));
|
|
}
|
|
if (recursive && entry.isDirectory()) queue.push(entryPath);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
result = [];
|
|
err = e;
|
|
}
|
|
return done(err, result, cb);
|
|
}
|
|
function readdirSync(filepath, opts) {
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
const { withFileTypes = false, recursive = false } = opts;
|
|
filepath = toNamespacedPath(filepath);
|
|
const queue = [filepath];
|
|
const result = [];
|
|
while (queue.length !== 0) {
|
|
const dir = opendirSync(queue.pop(), opts);
|
|
for (const entry of dir) {
|
|
const entryPath = path.join(entry.parentPath, entry.name);
|
|
if (withFileTypes) {
|
|
result.push(entry);
|
|
} else {
|
|
result.push(path.relative(filepath, entryPath));
|
|
}
|
|
if (recursive && entry.isDirectory()) queue.push(entryPath);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
async function readFile(filepath, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
const { encoding = "buffer" } = opts;
|
|
let fd = -1;
|
|
let buffer = null;
|
|
let err = null;
|
|
try {
|
|
fd = await open(filepath, opts.flag || "r");
|
|
const st = await fstat(fd);
|
|
let len = 0;
|
|
if (st.size === 0) {
|
|
const buffers = [];
|
|
while (true) {
|
|
buffer = Buffer.allocUnsafe(8192);
|
|
const r = await read(fd, buffer);
|
|
len += r;
|
|
if (r === 0) break;
|
|
buffers.push(buffer.subarray(0, r));
|
|
}
|
|
buffer = Buffer.concat(buffers);
|
|
} else {
|
|
buffer = Buffer.allocUnsafe(st.size);
|
|
while (true) {
|
|
const r = await read(fd, len ? buffer.subarray(len) : buffer);
|
|
len += r;
|
|
if (r === 0 || len === buffer.byteLength) break;
|
|
}
|
|
if (len !== buffer.byteLength) buffer = buffer.subarray(0, len);
|
|
}
|
|
if (encoding !== "buffer") buffer = buffer.toString(encoding);
|
|
} catch (e) {
|
|
err = e;
|
|
} finally {
|
|
if (fd !== -1) await close(fd);
|
|
}
|
|
return done(err, buffer, cb);
|
|
}
|
|
function readFileSync(filepath, opts) {
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
const { encoding = "buffer" } = opts;
|
|
let fd = -1;
|
|
try {
|
|
fd = openSync(filepath, opts.flag || "r");
|
|
const st = fstatSync(fd);
|
|
let buffer;
|
|
let len = 0;
|
|
if (st.size === 0) {
|
|
const buffers = [];
|
|
while (true) {
|
|
buffer = Buffer.allocUnsafe(8192);
|
|
const r = readSync(fd, buffer);
|
|
len += r;
|
|
if (r === 0) break;
|
|
buffers.push(buffer.subarray(0, r));
|
|
}
|
|
buffer = Buffer.concat(buffers);
|
|
} else {
|
|
buffer = Buffer.allocUnsafe(st.size);
|
|
while (true) {
|
|
const r = readSync(fd, len ? buffer.subarray(len) : buffer);
|
|
len += r;
|
|
if (r === 0 || len === buffer.byteLength) break;
|
|
}
|
|
if (len !== buffer.byteLength) buffer = buffer.subarray(0, len);
|
|
}
|
|
if (encoding !== "buffer") buffer = buffer.toString(encoding);
|
|
return buffer;
|
|
} finally {
|
|
if (fd !== -1) closeSync(fd);
|
|
}
|
|
}
|
|
async function writeFile(filepath, data, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
if (typeof data === "string") data = Buffer.from(data, opts.encoding);
|
|
let fd = -1;
|
|
let len = 0;
|
|
let err = null;
|
|
try {
|
|
fd = await open(filepath, opts.flag || "w", opts.mode || 438);
|
|
while (true) {
|
|
len += await write(fd, len ? data.subarray(len) : data);
|
|
if (len === data.byteLength) break;
|
|
}
|
|
} catch (e) {
|
|
err = e;
|
|
} finally {
|
|
if (fd !== -1) await close(fd);
|
|
}
|
|
return done(err, len, cb);
|
|
}
|
|
function writeFileSync(filepath, data, opts) {
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
if (typeof data === "string") data = Buffer.from(data, opts.encoding);
|
|
let fd = -1;
|
|
try {
|
|
fd = openSync(filepath, opts.flag || "w", opts.mode || 438);
|
|
let len = 0;
|
|
while (true) {
|
|
len += writeSync(fd, len ? data.subarray(len) : data);
|
|
if (len === data.byteLength) break;
|
|
}
|
|
} finally {
|
|
if (fd !== -1) closeSync(fd);
|
|
}
|
|
}
|
|
function appendFile(filepath, data, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
if (!opts.flag) opts = { ...opts, flag: "a" };
|
|
return writeFile(filepath, data, opts, cb);
|
|
}
|
|
function appendFileSync(filepath, data, opts) {
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
if (!opts.flag) opts = { ...opts, flag: "a" };
|
|
return writeFileSync(filepath, data, opts);
|
|
}
|
|
function watch(filepath, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (typeof opts === "string") opts = { encoding: opts };
|
|
else if (!opts) opts = {};
|
|
filepath = toNamespacedPath(filepath);
|
|
return new Watcher(filepath, opts, cb);
|
|
}
|
|
var Stats = class {
|
|
constructor(dev, mode, nlink, uid, gid, rdev, blksize, ino, size, blocks, atimeMs, mtimeMs, ctimeMs, birthtimeMs) {
|
|
this.dev = dev;
|
|
this.mode = mode;
|
|
this.nlink = nlink;
|
|
this.uid = uid;
|
|
this.gid = gid;
|
|
this.rdev = rdev;
|
|
this.blksize = blksize;
|
|
this.ino = ino;
|
|
this.size = size;
|
|
this.blocks = blocks;
|
|
this.atimeMs = atimeMs;
|
|
this.mtimeMs = mtimeMs;
|
|
this.ctimeMs = ctimeMs;
|
|
this.birthtimeMs = birthtimeMs;
|
|
this.atime = new Date(atimeMs);
|
|
this.mtime = new Date(mtimeMs);
|
|
this.ctime = new Date(ctimeMs);
|
|
this.birthtime = new Date(birthtimeMs);
|
|
}
|
|
isDirectory() {
|
|
return (this.mode & constants.S_IFMT) === constants.S_IFDIR;
|
|
}
|
|
isFile() {
|
|
return (this.mode & constants.S_IFMT) === constants.S_IFREG;
|
|
}
|
|
isBlockDevice() {
|
|
return (this.mode & constants.S_IFMT) === constants.S_IFBLK;
|
|
}
|
|
isCharacterDevice() {
|
|
return (this.mode & constants.S_IFMT) === constants.S_IFCHR;
|
|
}
|
|
isFIFO() {
|
|
return (this.mode & constants.S_IFMT) === constants.S_IFIFO;
|
|
}
|
|
isSymbolicLink() {
|
|
return (this.mode & constants.S_IFMT) === constants.S_IFLNK;
|
|
}
|
|
isSocket() {
|
|
return (this.mode & constants.S_IFMT) === constants.S_IFSOCK;
|
|
}
|
|
};
|
|
var StatFs = class {
|
|
constructor(type, bsize, blocks, bfree, bavail, files, ffree, frsize) {
|
|
this.type = type;
|
|
this.bsize = bsize;
|
|
this.blocks = blocks;
|
|
this.bfree = bfree;
|
|
this.bavail = bavail;
|
|
this.files = files;
|
|
this.ffree = ffree;
|
|
this.frsize = frsize;
|
|
}
|
|
};
|
|
var Dir = class {
|
|
constructor(path2, handle, opts = {}) {
|
|
const { encoding = "utf8", bufferSize = 32 } = opts;
|
|
this.path = path2;
|
|
this._encoding = encoding;
|
|
this._capacity = bufferSize;
|
|
this._buffer = new FIFO();
|
|
this._ended = false;
|
|
this._handle = handle;
|
|
}
|
|
async read(cb) {
|
|
if (this._buffer.length) return ok(this._buffer.shift(), cb);
|
|
if (this._ended) return ok(null, cb);
|
|
const req = FileRequest.borrow();
|
|
let entries;
|
|
let err = null;
|
|
try {
|
|
req.retain(binding.readdir(req.handle, this._handle, this._capacity));
|
|
await req;
|
|
entries = binding.requestResultDirents(req.handle);
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "readdir",
|
|
code: e.code,
|
|
path: this.path
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
if (err) return fail(err, cb);
|
|
if (entries.length === 0) {
|
|
this._ended = true;
|
|
return ok(null, cb);
|
|
}
|
|
for (const entry of entries) {
|
|
let name = Buffer.from(entry.name);
|
|
if (this._encoding !== "buffer") name = name.toString(this._encoding);
|
|
this._buffer.push(new Dirent(this.path, name, entry.type));
|
|
}
|
|
return ok(this._buffer.shift(), cb);
|
|
}
|
|
readSync() {
|
|
if (this._buffer.length) return this._buffer.shift();
|
|
if (this._ended) return null;
|
|
const req = FileRequest.borrow();
|
|
let entries;
|
|
try {
|
|
req.retain(binding.readdirSync(req.handle, this._handle, this._capacity));
|
|
entries = binding.requestResultDirents(req.handle);
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "readdir",
|
|
code: e.code,
|
|
path: this.path
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
if (entries.length === 0) {
|
|
this._ended = true;
|
|
return null;
|
|
}
|
|
for (const entry of entries) {
|
|
let name = Buffer.from(entry.name);
|
|
if (this._encoding !== "buffer") name = name.toString(this._encoding);
|
|
this._buffer.push(new Dirent(this.path, name, entry.type));
|
|
}
|
|
return this._buffer.shift();
|
|
}
|
|
async close(cb) {
|
|
const req = FileRequest.borrow();
|
|
let err = null;
|
|
try {
|
|
binding.closedir(req.handle, this._handle);
|
|
await req;
|
|
} catch (e) {
|
|
err = new FileError(e.message, {
|
|
operation: "closedir",
|
|
code: e.code,
|
|
path: this.path
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
this._handle = null;
|
|
return done(err, cb);
|
|
}
|
|
closeSync() {
|
|
const req = FileRequest.borrow();
|
|
try {
|
|
binding.closedirSync(req.handle, this._handle);
|
|
} catch (e) {
|
|
throw new FileError(e.message, {
|
|
operation: "closedir",
|
|
code: e.code,
|
|
path: this.path
|
|
});
|
|
} finally {
|
|
req.return();
|
|
}
|
|
this._handle = null;
|
|
}
|
|
[Symbol.dispose]() {
|
|
this.closeSync();
|
|
}
|
|
async [Symbol.asyncDispose]() {
|
|
await this.close();
|
|
}
|
|
*[Symbol.iterator]() {
|
|
while (true) {
|
|
const entry = this.readSync();
|
|
if (entry === null) break;
|
|
yield entry;
|
|
}
|
|
this.closeSync();
|
|
}
|
|
async *[Symbol.asyncIterator]() {
|
|
while (true) {
|
|
const entry = await this.read();
|
|
if (entry === null) break;
|
|
yield entry;
|
|
}
|
|
await this.close();
|
|
}
|
|
};
|
|
var Dirent = class {
|
|
constructor(parentPath, name, type) {
|
|
this.parentPath = parentPath;
|
|
this.name = name;
|
|
this.type = type;
|
|
}
|
|
isFile() {
|
|
return this.type === constants.UV_DIRENT_FILE;
|
|
}
|
|
isDirectory() {
|
|
return this.type === constants.UV_DIRENT_DIR;
|
|
}
|
|
isSymbolicLink() {
|
|
return this.type === constants.UV_DIRENT_LINK;
|
|
}
|
|
isFIFO() {
|
|
return this.type === constants.UV_DIRENT_FIFO;
|
|
}
|
|
isSocket() {
|
|
return this.type === constants.UV_DIRENT_SOCKET;
|
|
}
|
|
isCharacterDevice() {
|
|
return this.type === constants.UV_DIRENT_CHAR;
|
|
}
|
|
isBlockDevice() {
|
|
return this.type === constants.UV_DIRENT_BLOCK;
|
|
}
|
|
};
|
|
var FileReadStream = class extends Readable {
|
|
constructor(path2, opts = {}) {
|
|
const { eagerOpen = true } = opts;
|
|
super({ eagerOpen, ...opts });
|
|
this.path = path2;
|
|
this.fd = typeof opts.fd === "number" ? opts.fd : -1;
|
|
this.flags = opts.flags || "r";
|
|
this.mode = opts.mode || 438;
|
|
this._offset = opts.start || 0;
|
|
this._missing = 0;
|
|
if (opts.length) {
|
|
this._missing = opts.length;
|
|
} else if (typeof opts.end === "number") {
|
|
this._missing = opts.end - this._offset + 1;
|
|
} else {
|
|
this._missing = -1;
|
|
}
|
|
}
|
|
async _open(cb) {
|
|
let err;
|
|
if (this.fd === -1) {
|
|
err = null;
|
|
try {
|
|
this.fd = await open(this.path, this.flags, this.mode);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
if (err) return cb(err);
|
|
}
|
|
let st;
|
|
err = null;
|
|
try {
|
|
st = await fstat(this.fd);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
if (err) return cb(err);
|
|
if (this._missing === -1) this._missing = st.size;
|
|
if (st.size < this._offset) {
|
|
this._offset = st.size;
|
|
this._missing = 0;
|
|
} else if (st.size < this._offset + this._missing) {
|
|
this._missing = st.size - this._offset;
|
|
}
|
|
cb(null);
|
|
}
|
|
async _read(size) {
|
|
if (this._missing <= 0) return this.push(null);
|
|
const data = Buffer.allocUnsafe(Math.min(this._missing, size));
|
|
let len;
|
|
let err = null;
|
|
try {
|
|
len = await read(this.fd, data, 0, data.byteLength, this._offset);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
if (err) return this.destroy(err);
|
|
if (len === 0) return this.push(null);
|
|
if (this._missing < len) len = this._missing;
|
|
this._missing -= len;
|
|
this._offset += len;
|
|
this.push(data.subarray(0, len));
|
|
}
|
|
async _destroy(err, cb) {
|
|
if (this.fd === -1) return cb(err);
|
|
try {
|
|
await close(this.fd);
|
|
} catch (e) {
|
|
err = err || e;
|
|
}
|
|
cb(err);
|
|
}
|
|
};
|
|
var FileWriteStream = class extends Writable {
|
|
constructor(path2, opts = {}) {
|
|
const { eagerOpen = true } = opts;
|
|
super({ eagerOpen, ...opts });
|
|
this.path = path2;
|
|
this.fd = typeof opts.fd === "number" ? opts.fd : -1;
|
|
this.flags = opts.flags || "w";
|
|
this.mode = opts.mode || 438;
|
|
}
|
|
async _open(cb) {
|
|
if (this.fd !== -1) return cb(null);
|
|
let err = null;
|
|
try {
|
|
this.fd = await open(this.path, this.flags, this.mode);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _writev(batch, cb) {
|
|
let err = null;
|
|
try {
|
|
await writev(
|
|
this.fd,
|
|
batch.map(({ chunk }) => chunk)
|
|
);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _destroy(err, cb) {
|
|
if (this.fd === -1) return cb(err);
|
|
try {
|
|
await close(this.fd);
|
|
} catch (e) {
|
|
err = err || e;
|
|
}
|
|
cb(err);
|
|
}
|
|
};
|
|
var Watcher = class extends EventEmitter {
|
|
constructor(path2, opts, onchange) {
|
|
if (typeof opts === "function") {
|
|
onchange = opts;
|
|
opts = {};
|
|
}
|
|
if (!opts) opts = {};
|
|
const { persistent = true, recursive = false, encoding = "utf8" } = opts;
|
|
super();
|
|
this._closed = false;
|
|
this._encoding = encoding;
|
|
this._handle = binding.watcherInit(path2, recursive, this, this._onevent, this._onclose);
|
|
if (!persistent) this.unref();
|
|
if (onchange) this.on("change", onchange);
|
|
}
|
|
close() {
|
|
if (this._closed) return;
|
|
this._closed = true;
|
|
binding.watcherClose(this._handle);
|
|
}
|
|
ref() {
|
|
if (this._handle) binding.watcherRef(this._handle);
|
|
return this;
|
|
}
|
|
unref() {
|
|
if (this._handle) binding.watcherUnref(this._handle);
|
|
return this;
|
|
}
|
|
[Symbol.asyncIterator]() {
|
|
const buffer = [];
|
|
let done2 = false;
|
|
let error = null;
|
|
let next = null;
|
|
this.on("change", (eventType, filename) => {
|
|
if (next) {
|
|
next.resolve({ done: false, value: { eventType, filename } });
|
|
next = null;
|
|
} else {
|
|
buffer.push({ eventType, filename });
|
|
}
|
|
}).on("error", (err) => {
|
|
done2 = true;
|
|
error = err;
|
|
if (next) {
|
|
next.reject(error);
|
|
next = null;
|
|
}
|
|
}).on("close", () => {
|
|
done2 = true;
|
|
if (next) {
|
|
next.resolve({ done: done2 });
|
|
next = null;
|
|
}
|
|
});
|
|
return {
|
|
next: () => new Promise((resolve, reject) => {
|
|
if (error) return reject(error);
|
|
if (buffer.length) return resolve({ done: false, value: buffer.shift() });
|
|
if (done2) return resolve({ done: done2 });
|
|
next = { resolve, reject };
|
|
})
|
|
};
|
|
}
|
|
_onevent(err, events, filename) {
|
|
if (err) {
|
|
this.close();
|
|
this.emit("error", err);
|
|
} else {
|
|
const path2 = this._encoding === "buffer" ? Buffer.from(filename) : Buffer.from(filename).toString(this._encoding);
|
|
if (events & binding.UV_RENAME) {
|
|
this.emit("change", "rename", path2);
|
|
}
|
|
if (events & binding.UV_CHANGE) {
|
|
this.emit("change", "change", path2);
|
|
}
|
|
}
|
|
}
|
|
_onclose() {
|
|
this._handle = null;
|
|
this.emit("close");
|
|
}
|
|
};
|
|
exports.access = access;
|
|
exports.appendFile = appendFile;
|
|
exports.chmod = chmod;
|
|
exports.chown = chown;
|
|
exports.close = close;
|
|
exports.copyFile = copyFile;
|
|
exports.cp = cp;
|
|
exports.exists = exists;
|
|
exports.fchmod = fchmod;
|
|
exports.fchown = fchown;
|
|
exports.fdatasync = fdatasync;
|
|
exports.fstat = fstat;
|
|
exports.fsync = fsync;
|
|
exports.ftruncate = ftruncate;
|
|
exports.futimes = futimes;
|
|
exports.lchown = lchown;
|
|
exports.lutimes = lutimes;
|
|
exports.link = link;
|
|
exports.lstat = lstat;
|
|
exports.mkdir = mkdir;
|
|
exports.mkdtemp = mkdtemp;
|
|
exports.open = open;
|
|
exports.opendir = opendir;
|
|
exports.read = read;
|
|
exports.readFile = readFile;
|
|
exports.readdir = readdir;
|
|
exports.readlink = readlink;
|
|
exports.readv = readv;
|
|
exports.realpath = realpath;
|
|
exports.rename = rename;
|
|
exports.rm = rm;
|
|
exports.rmdir = rmdir;
|
|
exports.stat = stat;
|
|
exports.statfs = statfs;
|
|
exports.symlink = symlink;
|
|
exports.truncate = truncate;
|
|
exports.unlink = unlink;
|
|
exports.utimes = utimes;
|
|
exports.watch = watch;
|
|
exports.write = write;
|
|
exports.writeFile = writeFile;
|
|
exports.writev = writev;
|
|
exports.accessSync = accessSync;
|
|
exports.appendFileSync = appendFileSync;
|
|
exports.chmodSync = chmodSync;
|
|
exports.chownSync = chownSync;
|
|
exports.closeSync = closeSync;
|
|
exports.copyFileSync = copyFileSync;
|
|
exports.cpSync = cpSync;
|
|
exports.existsSync = existsSync;
|
|
exports.fchmodSync = fchmodSync;
|
|
exports.fchownSync = fchownSync;
|
|
exports.fdatasyncSync = fdatasyncSync;
|
|
exports.fstatSync = fstatSync;
|
|
exports.fsyncSync = fsyncSync;
|
|
exports.ftruncateSync = ftruncateSync;
|
|
exports.futimesSync = futimesSync;
|
|
exports.lchownSync = lchownSync;
|
|
exports.lutimesSync = lutimesSync;
|
|
exports.linkSync = linkSync;
|
|
exports.lstatSync = lstatSync;
|
|
exports.mkdirSync = mkdirSync;
|
|
exports.mkdtempSync = mkdtempSync;
|
|
exports.openSync = openSync;
|
|
exports.opendirSync = opendirSync;
|
|
exports.readFileSync = readFileSync;
|
|
exports.readSync = readSync;
|
|
exports.readdirSync = readdirSync;
|
|
exports.readlinkSync = readlinkSync;
|
|
exports.readvSync = readvSync;
|
|
exports.realpathSync = realpathSync;
|
|
exports.renameSync = renameSync;
|
|
exports.rmSync = rmSync;
|
|
exports.rmdirSync = rmdirSync;
|
|
exports.statSync = statSync;
|
|
exports.statfsSync = statfsSync;
|
|
exports.symlinkSync = symlinkSync;
|
|
exports.truncateSync = truncateSync;
|
|
exports.unlinkSync = unlinkSync;
|
|
exports.utimesSync = utimesSync;
|
|
exports.writeFileSync = writeFileSync;
|
|
exports.writeSync = writeSync;
|
|
exports.writevSync = writevSync;
|
|
exports.promises = require_promises();
|
|
exports.Stats = Stats;
|
|
exports.StatFs = StatFs;
|
|
exports.Dir = Dir;
|
|
exports.Dirent = Dirent;
|
|
exports.Watcher = Watcher;
|
|
exports.ReadStream = FileReadStream;
|
|
exports.createReadStream = function createReadStream(path2, opts) {
|
|
return new FileReadStream(path2, opts);
|
|
};
|
|
exports.WriteStream = FileWriteStream;
|
|
exports.createWriteStream = function createWriteStream(path2, opts) {
|
|
return new FileWriteStream(path2, opts);
|
|
};
|
|
function toNamespacedPath(filepath) {
|
|
if (typeof filepath !== "string") {
|
|
if (isURL(filepath)) filepath = fileURLToPath(filepath);
|
|
else filepath = filepath.toString();
|
|
}
|
|
return path.toNamespacedPath(filepath);
|
|
}
|
|
function toFlags(flags) {
|
|
switch (flags) {
|
|
case "r":
|
|
return constants.O_RDONLY;
|
|
case "rs":
|
|
// Fall through.
|
|
case "sr":
|
|
return constants.O_RDONLY | constants.O_SYNC;
|
|
case "r+":
|
|
return constants.O_RDWR;
|
|
case "rs+":
|
|
// Fall through.
|
|
case "sr+":
|
|
return constants.O_RDWR | constants.O_SYNC;
|
|
case "w":
|
|
return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY;
|
|
case "wx":
|
|
// Fall through.
|
|
case "xw":
|
|
return constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY | constants.O_EXCL;
|
|
case "w+":
|
|
return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR;
|
|
case "wx+":
|
|
// Fall through.
|
|
case "xw+":
|
|
return constants.O_TRUNC | constants.O_CREAT | constants.O_RDWR | constants.O_EXCL;
|
|
case "a":
|
|
return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY;
|
|
case "ax":
|
|
// Fall through.
|
|
case "xa":
|
|
return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY | constants.O_EXCL;
|
|
case "as":
|
|
// Fall through.
|
|
case "sa":
|
|
return constants.O_APPEND | constants.O_CREAT | constants.O_WRONLY | constants.O_SYNC;
|
|
case "a+":
|
|
return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR;
|
|
case "ax+":
|
|
// Fall through.
|
|
case "xa+":
|
|
return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR | constants.O_EXCL;
|
|
case "as+":
|
|
// Fall through.
|
|
case "sa+":
|
|
return constants.O_APPEND | constants.O_CREAT | constants.O_RDWR | constants.O_SYNC;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
function toMode(mode) {
|
|
return parseInt(mode, 8);
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-fs/promises.js
|
|
var require_promises = __commonJS({
|
|
"../../node_modules/bare-fs/promises.js"(exports) {
|
|
var EventEmitter = require_bare_events();
|
|
var fs = require_bare_fs();
|
|
var FileHandle = class extends EventEmitter {
|
|
constructor(fd) {
|
|
super();
|
|
this.fd = fd;
|
|
}
|
|
async close() {
|
|
await fs.close(this.fd);
|
|
this.fd = -1;
|
|
this.emit("close");
|
|
}
|
|
async read(buffer, ...args) {
|
|
return {
|
|
bytesRead: await fs.read(this.fd, buffer, ...args),
|
|
buffer
|
|
};
|
|
}
|
|
async readv(buffers, ...args) {
|
|
return {
|
|
bytesRead: await fs.readv(this.fd, buffers, ...args),
|
|
buffers
|
|
};
|
|
}
|
|
async write(buffer, ...args) {
|
|
return {
|
|
bytesWritten: await fs.write(this.fd, buffer, ...args),
|
|
buffer
|
|
};
|
|
}
|
|
async writev(buffers, ...args) {
|
|
return {
|
|
bytesWritten: await fs.writev(this.fd, buffers, ...args),
|
|
buffers
|
|
};
|
|
}
|
|
async stat() {
|
|
return fs.fstat(this.fd);
|
|
}
|
|
async chmod(mode) {
|
|
await fs.fchmod(this.fd, mode);
|
|
}
|
|
async chown(uid, gid) {
|
|
await fs.fchown(this.fd, uid, gid);
|
|
}
|
|
async datasync() {
|
|
return fs.fdatasync(this.fd);
|
|
}
|
|
async sync() {
|
|
return fs.fsync(this.fd);
|
|
}
|
|
async truncate(len) {
|
|
await fs.ftruncate(this.fd, len);
|
|
}
|
|
async utimes(atime, mtime) {
|
|
await fs.futimes(this.fd, atime, mtime);
|
|
}
|
|
createReadStream(opts) {
|
|
return fs.createReadStream(null, { ...opts, fd: this.fd });
|
|
}
|
|
createWriteStream(opts) {
|
|
return fs.createWriteStream(null, { ...opts, fd: this.fd });
|
|
}
|
|
async [Symbol.asyncDispose]() {
|
|
await this.close();
|
|
}
|
|
};
|
|
exports.open = async function open(filepath, flags, mode) {
|
|
return new FileHandle(await fs.open(filepath, flags, mode));
|
|
};
|
|
exports.access = fs.access;
|
|
exports.appendFile = fs.appendFile;
|
|
exports.chmod = fs.chmod;
|
|
exports.chown = fs.chown;
|
|
exports.constants = fs.constants;
|
|
exports.copyFile = fs.copyFile;
|
|
exports.cp = fs.cp;
|
|
exports.lchown = fs.lchown;
|
|
exports.lutimes = fs.lutimes;
|
|
exports.link = fs.link;
|
|
exports.lstat = fs.lstat;
|
|
exports.mkdir = fs.mkdir;
|
|
exports.mkdtemp = fs.mkdtemp;
|
|
exports.opendir = fs.opendir;
|
|
exports.readFile = fs.readFile;
|
|
exports.readdir = fs.readdir;
|
|
exports.readlink = fs.readlink;
|
|
exports.realpath = fs.realpath;
|
|
exports.rename = fs.rename;
|
|
exports.rm = fs.rm;
|
|
exports.rmdir = fs.rmdir;
|
|
exports.stat = fs.stat;
|
|
exports.statfs = fs.statfs;
|
|
exports.truncate = fs.truncate;
|
|
exports.symlink = fs.symlink;
|
|
exports.unlink = fs.unlink;
|
|
exports.utimes = fs.utimes;
|
|
exports.watch = fs.watch;
|
|
exports.writeFile = fs.writeFile;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/promaphore/index.js
|
|
var require_promaphore = __commonJS({
|
|
"../../node_modules/promaphore/index.js"(exports, module) {
|
|
var DONE = Promise.resolve(true);
|
|
var DESTROYED = Promise.resolve(false);
|
|
module.exports = class Semaphore {
|
|
constructor(limit = 1) {
|
|
this.limit = limit;
|
|
this.active = 0;
|
|
this.waiting = [];
|
|
this.destroyed = false;
|
|
this._onwait = (resolve) => {
|
|
this.waiting.push(resolve);
|
|
};
|
|
}
|
|
wait() {
|
|
if (this.destroyed === true) return DESTROYED;
|
|
if (this.active < this.limit && this.waiting.length === 0) {
|
|
this.active++;
|
|
return DONE;
|
|
}
|
|
return new Promise(this._onwait);
|
|
}
|
|
signal() {
|
|
if (this.destroyed === true) return;
|
|
this.active--;
|
|
while (this.active < this.limit && this.waiting.length > 0 && this.destroyed === false) {
|
|
this.active++;
|
|
this.waiting.shift()(true);
|
|
}
|
|
}
|
|
async flush() {
|
|
if (this.destroyed === true) return;
|
|
this.limit = 1;
|
|
await this.wait();
|
|
this.signal();
|
|
}
|
|
destroy() {
|
|
this.destroyed = true;
|
|
this.active = 0;
|
|
while (this.waiting.length) this.waiting.pop()(false);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-bundle/lib/errors.js
|
|
var require_errors5 = __commonJS({
|
|
"../../node_modules/bare-bundle/lib/errors.js"(exports, module) {
|
|
module.exports = class BundleError extends Error {
|
|
constructor(msg, fn = BundleError, opts = {}) {
|
|
const { cause, code = fn.name } = opts;
|
|
super(`${code}: ${msg}`, { cause });
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "BundleError";
|
|
}
|
|
static INVALID_BUNDLE_HEADER(msg, cause) {
|
|
return new BundleError(msg, BundleError.INVALID_BUNDLE_HEADER, { cause });
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-bundle/index.js
|
|
var require_bare_bundle = __commonJS({
|
|
"../../node_modules/bare-bundle/index.js"(exports, module) {
|
|
var errors = require_errors5();
|
|
var kind = Symbol.for("bare.bundle.kind");
|
|
var MemoryFile = class _MemoryFile {
|
|
constructor(data, opts = {}) {
|
|
const { executable = false, mode = executable ? 493 : 420 } = opts;
|
|
this._data = typeof data === "string" ? Buffer.from(data) : data;
|
|
this._mode = mode;
|
|
}
|
|
size() {
|
|
return this._data.byteLength;
|
|
}
|
|
mode() {
|
|
return this._mode;
|
|
}
|
|
read() {
|
|
return this._data;
|
|
}
|
|
inspect() {
|
|
return {
|
|
__proto__: { constructor: _MemoryFile },
|
|
data: this._data,
|
|
mode: this._mode.toString(8)
|
|
};
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return this.inspect();
|
|
}
|
|
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
return this.inspect();
|
|
}
|
|
};
|
|
module.exports = exports = class Bundle2 {
|
|
static get [kind]() {
|
|
return 0;
|
|
}
|
|
static get version() {
|
|
return 0;
|
|
}
|
|
constructor(opts = {}) {
|
|
const { File = MemoryFile } = opts;
|
|
this._File = File;
|
|
this._id = null;
|
|
this._main = null;
|
|
this._imports = {};
|
|
this._resolutions = {};
|
|
this._addons = [];
|
|
this._assets = [];
|
|
this._files = /* @__PURE__ */ new Map();
|
|
}
|
|
get [kind]() {
|
|
return Bundle2[kind];
|
|
}
|
|
get version() {
|
|
return Bundle2.version;
|
|
}
|
|
get id() {
|
|
return this._id;
|
|
}
|
|
set id(value) {
|
|
if (typeof value !== "string" && value !== null) {
|
|
throw new TypeError(`ID must be a string or null. Received type ${typeof value} (${value})`);
|
|
}
|
|
this._id = value;
|
|
}
|
|
get main() {
|
|
return this._main;
|
|
}
|
|
set main(value) {
|
|
if (typeof value !== "string" && value !== null) {
|
|
throw new TypeError(`Main must be a string or null. Received type ${typeof value} (${value})`);
|
|
}
|
|
this._main = value;
|
|
}
|
|
get imports() {
|
|
return this._imports;
|
|
}
|
|
set imports(value) {
|
|
this._imports = cloneImportsMap(value);
|
|
}
|
|
get resolutions() {
|
|
return this._resolutions;
|
|
}
|
|
set resolutions(value) {
|
|
this._resolutions = cloneResolutionsMap(value);
|
|
}
|
|
get addons() {
|
|
return this._addons;
|
|
}
|
|
set addons(value) {
|
|
this._addons = cloneFilesList(value, "Addons");
|
|
}
|
|
get assets() {
|
|
return this._assets;
|
|
}
|
|
set assets(value) {
|
|
this._assets = cloneFilesList(value, "Assets");
|
|
}
|
|
get files() {
|
|
return Object.fromEntries(this._files.entries());
|
|
}
|
|
*[Symbol.iterator]() {
|
|
for (const [key, file] of this._files) {
|
|
yield [key, file.read(), file.mode()];
|
|
}
|
|
}
|
|
empty() {
|
|
return this._files.size === 0;
|
|
}
|
|
keys() {
|
|
return this._files.keys();
|
|
}
|
|
exists(key) {
|
|
return this._files.has(key);
|
|
}
|
|
size(key) {
|
|
const file = this._files.get(key) || null;
|
|
if (file === null) return 0;
|
|
return file.size();
|
|
}
|
|
mode(key) {
|
|
const file = this._files.get(key) || null;
|
|
if (file === null) return 0;
|
|
return file.mode();
|
|
}
|
|
read(key) {
|
|
const file = this._files.get(key) || null;
|
|
if (file === null) return null;
|
|
return file.read();
|
|
}
|
|
write(key, data, opts = {}) {
|
|
if (typeof key !== "string") {
|
|
throw new TypeError(`File path must be a string. Received type ${typeof key} (${key})`);
|
|
}
|
|
const { main = false, alias = null, imports = null, addon = false, asset = false } = opts;
|
|
this._files.set(key, new MemoryFile(data, opts));
|
|
if (main) this._main = key;
|
|
if (alias) this._imports[alias] = key;
|
|
if (imports) this._resolutions[key] = cloneImportsMap(imports);
|
|
if (addon) this._addons.push(key);
|
|
if (asset) this._assets.push(key);
|
|
return this;
|
|
}
|
|
mount(root, opts = {}) {
|
|
const bundle = new Bundle2();
|
|
bundle._File = this._File;
|
|
bundle._id = this._id;
|
|
if (this._main) bundle._main = mountSpecifier(this._main, root);
|
|
bundle._imports = transformImportsMap(this._imports, root, null, opts, mountSpecifier);
|
|
bundle._resolutions = transformResolutionsMap(this._resolutions, root, opts, mountSpecifier);
|
|
for (const [key, file] of this._files) {
|
|
bundle._files.set(mountSpecifier(key, root), file);
|
|
}
|
|
bundle._addons = transformFilesList(this._addons, root, mountSpecifier);
|
|
bundle._assets = transformFilesList(this._assets, root, mountSpecifier);
|
|
return bundle;
|
|
}
|
|
unmount(root, opts = {}) {
|
|
const bundle = new Bundle2();
|
|
bundle._File = this._File;
|
|
bundle._id = this._id;
|
|
if (this._main) bundle._main = unmountSpecifier(this._main, root);
|
|
bundle._imports = transformImportsMap(this._imports, root, null, opts, unmountSpecifier);
|
|
bundle._resolutions = transformResolutionsMap(this._resolutions, root, opts, unmountSpecifier);
|
|
for (const [key, file] of this._files) {
|
|
bundle._files.set(unmountSpecifier(key, root), file);
|
|
}
|
|
bundle._addons = transformFilesList(this._addons, root, unmountSpecifier);
|
|
bundle._assets = transformFilesList(this._assets, root, unmountSpecifier);
|
|
return bundle;
|
|
}
|
|
toBuffer(opts = {}) {
|
|
const { indent = 0, shared = false } = opts;
|
|
const header = {
|
|
version: Bundle2.version,
|
|
id: this._id,
|
|
main: this._main,
|
|
imports: cloneImportsMap(this._imports),
|
|
resolutions: cloneResolutionsMap(this._resolutions),
|
|
addons: cloneFilesList(this._addons, "Addons"),
|
|
assets: cloneFilesList(this._assets, "Assets"),
|
|
files: {}
|
|
};
|
|
const keys = [...this._files.keys()].sort();
|
|
let offset = 0;
|
|
for (const key of keys) {
|
|
const length2 = this.size(key);
|
|
header.files[key] = { offset, length: length2, mode: this.mode(key) };
|
|
offset += length2;
|
|
}
|
|
const json = Buffer.from(`
|
|
${JSON.stringify(header, null, indent)}
|
|
`);
|
|
const length = Buffer.from(json.byteLength.toString(10));
|
|
const total = length.byteLength + json.byteLength + offset;
|
|
const storage = shared ? new SharedArrayBuffer(total) : new ArrayBuffer(total);
|
|
const buffer = Buffer.from(storage);
|
|
offset = 0;
|
|
buffer.set(length, offset);
|
|
offset += length.byteLength;
|
|
buffer.set(json, offset);
|
|
offset += json.byteLength;
|
|
for (const key of keys) {
|
|
buffer.set(this.read(key), offset);
|
|
offset += this.size(key);
|
|
}
|
|
return buffer;
|
|
}
|
|
inspect() {
|
|
return {
|
|
__proto__: { constructor: Bundle2 },
|
|
version: this.version,
|
|
id: this.id,
|
|
main: this.main,
|
|
imports: this.imports,
|
|
resolutions: this.resolutions,
|
|
addons: this.addons,
|
|
assets: this.assets,
|
|
files: this.files
|
|
};
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return this.inspect();
|
|
}
|
|
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
return this.inspect();
|
|
}
|
|
};
|
|
var Bundle = exports;
|
|
exports.errors = errors;
|
|
exports.isBundle = function isBundle(value) {
|
|
if (value instanceof Bundle) return true;
|
|
return typeof value === "object" && value !== null && value[kind] === Bundle[kind];
|
|
};
|
|
exports.from = function from(value) {
|
|
if (typeof value === "string") return fromString(value);
|
|
if (Buffer.isBuffer(value)) return fromBuffer(value);
|
|
return value;
|
|
};
|
|
function fromString(string) {
|
|
return fromBuffer(Buffer.from(string));
|
|
}
|
|
function fromBuffer(buffer) {
|
|
if (buffer[0] === 35 && buffer[1] === 33) {
|
|
let end2 = 2;
|
|
while (buffer[end2] !== 10) end2++;
|
|
buffer = buffer.subarray(end2 + 1);
|
|
}
|
|
let end = 0;
|
|
while (isDecimal(buffer[end])) end++;
|
|
const len = parseInt(buffer.toString("utf8", 0, end), 10);
|
|
let header;
|
|
try {
|
|
header = JSON.parse(buffer.toString("utf8", end, end + len));
|
|
} catch (err) {
|
|
throw errors.INVALID_BUNDLE_HEADER("Invalid bundle header", err);
|
|
}
|
|
const bundle = new Bundle();
|
|
if (header.id) bundle.id = header.id;
|
|
if (header.main) bundle.main = header.main;
|
|
if (header.imports) bundle.imports = header.imports;
|
|
if (header.resolutions) bundle.resolutions = header.resolutions;
|
|
if (header.addons) bundle.addons = header.addons;
|
|
if (header.assets) bundle.assets = header.assets;
|
|
let offset = end + len;
|
|
for (const [file, info] of Object.entries(header.files)) {
|
|
bundle.write(file, buffer.subarray(offset, offset + info.length), {
|
|
mode: info.mode || 420
|
|
});
|
|
offset += info.length;
|
|
}
|
|
return bundle;
|
|
}
|
|
function isDecimal(c) {
|
|
return c >= 48 && c <= 57;
|
|
}
|
|
function compareKeys([a], [b]) {
|
|
return a > b ? 1 : a < b ? -1 : 0;
|
|
}
|
|
function cloneImportsMap(value) {
|
|
if (typeof value === "object" && value !== null) {
|
|
const imports = {};
|
|
for (const entry of Object.entries(value).sort(compareKeys)) {
|
|
imports[entry[0]] = cloneImportsMapEntry(entry[1]);
|
|
}
|
|
return imports;
|
|
}
|
|
throw new TypeError(`Imports map must be an object. Received type ${typeof value} (${value})`);
|
|
}
|
|
function cloneImportsMapEntry(value) {
|
|
if (typeof value === "string") return value;
|
|
if (typeof value === "object" && value !== null) {
|
|
const imports = {};
|
|
for (const entry of Object.entries(value)) {
|
|
imports[entry[0]] = cloneImportsMapEntry(entry[1]);
|
|
}
|
|
return imports;
|
|
}
|
|
throw new TypeError(
|
|
`Imports map entry must be a string or object. Received type ${typeof value} (${value})`
|
|
);
|
|
}
|
|
function cloneResolutionsMap(value) {
|
|
if (typeof value === "object" && value !== null) {
|
|
const resolutions = {};
|
|
for (const entry of Object.entries(value).sort(compareKeys)) {
|
|
resolutions[entry[0]] = cloneImportsMap(entry[1]);
|
|
}
|
|
return resolutions;
|
|
}
|
|
throw new TypeError(`Resolutions map must be an object. Received type ${typeof value} (${value})`);
|
|
}
|
|
function cloneFilesList(value, name) {
|
|
if (Array.isArray(value)) {
|
|
const files = [];
|
|
for (const entry of value) {
|
|
if (typeof entry !== "string") {
|
|
throw new TypeError(
|
|
`${name} entry must be a string. Received type ${typeof entry} (${entry})`
|
|
);
|
|
}
|
|
files.push(entry);
|
|
}
|
|
return files.sort();
|
|
}
|
|
throw new TypeError(`${name} list must be an array. Received type ${typeof value} (${value})`);
|
|
}
|
|
function transformImportsMap(value, root, conditionalRoot, opts, fn) {
|
|
const { conditions = {} } = opts;
|
|
const imports = {};
|
|
for (const entry of Object.entries(value)) {
|
|
const condition = entry[0];
|
|
imports[condition] = transformImportsMapEntry(
|
|
entry[1],
|
|
root,
|
|
conditionalRoot || conditions[condition],
|
|
opts,
|
|
fn
|
|
);
|
|
}
|
|
return imports;
|
|
}
|
|
function transformImportsMapEntry(value, root, conditionalRoot, opts, fn) {
|
|
const { conditions = {} } = opts;
|
|
if (typeof value === "string") {
|
|
return fn(value, conditionalRoot || conditions.default || root);
|
|
}
|
|
return transformImportsMap(value, root, conditionalRoot, opts, fn);
|
|
}
|
|
function transformResolutionsMap(value, root, opts, fn) {
|
|
const resolutions = {};
|
|
for (const entry of Object.entries(value)) {
|
|
resolutions[fn(entry[0], root)] = transformImportsMap(entry[1], root, null, opts, fn);
|
|
}
|
|
return resolutions;
|
|
}
|
|
function transformFilesList(value, root, fn) {
|
|
const files = [];
|
|
for (const entry of value) {
|
|
files.push(fn(entry, root));
|
|
}
|
|
return files;
|
|
}
|
|
function mountSpecifier(specifier, root) {
|
|
if (startsWithWindowsDriveLetter(specifier)) {
|
|
specifier = "/" + specifier;
|
|
}
|
|
if (specifier[0] === "/" || specifier[0] === "\\") {
|
|
specifier = "." + specifier;
|
|
}
|
|
if (specifier.startsWith("./") || specifier.startsWith(".\\")) {
|
|
return new URL(specifier, root).href;
|
|
}
|
|
return specifier;
|
|
}
|
|
function unmountSpecifier(specifier, root) {
|
|
specifier = new URL(specifier);
|
|
if (typeof root === "string") root = new URL(root);
|
|
if (specifier.protocol !== root.protocol || specifier.host !== root.host || specifier.port !== root.port) {
|
|
return specifier.href;
|
|
}
|
|
const specifierPath = splitPath(specifier.pathname);
|
|
const rootPath = splitPath(root.pathname);
|
|
while (specifierPath.length > 0 && rootPath[0] === specifierPath[0]) {
|
|
specifierPath.shift();
|
|
rootPath.shift();
|
|
}
|
|
rootPath.fill("..");
|
|
return "/" + rootPath.concat(specifierPath).join("/");
|
|
}
|
|
function splitPath(path) {
|
|
const parts = path.split("/");
|
|
if (!parts[0]) parts.shift();
|
|
if (!parts[parts.length - 1]) parts.pop();
|
|
return parts;
|
|
}
|
|
function isASCIIUpperAlpha(c) {
|
|
return c >= 65 && c <= 90;
|
|
}
|
|
function isASCIILowerAlpha(c) {
|
|
return c >= 97 && c <= 122;
|
|
}
|
|
function isASCIIAlpha(c) {
|
|
return isASCIIUpperAlpha(c) || isASCIILowerAlpha(c);
|
|
}
|
|
function isWindowsDriveLetter(input) {
|
|
return input.length >= 2 && isASCIIAlpha(input.charCodeAt(0)) && (input.charCodeAt(1) === 58 || input.charCodeAt(1) === 124);
|
|
}
|
|
function startsWithWindowsDriveLetter(input) {
|
|
return input.length >= 2 && isWindowsDriveLetter(input) && (input.length === 2 || input.charCodeAt(2) === 47 || input.charCodeAt(2) === 92 || input.charCodeAt(2) === 63 || input.charCodeAt(2) === 35);
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-semver/lib/constants.js
|
|
var require_constants3 = __commonJS({
|
|
"../../node_modules/bare-semver/lib/constants.js"(exports, module) {
|
|
module.exports = {
|
|
EQ: 1,
|
|
LT: 2,
|
|
LTE: 3,
|
|
GT: 4,
|
|
GTE: 5
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-semver/lib/errors.js
|
|
var require_errors6 = __commonJS({
|
|
"../../node_modules/bare-semver/lib/errors.js"(exports, module) {
|
|
module.exports = class SemVerError extends Error {
|
|
constructor(msg, code, fn = SemVerError) {
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "SemVerError";
|
|
}
|
|
static INVALID_VERSION(msg, fn = SemVerError.INVALID_VERSION) {
|
|
return new SemVerError(msg, "INVALID_VERSION", fn);
|
|
}
|
|
static INVALID_RANGE(msg, fn = SemVerError.INVALID_RANGE) {
|
|
return new SemVerError(msg, "INVALID_RANGE", fn);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-semver/lib/version.js
|
|
var require_version = __commonJS({
|
|
"../../node_modules/bare-semver/lib/version.js"(exports, module) {
|
|
var errors = require_errors6();
|
|
var Version = class {
|
|
constructor(major, minor, patch, opts = {}) {
|
|
const { prerelease = [], build = [] } = opts;
|
|
this.major = major;
|
|
this.minor = minor;
|
|
this.patch = patch;
|
|
this.prerelease = prerelease;
|
|
this.build = build;
|
|
}
|
|
compare(version) {
|
|
return exports.compare(this, version);
|
|
}
|
|
toString() {
|
|
let result = `${this.major}.${this.minor}.${this.patch}`;
|
|
if (this.prerelease.length) {
|
|
result += "-" + this.prerelease.join(".");
|
|
}
|
|
if (this.build.length) {
|
|
result += "+" + this.build.join(".");
|
|
}
|
|
return result;
|
|
}
|
|
};
|
|
module.exports = exports = Version;
|
|
exports.parse = function parse(input, state = { position: 0, partial: false, range: false, precision: 0 }) {
|
|
let i = state.position;
|
|
let c;
|
|
const unexpected = (expected) => {
|
|
let msg;
|
|
if (i >= input.length) {
|
|
msg = `Unexpected end of input in '${input}'`;
|
|
} else {
|
|
msg = `Unexpected token '${input[i]}' in '${input}' at position ${i}`;
|
|
}
|
|
if (expected) msg += `, ${expected}`;
|
|
throw errors.INVALID_VERSION(msg, unexpected);
|
|
};
|
|
const components = [0, 0, 0];
|
|
let k = 0;
|
|
while (k < 3) {
|
|
c = input[i];
|
|
if (k > 0) {
|
|
if (c === ".") c = input[++i];
|
|
else if (state.range) break;
|
|
else unexpected("expected '.'");
|
|
}
|
|
if (state.range && (c === "x" || c === "X" || c === "*")) {
|
|
i++;
|
|
while (input[i] === ".") {
|
|
let j = i + 1;
|
|
while (input[j] >= "0" && input[j] <= "9" || input[j] === "x" || input[j] === "X" || input[j] === "*") {
|
|
j++;
|
|
}
|
|
if (j === i + 1) break;
|
|
i = j;
|
|
}
|
|
break;
|
|
}
|
|
if (c === "0") {
|
|
i++;
|
|
k++;
|
|
} else if (c >= "1" && c <= "9") {
|
|
let j = 0;
|
|
do
|
|
c = input[i + ++j];
|
|
while (c >= "0" && c <= "9");
|
|
components[k++] = parseInt(input.substring(i, i + j));
|
|
i += j;
|
|
} else unexpected("expected /[0-9]/");
|
|
}
|
|
state.precision = k;
|
|
const prerelease = [];
|
|
if (k === 3 && input[i] === "-") {
|
|
i++;
|
|
while (true) {
|
|
c = input[i];
|
|
let tag = "";
|
|
let j = 0;
|
|
while (c >= "0" && c <= "9") c = input[i + ++j];
|
|
let isNumeric = false;
|
|
if (j) {
|
|
tag += input.substring(i, i + j);
|
|
c = input[i += j];
|
|
isNumeric = tag[0] !== "0" || tag.length === 1;
|
|
}
|
|
j = 0;
|
|
while (c >= "0" && c <= "9" || c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c === "-") {
|
|
c = input[i + ++j];
|
|
}
|
|
if (j) {
|
|
tag += input.substring(i, i + j);
|
|
c = input[i += j];
|
|
} else if (!isNumeric) unexpected("expected /[a-zA-Z-]/");
|
|
prerelease.push(tag);
|
|
if (c === ".") c = input[++i];
|
|
else break;
|
|
}
|
|
}
|
|
const build = [];
|
|
if (k === 3 && input[i] === "+") {
|
|
i++;
|
|
while (true) {
|
|
c = input[i];
|
|
let tag = "";
|
|
let j = 0;
|
|
while (c >= "0" && c <= "9" || c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c === "-") {
|
|
c = input[i + ++j];
|
|
}
|
|
if (j) {
|
|
tag += input.substring(i, i + j);
|
|
c = input[i += j];
|
|
} else unexpected("expected /[0-9a-zA-Z-]/");
|
|
build.push(tag);
|
|
if (c === ".") c = input[++i];
|
|
else break;
|
|
}
|
|
}
|
|
if (i < input.length && state.partial === false) {
|
|
unexpected("expected end of input");
|
|
}
|
|
state.position = i;
|
|
return new Version(...components, { prerelease, build });
|
|
};
|
|
var integer = /^[0-9]+$/;
|
|
exports.compare = function compare(a, b) {
|
|
if (a.major > b.major) return 1;
|
|
if (a.major < b.major) return -1;
|
|
if (a.minor > b.minor) return 1;
|
|
if (a.minor < b.minor) return -1;
|
|
if (a.patch > b.patch) return 1;
|
|
if (a.patch < b.patch) return -1;
|
|
if (a.prerelease.length === 0) return b.prerelease.length === 0 ? 0 : 1;
|
|
if (b.prerelease.length === 0) return -1;
|
|
let i = 0;
|
|
do {
|
|
let x = a.prerelease[i];
|
|
let y = b.prerelease[i];
|
|
if (x === void 0) return y === void 0 ? 0 : -1;
|
|
if (y === void 0) return 1;
|
|
if (x === y) continue;
|
|
const xInt = integer.test(x);
|
|
const yInt = integer.test(y);
|
|
if (xInt && yInt) {
|
|
x = +x;
|
|
y = +y;
|
|
} else {
|
|
if (xInt) return -1;
|
|
if (yInt) return 1;
|
|
}
|
|
return x > y ? 1 : -1;
|
|
} while (++i);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-semver/lib/comparator.js
|
|
var require_comparator = __commonJS({
|
|
"../../node_modules/bare-semver/lib/comparator.js"(exports, module) {
|
|
var constants = require_constants3();
|
|
var symbols = {
|
|
[constants.EQ]: "=",
|
|
[constants.LT]: "<",
|
|
[constants.LTE]: "<=",
|
|
[constants.GT]: ">",
|
|
[constants.GTE]: ">="
|
|
};
|
|
module.exports = class Comparator {
|
|
constructor(operator, version) {
|
|
this.operator = operator;
|
|
this.version = version;
|
|
}
|
|
test(version) {
|
|
const result = version.compare(this.version);
|
|
switch (this.operator) {
|
|
case constants.LT:
|
|
return result < 0;
|
|
case constants.LTE:
|
|
return result <= 0;
|
|
case constants.GT:
|
|
return result > 0;
|
|
case constants.GTE:
|
|
return result >= 0;
|
|
default:
|
|
return result === 0;
|
|
}
|
|
}
|
|
toString() {
|
|
return symbols[this.operator] + this.version;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-semver/lib/range.js
|
|
var require_range = __commonJS({
|
|
"../../node_modules/bare-semver/lib/range.js"(exports, module) {
|
|
var constants = require_constants3();
|
|
var errors = require_errors6();
|
|
var Version = require_version();
|
|
var Comparator = require_comparator();
|
|
var Range = class {
|
|
constructor(comparators = []) {
|
|
this.comparators = comparators;
|
|
}
|
|
test(version) {
|
|
for (const set of this.comparators) {
|
|
let matches = true;
|
|
for (const comparator of set) {
|
|
if (comparator.test(version)) continue;
|
|
matches = false;
|
|
break;
|
|
}
|
|
if (!matches) continue;
|
|
if (version.prerelease.length && !allows(set, version)) continue;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
toString() {
|
|
let result = "";
|
|
let first = true;
|
|
for (const set of this.comparators) {
|
|
if (first) first = false;
|
|
else result += " || ";
|
|
result += set.join(" ");
|
|
}
|
|
return result;
|
|
}
|
|
};
|
|
module.exports = exports = Range;
|
|
exports.parse = function parse(input, state = { position: 0, partial: false }) {
|
|
let i = state.position;
|
|
let c;
|
|
const unexpected = (expected) => {
|
|
let msg;
|
|
if (i >= input.length) {
|
|
msg = `Unexpected end of input in '${input}'`;
|
|
} else {
|
|
msg = `Unexpected token '${input[i]}' in '${input}' at position ${i}`;
|
|
}
|
|
if (expected) msg += `, ${expected}`;
|
|
throw errors.INVALID_VERSION(msg, unexpected);
|
|
};
|
|
const comparators = [];
|
|
while (i < input.length) {
|
|
const set = [];
|
|
while (i < input.length) {
|
|
c = input[i];
|
|
let operator = constants.EQ;
|
|
let caret = false;
|
|
let tilde = false;
|
|
if (c === "<") {
|
|
operator = constants.LT;
|
|
c = input[++i];
|
|
if (c === "=") {
|
|
operator = constants.LTE;
|
|
c = input[++i];
|
|
}
|
|
} else if (c === ">") {
|
|
operator = constants.GT;
|
|
c = input[++i];
|
|
if (c === "=") {
|
|
operator = constants.GTE;
|
|
c = input[++i];
|
|
}
|
|
} else if (c === "=") {
|
|
c = input[++i];
|
|
} else if (c === "^") {
|
|
caret = true;
|
|
c = input[++i];
|
|
} else if (c === "~") {
|
|
tilde = true;
|
|
c = input[++i];
|
|
if (c === ">") c = input[++i];
|
|
}
|
|
while (c === " ") c = input[++i];
|
|
const state2 = { position: i, partial: true, range: true };
|
|
const lower = Version.parse(input, state2);
|
|
const precision = state2.precision;
|
|
c = input[i = state2.position];
|
|
while (c === " ") c = input[++i];
|
|
if (c === "-" && input[i + 1] === " " && operator === constants.EQ && !caret && !tilde) {
|
|
c = input[++i];
|
|
while (c === " ") c = input[++i];
|
|
state2.position = i;
|
|
const high = Version.parse(input, state2);
|
|
c = input[i = state2.position];
|
|
set.push(new Comparator(constants.GTE, lower));
|
|
if (state2.precision === 3) {
|
|
set.push(new Comparator(constants.LTE, high));
|
|
} else if (state2.precision === 2) {
|
|
set.push(upper(high.major, high.minor + 1, 0));
|
|
} else if (state2.precision === 1) {
|
|
set.push(upper(high.major + 1, 0, 0));
|
|
}
|
|
while (c === " ") c = input[++i];
|
|
} else {
|
|
if (caret) {
|
|
for (const comparator of expandCaret(lower, precision)) set.push(comparator);
|
|
} else if (tilde) {
|
|
for (const comparator of expandTilde(lower, precision)) set.push(comparator);
|
|
} else if (operator === constants.EQ) {
|
|
for (const comparator of expandPartial(lower, precision)) set.push(comparator);
|
|
} else {
|
|
set.push(new Comparator(operator, lower));
|
|
}
|
|
}
|
|
if (c === "|" && input[i + 1] === "|") {
|
|
c = input[i += 2];
|
|
while (c === " ") c = input[++i];
|
|
break;
|
|
}
|
|
if (c && c !== "<" && c !== ">" && c !== "^" && c !== "~" && c !== "=") {
|
|
unexpected("expected '||', '<', '>', '^', '~', or '='");
|
|
}
|
|
}
|
|
if (set.length) comparators.push(set);
|
|
}
|
|
if (i < input.length && state.partial === false) {
|
|
unexpected("expected end of input");
|
|
}
|
|
state.position = i;
|
|
return new Range(comparators);
|
|
};
|
|
function allows(set, version) {
|
|
for (const comparator of set) {
|
|
const target = comparator.version;
|
|
if (target.prerelease.length && target.major === version.major && target.minor === version.minor && target.patch === version.patch) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
function upper(major, minor, patch) {
|
|
return new Comparator(constants.LT, new Version(major, minor, patch, { prerelease: ["0"] }));
|
|
}
|
|
function expandPartial(version, precision) {
|
|
if (precision === 0) return [new Comparator(constants.GTE, new Version(0, 0, 0))];
|
|
if (precision === 3) return [new Comparator(constants.EQ, version)];
|
|
const set = [new Comparator(constants.GTE, version)];
|
|
if (precision === 1) set.push(upper(version.major + 1, 0, 0));
|
|
else set.push(upper(version.major, version.minor + 1, 0));
|
|
return set;
|
|
}
|
|
function expandCaret(version, precision) {
|
|
if (precision === 0) return [new Comparator(constants.GTE, new Version(0, 0, 0))];
|
|
const { major, minor, patch } = version;
|
|
const set = [new Comparator(constants.GTE, version)];
|
|
if (major !== 0) set.push(upper(major + 1, 0, 0));
|
|
else if (precision === 1) set.push(upper(1, 0, 0));
|
|
else if (minor !== 0) set.push(upper(0, minor + 1, 0));
|
|
else if (precision === 2) set.push(upper(0, 1, 0));
|
|
else set.push(upper(0, 0, patch + 1));
|
|
return set;
|
|
}
|
|
function expandTilde(version, precision) {
|
|
if (precision === 0) return [new Comparator(constants.GTE, new Version(0, 0, 0))];
|
|
const { major, minor } = version;
|
|
const set = [new Comparator(constants.GTE, version)];
|
|
if (precision === 1) set.push(upper(major + 1, 0, 0));
|
|
else set.push(upper(major, minor + 1, 0));
|
|
return set;
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-semver/index.js
|
|
var require_bare_semver = __commonJS({
|
|
"../../node_modules/bare-semver/index.js"(exports) {
|
|
exports.constants = require_constants3();
|
|
exports.errors = require_errors6();
|
|
var Version = exports.Version = require_version();
|
|
var Range = exports.Range = require_range();
|
|
exports.Comparator = require_comparator();
|
|
exports.satisfies = function satisfies(version, range) {
|
|
if (typeof version === "string") version = Version.parse(version);
|
|
if (typeof range === "string") range = Range.parse(range);
|
|
return range.test(version);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-resolve/lib/errors.js
|
|
var require_errors7 = __commonJS({
|
|
"../../node_modules/bare-module-resolve/lib/errors.js"(exports, module) {
|
|
module.exports = class ModuleResolveError extends Error {
|
|
constructor(msg, fn = ModuleResolveError, code = fn.name) {
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) Error.captureStackTrace(this, fn);
|
|
}
|
|
get name() {
|
|
return "ModuleResolveError";
|
|
}
|
|
static INVALID_MODULE_SPECIFIER(msg) {
|
|
return new ModuleResolveError(msg, ModuleResolveError.INVALID_MODULE_SPECIFIER);
|
|
}
|
|
static INVALID_PACKAGE_TARGET(msg) {
|
|
return new ModuleResolveError(msg, ModuleResolveError.INVALID_PACKAGE_TARGET);
|
|
}
|
|
static INVALID_PACKAGE_CONFIGURATION(msg) {
|
|
return new ModuleResolveError(msg, ModuleResolveError.INVALID_PACKAGE_CONFIGURATION);
|
|
}
|
|
static PACKAGE_PATH_NOT_EXPORTED(msg) {
|
|
return new ModuleResolveError(msg, ModuleResolveError.PACKAGE_PATH_NOT_EXPORTED);
|
|
}
|
|
static PACKAGE_IMPORT_NOT_DEFINED(msg) {
|
|
return new ModuleResolveError(msg, ModuleResolveError.PACKAGE_IMPORT_NOT_DEFINED);
|
|
}
|
|
static UNSUPPORTED_ENGINE(msg) {
|
|
return new ModuleResolveError(msg, ModuleResolveError.UNSUPPORTED_ENGINE);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-resolve/index.js
|
|
var require_bare_module_resolve = __commonJS({
|
|
"../../node_modules/bare-module-resolve/index.js"(exports, module) {
|
|
var { satisfies } = require_bare_semver();
|
|
var errors = require_errors7();
|
|
module.exports = exports = function resolve(specifier, parentURL, opts, readPackage) {
|
|
if (typeof opts === "function") {
|
|
readPackage = opts;
|
|
opts = {};
|
|
} else if (typeof readPackage !== "function") {
|
|
readPackage = defaultReadPackage;
|
|
}
|
|
return {
|
|
*[Symbol.iterator]() {
|
|
const generator = exports.module(specifier, parentURL, opts);
|
|
let next = generator.next();
|
|
while (next.done !== true) {
|
|
const value = next.value;
|
|
if (value.package) {
|
|
next = generator.next(readPackage(value.package));
|
|
} else {
|
|
next = generator.next(yield value.resolution);
|
|
}
|
|
}
|
|
return next.value;
|
|
},
|
|
async *[Symbol.asyncIterator]() {
|
|
const generator = exports.module(specifier, parentURL, opts);
|
|
let next = generator.next();
|
|
while (next.done !== true) {
|
|
const value = next.value;
|
|
if (value.package) {
|
|
next = generator.next(await readPackage(value.package));
|
|
} else {
|
|
next = generator.next(yield value.resolution);
|
|
}
|
|
}
|
|
return next.value;
|
|
}
|
|
};
|
|
};
|
|
function defaultReadPackage() {
|
|
return null;
|
|
}
|
|
var UNRESOLVED = 0;
|
|
var YIELDED = 1;
|
|
var RESOLVED = YIELDED | 2;
|
|
var CYCLIC = 4;
|
|
exports.constants = {
|
|
UNRESOLVED,
|
|
YIELDED,
|
|
RESOLVED,
|
|
CYCLIC
|
|
};
|
|
exports.module = function* (specifier, parentURL, opts = {}) {
|
|
const { resolutions = null, imports = null } = opts;
|
|
if (exports.startsWithWindowsDriveLetter(specifier)) {
|
|
specifier = "/" + specifier;
|
|
}
|
|
let status;
|
|
if (resolutions) {
|
|
status = yield* exports.preresolved(specifier, resolutions, parentURL, opts);
|
|
if (status) return status;
|
|
}
|
|
status = yield* exports.url(specifier, parentURL, opts);
|
|
if (status) return status;
|
|
status = yield* exports.packageImports(specifier, parentURL, opts);
|
|
if (status) return status;
|
|
if (specifier === "." || specifier === ".." || specifier[0] === "/" || specifier[0] === "\\" || specifier.startsWith("./") || specifier.startsWith(".\\") || specifier.startsWith("../") || specifier.startsWith("..\\")) {
|
|
if (imports) {
|
|
status = yield* exports.packageImportsExports(specifier, imports, parentURL, true, opts);
|
|
if (status) return status;
|
|
}
|
|
status = yield* exports.deferred(specifier, opts);
|
|
if (status) return status;
|
|
status = yield* exports.file(specifier, parentURL, false, opts);
|
|
if (status === RESOLVED) return status;
|
|
const yielded = (status & YIELDED) !== 0;
|
|
status = yield* exports.directory(specifier, parentURL, opts);
|
|
if (yielded) status |= YIELDED;
|
|
return status;
|
|
}
|
|
return yield* exports.package(specifier, parentURL, opts);
|
|
};
|
|
exports.url = function* (url, parentURL, opts = {}) {
|
|
const { imports = null, deferredProtocol = "deferred:", resolutions = null } = opts;
|
|
let resolution;
|
|
try {
|
|
resolution = new URL(url);
|
|
} catch {
|
|
return UNRESOLVED;
|
|
}
|
|
if (imports) {
|
|
const status = yield* exports.packageImportsExports(
|
|
resolution.href,
|
|
imports,
|
|
parentURL,
|
|
true,
|
|
opts
|
|
);
|
|
if (status && (status & CYCLIC) === 0) return status;
|
|
}
|
|
if (resolution.protocol === deferredProtocol) {
|
|
const specifier = resolution.pathname;
|
|
if (resolutions) {
|
|
const imports2 = resolutions[parentURL.href];
|
|
if (typeof imports2 === "object" && imports2 !== null) {
|
|
opts = {
|
|
...opts,
|
|
resolutions: { ...resolutions, [parentURL.href]: { ...imports2, [specifier]: null } }
|
|
};
|
|
}
|
|
}
|
|
return yield* exports.module(specifier, parentURL, opts);
|
|
}
|
|
if (resolution.protocol === "node:") {
|
|
const specifier = resolution.pathname;
|
|
if (specifier === "." || specifier === ".." || specifier[0] === "/" || specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
throw errors.INVALID_MODULE_SPECIFIER(`Module specifier '${url}' is not a valid package name`);
|
|
}
|
|
return yield* exports.package(specifier, parentURL, opts);
|
|
}
|
|
const resolved = yield { resolution };
|
|
return resolved ? RESOLVED : YIELDED;
|
|
};
|
|
exports.preresolved = function* (specifier, resolutions, parentURL, opts = {}) {
|
|
const imports = resolutions[parentURL.href];
|
|
if (typeof imports === "object" && imports !== null) {
|
|
return yield* exports.packageImportsExports(specifier, imports, parentURL, true, opts);
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.deferred = function* (specifier, opts = {}) {
|
|
const { deferredProtocol = "deferred:", defer = [] } = opts;
|
|
if (defer.includes(specifier)) {
|
|
const resolved = yield { resolution: new URL(deferredProtocol + specifier) };
|
|
return resolved ? RESOLVED : YIELDED;
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.package = function* (packageSpecifier, parentURL, opts = {}) {
|
|
const { builtins = [] } = opts;
|
|
if (packageSpecifier === "") {
|
|
throw errors.INVALID_MODULE_SPECIFIER(
|
|
`Module specifier '${packageSpecifier}' is not a valid package name`
|
|
);
|
|
}
|
|
let packageName;
|
|
if (packageSpecifier[0] !== "@") {
|
|
packageName = packageSpecifier.split("/", 1).join();
|
|
} else {
|
|
if (!packageSpecifier.includes("/")) {
|
|
throw errors.INVALID_MODULE_SPECIFIER(
|
|
`Module specifier '${packageSpecifier}' is not a valid package name`
|
|
);
|
|
}
|
|
packageName = packageSpecifier.split("/", 2).join("/");
|
|
}
|
|
if (packageName[0] === "." || packageName.includes("\\") || packageName.includes("%")) {
|
|
throw errors.INVALID_MODULE_SPECIFIER(
|
|
`Module specifier '${packageSpecifier}' is not a valid package name`
|
|
);
|
|
}
|
|
let status;
|
|
status = yield* exports.builtinTarget(packageSpecifier, null, builtins, opts);
|
|
if (status) return status;
|
|
status = yield* exports.deferred(packageSpecifier, opts);
|
|
if (status) return status;
|
|
let packageSubpath = "." + packageSpecifier.substring(packageName.length);
|
|
status = yield* exports.packageSelf(packageName, packageSubpath, parentURL, opts);
|
|
if (status) return status;
|
|
parentURL = new URL(parentURL.href);
|
|
for (const packageURL of exports.lookupPackageRoot(packageName, parentURL)) {
|
|
const info = yield { package: packageURL };
|
|
if (info) {
|
|
if (info.engines) exports.validateEngines(packageURL, info.engines, opts);
|
|
if (info.exports) {
|
|
return yield* exports.packageExports(packageURL, packageSubpath, info.exports, opts);
|
|
}
|
|
if (packageSubpath === ".") {
|
|
if (typeof info.main === "string" && info.main !== "") {
|
|
packageSubpath = info.main;
|
|
} else {
|
|
return yield* exports.file("index", packageURL, true, opts);
|
|
}
|
|
}
|
|
status = yield* exports.file(packageSubpath, packageURL, false, opts);
|
|
if (status === RESOLVED) return status;
|
|
const yielded = (status & YIELDED) !== 0;
|
|
status = yield* exports.directory(packageSubpath, packageURL, opts);
|
|
if (yielded) status |= YIELDED;
|
|
return status;
|
|
}
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.packageSelf = function* (packageName, packageSubpath, parentURL, opts = {}) {
|
|
for (const packageURL of exports.lookupPackageScope(parentURL, opts)) {
|
|
const info = yield { package: packageURL };
|
|
if (info) {
|
|
if (info.name !== packageName) return false;
|
|
if (info.exports) {
|
|
return yield* exports.packageExports(packageURL, packageSubpath, info.exports, opts);
|
|
}
|
|
if (packageSubpath === ".") {
|
|
if (typeof info.main === "string" && info.main !== "") {
|
|
packageSubpath = info.main;
|
|
} else {
|
|
return yield* exports.file("index", packageURL, true, opts);
|
|
}
|
|
}
|
|
let status = yield* exports.file(packageSubpath, packageURL, false, opts);
|
|
if (status === RESOLVED) return status;
|
|
const yielded = (status & YIELDED) !== 0;
|
|
status = yield* exports.directory(packageSubpath, packageURL, opts);
|
|
if (yielded) status |= YIELDED;
|
|
return status;
|
|
}
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.packageExports = function* (packageURL, subpath, packageExports, opts = {}) {
|
|
if (typeof packageExports === "object" && packageExports !== null && !Array.isArray(packageExports)) {
|
|
const keys = Object.keys(packageExports);
|
|
const relative = keys.filter((key) => key.startsWith(".")).length;
|
|
if (relative !== 0 && relative !== keys.length) {
|
|
throw errors.INVALID_PACKAGE_CONFIGURATION(
|
|
`"exports" in '${packageURL}' cannot contain some keys starting with '.' and some not`
|
|
);
|
|
}
|
|
}
|
|
if (subpath === ".") {
|
|
let mainExport;
|
|
if (typeof packageExports === "string" || Array.isArray(packageExports)) {
|
|
mainExport = packageExports;
|
|
} else if (typeof packageExports === "object" && packageExports !== null) {
|
|
const keys = Object.keys(packageExports);
|
|
if (keys.some((key) => key.startsWith("."))) {
|
|
if ("." in packageExports) mainExport = packageExports["."];
|
|
} else {
|
|
mainExport = packageExports;
|
|
}
|
|
}
|
|
if (mainExport) {
|
|
const status = yield* exports.packageTarget(packageURL, mainExport, null, false, opts);
|
|
if (status) return status;
|
|
}
|
|
} else if (typeof packageExports === "object" && packageExports !== null) {
|
|
const keys = Object.keys(packageExports);
|
|
if (keys.every((key) => key.startsWith("."))) {
|
|
const status = yield* exports.packageImportsExports(
|
|
subpath,
|
|
packageExports,
|
|
packageURL,
|
|
false,
|
|
opts
|
|
);
|
|
if (status) return status;
|
|
}
|
|
}
|
|
throw errors.PACKAGE_PATH_NOT_EXPORTED(
|
|
`Package subpath '${subpath}' is not defined by "exports" in '${packageURL}'`
|
|
);
|
|
};
|
|
exports.packageImports = function* (specifier, parentURL, opts = {}) {
|
|
const { imports = null } = opts;
|
|
if (specifier === "#" || specifier.startsWith("#/")) {
|
|
throw errors.INVALID_MODULE_SPECIFIER(
|
|
`Module specifier '${specifier}' is not a valid internal imports specifier`
|
|
);
|
|
}
|
|
for (const packageURL of exports.lookupPackageScope(parentURL, opts)) {
|
|
const info = yield { package: packageURL };
|
|
if (info) {
|
|
if (info.imports) {
|
|
const status = yield* exports.packageImportsExports(
|
|
specifier,
|
|
info.imports,
|
|
packageURL,
|
|
true,
|
|
opts
|
|
);
|
|
if (status) return status;
|
|
}
|
|
if (specifier.startsWith("#")) {
|
|
throw errors.PACKAGE_IMPORT_NOT_DEFINED(
|
|
`Package import specifier '${specifier}' is not defined by "imports" in '${packageURL}'`
|
|
);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (imports) {
|
|
const status = yield* exports.packageImportsExports(specifier, imports, parentURL, true, opts);
|
|
if (status) return status;
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.packageImportsExports = function* (matchKey, matchObject, packageURL, isImports, opts = {}) {
|
|
if (matchKey in matchObject && !matchKey.includes("*")) {
|
|
const target = matchObject[matchKey];
|
|
return yield* exports.packageTarget(packageURL, target, null, isImports, opts);
|
|
}
|
|
const expansionKeys = Object.keys(matchObject).filter((key) => key.includes("*")).sort(exports.patternKeyCompare);
|
|
for (const expansionKey of expansionKeys) {
|
|
const patternIndex = expansionKey.indexOf("*");
|
|
const patternBase = expansionKey.substring(0, patternIndex);
|
|
if (matchKey.startsWith(patternBase) && matchKey !== patternBase) {
|
|
const patternTrailer = expansionKey.substring(patternIndex + 1);
|
|
if (patternTrailer === "" || matchKey.endsWith(patternTrailer) && matchKey.length >= expansionKey.length) {
|
|
const target = matchObject[expansionKey];
|
|
const patternMatch = matchKey.substring(
|
|
patternBase.length,
|
|
matchKey.length - patternTrailer.length
|
|
);
|
|
return yield* exports.packageTarget(packageURL, target, patternMatch, isImports, opts);
|
|
}
|
|
}
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.validateEngines = function validateEngines(packageURL, packageEngines, opts = {}) {
|
|
const { engines = {} } = opts;
|
|
for (const [engine, range] of Object.entries(packageEngines)) {
|
|
if (engine in engines) {
|
|
const version = engines[engine];
|
|
if (!satisfies(version, range)) {
|
|
throw errors.UNSUPPORTED_ENGINE(
|
|
`Package not compatible with engine '${engine}' ${version}, requires range '${range}' defined by "engines" in '${packageURL}'`
|
|
);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
exports.patternKeyCompare = function patternKeyCompare(keyA, keyB) {
|
|
const patternIndexA = keyA.indexOf("*");
|
|
const patternIndexB = keyB.indexOf("*");
|
|
const baseLengthA = patternIndexA === -1 ? keyA.length : patternIndexA + 1;
|
|
const baseLengthB = patternIndexB === -1 ? keyB.length : patternIndexB + 1;
|
|
if (baseLengthA > baseLengthB) return -1;
|
|
if (baseLengthB > baseLengthA) return 1;
|
|
if (patternIndexA === -1) return 1;
|
|
if (patternIndexB === -1) return -1;
|
|
if (keyA.length > keyB.length) return -1;
|
|
if (keyB.length > keyA.length) return 1;
|
|
return 0;
|
|
};
|
|
exports.packageTarget = function* (packageURL, target, patternMatch, isImports, opts = {}) {
|
|
const { conditions = [], matchedConditions = [], matchedTargets = [] } = opts;
|
|
opts = { ...opts, matchedConditions, matchedTargets };
|
|
if (typeof target === "string") {
|
|
if (!target.startsWith("./") && !isImports) {
|
|
throw errors.INVALID_PACKAGE_TARGET(
|
|
`Invalid target '${target}' defined by "exports" in '${packageURL}'`
|
|
);
|
|
}
|
|
if (patternMatch !== null) {
|
|
target = target.replaceAll("*", patternMatch);
|
|
}
|
|
if (matchedTargets.includes(target)) return CYCLIC;
|
|
matchedTargets.push(target);
|
|
let status = yield* exports.url(target, packageURL, opts);
|
|
if (status) {
|
|
matchedTargets.pop();
|
|
return status;
|
|
}
|
|
if (target === "." || target === ".." || target[0] === "/" || target.startsWith("./") || target.startsWith("../")) {
|
|
if (hasOpaquePath(packageURL)) {
|
|
matchedTargets.pop();
|
|
return UNRESOLVED;
|
|
}
|
|
const resolved = yield { resolution: new URL(target, packageURL) };
|
|
matchedTargets.pop();
|
|
return resolved ? RESOLVED : YIELDED;
|
|
}
|
|
status = yield* exports.package(target, packageURL, opts);
|
|
matchedTargets.pop();
|
|
return status;
|
|
}
|
|
if (Array.isArray(target)) {
|
|
let status = UNRESOLVED;
|
|
for (const targetValue of target) {
|
|
status |= yield* exports.packageTarget(packageURL, targetValue, patternMatch, isImports, opts);
|
|
if (status === RESOLVED) return status;
|
|
}
|
|
return status;
|
|
}
|
|
if (typeof target === "object" && target !== null) {
|
|
let status = UNRESOLVED;
|
|
for (const [condition, targetValue, subset] of exports.conditionMatches(
|
|
target,
|
|
conditions,
|
|
opts
|
|
)) {
|
|
matchedConditions.push(condition);
|
|
status |= yield* exports.packageTarget(packageURL, targetValue, patternMatch, isImports, {
|
|
...opts,
|
|
conditions: subset
|
|
});
|
|
matchedConditions.pop();
|
|
}
|
|
return status;
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.builtinTarget = function* (packageSpecifier, packageVersion, target, opts = {}) {
|
|
const { builtinProtocol = "builtin:", conditions = [], matchedConditions = [] } = opts;
|
|
opts = { ...opts, matchedConditions };
|
|
if (typeof target === "string") {
|
|
const targetParts = target.split("@");
|
|
let targetName;
|
|
let targetVersion;
|
|
if (target[0] !== "@") {
|
|
targetName = targetParts[0];
|
|
targetVersion = targetParts[1] || null;
|
|
} else {
|
|
targetName = targetParts.slice(0, 2).join("@");
|
|
targetVersion = targetParts[2] || null;
|
|
}
|
|
if (packageSpecifier === targetName) {
|
|
if (packageVersion === null && targetVersion === null) {
|
|
const resolved = yield {
|
|
resolution: new URL(builtinProtocol + packageSpecifier)
|
|
};
|
|
return resolved ? RESOLVED : YIELDED;
|
|
}
|
|
let version = null;
|
|
if (packageVersion === null) {
|
|
version = targetVersion;
|
|
} else if (targetVersion === null || packageVersion === targetVersion) {
|
|
version = packageVersion;
|
|
}
|
|
if (version !== null) {
|
|
const resolved = yield {
|
|
resolution: new URL(builtinProtocol + packageSpecifier + "@" + version)
|
|
};
|
|
return resolved ? RESOLVED : YIELDED;
|
|
}
|
|
}
|
|
return UNRESOLVED;
|
|
}
|
|
if (Array.isArray(target)) {
|
|
let status = UNRESOLVED;
|
|
for (const targetValue of target) {
|
|
status |= yield* exports.builtinTarget(packageSpecifier, packageVersion, targetValue, opts);
|
|
if (status === RESOLVED) return status;
|
|
}
|
|
return status;
|
|
}
|
|
if (typeof target === "object" && target !== null) {
|
|
let status = UNRESOLVED;
|
|
for (const [condition, targetValue, subset] of exports.conditionMatches(
|
|
target,
|
|
conditions,
|
|
opts
|
|
)) {
|
|
matchedConditions.push(condition);
|
|
status |= yield* exports.builtinTarget(packageSpecifier, packageVersion, targetValue, {
|
|
...opts,
|
|
conditions: subset
|
|
});
|
|
matchedConditions.pop();
|
|
}
|
|
return status;
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.conditionMatches = function* conditionMatches(target, conditions, opts = {}) {
|
|
if (conditions.every((condition) => typeof condition === "string")) {
|
|
const keys = Object.keys(target);
|
|
for (const condition of keys) {
|
|
if (condition === "default" || conditions.includes(condition)) {
|
|
yield [condition, target[condition], conditions];
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
let yielded = false;
|
|
for (const subset of conditions) {
|
|
if (yield* conditionMatches(target, subset, opts)) {
|
|
yielded = true;
|
|
}
|
|
}
|
|
return yielded;
|
|
};
|
|
exports.lookupPackageRoot = function* (packageName, parentURL) {
|
|
if (hasOpaquePath(parentURL)) return null;
|
|
parentURL = new URL(parentURL.href);
|
|
do {
|
|
const packageURL = new URL("node_modules/" + packageName + "/", parentURL);
|
|
const info = yield new URL("package.json", packageURL);
|
|
if (info) return info;
|
|
parentURL.pathname = parentURL.pathname.substring(0, parentURL.pathname.lastIndexOf("/"));
|
|
if (parentURL.pathname.length === 3 && exports.isWindowsDriveLetter(parentURL.pathname.substring(1))) {
|
|
break;
|
|
}
|
|
} while (parentURL.pathname !== "" && parentURL.pathname !== "/");
|
|
return null;
|
|
};
|
|
exports.lookupPackageScope = function* lookupPackageScope(scopeURL, opts = {}) {
|
|
const { resolutions = null } = opts;
|
|
if (resolutions) {
|
|
for (const { resolution } of exports.preresolved("#package", resolutions, scopeURL, opts)) {
|
|
if (resolution) return yield resolution;
|
|
}
|
|
}
|
|
if (hasOpaquePath(scopeURL)) return null;
|
|
scopeURL = new URL(scopeURL.href);
|
|
do {
|
|
if (scopeURL.pathname.endsWith("/node_modules")) break;
|
|
const info = yield new URL("package.json", scopeURL);
|
|
if (info) return info;
|
|
scopeURL.pathname = scopeURL.pathname.substring(0, scopeURL.pathname.lastIndexOf("/"));
|
|
if (scopeURL.pathname.length === 3 && exports.isWindowsDriveLetter(scopeURL.pathname.substring(1))) {
|
|
break;
|
|
}
|
|
} while (scopeURL.pathname !== "" && scopeURL.pathname !== "/");
|
|
return null;
|
|
};
|
|
exports.file = function* (filename, parentURL, isIndex, opts = {}) {
|
|
if (filename === "." || filename === ".." || filename[filename.length - 1] === "/" || filename[filename.length - 1] === "\\") {
|
|
return UNRESOLVED;
|
|
}
|
|
if (hasOpaquePath(parentURL)) return UNRESOLVED;
|
|
if (parentURL.protocol === "file:" && /%2f|%5c/i.test(filename)) {
|
|
throw errors.INVALID_MODULE_SPECIFIER(`Module specifier '${filename}' is invalid`);
|
|
}
|
|
const { extensions = [] } = opts;
|
|
let status = UNRESOLVED;
|
|
if (!isIndex) {
|
|
if (yield { resolution: new URL(filename, parentURL) }) {
|
|
return RESOLVED;
|
|
}
|
|
status = YIELDED;
|
|
}
|
|
for (const ext of extensions) {
|
|
if (filename.endsWith(ext)) continue;
|
|
if (yield { resolution: new URL(filename + ext, parentURL) }) {
|
|
return RESOLVED;
|
|
}
|
|
status = YIELDED;
|
|
}
|
|
return status;
|
|
};
|
|
exports.directory = function* (dirname, parentURL, opts = {}) {
|
|
if (hasOpaquePath(parentURL)) return UNRESOLVED;
|
|
let directoryURL;
|
|
if (dirname[dirname.length - 1] === "/" || dirname[dirname.length - 1] === "\\") {
|
|
directoryURL = new URL(dirname, parentURL);
|
|
} else {
|
|
directoryURL = new URL(dirname + "/", parentURL);
|
|
}
|
|
const info = yield { package: new URL("package.json", directoryURL) };
|
|
if (info) {
|
|
if (info.exports) {
|
|
return yield* exports.packageExports(directoryURL, ".", info.exports, opts);
|
|
}
|
|
if (typeof info.main === "string" && info.main !== "") {
|
|
let status = yield* exports.file(info.main, directoryURL, false, opts);
|
|
if (status === RESOLVED) return status;
|
|
const yielded = (status & YIELDED) !== 0;
|
|
status = yield* exports.directory(info.main, directoryURL, opts);
|
|
if (yielded) status |= YIELDED;
|
|
return status;
|
|
}
|
|
}
|
|
return yield* exports.file("index", directoryURL, true, opts);
|
|
};
|
|
function hasOpaquePath(url) {
|
|
return url.pathname[0] !== "/";
|
|
}
|
|
function isASCIIUpperAlpha(c) {
|
|
return c >= 65 && c <= 90;
|
|
}
|
|
function isASCIILowerAlpha(c) {
|
|
return c >= 97 && c <= 122;
|
|
}
|
|
function isASCIIAlpha(c) {
|
|
return isASCIIUpperAlpha(c) || isASCIILowerAlpha(c);
|
|
}
|
|
exports.isWindowsDriveLetter = function isWindowsDriveLetter(input) {
|
|
return input.length >= 2 && isASCIIAlpha(input.charCodeAt(0)) && (input.charCodeAt(1) === 58 || input.charCodeAt(1) === 124);
|
|
};
|
|
exports.startsWithWindowsDriveLetter = function startsWithWindowsDriveLetter(input) {
|
|
return input.length >= 2 && exports.isWindowsDriveLetter(input) && (input.length === 2 || input.charCodeAt(2) === 47 || input.charCodeAt(2) === 92 || input.charCodeAt(2) === 63 || input.charCodeAt(2) === 35);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-lexer/lib/binding/bare.js
|
|
var require_bare = __commonJS({
|
|
"../../node_modules/bare-module-lexer/lib/binding/bare.js"(exports, module) {
|
|
module.exports = __require.addon("../..");
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-lexer/index.js
|
|
var require_bare_module_lexer = __commonJS({
|
|
"../../node_modules/bare-module-lexer/index.js"(exports, module) {
|
|
var binding = require_bare();
|
|
module.exports = exports = function lex(input, encoding, opts = {}) {
|
|
if (typeof encoding === "object" && encoding !== null) {
|
|
opts = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof input !== "string" && !ArrayBuffer.isView(input)) {
|
|
throw new TypeError(`Input must be a string or buffer. Received type ${typeof input}`);
|
|
}
|
|
return binding.lex(typeof input === "string" ? Buffer.from(input, encoding) : input);
|
|
};
|
|
exports.constants = {
|
|
/**
|
|
* CommonJS `require()`.
|
|
*/
|
|
REQUIRE: binding.REQUIRE,
|
|
/**
|
|
* ES module `import`.
|
|
*/
|
|
IMPORT: binding.IMPORT,
|
|
/**
|
|
* ES module `import()` if `IMPORT` is set.
|
|
*/
|
|
DYNAMIC: binding.DYNAMIC,
|
|
/**
|
|
* CommonJS `require.addon()` if `REQUIRE` is set, or ES module `import.meta.addon()` if `IMPORT` is set.
|
|
*/
|
|
ADDON: binding.ADDON,
|
|
/**
|
|
* CommonJS `require.asset()` if `REQUIRE` is set, or ES module `import.meta.asset()` if `IMPORT` is set.
|
|
*/
|
|
ASSET: binding.ASSET,
|
|
/**
|
|
* CommonJS `require.resolve()` or `require.addon.resolve()` if `REQUIRE` and optionally `ADDON` are set, or ES module
|
|
* `import.meta.resolve()` or `import.meta.addon.resolve()` if `IMPORT` and optionally `ADDON` are set.
|
|
*/
|
|
RESOLVE: binding.RESOLVE,
|
|
/**
|
|
* Re-export of a CommonJS `require()` if `REQUIRE` is set.
|
|
*/
|
|
REEXPORT: binding.REEXPORT
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-mime/index.js
|
|
var require_bare_mime = __commonJS({
|
|
"../../node_modules/bare-mime/index.js"(exports, module) {
|
|
var MIME = class {
|
|
constructor(type, subtype, parameters = /* @__PURE__ */ new Map()) {
|
|
this._type = type;
|
|
this._subtype = subtype;
|
|
this._parameters = parameters;
|
|
}
|
|
// https://mimesniff.spec.whatwg.org/#type
|
|
get type() {
|
|
return this._type;
|
|
}
|
|
// https://mimesniff.spec.whatwg.org/#subtype
|
|
get subtype() {
|
|
return this._subtype;
|
|
}
|
|
// https://mimesniff.spec.whatwg.org/#parameters
|
|
get parameters() {
|
|
return this._parameters;
|
|
}
|
|
};
|
|
module.exports = exports = MIME;
|
|
exports.parse = function parse(input) {
|
|
input = input.replace(httpWhitespaceLeadingAndTrailing, "");
|
|
let position = 0;
|
|
let type = "";
|
|
while (position < input.length && input[position] !== "/") {
|
|
type += input[position++];
|
|
}
|
|
if (type === "" || !isHTTPTokenCodePoints(type)) return null;
|
|
if (position >= input.length) return null;
|
|
position++;
|
|
let subtype = "";
|
|
while (position < input.length && input[position] !== ";") {
|
|
subtype += input[position++];
|
|
}
|
|
subtype = subtype.replace(httpWhitespaceTrailing, "");
|
|
if (subtype === "" || !isHTTPTokenCodePoints(subtype)) return null;
|
|
const mimeType = new MIME(type.toLowerCase(), subtype.toLowerCase());
|
|
while (position < input.length) {
|
|
position++;
|
|
while (position < input.length && httpWhitespace.test(input[position])) {
|
|
position++;
|
|
}
|
|
let parameterName = "";
|
|
while (position < input.length && input[position] !== ";" && input[position] !== "=") {
|
|
parameterName += input[position++];
|
|
}
|
|
parameterName = parameterName.toLowerCase();
|
|
if (position < input.length && input[position] === ";") continue;
|
|
if (position >= input.length) break;
|
|
position++;
|
|
let parameterValue;
|
|
if (position < input.length && input[position] === '"') {
|
|
parameterValue = collectHTTPQuotedString(input, position);
|
|
position = parameterValue.position;
|
|
parameterValue = parameterValue.value;
|
|
while (position < input.length && input[position] !== ";") {
|
|
position++;
|
|
}
|
|
} else {
|
|
parameterValue = "";
|
|
while (position < input.length && input[position] !== ";") {
|
|
parameterValue += input[position++];
|
|
}
|
|
parameterValue = parameterValue.replace(httpWhitespaceTrailing, "");
|
|
if (parameterValue === "") continue;
|
|
}
|
|
if (parameterName !== "" && isHTTPTokenCodePoints(parameterName) && isHTTPQuotedStringTokenCodePoints(parameterValue) && !mimeType._parameters.has(parameterName)) {
|
|
mimeType._parameters.set(parameterName, parameterValue);
|
|
}
|
|
}
|
|
return mimeType;
|
|
};
|
|
var httpWhitespace = /[\t\n\r ]/;
|
|
var httpWhitespaceLeadingAndTrailing = /^[\t\n\r ]+|[\t\n\r ]+$/g;
|
|
var httpWhitespaceTrailing = /[\t\n\r ]+$/;
|
|
var httpTokenCodePoints = /^[!#$%&'*+\-.^_`|~A-Za-z0-9]+$/;
|
|
var httpQuotedStringTokenCodePoints = /^[\t\x20-\x7e\x80-\xff]*$/;
|
|
function isHTTPTokenCodePoints(s) {
|
|
return httpTokenCodePoints.test(s);
|
|
}
|
|
function isHTTPQuotedStringTokenCodePoints(s) {
|
|
return httpQuotedStringTokenCodePoints.test(s);
|
|
}
|
|
function collectHTTPQuotedString(input, position) {
|
|
let value = "";
|
|
position++;
|
|
while (true) {
|
|
while (position < input.length && input[position] !== '"' && input[position] !== "\\") {
|
|
value += input[position++];
|
|
}
|
|
if (position >= input.length) break;
|
|
const quoteOrBackslash = input[position++];
|
|
if (quoteOrBackslash === "\\") {
|
|
if (position >= input.length) {
|
|
value += "\\";
|
|
break;
|
|
}
|
|
value += input[position++];
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
return { value, position };
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-addon-resolve/lib/errors.js
|
|
var require_errors8 = __commonJS({
|
|
"../../node_modules/bare-addon-resolve/lib/errors.js"(exports, module) {
|
|
module.exports = class AddonResolveError extends Error {
|
|
constructor(msg, code, fn = AddonResolveError) {
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "AddonResolveError";
|
|
}
|
|
static INVALID_ADDON_SPECIFIER(msg) {
|
|
return new AddonResolveError(
|
|
msg,
|
|
"INVALID_ADDON_SPECIFIER",
|
|
AddonResolveError.INVALID_ADDON_SPECIFIER
|
|
);
|
|
}
|
|
static INVALID_PACKAGE_NAME(msg) {
|
|
return new AddonResolveError(
|
|
msg,
|
|
"INVALID_PACKAGE_NAME",
|
|
AddonResolveError.INVALID_PACKAGE_NAME
|
|
);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-addon-resolve/index.js
|
|
var require_bare_addon_resolve = __commonJS({
|
|
"../../node_modules/bare-addon-resolve/index.js"(exports, module) {
|
|
var resolve = require_bare_module_resolve();
|
|
var { Version } = require_bare_semver();
|
|
var errors = require_errors8();
|
|
module.exports = exports = function resolve2(specifier, parentURL, opts, readPackage) {
|
|
if (typeof opts === "function") {
|
|
readPackage = opts;
|
|
opts = {};
|
|
} else if (typeof readPackage !== "function") {
|
|
readPackage = defaultReadPackage;
|
|
}
|
|
return {
|
|
*[Symbol.iterator]() {
|
|
const generator = exports.addon(specifier, parentURL, opts);
|
|
let next = generator.next();
|
|
while (next.done !== true) {
|
|
const value = next.value;
|
|
if (value.package) {
|
|
next = generator.next(readPackage(value.package));
|
|
} else {
|
|
next = generator.next(yield value.resolution);
|
|
}
|
|
}
|
|
return next.value;
|
|
},
|
|
async *[Symbol.asyncIterator]() {
|
|
const generator = exports.addon(specifier, parentURL, opts);
|
|
let next = generator.next();
|
|
while (next.done !== true) {
|
|
const value = next.value;
|
|
if (value.package) {
|
|
next = generator.next(await readPackage(value.package));
|
|
} else {
|
|
next = generator.next(yield value.resolution);
|
|
}
|
|
}
|
|
return next.value;
|
|
}
|
|
};
|
|
};
|
|
function defaultReadPackage() {
|
|
return null;
|
|
}
|
|
var { UNRESOLVED, YIELDED, RESOLVED } = resolve.constants;
|
|
exports.constants = {
|
|
UNRESOLVED,
|
|
YIELDED,
|
|
RESOLVED
|
|
};
|
|
exports.addon = function* (specifier, parentURL, opts = {}) {
|
|
const { resolutions = null } = opts;
|
|
if (exports.startsWithWindowsDriveLetter(specifier)) {
|
|
specifier = "/" + specifier;
|
|
}
|
|
let status;
|
|
if (resolutions) {
|
|
status = yield* resolve.preresolved(specifier, resolutions, parentURL, opts);
|
|
if (status) return status;
|
|
}
|
|
status = yield* exports.url(specifier, parentURL, opts);
|
|
if (status) return status;
|
|
let version = null;
|
|
const i = specifier.lastIndexOf("@");
|
|
if (i > 0) {
|
|
version = specifier.substring(i + 1);
|
|
try {
|
|
Version.parse(version);
|
|
specifier = specifier.substring(0, i);
|
|
} catch {
|
|
version = null;
|
|
}
|
|
}
|
|
if (specifier === "." || specifier === ".." || specifier[0] === "/" || specifier[0] === "\\" || specifier.startsWith("./") || specifier.startsWith(".\\") || specifier.startsWith("../") || specifier.startsWith("..\\")) {
|
|
status = yield* exports.file(specifier, parentURL, opts);
|
|
if (status === RESOLVED) return status;
|
|
return yield* exports.directory(specifier, version, parentURL, opts);
|
|
}
|
|
return yield* exports.package(specifier, version, parentURL, opts);
|
|
};
|
|
exports.url = function* (url, parentURL, opts = {}) {
|
|
let resolution;
|
|
try {
|
|
resolution = new URL(url);
|
|
} catch {
|
|
return UNRESOLVED;
|
|
}
|
|
const resolved = yield { resolution };
|
|
return resolved ? RESOLVED : YIELDED;
|
|
};
|
|
exports.package = function* (packageSpecifier, packageVersion, parentURL, opts = {}) {
|
|
if (packageSpecifier === "") {
|
|
throw errors.INVALID_ADDON_SPECIFIER(
|
|
`Addon specifier '${packageSpecifier}' is not a valid package name`
|
|
);
|
|
}
|
|
let packageName;
|
|
if (packageSpecifier[0] !== "@") {
|
|
packageName = packageSpecifier.split("/", 1).join();
|
|
} else {
|
|
if (!packageSpecifier.includes("/")) {
|
|
throw errors.INVALID_ADDON_SPECIFIER(
|
|
`Addon specifier '${packageSpecifier}' is not a valid package name`
|
|
);
|
|
}
|
|
packageName = packageSpecifier.split("/", 2).join("/");
|
|
}
|
|
if (packageName[0] === "." || packageName.includes("\\") || packageName.includes("%")) {
|
|
throw errors.INVALID_ADDON_SPECIFIER(
|
|
`Addon specifier '${packageSpecifier}' is not a valid package name`
|
|
);
|
|
}
|
|
const packageSubpath = "." + packageSpecifier.substring(packageName.length);
|
|
if (hasOpaquePath(parentURL)) return UNRESOLVED;
|
|
const status = yield* exports.packageSelf(
|
|
packageName,
|
|
packageSubpath,
|
|
packageVersion,
|
|
parentURL,
|
|
opts
|
|
);
|
|
if (status) return status;
|
|
parentURL = new URL(parentURL.href);
|
|
do {
|
|
const packageURL = new URL("node_modules/" + packageName + "/", parentURL);
|
|
parentURL.pathname = parentURL.pathname.substring(0, parentURL.pathname.lastIndexOf("/"));
|
|
const info = yield { package: new URL("package.json", packageURL) };
|
|
if (info) {
|
|
return yield* exports.directory(packageSubpath, packageVersion, packageURL, opts);
|
|
}
|
|
} while (parentURL.pathname !== "" && parentURL.pathname !== "/");
|
|
return UNRESOLVED;
|
|
};
|
|
exports.packageSelf = function* (packageName, packageSubpath, packageVersion, parentURL, opts = {}) {
|
|
for (const packageURL of resolve.lookupPackageScope(parentURL, opts)) {
|
|
const info = yield { package: packageURL };
|
|
if (info) {
|
|
if (info.name === packageName) {
|
|
return yield* exports.directory(packageSubpath, packageVersion, packageURL, opts);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.lookupPrebuildsScope = function* lookupPrebuildsScope(url, opts = {}) {
|
|
if (hasOpaquePath(url)) return;
|
|
const scopeURL = new URL(url.href);
|
|
do {
|
|
yield new URL("prebuilds/", scopeURL);
|
|
scopeURL.pathname = scopeURL.pathname.substring(0, scopeURL.pathname.lastIndexOf("/"));
|
|
if (scopeURL.pathname.length === 3 && exports.isWindowsDriveLetter(scopeURL.pathname.substring(1))) {
|
|
break;
|
|
}
|
|
} while (scopeURL.pathname !== "" && scopeURL.pathname !== "/");
|
|
};
|
|
exports.file = function* (filename, parentURL, opts = {}) {
|
|
if (filename === "." || filename === ".." || filename[filename.length - 1] === "/" || filename[filename.length - 1] === "\\") {
|
|
return UNRESOLVED;
|
|
}
|
|
if (hasOpaquePath(parentURL)) return UNRESOLVED;
|
|
if (parentURL.protocol === "file:" && /%2f|%5c/i.test(filename)) {
|
|
throw errors.INVALID_ADDON_SPECIFIER(`Addon specifier '${filename}' is invalid`);
|
|
}
|
|
const { extensions = [] } = opts;
|
|
let status = UNRESOLVED;
|
|
for (let ext of extensions) {
|
|
if (filename.endsWith(ext)) ext = "";
|
|
if (yield { resolution: new URL(filename + ext, parentURL) }) {
|
|
return RESOLVED;
|
|
}
|
|
status = YIELDED;
|
|
}
|
|
return status;
|
|
};
|
|
exports.directory = function* (dirname, version, parentURL, opts = {}) {
|
|
const {
|
|
host = null,
|
|
// Shorthand for single host resolution
|
|
hosts = host !== null ? [host] : [],
|
|
builtins = [],
|
|
matchedConditions = []
|
|
} = opts;
|
|
if (hasOpaquePath(parentURL)) return UNRESOLVED;
|
|
let directoryURL;
|
|
if (dirname[dirname.length - 1] === "/" || dirname[dirname.length - 1] === "\\") {
|
|
directoryURL = new URL(dirname, parentURL);
|
|
} else {
|
|
directoryURL = new URL(dirname + "/", parentURL);
|
|
}
|
|
const unversioned = version === null;
|
|
let name = null;
|
|
const info = yield { package: new URL("package.json", directoryURL) };
|
|
if (info) {
|
|
if (typeof info.name === "string" && info.name !== "") {
|
|
if (info.name.includes("__")) {
|
|
throw errors.INVALID_PACKAGE_NAME(`Package name '${info.name}' is invalid`);
|
|
}
|
|
name = info.name.replace(/\//g, "__").replace(/^@/, "");
|
|
} else {
|
|
return UNRESOLVED;
|
|
}
|
|
if (typeof info.version === "string" && info.version !== "") {
|
|
if (version !== null && info.version !== version) return UNRESOLVED;
|
|
version = info.version;
|
|
}
|
|
} else {
|
|
return UNRESOLVED;
|
|
}
|
|
let status;
|
|
status = yield* resolve.builtinTarget(name, version, builtins, opts);
|
|
if (status) return status;
|
|
for (const prebuildsURL of exports.lookupPrebuildsScope(directoryURL, opts)) {
|
|
status = UNRESOLVED;
|
|
for (const host2 of hosts) {
|
|
const conditions = host2.split("-");
|
|
const universal = supportsUniversalPrebuilds(host2) ? conditions.with(1, "universal").join("-") : null;
|
|
matchedConditions.push(...conditions);
|
|
if (version !== null) {
|
|
status |= yield* exports.file(host2 + "/" + name + "@" + version, prebuildsURL, opts);
|
|
if (universal) {
|
|
status |= yield* exports.file(universal + "/" + name + "@" + version, prebuildsURL, opts);
|
|
}
|
|
}
|
|
if (unversioned) {
|
|
status |= yield* exports.file(host2 + "/" + name, prebuildsURL, opts);
|
|
if (universal) {
|
|
status |= yield* exports.file(universal + "/" + name, prebuildsURL, opts);
|
|
}
|
|
}
|
|
for (const _ of conditions) matchedConditions.pop();
|
|
}
|
|
if (status === RESOLVED) return status;
|
|
}
|
|
return yield* exports.linked(name, version, opts);
|
|
};
|
|
exports.linked = function* (name, version = null, opts = {}) {
|
|
const {
|
|
linked = true,
|
|
host = null,
|
|
// Shorthand for single host resolution
|
|
hosts = host !== null ? [host] : [],
|
|
matchedConditions = []
|
|
} = opts;
|
|
if (linked === false || hosts.length === 0) return UNRESOLVED;
|
|
let status = UNRESOLVED;
|
|
for (const host2 of hosts) {
|
|
const [platform = null] = host2.split("-", 1);
|
|
if (platform === null) continue;
|
|
matchedConditions.push(platform);
|
|
status |= yield* platformArtefact(name, version, platform, opts);
|
|
matchedConditions.pop();
|
|
}
|
|
return status;
|
|
};
|
|
function* platformArtefact(name, version = null, platform, opts = {}) {
|
|
const { linkedProtocol = "linked:" } = opts;
|
|
if (platform === "darwin" || platform === "ios") {
|
|
if (version !== null) {
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}${name}.${version}.framework/${name}.${version}`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
if (platform === "darwin") {
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}lib${name}.${version}.dylib`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
}
|
|
}
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}${name}.framework/${name}`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
if (platform === "darwin") {
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}lib${name}.dylib`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
}
|
|
return YIELDED;
|
|
}
|
|
if (platform === "linux" || platform === "android") {
|
|
if (version !== null) {
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}lib${name}.${version}.so`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
}
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}lib${name}.so`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
return YIELDED;
|
|
}
|
|
if (platform === "win32") {
|
|
if (version !== null) {
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}${name}-${version}.dll`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
}
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}${name}.dll`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
}
|
|
return UNRESOLVED;
|
|
}
|
|
exports.isWindowsDriveLetter = resolve.isWindowsDriveLetter;
|
|
exports.startsWithWindowsDriveLetter = resolve.startsWithWindowsDriveLetter;
|
|
function supportsUniversalPrebuilds(host) {
|
|
return host === "darwin-arm64" || host === "darwin-x64" || host === "ios-arm64-simulator" || host === "ios-x64-simulator";
|
|
}
|
|
function hasOpaquePath(url) {
|
|
return url.pathname[0] !== "/";
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-traverse/lib/resolve/default.js
|
|
var require_default2 = __commonJS({
|
|
"../../node_modules/bare-module-traverse/lib/resolve/default.js"(exports, module) {
|
|
var lex = require_bare_module_lexer();
|
|
var resolve = require_resolve();
|
|
module.exports = function(entry, parentURL, opts) {
|
|
if (entry.type & lex.constants.ADDON) {
|
|
return resolve.addon(entry.specifier || ".", parentURL, opts);
|
|
}
|
|
return resolve.module(entry.specifier, parentURL, opts);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-traverse/lib/runtime/bare.js
|
|
var require_bare2 = __commonJS({
|
|
"../../node_modules/bare-module-traverse/lib/runtime/bare.js"(exports) {
|
|
exports.host = Bare.Addon.host;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-traverse/lib/runtime.js
|
|
var require_runtime = __commonJS({
|
|
"../../node_modules/bare-module-traverse/lib/runtime.js"(exports, module) {
|
|
module.exports = require_bare2();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-traverse/lib/resolve/bare.js
|
|
var require_bare3 = __commonJS({
|
|
"../../node_modules/bare-module-traverse/lib/resolve/bare.js"(exports, module) {
|
|
var lex = require_bare_module_lexer();
|
|
var resolve = require_resolve();
|
|
var runtime = require_runtime();
|
|
module.exports = function(entry, parentURL, opts = {}) {
|
|
const { linked = false, host = runtime.host, hosts = [host] } = opts;
|
|
let extensions;
|
|
let conditions = hosts.map((host2) => ["bare", "node", ...host2.split("-")]);
|
|
if (entry.type & lex.constants.ADDON) {
|
|
extensions = linked ? [] : [".bare", ".node"];
|
|
conditions = conditions.map((conditions2) => ["addon", ...conditions2]);
|
|
return resolve.addon(entry.specifier || ".", parentURL, {
|
|
...opts,
|
|
extensions,
|
|
conditions,
|
|
hosts,
|
|
linked
|
|
});
|
|
}
|
|
if (entry.type & lex.constants.ASSET) {
|
|
conditions = conditions.map((conditions2) => ["asset", ...conditions2]);
|
|
} else {
|
|
extensions = [".js", ".cjs", ".mjs", ".ts", ".cts", ".mts", ".json", ".bare", ".node"];
|
|
if (entry.type & lex.constants.REQUIRE) {
|
|
conditions = conditions.map((conditions2) => ["require", ...conditions2]);
|
|
} else if (entry.type & lex.constants.IMPORT) {
|
|
conditions = conditions.map((conditions2) => ["import", ...conditions2]);
|
|
}
|
|
}
|
|
return resolve.module(entry.specifier, parentURL, {
|
|
...opts,
|
|
extensions,
|
|
conditions
|
|
});
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-traverse/lib/resolve/node.js
|
|
var require_node = __commonJS({
|
|
"../../node_modules/bare-module-traverse/lib/resolve/node.js"(exports, module) {
|
|
var lex = require_bare_module_lexer();
|
|
var resolve = require_resolve();
|
|
var runtime = require_runtime();
|
|
module.exports = function(entry, parentURL, opts = {}) {
|
|
const { host = runtime.host, hosts = [host] } = opts;
|
|
let extensions;
|
|
let conditions = hosts.map((host2) => ["node", ...host2.split("-")]);
|
|
if (entry.type & lex.constants.ADDON) {
|
|
extensions = [".node"];
|
|
conditions = conditions.map((conditions2) => ["addon", ...conditions2]);
|
|
return resolve.addon(entry.specifier || ".", parentURL, {
|
|
...opts,
|
|
extensions,
|
|
conditions,
|
|
hosts
|
|
});
|
|
}
|
|
if (entry.type & lex.constants.ASSET) {
|
|
conditions = conditions.map((conditions2) => ["asset", ...conditions2]);
|
|
} else if (entry.type & lex.constants.REQUIRE) {
|
|
extensions = [".js", ".json", ".node"];
|
|
conditions = conditions.map((conditions2) => ["require", ...conditions2]);
|
|
} else if (entry.type & lex.constants.IMPORT) {
|
|
conditions = conditions.map((conditions2) => ["import", ...conditions2]);
|
|
}
|
|
return resolve.module(entry.specifier, parentURL, {
|
|
...opts,
|
|
extensions,
|
|
conditions
|
|
});
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-traverse/lib/resolve.js
|
|
var require_resolve = __commonJS({
|
|
"../../node_modules/bare-module-traverse/lib/resolve.js"(exports) {
|
|
exports.module = require_bare_module_resolve().module;
|
|
exports.addon = require_bare_addon_resolve().addon;
|
|
exports.default = require_default2();
|
|
exports.bare = require_bare3();
|
|
exports.node = require_node();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-traverse/lib/errors.js
|
|
var require_errors9 = __commonJS({
|
|
"../../node_modules/bare-module-traverse/lib/errors.js"(exports, module) {
|
|
module.exports = class ModuleTraverseError extends Error {
|
|
constructor(msg, fn = ModuleTraverseError, code = fn.name) {
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) Error.captureStackTrace(this, fn);
|
|
}
|
|
get name() {
|
|
return "ModuleTraverseError";
|
|
}
|
|
static MODULE_NOT_FOUND(msg, specifier, referrer = null, candidates = []) {
|
|
const err = new ModuleTraverseError(msg, ModuleTraverseError.MODULE_NOT_FOUND);
|
|
err.specifier = specifier;
|
|
err.referrer = referrer;
|
|
err.candidates = candidates;
|
|
return err;
|
|
}
|
|
static ADDON_NOT_FOUND(msg, specifier, referrer = null, candidates = []) {
|
|
const err = new ModuleTraverseError(msg, ModuleTraverseError.ADDON_NOT_FOUND);
|
|
err.specifier = specifier;
|
|
err.referrer = referrer;
|
|
err.candidates = candidates;
|
|
return err;
|
|
}
|
|
static ASSET_NOT_FOUND(msg, specifier, referrer = null, candidates = []) {
|
|
const err = new ModuleTraverseError(msg, ModuleTraverseError.ASSET_NOT_FOUND);
|
|
err.specifier = specifier;
|
|
err.referrer = referrer;
|
|
err.candidates = candidates;
|
|
return err;
|
|
}
|
|
static INVALID_IMPORTS_MAP(msg) {
|
|
return new ModuleTraverseError(msg, ModuleTraverseError.INVALID_IMPORTS_MAP);
|
|
}
|
|
static TYPE_INCOMPATIBLE(msg) {
|
|
return new ModuleTraverseError(msg, ModuleTraverseError.TYPE_INCOMPATIBLE);
|
|
}
|
|
static UNKNOWN_DATA_URL_CHARSET(msg, charset) {
|
|
const err = new ModuleTraverseError(msg, ModuleTraverseError.UNKNOWN_DATA_URL_CHARSET);
|
|
err.charset = charset;
|
|
return err;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-traverse/index.js
|
|
var require_bare_module_traverse = __commonJS({
|
|
"../../node_modules/bare-module-traverse/index.js"(exports, module) {
|
|
var { lookupPackageScope, conditionMatches } = require_bare_module_resolve();
|
|
var lex = require_bare_module_lexer();
|
|
var MIME = require_bare_mime();
|
|
var resolve = require_resolve();
|
|
var errors = require_errors9();
|
|
var constants = {
|
|
SCRIPT: 1,
|
|
MODULE: 2,
|
|
JSON: 3,
|
|
BUNDLE: 4,
|
|
ADDON: 5,
|
|
BINARY: 6,
|
|
TEXT: 7
|
|
};
|
|
function defaultResolveModule(url) {
|
|
return url;
|
|
}
|
|
function defaultProbeModule() {
|
|
return void 0;
|
|
}
|
|
module.exports = exports = function traverse(entry, opts, readModule, listPrefix, probeModule, resolveModule) {
|
|
if (typeof opts === "function") {
|
|
resolveModule = probeModule;
|
|
probeModule = listPrefix;
|
|
listPrefix = readModule;
|
|
readModule = opts;
|
|
opts = {};
|
|
}
|
|
if (typeof resolveModule !== "function") resolveModule = defaultResolveModule;
|
|
if (typeof probeModule !== "function") probeModule = defaultProbeModule;
|
|
return {
|
|
*[Symbol.iterator]() {
|
|
const artifacts = { addons: [], assets: [] };
|
|
const visited = opts.visited || /* @__PURE__ */ new Set();
|
|
const queue = [exports.module(entry, null, {}, artifacts, visited, opts)];
|
|
const deferred = [];
|
|
function* drive(generator) {
|
|
let next = generator.next();
|
|
while (next.done !== true) {
|
|
const value = next.value;
|
|
if (value.module) {
|
|
next = generator.next(readModule(value.module));
|
|
} else if (value.probe) {
|
|
next = generator.next(probeModule(value.probe));
|
|
} else if (value.resolution) {
|
|
next = generator.next(resolveModule(value.resolution));
|
|
} else if (value.prefix) {
|
|
const result = [];
|
|
if (typeof listPrefix === "function") {
|
|
for (const url of listPrefix(value.prefix)) {
|
|
result.push(url);
|
|
}
|
|
} else {
|
|
if (readModule(value.prefix) !== null) {
|
|
result.push(value.prefix);
|
|
}
|
|
}
|
|
next = generator.next(result);
|
|
} else if (value.links) {
|
|
for (const link of value.links) yield* drive(link);
|
|
next = generator.next();
|
|
} else if (value.children) {
|
|
if (value.deferred) deferred.push(value.children);
|
|
else queue.push(value.children);
|
|
next = generator.next();
|
|
} else {
|
|
yield value.dependency;
|
|
next = generator.next();
|
|
}
|
|
}
|
|
}
|
|
while (queue.length > 0 || deferred.length > 0) {
|
|
yield* drive(queue.length > 0 ? queue.pop() : deferred.shift());
|
|
}
|
|
return artifacts;
|
|
},
|
|
async *[Symbol.asyncIterator]() {
|
|
const artifacts = { addons: [], assets: [] };
|
|
const visited = opts.visited || /* @__PURE__ */ new Set();
|
|
const queue = [exports.module(entry, null, {}, artifacts, visited, opts)];
|
|
const deferred = [];
|
|
async function* drive(generator) {
|
|
let next = generator.next();
|
|
while (next.done !== true) {
|
|
const value = next.value;
|
|
if (value.module) {
|
|
next = generator.next(await readModule(value.module));
|
|
} else if (value.probe) {
|
|
next = generator.next(await probeModule(value.probe));
|
|
} else if (value.resolution) {
|
|
next = generator.next(await resolveModule(value.resolution));
|
|
} else if (value.prefix) {
|
|
const result = [];
|
|
if (typeof listPrefix === "function") {
|
|
for await (const url of listPrefix(value.prefix)) {
|
|
result.push(url);
|
|
}
|
|
} else {
|
|
if (await readModule(value.prefix) !== null) {
|
|
result.push(value.prefix);
|
|
}
|
|
}
|
|
next = generator.next(result);
|
|
} else if (value.links) {
|
|
for (const link of value.links) yield* drive(link);
|
|
next = generator.next();
|
|
} else if (value.children) {
|
|
if (value.deferred) deferred.push(value.children);
|
|
else queue.push(value.children);
|
|
next = generator.next();
|
|
} else {
|
|
yield value.dependency;
|
|
next = generator.next();
|
|
}
|
|
}
|
|
}
|
|
while (queue.length > 0 || deferred.length > 0) {
|
|
yield* drive(queue.length > 0 ? queue.pop() : deferred.shift());
|
|
}
|
|
return artifacts;
|
|
}
|
|
};
|
|
};
|
|
exports.constants = constants;
|
|
exports.resolve = resolve;
|
|
exports.alias = function alias(url, opts = {}) {
|
|
const { aliases = null } = opts;
|
|
if (aliases === null) return url;
|
|
const match = url.pathname.match(/\.[a-z]+$/);
|
|
if (match === null) return url;
|
|
const [extension] = match;
|
|
if (extension in aliases === false) return url;
|
|
url = new URL(url);
|
|
url.pathname = url.pathname.slice(0, -extension.length) + aliases[extension];
|
|
return url;
|
|
};
|
|
exports.module = function* (url, source, attributes, artifacts, visited, opts = {}) {
|
|
const { resolutions = null, asset = false, probed } = opts;
|
|
if (visited.has(url.href)) return false;
|
|
visited.add(url.href);
|
|
if (probed !== void 0) opts = { ...opts, probed: void 0 };
|
|
attributes = attributes || {};
|
|
const artifact = asset === true || moduleType(url, attributes, null, opts) === constants.ADDON;
|
|
if (source === null) {
|
|
if (url.protocol === "data:") {
|
|
source = decodeDataURL(url);
|
|
} else {
|
|
const exists = probed !== void 0 ? probed : artifact ? yield { probe: url } : void 0;
|
|
if (exists === false) {
|
|
throw errors.MODULE_NOT_FOUND(`Cannot find module '${url.href}'`, url.href);
|
|
}
|
|
source = yield { module: url, artifact };
|
|
if (exists !== true && source === null) {
|
|
throw errors.MODULE_NOT_FOUND(`Cannot find module '${url.href}'`, url.href);
|
|
}
|
|
}
|
|
}
|
|
if (resolutions) {
|
|
if (yield* exports.preresolved(url, source, resolutions, artifacts, visited, opts)) {
|
|
return true;
|
|
}
|
|
}
|
|
const imports = {};
|
|
let info = null;
|
|
if (url.protocol !== "data:") {
|
|
for (const packageURL of lookupPackageScope(url, opts)) {
|
|
const source2 = yield { module: packageURL, artifact: false };
|
|
if (source2 !== null) {
|
|
info = JSON.parse(source2);
|
|
imports["#package"] = packageURL.href;
|
|
yield {
|
|
children: exports.package(packageURL, source2, artifacts, visited, opts),
|
|
deferred: false
|
|
};
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (typeof attributes.imports === "string") {
|
|
const url2 = new URL(attributes.imports);
|
|
const source2 = yield { module: url2, artifact: false };
|
|
if (source2 !== null) {
|
|
opts = {
|
|
...opts,
|
|
imports: mixinImports(opts.imports, JSON.parse(source2), url2)
|
|
};
|
|
}
|
|
}
|
|
const type = moduleType(url, attributes, info, opts);
|
|
const lexer = { imports: [], exports: [] };
|
|
if (asset === false) {
|
|
if (type === constants.SCRIPT || type === constants.MODULE) {
|
|
yield* exports.imports(url, source, imports, artifacts, lexer, visited, {
|
|
...opts,
|
|
referrerType: type
|
|
});
|
|
} else if (type === constants.ADDON) {
|
|
yield* exports.addons(url, artifacts, visited, opts);
|
|
}
|
|
}
|
|
yield {
|
|
dependency: {
|
|
url: exports.alias(url, opts),
|
|
source,
|
|
type,
|
|
imports: compressImportsMap(imports),
|
|
lexer
|
|
}
|
|
};
|
|
return true;
|
|
};
|
|
exports.package = function* (url, source, artifacts, visited, opts = {}) {
|
|
if (visited.has(url.href)) return false;
|
|
visited.add(url.href);
|
|
if (source === null) {
|
|
source = yield { module: url, artifact: false };
|
|
if (source === null) return false;
|
|
}
|
|
const info = JSON.parse(source);
|
|
if (info) {
|
|
yield {
|
|
dependency: {
|
|
url,
|
|
source,
|
|
type: constants.JSON,
|
|
imports: {},
|
|
lexer: { imports: [], exports: [] }
|
|
}
|
|
};
|
|
if (info.assets) {
|
|
yield {
|
|
children: exports.assets(info.assets, url, artifacts, visited, opts),
|
|
deferred: false
|
|
};
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
exports.preresolved = function* (url, source, resolutions, artifacts, visited, opts = {}) {
|
|
const {
|
|
builtinProtocol = "builtin:",
|
|
linkedProtocol = "linked:",
|
|
deferredProtocol = "deferred:"
|
|
} = opts;
|
|
const imports = resolutions[url.href];
|
|
if (typeof imports !== "object" || imports === null) return false;
|
|
const type = moduleType(url, {}, null, opts);
|
|
for (const [specifier, entry] of Object.entries(imports)) {
|
|
const stack = [{ entry, asset: false }];
|
|
while (stack.length > 0) {
|
|
const { entry: entry2, asset } = stack.pop();
|
|
if (typeof entry2 === "string") {
|
|
const url2 = new URL(entry2);
|
|
if (specifier === "#package") {
|
|
yield {
|
|
children: exports.package(url2, null, artifacts, visited, opts),
|
|
deferred: false
|
|
};
|
|
} else if (asset) {
|
|
addURL(artifacts.assets, url2);
|
|
yield {
|
|
children: exports.module(url2, null, {}, artifacts, visited, {
|
|
...opts,
|
|
asset: true,
|
|
referrerType: type
|
|
}),
|
|
deferred: true
|
|
};
|
|
} else if (url2.protocol !== builtinProtocol && url2.protocol !== linkedProtocol && url2.protocol !== deferredProtocol) {
|
|
yield {
|
|
children: exports.module(url2, null, {}, artifacts, visited, {
|
|
...opts,
|
|
referrerType: type
|
|
}),
|
|
deferred: false
|
|
};
|
|
}
|
|
} else {
|
|
for (const [condition, child] of Object.entries(entry2)) {
|
|
stack.push({ entry: child, asset: asset || condition === "asset" });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const lexer = { imports: [], exports: [] };
|
|
if (type === constants.SCRIPT || type === constants.MODULE) {
|
|
lexer.exports = lex(source).exports;
|
|
}
|
|
yield {
|
|
dependency: {
|
|
url: exports.alias(url, opts),
|
|
source,
|
|
type,
|
|
imports: compressImportsMap(imports),
|
|
lexer
|
|
}
|
|
};
|
|
return true;
|
|
};
|
|
exports.imports = function* (parentURL, source, imports, artifacts, lexer, visited, opts = {}) {
|
|
const lexed = lex(source);
|
|
lexer.exports = lexed.exports;
|
|
const links = [];
|
|
for (const entry of lexed.imports) {
|
|
let specifier = entry.specifier;
|
|
let condition = "default";
|
|
if (entry.type & lex.constants.ADDON) {
|
|
specifier = specifier || ".";
|
|
condition = "addon";
|
|
} else if (entry.type & lex.constants.ASSET) {
|
|
condition = "asset";
|
|
} else if (entry.type & lex.constants.REQUIRE) {
|
|
condition = "require";
|
|
} else if (entry.type & lex.constants.IMPORT) {
|
|
condition = "import";
|
|
}
|
|
lexer.imports.push(entry);
|
|
links.push(
|
|
exports.link(entry, specifier, condition, parentURL, imports, artifacts, visited, opts)
|
|
);
|
|
}
|
|
yield { links };
|
|
};
|
|
exports.link = function* (entry, specifier, condition, parentURL, imports, artifacts, visited, opts = {}) {
|
|
if (entry.attributes.imports) {
|
|
const specifier2 = entry.attributes.imports;
|
|
yield* resolveImport(
|
|
{ type: 0, specifier: specifier2, names: [], attributes: {}, position: [0, 0, 0] },
|
|
specifier2,
|
|
"default",
|
|
parentURL,
|
|
imports,
|
|
artifacts,
|
|
visited,
|
|
opts
|
|
);
|
|
}
|
|
yield* resolveImport(entry, specifier, condition, parentURL, imports, artifacts, visited, opts);
|
|
};
|
|
function* resolveImport(entry, specifier, condition, parentURL, imports, artifacts, visited, opts) {
|
|
const {
|
|
resolve: resolve2 = exports.resolve.default,
|
|
builtinProtocol = "builtin:",
|
|
linkedProtocol = "linked:",
|
|
deferredProtocol = "deferred:"
|
|
} = opts;
|
|
const matchedConditions = [];
|
|
opts = { ...opts, matchedConditions };
|
|
matchedConditions.push(condition);
|
|
const resolver = resolve2(entry, parentURL, opts);
|
|
const candidates = [];
|
|
let next = resolver.next();
|
|
let resolutions = 0;
|
|
while (next.done !== true) {
|
|
const value = next.value;
|
|
if (value.package) {
|
|
next = resolver.next(JSON.parse(yield { module: value.package, artifact: false }));
|
|
} else {
|
|
const url = value.resolution;
|
|
candidates.push(url);
|
|
let resolved = false;
|
|
let resolution = url;
|
|
if (url.protocol === builtinProtocol || url.protocol === linkedProtocol || url.protocol === deferredProtocol) {
|
|
addResolution(imports, specifier, matchedConditions, url);
|
|
resolved = true;
|
|
} else if (condition === "asset") {
|
|
const prefix = url;
|
|
for (const url2 of yield { prefix }) {
|
|
const resolution2 = yield* postresolve(url2);
|
|
yield {
|
|
children: exports.module(resolution2, null, {}, artifacts, visited, {
|
|
...opts,
|
|
asset: true
|
|
}),
|
|
deferred: true
|
|
};
|
|
addURL(artifacts.assets, resolution2);
|
|
resolved = true;
|
|
}
|
|
if (resolved) addResolution(imports, specifier, matchedConditions, url);
|
|
} else if (condition === "addon" || moduleType(url, entry.attributes, null, opts) === constants.ADDON) {
|
|
let exists = yield { probe: url };
|
|
let source = null;
|
|
if (exists === void 0) {
|
|
source = yield { module: url, artifact: false };
|
|
exists = source !== null;
|
|
}
|
|
if (exists) {
|
|
resolution = yield* postresolve(url);
|
|
addResolution(imports, specifier, matchedConditions, exports.alias(resolution, opts));
|
|
yield {
|
|
children: exports.module(resolution, source, {}, artifacts, visited, {
|
|
...opts,
|
|
probed: true
|
|
}),
|
|
deferred: false
|
|
};
|
|
resolved = true;
|
|
}
|
|
} else {
|
|
let source;
|
|
if (url.protocol === "data:") {
|
|
source = decodeDataURL(url);
|
|
} else {
|
|
source = yield { module: url, artifact: false };
|
|
}
|
|
if (source !== null) {
|
|
resolution = yield* postresolve(url);
|
|
addResolution(imports, specifier, matchedConditions, exports.alias(resolution, opts));
|
|
let attributes = entry.attributes;
|
|
if (attributes.imports) {
|
|
attributes = { ...attributes, imports: imports[attributes.imports].default };
|
|
}
|
|
yield {
|
|
children: exports.module(resolution, source, attributes, artifacts, visited, opts),
|
|
deferred: false
|
|
};
|
|
resolved = true;
|
|
}
|
|
}
|
|
if (resolved) {
|
|
if (condition === "addon") addURL(artifacts.addons, resolution);
|
|
resolutions++;
|
|
}
|
|
next = resolver.next(resolved);
|
|
}
|
|
}
|
|
matchedConditions.pop();
|
|
if (resolutions === 0) {
|
|
let message = `Cannot find ${condition === "addon" || condition === "asset" ? condition : "module"} '${specifier}' imported from '${parentURL.href}'`;
|
|
if (candidates.length > 0) {
|
|
message += "\nCandidates:";
|
|
message += "\n" + candidates.map((url) => "- " + url.href).join("\n");
|
|
}
|
|
switch (condition) {
|
|
case "addon":
|
|
throw errors.ADDON_NOT_FOUND(message, specifier, parentURL, candidates);
|
|
case "asset":
|
|
throw errors.ASSET_NOT_FOUND(message, specifier, parentURL, candidates);
|
|
default:
|
|
throw errors.MODULE_NOT_FOUND(message, specifier, parentURL, candidates);
|
|
}
|
|
}
|
|
}
|
|
var ADDON_EXTENSION = /\.(bare|node)$/;
|
|
exports.addons = function* (parentURL, artifacts, visited, opts = {}) {
|
|
let yielded = false;
|
|
if (ADDON_EXTENSION.test(parentURL.pathname)) {
|
|
const prefix = new URL(parentURL);
|
|
prefix.pathname = prefix.pathname.replace(ADDON_EXTENSION, "") + "/";
|
|
for (const url of yield { prefix }) {
|
|
const resolution = yield* postresolve(url);
|
|
yield {
|
|
children: exports.module(resolution, null, {}, artifacts, visited, opts),
|
|
deferred: false
|
|
};
|
|
addURL(artifacts.addons, resolution);
|
|
yielded = true;
|
|
}
|
|
}
|
|
return yielded;
|
|
};
|
|
exports.assets = function* (patterns, parentURL, artifacts, visited, opts = {}) {
|
|
const matches = yield* exports.patternMatches(patterns, parentURL, [], opts);
|
|
let yielded = false;
|
|
for (const url of matches) {
|
|
const resolution = yield* postresolve(url);
|
|
addURL(artifacts.assets, resolution);
|
|
yield {
|
|
children: exports.module(resolution, null, {}, artifacts, visited, {
|
|
...opts,
|
|
asset: true
|
|
}),
|
|
deferred: true
|
|
};
|
|
yielded = true;
|
|
}
|
|
return yielded;
|
|
};
|
|
exports.patternMatches = function* patternMatches(pattern, parentURL, matches, opts = {}) {
|
|
const { conditions = [], matchedConditions = [] } = opts;
|
|
if (typeof pattern === "string") {
|
|
let patternNegate = false;
|
|
let patternBase;
|
|
let patternTrailer;
|
|
if (pattern[0] === "!") {
|
|
pattern = pattern.substring(1);
|
|
patternNegate = true;
|
|
}
|
|
const patternIndex = pattern.indexOf("*");
|
|
if (patternIndex === -1) {
|
|
patternBase = pattern;
|
|
patternTrailer = "";
|
|
} else {
|
|
patternBase = pattern.substring(0, patternIndex);
|
|
patternTrailer = pattern.substring(patternIndex + 1);
|
|
}
|
|
const prefix = new URL(patternBase, parentURL);
|
|
for (const url of yield { prefix }) {
|
|
if (patternIndex === -1) {
|
|
if (patternNegate) removeURL(matches, url);
|
|
else addURL(matches, url);
|
|
} else if (patternTrailer === "" || url.href.endsWith(patternTrailer)) {
|
|
if (patternNegate) removeURL(matches, url);
|
|
else addURL(matches, url);
|
|
}
|
|
}
|
|
} else if (Array.isArray(pattern)) {
|
|
for (const patternValue of pattern) {
|
|
yield* patternMatches(patternValue, parentURL, matches, opts);
|
|
}
|
|
} else if (typeof pattern === "object" && pattern !== null) {
|
|
let yielded = false;
|
|
for (const [condition, patternValue, subset] of conditionMatches(pattern, conditions, opts)) {
|
|
matchedConditions.push(condition);
|
|
if (yield* patternMatches(patternValue, parentURL, matches, {
|
|
...opts,
|
|
conditions: subset
|
|
})) {
|
|
yielded = true;
|
|
}
|
|
matchedConditions.pop();
|
|
}
|
|
if (yielded) return true;
|
|
}
|
|
return matches;
|
|
};
|
|
function* postresolve(url) {
|
|
return (yield { resolution: url }) || url;
|
|
}
|
|
function moduleType(url, attributes, info, opts = {}) {
|
|
const { defaultType = constants.SCRIPT, aliases = null } = opts;
|
|
if (url.protocol === "data:") {
|
|
return dataURLModuleType(url, attributes, opts);
|
|
}
|
|
if (typeof attributes.type === "string") {
|
|
return typeForAttribute(attributes.type);
|
|
}
|
|
const match = url.pathname.match(/\.[a-z]+$/);
|
|
if (match === null) return defaultType;
|
|
let [extension] = match;
|
|
if (aliases !== null && extension in aliases) extension = aliases[extension];
|
|
switch (extension) {
|
|
case ".js":
|
|
case ".ts":
|
|
return defaultType === constants.MODULE || info !== null && info.type === "module" ? constants.MODULE : constants.SCRIPT;
|
|
case ".cjs":
|
|
case ".cts":
|
|
return constants.SCRIPT;
|
|
case ".mjs":
|
|
case ".mts":
|
|
return constants.MODULE;
|
|
case ".json":
|
|
return constants.JSON;
|
|
case ".bundle":
|
|
return constants.BUNDLE;
|
|
case ".bare":
|
|
case ".node":
|
|
return constants.ADDON;
|
|
case ".bin":
|
|
return constants.BINARY;
|
|
case ".txt":
|
|
return constants.TEXT;
|
|
}
|
|
return defaultType;
|
|
}
|
|
function typeForAttribute(type) {
|
|
switch (type) {
|
|
case "script":
|
|
return constants.SCRIPT;
|
|
case "module":
|
|
return constants.MODULE;
|
|
case "json":
|
|
return constants.JSON;
|
|
case "bundle":
|
|
return constants.BUNDLE;
|
|
case "addon":
|
|
return constants.ADDON;
|
|
case "binary":
|
|
return constants.BINARY;
|
|
case "text":
|
|
return constants.TEXT;
|
|
}
|
|
return 0;
|
|
}
|
|
function dataURLModuleType(url, attributes, opts = {}) {
|
|
const { defaultType = constants.SCRIPT, referrerType } = opts;
|
|
const { mime } = parseDataURL(url);
|
|
const asserted = typeof attributes.type === "string" ? typeForAttribute(attributes.type) : null;
|
|
if (mime === null || mime.subtype === "javascript") {
|
|
if (asserted === constants.SCRIPT || asserted === constants.MODULE) return asserted;
|
|
if (asserted !== null) {
|
|
throw errors.TYPE_INCOMPATIBLE(`Module '${url.href}' is not of type '${attributes.type}'`);
|
|
}
|
|
if (referrerType) return referrerType;
|
|
return defaultType === constants.MODULE ? constants.MODULE : constants.SCRIPT;
|
|
}
|
|
let type;
|
|
if (mime.subtype === "json") {
|
|
type = constants.JSON;
|
|
} else if (mime.type === "text") {
|
|
type = constants.TEXT;
|
|
} else if (mime.subtype === "octet-stream") {
|
|
type = constants.BINARY;
|
|
} else {
|
|
throw errors.TYPE_INCOMPATIBLE(
|
|
`Media type '${mime.type}/${mime.subtype}' of '${url.href}' is not supported`
|
|
);
|
|
}
|
|
if (asserted !== null && asserted !== type) {
|
|
throw errors.TYPE_INCOMPATIBLE(`Module '${url.href}' is not of type '${attributes.type}'`);
|
|
}
|
|
return type;
|
|
}
|
|
function parseDataURL(url) {
|
|
const { pathname } = url;
|
|
const comma = pathname.indexOf(",");
|
|
const meta = comma === -1 ? pathname : pathname.slice(0, comma);
|
|
const data = comma === -1 ? "" : pathname.slice(comma + 1);
|
|
const base64 = /;base64$/i.test(meta);
|
|
return { mime: MIME.parse(meta), base64, data };
|
|
}
|
|
function decodeDataURL(url) {
|
|
const { mime, base64, data } = parseDataURL(url);
|
|
const charset = mime === null ? void 0 : mime.parameters.get("charset");
|
|
if (charset !== void 0 && !/^utf-?8$/i.test(charset)) {
|
|
throw errors.UNKNOWN_DATA_URL_CHARSET(
|
|
`Unsupported charset '${charset}' in data URL '${url.href}'`,
|
|
charset
|
|
);
|
|
}
|
|
if (base64) return Buffer.from(data, "base64");
|
|
return decodeURIComponent(data);
|
|
}
|
|
function addURL(collection, url) {
|
|
if (Array.isArray(collection)) {
|
|
let lo = 0;
|
|
let hi = collection.length - 1;
|
|
while (lo <= hi) {
|
|
const mid = lo + (hi - lo >> 1);
|
|
const found = collection[mid];
|
|
if (found.href === url.href) return;
|
|
if (found.href < url.href) {
|
|
lo = mid + 1;
|
|
} else {
|
|
hi = mid - 1;
|
|
}
|
|
}
|
|
collection.splice(lo, 0, url);
|
|
} else {
|
|
collection.add(url.href);
|
|
}
|
|
}
|
|
function removeURL(array, url) {
|
|
let lo = 0;
|
|
let hi = array.length - 1;
|
|
while (lo <= hi) {
|
|
const mid = lo + (hi - lo >> 1);
|
|
const found = array[mid];
|
|
if (found.href === url.href) break;
|
|
if (found.href < url.href) {
|
|
lo = mid + 1;
|
|
} else {
|
|
hi = mid - 1;
|
|
}
|
|
}
|
|
if (array[lo].href === url.href) array.splice(lo, 1);
|
|
}
|
|
function addResolution(imports, specifier, conditions, url) {
|
|
imports[specifier] = imports[specifier] || {};
|
|
let current = imports[specifier];
|
|
for (let i = 0, n = conditions.length - 1; i < n; i++) {
|
|
const key = conditions[i];
|
|
if (key in current === false) {
|
|
current[key] = {};
|
|
} else if (typeof current[key] !== "object") {
|
|
current[key] = { default: current[key] };
|
|
}
|
|
current = current[key];
|
|
}
|
|
const last = conditions[conditions.length - 1];
|
|
current[last] = url.href;
|
|
if ("default" in current) {
|
|
const value = current.default;
|
|
delete current.default;
|
|
current.default = value;
|
|
}
|
|
}
|
|
function compressImportsMap(imports) {
|
|
const entries = [];
|
|
for (const entry of Object.entries(imports)) {
|
|
entry[1] = compressImportsMapEntry(entry[1]);
|
|
entries.push(entry);
|
|
}
|
|
return Object.fromEntries(entries);
|
|
}
|
|
function compressImportsMapEntry(resolved) {
|
|
if (typeof resolved === "string") return resolved;
|
|
let entries = [];
|
|
let primary = null;
|
|
for (const entry of Object.entries(resolved)) {
|
|
entry[1] = compressImportsMapEntry(entry[1]);
|
|
entries.push(entry);
|
|
if (entry[0] === "default") primary = entry[1];
|
|
}
|
|
if (entries.length === 0) return resolved;
|
|
const [, first] = entries[0];
|
|
if (entries.every(([, resolved2]) => resolved2 === first)) return first;
|
|
entries = entries.filter(
|
|
([condition, resolved2]) => condition === "default" || resolved2 !== primary
|
|
);
|
|
if (entries.length === 1) return entries[0][1];
|
|
return Object.fromEntries(entries);
|
|
}
|
|
function mixinImports(target, imports, url) {
|
|
if (typeof imports === "object" && imports !== null && "imports" in imports) {
|
|
imports = imports.imports;
|
|
}
|
|
if (typeof imports !== "object" || imports === null) {
|
|
throw errors.INVALID_IMPORTS_MAP(`Imports map at '${url.href}' is not valid`);
|
|
}
|
|
return { ...target, ...imports };
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-pack/lib/preset/android.js
|
|
var require_android = __commonJS({
|
|
"../../node_modules/bare-pack/lib/preset/android.js"(exports, module) {
|
|
module.exports = {
|
|
linked: true,
|
|
hosts: ["android-arm", "android-arm64", "android-ia32", "android-x64"]
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-pack/lib/preset/darwin.js
|
|
var require_darwin = __commonJS({
|
|
"../../node_modules/bare-pack/lib/preset/darwin.js"(exports, module) {
|
|
module.exports = {
|
|
hosts: ["darwin-arm64", "darwin-x64"]
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-pack/lib/preset/desktop.js
|
|
var require_desktop = __commonJS({
|
|
"../../node_modules/bare-pack/lib/preset/desktop.js"(exports, module) {
|
|
module.exports = {
|
|
hosts: ["darwin-arm64", "darwin-x64", "linux-arm64", "linux-x64", "win32-arm64", "win32-x64"]
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-pack/lib/preset/ios.js
|
|
var require_ios = __commonJS({
|
|
"../../node_modules/bare-pack/lib/preset/ios.js"(exports, module) {
|
|
module.exports = {
|
|
linked: true,
|
|
hosts: ["ios-arm64", "ios-arm64-simulator", "ios-x64-simulator"]
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-pack/lib/preset/linux.js
|
|
var require_linux = __commonJS({
|
|
"../../node_modules/bare-pack/lib/preset/linux.js"(exports, module) {
|
|
module.exports = {
|
|
hosts: ["linux-arm64", "linux-x64"]
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-pack/lib/preset/mobile.js
|
|
var require_mobile = __commonJS({
|
|
"../../node_modules/bare-pack/lib/preset/mobile.js"(exports, module) {
|
|
module.exports = {
|
|
linked: true,
|
|
hosts: [
|
|
"android-arm",
|
|
"android-arm64",
|
|
"android-ia32",
|
|
"android-x64",
|
|
"ios-arm64",
|
|
"ios-arm64-simulator",
|
|
"ios-x64-simulator"
|
|
]
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-pack/lib/preset/win32.js
|
|
var require_win322 = __commonJS({
|
|
"../../node_modules/bare-pack/lib/preset/win32.js"(exports, module) {
|
|
module.exports = {
|
|
hosts: ["win32-arm64", "win32-x64"]
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-pack/lib/preset.js
|
|
var require_preset = __commonJS({
|
|
"../../node_modules/bare-pack/lib/preset.js"(exports) {
|
|
exports.android = require_android();
|
|
exports.darwin = require_darwin();
|
|
exports.desktop = require_desktop();
|
|
exports.ios = require_ios();
|
|
exports.linux = require_linux();
|
|
exports.mobile = require_mobile();
|
|
exports.win32 = require_win322();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-pack/index.js
|
|
var require_bare_pack = __commonJS({
|
|
"../../node_modules/bare-pack/index.js"(exports, module) {
|
|
var Semaphore = require_promaphore();
|
|
var Bundle = require_bare_bundle();
|
|
var traverse = require_bare_module_traverse();
|
|
var preset = require_preset();
|
|
module.exports = async function pack(entry, opts, readModule, listPrefix, writeFile) {
|
|
if (typeof opts === "function") {
|
|
writeFile = listPrefix;
|
|
listPrefix = readModule;
|
|
readModule = opts;
|
|
opts = {};
|
|
}
|
|
if (!listPrefix) listPrefix = defaultListPrefix(readModule);
|
|
if (!writeFile) writeFile = defaultWriteFile;
|
|
opts = withPreset(opts);
|
|
let {
|
|
concurrency = 0,
|
|
base = null,
|
|
offload = false,
|
|
builtinProtocol = "builtin:",
|
|
linkedProtocol = "linked:",
|
|
deferredProtocol = "deferred:"
|
|
} = opts;
|
|
if (base !== null) base = new URL(base);
|
|
const offloadAddons = offload === true || offload && offload.addons === true;
|
|
const offloadAssets = offload === true || offload && offload.assets === true;
|
|
const semaphore = concurrency > 0 ? new Semaphore(concurrency) : null;
|
|
let bundle = new Bundle();
|
|
const addons = /* @__PURE__ */ new Set();
|
|
const assets = /* @__PURE__ */ new Set();
|
|
const dependencies = [];
|
|
const deferred = [];
|
|
await collect(
|
|
traverse.module(entry, await readModule(entry), null, { addons, assets }, /* @__PURE__ */ new Set(), opts)
|
|
);
|
|
while (deferred.length > 0) {
|
|
await Promise.all(deferred.splice(0).map(collect));
|
|
}
|
|
const rewrites = /* @__PURE__ */ new Map();
|
|
await Promise.all(dependencies.map(process));
|
|
const main = traverse.alias(entry, opts);
|
|
for (const { url, source, imports } of dependencies) {
|
|
if (shouldOffload(url.href)) continue;
|
|
bundle.write(url.href, source, {
|
|
main: url.href === main.href,
|
|
imports
|
|
});
|
|
}
|
|
bundle.addons = [...addons].filter((href) => !shouldOffload(href)).sort();
|
|
bundle.assets = [...assets].filter((href) => !shouldOffload(href)).sort();
|
|
if (base !== null) bundle = bundle.unmount(base);
|
|
if (rewrites.size > 0) {
|
|
const resolutions = {};
|
|
for (const [key, value] of Object.entries(bundle.resolutions)) {
|
|
resolutions[key] = rewriteImportsMap(value, rewrites);
|
|
}
|
|
bundle.resolutions = resolutions;
|
|
}
|
|
return bundle;
|
|
function shouldOffload(href) {
|
|
if (href.startsWith(builtinProtocol)) return false;
|
|
if (href.startsWith(linkedProtocol)) return false;
|
|
if (href.startsWith(deferredProtocol)) return false;
|
|
return offloadAddons && addons.has(href) || offloadAssets && assets.has(href);
|
|
}
|
|
function postUnmountPath(url) {
|
|
if (base === null || url.protocol !== base.protocol || url.host !== base.host || url.port !== base.port) {
|
|
return url.href;
|
|
}
|
|
let basePath = base.pathname;
|
|
if (!basePath.endsWith("/")) basePath += "/";
|
|
if (!url.pathname.startsWith(basePath)) return url.href;
|
|
return "/" + url.pathname.slice(basePath.length);
|
|
}
|
|
async function process({ url, source }) {
|
|
if (!shouldOffload(url.href)) return;
|
|
if (semaphore !== null) await semaphore.wait();
|
|
const target = await writeFile(url, source);
|
|
let key = postUnmountPath(url);
|
|
let value = null;
|
|
if (target) value = String(target);
|
|
else if (base !== null) value = "/.." + key;
|
|
if (value !== null) {
|
|
rewrites.set(key, value);
|
|
for (; ; ) {
|
|
key = key.substring(0, key.lastIndexOf("/"));
|
|
if (isTerminator(key)) break;
|
|
value = value.substring(0, value.lastIndexOf("/"));
|
|
if (isTerminator(value)) break;
|
|
rewrites.set(key, value);
|
|
}
|
|
}
|
|
if (semaphore !== null) semaphore.signal();
|
|
}
|
|
async function collect(generator) {
|
|
if (semaphore !== null) await semaphore.wait();
|
|
const queue = [];
|
|
let next = generator.next();
|
|
while (next.done !== true) {
|
|
const value = next.value;
|
|
if (value.module) {
|
|
next = generator.next(await readModule(value.module));
|
|
} else if (value.probe) {
|
|
next = generator.next();
|
|
} else if (value.resolution) {
|
|
next = generator.next(value.resolution);
|
|
} else if (value.prefix) {
|
|
const result = [];
|
|
for await (const url of listPrefix(value.prefix)) {
|
|
result.push(url);
|
|
}
|
|
next = generator.next(result);
|
|
} else if (value.links) {
|
|
if (semaphore !== null) semaphore.signal();
|
|
await Promise.all(value.links.map(collect));
|
|
if (semaphore !== null) await semaphore.wait();
|
|
next = generator.next();
|
|
} else if (value.children) {
|
|
if (value.deferred) deferred.push(value.children);
|
|
else queue.push(value.children);
|
|
next = generator.next();
|
|
} else {
|
|
dependencies.push(value.dependency);
|
|
next = generator.next();
|
|
}
|
|
}
|
|
if (semaphore !== null) semaphore.signal();
|
|
await Promise.all(queue.map(collect));
|
|
}
|
|
};
|
|
function withPreset(opts = {}) {
|
|
if (opts.preset) {
|
|
if (opts.preset in preset === false) {
|
|
throw new Error(`Unknown preset '${opts.preset}'`);
|
|
}
|
|
opts = Object.assign({}, opts, preset[opts.preset]);
|
|
}
|
|
return opts;
|
|
}
|
|
function defaultListPrefix(readModule) {
|
|
return async function* listPrefix(prefix) {
|
|
if (await readModule(prefix) !== null) {
|
|
yield prefix;
|
|
}
|
|
};
|
|
}
|
|
function defaultWriteFile() {
|
|
return null;
|
|
}
|
|
function isTerminator(input) {
|
|
return input === "" || input.endsWith("/") || input.endsWith(":");
|
|
}
|
|
function rewriteImportsMap(imports, rewrites) {
|
|
if (rewrites.size === 0 || typeof imports !== "object" || imports === null) return null;
|
|
return transformImportsMap(imports, (value) => rewrites.get(value) || value);
|
|
}
|
|
function transformImportsMap(value, fn) {
|
|
const imports = {};
|
|
for (const entry of Object.entries(value)) {
|
|
const condition = entry[0];
|
|
imports[condition] = transformImportsMapEntry(entry[1], fn);
|
|
}
|
|
return imports;
|
|
}
|
|
function transformImportsMapEntry(value, fn) {
|
|
if (typeof value === "string") return fn(value);
|
|
return transformImportsMap(value, fn);
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-pack-drive/index.js
|
|
var require_bare_pack_drive = __commonJS({
|
|
"../../node_modules/bare-pack-drive/index.js"(exports, module) {
|
|
var pack = require_bare_pack();
|
|
module.exports = async function(drive, entry = "/index.js", writeFile = null, opts = {}) {
|
|
if (typeof entry === "object" && entry !== null) {
|
|
opts = entry;
|
|
entry = "/index.js";
|
|
} else if (typeof writeFile === "object" && writeFile !== null) {
|
|
opts = writeFile;
|
|
writeFile = null;
|
|
}
|
|
const root = new URL("drive:///");
|
|
const bundle = await pack(new URL(entry, root), opts, readModule, listPrefix, writeFile);
|
|
return bundle.unmount(root);
|
|
async function readModule(url) {
|
|
return drive.get(url.pathname);
|
|
}
|
|
async function* listPrefix(url) {
|
|
const entry2 = await drive.get(url.pathname);
|
|
if (entry2 !== null) return yield url;
|
|
if (url.pathname[url.pathname.length - 1] !== "/") {
|
|
url.pathname += "/";
|
|
}
|
|
for await (const { key } of drive.list(url.pathname, { recursive: true })) {
|
|
yield new URL(key, url);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-type-stripper/lib/binding/bare.js
|
|
var require_bare4 = __commonJS({
|
|
"../../node_modules/bare-type-stripper/lib/binding/bare.js"(exports, module) {
|
|
module.exports = __require.addon("../..");
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-type-stripper/index.js
|
|
var require_bare_type_stripper = __commonJS({
|
|
"../../node_modules/bare-type-stripper/index.js"(exports, module) {
|
|
var binding = require_bare4();
|
|
module.exports = exports = function strip(input, encoding, opts = {}) {
|
|
if (typeof encoding === "object" && encoding !== null) {
|
|
opts = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof input !== "string" && !ArrayBuffer.isView(input)) {
|
|
throw new TypeError(`Input must be a string or buffer. Received type ${typeof input}`);
|
|
}
|
|
const buffer = typeof input === "string" ? Buffer.from(input, encoding) : input;
|
|
const ranges = binding.lex(buffer);
|
|
check(buffer, ranges);
|
|
return apply(buffer, ranges);
|
|
};
|
|
exports.lex = function lex(input, encoding, opts = {}) {
|
|
if (typeof encoding === "object" && encoding !== null) {
|
|
opts = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof input !== "string" && !ArrayBuffer.isView(input)) {
|
|
throw new TypeError(`Input must be a string or buffer. Received type ${typeof input}`);
|
|
}
|
|
const ranges = binding.lex(typeof input === "string" ? Buffer.from(input, encoding) : input);
|
|
const result = [];
|
|
for (let r = 0; r < ranges.length; r += 3) {
|
|
const flags = ranges[r + 2];
|
|
result.push(flags ? [ranges[r], ranges[r + 1], flags] : [ranges[r], ranges[r + 1]]);
|
|
}
|
|
return result;
|
|
};
|
|
exports.constants = {
|
|
/**
|
|
* Range flag: The first byte of the stripped range becomes ';' instead of
|
|
* a space, so ASI can't fold the previous statement into whatever follows.
|
|
*/
|
|
SEMI: binding.SEMI,
|
|
/**
|
|
* Range flag: The first byte of the stripped range becomes ')' instead of
|
|
* a space. Used in tandem with a wider strip range to relocate the closing
|
|
* ')' of an arrow function's parameter list to the line where '=>' lives,
|
|
* when the (now stripped) return-type annotation spanned newlines.
|
|
*/
|
|
PAREN: binding.PAREN,
|
|
/**
|
|
* Range flag: The range marks non-erasable TypeScript syntax (enums,
|
|
* namespaces, parameter properties, angle casts) that cannot be stripped
|
|
* to valid JavaScript. strip() throws on these; lex() returns them so
|
|
* callers can implement their own handling.
|
|
*/
|
|
ERROR: binding.ERROR
|
|
};
|
|
function check(buffer, ranges) {
|
|
for (let r = 0; r < ranges.length; r += 3) {
|
|
if ((ranges[r + 2] & binding.ERROR) === 0) continue;
|
|
const start = ranges[r];
|
|
const end = ranges[r + 1];
|
|
let line = 1;
|
|
let column = 1;
|
|
for (let i = 0; i < start; i++) {
|
|
if (buffer[i] === 10) {
|
|
line++;
|
|
column = 1;
|
|
} else {
|
|
column++;
|
|
}
|
|
}
|
|
const source = Buffer.from(buffer.subarray(start, Math.min(end, start + 32))).toString();
|
|
throw new SyntaxError(
|
|
`Cannot strip non-erasable TypeScript syntax '${source}' at ${line}:${column}`
|
|
);
|
|
}
|
|
}
|
|
function apply(buffer, ranges) {
|
|
const out = Buffer.from(buffer);
|
|
for (let r = 0; r < ranges.length; r += 3) {
|
|
const s = ranges[r];
|
|
const e = ranges[r + 1];
|
|
const f = ranges[r + 2];
|
|
if (f & binding.ERROR) continue;
|
|
for (let i = s; i < e; i++) {
|
|
if (i === s) {
|
|
if (f & binding.SEMI) {
|
|
out[i] = 59;
|
|
continue;
|
|
}
|
|
if (f & binding.PAREN) {
|
|
out[i] = 41;
|
|
continue;
|
|
}
|
|
}
|
|
const c = out[i];
|
|
if (c === 10 || c === 13) continue;
|
|
out[i] = 32;
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module/lib/protocol.js
|
|
var require_protocol = __commonJS({
|
|
"../../node_modules/bare-module/lib/protocol.js"(exports, module) {
|
|
module.exports = class ModuleProtocol {
|
|
constructor(methods = {}, context = null) {
|
|
for (const name of [
|
|
"preresolve",
|
|
"postresolve",
|
|
"resolve",
|
|
"exists",
|
|
"read",
|
|
"addon",
|
|
"asset"
|
|
]) {
|
|
const method = methods[name];
|
|
if (typeof method === "function") {
|
|
this[name] = context ? method.bind(this, context) : method.bind(this);
|
|
} else if (context) {
|
|
const method2 = context[name];
|
|
if (typeof method2 === "function") {
|
|
this[name] = method2;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
preresolve(specifier, parentURL) {
|
|
return specifier;
|
|
}
|
|
postresolve(url) {
|
|
return url;
|
|
}
|
|
*resolve(specifier, parentURL, imports) {
|
|
}
|
|
exists(url, type) {
|
|
return false;
|
|
}
|
|
read(url) {
|
|
return null;
|
|
}
|
|
addon(url) {
|
|
return url;
|
|
}
|
|
asset(url) {
|
|
return url;
|
|
}
|
|
extend(methods) {
|
|
return new ModuleProtocol(methods, this);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module/lib/constants.js
|
|
var require_constants4 = __commonJS({
|
|
"../../node_modules/bare-module/lib/constants.js"(exports, module) {
|
|
module.exports = {
|
|
states: {
|
|
EVALUATED: 1,
|
|
SYNTHESIZED: 2,
|
|
RUN: 4
|
|
},
|
|
types: {
|
|
SCRIPT: 1,
|
|
MODULE: 2,
|
|
JSON: 3,
|
|
BUNDLE: 4,
|
|
ADDON: 5,
|
|
BINARY: 6,
|
|
TEXT: 7,
|
|
ASSET: 8
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module/lib/errors.js
|
|
var require_errors10 = __commonJS({
|
|
"../../node_modules/bare-module/lib/errors.js"(exports, module) {
|
|
module.exports = class ModuleError extends Error {
|
|
constructor(msg, fn = ModuleError, code = fn.name) {
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "ModuleError";
|
|
}
|
|
static MODULE_NOT_FOUND(msg, specifier, referrer = null, candidates = []) {
|
|
const err = new ModuleError(msg, ModuleError.MODULE_NOT_FOUND);
|
|
err.specifier = specifier;
|
|
err.referrer = referrer;
|
|
err.candidates = candidates;
|
|
return err;
|
|
}
|
|
static ASSET_NOT_FOUND(msg, specifier, referrer = null, candidates = []) {
|
|
const err = new ModuleError(msg, ModuleError.ASSET_NOT_FOUND);
|
|
err.specifier = specifier;
|
|
err.referrer = referrer;
|
|
err.candidates = candidates;
|
|
return err;
|
|
}
|
|
static UNKNOWN_PROTOCOL(msg) {
|
|
return new ModuleError(msg, ModuleError.UNKNOWN_PROTOCOL);
|
|
}
|
|
static INVALID_BUNDLE_EXTENSION(msg) {
|
|
return new ModuleError(msg, ModuleError.INVALID_BUNDLE_EXTENSION);
|
|
}
|
|
static INVALID_URL_PATH(msg) {
|
|
return new ModuleError(msg, ModuleError.INVALID_URL_PATH);
|
|
}
|
|
static INVALID_IMPORTS_MAP(msg) {
|
|
return new ModuleError(msg, ModuleError.INVALID_IMPORTS_MAP);
|
|
}
|
|
static TYPE_INCOMPATIBLE(msg) {
|
|
return new ModuleError(msg, ModuleError.TYPE_INCOMPATIBLE);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module/binding.js
|
|
var require_binding4 = __commonJS({
|
|
"../../node_modules/bare-module/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module/index.js
|
|
var require_bare_module = __commonJS({
|
|
"../../node_modules/bare-module/index.js"(exports, module) {
|
|
var path = require_bare_path();
|
|
var resolve = require_bare_module_resolve();
|
|
var lex = require_bare_module_lexer();
|
|
var strip = require_bare_type_stripper();
|
|
var { isURL, fileURLToPath, pathToFileURL } = require_bare_url();
|
|
var Bundle = require_bare_bundle();
|
|
var Protocol = require_protocol();
|
|
var constants = require_constants4();
|
|
var errors = require_errors10();
|
|
var binding = require_binding4();
|
|
var kind = Symbol.for("bare.module.kind");
|
|
var isWindows = Bare.platform === "win32";
|
|
var { startsWithWindowsDriveLetter } = resolve;
|
|
module.exports = exports = class Module2 {
|
|
static get [kind]() {
|
|
return 1;
|
|
}
|
|
constructor(url) {
|
|
this._url = url;
|
|
this._state = 0;
|
|
this._type = 0;
|
|
this._defaultType = 0;
|
|
this._main = null;
|
|
this._exports = null;
|
|
this._imports = null;
|
|
this._resolutions = null;
|
|
this._builtins = null;
|
|
this._conditions = null;
|
|
this._protocol = null;
|
|
this._cache = null;
|
|
this._source = null;
|
|
this._function = null;
|
|
this._names = null;
|
|
this._promise = null;
|
|
this._handle = null;
|
|
Object.preventExtensions(this);
|
|
}
|
|
get [kind]() {
|
|
return Module2[kind];
|
|
}
|
|
get url() {
|
|
return this._url;
|
|
}
|
|
get type() {
|
|
return this._type;
|
|
}
|
|
get defaultType() {
|
|
return this._defaultType;
|
|
}
|
|
get main() {
|
|
return this._main;
|
|
}
|
|
get exports() {
|
|
return this._exports;
|
|
}
|
|
set exports(value) {
|
|
this._exports = value;
|
|
}
|
|
get imports() {
|
|
return this._imports;
|
|
}
|
|
get resolutions() {
|
|
return this._resolutions;
|
|
}
|
|
get builtins() {
|
|
return this._builtins;
|
|
}
|
|
get conditions() {
|
|
return Array.from(this._conditions);
|
|
}
|
|
get protocol() {
|
|
return this._protocol;
|
|
}
|
|
get cache() {
|
|
return this._cache;
|
|
}
|
|
// For Node.js compatibility
|
|
get filename() {
|
|
return urlToPath(this._url);
|
|
}
|
|
// For Node.js compatibility
|
|
get dirname() {
|
|
return urlToDirname(this._url);
|
|
}
|
|
// For Node.js compatibility
|
|
get id() {
|
|
return this.filename;
|
|
}
|
|
// For Node.js compatibility
|
|
get path() {
|
|
return this.dirname;
|
|
}
|
|
_transform(isImport, isDynamicImport) {
|
|
if (isDynamicImport) {
|
|
this._run();
|
|
} else if (isImport) {
|
|
this._synthesize();
|
|
} else {
|
|
this._evaluate();
|
|
}
|
|
return this;
|
|
}
|
|
_synthesize() {
|
|
if ((this._state & constants.states.SYNTHESIZED) !== 0) return;
|
|
this._state |= constants.states.SYNTHESIZED;
|
|
if (this._type === constants.types.MODULE) return;
|
|
const names = /* @__PURE__ */ new Set(["default"]);
|
|
const queue = [this];
|
|
const seen = /* @__PURE__ */ new Set();
|
|
while (queue.length) {
|
|
const module2 = queue.pop();
|
|
if (seen.has(module2)) continue;
|
|
seen.add(module2);
|
|
switch (module2._type) {
|
|
case constants.types.SCRIPT: {
|
|
const result = lex(module2._source);
|
|
for (const { name } of result.exports) names.add(name);
|
|
const referrer = module2;
|
|
for (const { specifier, type } of result.imports) {
|
|
if ((type & lex.constants.REEXPORT) !== 0 && (type & lex.constants.ADDON) === 0 && (type & lex.constants.ASSET) === 0) {
|
|
const resolved = Module2.resolve(specifier, referrer._url, {
|
|
isImport: true,
|
|
referrer
|
|
});
|
|
const module3 = Module2.load(resolved, {
|
|
isImport: true,
|
|
referrer
|
|
});
|
|
if (module3._names) {
|
|
for (const name of module3._names) names.add(name);
|
|
} else {
|
|
queue.push(module3);
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case constants.types.MODULE:
|
|
module2._evaluate();
|
|
for (const name of Object.keys(module2._exports)) names.add(name);
|
|
break;
|
|
case constants.types.JSON:
|
|
for (const name of Object.keys(module2._exports)) names.add(name);
|
|
}
|
|
}
|
|
this._names = Array.from(names);
|
|
this._handle = binding.createSyntheticModule(this._url.href, this._names, Module2._handle);
|
|
const id = binding.getModuleID(this._handle);
|
|
Module2._registry.set(id, this);
|
|
}
|
|
_evaluate() {
|
|
if ((this._state & constants.states.EVALUATED) !== 0) return;
|
|
this._state |= constants.states.EVALUATED;
|
|
if (this._type === constants.types.SCRIPT) {
|
|
const require2 = exports.createRequire(this._url, { module: this });
|
|
this._exports = {};
|
|
const fn = this._function;
|
|
fn(require2, this, this._exports, urlToPath(this._url), urlToDirname(this._url));
|
|
} else if (this._type === constants.types.MODULE) {
|
|
this._run();
|
|
this._exports = binding.getModuleNamespace(this._handle);
|
|
}
|
|
}
|
|
_run() {
|
|
if ((this._state & constants.states.RUN) !== 0) return;
|
|
this._state |= constants.states.RUN;
|
|
this._synthesize();
|
|
this._promise = binding.runModule(this._handle, Module2._handle, Module2._onrun);
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return {
|
|
__proto__: { constructor: Module2 },
|
|
url: this.url,
|
|
type: this.type,
|
|
defaultType: this.defaultType,
|
|
main: this.main,
|
|
exports: this.exports,
|
|
imports: this.imports,
|
|
resolutions: this.resolutions,
|
|
builtins: this.builtins,
|
|
conditions: this.conditions
|
|
};
|
|
}
|
|
static _extensions = /* @__PURE__ */ Object.create(null);
|
|
static _protocol = null;
|
|
static _registry = /* @__PURE__ */ new WeakMap();
|
|
static _cache = module[kind] === Module2[kind] ? module.cache || /* @__PURE__ */ Object.create(null) : /* @__PURE__ */ Object.create(null);
|
|
static _conditions = ["bare", "node", ...Bare.Addon.host.split("-")];
|
|
static _handle = binding.init(this, this._onimport, this._onevaluate, this._onmeta);
|
|
static _onimport(specifier, attributes, referrerName, id, isDynamicImport) {
|
|
const referrer = this._registry.get(id) || null;
|
|
let parentURL;
|
|
if (referrer !== null) {
|
|
parentURL = referrer._url;
|
|
} else if (isDynamicImport) {
|
|
parentURL = referrerName ? toURL(referrerName) : pathToFileURL("./");
|
|
} else {
|
|
throw errors.MODULE_NOT_FOUND(`Cannot find referrer for module '${specifier}'`, specifier);
|
|
}
|
|
const resolved = this.resolve(specifier, parentURL, {
|
|
isImport: true,
|
|
referrer,
|
|
attributes
|
|
});
|
|
const module2 = this.load(resolved, {
|
|
isImport: true,
|
|
isDynamicImport,
|
|
referrer,
|
|
attributes
|
|
});
|
|
return isDynamicImport ? module2._promise.then(() => binding.getModuleNamespace(module2._handle)) : module2._handle;
|
|
}
|
|
static _onevaluate(id) {
|
|
const module2 = this._registry.get(id) || null;
|
|
if (module2 === null) {
|
|
throw errors.MODULE_NOT_FOUND("Cannot find module");
|
|
}
|
|
module2._evaluate();
|
|
for (const name of module2._names) {
|
|
let value;
|
|
if (name === "default" && (typeof module2._exports !== "object" || module2._exports === null || name in module2._exports === false)) {
|
|
value = module2._exports;
|
|
} else {
|
|
value = module2._exports[name];
|
|
}
|
|
binding.setModuleExport(module2._handle, name, value);
|
|
}
|
|
}
|
|
static _onmeta(id, meta) {
|
|
const module2 = this._registry.get(id) || null;
|
|
if (module2 === null) {
|
|
throw errors.MODULE_NOT_FOUND("Cannot find module");
|
|
}
|
|
const referrer = module2;
|
|
meta.url = module2._url.href;
|
|
meta.main = module2._main === module2;
|
|
meta.cache = module2._cache;
|
|
meta.dirname = module2.dirname;
|
|
meta.filename = module2.filename;
|
|
meta.resolve = function resolve2(specifier, parentURL = referrer._url) {
|
|
return Module2.resolve(specifier, toURL(parentURL, referrer._url), {
|
|
referrer
|
|
}).href;
|
|
};
|
|
meta.addon = function addon(specifier = ".", parentURL = referrer._url) {
|
|
const resolved = Bare.Addon.resolve(specifier, toURL(parentURL, referrer._url), { referrer });
|
|
const addon2 = Bare.Addon.load(resolved, { referrer });
|
|
return addon2._exports;
|
|
};
|
|
meta.addon.resolve = function resolve2(specifier = ".", parentURL = referrer._url) {
|
|
return Bare.Addon.resolve(specifier, toURL(parentURL, referrer._url), {
|
|
referrer
|
|
}).href;
|
|
};
|
|
meta.addon.host = Bare.Addon.host;
|
|
meta.asset = function asset(specifier, parentURL = referrer._url) {
|
|
return Module2.asset(specifier, toURL(parentURL, referrer._url), {
|
|
referrer
|
|
}).href;
|
|
};
|
|
}
|
|
static _onrun(reason, promise, err = reason) {
|
|
if (err) {
|
|
promise.catch(() => {
|
|
});
|
|
throw err;
|
|
} else {
|
|
promise.catch(
|
|
(err2) => queueMicrotask(() => {
|
|
throw err2;
|
|
})
|
|
);
|
|
}
|
|
}
|
|
static get protocol() {
|
|
return this._protocol;
|
|
}
|
|
static get cache() {
|
|
return this._cache;
|
|
}
|
|
static load(url, source = null, opts = {}) {
|
|
if (!ArrayBuffer.isView(source) && !Bundle.isBundle(source) && typeof source !== "string" && source !== null) {
|
|
opts = source;
|
|
source = null;
|
|
}
|
|
const referrer = opts.referrer || null;
|
|
const inherited = inherit(referrer);
|
|
const {
|
|
isImport = false,
|
|
isDynamicImport = false,
|
|
attributes,
|
|
type = typeForAttributes(attributes),
|
|
defaultType = inherited.defaultType,
|
|
cache = inherited.cache,
|
|
main = inherited.main,
|
|
protocol = inherited.protocol,
|
|
imports = inherited.imports,
|
|
resolutions = inherited.resolutions,
|
|
builtins = inherited.builtins,
|
|
conditions = inherited.conditions
|
|
} = opts;
|
|
let module2 = cache[url.href] || null;
|
|
if (module2 !== null) {
|
|
if (type !== 0 && type !== module2._type) {
|
|
throw errors.TYPE_INCOMPATIBLE(
|
|
`Module '${module2.url.href}' is not of type '${nameOfType(type)}'`
|
|
);
|
|
}
|
|
return module2._transform(isImport, isDynamicImport);
|
|
}
|
|
module2 = cache[url.href] = new Module2(url);
|
|
try {
|
|
switch (url.protocol) {
|
|
case "builtin:":
|
|
module2._exports = builtins[url.pathname];
|
|
break;
|
|
default: {
|
|
module2._defaultType = defaultType;
|
|
module2._cache = cache;
|
|
module2._main = main || module2;
|
|
module2._protocol = protocol;
|
|
module2._imports = imports;
|
|
module2._resolutions = resolutions;
|
|
module2._builtins = builtins;
|
|
module2._conditions = conditions;
|
|
if (typeof attributes === "object" && attributes !== null && typeof attributes.imports === "string") {
|
|
const resolved = Module2.resolve(attributes.imports, referrer._url, {
|
|
referrer: module2
|
|
});
|
|
const imports2 = Module2.load(resolved, {
|
|
referrer: module2,
|
|
type: constants.types.JSON
|
|
});
|
|
module2._imports = mixinImports(module2._imports, imports2._exports, resolved);
|
|
}
|
|
let extension = canonicalExtensionForType(type) || path.extname(url.pathname);
|
|
if (extension in Module2._extensions === false) {
|
|
if (defaultType) {
|
|
extension = canonicalExtensionForType(defaultType) || ".js";
|
|
} else {
|
|
extension = ".js";
|
|
}
|
|
}
|
|
Module2._extensions[extension](module2, source, referrer);
|
|
}
|
|
}
|
|
return module2._transform(isImport, isDynamicImport);
|
|
} catch (err) {
|
|
delete cache[url.href];
|
|
throw err;
|
|
}
|
|
}
|
|
static resolve(specifier, parentURL, opts = {}) {
|
|
if (typeof specifier !== "string") {
|
|
throw new TypeError(
|
|
`Specifier must be a string. Received type ${typeof specifier} (${specifier})`
|
|
);
|
|
}
|
|
const referrer = opts.referrer || null;
|
|
const inherited = inherit(referrer);
|
|
const {
|
|
isImport = false,
|
|
attributes,
|
|
type = typeForAttributes(attributes),
|
|
extensions = extensionsForType(type),
|
|
cache = referrer ? referrer._cache : /* @__PURE__ */ Object.create(null),
|
|
protocol = inherited.protocol,
|
|
imports = inherited.imports,
|
|
resolutions = inherited.resolutions,
|
|
builtins = inherited.builtins,
|
|
conditions = inherited.conditions
|
|
} = opts;
|
|
const resolved = protocol.preresolve(specifier, parentURL);
|
|
const [resolution] = protocol.resolve(resolved, parentURL, imports);
|
|
if (resolution) return protocol.postresolve(resolution);
|
|
const candidates = [];
|
|
for (const resolution2 of resolve(
|
|
resolved,
|
|
parentURL,
|
|
{
|
|
conditions: isImport ? ["import", ...conditions] : ["require", ...conditions],
|
|
imports,
|
|
resolutions,
|
|
extensions,
|
|
builtins: builtins ? Object.keys(builtins) : [],
|
|
engines: Bare.versions
|
|
},
|
|
readPackageFor(protocol, cache)
|
|
)) {
|
|
candidates.push(resolution2);
|
|
const condition = isImport ? "import" : "require";
|
|
switch (resolution2.protocol) {
|
|
case "builtin:":
|
|
cacheResolution(resolutions, parentURL, resolved, condition, resolution2);
|
|
return resolution2;
|
|
default:
|
|
if (protocol.exists(resolution2, type)) {
|
|
const postresolved = protocol.postresolve(resolution2);
|
|
cacheResolution(resolutions, parentURL, resolved, condition, postresolved);
|
|
return postresolved;
|
|
}
|
|
}
|
|
}
|
|
throw errors.MODULE_NOT_FOUND(
|
|
notFound("module", specifier, parentURL, candidates),
|
|
specifier,
|
|
parentURL,
|
|
candidates
|
|
);
|
|
}
|
|
static asset(specifier, parentURL, opts = {}) {
|
|
if (typeof specifier !== "string") {
|
|
throw new TypeError(
|
|
`Specifier must be a string. Received type ${typeof specifier} (${specifier})`
|
|
);
|
|
}
|
|
const referrer = opts.referrer || null;
|
|
const inherited = inherit(referrer);
|
|
const {
|
|
cache = referrer ? referrer._cache : /* @__PURE__ */ Object.create(null),
|
|
protocol = inherited.protocol,
|
|
imports = inherited.imports,
|
|
resolutions = inherited.resolutions,
|
|
conditions = inherited.conditions
|
|
} = opts;
|
|
const resolved = protocol.preresolve(specifier, parentURL);
|
|
const [resolution] = protocol.resolve(resolved, parentURL, imports);
|
|
if (resolution) return protocol.postresolve(resolution);
|
|
const candidates = [];
|
|
for (const resolution2 of resolve(
|
|
resolved,
|
|
parentURL,
|
|
{
|
|
conditions: ["asset", ...conditions],
|
|
imports,
|
|
resolutions,
|
|
engines: Bare.versions
|
|
},
|
|
readPackageFor(protocol, cache)
|
|
)) {
|
|
candidates.push(resolution2);
|
|
if (protocol.exists(resolution2, constants.types.ASSET)) {
|
|
const postresolved = protocol.postresolve(
|
|
protocol.asset ? protocol.asset(resolution2) : resolution2
|
|
);
|
|
cacheResolution(resolutions, parentURL, resolved, "asset", postresolved);
|
|
return postresolved;
|
|
}
|
|
}
|
|
throw errors.ASSET_NOT_FOUND(
|
|
notFound("asset", specifier, parentURL, candidates),
|
|
specifier,
|
|
parentURL,
|
|
candidates
|
|
);
|
|
}
|
|
};
|
|
var Module = exports;
|
|
function inherit(referrer) {
|
|
return {
|
|
defaultType: referrer ? referrer._defaultType : 0,
|
|
cache: referrer ? referrer._cache : Module._cache,
|
|
main: referrer ? referrer._main : null,
|
|
protocol: referrer ? referrer._protocol : Module._protocol,
|
|
imports: referrer ? referrer._imports : null,
|
|
resolutions: referrer ? referrer._resolutions : /* @__PURE__ */ Object.create(null),
|
|
builtins: referrer ? referrer._builtins : null,
|
|
conditions: referrer ? referrer._conditions : Module._conditions
|
|
};
|
|
}
|
|
function readPackageFor(protocol, cache) {
|
|
return function readPackage(packageURL) {
|
|
if (protocol.exists(packageURL, constants.types.JSON)) {
|
|
return Module.load(packageURL, { protocol, cache })._exports;
|
|
}
|
|
return null;
|
|
};
|
|
}
|
|
function notFound(kind2, specifier, parentURL, candidates) {
|
|
let message = `Cannot find ${kind2} '${specifier}' imported from '${parentURL.href}'`;
|
|
if (candidates.length > 0) {
|
|
message += "\nCandidates:";
|
|
message += "\n" + candidates.map((url) => "- " + url.href).join("\n");
|
|
}
|
|
return message;
|
|
}
|
|
var typeInfo = {
|
|
[constants.types.SCRIPT]: {
|
|
name: "script",
|
|
attribute: "script",
|
|
canonicalExtension: ".cjs",
|
|
extensions: [".js", ".cjs", ".ts", ".cts"]
|
|
},
|
|
[constants.types.MODULE]: {
|
|
name: "module",
|
|
attribute: "module",
|
|
canonicalExtension: ".mjs",
|
|
extensions: [".js", ".mjs", ".ts", ".mts"]
|
|
},
|
|
[constants.types.JSON]: {
|
|
name: "json",
|
|
attribute: "json",
|
|
canonicalExtension: ".json",
|
|
extensions: [".json"]
|
|
},
|
|
[constants.types.BUNDLE]: {
|
|
name: "bundle",
|
|
attribute: "bundle",
|
|
canonicalExtension: ".bundle",
|
|
extensions: [".bundle"]
|
|
},
|
|
[constants.types.ADDON]: {
|
|
name: "bare",
|
|
attribute: "addon",
|
|
canonicalExtension: ".bare",
|
|
extensions: [".bare", ".node"]
|
|
},
|
|
[constants.types.BINARY]: {
|
|
name: "binary",
|
|
attribute: "binary",
|
|
canonicalExtension: ".bin",
|
|
extensions: [".bin"]
|
|
},
|
|
[constants.types.TEXT]: {
|
|
name: "text",
|
|
attribute: "text",
|
|
canonicalExtension: ".txt",
|
|
extensions: [".txt"]
|
|
}
|
|
};
|
|
var defaultExtensions = [".js", ".cjs", ".mjs", ".ts", ".cts", ".mts", ".json", ".bare", ".node"];
|
|
var typeByAttribute = /* @__PURE__ */ Object.create(null);
|
|
for (const type in typeInfo) {
|
|
typeByAttribute[typeInfo[type].attribute] = +type;
|
|
}
|
|
function extensionsForType(type) {
|
|
return type in typeInfo ? typeInfo[type].extensions : defaultExtensions;
|
|
}
|
|
function canonicalExtensionForType(type) {
|
|
return type in typeInfo ? typeInfo[type].canonicalExtension : null;
|
|
}
|
|
function nameOfType(type) {
|
|
return type in typeInfo ? typeInfo[type].name : null;
|
|
}
|
|
function typeForAttributes(attributes) {
|
|
if (typeof attributes !== "object" || attributes === null) return 0;
|
|
return typeByAttribute[attributes.type] || 0;
|
|
}
|
|
function mixinImports(target, imports, url) {
|
|
if (typeof imports === "object" && imports !== null && "imports" in imports) {
|
|
imports = imports.imports;
|
|
}
|
|
if (typeof imports !== "object" || imports === null) {
|
|
throw errors.INVALID_IMPORTS_MAP(`Imports map at '${url.href}' is not valid`);
|
|
}
|
|
return { ...target, ...imports };
|
|
}
|
|
function cacheResolution(resolutions, parentURL, specifier, condition, resolved) {
|
|
if (resolutions === null) return;
|
|
let imports = resolutions[parentURL.href];
|
|
if (typeof imports !== "object" || imports === null) {
|
|
imports = resolutions[parentURL.href] = /* @__PURE__ */ Object.create(null);
|
|
}
|
|
if (specifier in imports) return;
|
|
imports[specifier] = { [condition]: resolved.href };
|
|
}
|
|
exports.Protocol = Protocol;
|
|
exports.constants = constants;
|
|
exports.builtinModules = [];
|
|
exports.isBuiltin = function isBuiltin() {
|
|
return false;
|
|
};
|
|
exports.createRequire = function createRequire(parentURL, opts = {}) {
|
|
const inherited = inherit(opts.referrer);
|
|
const {
|
|
type = constants.types.SCRIPT,
|
|
defaultType = inherited.defaultType || constants.types.SCRIPT,
|
|
cache = inherited.cache,
|
|
main = inherited.main,
|
|
protocol = inherited.protocol,
|
|
imports = inherited.imports,
|
|
resolutions = inherited.resolutions,
|
|
builtins = inherited.builtins,
|
|
conditions = inherited.conditions
|
|
} = opts;
|
|
let module2 = opts.module || null;
|
|
if (module2 === null) {
|
|
module2 = new Module(toURL(parentURL));
|
|
module2._type = type;
|
|
module2._defaultType = defaultType;
|
|
module2._cache = cache;
|
|
module2._main = main || module2;
|
|
module2._protocol = protocol;
|
|
module2._imports = imports;
|
|
module2._resolutions = resolutions;
|
|
module2._builtins = builtins;
|
|
module2._conditions = conditions;
|
|
}
|
|
const referrer = module2;
|
|
function require2(specifier, opts2 = {}) {
|
|
const attributes = opts2 && opts2.with;
|
|
const resolved = Module.resolve(specifier, referrer._url, {
|
|
referrer,
|
|
attributes
|
|
});
|
|
const module3 = Module.load(resolved, { referrer, attributes });
|
|
return module3._exports;
|
|
}
|
|
require2.main = module2._main;
|
|
require2.cache = module2._cache;
|
|
require2.resolve = function resolve2(specifier, parentURL2 = referrer._url) {
|
|
return urlToPath(Module.resolve(specifier, toURL(parentURL2, referrer._url), { referrer }));
|
|
};
|
|
require2.addon = function addon(specifier = ".", parentURL2 = referrer._url) {
|
|
const resolved = Bare.Addon.resolve(specifier, toURL(parentURL2, referrer._url), { referrer });
|
|
const addon2 = Bare.Addon.load(resolved, { referrer });
|
|
return addon2._exports;
|
|
};
|
|
require2.addon.host = Bare.Addon.host;
|
|
require2.addon.resolve = function resolve2(specifier = ".", parentURL2 = referrer._url) {
|
|
return urlToPath(
|
|
Bare.Addon.resolve(specifier, toURL(parentURL2, referrer._url), {
|
|
referrer
|
|
})
|
|
);
|
|
};
|
|
require2.asset = function asset(specifier, parentURL2 = referrer._url) {
|
|
return urlToPath(Module.asset(specifier, toURL(parentURL2, referrer._url), { referrer }));
|
|
};
|
|
return require2;
|
|
};
|
|
function readSource(module2, source) {
|
|
if (source === null) source = module2._protocol.read(module2._url);
|
|
if (typeof source === "string") source = Buffer.from(source);
|
|
return source;
|
|
}
|
|
Module._extensions[".js"] = function(module2, source, referrer) {
|
|
const cache = module2._cache;
|
|
const protocol = module2._protocol;
|
|
const resolutions = module2._resolutions;
|
|
let pkg;
|
|
for (const packageURL of resolve.lookupPackageScope(module2._url, {
|
|
resolutions
|
|
})) {
|
|
if (cache[packageURL.href]) {
|
|
pkg = cache[packageURL.href];
|
|
break;
|
|
}
|
|
if (protocol.exists(packageURL, constants.types.JSON)) {
|
|
pkg = Module.load(packageURL, { protocol, cache });
|
|
break;
|
|
}
|
|
}
|
|
const info = pkg && pkg._exports || {};
|
|
const isESM = (
|
|
// The default type is ES modules.
|
|
constants.types.MODULE === module2._defaultType || // The package is explicitly declared as an ES module.
|
|
info && info.type === "module"
|
|
);
|
|
return Module._extensions[isESM ? ".mjs" : ".cjs"](module2, source, referrer);
|
|
};
|
|
Module._extensions[".cjs"] = function(module2, source, referrer) {
|
|
module2._type = constants.types.SCRIPT;
|
|
source = readSource(module2, source);
|
|
module2._source = source;
|
|
module2._function = binding.createFunction(
|
|
module2._url.href,
|
|
["require", "module", "exports", "__filename", "__dirname"],
|
|
source.toString(),
|
|
0
|
|
);
|
|
const id = binding.getFunctionID(module2._function);
|
|
Module._registry.set(id, module2);
|
|
};
|
|
Module._extensions[".mjs"] = function(module2, source, referrer) {
|
|
module2._type = constants.types.MODULE;
|
|
source = readSource(module2, source);
|
|
module2._source = source;
|
|
module2._handle = binding.createModule(module2._url.href, source.toString(), 0, Module._handle);
|
|
const id = binding.getModuleID(module2._handle);
|
|
Module._registry.set(id, module2);
|
|
};
|
|
for (const [typescript, javascript] of [
|
|
[".ts", ".js"],
|
|
[".cts", ".cjs"],
|
|
[".mts", ".mjs"]
|
|
]) {
|
|
Module._extensions[typescript] = function(module2, source, referrer) {
|
|
return Module._extensions[javascript](module2, strip(readSource(module2, source)), referrer);
|
|
};
|
|
}
|
|
Module._extensions[".json"] = function(module2, source, referrer) {
|
|
module2._type = constants.types.JSON;
|
|
source = readSource(module2, source);
|
|
module2._source = source;
|
|
module2._exports = JSON.parse(source.toString());
|
|
};
|
|
Module._extensions[".bare"] = Module._extensions[".node"] = function(module2, source, referrer) {
|
|
module2._type = constants.types.ADDON;
|
|
referrer = module2;
|
|
module2._exports = Bare.Addon.load(module2._url, { referrer }).exports;
|
|
};
|
|
Module._extensions[".bundle"] = function(module2, source, referrer) {
|
|
const protocol = module2._protocol;
|
|
module2._type = constants.types.BUNDLE;
|
|
source = readSource(module2, source);
|
|
referrer = module2;
|
|
const bundle = Bundle.from(source).mount(module2._url.href + "/");
|
|
module2._source = source;
|
|
module2._imports = bundle.imports;
|
|
module2._resolutions = bundle.resolutions;
|
|
module2._protocol = protocol.extend({
|
|
postresolve(context, url) {
|
|
return bundle.exists(url.href) ? url : context.postresolve(url);
|
|
},
|
|
exists(context, url, type) {
|
|
return bundle.exists(url.href) || context.exists(url, type);
|
|
},
|
|
read(context, url) {
|
|
return bundle.read(url.href) || context.read(url);
|
|
}
|
|
});
|
|
if (bundle.main) {
|
|
module2._exports = Module.load(new URL(bundle.main), bundle.read(bundle.main), {
|
|
referrer
|
|
})._exports;
|
|
}
|
|
};
|
|
Module._extensions[".bin"] = function(module2, source, referrer) {
|
|
module2._type = constants.types.BINARY;
|
|
source = readSource(module2, source);
|
|
module2._source = module2._exports = source;
|
|
};
|
|
Module._extensions[".txt"] = function(module2, source, referrer) {
|
|
module2._type = constants.types.TEXT;
|
|
source = readSource(module2, source);
|
|
module2._source = source;
|
|
module2._exports = source.toString();
|
|
};
|
|
Module._protocol = new Protocol({
|
|
postresolve(url) {
|
|
switch (url.protocol) {
|
|
case "file:":
|
|
return pathToFileURL(binding.realpath(path.toNamespacedPath(fileURLToPath(url))));
|
|
default:
|
|
return url;
|
|
}
|
|
},
|
|
exists(url, type = 0) {
|
|
switch (url.protocol) {
|
|
case "file:":
|
|
return binding.exists(
|
|
path.toNamespacedPath(fileURLToPath(url)),
|
|
type === constants.types.ASSET ? binding.FILE | binding.DIR : binding.FILE
|
|
);
|
|
default:
|
|
return false;
|
|
}
|
|
},
|
|
read(url) {
|
|
switch (url.protocol) {
|
|
case "file:":
|
|
return Buffer.from(binding.read(path.toNamespacedPath(fileURLToPath(url))));
|
|
default:
|
|
throw errors.UNKNOWN_PROTOCOL(`Cannot load module '${url.href}'`);
|
|
}
|
|
}
|
|
});
|
|
function toURL(value, base) {
|
|
if (isURL(value)) return value;
|
|
if (startsWithWindowsDriveLetter(value)) {
|
|
return pathToFileURL(value);
|
|
}
|
|
return URL.parse(value, base) || pathToFileURL(value);
|
|
}
|
|
function urlToPath(url) {
|
|
if (url.protocol === "file:") return fileURLToPath(url);
|
|
assertValidURLPath(url);
|
|
return decodeURIComponent(url.pathname);
|
|
}
|
|
function urlToDirname(url) {
|
|
if (url.protocol === "file:") return path.dirname(fileURLToPath(url));
|
|
assertValidURLPath(url);
|
|
return decodeURIComponent(new URL(".", url).pathname).replace(/\/$/, "");
|
|
}
|
|
function assertValidURLPath(url) {
|
|
if (isWindows) {
|
|
if (/%2f|%5c/i.test(url.pathname)) {
|
|
throw errors.INVALID_URL_PATH("The URL path must not include encoded \\ or / characters");
|
|
}
|
|
} else {
|
|
if (/%2f/i.test(url.pathname)) {
|
|
throw errors.INVALID_URL_PATH("The URL path must not include encoded / characters");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-boot/index.js
|
|
var require_bare_boot = __commonJS({
|
|
"../../node_modules/bare-boot/index.js"(exports, module) {
|
|
var path = require_bare_path();
|
|
var url = require_bare_url();
|
|
var fs = require_promises();
|
|
var pack = require_bare_pack_drive();
|
|
var Module = require_bare_module();
|
|
var { resolve } = require_bare_module_traverse();
|
|
module.exports = async function boot(drive, entry = "/index.js", opts = {}) {
|
|
if (typeof entry === "object" && entry !== null) {
|
|
opts = entry;
|
|
entry = "/index.js";
|
|
}
|
|
const { host, cwd = "." } = opts;
|
|
const base = url.pathToFileURL(path.resolve(cwd) + path.sep);
|
|
const bundle = await pack(drive, entry, writeFile, {
|
|
host,
|
|
resolve: resolve.bare,
|
|
offload: true
|
|
});
|
|
const module2 = Module.load(new URL(`drive:///${path.basename(entry)}.bundle`), bundle, {
|
|
cache: /* @__PURE__ */ Object.create(null)
|
|
});
|
|
return module2.exports;
|
|
async function writeFile(href, source) {
|
|
const file = new URL(href.pathname.slice(1), base);
|
|
await fs.mkdir(new URL(".", file), { recursive: true });
|
|
await fs.writeFile(file, source);
|
|
return file;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../bare-lib-entry-bareBoot.js
|
|
var bare_lib_entry_bareBoot_exports = {};
|
|
__export(bare_lib_entry_bareBoot_exports, {
|
|
default: () => bare_lib_entry_bareBoot_default
|
|
});
|
|
var import_bare_boot = __toESM(require_bare_boot());
|
|
var bare_lib_entry_bareBoot_default = import_bare_boot.default;
|
|
return __toCommonJS(bare_lib_entry_bareBoot_exports);
|
|
})();
|
|
;(function(){var g=globalThis;var s="__bare_os_stdlib__";g[s]=g[s]||{};var e=typeof __bare_os_bundle_exports__!=="undefined"?__bare_os_bundle_exports__:void 0;var v=e!=null&&typeof e==="object"&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;g[s]["bareBoot"]=v;})();
|