#!/usr/bin/env node 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 __commonJS = (cb, mod) => function __require() { try { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; } catch (e) { throw mod = 0, e; } }; var __copyProps = (to2, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to2, key) && key !== except) __defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to2; }; 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 )); // node_modules/semver/internal/constants.js var require_constants = __commonJS({ "node_modules/semver/internal/constants.js"(exports2, module2) { "use strict"; var SEMVER_SPEC_VERSION = "2.0.0"; var MAX_LENGTH = 256; var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || /* istanbul ignore next */ 9007199254740991; var MAX_SAFE_COMPONENT_LENGTH = 16; var MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6; var WHITESPACE_CHARACTERS = [ " ", "\n", "\v", "\f", "\r", " ", "\xA0", "\u1680", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200A", "\u2028", "\u2029", "\u202F", "\u205F", "\u3000", "\uFEFF" ]; var RELEASE_TYPES = [ "major", "premajor", "minor", "preminor", "patch", "prepatch", "prerelease" ]; module2.exports = { MAX_LENGTH, MAX_SAFE_COMPONENT_LENGTH, MAX_SAFE_BUILD_LENGTH, MAX_SAFE_INTEGER, WHITESPACE_CHARACTERS, RELEASE_TYPES, SEMVER_SPEC_VERSION, FLAG_INCLUDE_PRERELEASE: 1, FLAG_LOOSE: 2 }; } }); // node_modules/semver/internal/debug.js var require_debug = __commonJS({ "node_modules/semver/internal/debug.js"(exports2, module2) { "use strict"; var debug = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => { }; module2.exports = debug; } }); // node_modules/semver/internal/re.js var require_re = __commonJS({ "node_modules/semver/internal/re.js"(exports2, module2) { "use strict"; var { MAX_SAFE_COMPONENT_LENGTH, MAX_SAFE_BUILD_LENGTH, MAX_LENGTH } = require_constants(); var debug = require_debug(); exports2 = module2.exports = {}; var re2 = exports2.re = []; var safeRe = exports2.safeRe = []; var src = exports2.src = []; var safeSrc = exports2.safeSrc = []; var t = exports2.t = {}; var R2 = 0; var LETTERDASHNUMBER = "[a-zA-Z0-9-]"; var safeRegexReplacements = [ ["\\s", 1], ["\\d", MAX_LENGTH], [LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH] ]; var makeSafeRegex = (value) => { for (const [token2, max] of safeRegexReplacements) { value = value.split(`${token2}*`).join(`${token2}{0,${max}}`).split(`${token2}+`).join(`${token2}{1,${max}}`); } return value; }; var createToken = (name, value, isGlobal) => { const safe = makeSafeRegex(value); const index = R2++; debug(name, index, value); t[name] = index; src[index] = value; safeSrc[index] = safe; re2[index] = new RegExp(value, isGlobal ? "g" : void 0); safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0); }; createToken("NUMERICIDENTIFIER", "0|[1-9]\\d*"); createToken("NUMERICIDENTIFIERLOOSE", "\\d+"); createToken("NONNUMERICIDENTIFIER", `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`); createToken("MAINVERSION", `(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})`); createToken("MAINVERSIONLOOSE", `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})`); createToken("PRERELEASEIDENTIFIER", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIER]})`); createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIERLOOSE]})`); createToken("PRERELEASE", `(?:-(${src[t.PRERELEASEIDENTIFIER]}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`); createToken("PRERELEASELOOSE", `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`); createToken("BUILDIDENTIFIER", `${LETTERDASHNUMBER}+`); createToken("BUILD", `(?:\\+(${src[t.BUILDIDENTIFIER]}(?:\\.${src[t.BUILDIDENTIFIER]})*))`); createToken("FULLPLAIN", `v?${src[t.MAINVERSION]}${src[t.PRERELEASE]}?${src[t.BUILD]}?`); createToken("FULL", `^${src[t.FULLPLAIN]}$`); createToken("LOOSEPLAIN", `[v=\\s]*${src[t.MAINVERSIONLOOSE]}${src[t.PRERELEASELOOSE]}?${src[t.BUILD]}?`); createToken("LOOSE", `^${src[t.LOOSEPLAIN]}$`); createToken("GTLT", "((?:<|>)?=?)"); createToken("XRANGEIDENTIFIERLOOSE", `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`); createToken("XRANGEIDENTIFIER", `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`); createToken("XRANGEPLAIN", `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:${src[t.PRERELEASE]})?${src[t.BUILD]}?)?)?`); createToken("XRANGEPLAINLOOSE", `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:${src[t.PRERELEASELOOSE]})?${src[t.BUILD]}?)?)?`); createToken("XRANGE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`); createToken("XRANGELOOSE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`); createToken("COERCEPLAIN", `${"(^|[^\\d])(\\d{1,"}${MAX_SAFE_COMPONENT_LENGTH}})(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`); createToken("COERCE", `${src[t.COERCEPLAIN]}(?:$|[^\\d])`); createToken("COERCEFULL", src[t.COERCEPLAIN] + `(?:${src[t.PRERELEASE]})?(?:${src[t.BUILD]})?(?:$|[^\\d])`); createToken("COERCERTL", src[t.COERCE], true); createToken("COERCERTLFULL", src[t.COERCEFULL], true); createToken("LONETILDE", "(?:~>?)"); createToken("TILDETRIM", `(\\s*)${src[t.LONETILDE]}\\s+`, true); exports2.tildeTrimReplace = "$1~"; createToken("TILDE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`); createToken("TILDELOOSE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`); createToken("LONECARET", "(?:\\^)"); createToken("CARETTRIM", `(\\s*)${src[t.LONECARET]}\\s+`, true); exports2.caretTrimReplace = "$1^"; createToken("CARET", `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`); createToken("CARETLOOSE", `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`); createToken("COMPARATORLOOSE", `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`); createToken("COMPARATOR", `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`); createToken("COMPARATORTRIM", `(\\s*)${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true); exports2.comparatorTrimReplace = "$1$2$3"; createToken("HYPHENRANGE", `^\\s*(${src[t.XRANGEPLAIN]})\\s+-\\s+(${src[t.XRANGEPLAIN]})\\s*$`); createToken("HYPHENRANGELOOSE", `^\\s*(${src[t.XRANGEPLAINLOOSE]})\\s+-\\s+(${src[t.XRANGEPLAINLOOSE]})\\s*$`); createToken("STAR", "(<|>)?=?\\s*\\*"); createToken("GTE0", "^\\s*>=\\s*0\\.0\\.0\\s*$"); createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$"); } }); // node_modules/semver/internal/parse-options.js var require_parse_options = __commonJS({ "node_modules/semver/internal/parse-options.js"(exports2, module2) { "use strict"; var looseOption = Object.freeze({ loose: true }); var emptyOpts = Object.freeze({}); var parseOptions = (options) => { if (!options) { return emptyOpts; } if (typeof options !== "object") { return looseOption; } return options; }; module2.exports = parseOptions; } }); // node_modules/semver/internal/identifiers.js var require_identifiers = __commonJS({ "node_modules/semver/internal/identifiers.js"(exports2, module2) { "use strict"; var numeric = /^[0-9]+$/; var compareIdentifiers = (a, b2) => { if (typeof a === "number" && typeof b2 === "number") { return a === b2 ? 0 : a < b2 ? -1 : 1; } const anum = numeric.test(a); const bnum = numeric.test(b2); if (anum && bnum) { a = +a; b2 = +b2; } return a === b2 ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b2 ? -1 : 1; }; var rcompareIdentifiers = (a, b2) => compareIdentifiers(b2, a); module2.exports = { compareIdentifiers, rcompareIdentifiers }; } }); // node_modules/semver/classes/semver.js var require_semver = __commonJS({ "node_modules/semver/classes/semver.js"(exports2, module2) { "use strict"; var debug = require_debug(); var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants(); var { safeRe: re2, t } = require_re(); var parseOptions = require_parse_options(); var { compareIdentifiers } = require_identifiers(); var isPrereleaseIdentifier = (prerelease, identifier) => { const identifiers = identifier.split("."); if (identifiers.length > prerelease.length) { return false; } for (let i = 0; i < identifiers.length; i++) { if (compareIdentifiers(prerelease[i], identifiers[i]) !== 0) { return false; } } return true; }; var SemVer = class _SemVer { constructor(version2, options) { options = parseOptions(options); if (version2 instanceof _SemVer) { if (version2.loose === !!options.loose && version2.includePrerelease === !!options.includePrerelease) { return version2; } else { version2 = version2.version; } } else if (typeof version2 !== "string") { throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version2}".`); } if (version2.length > MAX_LENGTH) { throw new TypeError( `version is longer than ${MAX_LENGTH} characters` ); } debug("SemVer", version2, options); this.options = options; this.loose = !!options.loose; this.includePrerelease = !!options.includePrerelease; const m2 = version2.trim().match(options.loose ? re2[t.LOOSE] : re2[t.FULL]); if (!m2) { throw new TypeError(`Invalid Version: ${version2}`); } this.raw = version2; this.major = +m2[1]; this.minor = +m2[2]; this.patch = +m2[3]; if (this.major > MAX_SAFE_INTEGER || this.major < 0) { throw new TypeError("Invalid major version"); } if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) { throw new TypeError("Invalid minor version"); } if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) { throw new TypeError("Invalid patch version"); } if (!m2[4]) { this.prerelease = []; } else { this.prerelease = m2[4].split(".").map((id) => { if (/^[0-9]+$/.test(id)) { const num = +id; if (num >= 0 && num < MAX_SAFE_INTEGER) { return num; } } return id; }); } this.build = m2[5] ? m2[5].split(".") : []; this.format(); } format() { this.version = `${this.major}.${this.minor}.${this.patch}`; if (this.prerelease.length) { this.version += `-${this.prerelease.join(".")}`; } return this.version; } toString() { return this.version; } compare(other) { debug("SemVer.compare", this.version, this.options, other); if (!(other instanceof _SemVer)) { if (typeof other === "string" && other === this.version) { return 0; } other = new _SemVer(other, this.options); } if (other.version === this.version) { return 0; } return this.compareMain(other) || this.comparePre(other); } compareMain(other) { if (!(other instanceof _SemVer)) { other = new _SemVer(other, this.options); } if (this.major < other.major) { return -1; } if (this.major > other.major) { return 1; } if (this.minor < other.minor) { return -1; } if (this.minor > other.minor) { return 1; } if (this.patch < other.patch) { return -1; } if (this.patch > other.patch) { return 1; } return 0; } comparePre(other) { if (!(other instanceof _SemVer)) { other = new _SemVer(other, this.options); } if (this.prerelease.length && !other.prerelease.length) { return -1; } else if (!this.prerelease.length && other.prerelease.length) { return 1; } else if (!this.prerelease.length && !other.prerelease.length) { return 0; } let i = 0; do { const a = this.prerelease[i]; const b2 = other.prerelease[i]; debug("prerelease compare", i, a, b2); if (a === void 0 && b2 === void 0) { return 0; } else if (b2 === void 0) { return 1; } else if (a === void 0) { return -1; } else if (a === b2) { continue; } else { return compareIdentifiers(a, b2); } } while (++i); } compareBuild(other) { if (!(other instanceof _SemVer)) { other = new _SemVer(other, this.options); } let i = 0; do { const a = this.build[i]; const b2 = other.build[i]; debug("build compare", i, a, b2); if (a === void 0 && b2 === void 0) { return 0; } else if (b2 === void 0) { return 1; } else if (a === void 0) { return -1; } else if (a === b2) { continue; } else { return compareIdentifiers(a, b2); } } while (++i); } // preminor will bump the version up to the next minor release, and immediately // down to pre-release. premajor and prepatch work the same way. inc(release, identifier, identifierBase) { if (release.startsWith("pre")) { if (!identifier && identifierBase === false) { throw new Error("invalid increment argument: identifier is empty"); } if (identifier) { const match = `-${identifier}`.match(this.options.loose ? re2[t.PRERELEASELOOSE] : re2[t.PRERELEASE]); if (!match || match[1] !== identifier) { throw new Error(`invalid identifier: ${identifier}`); } } } switch (release) { case "premajor": this.prerelease.length = 0; this.patch = 0; this.minor = 0; this.major++; this.inc("pre", identifier, identifierBase); break; case "preminor": this.prerelease.length = 0; this.patch = 0; this.minor++; this.inc("pre", identifier, identifierBase); break; case "prepatch": this.prerelease.length = 0; this.inc("patch", identifier, identifierBase); this.inc("pre", identifier, identifierBase); break; // If the input is a non-prerelease version, this acts the same as // prepatch. case "prerelease": if (this.prerelease.length === 0) { this.inc("patch", identifier, identifierBase); } this.inc("pre", identifier, identifierBase); break; case "release": if (this.prerelease.length === 0) { throw new Error(`version ${this.raw} is not a prerelease`); } this.prerelease.length = 0; break; case "major": if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) { this.major++; } this.minor = 0; this.patch = 0; this.prerelease = []; break; case "minor": if (this.patch !== 0 || this.prerelease.length === 0) { this.minor++; } this.patch = 0; this.prerelease = []; break; case "patch": if (this.prerelease.length === 0) { this.patch++; } this.prerelease = []; break; // This probably shouldn't be used publicly. // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction. case "pre": { const base = Number(identifierBase) ? 1 : 0; if (this.prerelease.length === 0) { this.prerelease = [base]; } else { let i = this.prerelease.length; while (--i >= 0) { if (typeof this.prerelease[i] === "number") { this.prerelease[i]++; i = -2; } } if (i === -1) { if (identifier === this.prerelease.join(".") && identifierBase === false) { throw new Error("invalid increment argument: identifier already exists"); } this.prerelease.push(base); } } if (identifier) { let prerelease = [identifier, base]; if (identifierBase === false) { prerelease = [identifier]; } if (isPrereleaseIdentifier(this.prerelease, identifier)) { const prereleaseBase = this.prerelease[identifier.split(".").length]; if (isNaN(prereleaseBase)) { this.prerelease = prerelease; } } else { this.prerelease = prerelease; } } break; } default: throw new Error(`invalid increment argument: ${release}`); } this.raw = this.format(); if (this.build.length) { this.raw += `+${this.build.join(".")}`; } return this; } }; module2.exports = SemVer; } }); // node_modules/semver/functions/parse.js var require_parse = __commonJS({ "node_modules/semver/functions/parse.js"(exports2, module2) { "use strict"; var SemVer = require_semver(); var parse = (version2, options, throwErrors = false) => { if (version2 instanceof SemVer) { return version2; } try { return new SemVer(version2, options); } catch (er2) { if (!throwErrors) { return null; } throw er2; } }; module2.exports = parse; } }); // node_modules/semver/functions/valid.js var require_valid = __commonJS({ "node_modules/semver/functions/valid.js"(exports2, module2) { "use strict"; var parse = require_parse(); var valid = (version2, options) => { const v2 = parse(version2, options); return v2 ? v2.version : null; }; module2.exports = valid; } }); // node_modules/semver/functions/clean.js var require_clean = __commonJS({ "node_modules/semver/functions/clean.js"(exports2, module2) { "use strict"; var parse = require_parse(); var clean = (version2, options) => { const s3 = parse(version2.trim().replace(/^[=v]+/, ""), options); return s3 ? s3.version : null; }; module2.exports = clean; } }); // node_modules/semver/functions/inc.js var require_inc = __commonJS({ "node_modules/semver/functions/inc.js"(exports2, module2) { "use strict"; var SemVer = require_semver(); var inc = (version2, release, options, identifier, identifierBase) => { if (typeof options === "string") { identifierBase = identifier; identifier = options; options = void 0; } try { return new SemVer( version2 instanceof SemVer ? version2.version : version2, options ).inc(release, identifier, identifierBase).version; } catch (er2) { return null; } }; module2.exports = inc; } }); // node_modules/semver/functions/diff.js var require_diff = __commonJS({ "node_modules/semver/functions/diff.js"(exports2, module2) { "use strict"; var parse = require_parse(); var diff = (version1, version2) => { const v1 = parse(version1, null, true); const v2 = parse(version2, null, true); const comparison = v1.compare(v2); if (comparison === 0) { return null; } const v1Higher = comparison > 0; const highVersion = v1Higher ? v1 : v2; const lowVersion = v1Higher ? v2 : v1; const highHasPre = !!highVersion.prerelease.length; const lowHasPre = !!lowVersion.prerelease.length; if (lowHasPre && !highHasPre) { if (!lowVersion.patch && !lowVersion.minor) { return "major"; } if (lowVersion.compareMain(highVersion) === 0) { if (lowVersion.minor && !lowVersion.patch) { return "minor"; } return "patch"; } } const prefix = highHasPre ? "pre" : ""; if (v1.major !== v2.major) { return prefix + "major"; } if (v1.minor !== v2.minor) { return prefix + "minor"; } if (v1.patch !== v2.patch) { return prefix + "patch"; } return "prerelease"; }; module2.exports = diff; } }); // node_modules/semver/functions/major.js var require_major = __commonJS({ "node_modules/semver/functions/major.js"(exports2, module2) { "use strict"; var SemVer = require_semver(); var major = (a, loose) => new SemVer(a, loose).major; module2.exports = major; } }); // node_modules/semver/functions/minor.js var require_minor = __commonJS({ "node_modules/semver/functions/minor.js"(exports2, module2) { "use strict"; var SemVer = require_semver(); var minor = (a, loose) => new SemVer(a, loose).minor; module2.exports = minor; } }); // node_modules/semver/functions/patch.js var require_patch = __commonJS({ "node_modules/semver/functions/patch.js"(exports2, module2) { "use strict"; var SemVer = require_semver(); var patch = (a, loose) => new SemVer(a, loose).patch; module2.exports = patch; } }); // node_modules/semver/functions/prerelease.js var require_prerelease = __commonJS({ "node_modules/semver/functions/prerelease.js"(exports2, module2) { "use strict"; var parse = require_parse(); var prerelease = (version2, options) => { const parsed = parse(version2, options); return parsed && parsed.prerelease.length ? parsed.prerelease : null; }; module2.exports = prerelease; } }); // node_modules/semver/functions/compare.js var require_compare = __commonJS({ "node_modules/semver/functions/compare.js"(exports2, module2) { "use strict"; var SemVer = require_semver(); var compare = (a, b2, loose) => new SemVer(a, loose).compare(new SemVer(b2, loose)); module2.exports = compare; } }); // node_modules/semver/functions/rcompare.js var require_rcompare = __commonJS({ "node_modules/semver/functions/rcompare.js"(exports2, module2) { "use strict"; var compare = require_compare(); var rcompare = (a, b2, loose) => compare(b2, a, loose); module2.exports = rcompare; } }); // node_modules/semver/functions/compare-loose.js var require_compare_loose = __commonJS({ "node_modules/semver/functions/compare-loose.js"(exports2, module2) { "use strict"; var compare = require_compare(); var compareLoose = (a, b2) => compare(a, b2, true); module2.exports = compareLoose; } }); // node_modules/semver/functions/compare-build.js var require_compare_build = __commonJS({ "node_modules/semver/functions/compare-build.js"(exports2, module2) { "use strict"; var SemVer = require_semver(); var compareBuild = (a, b2, loose) => { const versionA = new SemVer(a, loose); const versionB = new SemVer(b2, loose); return versionA.compare(versionB) || versionA.compareBuild(versionB); }; module2.exports = compareBuild; } }); // node_modules/semver/functions/sort.js var require_sort = __commonJS({ "node_modules/semver/functions/sort.js"(exports2, module2) { "use strict"; var compareBuild = require_compare_build(); var sort = (list, loose) => list.sort((a, b2) => compareBuild(a, b2, loose)); module2.exports = sort; } }); // node_modules/semver/functions/rsort.js var require_rsort = __commonJS({ "node_modules/semver/functions/rsort.js"(exports2, module2) { "use strict"; var compareBuild = require_compare_build(); var rsort = (list, loose) => list.sort((a, b2) => compareBuild(b2, a, loose)); module2.exports = rsort; } }); // node_modules/semver/functions/gt.js var require_gt = __commonJS({ "node_modules/semver/functions/gt.js"(exports2, module2) { "use strict"; var compare = require_compare(); var gt2 = (a, b2, loose) => compare(a, b2, loose) > 0; module2.exports = gt2; } }); // node_modules/semver/functions/lt.js var require_lt = __commonJS({ "node_modules/semver/functions/lt.js"(exports2, module2) { "use strict"; var compare = require_compare(); var lt2 = (a, b2, loose) => compare(a, b2, loose) < 0; module2.exports = lt2; } }); // node_modules/semver/functions/eq.js var require_eq = __commonJS({ "node_modules/semver/functions/eq.js"(exports2, module2) { "use strict"; var compare = require_compare(); var eq = (a, b2, loose) => compare(a, b2, loose) === 0; module2.exports = eq; } }); // node_modules/semver/functions/neq.js var require_neq = __commonJS({ "node_modules/semver/functions/neq.js"(exports2, module2) { "use strict"; var compare = require_compare(); var neq = (a, b2, loose) => compare(a, b2, loose) !== 0; module2.exports = neq; } }); // node_modules/semver/functions/gte.js var require_gte = __commonJS({ "node_modules/semver/functions/gte.js"(exports2, module2) { "use strict"; var compare = require_compare(); var gte = (a, b2, loose) => compare(a, b2, loose) >= 0; module2.exports = gte; } }); // node_modules/semver/functions/lte.js var require_lte = __commonJS({ "node_modules/semver/functions/lte.js"(exports2, module2) { "use strict"; var compare = require_compare(); var lte = (a, b2, loose) => compare(a, b2, loose) <= 0; module2.exports = lte; } }); // node_modules/semver/functions/cmp.js var require_cmp = __commonJS({ "node_modules/semver/functions/cmp.js"(exports2, module2) { "use strict"; var eq = require_eq(); var neq = require_neq(); var gt2 = require_gt(); var gte = require_gte(); var lt2 = require_lt(); var lte = require_lte(); var cmp = (a, op, b2, loose) => { switch (op) { case "===": if (typeof a === "object") { a = a.version; } if (typeof b2 === "object") { b2 = b2.version; } return a === b2; case "!==": if (typeof a === "object") { a = a.version; } if (typeof b2 === "object") { b2 = b2.version; } return a !== b2; case "": case "=": case "==": return eq(a, b2, loose); case "!=": return neq(a, b2, loose); case ">": return gt2(a, b2, loose); case ">=": return gte(a, b2, loose); case "<": return lt2(a, b2, loose); case "<=": return lte(a, b2, loose); default: throw new TypeError(`Invalid operator: ${op}`); } }; module2.exports = cmp; } }); // node_modules/semver/functions/coerce.js var require_coerce = __commonJS({ "node_modules/semver/functions/coerce.js"(exports2, module2) { "use strict"; var SemVer = require_semver(); var parse = require_parse(); var { safeRe: re2, t } = require_re(); var coerce = (version2, options) => { if (version2 instanceof SemVer) { return version2; } if (typeof version2 === "number") { version2 = String(version2); } if (typeof version2 !== "string") { return null; } options = options || {}; let match = null; if (!options.rtl) { match = version2.match(options.includePrerelease ? re2[t.COERCEFULL] : re2[t.COERCE]); } else { const coerceRtlRegex = options.includePrerelease ? re2[t.COERCERTLFULL] : re2[t.COERCERTL]; let next; while ((next = coerceRtlRegex.exec(version2)) && (!match || match.index + match[0].length !== version2.length)) { if (!match || next.index + next[0].length !== match.index + match[0].length) { match = next; } coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length; } coerceRtlRegex.lastIndex = -1; } if (match === null) { return null; } const major = match[2]; const minor = match[3] || "0"; const patch = match[4] || "0"; const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : ""; const build = options.includePrerelease && match[6] ? `+${match[6]}` : ""; return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options); }; module2.exports = coerce; } }); // node_modules/semver/functions/truncate.js var require_truncate = __commonJS({ "node_modules/semver/functions/truncate.js"(exports2, module2) { "use strict"; var parse = require_parse(); var constants = require_constants(); var SemVer = require_semver(); var truncate = (version2, truncation, options) => { if (!constants.RELEASE_TYPES.includes(truncation)) { return null; } const clonedVersion = cloneInputVersion(version2, options); return clonedVersion && doTruncation(clonedVersion, truncation); }; var cloneInputVersion = (version2, options) => { const versionStringToParse = version2 instanceof SemVer ? version2.version : version2; return parse(versionStringToParse, options); }; var doTruncation = (version2, truncation) => { if (isPrerelease(truncation)) { return version2.version; } version2.prerelease = []; switch (truncation) { case "major": version2.minor = 0; version2.patch = 0; break; case "minor": version2.patch = 0; break; } return version2.format(); }; var isPrerelease = (type) => { return type.startsWith("pre"); }; module2.exports = truncate; } }); // node_modules/semver/internal/lrucache.js var require_lrucache = __commonJS({ "node_modules/semver/internal/lrucache.js"(exports2, module2) { "use strict"; var LRUCache = class { constructor() { this.max = 1e3; this.map = /* @__PURE__ */ new Map(); } get(key) { const value = this.map.get(key); if (value === void 0) { return void 0; } else { this.map.delete(key); this.map.set(key, value); return value; } } delete(key) { return this.map.delete(key); } set(key, value) { const deleted = this.delete(key); if (!deleted && value !== void 0) { if (this.map.size >= this.max) { const firstKey = this.map.keys().next().value; this.delete(firstKey); } this.map.set(key, value); } return this; } }; module2.exports = LRUCache; } }); // node_modules/semver/internal/trim-comparator-whitespace.js var require_trim_comparator_whitespace = __commonJS({ "node_modules/semver/internal/trim-comparator-whitespace.js"(exports2, module2) { "use strict"; var { MAX_LENGTH, MAX_SAFE_BUILD_LENGTH, WHITESPACE_CHARACTERS } = require_constants(); var whitespace = new Uint8Array(65536); for (const char of WHITESPACE_CHARACTERS) { whitespace[char.charCodeAt(0)] = 1; } var isWhitespace = (char) => char !== void 0 && whitespace[char.charCodeAt(0)] === 1; var isVersionPrefix = (char) => char === "v" || char === "=" || isWhitespace(char); var isDigit = (char) => char !== void 0 && char >= "0" && char <= "9"; var isLetter = (char) => char !== void 0 && (char >= "a" && char <= "z" || char >= "A" && char <= "Z"); var isIdentifierCharacter = (char) => isDigit(char) || isLetter(char) || char === "-"; var isVersionStart = (char) => isDigit(char) || char === "x" || char === "X" || char === "*"; var findDigitsEndIndex = (range, start, limit, digitRuns) => { if (!isDigit(range[start])) { return start; } if (start >= digitRuns.start && start < digitRuns.end) { return Math.min(start + limit, digitRuns.end); } if (start >= digitRuns.previousStart && start < digitRuns.previousEnd) { return Math.min(start + limit, digitRuns.previousEnd); } let end = start + 1; while (isDigit(range[end])) { end++; } digitRuns.previousStart = digitRuns.start; digitRuns.previousEnd = digitRuns.end; digitRuns.start = start; digitRuns.end = end; return Math.min(start + limit, end); }; var findVersionNumberEndIndex = (range, start, loose, digitRuns) => { if (!loose && range[start] === "0") { return start + 1; } return findDigitsEndIndex(range, start, loose ? MAX_LENGTH : MAX_LENGTH + 1, digitRuns); }; var findPrereleaseIdentifierEndIndex = (range, start, loose, digitRuns) => { const digitsEnd = findDigitsEndIndex(range, start, MAX_LENGTH, digitRuns); if (isLetter(range[digitsEnd]) || range[digitsEnd] === "-") { let end = digitsEnd + 1; const limit = end + MAX_SAFE_BUILD_LENGTH; while (end < limit && isIdentifierCharacter(range[end])) { end++; } return end; } return findVersionNumberEndIndex(range, start, loose, digitRuns); }; var findPrereleaseEndIndex = (range, start, loose, digitRuns) => { const hyphen = range[start] === "-"; if (!loose && !hyphen) { return start; } const identifierStart = start + (hyphen ? 1 : 0); let end = findPrereleaseIdentifierEndIndex(range, identifierStart, loose, digitRuns); if (end === identifierStart) { if (!loose || !hyphen) { return start; } end = findPrereleaseIdentifierEndIndex(range, start, loose, digitRuns); } while (range[end] === ".") { const next = findPrereleaseIdentifierEndIndex(range, end + 1, loose, digitRuns); if (next === end + 1) { break; } end = next; } return end; }; var findBuildIdentifierEndIndex = (range, start) => { let end = start; while (end - start < MAX_SAFE_BUILD_LENGTH && isIdentifierCharacter(range[end])) { end++; } return end; }; var findBuildEndIndex = (range, start) => { if (range[start] !== "+") { return start; } let end = findBuildIdentifierEndIndex(range, start + 1); if (end === start + 1) { return start; } while (range[end] === ".") { const next = findBuildIdentifierEndIndex(range, end + 1); if (next === end + 1) { break; } end = next; } return end; }; var findLooseFullVersionEndIndex = (range, start, digitRuns) => { let end = start; for (let component = 0; component < 3; component++) { const next = findVersionNumberEndIndex(range, end, true, digitRuns); if (next === end) { return start; } end = next; if (component < 2) { if (range[end] !== ".") { return start; } end++; } } const prereleaseEnd = findPrereleaseEndIndex(range, end, true, digitRuns); return findBuildEndIndex(range, prereleaseEnd); }; var findPartialVersionComponentEndIndex = (range, start, digitRuns) => { if (isDigit(range[start])) { return findVersionNumberEndIndex(range, start, false, digitRuns); } return isVersionStart(range[start]) ? start + 1 : start; }; var findPartialVersionEndIndex = (range, start, digitRuns) => { let end = findPartialVersionComponentEndIndex(range, start, digitRuns); for (let component = 0; component < 2; component++) { if (range[end] !== ".") { return end; } const next = findPartialVersionComponentEndIndex(range, end + 1, digitRuns); if (next === end + 1) { return end; } end = next; } const prereleaseEnd = findPrereleaseEndIndex(range, end, false, digitRuns); return findBuildEndIndex(range, prereleaseEnd); }; var findVersionEndIndex = (range, start, digitRuns) => { const fullVersionEnd = findLooseFullVersionEndIndex(range, start, digitRuns); return fullVersionEnd !== start ? fullVersionEnd : findPartialVersionEndIndex(range, start, digitRuns); }; var findRemovableWhitespaceIndex = (range, matchStart) => { let position = matchStart; if (isWhitespace(range[position])) { position++; } if (range[position] === "<" || range[position] === ">") { position++; } if (range[position] === "=") { position++; } return isWhitespace(range[position]) ? position : -1; }; var trimComparatorWhitespace = (range) => { let result = ""; let copyFrom = 0; let cursor = 0; const digitRuns = { start: -1, end: -1, previousStart: -1, previousEnd: -1 }; while (cursor < range.length) { const matchStart = cursor; if (range[cursor] === "<" || range[cursor] === ">") { cursor++; } else if (!isVersionPrefix(range[cursor]) && !isVersionStart(range[cursor])) { cursor++; continue; } while (cursor < range.length && isVersionPrefix(range[cursor])) { cursor++; } if (!isVersionStart(range[cursor])) { continue; } const whitespacePosition = findRemovableWhitespaceIndex(range, matchStart); if (whitespacePosition !== -1) { result += range.slice(copyFrom, whitespacePosition); copyFrom = whitespacePosition + 1; } cursor = findVersionEndIndex(range, cursor, digitRuns); } return result + range.slice(copyFrom); }; module2.exports = trimComparatorWhitespace; } }); // node_modules/semver/classes/range.js var require_range = __commonJS({ "node_modules/semver/classes/range.js"(exports2, module2) { "use strict"; var SPACE_CHARACTERS = /\s+/g; var Range = class _Range { constructor(range, options) { options = parseOptions(options); if (range instanceof _Range) { if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) { return range; } else { return new _Range(range.raw, options); } } if (range instanceof Comparator) { this.raw = range.value; this.set = [[range]]; this.formatted = void 0; return this; } this.options = options; this.loose = !!options.loose; this.includePrerelease = !!options.includePrerelease; this.raw = range.trim().replace(SPACE_CHARACTERS, " "); this.set = this.raw.split("||").map((r) => this.parseRange(r.trim())).filter((c) => c.length); if (!this.set.length) { throw new TypeError(`Invalid SemVer Range: ${this.raw}`); } if (this.set.length > 1) { const first = this.set[0]; this.set = this.set.filter((c) => !isNullSet(c[0])); if (this.set.length === 0) { this.set = [first]; } else if (this.set.length > 1) { for (const c of this.set) { if (c.length === 1 && isAny(c[0])) { this.set = [c]; break; } } } } this.formatted = void 0; } get range() { if (this.formatted === void 0) { this.formatted = ""; for (let i = 0; i < this.set.length; i++) { if (i > 0) { this.formatted += "||"; } const comps = this.set[i]; for (let k2 = 0; k2 < comps.length; k2++) { if (k2 > 0) { this.formatted += " "; } this.formatted += comps[k2].toString().trim(); } } } return this.formatted; } format() { return this.range; } toString() { return this.range; } parseRange(range) { range = range.replace(BUILDSTRIPRE, ""); const memoOpts = (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | (this.options.loose && FLAG_LOOSE); const memoKey = memoOpts + ":" + range; const cached = cache.get(memoKey); if (cached) { return cached; } const loose = this.options.loose; const hr2 = loose ? re2[t.HYPHENRANGELOOSE] : re2[t.HYPHENRANGE]; range = range.replace(hr2, hyphenReplace(this.options.includePrerelease)); debug("hyphen replace", range); range = trimComparatorWhitespace(range); debug("comparator trim", range); range = range.replace(re2[t.TILDETRIM], tildeTrimReplace); debug("tilde trim", range); range = range.replace(re2[t.CARETTRIM], caretTrimReplace); debug("caret trim", range); let rangeList = range.split(" ").map((comp) => parseComparator(comp, this.options)).join(" ").split(/\s+/).map((comp) => replaceGTE0(comp, this.options)); if (loose) { rangeList = rangeList.filter((comp) => { debug("loose invalid filter", comp, this.options); return !!comp.match(re2[t.COMPARATORLOOSE]); }); } debug("range list", rangeList); const rangeMap = /* @__PURE__ */ new Map(); const comparators = rangeList.map((comp) => new Comparator(comp, this.options)); for (const comp of comparators) { if (isNullSet(comp)) { return [comp]; } rangeMap.set(comp.value, comp); } if (rangeMap.size > 1 && rangeMap.has("")) { rangeMap.delete(""); } const result = [...rangeMap.values()]; cache.set(memoKey, result); return result; } intersects(range, options) { if (!(range instanceof _Range)) { throw new TypeError("a Range is required"); } return this.set.some((thisComparators) => { return isSatisfiable(thisComparators, options) && range.set.some((rangeComparators) => { return isSatisfiable(rangeComparators, options) && thisComparators.every((thisComparator) => { return rangeComparators.every((rangeComparator) => { return thisComparator.intersects(rangeComparator, options); }); }); }); }); } // if ANY of the sets match ALL of its comparators, then pass test(version2) { if (!version2) { return false; } if (typeof version2 === "string") { try { version2 = new SemVer(version2, this.options); } catch (er2) { return false; } } for (let i = 0; i < this.set.length; i++) { if (testSet(this.set[i], version2, this.options)) { return true; } } return false; } }; module2.exports = Range; var LRU = require_lrucache(); var cache = new LRU(); var parseOptions = require_parse_options(); var Comparator = require_comparator(); var debug = require_debug(); var SemVer = require_semver(); var trimComparatorWhitespace = require_trim_comparator_whitespace(); var { safeRe: re2, src, t, tildeTrimReplace, caretTrimReplace } = require_re(); var { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require_constants(); var BUILDSTRIPRE = new RegExp(src[t.BUILD], "g"); var isNullSet = (c) => c.value === "<0.0.0-0"; var isAny = (c) => c.value === ""; var isSatisfiable = (comparators, options) => { let result = true; const remainingComparators = comparators.slice(); let testComparator = remainingComparators.pop(); while (result && remainingComparators.length) { result = remainingComparators.every((otherComparator) => { return testComparator.intersects(otherComparator, options); }); testComparator = remainingComparators.pop(); } return result; }; var parseComparator = (comp, options) => { comp = comp.replace(re2[t.BUILD], ""); debug("comp", comp, options); comp = replaceCarets(comp, options); debug("caret", comp); comp = replaceTildes(comp, options); debug("tildes", comp); comp = replaceXRanges(comp, options); debug("xrange", comp); comp = replaceStars(comp, options); debug("stars", comp); return comp; }; var isX = (id) => !id || id.toLowerCase() === "x" || id === "*"; var invalidXRangeOrder = (M2, m2, p2) => isX(M2) && !isX(m2) || isX(m2) && p2 && !isX(p2); var replaceTildes = (comp, options) => { return comp.trim().split(/\s+/).map((c) => replaceTilde(c, options)).join(" "); }; var replaceTilde = (comp, options) => { const r = options.loose ? re2[t.TILDELOOSE] : re2[t.TILDE]; const z2 = options.includePrerelease ? "-0" : ""; return comp.replace(r, (_2, M2, m2, p2, pr2) => { debug("tilde", comp, _2, M2, m2, p2, pr2); let ret; if (isX(M2)) { ret = ""; } else if (isX(m2)) { ret = `>=${M2}.0.0${z2} <${+M2 + 1}.0.0-0`; } else if (isX(p2)) { ret = `>=${M2}.${m2}.0${z2} <${M2}.${+m2 + 1}.0-0`; } else if (pr2) { debug("replaceTilde pr", pr2); ret = `>=${M2}.${m2}.${p2}-${pr2} <${M2}.${+m2 + 1}.0-0`; } else { ret = `>=${M2}.${m2}.${p2} <${M2}.${+m2 + 1}.0-0`; } debug("tilde return", ret); return ret; }); }; var replaceCarets = (comp, options) => { return comp.trim().split(/\s+/).map((c) => replaceCaret(c, options)).join(" "); }; var replaceCaret = (comp, options) => { debug("caret", comp, options); const r = options.loose ? re2[t.CARETLOOSE] : re2[t.CARET]; const z2 = options.includePrerelease ? "-0" : ""; return comp.replace(r, (_2, M2, m2, p2, pr2) => { debug("caret", comp, _2, M2, m2, p2, pr2); let ret; if (isX(M2)) { ret = ""; } else if (isX(m2)) { ret = `>=${M2}.0.0${z2} <${+M2 + 1}.0.0-0`; } else if (isX(p2)) { if (M2 === "0") { ret = `>=${M2}.${m2}.0${z2} <${M2}.${+m2 + 1}.0-0`; } else { ret = `>=${M2}.${m2}.0${z2} <${+M2 + 1}.0.0-0`; } } else if (pr2) { debug("replaceCaret pr", pr2); if (M2 === "0") { if (m2 === "0") { ret = `>=${M2}.${m2}.${p2}-${pr2} <${M2}.${m2}.${+p2 + 1}-0`; } else { ret = `>=${M2}.${m2}.${p2}-${pr2} <${M2}.${+m2 + 1}.0-0`; } } else { ret = `>=${M2}.${m2}.${p2}-${pr2} <${+M2 + 1}.0.0-0`; } } else { debug("no pr"); if (M2 === "0") { if (m2 === "0") { ret = `>=${M2}.${m2}.${p2} <${M2}.${m2}.${+p2 + 1}-0`; } else { ret = `>=${M2}.${m2}.${p2} <${M2}.${+m2 + 1}.0-0`; } } else { ret = `>=${M2}.${m2}.${p2} <${+M2 + 1}.0.0-0`; } } debug("caret return", ret); return ret; }); }; var replaceXRanges = (comp, options) => { debug("replaceXRanges", comp, options); return comp.split(/\s+/).map((c) => replaceXRange(c, options)).join(" "); }; var replaceXRange = (comp, options) => { comp = comp.trim(); const r = options.loose ? re2[t.XRANGELOOSE] : re2[t.XRANGE]; return comp.replace(r, (ret, gtlt, M2, m2, p2, pr2) => { debug("xRange", comp, ret, gtlt, M2, m2, p2, pr2); if (invalidXRangeOrder(M2, m2, p2)) { return comp; } const xM = isX(M2); const xm = xM || isX(m2); const xp = xm || isX(p2); const anyX = xp; if (gtlt === "=" && anyX) { gtlt = ""; } pr2 = options.includePrerelease ? "-0" : ""; if (xM) { if (gtlt === ">" || gtlt === "<") { ret = "<0.0.0-0"; } else { ret = "*"; } } else if (gtlt && anyX) { if (xm) { m2 = 0; } p2 = 0; if (gtlt === ">") { gtlt = ">="; if (xm) { M2 = +M2 + 1; m2 = 0; p2 = 0; } else { m2 = +m2 + 1; p2 = 0; } } else if (gtlt === "<=") { gtlt = "<"; if (xm) { M2 = +M2 + 1; } else { m2 = +m2 + 1; } } if (gtlt === "<") { pr2 = "-0"; } ret = `${gtlt + M2}.${m2}.${p2}${pr2}`; } else if (xm) { ret = `>=${M2}.0.0${pr2} <${+M2 + 1}.0.0-0`; } else if (xp) { ret = `>=${M2}.${m2}.0${pr2} <${M2}.${+m2 + 1}.0-0`; } debug("xRange return", ret); return ret; }); }; var replaceStars = (comp, options) => { debug("replaceStars", comp, options); return comp.trim().replace(re2[t.STAR], ""); }; var replaceGTE0 = (comp, options) => { debug("replaceGTE0", comp, options); return comp.trim().replace(re2[options.includePrerelease ? t.GTE0PRE : t.GTE0], ""); }; var hyphenReplace = (incPr) => ($0, from, fM, fm, fp, fpr, fb, to2, tM, tm, tp, tpr) => { if (isX(fM)) { from = ""; } else if (isX(fm)) { from = `>=${fM}.0.0${incPr ? "-0" : ""}`; } else if (isX(fp)) { from = `>=${fM}.${fm}.0${incPr ? "-0" : ""}`; } else if (fpr) { from = `>=${from}`; } else { from = `>=${from}${incPr ? "-0" : ""}`; } if (isX(tM)) { to2 = ""; } else if (isX(tm)) { to2 = `<${+tM + 1}.0.0-0`; } else if (isX(tp)) { to2 = `<${tM}.${+tm + 1}.0-0`; } else if (tpr) { to2 = `<=${tM}.${tm}.${tp}-${tpr}`; } else if (incPr) { to2 = `<${tM}.${tm}.${+tp + 1}-0`; } else { to2 = `<=${to2}`; } return `${from} ${to2}`.trim(); }; var testSet = (set, version2, options) => { for (let i = 0; i < set.length; i++) { if (!set[i].test(version2)) { return false; } } if (version2.prerelease.length && !options.includePrerelease) { for (let i = 0; i < set.length; i++) { debug(set[i].semver); if (set[i].semver === Comparator.ANY) { continue; } if (set[i].semver.prerelease.length > 0) { const allowed = set[i].semver; if (allowed.major === version2.major && allowed.minor === version2.minor && allowed.patch === version2.patch) { return true; } } } return false; } return true; }; } }); // node_modules/semver/classes/comparator.js var require_comparator = __commonJS({ "node_modules/semver/classes/comparator.js"(exports2, module2) { "use strict"; var ANY = /* @__PURE__ */ Symbol("SemVer ANY"); var Comparator = class _Comparator { static get ANY() { return ANY; } constructor(comp, options) { options = parseOptions(options); if (comp instanceof _Comparator) { if (comp.loose === !!options.loose) { return comp; } else { comp = comp.value; } } comp = comp.trim().split(/\s+/).join(" "); debug("comparator", comp, options); this.options = options; this.loose = !!options.loose; this.parse(comp); if (this.semver === ANY) { this.value = ""; } else { this.value = this.operator + this.semver.version; } debug("comp", this); } parse(comp) { const r = this.options.loose ? re2[t.COMPARATORLOOSE] : re2[t.COMPARATOR]; const m2 = comp.match(r); if (!m2) { throw new TypeError(`Invalid comparator: ${comp}`); } this.operator = m2[1] !== void 0 ? m2[1] : ""; if (this.operator === "=") { this.operator = ""; } if (!m2[2]) { this.semver = ANY; } else { this.semver = new SemVer(m2[2], this.options.loose); } } toString() { return this.value; } test(version2) { debug("Comparator.test", version2, this.options.loose); if (this.semver === ANY || version2 === ANY) { return true; } if (typeof version2 === "string") { try { version2 = new SemVer(version2, this.options); } catch (er2) { return false; } } return cmp(version2, this.operator, this.semver, this.options); } intersects(comp, options) { if (!(comp instanceof _Comparator)) { throw new TypeError("a Comparator is required"); } if (this.operator === "") { if (this.value === "") { return true; } return new Range(comp.value, options).test(this.value); } else if (comp.operator === "") { if (comp.value === "") { return true; } return new Range(this.value, options).test(comp.semver); } options = parseOptions(options); if (options.includePrerelease && (this.value === "<0.0.0-0" || comp.value === "<0.0.0-0")) { return false; } if (!options.includePrerelease && (this.value.startsWith("<0.0.0") || comp.value.startsWith("<0.0.0"))) { return false; } if (this.operator.startsWith(">") && comp.operator.startsWith(">")) { return true; } if (this.operator.startsWith("<") && comp.operator.startsWith("<")) { return true; } if (this.semver.version === comp.semver.version && this.operator.includes("=") && comp.operator.includes("=")) { return true; } if (cmp(this.semver, "<", comp.semver, options) && this.operator.startsWith(">") && comp.operator.startsWith("<")) { return true; } if (cmp(this.semver, ">", comp.semver, options) && this.operator.startsWith("<") && comp.operator.startsWith(">")) { return true; } return false; } }; module2.exports = Comparator; var parseOptions = require_parse_options(); var { safeRe: re2, t } = require_re(); var cmp = require_cmp(); var debug = require_debug(); var SemVer = require_semver(); var Range = require_range(); } }); // node_modules/semver/functions/satisfies.js var require_satisfies = __commonJS({ "node_modules/semver/functions/satisfies.js"(exports2, module2) { "use strict"; var Range = require_range(); var satisfies = (version2, range, options) => { try { range = new Range(range, options); } catch (er2) { return false; } return range.test(version2); }; module2.exports = satisfies; } }); // node_modules/semver/ranges/to-comparators.js var require_to_comparators = __commonJS({ "node_modules/semver/ranges/to-comparators.js"(exports2, module2) { "use strict"; var Range = require_range(); var toComparators = (range, options) => new Range(range, options).set.map((comp) => comp.map((c) => c.value).join(" ").trim().split(" ")); module2.exports = toComparators; } }); // node_modules/semver/ranges/max-satisfying.js var require_max_satisfying = __commonJS({ "node_modules/semver/ranges/max-satisfying.js"(exports2, module2) { "use strict"; var SemVer = require_semver(); var Range = require_range(); var maxSatisfying = (versions, range, options) => { let max = null; let maxSV = null; let rangeObj = null; try { rangeObj = new Range(range, options); } catch (er2) { return null; } versions.forEach((v2) => { if (rangeObj.test(v2)) { if (!max || maxSV.compare(v2) === -1) { max = v2; maxSV = new SemVer(max, options); } } }); return max; }; module2.exports = maxSatisfying; } }); // node_modules/semver/ranges/min-satisfying.js var require_min_satisfying = __commonJS({ "node_modules/semver/ranges/min-satisfying.js"(exports2, module2) { "use strict"; var SemVer = require_semver(); var Range = require_range(); var minSatisfying = (versions, range, options) => { let min = null; let minSV = null; let rangeObj = null; try { rangeObj = new Range(range, options); } catch (er2) { return null; } versions.forEach((v2) => { if (rangeObj.test(v2)) { if (!min || minSV.compare(v2) === 1) { min = v2; minSV = new SemVer(min, options); } } }); return min; }; module2.exports = minSatisfying; } }); // node_modules/semver/ranges/min-version.js var require_min_version = __commonJS({ "node_modules/semver/ranges/min-version.js"(exports2, module2) { "use strict"; var SemVer = require_semver(); var Range = require_range(); var gt2 = require_gt(); var minVersion = (range, loose) => { range = new Range(range, loose); let minver = new SemVer("0.0.0"); if (range.test(minver)) { return minver; } minver = new SemVer("0.0.0-0"); if (range.test(minver)) { return minver; } minver = null; for (let i = 0; i < range.set.length; ++i) { const comparators = range.set[i]; let setMin = null; comparators.forEach((comparator) => { const compver = new SemVer(comparator.semver.version); switch (comparator.operator) { case ">": if (compver.prerelease.length === 0) { compver.patch++; } else { compver.prerelease.push(0); } compver.raw = compver.format(); /* fallthrough */ case "": case ">=": if (!setMin || gt2(compver, setMin)) { setMin = compver; } break; case "<": case "<=": break; /* istanbul ignore next */ default: throw new Error(`Unexpected operation: ${comparator.operator}`); } }); if (setMin && (!minver || gt2(minver, setMin))) { minver = setMin; } } if (minver && range.test(minver)) { return minver; } return null; }; module2.exports = minVersion; } }); // node_modules/semver/ranges/valid.js var require_valid2 = __commonJS({ "node_modules/semver/ranges/valid.js"(exports2, module2) { "use strict"; var Range = require_range(); var validRange = (range, options) => { try { return new Range(range, options).range || "*"; } catch (er2) { return null; } }; module2.exports = validRange; } }); // node_modules/semver/ranges/outside.js var require_outside = __commonJS({ "node_modules/semver/ranges/outside.js"(exports2, module2) { "use strict"; var SemVer = require_semver(); var Comparator = require_comparator(); var { ANY } = Comparator; var Range = require_range(); var satisfies = require_satisfies(); var gt2 = require_gt(); var lt2 = require_lt(); var lte = require_lte(); var gte = require_gte(); var outside = (version2, range, hilo, options) => { version2 = new SemVer(version2, options); range = new Range(range, options); let gtfn, ltefn, ltfn, comp, ecomp; switch (hilo) { case ">": gtfn = gt2; ltefn = lte; ltfn = lt2; comp = ">"; ecomp = ">="; break; case "<": gtfn = lt2; ltefn = gte; ltfn = gt2; comp = "<"; ecomp = "<="; break; default: throw new TypeError('Must provide a hilo val of "<" or ">"'); } if (satisfies(version2, range, options)) { return false; } for (let i = 0; i < range.set.length; ++i) { const comparators = range.set[i]; let high = null; let low = null; comparators.forEach((comparator) => { if (comparator.semver === ANY) { comparator = new Comparator(">=0.0.0"); } high = high || comparator; low = low || comparator; if (gtfn(comparator.semver, high.semver, options)) { high = comparator; } else if (ltfn(comparator.semver, low.semver, options)) { low = comparator; } }); if (high.operator === comp || high.operator === ecomp) { return false; } if ((!low.operator || low.operator === comp) && ltefn(version2, low.semver)) { return false; } else if (low.operator === ecomp && ltfn(version2, low.semver)) { return false; } } return true; }; module2.exports = outside; } }); // node_modules/semver/ranges/gtr.js var require_gtr = __commonJS({ "node_modules/semver/ranges/gtr.js"(exports2, module2) { "use strict"; var outside = require_outside(); var gtr = (version2, range, options) => outside(version2, range, ">", options); module2.exports = gtr; } }); // node_modules/semver/ranges/ltr.js var require_ltr = __commonJS({ "node_modules/semver/ranges/ltr.js"(exports2, module2) { "use strict"; var outside = require_outside(); var ltr = (version2, range, options) => outside(version2, range, "<", options); module2.exports = ltr; } }); // node_modules/semver/ranges/intersects.js var require_intersects = __commonJS({ "node_modules/semver/ranges/intersects.js"(exports2, module2) { "use strict"; var Range = require_range(); var intersects = (r1, r2, options) => { r1 = new Range(r1, options); r2 = new Range(r2, options); return r1.intersects(r2, options); }; module2.exports = intersects; } }); // node_modules/semver/ranges/simplify.js var require_simplify = __commonJS({ "node_modules/semver/ranges/simplify.js"(exports2, module2) { "use strict"; var satisfies = require_satisfies(); var compare = require_compare(); module2.exports = (versions, range, options) => { const set = []; let first = null; let prev = null; const v2 = versions.sort((a, b2) => compare(a, b2, options)); for (const version2 of v2) { const included = satisfies(version2, range, options); if (included) { prev = version2; if (!first) { first = version2; } } else { if (prev) { set.push([first, prev]); } prev = null; first = null; } } if (first) { set.push([first, null]); } const ranges = []; for (const [min, max] of set) { if (min === max) { ranges.push(min); } else if (!max && min === v2[0]) { ranges.push("*"); } else if (!max) { ranges.push(`>=${min}`); } else if (min === v2[0]) { ranges.push(`<=${max}`); } else { ranges.push(`${min} - ${max}`); } } const simplified = ranges.join(" || "); const original = typeof range.raw === "string" ? range.raw : String(range); return simplified.length < original.length ? simplified : range; }; } }); // node_modules/semver/ranges/subset.js var require_subset = __commonJS({ "node_modules/semver/ranges/subset.js"(exports2, module2) { "use strict"; var Range = require_range(); var Comparator = require_comparator(); var { ANY } = Comparator; var satisfies = require_satisfies(); var compare = require_compare(); var subset = (sub, dom, options = {}) => { if (sub === dom) { return true; } sub = new Range(sub, options); dom = new Range(dom, options); let sawNonNull = false; OUTER: for (const simpleSub of sub.set) { for (const simpleDom of dom.set) { const isSub = simpleSubset(simpleSub, simpleDom, options); sawNonNull = sawNonNull || isSub !== null; if (isSub) { continue OUTER; } } if (sawNonNull) { return false; } } return true; }; var minimumVersionWithPreRelease = [new Comparator(">=0.0.0-0")]; var minimumVersion = [new Comparator(">=0.0.0")]; var simpleSubset = (sub, dom, options) => { if (sub === dom) { return true; } if (sub.length === 1 && sub[0].semver === ANY) { if (dom.length === 1 && dom[0].semver === ANY) { return true; } else if (options.includePrerelease) { sub = minimumVersionWithPreRelease; } else { sub = minimumVersion; } } if (dom.length === 1 && dom[0].semver === ANY) { if (options.includePrerelease) { return true; } else { dom = minimumVersion; } } const eqSet = /* @__PURE__ */ new Set(); let gt2, lt2; for (const c of sub) { if (c.operator === ">" || c.operator === ">=") { gt2 = higherGT(gt2, c, options); } else if (c.operator === "<" || c.operator === "<=") { lt2 = lowerLT(lt2, c, options); } else { eqSet.add(c.semver); } } if (eqSet.size > 1) { return null; } let gtltComp; if (gt2 && lt2) { gtltComp = compare(gt2.semver, lt2.semver, options); if (gtltComp > 0) { return null; } else if (gtltComp === 0 && (gt2.operator !== ">=" || lt2.operator !== "<=")) { return null; } } for (const eq of eqSet) { if (gt2 && !satisfies(eq, String(gt2), options)) { return null; } if (lt2 && !satisfies(eq, String(lt2), options)) { return null; } for (const c of dom) { if (!satisfies(eq, String(c), options)) { return false; } } return true; } let higher, lower; let hasDomLT, hasDomGT; let needDomLTPre = lt2 && !options.includePrerelease && lt2.semver.prerelease.length ? lt2.semver : false; let needDomGTPre = gt2 && !options.includePrerelease && gt2.semver.prerelease.length ? gt2.semver : false; if (needDomLTPre && needDomLTPre.prerelease.length === 1 && lt2.operator === "<" && needDomLTPre.prerelease[0] === 0) { needDomLTPre = false; } for (const c of dom) { hasDomGT = hasDomGT || c.operator === ">" || c.operator === ">="; hasDomLT = hasDomLT || c.operator === "<" || c.operator === "<="; if (gt2) { if (needDomGTPre) { if (c.semver.prerelease && c.semver.prerelease.length && c.semver.major === needDomGTPre.major && c.semver.minor === needDomGTPre.minor && c.semver.patch === needDomGTPre.patch) { needDomGTPre = false; } } if (c.operator === ">" || c.operator === ">=") { higher = higherGT(gt2, c, options); if (higher === c && higher !== gt2) { return false; } } else if (gt2.operator === ">=" && !c.test(gt2.semver)) { return false; } } if (lt2) { if (needDomLTPre) { if (c.semver.prerelease && c.semver.prerelease.length && c.semver.major === needDomLTPre.major && c.semver.minor === needDomLTPre.minor && c.semver.patch === needDomLTPre.patch) { needDomLTPre = false; } } if (c.operator === "<" || c.operator === "<=") { lower = lowerLT(lt2, c, options); if (lower === c && lower !== lt2) { return false; } } else if (lt2.operator === "<=" && !c.test(lt2.semver)) { return false; } } if (!c.operator && (lt2 || gt2) && gtltComp !== 0) { return false; } } if (gt2 && hasDomLT && !lt2 && gtltComp !== 0) { return false; } if (lt2 && hasDomGT && !gt2 && gtltComp !== 0) { return false; } if (needDomGTPre || needDomLTPre) { return false; } return true; }; var higherGT = (a, b2, options) => { if (!a) { return b2; } const comp = compare(a.semver, b2.semver, options); return comp > 0 ? a : comp < 0 ? b2 : b2.operator === ">" && a.operator === ">=" ? b2 : a; }; var lowerLT = (a, b2, options) => { if (!a) { return b2; } const comp = compare(a.semver, b2.semver, options); return comp < 0 ? a : comp > 0 ? b2 : b2.operator === "<" && a.operator === "<=" ? b2 : a; }; module2.exports = subset; } }); // node_modules/semver/index.js var require_semver2 = __commonJS({ "node_modules/semver/index.js"(exports2, module2) { "use strict"; var internalRe = require_re(); var constants = require_constants(); var SemVer = require_semver(); var identifiers = require_identifiers(); var parse = require_parse(); var valid = require_valid(); var clean = require_clean(); var inc = require_inc(); var diff = require_diff(); var major = require_major(); var minor = require_minor(); var patch = require_patch(); var prerelease = require_prerelease(); var compare = require_compare(); var rcompare = require_rcompare(); var compareLoose = require_compare_loose(); var compareBuild = require_compare_build(); var sort = require_sort(); var rsort = require_rsort(); var gt2 = require_gt(); var lt2 = require_lt(); var eq = require_eq(); var neq = require_neq(); var gte = require_gte(); var lte = require_lte(); var cmp = require_cmp(); var coerce = require_coerce(); var truncate = require_truncate(); var Comparator = require_comparator(); var Range = require_range(); var satisfies = require_satisfies(); var toComparators = require_to_comparators(); var maxSatisfying = require_max_satisfying(); var minSatisfying = require_min_satisfying(); var minVersion = require_min_version(); var validRange = require_valid2(); var outside = require_outside(); var gtr = require_gtr(); var ltr = require_ltr(); var intersects = require_intersects(); var simplifyRange = require_simplify(); var subset = require_subset(); module2.exports = { parse, valid, clean, inc, diff, major, minor, patch, prerelease, compare, rcompare, compareLoose, compareBuild, sort, rsort, gt: gt2, lt: lt2, eq, neq, gte, lte, cmp, coerce, truncate, Comparator, Range, satisfies, toComparators, maxSatisfying, minSatisfying, minVersion, validRange, outside, gtr, ltr, intersects, simplifyRange, subset, SemVer, re: internalRe.re, src: internalRe.src, tokens: internalRe.t, SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION, RELEASE_TYPES: constants.RELEASE_TYPES, compareIdentifiers: identifiers.compareIdentifiers, rcompareIdentifiers: identifiers.rcompareIdentifiers }; } }); // src/qz.mjs var import_promises5 = __toESM(require("node:fs/promises"), 1); var import_node_fs9 = require("node:fs"); var import_node_crypto3 = require("node:crypto"); var import_node_path12 = __toESM(require("node:path"), 1); var import_node_os = __toESM(require("node:os"), 1); var import_node_child_process = require("node:child_process"); var import_semver = __toESM(require_semver2(), 1); // node_modules/tar/dist/esm/index.min.js var import_events = __toESM(require("events"), 1); var import_fs = __toESM(require("fs"), 1); var import_node_events = require("node:events"); var import_node_stream = __toESM(require("node:stream"), 1); var import_node_string_decoder = require("node:string_decoder"); var import_node_path = __toESM(require("node:path"), 1); var import_node_fs = __toESM(require("node:fs"), 1); var import_path = require("path"); var import_events2 = require("events"); var import_assert = __toESM(require("assert"), 1); var import_buffer = require("buffer"); var Ps = __toESM(require("zlib"), 1); var import_zlib = __toESM(require("zlib"), 1); var import_node_path2 = require("node:path"); var import_node_path3 = require("node:path"); var import_fs2 = __toESM(require("fs"), 1); var import_fs3 = __toESM(require("fs"), 1); var import_path2 = __toESM(require("path"), 1); var import_node_path4 = require("node:path"); var import_path3 = __toESM(require("path"), 1); var import_node_fs2 = __toESM(require("node:fs"), 1); var import_node_assert = __toESM(require("node:assert"), 1); var import_node_crypto = require("node:crypto"); var import_node_fs3 = __toESM(require("node:fs"), 1); var import_node_path5 = __toESM(require("node:path"), 1); var import_fs4 = __toESM(require("fs"), 1); var import_node_fs4 = __toESM(require("node:fs"), 1); var import_node_path6 = __toESM(require("node:path"), 1); var import_node_fs5 = __toESM(require("node:fs"), 1); var import_promises = __toESM(require("node:fs/promises"), 1); var import_node_path7 = __toESM(require("node:path"), 1); var import_node_path8 = require("node:path"); var import_node_fs6 = __toESM(require("node:fs"), 1); var import_node_path9 = __toESM(require("node:path"), 1); var zr = Object.defineProperty; var Ur = (s3, t) => { for (var e in t) zr(s3, e, { get: t[e], enumerable: true }); }; var Ds = typeof process == "object" && process ? process : { stdout: null, stderr: null }; var Wr = (s3) => !!s3 && typeof s3 == "object" && (s3 instanceof A || s3 instanceof import_node_stream.default || Gr(s3) || Zr(s3)); var Gr = (s3) => !!s3 && typeof s3 == "object" && s3 instanceof import_node_events.EventEmitter && typeof s3.pipe == "function" && s3.pipe !== import_node_stream.default.Writable.prototype.pipe; var Zr = (s3) => !!s3 && typeof s3 == "object" && s3 instanceof import_node_events.EventEmitter && typeof s3.write == "function" && typeof s3.end == "function"; var Q = /* @__PURE__ */ Symbol("EOF"); var J = /* @__PURE__ */ Symbol("maybeEmitEnd"); var nt = /* @__PURE__ */ Symbol("emittedEnd"); var De = /* @__PURE__ */ Symbol("emittingEnd"); var qt = /* @__PURE__ */ Symbol("emittedError"); var Ne = /* @__PURE__ */ Symbol("closed"); var Ns = /* @__PURE__ */ Symbol("read"); var Ae = /* @__PURE__ */ Symbol("flush"); var As = /* @__PURE__ */ Symbol("flushChunk"); var z = /* @__PURE__ */ Symbol("encoding"); var vt = /* @__PURE__ */ Symbol("decoder"); var g = /* @__PURE__ */ Symbol("flowing"); var Qt = /* @__PURE__ */ Symbol("paused"); var Bt = /* @__PURE__ */ Symbol("resume"); var b = /* @__PURE__ */ Symbol("buffer"); var N = /* @__PURE__ */ Symbol("pipes"); var _ = /* @__PURE__ */ Symbol("bufferLength"); var bi = /* @__PURE__ */ Symbol("bufferPush"); var Ie = /* @__PURE__ */ Symbol("bufferShift"); var L = /* @__PURE__ */ Symbol("objectMode"); var S = /* @__PURE__ */ Symbol("destroyed"); var _i = /* @__PURE__ */ Symbol("error"); var Oi = /* @__PURE__ */ Symbol("emitData"); var Is = /* @__PURE__ */ Symbol("emitEnd"); var Ti = /* @__PURE__ */ Symbol("emitEnd2"); var Z = /* @__PURE__ */ Symbol("async"); var xi = /* @__PURE__ */ Symbol("abort"); var Ce = /* @__PURE__ */ Symbol("aborted"); var Jt = /* @__PURE__ */ Symbol("signal"); var Rt = /* @__PURE__ */ Symbol("dataListeners"); var C = /* @__PURE__ */ Symbol("discarded"); var jt = (s3) => Promise.resolve().then(s3); var Yr = (s3) => s3(); var Kr = (s3) => s3 === "end" || s3 === "finish" || s3 === "prefinish"; var $r = (s3) => s3 instanceof ArrayBuffer || !!s3 && typeof s3 == "object" && s3.constructor && s3.constructor.name === "ArrayBuffer" && s3.byteLength >= 0; var Vr = (s3) => !Buffer.isBuffer(s3) && ArrayBuffer.isView(s3); var Fe = class { src; dest; opts; ondrain; constructor(t, e, i) { this.src = t, this.dest = e, this.opts = i, this.ondrain = () => t[Bt](), this.dest.on("drain", this.ondrain); } unpipe() { this.dest.removeListener("drain", this.ondrain); } proxyErrors(t) { } end() { this.unpipe(), this.opts.end && this.dest.end(); } }; var Li = class extends Fe { unpipe() { this.src.removeListener("error", this.proxyErrors), super.unpipe(); } constructor(t, e, i) { super(t, e, i), this.proxyErrors = (r) => this.dest.emit("error", r), t.on("error", this.proxyErrors); } }; var Xr = (s3) => !!s3.objectMode; var qr = (s3) => !s3.objectMode && !!s3.encoding && s3.encoding !== "buffer"; var A = class extends import_node_events.EventEmitter { [g] = false; [Qt] = false; [N] = []; [b] = []; [L]; [z]; [Z]; [vt]; [Q] = false; [nt] = false; [De] = false; [Ne] = false; [qt] = null; [_] = 0; [S] = false; [Jt]; [Ce] = false; [Rt] = 0; [C] = false; writable = true; readable = true; constructor(...t) { let e = t[0] || {}; if (super(), e.objectMode && typeof e.encoding == "string") throw new TypeError("Encoding and objectMode may not be used together"); Xr(e) ? (this[L] = true, this[z] = null) : qr(e) ? (this[z] = e.encoding, this[L] = false) : (this[L] = false, this[z] = null), this[Z] = !!e.async, this[vt] = this[z] ? new import_node_string_decoder.StringDecoder(this[z]) : null, e && e.debugExposeBuffer === true && Object.defineProperty(this, "buffer", { get: () => this[b] }), e && e.debugExposePipes === true && Object.defineProperty(this, "pipes", { get: () => this[N] }); let { signal: i } = e; i && (this[Jt] = i, i.aborted ? this[xi]() : i.addEventListener("abort", () => this[xi]())); } get bufferLength() { return this[_]; } get encoding() { return this[z]; } set encoding(t) { throw new Error("Encoding must be set at instantiation time"); } setEncoding(t) { throw new Error("Encoding must be set at instantiation time"); } get objectMode() { return this[L]; } set objectMode(t) { throw new Error("objectMode must be set at instantiation time"); } get async() { return this[Z]; } set async(t) { this[Z] = this[Z] || !!t; } [xi]() { this[Ce] = true, this.emit("abort", this[Jt]?.reason), this.destroy(this[Jt]?.reason); } get aborted() { return this[Ce]; } set aborted(t) { } write(t, e, i) { if (this[Ce]) return false; if (this[Q]) throw new Error("write after end"); if (this[S]) return this.emit("error", Object.assign(new Error("Cannot call write after a stream was destroyed"), { code: "ERR_STREAM_DESTROYED" })), true; typeof e == "function" && (i = e, e = "utf8"), e || (e = "utf8"); let r = this[Z] ? jt : Yr; if (!this[L] && !Buffer.isBuffer(t)) { if (Vr(t)) t = Buffer.from(t.buffer, t.byteOffset, t.byteLength); else if ($r(t)) t = Buffer.from(t); else if (typeof t != "string") throw new Error("Non-contiguous data written to non-objectMode stream"); } return this[L] ? (this[g] && this[_] !== 0 && this[Ae](true), this[g] ? this.emit("data", t) : this[bi](t), this[_] !== 0 && this.emit("readable"), i && r(i), this[g]) : t.length ? (typeof t == "string" && !(e === this[z] && !this[vt]?.lastNeed) && (t = Buffer.from(t, e)), Buffer.isBuffer(t) && this[z] && (t = this[vt].write(t)), this[g] && this[_] !== 0 && this[Ae](true), this[g] ? this.emit("data", t) : this[bi](t), this[_] !== 0 && this.emit("readable"), i && r(i), this[g]) : (this[_] !== 0 && this.emit("readable"), i && r(i), this[g]); } read(t) { if (this[S]) return null; if (this[C] = false, this[_] === 0 || t === 0 || t && t > this[_]) return this[J](), null; this[L] && (t = null), this[b].length > 1 && !this[L] && (this[b] = [this[z] ? this[b].join("") : Buffer.concat(this[b], this[_])]); let e = this[Ns](t || null, this[b][0]); return this[J](), e; } [Ns](t, e) { if (this[L]) this[Ie](); else { let i = e; t === i.length || t === null ? this[Ie]() : typeof i == "string" ? (this[b][0] = i.slice(t), e = i.slice(0, t), this[_] -= t) : (this[b][0] = i.subarray(t), e = i.subarray(0, t), this[_] -= t); } return this.emit("data", e), !this[b].length && !this[Q] && this.emit("drain"), e; } end(t, e, i) { return typeof t == "function" && (i = t, t = void 0), typeof e == "function" && (i = e, e = "utf8"), t !== void 0 && this.write(t, e), i && this.once("end", i), this[Q] = true, this.writable = false, (this[g] || !this[Qt]) && this[J](), this; } [Bt]() { this[S] || (!this[Rt] && !this[N].length && (this[C] = true), this[Qt] = false, this[g] = true, this.emit("resume"), this[b].length ? this[Ae]() : this[Q] ? this[J]() : this.emit("drain")); } resume() { return this[Bt](); } pause() { this[g] = false, this[Qt] = true, this[C] = false; } get destroyed() { return this[S]; } get flowing() { return this[g]; } get paused() { return this[Qt]; } [bi](t) { this[L] ? this[_] += 1 : this[_] += t.length, this[b].push(t); } [Ie]() { return this[L] ? this[_] -= 1 : this[_] -= this[b][0].length, this[b].shift(); } [Ae](t = false) { do ; while (this[As](this[Ie]()) && this[b].length); !t && !this[b].length && !this[Q] && this.emit("drain"); } [As](t) { return this.emit("data", t), this[g]; } pipe(t, e) { if (this[S]) return t; this[C] = false; let i = this[nt]; return e = e || {}, t === Ds.stdout || t === Ds.stderr ? e.end = false : e.end = e.end !== false, e.proxyErrors = !!e.proxyErrors, i ? e.end && t.end() : (this[N].push(e.proxyErrors ? new Li(this, t, e) : new Fe(this, t, e)), this[Z] ? jt(() => this[Bt]()) : this[Bt]()), t; } unpipe(t) { let e = this[N].find((i) => i.dest === t); e && (this[N].length === 1 ? (this[g] && this[Rt] === 0 && (this[g] = false), this[N] = []) : this[N].splice(this[N].indexOf(e), 1), e.unpipe()); } addListener(t, e) { return this.on(t, e); } on(t, e) { let i = super.on(t, e); if (t === "data") this[C] = false, this[Rt]++, !this[N].length && !this[g] && this[Bt](); else if (t === "readable" && this[_] !== 0) super.emit("readable"); else if (Kr(t) && this[nt]) super.emit(t), this.removeAllListeners(t); else if (t === "error" && this[qt]) { let r = e; this[Z] ? jt(() => r.call(this, this[qt])) : r.call(this, this[qt]); } return i; } removeListener(t, e) { return this.off(t, e); } off(t, e) { let i = super.off(t, e); return t === "data" && (this[Rt] = this.listeners("data").length, this[Rt] === 0 && !this[C] && !this[N].length && (this[g] = false)), i; } removeAllListeners(t) { let e = super.removeAllListeners(t); return (t === "data" || t === void 0) && (this[Rt] = 0, !this[C] && !this[N].length && (this[g] = false)), e; } get emittedEnd() { return this[nt]; } [J]() { !this[De] && !this[nt] && !this[S] && this[b].length === 0 && this[Q] && (this[De] = true, this.emit("end"), this.emit("prefinish"), this.emit("finish"), this[Ne] && this.emit("close"), this[De] = false); } emit(t, ...e) { let i = e[0]; if (t !== "error" && t !== "close" && t !== S && this[S]) return false; if (t === "data") return !this[L] && !i ? false : this[Z] ? (jt(() => this[Oi](i)), true) : this[Oi](i); if (t === "end") return this[Is](); if (t === "close") { if (this[Ne] = true, !this[nt] && !this[S]) return false; let n = super.emit("close"); return this.removeAllListeners("close"), n; } else if (t === "error") { this[qt] = i, super.emit(_i, i); let n = !this[Jt] || this.listeners("error").length ? super.emit("error", i) : false; return this[J](), n; } else if (t === "resume") { let n = super.emit("resume"); return this[J](), n; } else if (t === "finish" || t === "prefinish") { let n = super.emit(t); return this.removeAllListeners(t), n; } let r = super.emit(t, ...e); return this[J](), r; } [Oi](t) { for (let i of this[N]) i.dest.write(t) === false && this.pause(); let e = this[C] ? false : super.emit("data", t); return this[J](), e; } [Is]() { return this[nt] ? false : (this[nt] = true, this.readable = false, this[Z] ? (jt(() => this[Ti]()), true) : this[Ti]()); } [Ti]() { if (this[vt]) { let e = this[vt].end(); if (e) { for (let i of this[N]) i.dest.write(e); this[C] || super.emit("data", e); } } for (let e of this[N]) e.end(); let t = super.emit("end"); return this.removeAllListeners("end"), t; } async collect() { let t = Object.assign([], { dataLength: 0 }); this[L] || (t.dataLength = 0); let e = this.promise(); return this.on("data", (i) => { t.push(i), this[L] || (t.dataLength += i.length); }), await e, t; } async concat() { if (this[L]) throw new Error("cannot concat in objectMode"); let t = await this.collect(); return this[z] ? t.join("") : Buffer.concat(t, t.dataLength); } async promise() { return new Promise((t, e) => { this.on(S, () => e(new Error("stream destroyed"))), this.on("error", (i) => e(i)), this.on("end", () => t()); }); } [Symbol.asyncIterator]() { this[C] = false; let t = false, e = async () => (this.pause(), t = true, { value: void 0, done: true }); return { next: () => { if (t) return e(); let r = this.read(); if (r !== null) return Promise.resolve({ done: false, value: r }); if (this[Q]) return e(); let n, o, h = (d) => { this.off("data", a), this.off("end", l), this.off(S, c), e(), o(d); }, a = (d) => { this.off("error", h), this.off("end", l), this.off(S, c), this.pause(), n({ value: d, done: !!this[Q] }); }, l = () => { this.off("error", h), this.off("data", a), this.off(S, c), e(), n({ done: true, value: void 0 }); }, c = () => h(new Error("stream destroyed")); return new Promise((d, y) => { o = y, n = d, this.once(S, c), this.once("error", h), this.once("end", l), this.once("data", a); }); }, throw: e, return: e, [Symbol.asyncIterator]() { return this; }, [Symbol.asyncDispose]: async () => { } }; } [Symbol.iterator]() { this[C] = false; let t = false, e = () => (this.pause(), this.off(_i, e), this.off(S, e), this.off("end", e), t = true, { done: true, value: void 0 }), i = () => { if (t) return e(); let r = this.read(); return r === null ? e() : { done: false, value: r }; }; return this.once("end", e), this.once(_i, e), this.once(S, e), { next: i, throw: e, return: e, [Symbol.iterator]() { return this; }, [Symbol.dispose]: () => { } }; } destroy(t) { if (this[S]) return t ? this.emit("error", t) : this.emit(S), this; this[S] = true, this[C] = true, this[b].length = 0, this[_] = 0; let e = this; return typeof e.close == "function" && !this[Ne] && e.close(), t ? this.emit("error", t) : this.emit(S), this; } static get isStream() { return Wr; } }; var Jr = import_fs.default.writev; var ht = /* @__PURE__ */ Symbol("_autoClose"); var H = /* @__PURE__ */ Symbol("_close"); var te = /* @__PURE__ */ Symbol("_ended"); var u = /* @__PURE__ */ Symbol("_fd"); var Ni = /* @__PURE__ */ Symbol("_finished"); var tt = /* @__PURE__ */ Symbol("_flags"); var Ai = /* @__PURE__ */ Symbol("_flush"); var ki = /* @__PURE__ */ Symbol("_handleChunk"); var Mi = /* @__PURE__ */ Symbol("_makeBuf"); var ie = /* @__PURE__ */ Symbol("_mode"); var ke = /* @__PURE__ */ Symbol("_needDrain"); var Ut = /* @__PURE__ */ Symbol("_onerror"); var Ht = /* @__PURE__ */ Symbol("_onopen"); var Ii = /* @__PURE__ */ Symbol("_onread"); var Pt = /* @__PURE__ */ Symbol("_onwrite"); var at = /* @__PURE__ */ Symbol("_open"); var U = /* @__PURE__ */ Symbol("_path"); var ot = /* @__PURE__ */ Symbol("_pos"); var Y = /* @__PURE__ */ Symbol("_queue"); var zt = /* @__PURE__ */ Symbol("_read"); var Ci = /* @__PURE__ */ Symbol("_readSize"); var j = /* @__PURE__ */ Symbol("_reading"); var ee = /* @__PURE__ */ Symbol("_remain"); var Fi = /* @__PURE__ */ Symbol("_size"); var Me = /* @__PURE__ */ Symbol("_write"); var gt = /* @__PURE__ */ Symbol("_writing"); var ve = /* @__PURE__ */ Symbol("_defaultFlag"); var bt = /* @__PURE__ */ Symbol("_errored"); var _t = class extends A { [bt] = false; [u]; [U]; [Ci]; [j] = false; [Fi]; [ee]; [ht]; constructor(t, e) { if (e = e || {}, super(e), this.readable = true, this.writable = false, typeof t != "string") throw new TypeError("path must be a string"); this[bt] = false, this[u] = typeof e.fd == "number" ? e.fd : void 0, this[U] = t, this[Ci] = e.readSize || 16 * 1024 * 1024, this[j] = false, this[Fi] = typeof e.size == "number" ? e.size : 1 / 0, this[ee] = this[Fi], this[ht] = typeof e.autoClose == "boolean" ? e.autoClose : true, typeof this[u] == "number" ? this[zt]() : this[at](); } get fd() { return this[u]; } get path() { return this[U]; } write() { throw new TypeError("this is a readable stream"); } end() { throw new TypeError("this is a readable stream"); } [at]() { import_fs.default.open(this[U], "r", (t, e) => this[Ht](t, e)); } [Ht](t, e) { t ? this[Ut](t) : (this[u] = e, this.emit("open", e), this[zt]()); } [Mi]() { return Buffer.allocUnsafe(Math.min(this[Ci], this[ee])); } [zt]() { if (!this[j]) { this[j] = true; let t = this[Mi](); if (t.length === 0) return process.nextTick(() => this[Ii](null, 0, t)); import_fs.default.read(this[u], t, 0, t.length, null, (e, i, r) => this[Ii](e, i, r)); } } [Ii](t, e, i) { this[j] = false, t ? this[Ut](t) : this[ki](e, i) && this[zt](); } [H]() { if (this[ht] && typeof this[u] == "number") { let t = this[u]; this[u] = void 0, import_fs.default.close(t, (e) => e ? this.emit("error", e) : this.emit("close")); } } [Ut](t) { this[j] = true, this[H](), this.emit("error", t); } [ki](t, e) { let i = false; return this[ee] -= t, t > 0 && (i = super.write(t < e.length ? e.subarray(0, t) : e)), (t === 0 || this[ee] <= 0) && (i = false, this[H](), super.end()), i; } emit(t, ...e) { switch (t) { case "prefinish": case "finish": return false; case "drain": return typeof this[u] == "number" && this[zt](), false; case "error": return this[bt] ? false : (this[bt] = true, super.emit(t, ...e)); default: return super.emit(t, ...e); } } }; var Be = class extends _t { [at]() { let t = true; try { this[Ht](null, import_fs.default.openSync(this[U], "r")), t = false; } finally { t && this[H](); } } [zt]() { let t = true; try { if (!this[j]) { this[j] = true; do { let e = this[Mi](), i = e.length === 0 ? 0 : import_fs.default.readSync(this[u], e, 0, e.length, null); if (!this[ki](i, e)) break; } while (true); this[j] = false; } t = false; } finally { t && this[H](); } } [H]() { if (this[ht] && typeof this[u] == "number") { let t = this[u]; this[u] = void 0, import_fs.default.closeSync(t), this.emit("close"); } } }; var et = class extends import_events.default { readable = false; writable = true; [bt] = false; [gt] = false; [te] = false; [Y] = []; [ke] = false; [U]; [ie]; [ht]; [u]; [ve]; [tt]; [Ni] = false; [ot]; constructor(t, e) { e = e || {}, super(e), this[U] = t, this[u] = typeof e.fd == "number" ? e.fd : void 0, this[ie] = e.mode === void 0 ? 438 : e.mode, this[ot] = typeof e.start == "number" ? e.start : void 0, this[ht] = typeof e.autoClose == "boolean" ? e.autoClose : true; let i = this[ot] !== void 0 ? "r+" : "w"; this[ve] = e.flags === void 0, this[tt] = e.flags === void 0 ? i : e.flags, this[u] === void 0 && this[at](); } emit(t, ...e) { if (t === "error") { if (this[bt]) return false; this[bt] = true; } return super.emit(t, ...e); } get fd() { return this[u]; } get path() { return this[U]; } [Ut](t) { this[H](), this[gt] = true, this.emit("error", t); } [at]() { import_fs.default.open(this[U], this[tt], this[ie], (t, e) => this[Ht](t, e)); } [Ht](t, e) { this[ve] && this[tt] === "r+" && t && t.code === "ENOENT" ? (this[tt] = "w", this[at]()) : t ? this[Ut](t) : (this[u] = e, this.emit("open", e), this[gt] || this[Ai]()); } end(t, e) { return t && this.write(t, e), this[te] = true, !this[gt] && !this[Y].length && typeof this[u] == "number" && this[Pt](null, 0), this; } write(t, e) { return typeof t == "string" && (t = Buffer.from(t, e)), this[te] ? (this.emit("error", new Error("write() after end()")), false) : this[u] === void 0 || this[gt] || this[Y].length ? (this[Y].push(t), this[ke] = true, false) : (this[gt] = true, this[Me](t), true); } [Me](t) { import_fs.default.write(this[u], t, 0, t.length, this[ot], (e, i) => this[Pt](e, i)); } [Pt](t, e) { t ? this[Ut](t) : (this[ot] !== void 0 && typeof e == "number" && (this[ot] += e), this[Y].length ? this[Ai]() : (this[gt] = false, this[te] && !this[Ni] ? (this[Ni] = true, this[H](), this.emit("finish")) : this[ke] && (this[ke] = false, this.emit("drain")))); } [Ai]() { if (this[Y].length === 0) this[te] && this[Pt](null, 0); else if (this[Y].length === 1) this[Me](this[Y].pop()); else { let t = this[Y]; this[Y] = [], Jr(this[u], t, this[ot], (e, i) => this[Pt](e, i)); } } [H]() { if (this[ht] && typeof this[u] == "number") { let t = this[u]; this[u] = void 0, import_fs.default.close(t, (e) => e ? this.emit("error", e) : this.emit("close")); } } }; var Wt = class extends et { [at]() { let t; if (this[ve] && this[tt] === "r+") try { t = import_fs.default.openSync(this[U], this[tt], this[ie]); } catch (e) { if (e?.code === "ENOENT") return this[tt] = "w", this[at](); throw e; } else t = import_fs.default.openSync(this[U], this[tt], this[ie]); this[Ht](null, t); } [H]() { if (this[ht] && typeof this[u] == "number") { let t = this[u]; this[u] = void 0, import_fs.default.closeSync(t), this.emit("close"); } } [Me](t) { let e = true; try { this[Pt](null, import_fs.default.writeSync(this[u], t, 0, t.length, this[ot])), e = false; } finally { if (e) try { this[H](); } catch { } } } }; var jr = /* @__PURE__ */ new Map([["C", "cwd"], ["f", "file"], ["z", "gzip"], ["P", "preservePaths"], ["U", "unlink"], ["strip-components", "strip"], ["stripComponents", "strip"], ["keep-newer", "newer"], ["keepNewer", "newer"], ["keep-newer-files", "newer"], ["keepNewerFiles", "newer"], ["k", "keep"], ["keep-existing", "keep"], ["keepExisting", "keep"], ["m", "noMtime"], ["no-mtime", "noMtime"], ["p", "preserveOwner"], ["L", "follow"], ["h", "follow"], ["onentry", "onReadEntry"]]); var Fs = (s3) => !!s3.sync && !!s3.file; var ks = (s3) => !s3.sync && !!s3.file; var Ms = (s3) => !!s3.sync && !s3.file; var vs = (s3) => !s3.sync && !s3.file; var Bs = (s3) => !!s3.file; var tn = (s3) => { let t = jr.get(s3); return t || s3; }; var se = (s3 = {}) => { if (!s3) return {}; let t = {}; for (let [e, i] of Object.entries(s3)) { let r = tn(e); t[r] = i; } return t.chmod === void 0 && t.noChmod === false && (t.chmod = true), delete t.noChmod, t; }; var K = (s3, t, e, i, r) => Object.assign((n = [], o, h) => { Array.isArray(n) && (o = n, n = {}), typeof o == "function" && (h = o, o = void 0), o = o ? Array.from(o) : []; let a = se(n); if (r?.(a, o), Fs(a)) { if (typeof h == "function") throw new TypeError("callback not supported for sync tar functions"); return s3(a, o); } else if (ks(a)) { let l = t(a, o); return h ? l.then(() => h(), h) : l; } else if (Ms(a)) { if (typeof h == "function") throw new TypeError("callback not supported for sync tar functions"); return e(a, o); } else if (vs(a)) { if (typeof h == "function") throw new TypeError("callback only supported with file option"); return i(a, o); } throw new Error("impossible options??"); }, { syncFile: s3, asyncFile: t, syncNoFile: e, asyncNoFile: i, validate: r }); var sn = import_zlib.default.constants || { ZLIB_VERNUM: 4736 }; var v = Object.freeze(Object.assign(/* @__PURE__ */ Object.create(null), { Z_NO_FLUSH: 0, Z_PARTIAL_FLUSH: 1, Z_SYNC_FLUSH: 2, Z_FULL_FLUSH: 3, Z_FINISH: 4, Z_BLOCK: 5, Z_OK: 0, Z_STREAM_END: 1, Z_NEED_DICT: 2, Z_ERRNO: -1, Z_STREAM_ERROR: -2, Z_DATA_ERROR: -3, Z_MEM_ERROR: -4, Z_BUF_ERROR: -5, Z_VERSION_ERROR: -6, Z_NO_COMPRESSION: 0, Z_BEST_SPEED: 1, Z_BEST_COMPRESSION: 9, Z_DEFAULT_COMPRESSION: -1, Z_FILTERED: 1, Z_HUFFMAN_ONLY: 2, Z_RLE: 3, Z_FIXED: 4, Z_DEFAULT_STRATEGY: 0, DEFLATE: 1, INFLATE: 2, GZIP: 3, GUNZIP: 4, DEFLATERAW: 5, INFLATERAW: 6, UNZIP: 7, BROTLI_DECODE: 8, BROTLI_ENCODE: 9, Z_MIN_WINDOWBITS: 8, Z_MAX_WINDOWBITS: 15, Z_DEFAULT_WINDOWBITS: 15, Z_MIN_CHUNK: 64, Z_MAX_CHUNK: 1 / 0, Z_DEFAULT_CHUNK: 16384, Z_MIN_MEMLEVEL: 1, Z_MAX_MEMLEVEL: 9, Z_DEFAULT_MEMLEVEL: 8, Z_MIN_LEVEL: -1, Z_MAX_LEVEL: 9, Z_DEFAULT_LEVEL: -1, BROTLI_OPERATION_PROCESS: 0, BROTLI_OPERATION_FLUSH: 1, BROTLI_OPERATION_FINISH: 2, BROTLI_OPERATION_EMIT_METADATA: 3, BROTLI_MODE_GENERIC: 0, BROTLI_MODE_TEXT: 1, BROTLI_MODE_FONT: 2, BROTLI_DEFAULT_MODE: 0, BROTLI_MIN_QUALITY: 0, BROTLI_MAX_QUALITY: 11, BROTLI_DEFAULT_QUALITY: 11, BROTLI_MIN_WINDOW_BITS: 10, BROTLI_MAX_WINDOW_BITS: 24, BROTLI_LARGE_MAX_WINDOW_BITS: 30, BROTLI_DEFAULT_WINDOW: 22, BROTLI_MIN_INPUT_BLOCK_BITS: 16, BROTLI_MAX_INPUT_BLOCK_BITS: 24, BROTLI_PARAM_MODE: 0, BROTLI_PARAM_QUALITY: 1, BROTLI_PARAM_LGWIN: 2, BROTLI_PARAM_LGBLOCK: 3, BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: 4, BROTLI_PARAM_SIZE_HINT: 5, BROTLI_PARAM_LARGE_WINDOW: 6, BROTLI_PARAM_NPOSTFIX: 7, BROTLI_PARAM_NDIRECT: 8, BROTLI_DECODER_RESULT_ERROR: 0, BROTLI_DECODER_RESULT_SUCCESS: 1, BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: 2, BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: 3, BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: 0, BROTLI_DECODER_PARAM_LARGE_WINDOW: 1, BROTLI_DECODER_NO_ERROR: 0, BROTLI_DECODER_SUCCESS: 1, BROTLI_DECODER_NEEDS_MORE_INPUT: 2, BROTLI_DECODER_NEEDS_MORE_OUTPUT: 3, BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: -1, BROTLI_DECODER_ERROR_FORMAT_RESERVED: -2, BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: -3, BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: -4, BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: -5, BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: -6, BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: -7, BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: -8, BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: -9, BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: -10, BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: -11, BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: -12, BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: -13, BROTLI_DECODER_ERROR_FORMAT_PADDING_1: -14, BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -15, BROTLI_DECODER_ERROR_FORMAT_DISTANCE: -16, BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -19, BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: -20, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: -21, BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: -22, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: -25, BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: -26, BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: -27, BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: -30, BROTLI_DECODER_ERROR_UNREACHABLE: -31 }, sn)); var rn = import_buffer.Buffer.concat; var zs = Object.getOwnPropertyDescriptor(import_buffer.Buffer, "concat"); var nn = (s3) => s3; var Bi = zs?.writable === true || zs?.set !== void 0 ? (s3) => { import_buffer.Buffer.concat = s3 ? nn : rn; } : (s3) => { }; var Tt = /* @__PURE__ */ Symbol("_superWrite"); var Gt = class extends Error { code; errno; constructor(t, e) { super("zlib: " + t.message, { cause: t }), this.code = t.code, this.errno = t.errno, this.code || (this.code = "ZLIB_ERROR"), this.message = "zlib: " + t.message, Error.captureStackTrace(this, e ?? this.constructor); } get name() { return "ZlibError"; } }; var Pi = /* @__PURE__ */ Symbol("flushFlag"); var re = class extends A { #t = false; #i = false; #s; #n; #r; #e; #o; get sawError() { return this.#t; } get handle() { return this.#e; } get flushFlag() { return this.#s; } constructor(t, e) { if (!t || typeof t != "object") throw new TypeError("invalid options for ZlibBase constructor"); if (super(t), this.#s = t.flush ?? 0, this.#n = t.finishFlush ?? 0, this.#r = t.fullFlushFlag ?? 0, typeof Ps[e] != "function") throw new TypeError("Compression method not supported: " + e); try { this.#e = new Ps[e](t); } catch (i) { throw new Gt(i, this.constructor); } this.#o = (i) => { this.#t || (this.#t = true, this.close(), this.emit("error", i)); }, this.#e?.on("error", (i) => this.#o(new Gt(i))), this.once("end", () => this.close); } close() { this.#e && (this.#e.close(), this.#e = void 0, this.emit("close")); } reset() { if (!this.#t) return (0, import_assert.default)(this.#e, "zlib binding closed"), this.#e.reset?.(); } flush(t) { this.ended || (typeof t != "number" && (t = this.#r), this.write(Object.assign(import_buffer.Buffer.alloc(0), { [Pi]: t }))); } end(t, e, i) { return typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), t && (e ? this.write(t, e) : this.write(t)), this.flush(this.#n), this.#i = true, super.end(i); } get ended() { return this.#i; } [Tt](t) { return super.write(t); } write(t, e, i) { if (typeof e == "function" && (i = e, e = "utf8"), typeof t == "string" && (t = import_buffer.Buffer.from(t, e)), this.#t) return; (0, import_assert.default)(this.#e, "zlib binding closed"); let r = this.#e._handle, n = r.close; r.close = () => { }; let o = this.#e.close; this.#e.close = () => { }, Bi(true); let h; try { let l = typeof t[Pi] == "number" ? t[Pi] : this.#s; h = this.#e._processChunk(t, l), Bi(false); } catch (l) { Bi(false), this.#o(new Gt(l, this.write)); } finally { this.#e && (this.#e._handle = r, r.close = n, this.#e.close = o, this.#e.removeAllListeners("error")); } this.#e && this.#e.on("error", (l) => this.#o(new Gt(l, this.write))); let a; if (h) if (Array.isArray(h) && h.length > 0) { let l = h[0]; a = this[Tt](import_buffer.Buffer.from(l)); for (let c = 1; c < h.length; c++) a = this[Tt](h[c]); } else a = this[Tt](import_buffer.Buffer.from(h)); return i && i(), a; } }; var Pe = class extends re { #t; #i; constructor(t, e) { t = t || {}, t.flush = t.flush || v.Z_NO_FLUSH, t.finishFlush = t.finishFlush || v.Z_FINISH, t.fullFlushFlag = v.Z_FULL_FLUSH, super(t, e), this.#t = t.level, this.#i = t.strategy; } params(t, e) { if (!this.sawError) { if (!this.handle) throw new Error("cannot switch params when binding is closed"); if (!this.handle.params) throw new Error("not supported in this implementation"); if (this.#t !== t || this.#i !== e) { this.flush(v.Z_SYNC_FLUSH), (0, import_assert.default)(this.handle, "zlib binding closed"); let i = this.handle.flush; this.handle.flush = (r, n) => { typeof r == "function" && (n = r, r = this.flushFlag), this.flush(r), n?.(); }; try { this.handle.params(t, e); } finally { this.handle.flush = i; } this.handle && (this.#t = t, this.#i = e); } } } }; var ze = class extends Pe { #t; constructor(t) { super(t, "Gzip"), this.#t = t && !!t.portable; } [Tt](t) { return this.#t ? (this.#t = false, t[9] = 255, super[Tt](t)) : super[Tt](t); } }; var Ue = class extends Pe { constructor(t) { super(t, "Unzip"); } }; var He = class extends re { constructor(t, e) { t = t || {}, t.flush = t.flush || v.BROTLI_OPERATION_PROCESS, t.finishFlush = t.finishFlush || v.BROTLI_OPERATION_FINISH, t.fullFlushFlag = v.BROTLI_OPERATION_FLUSH, super(t, e); } }; var We = class extends He { constructor(t) { super(t, "BrotliCompress"); } }; var Ge = class extends He { constructor(t) { super(t, "BrotliDecompress"); } }; var Ze = class extends re { constructor(t, e) { t = t || {}, t.flush = t.flush || v.ZSTD_e_continue, t.finishFlush = t.finishFlush || v.ZSTD_e_end, t.fullFlushFlag = v.ZSTD_e_flush, super(t, e); } }; var Ye = class extends Ze { constructor(t) { super(t, "ZstdCompress"); } }; var Ke = class extends Ze { constructor(t) { super(t, "ZstdDecompress"); } }; var Us = (s3, t) => { if (Number.isSafeInteger(s3)) s3 < 0 ? an(s3, t) : hn(s3, t); else throw Error("cannot encode number outside of javascript safe integer range"); return t; }; var hn = (s3, t) => { t[0] = 128; for (var e = t.length; e > 1; e--) t[e - 1] = s3 & 255, s3 = Math.floor(s3 / 256); }; var an = (s3, t) => { t[0] = 255; var e = false; s3 = s3 * -1; for (var i = t.length; i > 1; i--) { var r = s3 & 255; s3 = Math.floor(s3 / 256), e ? t[i - 1] = Ws(r) : r === 0 ? t[i - 1] = 0 : (e = true, t[i - 1] = Gs(r)); } }; var Hs = (s3) => { let t = s3[0], e = t === 128 ? cn(s3.subarray(1, s3.length)) : t === 255 ? ln(s3) : null; if (e === null) throw Error("invalid base256 encoding"); if (!Number.isSafeInteger(e)) throw Error("parsed number outside of javascript safe integer range"); return e; }; var ln = (s3) => { for (var t = s3.length, e = 0, i = false, r = t - 1; r > -1; r--) { var n = Number(s3[r]), o; i ? o = Ws(n) : n === 0 ? o = n : (i = true, o = Gs(n)), o !== 0 && (e -= o * Math.pow(256, t - r - 1)); } return e; }; var cn = (s3) => { for (var t = s3.length, e = 0, i = t - 1; i > -1; i--) { var r = Number(s3[i]); r !== 0 && (e += r * Math.pow(256, t - i - 1)); } return e; }; var Ws = (s3) => (255 ^ s3) & 255; var Gs = (s3) => (255 ^ s3) + 1 & 255; var Hi = {}; Ur(Hi, { code: () => $e, isCode: () => ne, isName: () => dn, name: () => oe, normalFsTypes: () => Ui }); var ne = (s3) => oe.has(s3); var dn = (s3) => $e.has(s3); var Ui = /* @__PURE__ */ new Set(["0", "", "1", "2", "3", "4", "5", "6", "7", "D"]); var oe = /* @__PURE__ */ new Map([["0", "File"], ["", "OldFile"], ["1", "Link"], ["2", "SymbolicLink"], ["3", "CharacterDevice"], ["4", "BlockDevice"], ["5", "Directory"], ["6", "FIFO"], ["7", "ContiguousFile"], ["g", "GlobalExtendedHeader"], ["x", "ExtendedHeader"], ["A", "SolarisACL"], ["D", "GNUDumpDir"], ["I", "Inode"], ["K", "NextFileHasLongLinkpath"], ["L", "NextFileHasLongPath"], ["M", "ContinuationFile"], ["N", "OldGnuLongPath"], ["S", "SparseFile"], ["V", "TapeVolumeHeader"], ["X", "OldExtendedHeader"]]); var $e = new Map(Array.from(oe).map((s3) => [s3[1], s3[0]])); var mn = (s3) => s3 === void 0 || s3 < 0 ? void 0 : s3; var F = class { cksumValid = false; needPax = false; nullBlock = false; block; path; mode; uid; gid; size; cksum; #t = "Unsupported"; linkpath; uname; gname; devmaj = 0; devmin = 0; atime; ctime; mtime; charset; comment; constructor(t, e = 0, i, r) { Buffer.isBuffer(t) ? this.decode(t, e || 0, i, r) : t && this.#i(t); } decode(t, e, i, r) { if (e || (e = 0), !t || !(t.length >= e + 512)) throw new Error("need 512 bytes for header"); let n = xt(t, e + 156, 1), o = Ui.has(n), h = o ? i : void 0, a = o ? r : void 0; if (this.path = h?.path ?? xt(t, e, 100), this.mode = h?.mode ?? a?.mode ?? lt(t, e + 100, 8), this.uid = h?.uid ?? a?.uid ?? lt(t, e + 108, 8), this.gid = h?.gid ?? a?.gid ?? lt(t, e + 116, 8), this.size = mn(h?.size ?? a?.size ?? lt(t, e + 124, 12)), this.mtime = h?.mtime ?? a?.mtime ?? Wi(t, e + 136, 12), this.cksum = lt(t, e + 148, 12), a && this.#i(a, true), h && this.#i(h), ne(n) && (this.#t = n || "0"), this.#t === "0" && this.path.slice(-1) === "/" && (this.#t = "5"), this.#t === "5" && (this.size = 0), this.linkpath = xt(t, e + 157, 100), t.subarray(e + 257, e + 265).toString() === "ustar\x0000") if (this.uname = h?.uname ?? a?.uname ?? xt(t, e + 265, 32), this.gname = h?.gname ?? a?.gname ?? xt(t, e + 297, 32), this.devmaj = h?.devmaj ?? a?.devmaj ?? lt(t, e + 329, 8) ?? 0, this.devmin = h?.devmin ?? a?.devmin ?? lt(t, e + 337, 8) ?? 0, t[e + 475] !== 0) { let c = xt(t, e + 345, 155); this.path = c + "/" + this.path; } else { let c = xt(t, e + 345, 130); c && (this.path = c + "/" + this.path), this.atime = i?.atime ?? r?.atime ?? Wi(t, e + 476, 12), this.ctime = i?.ctime ?? r?.ctime ?? Wi(t, e + 488, 12); } let l = 256; for (let c = e; c < e + 148; c++) l += t[c]; for (let c = e + 156; c < e + 512; c++) l += t[c]; this.cksumValid = l === this.cksum, this.cksum === void 0 && l === 256 && (this.nullBlock = true); } #i(t, e = false) { Object.assign(this, Object.fromEntries(Object.entries(t).filter(([i, r]) => !(r == null || i === "size" && Number(r) < 0 || i === "path" && e || i === "linkpath" && e || i === "global")))); } encode(t, e = 0) { if (t || (t = this.block = Buffer.alloc(512)), this.#t === "Unsupported" && (this.#t = "0"), !(t.length >= e + 512)) throw new Error("need 512 bytes for header"); let i = this.ctime || this.atime ? 130 : 155, r = un(this.path || "", i), n = r[0], o = r[1]; this.needPax = !!r[2], this.needPax = Lt(t, e, 100, n) || this.needPax, this.needPax = ct(t, e + 100, 8, this.mode) || this.needPax, this.needPax = ct(t, e + 108, 8, this.uid) || this.needPax, this.needPax = ct(t, e + 116, 8, this.gid) || this.needPax, this.needPax = ct(t, e + 124, 12, this.size) || this.needPax, this.needPax = Gi(t, e + 136, 12, this.mtime) || this.needPax, t[e + 156] = Number(this.#t.codePointAt(0)), this.needPax = Lt(t, e + 157, 100, this.linkpath) || this.needPax, t.write("ustar\x0000", e + 257, 8), this.needPax = Lt(t, e + 265, 32, this.uname) || this.needPax, this.needPax = Lt(t, e + 297, 32, this.gname) || this.needPax, this.needPax = ct(t, e + 329, 8, this.devmaj) || this.needPax, this.needPax = ct(t, e + 337, 8, this.devmin) || this.needPax, this.needPax = Lt(t, e + 345, i, o) || this.needPax, t[e + 475] !== 0 ? this.needPax = Lt(t, e + 345, 155, o) || this.needPax : (this.needPax = Lt(t, e + 345, 130, o) || this.needPax, this.needPax = Gi(t, e + 476, 12, this.atime) || this.needPax, this.needPax = Gi(t, e + 488, 12, this.ctime) || this.needPax); let h = 256; for (let a = e; a < e + 148; a++) h += t[a]; for (let a = e + 156; a < e + 512; a++) h += t[a]; return this.cksum = h, ct(t, e + 148, 8, this.cksum), this.cksumValid = true, this.needPax; } get type() { return this.#t === "Unsupported" ? this.#t : oe.get(this.#t); } get typeKey() { return this.#t; } set type(t) { let e = String($e.get(t)); if (ne(e) || e === "Unsupported") this.#t = e; else if (ne(t)) this.#t = t; else throw new TypeError("invalid entry type: " + t); } }; var un = (s3, t) => { let i = s3, r = "", n, o = import_node_path2.posix.parse(s3).root || "."; if (Buffer.byteLength(i) < 100) n = [i, r, false]; else { r = import_node_path2.posix.dirname(i), i = import_node_path2.posix.basename(i); do Buffer.byteLength(i) <= 100 && Buffer.byteLength(r) <= t ? n = [i, r, false] : Buffer.byteLength(i) > 100 && Buffer.byteLength(r) <= t ? n = [i.slice(0, 99), r, true] : (i = import_node_path2.posix.join(import_node_path2.posix.basename(r), i), r = import_node_path2.posix.dirname(r)); while (r !== o && n === void 0); n || (n = [s3.slice(0, 99), "", true]); } return n; }; var xt = (s3, t, e) => s3.subarray(t, t + e).toString("utf8").replace(/\0.*/, ""); var Wi = (s3, t, e) => pn(lt(s3, t, e)); var pn = (s3) => s3 === void 0 ? void 0 : new Date(s3 * 1e3); var lt = (s3, t, e) => Number(s3[t]) & 128 ? Hs(s3.subarray(t, t + e)) : wn(s3, t, e); var En = (s3) => isNaN(s3) ? void 0 : s3; var wn = (s3, t, e) => En(parseInt(s3.subarray(t, t + e).toString("utf8").replace(/\0.*$/, "").trim(), 8)); var Sn = { 12: 8589934591, 8: 2097151 }; var ct = (s3, t, e, i) => i === void 0 ? false : i > Sn[e] || i < 0 ? (Us(i, s3.subarray(t, t + e)), true) : (yn(s3, t, e, i), false); var yn = (s3, t, e, i) => s3.write(Rn(i, e), t, e, "ascii"); var Rn = (s3, t) => gn(Math.floor(s3).toString(8), t); var gn = (s3, t) => (s3.length === t - 1 ? s3 : new Array(t - s3.length - 1).join("0") + s3 + " ") + "\0"; var Gi = (s3, t, e, i) => i === void 0 ? false : ct(s3, t, e, i.getTime() / 1e3); var bn = new Array(156).join("\0"); var Lt = (s3, t, e, i) => i === void 0 ? false : (s3.write(i + bn, t, e, "utf8"), i.length !== Buffer.byteLength(i) || i.length > e); var On = /^(?:0|[1-9]\d*)$/; var ft = class s { atime; mtime; ctime; charset; comment; gid; uid; gname; uname; linkpath; dev; ino; nlink; path; size; mode; global; constructor(t, e = false) { this.atime = t.atime, this.charset = t.charset, this.comment = t.comment, this.ctime = t.ctime, this.dev = t.dev, this.gid = t.gid, this.global = e, this.gname = t.gname, this.ino = t.ino, this.linkpath = t.linkpath, this.mtime = t.mtime, this.nlink = t.nlink, this.path = t.path, this.size = t.size, this.uid = t.uid, this.uname = t.uname; } encode() { let t = this.encodeBody(); if (t === "") return Buffer.allocUnsafe(0); let e = Buffer.byteLength(t), i = 512 * Math.ceil(1 + e / 512), r = Buffer.allocUnsafe(i); for (let n = 0; n < 512; n++) r[n] = 0; new F({ path: ("PaxHeader/" + (0, import_node_path3.basename)(this.path ?? "")).slice(0, 99), mode: this.mode || 420, uid: this.uid, gid: this.gid, size: e, mtime: this.mtime, type: this.global ? "GlobalExtendedHeader" : "ExtendedHeader", linkpath: "", uname: this.uname || "", gname: this.gname || "", devmaj: 0, devmin: 0, atime: this.atime, ctime: this.ctime }).encode(r), r.write(t, 512, e, "utf8"); for (let n = e + 512; n < r.length; n++) r[n] = 0; return r; } encodeBody() { return this.encodeField("path") + this.encodeField("ctime") + this.encodeField("atime") + this.encodeField("dev") + this.encodeField("ino") + this.encodeField("nlink") + this.encodeField("charset") + this.encodeField("comment") + this.encodeField("gid") + this.encodeField("gname") + this.encodeField("linkpath") + this.encodeField("mtime") + this.encodeField("size") + this.encodeField("uid") + this.encodeField("uname"); } encodeField(t) { if (this[t] === void 0) return ""; let e = this[t], i = e instanceof Date ? e.getTime() / 1e3 : e, r = " " + (t === "dev" || t === "ino" || t === "nlink" ? "SCHILY." : "") + t + "=" + i + ` `, n = Buffer.byteLength(r), o = Math.floor(Math.log(n) / Math.log(10)) + 1; return n + o >= Math.pow(10, o) && (o += 1), o + n + r; } static parse(t, e, i = false) { return new s(Tn(xn(t), e), i); } }; var Tn = (s3, t) => t ? Object.assign({}, t, s3) : s3; var xn = (s3) => s3.replace(/\n$/, "").split(` `).reduce(Ln, /* @__PURE__ */ Object.create(null)); var Ln = (s3, t) => { let e = parseInt(t, 10); if (e !== Buffer.byteLength(t) + 1) return s3; t = t.slice((e + " ").length); let i = t.split("="), r = i.shift(); if (!r) return s3; let n = r.replace(/^SCHILY\.(dev|ino|nlink)/, "$1"), o = i.join("=").replace(/\0.*/, ""); switch (n) { case "path": case "linkpath": case "type": case "charset": case "comment": case "gname": case "uname": s3[n] = o; break; case "ctime": case "atime": case "mtime": s3[n] = new Date(Number(o) * 1e3); break; case "size": if (!On.test(o.trim())) break; let h = +o; if (!Number.isSafeInteger(h)) break; s3[n] = h; break; case "gid": case "uid": case "dev": case "ino": case "nlink": case "mode": s3[n] = +o; break; } return s3; }; var Dn = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform; var f = Dn !== "win32" ? (s3) => String(s3) : (s3) => String(s3).replaceAll(/\\/g, "/"); var Ve = class extends A { extended; globalExtended; header; startBlockSize; blockRemain; remain; type; meta = false; ignore = false; path; mode; uid; gid; uname; gname; size = 0; mtime; atime; ctime; linkpath; dev; ino; nlink; invalid = false; absolute; unsupported = false; constructor(t, e, i) { switch (super({}), this.pause(), this.extended = e, this.globalExtended = i, this.header = t, this.remain = t.size ?? 0, this.startBlockSize = 512 * Math.ceil(this.remain / 512), this.blockRemain = this.startBlockSize, this.type = t.type, this.type) { case "File": case "OldFile": case "Link": case "SymbolicLink": case "CharacterDevice": case "BlockDevice": case "Directory": case "FIFO": case "ContiguousFile": case "GNUDumpDir": break; case "NextFileHasLongLinkpath": case "NextFileHasLongPath": case "OldGnuLongPath": case "GlobalExtendedHeader": case "ExtendedHeader": case "OldExtendedHeader": this.meta = true; break; default: this.ignore = true; } if (!t.path) throw new Error("no path provided for tar.ReadEntry"); this.path = f(t.path), this.mode = t.mode, this.mode && (this.mode = this.mode & 4095), this.uid = t.uid, this.gid = t.gid, this.uname = t.uname, this.gname = t.gname, this.size = this.remain, this.mtime = t.mtime, this.atime = t.atime, this.ctime = t.ctime, this.linkpath = t.linkpath ? f(t.linkpath) : void 0, this.uname = t.uname, this.gname = t.gname, e && this.#t(e), i && this.#t(i, true); } write(t) { let e = t.length; if (e > this.blockRemain) throw new Error("writing more to entry than is appropriate"); let i = this.remain, r = this.blockRemain; return this.remain = Math.max(0, i - e), this.blockRemain = Math.max(0, r - e), this.ignore ? true : i >= e ? super.write(t) : super.write(t.subarray(0, i)); } #t(t, e = false) { t.path && (t.path = f(t.path)), t.linkpath && (t.linkpath = f(t.linkpath)), Object.assign(this, Object.fromEntries(Object.entries(t).filter(([i, r]) => !(r == null || i === "path" && e)))); } }; var Dt = (s3, t, e, i = {}) => { s3.file && (i.file = s3.file), s3.cwd && (i.cwd = s3.cwd), i.code = e instanceof Error && e.code || t, i.tarCode = t, !s3.strict && i.recoverable !== false ? (e instanceof Error && (i = Object.assign(e, i), e = e.message), s3.emit("warn", t, e, i)) : e instanceof Error ? s3.emit("error", Object.assign(e, i)) : s3.emit("error", Object.assign(new Error(`${t}: ${e}`), i)); }; var An = 1024 * 1024; var Xi = Buffer.from([31, 139]); var qi = Buffer.from([40, 181, 47, 253]); var In = Math.max(Xi.length, qi.length); var B = /* @__PURE__ */ Symbol("state"); var Nt = /* @__PURE__ */ Symbol("writeEntry"); var it = /* @__PURE__ */ Symbol("readEntry"); var Zi = /* @__PURE__ */ Symbol("nextEntry"); var Zs = /* @__PURE__ */ Symbol("processEntry"); var $ = /* @__PURE__ */ Symbol("extendedHeader"); var he = /* @__PURE__ */ Symbol("globalExtendedHeader"); var dt = /* @__PURE__ */ Symbol("meta"); var Ys = /* @__PURE__ */ Symbol("emitMeta"); var p = /* @__PURE__ */ Symbol("buffer"); var st = /* @__PURE__ */ Symbol("queue"); var mt = /* @__PURE__ */ Symbol("ended"); var Yi = /* @__PURE__ */ Symbol("emittedEnd"); var At = /* @__PURE__ */ Symbol("emit"); var w = /* @__PURE__ */ Symbol("unzip"); var Xe = /* @__PURE__ */ Symbol("consumeChunk"); var qe = /* @__PURE__ */ Symbol("consumeChunkSub"); var Ki = /* @__PURE__ */ Symbol("consumeBody"); var Ks = /* @__PURE__ */ Symbol("consumeMeta"); var $s = /* @__PURE__ */ Symbol("consumeHeader"); var ae = /* @__PURE__ */ Symbol("consuming"); var $i = /* @__PURE__ */ Symbol("bufferConcat"); var Qe = /* @__PURE__ */ Symbol("maybeEnd"); var Yt = /* @__PURE__ */ Symbol("writing"); var V = /* @__PURE__ */ Symbol("aborted"); var Je = /* @__PURE__ */ Symbol("onDone"); var It = /* @__PURE__ */ Symbol("sawValidEntry"); var je = /* @__PURE__ */ Symbol("sawNullBlock"); var ti = /* @__PURE__ */ Symbol("sawEOF"); var Vs = /* @__PURE__ */ Symbol("closeStream"); var Cn = 1e3; var le = /* @__PURE__ */ Symbol("compressedBytesRead"); var Vi = /* @__PURE__ */ Symbol("decompressedBytesRead"); var Xs = /* @__PURE__ */ Symbol("checkDecompressionRatio"); var Fn = () => true; var rt = class extends import_events2.EventEmitter { file; strict; maxMetaEntrySize; filter; brotli; zstd; maxDecompressionRatio; writable = true; readable = false; [st] = []; [p]; [it]; [Nt]; [B] = "begin"; [dt] = ""; [$]; [he]; [mt] = false; [w]; [V] = false; [It]; [je] = false; [ti] = false; [Yt] = false; [ae] = false; [Yi] = false; [le] = 0; [Vi] = 0; constructor(t = {}) { super(), this.file = t.file || "", this.on(Je, () => { (this[B] === "begin" || this[It] === false) && this.warn("TAR_BAD_ARCHIVE", "Unrecognized archive format"); }), t.ondone ? this.on(Je, t.ondone) : this.on(Je, () => { this.emit("prefinish"), this.emit("finish"), this.emit("end"); }), this.strict = !!t.strict, this.maxDecompressionRatio = typeof t.maxDecompressionRatio == "number" ? t.maxDecompressionRatio : Cn, this.maxMetaEntrySize = t.maxMetaEntrySize || An, this.filter = typeof t.filter == "function" ? t.filter : Fn; let e = t.file && (t.file.endsWith(".tar.br") || t.file.endsWith(".tbr")); this.brotli = !(t.gzip || t.zstd) && t.brotli !== void 0 ? t.brotli : e ? void 0 : false; let i = t.file && (t.file.endsWith(".tar.zst") || t.file.endsWith(".tzst")); this.zstd = !(t.gzip || t.brotli) && t.zstd !== void 0 ? t.zstd : i ? true : void 0, this.on("end", () => this[Vs]()), typeof t.onwarn == "function" && this.on("warn", t.onwarn), typeof t.onReadEntry == "function" && this.on("entry", t.onReadEntry); } warn(t, e, i = {}) { Dt(this, t, e, i); } [$s](t, e) { this[It] === void 0 && (this[It] = false); let i; try { i = new F(t, e, this[$], this[he]); } catch (r) { return this.warn("TAR_ENTRY_INVALID", r); } if (i.nullBlock) this[je] ? (this[ti] = true, this[B] === "begin" && (this[B] = "header"), this[At]("eof")) : (this[je] = true, this[At]("nullBlock")); else if (this[je] = false, !i.cksumValid) this.warn("TAR_ENTRY_INVALID", "checksum failure", { header: i }); else if (!i.path) this.warn("TAR_ENTRY_INVALID", "path is required", { header: i }); else { let r = i.type; if (/^(Symbolic)?Link$/.test(r) && !i.linkpath) this.warn("TAR_ENTRY_INVALID", "linkpath required", { header: i }); else if (!/^(Symbolic)?Link$/.test(r) && !/^(Global)?ExtendedHeader$/.test(r) && i.linkpath) this.warn("TAR_ENTRY_INVALID", "linkpath forbidden", { header: i }); else { let n = this[Nt] = new Ve(i, this[$], this[he]); if (!this[It]) if (n.remain) { let o = () => { n.invalid || (this[It] = true); }; n.on("end", o); } else this[It] = true; n.meta ? n.size > this.maxMetaEntrySize ? (n.ignore = true, this[At]("ignoredEntry", n), this[B] = "ignore", n.resume()) : n.size > 0 && (this[dt] = "", n.on("data", (o) => this[dt] += o), this[B] = "meta") : (this[$] = void 0, n.ignore = n.ignore || !this.filter(n.path, n), n.ignore ? (this[At]("ignoredEntry", n), this[B] = n.remain ? "ignore" : "header", n.resume()) : (n.remain ? this[B] = "body" : (this[B] = "header", n.end()), this[it] ? this[st].push(n) : (this[st].push(n), this[Zi]()))); } } } [Vs]() { queueMicrotask(() => this.emit("close")); } [Zs](t) { let e = true; if (!t) this[it] = void 0, e = false; else if (Array.isArray(t)) { let [i, ...r] = t; this.emit(i, ...r); } else this[it] = t, this.emit("entry", t), t.emittedEnd || (t.on("end", () => this[Zi]()), e = false); return e; } [Zi]() { do ; while (this[Zs](this[st].shift())); if (this[st].length === 0) { let t = this[it]; !t || t.flowing || t.size === t.remain ? this[Yt] || this.emit("drain") : t.once("drain", () => this.emit("drain")); } } [Ki](t, e) { let i = this[Nt]; if (!i) throw new Error("attempt to consume body without entry??"); let r = i.blockRemain ?? 0, n = r >= t.length && e === 0 ? t : t.subarray(e, e + r); return i.write(n), i.blockRemain || (this[B] = "header", this[Nt] = void 0, i.end()), n.length; } [Ks](t, e) { let i = this[Nt], r = this[Ki](t, e); return !this[Nt] && i && this[Ys](i), r; } [At](t, e, i) { this[st].length === 0 && !this[it] ? this.emit(t, e, i) : this[st].push([t, e, i]); } [Ys](t) { switch (this[At]("meta", this[dt]), t.type) { case "ExtendedHeader": case "OldExtendedHeader": this[$] = ft.parse(this[dt], this[$], false); break; case "GlobalExtendedHeader": this[he] = ft.parse(this[dt], this[he], true); break; case "NextFileHasLongPath": case "OldGnuLongPath": { let e = this[$] ?? /* @__PURE__ */ Object.create(null); this[$] = e, e.path = this[dt].replace(/\0.*/, ""); break; } case "NextFileHasLongLinkpath": { let e = this[$] || /* @__PURE__ */ Object.create(null); this[$] = e, e.linkpath = this[dt].replace(/\0.*/, ""); break; } default: throw new Error("unknown meta: " + t.type); } } abort(t) { if (!this[V]) { if (this[w]) { let e = this[w]; e.write = () => true, e.end = () => e, e.emit = () => false, e.destroy?.(); } this[V] = true, this.emit("abort", t), this.warn("TAR_ABORT", t, { recoverable: false }); } } [Xs](t) { this[Vi] += t.length; let e = this[Vi] / this[le]; return e > this.maxDecompressionRatio ? (this.abort(new Error(`max decompression ratio exceeded: ${e.toFixed(2)} > ${this.maxDecompressionRatio}`)), false) : true; } write(t, e, i) { if (typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, typeof e == "string" ? e : "utf8")), this[V]) return i?.(), false; if ((this[w] === void 0 || this.brotli === void 0 && this[w] === false) && t) { if (this[p] && (t = Buffer.concat([this[p], t]), this[p] = void 0), t.length < In) return this[p] = t, i?.(), true; for (let a = 0; this[w] === void 0 && a < Xi.length; a++) t[a] !== Xi[a] && (this[w] = false); let o = false; if (this[w] === false && this.zstd !== false) { o = true; for (let a = 0; a < qi.length; a++) if (t[a] !== qi[a]) { o = false; break; } } let h = this.brotli === void 0 && !o; if (this[w] === false && h) if (t.length < 512) if (this[mt]) this.brotli = true; else return this[p] = t, i?.(), true; else try { new F(t.subarray(0, 512)), this.brotli = false; } catch { this.brotli = true; } if (this[w] === void 0 || this[w] === false && (this.brotli || o)) { let a = this[mt]; this[mt] = false, this[w] = this[w] === void 0 ? new Ue({}) : o ? new Ke({}) : new Ge({}), this[w].on("data", (c) => { this[Xs](c) && this[Xe](c); }), this[w].on("error", (c) => { this[V] || this.abort(c); }), this[w].on("end", () => { this[mt] = true, this[Xe](); }), this[Yt] = true, this[le] += t.length; let l = !!this[w][a ? "end" : "write"](t); return this[Yt] = false, i?.(), l; } } this[Yt] = true, this[w] ? (this[le] += t.length, this[w].write(t)) : this[Xe](t), this[Yt] = false; let n = this[st].length > 0 ? false : this[it] ? this[it].flowing : true; return !n && this[st].length === 0 && this[it]?.once("drain", () => this.emit("drain")), i?.(), n; } [$i](t) { t && !this[V] && (this[p] = this[p] ? Buffer.concat([this[p], t]) : t); } [Qe]() { if (this[mt] && !this[Yi] && !this[V] && !this[ae]) { this[Yi] = true; let t = this[Nt]; if (t?.blockRemain) { let e = this[p] ? this[p].length : 0; this.warn("TAR_BAD_ARCHIVE", `Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`, { entry: t }), this[p] && t.write(this[p]), t.end(); } this[At](Je); } } [Xe](t) { if (this[ae] && t) this[$i](t); else if (!t && !this[p]) this[Qe](); else if (t) { if (this[ae] = true, this[p]) { this[$i](t); let e = this[p]; this[p] = void 0, this[qe](e); } else this[qe](t); for (; this[p] && this[p]?.length >= 512 && !this[V] && !this[ti]; ) { let e = this[p]; this[p] = void 0, this[qe](e); } this[ae] = false; } (!this[p] || this[mt]) && this[Qe](); } [qe](t) { let e = 0, i = t.length; for (; e + 512 <= i && !this[V] && !this[ti]; ) switch (this[B]) { case "begin": case "header": this[$s](t, e), e += 512; break; case "ignore": case "body": e += this[Ki](t, e); break; case "meta": e += this[Ks](t, e); break; default: throw new Error("invalid state: " + this[B]); } e < i && (this[p] = this[p] ? Buffer.concat([t.subarray(e), this[p]]) : t.subarray(e)); } end(t, e, i) { return typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, e)), i && this.once("finish", i), this[V] || (this[w] ? (t && (this[le] += t.length, this[w].write(t)), this[w].end()) : (this[mt] = true, (this.brotli === void 0 || this.zstd === void 0) && (t = t || Buffer.alloc(0)), t && this.write(t), this[Qe]())), this; } }; var ut = (s3) => { let t = s3.length - 1, e = -1; for (; t > -1 && s3.charAt(t) === "/"; ) e = t, t--; return e === -1 ? s3 : s3.slice(0, e); }; var vn = (s3) => { let t = s3.onReadEntry; s3.onReadEntry = t ? (e) => { t(e), e.resume(); } : (e) => e.resume(); }; var Qi = (s3, t) => { let e = new Map(t.map((o) => [ut(o), true])), i = s3.filter, r = 100, n = (o, h = "", a = 0) => { if (a >= r) return e.set(o, false), false; let l = h || (0, import_path.parse)(o).root || ".", c; if (o === l) c = false; else { let d = e.get(o); c = d !== void 0 ? d : n((0, import_path.dirname)(o), l, a + 1); } return e.set(o, c), c; }; s3.filter = i ? (o, h) => i(o, h) && n(ut(o)) : (o) => n(ut(o)); }; var Bn = (s3) => { let t = new rt(s3), e = s3.file, i; try { i = import_node_fs.default.openSync(e, "r"); let r = import_node_fs.default.fstatSync(i), n = s3.maxReadSize || 16 * 1024 * 1024; if (r.size < n) { let o = Buffer.allocUnsafe(r.size), h = import_node_fs.default.readSync(i, o, 0, r.size, 0); t.end(h === o.byteLength ? o : o.subarray(0, h)); } else { let o = 0, h = Buffer.allocUnsafe(n); for (; o < r.size; ) { let a = import_node_fs.default.readSync(i, h, 0, n, o); if (a === 0) break; o += a, t.write(h.subarray(0, a)); } t.end(); } } finally { if (typeof i == "number") try { import_node_fs.default.closeSync(i); } catch { } } }; var Pn = (s3, t) => { let e = new rt(s3), i = s3.maxReadSize || 16 * 1024 * 1024, r = s3.file; return new Promise((o, h) => { e.on("error", h), e.on("end", o), import_node_fs.default.stat(r, (a, l) => { if (a) h(a); else { let c = new _t(r, { readSize: i, size: l.size }); c.on("error", h), c.pipe(e); } }); }); }; var Ct = K(Bn, Pn, (s3) => new rt(s3), (s3) => new rt(s3), (s3, t) => { t?.length && Qi(s3, t), s3.noResume || vn(s3); }); var Ji = (s3, t, e) => (s3 &= 4095, e && (s3 = (s3 | 384) & -19), t && (s3 & 256 && (s3 |= 64), s3 & 32 && (s3 |= 8), s3 & 4 && (s3 |= 1)), s3); var { isAbsolute: Un, parse: qs } = import_node_path4.win32; var ce = (s3) => { let t = "", e = qs(s3); for (; Un(s3) || e.root; ) { let i = s3.charAt(0) === "/" && s3.slice(0, 4) !== "//?/" ? "/" : e.root; s3 = s3.slice(i.length), t += i, e = qs(s3); } return [t, s3]; }; var ei = ["|", "<", ">", "?", ":"]; var ji = ei.map((s3) => String.fromCodePoint(61440 + Number(s3.codePointAt(0)))); var Hn = new Map(ei.map((s3, t) => [s3, ji[t]])); var Wn = new Map(ji.map((s3, t) => [s3, ei[t]])); var ts = (s3) => ei.reduce((t, e) => t.split(e).join(Hn.get(e)), s3); var Qs = (s3) => ji.reduce((t, e) => t.split(e).join(Wn.get(e)), s3); var rr = (s3, t) => t ? (s3 = f(s3).replace(/^\.(\/|$)/, ""), ut(t) + "/" + s3) : f(s3); var Gn = 16 * 1024 * 1024; var tr = /* @__PURE__ */ Symbol("process"); var er = /* @__PURE__ */ Symbol("file"); var ir = /* @__PURE__ */ Symbol("directory"); var is = /* @__PURE__ */ Symbol("symlink"); var sr = /* @__PURE__ */ Symbol("hardlink"); var fe = /* @__PURE__ */ Symbol("header"); var ii = /* @__PURE__ */ Symbol("read"); var ss = /* @__PURE__ */ Symbol("lstat"); var si = /* @__PURE__ */ Symbol("onlstat"); var rs = /* @__PURE__ */ Symbol("onread"); var ns = /* @__PURE__ */ Symbol("onreadlink"); var os = /* @__PURE__ */ Symbol("openfile"); var hs = /* @__PURE__ */ Symbol("onopenfile"); var pt = /* @__PURE__ */ Symbol("close"); var ri = /* @__PURE__ */ Symbol("mode"); var as = /* @__PURE__ */ Symbol("awaitDrain"); var es = /* @__PURE__ */ Symbol("ondrain"); var q = /* @__PURE__ */ Symbol("prefix"); var de = class extends A { path; portable; myuid = process.getuid && process.getuid() || 0; myuser = process.env.USER || ""; maxReadSize; linkCache; statCache; preservePaths; cwd; strict; mtime; noPax; noMtime; prefix; fd; blockLen = 0; blockRemain = 0; buf; pos = 0; remain = 0; length = 0; offset = 0; win32; absolute; header; type; linkpath; stat; onWriteEntry; #t = false; constructor(t, e = {}) { let i = se(e); super(), this.path = f(t), this.portable = !!i.portable, this.maxReadSize = i.maxReadSize || Gn, this.linkCache = i.linkCache || /* @__PURE__ */ new Map(), this.statCache = i.statCache || /* @__PURE__ */ new Map(), this.preservePaths = !!i.preservePaths, this.cwd = f(i.cwd || process.cwd()), this.strict = !!i.strict, this.noPax = !!i.noPax, this.noMtime = !!i.noMtime, this.mtime = i.mtime, this.prefix = i.prefix ? f(i.prefix) : void 0, this.onWriteEntry = i.onWriteEntry, typeof i.onwarn == "function" && this.on("warn", i.onwarn); let r = false; if (!this.preservePaths) { let [o, h] = ce(this.path); o && typeof h == "string" && (this.path = h, r = o); } this.win32 = !!i.win32 || process.platform === "win32", this.win32 && (this.path = Qs(this.path.replaceAll(/\\/g, "/")), t = t.replaceAll(/\\/g, "/")), this.absolute = f(i.absolute || import_path2.default.resolve(this.cwd, t)), this.path === "" && (this.path = "./"), r && this.warn("TAR_ENTRY_INFO", `stripping ${r} from absolute path`, { entry: this, path: r + this.path }); let n = this.statCache.get(this.absolute); n ? this[si](n) : this[ss](); } warn(t, e, i = {}) { return Dt(this, t, e, i); } emit(t, ...e) { return t === "error" && (this.#t = true), super.emit(t, ...e); } [ss]() { import_fs3.default.lstat(this.absolute, (t, e) => { if (t) return this.emit("error", t); this[si](e); }); } [si](t) { this.statCache.set(this.absolute, t), this.stat = t, t.isFile() || (t.size = 0), this.type = Zn(t), this.emit("stat", t), this[tr](); } [tr]() { switch (this.type) { case "File": return this[er](); case "Directory": return this[ir](); case "SymbolicLink": return this[is](); default: return this.end(); } } [ri](t) { return Ji(t, this.type === "Directory", this.portable); } [q](t) { return rr(t, this.prefix); } [fe]() { if (!this.stat) throw new Error("cannot write header before stat"); this.type === "Directory" && this.portable && (this.noMtime = true), this.onWriteEntry?.(this), this.header = new F({ path: this[q](this.path), linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[q](this.linkpath) : this.linkpath, mode: this[ri](this.stat.mode), uid: this.portable ? void 0 : this.stat.uid, gid: this.portable ? void 0 : this.stat.gid, size: this.stat.size, mtime: this.noMtime ? void 0 : this.mtime || this.stat.mtime, type: this.type === "Unsupported" ? void 0 : this.type, uname: this.portable ? void 0 : this.stat.uid === this.myuid ? this.myuser : "", atime: this.portable ? void 0 : this.stat.atime, ctime: this.portable ? void 0 : this.stat.ctime }), this.header.encode() && !this.noPax && super.write(new ft({ atime: this.portable ? void 0 : this.header.atime, ctime: this.portable ? void 0 : this.header.ctime, gid: this.portable ? void 0 : this.header.gid, mtime: this.noMtime ? void 0 : this.mtime || this.header.mtime, path: this[q](this.path), linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[q](this.linkpath) : this.linkpath, size: this.header.size, uid: this.portable ? void 0 : this.header.uid, uname: this.portable ? void 0 : this.header.uname, dev: this.portable ? void 0 : this.stat.dev, ino: this.portable ? void 0 : this.stat.ino, nlink: this.portable ? void 0 : this.stat.nlink }).encode()); let t = this.header?.block; if (!t) throw new Error("failed to encode header"); super.write(t); } [ir]() { if (!this.stat) throw new Error("cannot create directory entry without stat"); this.path.slice(-1) !== "/" && (this.path += "/"), this.stat.size = 0, this[fe](), this.end(); } [is]() { import_fs3.default.readlink(this.absolute, (t, e) => { if (t) return this.emit("error", t); this[ns](e); }); } [ns](t) { this.linkpath = f(t), this[fe](), this.end(); } [sr](t) { if (!this.stat) throw new Error("cannot create link entry without stat"); this.type = "Link", this.linkpath = f(import_path2.default.relative(this.cwd, t)), this.stat.size = 0, this[fe](), this.end(); } [er]() { if (!this.stat) throw new Error("cannot create file entry without stat"); if (this.stat.nlink > 1) { let t = `${this.stat.dev}:${this.stat.ino}`, e = this.linkCache.get(t); if (e?.indexOf(this.cwd) === 0) return this[sr](e); this.linkCache.set(t, this.absolute); } if (this[fe](), this.stat.size === 0) return this.end(); this[os](); } [os]() { import_fs3.default.open(this.absolute, "r", (t, e) => { if (t) return this.emit("error", t); this[hs](e); }); } [hs](t) { if (this.fd = t, this.#t) return this[pt](); if (!this.stat) throw new Error("should stat before calling onopenfile"); this.blockLen = 512 * Math.ceil(this.stat.size / 512), this.blockRemain = this.blockLen; let e = Math.min(this.blockLen, this.maxReadSize); this.buf = Buffer.allocUnsafe(e), this.offset = 0, this.pos = 0, this.remain = this.stat.size, this.length = this.buf.length, this[ii](); } [ii]() { let { fd: t, buf: e, offset: i, length: r, pos: n } = this; if (t === void 0 || e === void 0) throw new Error("cannot read file without first opening"); import_fs3.default.read(t, e, i, r, n, (o, h) => { if (o) return this[pt](() => this.emit("error", o)); this[rs](h); }); } [pt](t = () => { }) { this.fd !== void 0 && import_fs3.default.close(this.fd, t); } [rs](t) { if (t <= 0 && this.remain > 0) { let r = Object.assign(new Error("encountered unexpected EOF"), { path: this.absolute, syscall: "read", code: "EOF" }); return this[pt](() => this.emit("error", r)); } if (t > this.remain) { let r = Object.assign(new Error("did not encounter expected EOF"), { path: this.absolute, syscall: "read", code: "EOF" }); return this[pt](() => this.emit("error", r)); } if (!this.buf) throw new Error("should have created buffer prior to reading"); if (t === this.remain) for (let r = t; r < this.length && t < this.blockRemain; r++) this.buf[r + this.offset] = 0, t++, this.remain++; let e = this.offset === 0 && t === this.buf.length ? this.buf : this.buf.subarray(this.offset, this.offset + t); this.write(e) ? this[es]() : this[as](() => this[es]()); } [as](t) { this.once("drain", t); } write(t, e, i) { if (typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, typeof e == "string" ? e : "utf8")), this.blockRemain < t.length) { let r = Object.assign(new Error("writing more data than expected"), { path: this.absolute }); return this.emit("error", r); } return this.remain -= t.length, this.blockRemain -= t.length, this.pos += t.length, this.offset += t.length, super.write(t, null, i); } [es]() { if (!this.remain) return this.blockRemain && super.write(Buffer.alloc(this.blockRemain)), this[pt]((t) => t ? this.emit("error", t) : this.end()); if (!this.buf) throw new Error("buffer lost somehow in ONDRAIN"); this.offset >= this.length && (this.buf = Buffer.allocUnsafe(Math.min(this.blockRemain, this.buf.length)), this.offset = 0), this.length = this.buf.length - this.offset, this[ii](); } }; var ni = class extends de { sync = true; [ss]() { this[si](import_fs3.default.lstatSync(this.absolute)); } [is]() { this[ns](import_fs3.default.readlinkSync(this.absolute)); } [os]() { this[hs](import_fs3.default.openSync(this.absolute, "r")); } [ii]() { let t = true; try { let { fd: e, buf: i, offset: r, length: n, pos: o } = this; if (e === void 0 || i === void 0) throw new Error("fd and buf must be set in READ method"); let h = import_fs3.default.readSync(e, i, r, n, o); this[rs](h), t = false; } finally { if (t) try { this[pt](() => { }); } catch { } } } [as](t) { t(); } [pt](t = () => { }) { this.fd !== void 0 && import_fs3.default.closeSync(this.fd), t(); } }; var oi = class extends A { blockLen = 0; blockRemain = 0; buf = 0; pos = 0; remain = 0; length = 0; preservePaths; portable; strict; noPax; noMtime; readEntry; type; prefix; path; mode; uid; gid; uname; gname; header; mtime; atime; ctime; linkpath; size; onWriteEntry; warn(t, e, i = {}) { return Dt(this, t, e, i); } constructor(t, e = {}) { let i = se(e); super(), this.preservePaths = !!i.preservePaths, this.portable = !!i.portable, this.strict = !!i.strict, this.noPax = !!i.noPax, this.noMtime = !!i.noMtime, this.onWriteEntry = i.onWriteEntry, this.readEntry = t; let { type: r } = t; if (r === "Unsupported") throw new Error("writing entry that should be ignored"); this.type = r, this.type === "Directory" && this.portable && (this.noMtime = true), this.prefix = i.prefix, this.path = f(t.path), this.mode = t.mode !== void 0 ? this[ri](t.mode) : void 0, this.uid = this.portable ? void 0 : t.uid, this.gid = this.portable ? void 0 : t.gid, this.uname = this.portable ? void 0 : t.uname, this.gname = this.portable ? void 0 : t.gname, this.size = t.size, this.mtime = this.noMtime ? void 0 : i.mtime || t.mtime, this.atime = this.portable ? void 0 : t.atime, this.ctime = this.portable ? void 0 : t.ctime, this.linkpath = t.linkpath !== void 0 ? f(t.linkpath) : void 0, typeof i.onwarn == "function" && this.on("warn", i.onwarn); let n = false; if (!this.preservePaths) { let [h, a] = ce(this.path); h && typeof a == "string" && (this.path = a, n = h); } this.remain = t.size, this.blockRemain = t.startBlockSize, this.onWriteEntry?.(this), this.header = new F({ path: this[q](this.path), linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[q](this.linkpath) : this.linkpath, mode: this.mode, uid: this.portable ? void 0 : this.uid, gid: this.portable ? void 0 : this.gid, size: this.size, mtime: this.noMtime ? void 0 : this.mtime, type: this.type, uname: this.portable ? void 0 : this.uname, atime: this.portable ? void 0 : this.atime, ctime: this.portable ? void 0 : this.ctime }), n && this.warn("TAR_ENTRY_INFO", `stripping ${n} from absolute path`, { entry: this, path: n + this.path }), this.header.encode() && !this.noPax && super.write(new ft({ atime: this.portable ? void 0 : this.atime, ctime: this.portable ? void 0 : this.ctime, gid: this.portable ? void 0 : this.gid, mtime: this.noMtime ? void 0 : this.mtime, path: this[q](this.path), linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[q](this.linkpath) : this.linkpath, size: this.size, uid: this.portable ? void 0 : this.uid, uname: this.portable ? void 0 : this.uname, dev: this.portable ? void 0 : this.readEntry.dev, ino: this.portable ? void 0 : this.readEntry.ino, nlink: this.portable ? void 0 : this.readEntry.nlink }).encode()); let o = this.header?.block; if (!o) throw new Error("failed to encode header"); super.write(o), t.pipe(this); } [q](t) { return rr(t, this.prefix); } [ri](t) { return Ji(t, this.type === "Directory", this.portable); } write(t, e, i) { typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, typeof e == "string" ? e : "utf8")); let r = t.length; if (r > this.blockRemain) throw new Error("writing more to entry than is appropriate"); return this.blockRemain -= r, super.write(t, i); } end(t, e, i) { return this.blockRemain && super.write(Buffer.alloc(this.blockRemain)), typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, e ?? "utf8")), i && this.once("finish", i), t ? super.end(t, i) : super.end(i), this; } }; var Zn = (s3) => s3.isFile() ? "File" : s3.isDirectory() ? "Directory" : s3.isSymbolicLink() ? "SymbolicLink" : "Unsupported"; var hi = class s2 { tail; head; length = 0; static create(t = []) { return new s2(t); } constructor(t = []) { for (let e of t) this.push(e); } *[Symbol.iterator]() { for (let t = this.head; t; t = t.next) yield t.value; } removeNode(t) { if (t.list !== this) throw new Error("removing node which does not belong to this list"); let e = t.next, i = t.prev; return e && (e.prev = i), i && (i.next = e), t === this.head && (this.head = e), t === this.tail && (this.tail = i), this.length--, t.next = void 0, t.prev = void 0, t.list = void 0, e; } unshiftNode(t) { if (t === this.head) return; t.list && t.list.removeNode(t); let e = this.head; t.list = this, t.next = e, e && (e.prev = t), this.head = t, this.tail || (this.tail = t), this.length++; } pushNode(t) { if (t === this.tail) return; t.list && t.list.removeNode(t); let e = this.tail; t.list = this, t.prev = e, e && (e.next = t), this.tail = t, this.head || (this.head = t), this.length++; } push(...t) { for (let e = 0, i = t.length; e < i; e++) Kn(this, t[e]); return this.length; } unshift(...t) { for (var e = 0, i = t.length; e < i; e++) $n(this, t[e]); return this.length; } pop() { if (!this.tail) return; let t = this.tail.value, e = this.tail; return this.tail = this.tail.prev, this.tail ? this.tail.next = void 0 : this.head = void 0, e.list = void 0, this.length--, t; } shift() { if (!this.head) return; let t = this.head.value, e = this.head; return this.head = this.head.next, this.head ? this.head.prev = void 0 : this.tail = void 0, e.list = void 0, this.length--, t; } forEach(t, e) { e = e || this; for (let i = this.head, r = 0; i; r++) t.call(e, i.value, r, this), i = i.next; } forEachReverse(t, e) { e = e || this; for (let i = this.tail, r = this.length - 1; i; r--) t.call(e, i.value, r, this), i = i.prev; } get(t) { let e = 0, i = this.head; for (; i && e < t; e++) i = i.next; if (e === t && i) return i.value; } getReverse(t) { let e = 0, i = this.tail; for (; i && e < t; e++) i = i.prev; if (e === t && i) return i.value; } map(t, e) { e = e || this; let i = new s2(); for (let r = this.head; r; ) i.push(t.call(e, r.value, this)), r = r.next; return i; } mapReverse(t, e) { e = e || this; var i = new s2(); for (let r = this.tail; r; ) i.push(t.call(e, r.value, this)), r = r.prev; return i; } reduce(t, e) { let i, r = this.head; if (arguments.length > 1) i = e; else if (this.head) r = this.head.next, i = this.head.value; else throw new TypeError("Reduce of empty list with no initial value"); for (var n = 0; r; n++) i = t(i, r.value, n), r = r.next; return i; } reduceReverse(t, e) { let i, r = this.tail; if (arguments.length > 1) i = e; else if (this.tail) r = this.tail.prev, i = this.tail.value; else throw new TypeError("Reduce of empty list with no initial value"); for (let n = this.length - 1; r; n--) i = t(i, r.value, n), r = r.prev; return i; } toArray() { let t = new Array(this.length); for (let e = 0, i = this.head; i; e++) t[e] = i.value, i = i.next; return t; } toArrayReverse() { let t = new Array(this.length); for (let e = 0, i = this.tail; i; e++) t[e] = i.value, i = i.prev; return t; } slice(t = 0, e = this.length) { e < 0 && (e += this.length), t < 0 && (t += this.length); let i = new s2(); if (e < t || e < 0) return i; t < 0 && (t = 0), e > this.length && (e = this.length); let r = this.head, n = 0; for (n = 0; r && n < t; n++) r = r.next; for (; r && n < e; n++, r = r.next) i.push(r.value); return i; } sliceReverse(t = 0, e = this.length) { e < 0 && (e += this.length), t < 0 && (t += this.length); let i = new s2(); if (e < t || e < 0) return i; t < 0 && (t = 0), e > this.length && (e = this.length); let r = this.length, n = this.tail; for (; n && r > e; r--) n = n.prev; for (; n && r > t; r--, n = n.prev) i.push(n.value); return i; } splice(t, e = 0, ...i) { t > this.length && (t = this.length - 1), t < 0 && (t = this.length + t); let r = this.head; for (let o = 0; r && o < t; o++) r = r.next; let n = []; for (let o = 0; r && o < e; o++) n.push(r.value), r = this.removeNode(r); r ? r !== this.tail && (r = r.prev) : r = this.tail; for (let o of i) r = Yn(this, r, o); return n; } reverse() { let t = this.head, e = this.tail; for (let i = t; i; i = i.prev) { let r = i.prev; i.prev = i.next, i.next = r; } return this.head = e, this.tail = t, this; } }; function Yn(s3, t, e) { let i = t, r = t ? t.next : s3.head, n = new me(e, i, r, s3); return n.next === void 0 && (s3.tail = n), n.prev === void 0 && (s3.head = n), s3.length++, n; } function Kn(s3, t) { s3.tail = new me(t, s3.tail, void 0, s3), s3.head || (s3.head = s3.tail), s3.length++; } function $n(s3, t) { s3.head = new me(t, void 0, s3.head, s3), s3.tail || (s3.tail = s3.head), s3.length++; } var me = class { list; next; prev; value; constructor(t, e, i, r) { this.list = r, this.value = t, e ? (e.next = this, this.prev = e) : this.prev = void 0, i ? (i.prev = this, this.next = i) : this.next = void 0; } }; var pi = class { path; absolute; entry; stat; readdir; pending = false; pendingLink = false; ignore = false; piped = false; constructor(t, e) { this.path = t || "./", this.absolute = e; } }; var nr = Buffer.alloc(1024); var li = /* @__PURE__ */ Symbol("onStat"); var ue = /* @__PURE__ */ Symbol("ended"); var W = /* @__PURE__ */ Symbol("queue"); var pe = /* @__PURE__ */ Symbol("pendingLinks"); var Et = /* @__PURE__ */ Symbol("current"); var Ft = /* @__PURE__ */ Symbol("process"); var Ee = /* @__PURE__ */ Symbol("processing"); var ai = /* @__PURE__ */ Symbol("processJob"); var G = /* @__PURE__ */ Symbol("jobs"); var ls = /* @__PURE__ */ Symbol("jobDone"); var ci = /* @__PURE__ */ Symbol("addFSEntry"); var or = /* @__PURE__ */ Symbol("addTarEntry"); var ds = /* @__PURE__ */ Symbol("stat"); var ms = /* @__PURE__ */ Symbol("readdir"); var fi = /* @__PURE__ */ Symbol("onreaddir"); var di = /* @__PURE__ */ Symbol("pipe"); var hr = /* @__PURE__ */ Symbol("entry"); var cs = /* @__PURE__ */ Symbol("entryOpt"); var mi = /* @__PURE__ */ Symbol("writeEntryClass"); var lr = /* @__PURE__ */ Symbol("write"); var fs = /* @__PURE__ */ Symbol("ondrain"); var wt = class extends A { sync = false; opt; cwd; maxReadSize; preservePaths; strict; noPax; prefix; linkCache; statCache; file; portable; zip; readdirCache; noDirRecurse; follow; noMtime; mtime; filter; jobs; [mi]; onWriteEntry; [W]; [pe] = /* @__PURE__ */ new Map(); [G] = 0; [Ee] = false; [ue] = false; constructor(t = {}) { if (super(), this.opt = t, this.file = t.file || "", this.cwd = t.cwd || process.cwd(), this.maxReadSize = t.maxReadSize, this.preservePaths = !!t.preservePaths, this.strict = !!t.strict, this.noPax = !!t.noPax, this.prefix = f(t.prefix || ""), this.linkCache = t.linkCache || /* @__PURE__ */ new Map(), this.statCache = t.statCache || /* @__PURE__ */ new Map(), this.readdirCache = t.readdirCache || /* @__PURE__ */ new Map(), this.onWriteEntry = t.onWriteEntry, this[mi] = de, typeof t.onwarn == "function" && this.on("warn", t.onwarn), this.portable = !!t.portable, t.gzip || t.brotli || t.zstd) { if ((t.gzip ? 1 : 0) + (t.brotli ? 1 : 0) + (t.zstd ? 1 : 0) > 1) throw new TypeError("gzip, brotli, zstd are mutually exclusive"); if (t.gzip && (typeof t.gzip != "object" && (t.gzip = {}), this.portable && (t.gzip.portable = true), this.zip = new ze(t.gzip)), t.brotli && (typeof t.brotli != "object" && (t.brotli = {}), this.zip = new We(t.brotli)), t.zstd && (typeof t.zstd != "object" && (t.zstd = {}), this.zip = new Ye(t.zstd)), !this.zip) throw new Error("impossible"); let e = this.zip; e.on("data", (i) => super.write(i)), e.on("end", () => super.end()), e.on("drain", () => this[fs]()), this.on("resume", () => e.resume()); } else this.on("drain", this[fs]); this.noDirRecurse = !!t.noDirRecurse, this.follow = !!t.follow, this.noMtime = !!t.noMtime, t.mtime && (this.mtime = t.mtime), this.filter = typeof t.filter == "function" ? t.filter : () => true, this[W] = new hi(), this[G] = 0, this.jobs = Number(t.jobs) || 4, this[Ee] = false, this[ue] = false; } [lr](t) { return super.write(t); } add(t) { return this.write(t), this; } end(t, e, i) { return typeof t == "function" && (i = t, t = void 0), typeof e == "function" && (i = e, e = void 0), t && this.add(t), this[ue] = true, this[Ft](), i && i(), this; } write(t) { if (this[ue]) throw new Error("write after end"); return typeof t == "string" ? this[ci](t) : this[or](t), this.flowing; } [or](t) { let e = f(import_path3.default.resolve(this.cwd, t.path)); if (!this.filter(t.path, t)) t.resume(); else { let i = new pi(t.path, e); i.entry = new oi(t, this[cs](i)), i.entry.on("end", () => this[ls](i)), this[G] += 1, this[W].push(i); } this[Ft](); } [ci](t) { let e = f(import_path3.default.resolve(this.cwd, t)); this[W].push(new pi(t, e)), this[Ft](); } [ds](t) { t.pending = true, this[G] += 1; let e = this.follow ? "stat" : "lstat"; import_fs2.default[e](t.absolute, (i, r) => { t.pending = false, this[G] -= 1, i ? this.emit("error", i) : this[li](t, r); }); } [li](t, e) { if (this.statCache.set(t.absolute, e), t.stat = e, !this.filter(t.path, e)) t.ignore = true; else if (e.isFile() && e.nlink > 1 && !this.linkCache.get(`${e.dev}:${e.ino}`) && !this.sync) if (t === this[Et]) this[ai](t); else { let i = `${e.dev}:${e.ino}`, r = this[pe].get(i); r ? r.push(t) : this[pe].set(i, [t]), t.pendingLink = true, t.pending = true; } this[Ft](); } [ms](t) { t.pending = true, this[G] += 1, import_fs2.default.readdir(t.absolute, (e, i) => { if (t.pending = false, this[G] -= 1, e) return this.emit("error", e); this[fi](t, i); }); } [fi](t, e) { this.readdirCache.set(t.absolute, e), t.readdir = e, this[Ft](); } [Ft]() { if (!this[Ee]) { this[Ee] = true; for (let t = this[W].head; t && this[G] < this.jobs; t = t.next) if (this[ai](t.value), t.value.ignore) { let e = t.next; this[W].removeNode(t), t.next = e; } this[Ee] = false, this[ue] && this[W].length === 0 && this[G] === 0 && (this.zip ? this.zip.end(nr) : (super.write(nr), super.end())); } } get [Et]() { return this[W] && this[W].head && this[W].head.value; } [ls](t) { this[W].shift(), this[G] -= 1; let { stat: e } = t; if (e && e.isFile() && e.nlink > 1) { let i = `${e.dev}:${e.ino}`, r = this[pe].get(i); if (r) { this[pe].delete(i); for (let n of r) n.pending = false, this[ai](n); } } this[Ft](); } [ai](t) { if (t.pending && t.pendingLink && t === this[Et] && (t.pending = false, t.pendingLink = false), !t.pending) { if (t.entry) { t === this[Et] && !t.piped && this[di](t); return; } if (!t.stat) { let e = this.statCache.get(t.absolute); e ? this[li](t, e) : this[ds](t); } if (t.stat && !t.ignore) { if (!this.noDirRecurse && t.stat.isDirectory() && !t.readdir) { let e = this.readdirCache.get(t.absolute); if (e ? this[fi](t, e) : this[ms](t), !t.readdir) return; } if (t.entry = this[hr](t), !t.entry) { t.ignore = true; return; } t === this[Et] && !t.piped && this[di](t); } } } [cs](t) { return { onwarn: (e, i, r) => this.warn(e, i, r), noPax: this.noPax, cwd: this.cwd, absolute: t.absolute, preservePaths: this.preservePaths, maxReadSize: this.maxReadSize, strict: this.strict, portable: this.portable, linkCache: this.linkCache, statCache: this.statCache, noMtime: this.noMtime, mtime: this.mtime, prefix: this.prefix, onWriteEntry: this.onWriteEntry }; } [hr](t) { this[G] += 1; try { return new this[mi](t.path, this[cs](t)).on("end", () => this[ls](t)).on("error", (i) => this.emit("error", i)); } catch (e) { this.emit("error", e); } } [fs]() { this[Et] && this[Et].entry && this[Et].entry.resume(); } [di](t) { t.piped = true, t.readdir && t.readdir.forEach((r) => { let n = t.path, o = n === "./" ? "" : n.replace(/\/*$/, "/"); this[ci](o + r); }); let e = t.entry, i = this.zip; if (!e) throw new Error("cannot pipe without source"); i ? e.on("data", (r) => { i.write(r) || e.pause(); }) : e.on("data", (r) => { super.write(r) || e.pause(); }); } pause() { return this.zip && this.zip.pause(), super.pause(); } warn(t, e, i = {}) { Dt(this, t, e, i); } }; var kt = class extends wt { sync = true; constructor(t) { super(t), this[mi] = ni; } pause() { } resume() { } [ds](t) { let e = this.follow ? "statSync" : "lstatSync"; this[li](t, import_fs2.default[e](t.absolute)); } [ms](t) { this[fi](t, import_fs2.default.readdirSync(t.absolute)); } [di](t) { let e = t.entry, i = this.zip; if (t.readdir && t.readdir.forEach((r) => { let n = t.path, o = n === "./" ? "" : n.replace(/\/*$/, "/"); this[ci](o + r); }), !e) throw new Error("Cannot pipe without source"); i ? e.on("data", (r) => { i.write(r); }) : e.on("data", (r) => { super[lr](r); }); } }; var Vn = (s3, t) => { let e = new kt(s3), i = new Wt(s3.file, { mode: s3.mode || 438 }); e.pipe(i), fr(e, t); }; var Xn = (s3, t) => { let e = new wt(s3), i = new et(s3.file, { mode: s3.mode || 438 }); e.pipe(i); let r = new Promise((n, o) => { i.on("error", o), i.on("close", n), e.on("error", o); }); return dr(e, t).catch((n) => e.emit("error", n)), r; }; var fr = (s3, t) => { t.forEach((e) => { e.charAt(0) === "@" ? Ct({ file: import_node_path.default.resolve(s3.cwd, e.slice(1)), sync: true, noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e); }), s3.end(); }; var dr = async (s3, t) => { for (let e of t) e.charAt(0) === "@" ? await Ct({ file: import_node_path.default.resolve(String(s3.cwd), e.slice(1)), noResume: true, onReadEntry: (i) => { s3.add(i); } }) : s3.add(e); s3.end(); }; var qn = (s3, t) => { let e = new kt(s3); return fr(e, t), e; }; var Qn = (s3, t) => { let e = new wt(s3); return dr(e, t).catch((i) => e.emit("error", i)), e; }; var Jn = K(Vn, Xn, qn, Qn, (s3, t) => { if (!t?.length) throw new TypeError("no paths specified to add to archive"); }); var jn = process.env.__FAKE_PLATFORM__ || process.platform; var Er = jn === "win32"; var { O_CREAT: wr, O_NOFOLLOW: mr, O_TRUNC: Sr, O_WRONLY: yr } = import_fs4.default.constants; var Rr = Number(process.env.__FAKE_FS_O_FILENAME__) || import_fs4.default.constants.UV_FS_O_FILEMAP || 0; var to = Er && !!Rr; var eo = 512 * 1024; var io = Rr | Sr | wr | yr; var ur = !Er && typeof mr == "number" ? mr | Sr | wr | yr : null; var us = ur !== null ? () => ur : to ? (s3) => s3 < eo ? io : "w" : () => "w"; var ps = (s3, t, e) => { try { return import_node_fs4.default.lchownSync(s3, t, e); } catch (i) { if (i?.code !== "ENOENT") throw i; } }; var Ei = (s3, t, e, i) => { import_node_fs4.default.lchown(s3, t, e, (r) => { i(r && r?.code !== "ENOENT" ? r : null); }); }; var so = (s3, t, e, i, r) => { if (t.isDirectory()) Es(import_node_path6.default.resolve(s3, t.name), e, i, (n) => { if (n) return r(n); let o = import_node_path6.default.resolve(s3, t.name); Ei(o, e, i, r); }); else { let n = import_node_path6.default.resolve(s3, t.name); Ei(n, e, i, r); } }; var Es = (s3, t, e, i) => { import_node_fs4.default.readdir(s3, { withFileTypes: true }, (r, n) => { if (r) { if (r.code === "ENOENT") return i(); if (r.code !== "ENOTDIR" && r.code !== "ENOTSUP") return i(r); } if (r || !n.length) return Ei(s3, t, e, i); let o = n.length, h = null, a = (l) => { if (!h) { if (l) return i(h = l); if (--o === 0) return Ei(s3, t, e, i); } }; for (let l of n) so(s3, l, t, e, a); }); }; var ro = (s3, t, e, i) => { t.isDirectory() && ws(import_node_path6.default.resolve(s3, t.name), e, i), ps(import_node_path6.default.resolve(s3, t.name), e, i); }; var ws = (s3, t, e) => { let i; try { i = import_node_fs4.default.readdirSync(s3, { withFileTypes: true }); } catch (r) { let n = r; if (n?.code === "ENOENT") return; if (n?.code === "ENOTDIR" || n?.code === "ENOTSUP") return ps(s3, t, e); throw n; } for (let r of i) ro(s3, r, t, e); return ps(s3, t, e); }; var Se = class extends Error { path; code; syscall = "chdir"; constructor(t, e) { super(`${e}: Cannot cd into '${t}'`), this.path = t, this.code = e; } get name() { return "CwdError"; } }; var St = class extends Error { path; symlink; syscall = "symlink"; code = "TAR_SYMLINK_ERROR"; constructor(t, e) { super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"), this.symlink = t, this.path = e; } get name() { return "SymlinkError"; } }; var oo = (s3, t) => { import_node_fs5.default.stat(s3, (e, i) => { (e || !i.isDirectory()) && (e = new Se(s3, e?.code || "ENOTDIR")), t(e); }); }; var gr = (s3, t, e) => { s3 = f(s3); let i = t.umask ?? 18, r = t.mode | 448, n = (r & i) !== 0, o = t.uid, h = t.gid, a = typeof o == "number" && typeof h == "number" && (o !== t.processUid || h !== t.processGid), l = t.preserve, c = t.unlink, d = f(t.cwd), y = (E, x) => { E ? e(E) : x && a ? Es(x, o, h, (Le) => y(Le)) : n ? import_node_fs5.default.chmod(s3, r, e) : e(); }; if (s3 === d) return oo(s3, y); if (l) return import_promises.default.mkdir(s3, { mode: r, recursive: true }).then((E) => y(null, E ?? void 0), y); let D = f(import_node_path7.default.relative(d, s3)).split("/"); Ss(d, D, r, c, d, void 0, y); }; var Ss = (s3, t, e, i, r, n, o) => { if (t.length === 0) return o(null, n); let h = t.shift(), a = f(import_node_path7.default.resolve(s3 + "/" + h)); import_node_fs5.default.mkdir(a, e, br(a, t, e, i, r, n, o)); }; var br = (s3, t, e, i, r, n, o) => (h) => { h ? import_node_fs5.default.lstat(s3, (a, l) => { if (a) a.path = a.path && f(a.path), o(a); else if (l.isDirectory()) Ss(s3, t, e, i, r, n, o); else if (i) import_node_fs5.default.unlink(s3, (c) => { if (c) return o(c); import_node_fs5.default.mkdir(s3, e, br(s3, t, e, i, r, n, o)); }); else { if (l.isSymbolicLink()) return o(new St(s3, s3 + "/" + t.join("/"))); o(h); } }) : (n = n || s3, Ss(s3, t, e, i, r, n, o)); }; var ho = (s3) => { let t = false, e; try { t = import_node_fs5.default.statSync(s3).isDirectory(); } catch (i) { e = i?.code; } finally { if (!t) throw new Se(s3, e ?? "ENOTDIR"); } }; var _r = (s3, t) => { s3 = f(s3); let e = t.umask ?? 18, i = t.mode | 448, r = (i & e) !== 0, n = t.uid, o = t.gid, h = typeof n == "number" && typeof o == "number" && (n !== t.processUid || o !== t.processGid), a = t.preserve, l = t.unlink, c = f(t.cwd), d = (E) => { E && h && ws(E, n, o), r && import_node_fs5.default.chmodSync(s3, i); }; if (s3 === c) return ho(c), d(); if (a) return d(import_node_fs5.default.mkdirSync(s3, { mode: i, recursive: true }) ?? void 0); let T = f(import_node_path7.default.relative(c, s3)).split("/"), D; for (let E = T.shift(), x = c; E && (x += "/" + E); E = T.shift()) { x = f(import_node_path7.default.resolve(x)); try { import_node_fs5.default.mkdirSync(x, i), D = D || x; } catch { let Le = import_node_fs5.default.lstatSync(x); if (Le.isDirectory()) continue; if (l) { import_node_fs5.default.unlinkSync(x), import_node_fs5.default.mkdirSync(x, i), D = D || x; continue; } else if (Le.isSymbolicLink()) return new St(x, x + "/" + T.join("/")); } } return d(D); }; var ys = /* @__PURE__ */ Object.create(null); var Or = 1e4; var $t = /* @__PURE__ */ new Set(); var Tr = (s3) => { $t.has(s3) ? $t.delete(s3) : ys[s3] = s3.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"), $t.add(s3); let t = ys[s3], e = $t.size - Or; if (e > Or / 10) { for (let i of $t) if ($t.delete(i), delete ys[i], --e <= 0) break; } return t; }; var ao = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform; var lo = ao === "win32"; var co = (s3) => s3.split("/").slice(0, -1).reduce((e, i) => { let r = e.at(-1); return r !== void 0 && (i = (0, import_node_path8.join)(r, i)), e.push(i || "/"), e; }, []); var yi = class { #t = /* @__PURE__ */ new Map(); #i = /* @__PURE__ */ new Map(); #s = /* @__PURE__ */ new Set(); reserve(t, e) { t = lo ? ["win32 parallelization disabled"] : t.map((r) => ut((0, import_node_path8.join)(Tr(r)))); let i = new Set(t.map((r) => co(r)).reduce((r, n) => r.concat(n))); this.#i.set(e, { dirs: i, paths: t }); for (let r of t) { let n = this.#t.get(r); n ? n.push(e) : this.#t.set(r, [e]); } for (let r of i) { let n = this.#t.get(r); if (!n) this.#t.set(r, [/* @__PURE__ */ new Set([e])]); else { let o = n.at(-1); o instanceof Set ? o.add(e) : n.push(/* @__PURE__ */ new Set([e])); } } return this.#r(e); } #n(t) { let e = this.#i.get(t); if (!e) throw new Error("function does not have any path reservations"); return { paths: e.paths.map((i) => this.#t.get(i)), dirs: [...e.dirs].map((i) => this.#t.get(i)) }; } check(t) { let { paths: e, dirs: i } = this.#n(t); return e.every((r) => r && r[0] === t) && i.every((r) => r && r[0] instanceof Set && r[0].has(t)); } #r(t) { return this.#s.has(t) || !this.check(t) ? false : (this.#s.add(t), t(() => this.#e(t)), true); } #e(t) { if (!this.#s.has(t)) return false; let e = this.#i.get(t); if (!e) throw new Error("invalid reservation"); let { paths: i, dirs: r } = e, n = /* @__PURE__ */ new Set(); for (let o of i) { let h = this.#t.get(o); if (!h || h?.[0] !== t) continue; let a = h[1]; if (!a) { this.#t.delete(o); continue; } if (h.shift(), typeof a == "function") n.add(a); else for (let l of a) n.add(l); } for (let o of r) { let h = this.#t.get(o), a = h?.[0]; if (!(!h || !(a instanceof Set))) if (a.size === 1 && h.length === 1) { this.#t.delete(o); continue; } else if (a.size === 1) { h.shift(); let l = h[0]; typeof l == "function" && n.add(l); } else a.delete(t); } return this.#s.delete(t), n.forEach((o) => this.#r(o)), true; } }; var Lr = () => process.umask(); var Dr = /* @__PURE__ */ Symbol("onEntry"); var _s = /* @__PURE__ */ Symbol("checkFs"); var Nr = /* @__PURE__ */ Symbol("checkFs2"); var Os = /* @__PURE__ */ Symbol("isReusable"); var P = /* @__PURE__ */ Symbol("makeFs"); var Ts = /* @__PURE__ */ Symbol("file"); var xs = /* @__PURE__ */ Symbol("directory"); var gi = /* @__PURE__ */ Symbol("link"); var Ar = /* @__PURE__ */ Symbol("symlink"); var Ir = /* @__PURE__ */ Symbol("hardlink"); var Re = /* @__PURE__ */ Symbol("ensureNoSymlink"); var Cr = /* @__PURE__ */ Symbol("unsupported"); var Fr = /* @__PURE__ */ Symbol("checkPath"); var Rs = /* @__PURE__ */ Symbol("stripAbsolutePath"); var yt = /* @__PURE__ */ Symbol("mkdir"); var O = /* @__PURE__ */ Symbol("onError"); var Ri = /* @__PURE__ */ Symbol("pending"); var kr = /* @__PURE__ */ Symbol("pend"); var Vt = /* @__PURE__ */ Symbol("unpend"); var gs = /* @__PURE__ */ Symbol("ended"); var bs = /* @__PURE__ */ Symbol("maybeClose"); var Ls = /* @__PURE__ */ Symbol("skip"); var ge = /* @__PURE__ */ Symbol("doChown"); var be = /* @__PURE__ */ Symbol("uid"); var _e = /* @__PURE__ */ Symbol("gid"); var Oe = /* @__PURE__ */ Symbol("checkedCwd"); var mo = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform; var Te = mo === "win32"; var uo = 1024; var po = (s3, t) => { if (!Te) return import_node_fs3.default.unlink(s3, t); let e = s3 + ".DELETE." + (0, import_node_crypto.randomBytes)(16).toString("hex"); import_node_fs3.default.rename(s3, e, (i) => { if (i) return t(i); import_node_fs3.default.unlink(e, t); }); }; var Eo = (s3) => { if (!Te) return import_node_fs3.default.unlinkSync(s3); let t = s3 + ".DELETE." + (0, import_node_crypto.randomBytes)(16).toString("hex"); import_node_fs3.default.renameSync(s3, t), import_node_fs3.default.unlinkSync(t); }; var Mr = (s3, t, e) => s3 !== void 0 && s3 === s3 >>> 0 ? s3 : t !== void 0 && t === t >>> 0 ? t : e; var Xt = class extends rt { [gs] = false; [Oe] = false; [Ri] = 0; reservations = new yi(); transform; writable = true; readable = false; uid; gid; setOwner; preserveOwner; processGid; processUid; maxDepth; forceChown; win32; newer; keep; noMtime; preservePaths; unlink; cwd; strip; processUmask; umask; dmode; fmode; chmod; constructor(t = {}) { if (t.ondone = () => { this[gs] = true, this[bs](); }, super(t), this.transform = t.transform, this.chmod = !!t.chmod, typeof t.uid == "number" || typeof t.gid == "number") { if (typeof t.uid != "number" || typeof t.gid != "number") throw new TypeError("cannot set owner without number uid and gid"); if (t.preserveOwner) throw new TypeError("cannot preserve owner in archive and also set owner explicitly"); this.uid = t.uid, this.gid = t.gid, this.setOwner = true; } else this.uid = void 0, this.gid = void 0, this.setOwner = false; this.preserveOwner = t.preserveOwner === void 0 && typeof t.uid != "number" ? process.getuid?.() === 0 : !!t.preserveOwner, this.processUid = (this.preserveOwner || this.setOwner) && process.getuid ? process.getuid() : void 0, this.processGid = (this.preserveOwner || this.setOwner) && process.getgid ? process.getgid() : void 0, this.maxDepth = typeof t.maxDepth == "number" ? t.maxDepth : uo, this.forceChown = t.forceChown === true, this.win32 = !!t.win32 || Te, this.newer = !!t.newer, this.keep = !!t.keep, this.noMtime = !!t.noMtime, this.preservePaths = !!t.preservePaths, this.unlink = !!t.unlink, this.cwd = f(import_node_path5.default.resolve(t.cwd || process.cwd())), this.strip = Number(t.strip) || 0, this.processUmask = this.chmod ? typeof t.processUmask == "number" ? t.processUmask : Lr() : 0, this.umask = typeof t.umask == "number" ? t.umask : this.processUmask, this.dmode = t.dmode || 511 & ~this.umask, this.fmode = t.fmode || 438 & ~this.umask, this.on("entry", (e) => this[Dr](e)); } warn(t, e, i = {}) { return (t === "TAR_BAD_ARCHIVE" || t === "TAR_ABORT") && (i.recoverable = false), super.warn(t, e, i); } [bs]() { this[gs] && this[Ri] === 0 && (this.emit("prefinish"), this.emit("finish"), this.emit("end")); } [Rs](t, e) { let i = t[e], { type: r } = t; if (!i || this.preservePaths) return true; let [n, o] = ce(i), h = o.replaceAll(/\\/g, "/").split("/"); if (h.includes("..") || Te && /^[a-z]:\.\.$/i.test(h[0] ?? "")) { if (e === "path" || r === "Link") return this.warn("TAR_ENTRY_ERROR", `${e} contains '..'`, { entry: t, [e]: i }), false; let a = import_node_path5.default.posix.dirname(t.path), l = import_node_path5.default.posix.normalize(import_node_path5.default.posix.join(a, h.join("/"))); if (l.startsWith("../") || l === "..") return this.warn("TAR_ENTRY_ERROR", `${e} escapes extraction directory`, { entry: t, [e]: i }), false; } return n && (t[e] = String(o), this.warn("TAR_ENTRY_INFO", `stripping ${n} from absolute ${e}`, { entry: t, [e]: i })), true; } [Fr](t) { let e = f(t.path), i = e.split("/"); if (this.strip) { if (i.length < this.strip) return false; if (t.type === "Link") { let r = f(String(t.linkpath)).split("/"); if (r.length >= this.strip) t.linkpath = r.slice(this.strip).join("/"); else return false; } i.splice(0, this.strip), t.path = i.join("/"); } if (isFinite(this.maxDepth) && i.length > this.maxDepth) return this.warn("TAR_ENTRY_ERROR", "path excessively deep", { entry: t, path: e, depth: i.length, maxDepth: this.maxDepth }), false; if (!this[Rs](t, "path") || !this[Rs](t, "linkpath")) return false; if (t.absolute = import_node_path5.default.isAbsolute(t.path) ? f(import_node_path5.default.resolve(t.path)) : f(import_node_path5.default.resolve(this.cwd, t.path)), !this.preservePaths && typeof t.absolute == "string" && t.absolute.indexOf(this.cwd + "/") !== 0 && t.absolute !== this.cwd) return this.warn("TAR_ENTRY_ERROR", "path escaped extraction target", { entry: t, path: f(t.path), resolvedPath: t.absolute, cwd: this.cwd }), false; if (t.absolute === this.cwd && t.type !== "Directory" && t.type !== "GNUDumpDir") return false; if (this.win32) { let { root: r } = import_node_path5.default.win32.parse(String(t.absolute)); t.absolute = r + ts(String(t.absolute).slice(r.length)); let { root: n } = import_node_path5.default.win32.parse(t.path); t.path = n + ts(t.path.slice(n.length)); } return true; } [Dr](t) { if (!this[Fr](t)) return t.resume(); switch (import_node_assert.default.equal(typeof t.absolute, "string"), t.type) { case "Directory": case "GNUDumpDir": t.mode && (t.mode = t.mode | 448); case "File": case "OldFile": case "ContiguousFile": case "Link": case "SymbolicLink": return this[_s](t); default: return this[Cr](t); } } [O](t, e) { t.name === "CwdError" ? this.emit("error", t) : (this.warn("TAR_ENTRY_ERROR", t, { entry: e }), this[Vt](), e.resume()); } [yt](t, e, i) { gr(f(t), { uid: this.uid, gid: this.gid, processUid: this.processUid, processGid: this.processGid, umask: this.processUmask, preserve: this.preservePaths, unlink: this.unlink, cwd: this.cwd, mode: e }, i); } [ge](t) { return this.forceChown || this.preserveOwner && (typeof t.uid == "number" && t.uid !== this.processUid || typeof t.gid == "number" && t.gid !== this.processGid) || typeof this.uid == "number" && this.uid !== this.processUid || typeof this.gid == "number" && this.gid !== this.processGid; } [be](t) { return Mr(this.uid, t.uid, this.processUid); } [_e](t) { return Mr(this.gid, t.gid, this.processGid); } [Ts](t, e) { let i = typeof t.mode == "number" ? t.mode & 4095 : this.fmode, r = new et(String(t.absolute), { flags: us(t.size), mode: i, autoClose: false }); r.on("error", (a) => { r.fd && import_node_fs3.default.close(r.fd, () => { }), r.write = () => true, this[O](a, t), e(); }); let n = 1, o = (a) => { if (a) { r.fd && import_node_fs3.default.close(r.fd, () => { }), this[O](a, t), e(); return; } --n === 0 && r.fd !== void 0 && import_node_fs3.default.close(r.fd, (l) => { l ? this[O](l, t) : this[Vt](), e(); }); }; r.on("finish", () => { let a = String(t.absolute), l = r.fd; if (typeof l == "number" && t.mtime && !this.noMtime) { n++; let c = t.atime || /* @__PURE__ */ new Date(), d = t.mtime; import_node_fs3.default.futimes(l, c, d, (y) => y ? import_node_fs3.default.utimes(a, c, d, (T) => o(T && y)) : o()); } if (typeof l == "number" && this[ge](t)) { n++; let c = this[be](t), d = this[_e](t); typeof c == "number" && typeof d == "number" && import_node_fs3.default.fchown(l, c, d, (y) => y ? import_node_fs3.default.chown(a, c, d, (T) => o(T && y)) : o()); } o(); }); let h = this.transform && this.transform(t) || t; h !== t && (h.on("error", (a) => { this[O](a, t), e(); }), t.pipe(h)), h.pipe(r); } [xs](t, e) { let i = typeof t.mode == "number" ? t.mode & 4095 : this.dmode; this[yt](String(t.absolute), i, (r) => { if (r) { this[O](r, t), e(); return; } let n = 1, o = () => { --n === 0 && (e(), this[Vt](), t.resume()); }; t.mtime && !this.noMtime && (n++, import_node_fs3.default.utimes(String(t.absolute), t.atime || /* @__PURE__ */ new Date(), t.mtime, o)), this[ge](t) && (n++, import_node_fs3.default.chown(String(t.absolute), Number(this[be](t)), Number(this[_e](t)), o)), o(); }); } [Cr](t) { t.unsupported = true, this.warn("TAR_ENTRY_UNSUPPORTED", `unsupported entry type: ${t.type}`, { entry: t }), t.resume(); } [Ar](t, e) { let i = f(import_node_path5.default.relative(this.cwd, import_node_path5.default.resolve(import_node_path5.default.dirname(String(t.absolute)), String(t.linkpath)))).split("/"); this[Re](t, this.cwd, i, () => this[gi](t, String(t.linkpath), "symlink", e), (r) => { this[O](r, t), e(); }); } [Ir](t, e) { let i = f(import_node_path5.default.resolve(this.cwd, String(t.linkpath))), r = f(String(t.linkpath)).split("/"); this[Re](t, this.cwd, r, () => this[gi](t, i, "link", e), (n) => { this[O](n, t), e(); }); } [Re](t, e, i, r, n) { let o = i.shift(); if (this.preservePaths || o === void 0) return r(); let h = import_node_path5.default.resolve(e, o); import_node_fs3.default.lstat(h, (a, l) => { if (a) return r(); if (l?.isSymbolicLink()) return n(new St(h, import_node_path5.default.resolve(h, i.join("/")))); this[Re](t, h, i, r, n); }); } [kr]() { this[Ri]++; } [Vt]() { this[Ri]--, this[bs](); } [Ls](t) { this[Vt](), t.resume(); } [Os](t, e) { return t.type === "File" && !this.unlink && e.isFile() && e.nlink <= 1 && !Te; } [_s](t) { this[kr](); let e = [t.path]; t.linkpath && e.push(t.linkpath), this.reservations.reserve(e, (i) => this[Nr](t, i)); } [Nr](t, e) { let i = (h) => { e(h); }, r = () => { this[yt](this.cwd, this.dmode, (h) => { if (h) { this[O](h, t), i(); return; } this[Oe] = true, n(); }); }, n = () => { if (t.absolute !== this.cwd) { let h = f(import_node_path5.default.dirname(String(t.absolute))); if (h !== this.cwd) return this[yt](h, this.dmode, (a) => { if (a) { this[O](a, t), i(); return; } o(); }); } o(); }, o = () => { import_node_fs3.default.lstat(String(t.absolute), (h, a) => { if (a && (this.keep || this.newer && a.mtime > (t.mtime ?? a.mtime))) { this[Ls](t), i(); return; } if (h || this[Os](t, a)) return this[P](null, t, i); if (a.isDirectory()) { if (t.type === "Directory") { let l = this.chmod && t.mode && (a.mode & 4095) !== t.mode, c = (d) => this[P](d ?? null, t, i); return l ? import_node_fs3.default.chmod(String(t.absolute), Number(t.mode), c) : c(); } if (t.absolute !== this.cwd) return import_node_fs3.default.rmdir(String(t.absolute), (l) => this[P](l ?? null, t, i)); } if (t.absolute === this.cwd) return this[P](null, t, i); po(String(t.absolute), (l) => this[P](l ?? null, t, i)); }); }; this[Oe] ? n() : r(); } [P](t, e, i) { if (t) { this[O](t, e), i(); return; } switch (e.type) { case "File": case "OldFile": case "ContiguousFile": return this[Ts](e, i); case "Link": return this[Ir](e, i); case "SymbolicLink": return this[Ar](e, i); case "Directory": case "GNUDumpDir": return this[xs](e, i); } } [gi](t, e, i, r) { import_node_fs3.default[i](e, String(t.absolute), (n) => { n ? this[O](n, t) : (this[Vt](), t.resume()), r(); }); } }; var ye = (s3) => { try { return [null, s3()]; } catch (t) { return [t, null]; } }; var xe = class extends Xt { sync = true; [P](t, e) { return super[P](t, e, () => { }); } [_s](t) { if (!this[Oe]) { let n = this[yt](this.cwd, this.dmode); if (n) return this[O](n, t); this[Oe] = true; } if (t.absolute !== this.cwd) { let n = f(import_node_path5.default.dirname(String(t.absolute))); if (n !== this.cwd) { let o = this[yt](n, this.dmode); if (o) return this[O](o, t); } } let [e, i] = ye(() => import_node_fs3.default.lstatSync(String(t.absolute))); if (i && (this.keep || this.newer && i.mtime > (t.mtime ?? i.mtime))) return this[Ls](t); if (e || this[Os](t, i)) return this[P](null, t); if (i.isDirectory()) { if (t.type === "Directory") { let o = this.chmod && t.mode && (i.mode & 4095) !== t.mode, [h] = o ? ye(() => { import_node_fs3.default.chmodSync(String(t.absolute), Number(t.mode)); }) : []; return this[P](h, t); } let [n] = ye(() => import_node_fs3.default.rmdirSync(String(t.absolute))); this[P](n, t); } let [r] = t.absolute === this.cwd ? [] : ye(() => Eo(String(t.absolute))); this[P](r, t); } [Ts](t, e) { let i = typeof t.mode == "number" ? t.mode & 4095 : this.fmode, r = (h) => { let a; try { import_node_fs3.default.closeSync(n); } catch (l) { a = l; } (h || a) && this[O](h || a, t), e(); }, n; try { n = import_node_fs3.default.openSync(String(t.absolute), us(t.size), i); } catch (h) { return r(h); } let o = this.transform && this.transform(t) || t; o !== t && (o.on("error", (h) => this[O](h, t)), t.pipe(o)), o.on("data", (h) => { try { import_node_fs3.default.writeSync(n, h, 0, h.length); } catch (a) { r(a); } }), o.on("end", () => { let h = null; if (t.mtime && !this.noMtime) { let a = t.atime || /* @__PURE__ */ new Date(), l = t.mtime; try { import_node_fs3.default.futimesSync(n, a, l); } catch (c) { try { import_node_fs3.default.utimesSync(String(t.absolute), a, l); } catch { h = c; } } } if (this[ge](t)) { let a = this[be](t), l = this[_e](t); try { import_node_fs3.default.fchownSync(n, Number(a), Number(l)); } catch (c) { try { import_node_fs3.default.chownSync(String(t.absolute), Number(a), Number(l)); } catch { h = h || c; } } } r(h); }); } [xs](t, e) { let i = typeof t.mode == "number" ? t.mode & 4095 : this.dmode, r = this[yt](String(t.absolute), i); if (r) { this[O](r, t), e(); return; } if (t.mtime && !this.noMtime) try { import_node_fs3.default.utimesSync(String(t.absolute), t.atime || /* @__PURE__ */ new Date(), t.mtime); } catch { } if (this[ge](t)) try { import_node_fs3.default.chownSync(String(t.absolute), Number(this[be](t)), Number(this[_e](t))); } catch { } e(), t.resume(); } [yt](t, e) { try { return _r(f(t), { uid: this.uid, gid: this.gid, processUid: this.processUid, processGid: this.processGid, umask: this.processUmask, preserve: this.preservePaths, unlink: this.unlink, cwd: this.cwd, mode: e }); } catch (i) { return i; } } [Re](t, e, i, r, n) { if (this.preservePaths || i.length === 0) return r(); let o = e; for (let h of i) { o = import_node_path5.default.resolve(o, h); let [a, l] = ye(() => import_node_fs3.default.lstatSync(o)); if (a) return r(); if (l.isSymbolicLink()) return n(new St(o, import_node_path5.default.resolve(e, i.join("/")))); } r(); } [gi](t, e, i, r) { let n = `${i}Sync`; try { import_node_fs3.default[n](e, String(t.absolute)), r(), t.resume(); } catch (o) { return this[O](o, t); } } }; var wo = (s3) => { let t = new xe(s3), e = s3.file, i = import_node_fs2.default.statSync(e), r = s3.maxReadSize || 16 * 1024 * 1024; new Be(e, { readSize: r, size: i.size }).pipe(t); }; var So = (s3, t) => { let e = new Xt(s3), i = s3.maxReadSize || 16 * 1024 * 1024, r = s3.file; return new Promise((o, h) => { e.on("error", h), e.on("close", o), import_node_fs2.default.stat(r, (a, l) => { if (a) h(a); else { let c = new _t(r, { readSize: i, size: l.size }); c.on("error", h), c.pipe(e); } }); }); }; var yo = K(wo, So, (s3) => new xe(s3), (s3) => new Xt(s3), (s3, t) => { t?.length && Qi(s3, t); }); var Ro = (s3, t) => { let e = new kt(s3), i = true, r, n; try { try { r = import_node_fs6.default.openSync(s3.file, "r+"); } catch (a) { if (a?.code === "ENOENT") r = import_node_fs6.default.openSync(s3.file, "w+"); else throw a; } let o = import_node_fs6.default.fstatSync(r), h = Buffer.alloc(512); t: for (n = 0; n < o.size; n += 512) { for (let c = 0, d = 0; c < 512; c += d) { if (d = import_node_fs6.default.readSync(r, h, c, h.length - c, n + c), n === 0 && h[0] === 31 && h[1] === 139) throw new Error("cannot append to compressed archives"); if (!d) break t; } let a = new F(h); if (!a.cksumValid) break; let l = 512 * Math.ceil((a.size || 0) / 512); if (n + l + 512 > o.size) break; n += l, s3.mtimeCache && a.mtime && s3.mtimeCache.set(String(a.path), a.mtime); } i = false, go(s3, e, n, r, t); } finally { if (i) try { import_node_fs6.default.closeSync(r); } catch { } } }; var go = (s3, t, e, i, r) => { let n = new Wt(s3.file, { fd: i, start: e }); t.pipe(n), _o(t, r); }; var bo = (s3, t) => { t = Array.from(t); let e = new wt(s3), i = (n, o, h) => { let a = (T, D) => { T ? import_node_fs6.default.close(n, (E) => h(T)) : h(null, D); }, l = 0; if (o === 0) return a(null, 0); let c = 0, d = Buffer.alloc(512), y = (T, D) => { if (T || D === void 0) return a(T); if (c += D, c < 512 && D) return import_node_fs6.default.read(n, d, c, d.length - c, l + c, y); if (l === 0 && d[0] === 31 && d[1] === 139) return a(new Error("cannot append to compressed archives")); if (c < 512) return a(null, l); let E = new F(d); if (!E.cksumValid) return a(null, l); let x = 512 * Math.ceil((E.size ?? 0) / 512); if (l + x + 512 > o || (l += x + 512, l >= o)) return a(null, l); s3.mtimeCache && E.mtime && s3.mtimeCache.set(String(E.path), E.mtime), c = 0, import_node_fs6.default.read(n, d, 0, 512, l, y); }; import_node_fs6.default.read(n, d, 0, 512, l, y); }; return new Promise((n, o) => { e.on("error", o); let h = "r+", a = (l, c) => { if (l && l.code === "ENOENT" && h === "r+") return h = "w+", import_node_fs6.default.open(s3.file, h, a); if (l || !c) return o(l); import_node_fs6.default.fstat(c, (d, y) => { if (d) return import_node_fs6.default.close(c, () => o(d)); i(c, y.size, (T, D) => { if (T) return o(T); let E = new et(s3.file, { fd: c, start: D }); e.pipe(E), E.on("error", o), E.on("close", n), Oo(e, t); }); }); }; import_node_fs6.default.open(s3.file, h, a); }); }; var _o = (s3, t) => { t.forEach((e) => { e.charAt(0) === "@" ? Ct({ file: import_node_path9.default.resolve(s3.cwd, e.slice(1)), sync: true, noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e); }), s3.end(); }; var Oo = async (s3, t) => { for (let e of t) e.charAt(0) === "@" ? await Ct({ file: import_node_path9.default.resolve(String(s3.cwd), e.slice(1)), noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e); s3.end(); }; var Mt = K(Ro, bo, () => { throw new TypeError("file is required"); }, () => { throw new TypeError("file is required"); }, (s3, t) => { if (!Bs(s3)) throw new TypeError("file is required"); if (s3.gzip || s3.brotli || s3.zstd || s3.file.endsWith(".br") || s3.file.endsWith(".tbr")) throw new TypeError("cannot append to compressed archives"); if (!t?.length) throw new TypeError("no paths specified to add/replace"); }); var To = K(Mt.syncFile, Mt.asyncFile, Mt.syncNoFile, Mt.asyncNoFile, (s3, t = []) => { Mt.validate?.(s3, t), xo(s3); }); var xo = (s3) => { let t = s3.filter; s3.mtimeCache || (s3.mtimeCache = /* @__PURE__ */ new Map()), s3.filter = t ? (e, i) => t(e, i) && !((s3.mtimeCache?.get(e) ?? i.mtime ?? 0) > (i.mtime ?? 0)) : (e, i) => !((s3.mtimeCache?.get(e) ?? i.mtime ?? 0) > (i.mtime ?? 0)); }; // src/archive-cache.mjs var import_promises2 = __toESM(require("node:fs/promises"), 1); var import_node_fs7 = require("node:fs"); var import_node_crypto2 = require("node:crypto"); var import_node_path10 = require("node:path"); var import_promises3 = require("node:stream/promises"); var import_node_stream2 = require("node:stream"); var MAX_CACHE = 512 * 1024 * 1024; var MAX_ARCHIVE = 128 * 1024 * 1024; var RETRY = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]); var sleep = (ms2) => new Promise((resolve) => setTimeout(resolve, ms2)); async function digest(file2, algorithm) { const hash = (0, import_node_crypto2.createHash)(algorithm); let size = 0; for await (const data of (0, import_node_fs7.createReadStream)(file2)) { size += data.length; if (size > MAX_ARCHIVE) throw new Error("Cached archive is too large."); hash.update(data); } return hash.digest("base64"); } function createArchiveCache({ directory, request: request2, offline }) { let stored = false; const active = /* @__PURE__ */ new Map(); async function resolve(record, integrity, temporary) { const split = integrity.indexOf("-"); const algorithm = integrity.slice(0, split); const checksum = integrity.slice(split + 1); const key = (0, import_node_crypto2.createHash)("sha256").update(integrity).digest("hex") + ".tgz"; const cached = (0, import_node_path10.join)(directory, key); let isCached = false; try { const status = await import_promises2.default.lstat(cached); isCached = status.isFile() && status.size <= MAX_ARCHIVE && await digest(cached, algorithm) === checksum; } catch { } if (isCached) { if (offline) return cached; try { const current = await request2(record.dist.tarball, { method: "HEAD" }); if (current.ok) { await import_promises2.default.utimes(cached, /* @__PURE__ */ new Date(), /* @__PURE__ */ new Date()).catch(() => { }); return cached; } } catch (error) { if (error.status !== 405) throw error; } } if (offline) throw new Error("No verified archive is cached for " + record.name + "@" + record.version + ". Run a normal install first."); await import_promises2.default.mkdir(directory, { recursive: true, mode: 448 }).catch(() => { }); const temp = (0, import_node_path10.join)(temporary, (0, import_node_crypto2.randomUUID)() + ".tgz"); for (let attempt = 0; attempt < 3; attempt++) { try { const response = await request2(record.dist.tarball); const hash = (0, import_node_crypto2.createHash)(algorithm); let size = 0; await (0, import_promises3.pipeline)(import_node_stream2.Readable.fromWeb(response.body), async function* (source) { for await (const chunk of source) { size += chunk.length; if (size > MAX_ARCHIVE) throw new Error("Tarball too large: " + record.name); hash.update(chunk); yield chunk; } }, (0, import_node_fs7.createWriteStream)(temp, { flags: "wx", mode: 384 })); if (hash.digest("base64") !== checksum) throw new Error("Checksum mismatch for " + record.name); } catch (error) { await import_promises2.default.rm(temp, { force: true }); if (attempt === 2 || !(RETRY.has(error.status) || error.name === "TimeoutError" || error.cause?.code === "ECONNRESET")) throw error; await sleep((attempt + 1) * 300); continue; } const incoming = (0, import_node_path10.join)(directory, ".incoming-" + (0, import_node_crypto2.randomUUID)()); try { await import_promises2.default.copyFile(temp, incoming); await import_promises2.default.rename(incoming, cached); await import_promises2.default.rm(temp, { force: true }); stored = true; return cached; } catch { await import_promises2.default.rm(incoming, { force: true }).catch(() => { }); return temp; } } } async function prune() { if (!stored) return; const entries = await import_promises2.default.readdir(directory, { withFileTypes: true }).catch(() => []); const files = []; for (const entry of entries) { if (!entry.isFile() || !/^[a-f0-9]{64}\.tgz$/.test(entry.name)) continue; const path3 = (0, import_node_path10.join)(directory, entry.name); const stat = await import_promises2.default.stat(path3).catch(() => null); if (stat) files.push({ path: path3, mtime: stat.mtimeMs, size: stat.size }); } files.sort((a, b2) => b2.mtime - a.mtime); let bytes = 0; for (const file2 of files) { bytes += file2.size; if (bytes > MAX_CACHE) await import_promises2.default.rm(file2.path, { force: true }).catch(() => { }); } } return { get(record, integrity, temporary) { if (!active.has(integrity)) active.set(integrity, resolve(record, integrity, temporary)); return active.get(integrity); }, prune }; } // src/install-journal.mjs var import_promises4 = __toESM(require("node:fs/promises"), 1); var import_node_fs8 = require("node:fs"); var import_node_path11 = __toESM(require("node:path"), 1); var file = (guard) => import_node_path11.default.join(guard, "transaction.json"); async function saveInstall(guard, phase, state, atomic2) { await atomic2(file(guard), JSON.stringify({ ...state, phase, pid: process.pid })); } async function recoverInstall({ cwd: cwd2, guards, atomic: atomic2 }) { const guard = import_node_path11.default.join(cwd2, guards); let transaction; try { transaction = JSON.parse(await import_promises4.default.readFile(file(guard), "utf8")); } catch { throw new Error("No QZ install journal found. Check .qz-install manually if an older install left it behind."); } if (!Number.isSafeInteger(transaction.pid) || transaction.pid <= 0 || !["staging", "swapping", "committed"].includes(transaction.phase) || typeof transaction.manifest !== "string" || transaction.lock !== null && typeof transaction.lock !== "string" || typeof transaction.hadModules !== "boolean") throw new Error("Invalid QZ install journal."); try { process.kill(transaction.pid, 0); throw new Error("An install process is still running. Wait for it to finish before recovering."); } catch (error) { if (error.code !== "ESRCH") throw error; } if (transaction.phase === "swapping") { const destination = import_node_path11.default.join(cwd2, "node_modules"); const backup = import_node_path11.default.join(guard, "previous"); if ((0, import_node_fs8.existsSync)(backup)) { await import_promises4.default.rm(destination, { recursive: true, force: true, maxRetries: 4 }); await import_promises4.default.rename(backup, destination); } else if (!transaction.hadModules) await import_promises4.default.rm(destination, { recursive: true, force: true, maxRetries: 4 }); await atomic2(import_node_path11.default.join(cwd2, "package.json"), transaction.manifest); const lock = import_node_path11.default.join(cwd2, "qz.lock"); if (transaction.lock === null) await import_promises4.default.rm(lock, { force: true }); else await atomic2(lock, transaction.lock); } await import_promises4.default.rm(guard, { recursive: true, force: true, maxRetries: 4 }); return transaction.phase; } // src/qz.mjs var registry = "https://qzpkg.com"; var version = "0.6.0"; var cwd = process.cwd(); var home = import_node_path12.default.join(import_node_os.default.homedir(), ".qz"); var packagePath = import_node_path12.default.join(cwd, "package.json"); var lockPath = import_node_path12.default.join(cwd, "qz.lock"); var MAX_TREE = 5e3; var own = (obj, key) => Object.hasOwn(obj, key) ? obj[key] : void 0; var readJSON = async (file2) => JSON.parse((await import_promises5.default.readFile(file2, "utf8")).replace(/^\uFEFF/, "")); var err = (message) => { throw new Error(message); }; var nameOK = (name) => typeof name === "string" && name.length <= 214 && /^(?:@[a-z0-9_][a-z0-9._-]*\/)?[a-z0-9_][a-z0-9._-]*$/.test(name) && name.split("/").every((part) => !/^(?:__proto__|constructor|prototype|node_modules|(?:con|aux|nul|prn|com[1-9]|lpt[1-9])(?:\.|$))/i.test(part) && !part.endsWith(".")); var endpoint = (name) => nameOK(name) ? "/" + name.replace("/", "%2f") : err("Invalid package name: " + name); var inside = (base, target) => { const rel = import_node_path12.default.relative(base, target); return rel !== ".." && !rel.startsWith(".." + import_node_path12.default.sep) && !import_node_path12.default.isAbsolute(rel); }; var sha = (algorithm, data, encoding = "base64") => (0, import_node_crypto3.createHash)(algorithm).update(data).digest(encoding); async function atomic(file2, content) { const temp = file2 + "." + (0, import_node_crypto3.randomUUID)(); try { await import_promises5.default.writeFile(temp, content, { flag: "wx", mode: 384 }); await import_promises5.default.rename(temp, file2); } finally { await import_promises5.default.rm(temp, { force: true }); } } async function token() { const file2 = import_node_path12.default.join(home, "token"); const value = process.env.QZ_TOKEN || ((0, import_node_fs9.existsSync)(file2) ? (await import_promises5.default.readFile(file2, "utf8")).trim() : ""); if (!value) err("Run qz login or set QZ_TOKEN before publishing."); return value; } async function request(resource, options = {}) { const url = new URL(resource, registry); if (url.origin !== registry || url.username || url.password) err("Registry returned a URL outside " + registry); const response = await fetch(url, { ...options, redirect: "error", signal: AbortSignal.timeout(12e4), headers: { "user-agent": "qz/" + version, ...options.headers } }); if (!response.ok) { const why = await response.json().catch(() => ({})); throw Object.assign(new Error("Registry returned HTTP " + response.status + " for " + url.pathname + (typeof why.error === "string" ? ": " + why.error : "")), { status: response.status }); } return response; } async function login() { const user = process.env.QZ_USER || "qz-owner"; if (!/^[a-z0-9-]+$/.test(user)) err("Invalid QZ username."); if (!process.stdin.isTTY || !process.stdin.setRawMode) err("Run qz login in an interactive terminal, or use QZ_TOKEN for CI."); process.stderr.write("Passphrase for " + user + ": "); const password = await new Promise((resolve, reject) => { let input = ""; process.stdin.setEncoding("utf8"); process.stdin.setRawMode(true); process.stdin.resume(); function cleanup() { process.stdin.setRawMode(false); process.stdin.pause(); process.stdin.off("data", consume); process.stderr.write("\n"); } function consume(chunk) { for (const char of chunk) { if (char === "" || char === "") { cleanup(); reject(new Error("Login cancelled.")); return; } if (char === "\r" || char === "\n") { cleanup(); resolve(input); return; } if (char === "\x7F" || char === "\b") input = input.slice(0, -1); else input += char; } } process.stdin.on("data", consume); }); const answer = await request("/-/user/org.couchdb.user:" + user, { method: "PUT", headers: { "content-type": "application/json", authorization: "Basic " + Buffer.from(user + ":" + password).toString("base64") }, body: JSON.stringify({ name: user, password, type: "user", roles: [] }) }).then((r) => r.json()); if (typeof answer.token !== "string" || !answer.token) err("Registry did not return a token."); await import_promises5.default.mkdir(home, { mode: 448, recursive: true }); await atomic(import_node_path12.default.join(home, "token"), answer.token + "\n"); console.log("Signed in to " + registry + " as " + user); } function spec(argument) { const at2 = argument.indexOf("@", 1); const name = at2 < 0 ? argument : argument.slice(0, at2); endpoint(name); return [name, at2 < 0 ? "latest" : argument.slice(at2 + 1) || "latest"]; } function safeDist(entry) { const { dist, name, version: release } = entry; if (!dist || typeof dist.tarball !== "string" || !nameOK(name) || !import_semver.default.valid(release)) err("Invalid registry package record."); const filename = name.split("/").at(-1) + "-" + release + ".tgz"; const url = new URL(dist.tarball); if (url.origin !== registry || decodeURIComponent(url.pathname) !== "/" + name + "/-/" + filename) { err("Invalid tarball URL for " + name + ": " + url.origin); } const integrity = typeof dist.integrity === "string" && dist.integrity.split(/\s+/).find((value) => /^(sha512|sha384|sha256|sha1)-[A-Za-z0-9+/]+=*$/.test(value)); if (!integrity && !/^[0-9a-f]{40}$/i.test(dist.shasum || "")) err("Missing tarball checksum for " + name); return integrity || "sha1-" + Buffer.from(dist.shasum, "hex").toString("base64"); } function registrySpec(name, range) { if (typeof range !== "string") err("Invalid dependency " + name); const [real, requested] = range.startsWith("npm:") ? spec(range.slice(4)) : [name, range]; if (!import_semver.default.validRange(requested) && !/^[a-zA-Z][a-zA-Z0-9._-]*$/.test(requested)) err("Unsupported dependency " + name + "@" + range); return { real, requested }; } function deps(entry, key = "dependencies") { const values = entry[key] ?? {}; if (!values || typeof values !== "object" || Array.isArray(values)) err("Invalid " + key); for (const [name, range] of Object.entries(values)) { endpoint(name); registrySpec(name, range); } return values; } function platformSupported(entry) { const allows = (values, current) => !Array.isArray(values) || !values.includes("!" + current) && (!values.some((value) => !value.startsWith("!")) || values.includes(current)); return allows(entry.os, process.platform) && allows(entry.cpu, process.arch) && allows(entry.libc, process.platform === "linux" ? process.report.getReport().header.glibcVersionRuntime ? "glibc" : "musl" : ""); } function registryEntry(entry, name, range) { if (entry?.name !== name || !import_semver.default.valid(entry.version) || import_semver.default.validRange(range) && !import_semver.default.satisfies(entry.version, range)) err("Invalid resolution for " + name + "@" + range); safeDist(entry); return Object.fromEntries(["name", "version", "dist", "dependencies", "optionalDependencies", "peerDependencies", "peerDependenciesMeta", "deprecated", "os", "cpu", "libc"].filter((key) => entry[key] !== void 0).map((key) => [key, entry[key]])); } function resolver(old, refresh, frozen = false) { const metadata = /* @__PURE__ */ new Map(); const pins = /* @__PURE__ */ new Map(); async function resolve(name, range) { const label = name + "@" + range; if (pins.has(label)) return pins.get(label); const locked = refresh ? void 0 : own(old, label); if (locked) { const record2 = registryEntry(locked, name, range); pins.set(label, record2); return record2; } if (frozen) throw Object.assign(new Error("qz.lock has no resolution for " + label), { code: "QZ_MISSING_PIN" }); if (!metadata.has(name)) metadata.set(name, request(endpoint(name), { headers: { accept: "application/vnd.npm.install-v1+json" } }).then((r) => r.json())); const document = await metadata.get(name); const versions = document.versions ?? {}; const release = import_semver.default.validRange(range) ? import_semver.default.maxSatisfying(Object.keys(versions), range) : own(document["dist-tags"] ?? {}, range); if (!release || !own(versions, release)) err("No matching release for " + label); const record = registryEntry(versions[release], name, range); pins.set(label, record); return record; } return { resolve, pins }; } async function planInstall(manifest, resolution, production = false) { const result = []; const root = { dir: "", isRoot: true, record: manifest }; async function branch(parent, ancestors) { const { record } = parent; const optional = deps(record, "optionalDependencies"); const required = { ...parent.isRoot && !production ? deps(record, "devDependencies") : {}, ...deps(record) }; const group = { ...required, ...optional }; const siblings = /* @__PURE__ */ new Map(); for (const name of Object.keys(group).sort()) { const { real, requested: range } = registrySpec(name, group[name]); const visible = ancestors.get(name); if (visible?.record.name === real && import_semver.default.validRange(range) && import_semver.default.satisfies(visible.record.version, range)) continue; const resolved = await resolution.resolve(real, range).catch((error) => { if (own(optional, name) !== void 0 && error.code !== "QZ_MISSING_PIN") { console.warn("Skipped optional dependency " + name + ": " + error.message); return null; } throw error; }); if (!resolved) continue; if (!platformSupported(resolved)) { if (own(optional, name) !== void 0) continue; err("Unsupported platform for " + name + "@" + resolved.version); } if (visible?.record.name === real && visible.record.version === resolved.version) continue; if (result.length >= MAX_TREE || ancestors.depth >= 80) err("Dependency tree exceeded QZ limits."); const dir = import_node_path12.default.join(parent.dir, parent.isRoot ? "" : "node_modules", name); const node = { dir, placement: name, record: resolved }; result.push(node); siblings.set(name, node); } const visibility = new Map([...ancestors, ...siblings]); visibility.depth = (ancestors.depth || 0) + 1; for (const node of siblings.values()) { for (const [peer, range] of Object.entries(deps(node.record, "peerDependencies"))) { const peerNode = visibility.get(peer); if (!peerNode && own(node.record.peerDependenciesMeta ?? {}, peer)?.optional) continue; if (!peerNode || !import_semver.default.satisfies(peerNode.record.version, range)) { err(node.record.name + " requires peer " + peer + "@" + range + ". Add a compatible version to your project."); } } await branch(node, visibility); } } await branch(root, /* @__PURE__ */ new Map()); return result; } async function extract(record, target, temp, cache) { const archive = await cache.get(record, safeDist(record), temp); await import_promises5.default.mkdir(target, { recursive: true }); let expanded = 0; let entries = 0; await yo({ file: archive, cwd: target, strip: 1, strict: true, filter(name, entry) { const parts = name.replace(/\/$/, "").split("/"); if (!["File", "OldFile", "Directory"].includes(entry.type)) return false; if (++entries > 3e4 || (expanded += entry.size || 0) > 512 * 1024 * 1024) err("Expanded package too large: " + record.name); if (parts.some((part) => !part || part === "." || part === ".." || /[\\:\0]/.test(part))) err("Invalid path in package: " + record.name); if (parts.slice(1).includes("node_modules")) err("Bundled dependencies are unsupported: " + record.name); return true; } }); const installed = await readJSON(import_node_path12.default.join(target, "package.json")); if (installed.name !== record.name || installed.version !== record.version) err("Tarball manifest does not match registry metadata."); return installed; } async function linkBins(installed, where, placement) { const mapping = typeof installed.bin === "string" ? { [installed.name.split("/").at(-1)]: installed.bin } : installed.bin || {}; const modules = import_node_path12.default.dirname(placement.startsWith("@") ? import_node_path12.default.dirname(where) : where); const binDir = import_node_path12.default.join(modules, ".bin"); for (const [name, relative] of Object.entries(mapping)) { if (!nameOK(name) || name.includes("/") || typeof relative !== "string" || !/^[a-zA-Z0-9_./-]+$/.test(relative)) err("Invalid executable in " + installed.name); const target = import_node_path12.default.resolve(where, relative); if (!inside(where, target) || !(await import_promises5.default.stat(target)).isFile()) err("Invalid executable target in " + installed.name); await import_promises5.default.mkdir(binDir, { recursive: true }); const link = import_node_path12.default.join(binDir, name); if (process.platform === "win32") { const local = import_node_path12.default.relative(binDir, target); if ((0, import_node_fs9.existsSync)(link + ".cmd")) continue; await import_promises5.default.writeFile(link + ".cmd", '@echo off\r\nnode "%~dp0' + local + '" %*\r\n', { flag: "wx" }); } else { if ((0, import_node_fs9.existsSync)(link)) continue; await import_promises5.default.chmod(target, 493); await import_promises5.default.symlink(import_node_path12.default.relative(binDir, target), link); } } } async function install(args) { const refresh = args.includes("--update"); const offline = args.includes("--offline"); const production = args.includes("--production"); const frozen = offline || args.includes("--frozen"); const save = args.filter((arg) => !["--update", "--frozen", "--offline", "--production"].includes(arg)); if (frozen && (refresh || save.length)) err("--frozen requires an unchanged install."); const originalManifest = await import_promises5.default.readFile(packagePath, "utf8"); const existing = JSON.parse(originalManifest.replace(/^\uFEFF/, "")); const manifest = structuredClone(existing); if (save.length) { manifest.dependencies = { ...deps(manifest) }; for (const arg of save) { const [name, range] = spec(arg); manifest.dependencies[name] = range; } } const previousLock = (0, import_node_fs9.existsSync)(lockPath) ? await import_promises5.default.readFile(lockPath, "utf8") : null; const lock = previousLock === null ? {} : JSON.parse(previousLock); if (lock.format && lock.format !== 1) err("Unsupported qz.lock format."); const resolution = resolver(lock.resolutions ?? {}, refresh, frozen); const guard = import_node_path12.default.join(cwd, ".qz-install"); await import_promises5.default.mkdir(guard, { mode: 448 }).catch((error) => { if (error.code === "EEXIST") err("Another QZ install is active. If it was interrupted, run qz recover."); throw error; }); const cache = createArchiveCache({ directory: import_node_path12.default.join(home, "cache", "tarballs"), request, offline }); const state = { manifest: originalManifest, lock: previousLock, hadModules: (0, import_node_fs9.existsSync)(import_node_path12.default.join(cwd, "node_modules")) }; let preserveGuard = false; try { await saveInstall(guard, "staging", state, atomic); const plan = await planInstall(manifest, resolution, production); const warned = /* @__PURE__ */ new Set(); for (const { record } of plan) if (typeof record.deprecated === "string" && record.deprecated.trim()) { const id = record.name + "@" + record.version; if (!warned.has(id)) console.warn("Deprecated " + id + ": " + record.deprecated.replace(/[\x00-\x1f\x7f]/g, " ").slice(0, 500)); warned.add(id); } if (save.length) { for (const arg of save) { const [name, range] = spec(arg); if (range === "latest") manifest.dependencies[name] = "^" + (await resolution.resolve(name, range)).version; } for (const node of plan) { if (node.dir === import_node_path12.default.normalize(node.record.name)) { const range = own(manifest.dependencies, node.record.name); if (range) resolution.pins.set(node.record.name + "@" + range, node.record); } } } const rootRequests = Object.fromEntries(["dependencies", "devDependencies", "optionalDependencies"].map((key) => [ key, Object.fromEntries(Object.entries(deps(manifest, key)).sort(([a], [b2]) => a.localeCompare(b2))) ])); if (frozen && (JSON.stringify(lock.requests) !== JSON.stringify(rootRequests) || [...resolution.pins.keys()].some((key) => !own(lock.resolutions ?? {}, key)))) err("qz.lock is missing or out of date."); const stage = import_node_path12.default.join(guard, "node_modules"); await import_promises5.default.mkdir(stage); for (let start = 0; start < plan.length; start += 4) { const batch = plan.slice(start, start + 4); const extracted = await Promise.allSettled(batch.map(async ({ dir, record, placement }) => { const where = import_node_path12.default.resolve(stage, dir); if (!inside(stage, where)) err("Invalid installation path."); return { installed: await extract(record, where, guard, cache), where, placement }; })); const failed = extracted.find((item) => item.status === "rejected"); if (failed) throw failed.reason; for (const { value } of extracted) await linkBins(value.installed, value.where, value.placement); } await cache.prune(); const destination = import_node_path12.default.join(cwd, "node_modules"); const backup = import_node_path12.default.join(guard, "previous"); if (await import_promises5.default.readFile(packagePath, "utf8") !== originalManifest || ((0, import_node_fs9.existsSync)(lockPath) ? await import_promises5.default.readFile(lockPath, "utf8") : null) !== previousLock || (0, import_node_fs9.existsSync)(destination) !== state.hadModules) err("Project files changed while packages were staged. Run install again."); await saveInstall(guard, "swapping", state, atomic); if (state.hadModules) await import_promises5.default.rename(destination, backup); try { await import_promises5.default.cp(stage, destination, { recursive: true, errorOnExist: true, verbatimSymlinks: true }); if (!frozen) await atomic(lockPath, JSON.stringify({ format: 1, requests: rootRequests, resolutions: Object.fromEntries([...production && !refresh ? new Map([...Object.entries(lock.resolutions ?? {}), ...resolution.pins]) : resolution.pins].sort(([a], [b2]) => a.localeCompare(b2))) }, null, 2) + "\n"); if (save.length) await atomic(packagePath, JSON.stringify(manifest, null, 2) + "\n"); await saveInstall(guard, "committed", state, atomic); } catch (error) { try { await import_promises5.default.rm(destination, { recursive: true, force: true }); if ((0, import_node_fs9.existsSync)(backup)) await import_promises5.default.rename(backup, destination); if (save.length) await atomic(packagePath, originalManifest); if (!frozen && previousLock === null) await import_promises5.default.rm(lockPath, { force: true }); else if (!frozen) await atomic(lockPath, previousLock); } catch (rollbackError) { preserveGuard = true; err(error.message + "; rollback failed: " + rollbackError.message + ". Previous files may be under .qz-install."); } throw error; } console.log("Installed " + plan.length + " package(s) from " + registry); } finally { if (!preserveGuard) await import_promises5.default.rm(guard, { recursive: true, force: true, maxRetries: 4 }); } } async function packFiles(manifest, stage) { if (!Array.isArray(manifest.files) || !manifest.files.length) err("Set package.json files to the files and directories you want to publish."); const selected = /* @__PURE__ */ new Set(); const forbidden = /^(?:\..*|node_modules|qz\.lock|package-lock\.json|id_(?:rsa|ed25519)|credentials(?:\..*)?)$|\.(?:pem|key|pfx|p12)$/i; const safePart = (part) => part && part !== "." && part !== ".." && !forbidden.test(part) && !/[\\:\0]/.test(part); async function copy(relative) { const from = import_node_path12.default.resolve(cwd, relative); const info = await import_promises5.default.lstat(from); if (relative === "package.json" || selected.has(relative)) return; if (!inside(cwd, from) || info.isSymbolicLink()) err("Cannot publish link: " + relative); if (!inside(await import_promises5.default.realpath(cwd), await import_promises5.default.realpath(from))) err("File outside project: " + relative); if (info.isDirectory()) { for (const name of await import_promises5.default.readdir(from)) { if (safePart(name)) await copy(relative + "/" + name); } } else if (info.isFile()) { selected.add(relative); const to2 = import_node_path12.default.join(stage, "package", relative); await import_promises5.default.mkdir(import_node_path12.default.dirname(to2), { recursive: true }); await import_promises5.default.copyFile(from, to2); } else err("Cannot publish special file: " + relative); } for (const filename of manifest.files) { if (typeof filename !== "string" || !filename.replace(/\/$/, "").split("/").every(safePart)) err("Use explicit safe file paths in package.json files."); const normalized = filename.replace(/\/$/, ""); for (const [i, _2] of normalized.split("/").entries()) { const prefix = normalized.split("/").slice(0, i + 1).join("/"); if ((await import_promises5.default.lstat(import_node_path12.default.join(cwd, prefix))).isSymbolicLink()) err("Cannot publish link: " + prefix); } await copy(normalized); } for (const name of await import_promises5.default.readdir(cwd)) { if (/^(?:readme|licen[cs]e|copying)(?:\.[a-z0-9]+)?$/i.test(name) && (await import_promises5.default.lstat(import_node_path12.default.join(cwd, name))).isFile()) await copy(name); } await import_promises5.default.writeFile(import_node_path12.default.join(stage, "package", "package.json"), JSON.stringify(manifest, null, 2) + "\n"); } async function publish(tag = "latest") { const manifest = await readJSON(packagePath); const { name, version: release } = manifest; endpoint(name); if (name !== "qz" && !name.startsWith("@qz/")) err("QZ publishes packages under @qz/."); if (!import_semver.default.valid(release) || import_semver.default.valid(release) !== release) err("Set a valid version in package.json."); if (!/^[a-zA-Z][a-zA-Z0-9._-]*$/.test(tag) || import_semver.default.validRange(tag)) err("Invalid release tag."); if (manifest.private) err("This package is marked private."); for (const key of ["dependencies", "optionalDependencies", "peerDependencies"]) deps(manifest, key); const credential = await token(); const stage = await import_promises5.default.mkdtemp(import_node_path12.default.join(import_node_os.default.tmpdir(), "qz-pack-")); try { await import_promises5.default.mkdir(import_node_path12.default.join(stage, "package")); await packFiles(manifest, stage); const filename = name.split("/").at(-1) + "-" + release + ".tgz"; const file2 = import_node_path12.default.join(stage, filename); await Jn({ cwd: stage, file: file2, gzip: true, portable: true, noMtime: true }, ["package"]); if ((await import_promises5.default.stat(file2)).size > 20 * 1024 * 1024) err("Published tarballs must be at most 20 MiB."); const archive = await import_promises5.default.readFile(file2); const readmeName = (await import_promises5.default.readdir(import_node_path12.default.join(stage, "package"))).find((name2) => /^readme(?:\.[a-z0-9]+)?$/i.test(name2)); const readmePath = readmeName && import_node_path12.default.join(stage, "package", readmeName); const readme = readmePath && (await import_promises5.default.stat(readmePath)).size < 1024 * 1024 ? await import_promises5.default.readFile(readmePath, "utf8") : void 0; const record = { ...manifest, _id: name + "@" + release, dist: { tarball: registry + "/" + name + "/-/" + filename, integrity: "sha512-" + sha("sha512", archive), shasum: sha("sha1", archive, "hex") } }; await request(endpoint(name), { method: "PUT", headers: { "content-type": "application/json", authorization: "Bearer " + credential }, body: JSON.stringify({ _id: name, name, description: manifest.description, readme, "dist-tags": { [tag]: release }, versions: { [release]: record }, _attachments: { [filename]: { content_type: "application/octet-stream", data: archive.toString("base64"), length: archive.length } } }) }); console.log("Published " + name + "@" + release + " to " + registry); } finally { await import_promises5.default.rm(stage, { recursive: true, force: true }); } } async function runScript(name, args) { const scripts = (await readJSON(packagePath)).scripts ?? {}; const command = own(scripts, name); if (typeof command !== "string") err("No script named " + name); if (args.length) err("Script arguments are not supported by this release."); const env = { ...process.env }; const pathKey = Object.keys(env).find((key) => key.toLowerCase() === "path") ?? "PATH"; env[pathKey] = import_node_path12.default.join(cwd, "node_modules", ".bin") + import_node_path12.default.delimiter + (env[pathKey] || ""); const child = (0, import_node_child_process.spawn)(command, { shell: true, stdio: "inherit", env }); process.exitCode = await new Promise((resolve, reject) => { child.once("error", reject); child.once("exit", (code) => resolve(code ?? 1)); }); } var agentPendingPath = import_node_path12.default.join(home, "agent-pending.json"); var agentTokenPath = import_node_path12.default.join(home, "agent-token.json"); async function agentLogin(client = "agent") { await import_promises5.default.mkdir(home, { recursive: true, mode: 448 }); const approval = await request("/agents/device", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ client }) }).then((response) => response.json()); const link = new URL(approval.verification_uri); if (link.origin !== registry || !/^\/agents\/login\/[a-f0-9]{40}$/.test(link.pathname)) err("Invalid approval URL."); await atomic(agentPendingPath, JSON.stringify({ ...approval, expires: Date.now() + approval.expires_in * 1e3 })); console.log("Approve QZ publishing at " + link.href + "\nVerification code: " + approval.code + "\nEnter the code on the QZ page. Then run qz agent status. The link expires in 10 minutes."); } async function agentWait(poll = true) { if (!(0, import_node_fs9.existsSync)(agentPendingPath)) err("Run qz agent login first."); const device = await readJSON(agentPendingPath); while (Date.now() < device.expires) { const response = await request("/agents/token", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ id: device.id, device_secret: device.device_secret }) }); if (response.status === 200) { const { access_token, expires_in, username } = await response.json(); await atomic(agentTokenPath, JSON.stringify({ token: access_token, username, expires: Date.now() + expires_in * 1e3 })); await import_promises5.default.rm(agentPendingPath, { force: true }); console.log("Publishing approved as " + username + "."); return; } if (!poll) { console.log("Approval pending. Ask the user to enter the code on the QZ page, then run qz agent status again."); return; } await new Promise((resolve) => setTimeout(resolve, device.interval * 1e3)); } await import_promises5.default.rm(agentPendingPath, { force: true }); err("Approval expired. Run qz agent login for a new link."); } async function agentCredential() { if (process.env.QZ_AGENT_TOKEN) return process.env.QZ_AGENT_TOKEN; const saved = (0, import_node_fs9.existsSync)(agentTokenPath) ? await readJSON(agentTokenPath) : null; if (!saved || saved.expires <= Date.now()) err("Run qz agent login and qz agent wait first."); return saved.token; } async function agentCall(name, args, override) { const secret = override || await agentCredential(); const response = await request("/mcp", { method: "POST", headers: { "content-type": "application/json", accept: "application/json, text/event-stream", "mcp-protocol-version": "2025-11-25", authorization: "Bearer " + secret }, body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name, arguments: args } }) }); const body = await response.json(); if (body.error) err(body.error.message); const output = body.result.structuredContent || JSON.parse(body.result.content[0].text); if (body.result.isError) err(output.error); return output; } async function githubIdentity() { const endpoint2 = process.env.ACTIONS_ID_TOKEN_REQUEST_URL; const credential = process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN; if (!endpoint2 || !credential) err("Run --github in a GitHub Actions job with id-token: write."); const url = new URL(endpoint2); if (url.protocol !== "https:" || !url.hostname.endsWith(".actions.githubusercontent.com") || url.username || url.password) err("Invalid GitHub Actions identity endpoint."); url.searchParams.set("audience", registry); const response = await fetch(url, { headers: { authorization: "Bearer " + credential }, redirect: "error", signal: AbortSignal.timeout(1e4) }); if (!response.ok) err("GitHub could not issue an identity token (HTTP " + response.status + ")."); const { value } = await response.json(); if (typeof value !== "string" || !value) err("GitHub did not return an identity token."); return value; } async function agentPublish(slug, tag = "latest", options = {}) { const manifest = await readJSON(packagePath); if (slug && (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug) || slug.length > 50)) err("Usage: qz agent publish [package-slug]"); const name = slug ? void 0 : manifest.name; if (!slug && (!nameOK(name) || !name.startsWith("@"))) err("Set package.json name to @your-scope/package. Use your QZ username as the scope."); if (!/^[a-zA-Z][a-zA-Z0-9._-]{0,49}$/.test(tag) || import_semver.default.validRange(tag)) err("Use a valid release tag."); if (manifest.private) err("This package is marked private."); if (manifest.bundledDependencies || manifest.bundleDependencies) { err("Agent publishing does not support bundled dependencies."); } if (typeof manifest.version !== "string" || manifest.version.length > 64 || manifest.version.includes("+") || import_semver.default.valid(manifest.version) !== manifest.version) err("Set a valid package.json version without build metadata."); if (import_semver.default.prerelease(manifest.version) && tag === "latest") err("Publish prereleases with --tag beta or another non-latest tag."); if (typeof manifest.description !== "string" || !manifest.description.trim()) err("Set a package.json description."); const stage = await import_promises5.default.mkdtemp(import_node_path12.default.join(import_node_os.default.tmpdir(), "qz-agent-pack-")); try { const pack = import_node_path12.default.join(stage, "package"); await import_promises5.default.mkdir(pack); await packFiles(manifest, stage); const files = []; let bytes = 0; async function collect(directory, prefix = "") { for (const entry of await import_promises5.default.readdir(directory, { withFileTypes: true })) { const relative = prefix + entry.name; if (relative === "package.json") continue; const from = import_node_path12.default.join(directory, entry.name); if (entry.isDirectory()) await collect(from, relative + "/"); else { bytes += (await import_promises5.default.stat(from)).size; if (files.length >= 512 || bytes > 8 * 1024 * 1024) err("Packages are limited to 512 files and 8 MiB."); files.push({ path: relative, base64: (await import_promises5.default.readFile(from)).toString("base64") }); } } } await collect(pack); const rawBin = typeof manifest.bin === "string" ? { [manifest.name?.split("/").at(-1) || slug]: manifest.bin } : manifest.bin || {}; const bin = Object.fromEntries(Object.entries(rawBin).map(([name2, target]) => { if (typeof target !== "string") err("Invalid package.json bin entry."); return [name2, target.startsWith("./") ? target.slice(2) : target]; })); const result = await agentCall(options.preview ? "qz_preview" : "qz_publish", { slug, name, tag, version: manifest.version, description: manifest.description, main: (manifest.main || "index.js").replace(/^\.\//, ""), type: manifest.type || "commonjs", license: manifest.license, dependencies: deps(manifest), optionalDependencies: deps(manifest, "optionalDependencies"), peerDependencies: deps(manifest, "peerDependencies"), peerDependenciesMeta: manifest.peerDependenciesMeta, exports: manifest.exports, types: (manifest.types || manifest.typings)?.replace(/^\.\//, ""), repository: (typeof manifest.repository === "object" ? manifest.repository?.url : manifest.repository)?.replace(/^git\+/, ""), homepage: manifest.homepage, keywords: manifest.keywords, bin, files }, options.token); if (options.preview) return console.log("Review " + result.name + "@" + result.version + " at " + result.preview_url); console.log("Published " + result.name + "@" + result.version + "\n" + result.url + "\n" + result.install); } finally { await import_promises5.default.rm(stage, { recursive: true, force: true }); } } async function agentCommand([command, ...args]) { if (command === "login" && !args.length) return agentLogin(); if (command === "wait" && !args.length) return agentWait(); if (command === "status" && !args.length) { if ((0, import_node_fs9.existsSync)(agentPendingPath)) return agentWait(false); return console.log("Linked as " + (await agentCall("qz_whoami", {})).username + "."); } if (command === "whoami" && !args.length) return console.log((await agentCall("qz_whoami", {})).username); if (command === "publish" && args.length <= 1) return agentPublish(args[0]); if (command === "preview" && args.length <= 1) return agentPublish(args[0], void 0, { preview: true }); if (command === "delete" && args.length === 2) { const result = await agentCall("qz_delete", { name: args[0], version: args[1] }); return console.log("Confirm deletion at " + result.confirmation_url); } if (command === "logout" && !args.length) { if (process.env.QZ_AGENT_TOKEN || (0, import_node_fs9.existsSync)(agentTokenPath)) { await request("/agents/revoke-token", { method: "POST", headers: { authorization: "Bearer " + await agentCredential() } }); await import_promises5.default.rm(agentTokenPath, { force: true }); } await import_promises5.default.rm(agentPendingPath, { force: true }); console.log("Signed out of QZ agent access."); return; } err("Usage: qz agent login | status | wait | whoami | preview | publish | delete | logout"); } async function main([command, ...args]) { switch (command) { case "init": { if (args.length > 1) err("Usage: qz init [package-name]"); const name = args[0] ?? import_node_path12.default.basename(cwd).toLowerCase().replace(/[^a-z0-9_-]+/g, "-"); endpoint(name); await import_promises5.default.writeFile(packagePath, JSON.stringify({ name, version: "0.1.0", private: true }, null, 2) + "\n", { flag: "wx" }); console.log("Created package.json"); break; } case "install": case "i": case "add": await install(args); break; case "recover": { await recoverInstall({ cwd, guards: ".qz-install", atomic }); console.log("QZ install recovered."); break; } case "view": { if (args.length !== 1) err("Usage: qz view package[@version]"); const [name, range] = spec(args[0]); console.log(JSON.stringify(await resolver({}, false).resolve(name, range), null, 2)); break; } case "publish": { const owner = args.includes("--registry-owner"); const github = args.includes("--github"); const preview = args.includes("--preview"); if (owner && (github || preview) || github && preview) err("Choose one publish mode."); args = args.filter((arg) => arg !== "--github" && arg !== "--preview"); if (owner) args = args.filter((arg) => arg !== "--registry-owner"); if (args.length && (args.length !== 2 || args[0] !== "--tag")) err("Usage: qz publish [--tag name] [--preview | --github]"); if (owner) await publish(args[1]); else await agentPublish(void 0, args[1], { preview, token: github ? await githubIdentity() : void 0 }); break; } case "scope": { if (args[0] !== "claim" || args.length !== 2) err("Usage: qz scope claim "); const result = await agentCall("qz_claim_scope", { scope: args[1] }); console.log("Scope ready: " + result.scope); break; } case "agent": await agentCommand(args); break; case "login": if (args.length === 1 && args[0] === "--registry-owner") await login(); else if (args.length === 1 && args[0] === "--status") await agentCommand(["status"]); else if (!args.length) { await agentLogin("cli"); if (process.stdin.isTTY) await agentWait(); } else err("Usage: qz login [--status | --registry-owner]"); break; case "logout": if (args.length === 1 && args[0] === "--registry-owner") await import_promises5.default.rm(import_node_path12.default.join(home, "token"), { force: true }); else if (!args.length) await agentCommand(["logout"]); else err("Usage: qz logout"); break; case "run": await runScript(args[0], args.slice(1)); break; case "-v": case "--version": case "version": console.log(version); break; case void 0: case "--help": case "-h": case "help": console.log("QZ " + version + " " + registry + "\n\nqz init [name]\nqz install [package[@version] ...] [--frozen | --update | --offline] [--production]\nqz add package[@version]\nqz view package[@version]\nqz recover\nqz run script\nqz login [--status] | logout\nqz scope claim \nqz publish [--tag name] [--preview | --github]\nqz agent login | status | wait | whoami | preview | publish | delete | logout"); break; default: err("Unknown command: " + command + ". Run qz --help."); } } main(process.argv.slice(2)).catch((error) => { console.error("qz: " + error.message); process.exitCode = 1; });