weapp-vite
Version:
weapp-vite 一个现代化的小程序打包工具
1,509 lines (1,484 loc) • 1.12 MB
JavaScript
import {
__commonJS,
__require,
__toESM,
init_esm_shims
} from "./chunk-MDUMD5GP.mjs";
// ../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/internal/debug.js
var require_debug = __commonJS({
"../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/internal/debug.js"(exports, module) {
"use strict";
init_esm_shims();
var debug4 = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {
};
module.exports = debug4;
}
});
// ../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/internal/constants.js
var require_constants = __commonJS({
"../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/internal/constants.js"(exports, module) {
"use strict";
init_esm_shims();
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 RELEASE_TYPES = [
"major",
"premajor",
"minor",
"preminor",
"patch",
"prepatch",
"prerelease"
];
module.exports = {
MAX_LENGTH,
MAX_SAFE_COMPONENT_LENGTH,
MAX_SAFE_BUILD_LENGTH,
MAX_SAFE_INTEGER,
RELEASE_TYPES,
SEMVER_SPEC_VERSION,
FLAG_INCLUDE_PRERELEASE: 1,
FLAG_LOOSE: 2
};
}
});
// ../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/internal/re.js
var require_re = __commonJS({
"../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/internal/re.js"(exports, module) {
"use strict";
init_esm_shims();
var {
MAX_SAFE_COMPONENT_LENGTH,
MAX_SAFE_BUILD_LENGTH,
MAX_LENGTH
} = require_constants();
var debug4 = require_debug();
exports = module.exports = {};
var re = exports.re = [];
var safeRe = exports.safeRe = [];
var src = exports.src = [];
var safeSrc = exports.safeSrc = [];
var t2 = exports.t = {};
var R = 0;
var LETTERDASHNUMBER = "[a-zA-Z0-9-]";
var safeRegexReplacements = [
["\\s", 1],
["\\d", MAX_LENGTH],
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH]
];
var makeSafeRegex = (value) => {
for (const [token, max] of safeRegexReplacements) {
value = value.split(`${token}*`).join(`${token}{0,${max}}`).split(`${token}+`).join(`${token}{1,${max}}`);
}
return value;
};
var createToken = (name, value, isGlobal) => {
const safe = makeSafeRegex(value);
const index = R++;
debug4(name, index, value);
t2[name] = index;
src[index] = value;
safeSrc[index] = safe;
re[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[t2.NUMERICIDENTIFIER]})\\.(${src[t2.NUMERICIDENTIFIER]})\\.(${src[t2.NUMERICIDENTIFIER]})`);
createToken("MAINVERSIONLOOSE", `(${src[t2.NUMERICIDENTIFIERLOOSE]})\\.(${src[t2.NUMERICIDENTIFIERLOOSE]})\\.(${src[t2.NUMERICIDENTIFIERLOOSE]})`);
createToken("PRERELEASEIDENTIFIER", `(?:${src[t2.NONNUMERICIDENTIFIER]}|${src[t2.NUMERICIDENTIFIER]})`);
createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t2.NONNUMERICIDENTIFIER]}|${src[t2.NUMERICIDENTIFIERLOOSE]})`);
createToken("PRERELEASE", `(?:-(${src[t2.PRERELEASEIDENTIFIER]}(?:\\.${src[t2.PRERELEASEIDENTIFIER]})*))`);
createToken("PRERELEASELOOSE", `(?:-?(${src[t2.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t2.PRERELEASEIDENTIFIERLOOSE]})*))`);
createToken("BUILDIDENTIFIER", `${LETTERDASHNUMBER}+`);
createToken("BUILD", `(?:\\+(${src[t2.BUILDIDENTIFIER]}(?:\\.${src[t2.BUILDIDENTIFIER]})*))`);
createToken("FULLPLAIN", `v?${src[t2.MAINVERSION]}${src[t2.PRERELEASE]}?${src[t2.BUILD]}?`);
createToken("FULL", `^${src[t2.FULLPLAIN]}$`);
createToken("LOOSEPLAIN", `[v=\\s]*${src[t2.MAINVERSIONLOOSE]}${src[t2.PRERELEASELOOSE]}?${src[t2.BUILD]}?`);
createToken("LOOSE", `^${src[t2.LOOSEPLAIN]}$`);
createToken("GTLT", "((?:<|>)?=?)");
createToken("XRANGEIDENTIFIERLOOSE", `${src[t2.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
createToken("XRANGEIDENTIFIER", `${src[t2.NUMERICIDENTIFIER]}|x|X|\\*`);
createToken("XRANGEPLAIN", `[v=\\s]*(${src[t2.XRANGEIDENTIFIER]})(?:\\.(${src[t2.XRANGEIDENTIFIER]})(?:\\.(${src[t2.XRANGEIDENTIFIER]})(?:${src[t2.PRERELEASE]})?${src[t2.BUILD]}?)?)?`);
createToken("XRANGEPLAINLOOSE", `[v=\\s]*(${src[t2.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t2.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t2.XRANGEIDENTIFIERLOOSE]})(?:${src[t2.PRERELEASELOOSE]})?${src[t2.BUILD]}?)?)?`);
createToken("XRANGE", `^${src[t2.GTLT]}\\s*${src[t2.XRANGEPLAIN]}$`);
createToken("XRANGELOOSE", `^${src[t2.GTLT]}\\s*${src[t2.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[t2.COERCEPLAIN]}(?:$|[^\\d])`);
createToken("COERCEFULL", src[t2.COERCEPLAIN] + `(?:${src[t2.PRERELEASE]})?(?:${src[t2.BUILD]})?(?:$|[^\\d])`);
createToken("COERCERTL", src[t2.COERCE], true);
createToken("COERCERTLFULL", src[t2.COERCEFULL], true);
createToken("LONETILDE", "(?:~>?)");
createToken("TILDETRIM", `(\\s*)${src[t2.LONETILDE]}\\s+`, true);
exports.tildeTrimReplace = "$1~";
createToken("TILDE", `^${src[t2.LONETILDE]}${src[t2.XRANGEPLAIN]}$`);
createToken("TILDELOOSE", `^${src[t2.LONETILDE]}${src[t2.XRANGEPLAINLOOSE]}$`);
createToken("LONECARET", "(?:\\^)");
createToken("CARETTRIM", `(\\s*)${src[t2.LONECARET]}\\s+`, true);
exports.caretTrimReplace = "$1^";
createToken("CARET", `^${src[t2.LONECARET]}${src[t2.XRANGEPLAIN]}$`);
createToken("CARETLOOSE", `^${src[t2.LONECARET]}${src[t2.XRANGEPLAINLOOSE]}$`);
createToken("COMPARATORLOOSE", `^${src[t2.GTLT]}\\s*(${src[t2.LOOSEPLAIN]})$|^$`);
createToken("COMPARATOR", `^${src[t2.GTLT]}\\s*(${src[t2.FULLPLAIN]})$|^$`);
createToken("COMPARATORTRIM", `(\\s*)${src[t2.GTLT]}\\s*(${src[t2.LOOSEPLAIN]}|${src[t2.XRANGEPLAIN]})`, true);
exports.comparatorTrimReplace = "$1$2$3";
createToken("HYPHENRANGE", `^\\s*(${src[t2.XRANGEPLAIN]})\\s+-\\s+(${src[t2.XRANGEPLAIN]})\\s*$`);
createToken("HYPHENRANGELOOSE", `^\\s*(${src[t2.XRANGEPLAINLOOSE]})\\s+-\\s+(${src[t2.XRANGEPLAINLOOSE]})\\s*$`);
createToken("STAR", "(<|>)?=?\\s*\\*");
createToken("GTE0", "^\\s*>=\\s*0\\.0\\.0\\s*$");
createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
}
});
// ../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/internal/parse-options.js
var require_parse_options = __commonJS({
"../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/internal/parse-options.js"(exports, module) {
"use strict";
init_esm_shims();
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;
};
module.exports = parseOptions;
}
});
// ../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/internal/identifiers.js
var require_identifiers = __commonJS({
"../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/internal/identifiers.js"(exports, module) {
"use strict";
init_esm_shims();
var numeric2 = /^[0-9]+$/;
var compareIdentifiers = (a, b) => {
if (typeof a === "number" && typeof b === "number") {
return a === b ? 0 : a < b ? -1 : 1;
}
const anum = numeric2.test(a);
const bnum = numeric2.test(b);
if (anum && bnum) {
a = +a;
b = +b;
}
return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
};
var rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
module.exports = {
compareIdentifiers,
rcompareIdentifiers
};
}
});
// ../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/classes/semver.js
var require_semver = __commonJS({
"../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/classes/semver.js"(exports, module) {
"use strict";
init_esm_shims();
var debug4 = require_debug();
var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
var { safeRe: re, t: t2 } = require_re();
var parseOptions = require_parse_options();
var { compareIdentifiers } = require_identifiers();
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`
);
}
debug4("SemVer", version2, options);
this.options = options;
this.loose = !!options.loose;
this.includePrerelease = !!options.includePrerelease;
const m = version2.trim().match(options.loose ? re[t2.LOOSE] : re[t2.FULL]);
if (!m) {
throw new TypeError(`Invalid Version: ${version2}`);
}
this.raw = version2;
this.major = +m[1];
this.minor = +m[2];
this.patch = +m[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 (!m[4]) {
this.prerelease = [];
} else {
this.prerelease = m[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 = m[5] ? m[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) {
debug4("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 b = other.prerelease[i];
debug4("prerelease compare", i, a, b);
if (a === void 0 && b === void 0) {
return 0;
} else if (b === void 0) {
return 1;
} else if (a === void 0) {
return -1;
} else if (a === b) {
continue;
} else {
return compareIdentifiers(a, b);
}
} while (++i);
}
compareBuild(other) {
if (!(other instanceof _SemVer)) {
other = new _SemVer(other, this.options);
}
let i = 0;
do {
const a = this.build[i];
const b = other.build[i];
debug4("build compare", i, a, b);
if (a === void 0 && b === void 0) {
return 0;
} else if (b === void 0) {
return 1;
} else if (a === void 0) {
return -1;
} else if (a === b) {
continue;
} else {
return compareIdentifiers(a, b);
}
} 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, identifier2, identifierBase) {
if (release.startsWith("pre")) {
if (!identifier2 && identifierBase === false) {
throw new Error("invalid increment argument: identifier is empty");
}
if (identifier2) {
const match2 = `-${identifier2}`.match(this.options.loose ? re[t2.PRERELEASELOOSE] : re[t2.PRERELEASE]);
if (!match2 || match2[1] !== identifier2) {
throw new Error(`invalid identifier: ${identifier2}`);
}
}
}
switch (release) {
case "premajor":
this.prerelease.length = 0;
this.patch = 0;
this.minor = 0;
this.major++;
this.inc("pre", identifier2, identifierBase);
break;
case "preminor":
this.prerelease.length = 0;
this.patch = 0;
this.minor++;
this.inc("pre", identifier2, identifierBase);
break;
case "prepatch":
this.prerelease.length = 0;
this.inc("patch", identifier2, identifierBase);
this.inc("pre", identifier2, 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", identifier2, identifierBase);
}
this.inc("pre", identifier2, 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 (identifier2 === this.prerelease.join(".") && identifierBase === false) {
throw new Error("invalid increment argument: identifier already exists");
}
this.prerelease.push(base);
}
}
if (identifier2) {
let prerelease = [identifier2, base];
if (identifierBase === false) {
prerelease = [identifier2];
}
if (compareIdentifiers(this.prerelease[0], identifier2) === 0) {
if (isNaN(this.prerelease[1])) {
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;
}
};
module.exports = SemVer;
}
});
// ../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/functions/compare.js
var require_compare = __commonJS({
"../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/functions/compare.js"(exports, module) {
"use strict";
init_esm_shims();
var SemVer = require_semver();
var compare = (a, b, loose) => new SemVer(a, loose).compare(new SemVer(b, loose));
module.exports = compare;
}
});
// ../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/functions/gte.js
var require_gte = __commonJS({
"../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/functions/gte.js"(exports, module) {
"use strict";
init_esm_shims();
var compare = require_compare();
var gte2 = (a, b, loose) => compare(a, b, loose) >= 0;
module.exports = gte2;
}
});
// ../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js
var require_eventemitter3 = __commonJS({
"../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js"(exports, module) {
"use strict";
init_esm_shims();
var has = Object.prototype.hasOwnProperty;
var prefix = "~";
function Events() {
}
if (Object.create) {
Events.prototype = /* @__PURE__ */ Object.create(null);
if (!new Events().__proto__) prefix = false;
}
function EE(fn, context, once) {
this.fn = fn;
this.context = context;
this.once = once || false;
}
function addListener(emitter, event, fn, context, once) {
if (typeof fn !== "function") {
throw new TypeError("The listener must be a function");
}
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
else emitter._events[evt] = [emitter._events[evt], listener];
return emitter;
}
function clearEvent(emitter, evt) {
if (--emitter._eventsCount === 0) emitter._events = new Events();
else delete emitter._events[evt];
}
function EventEmitter4() {
this._events = new Events();
this._eventsCount = 0;
}
EventEmitter4.prototype.eventNames = function eventNames() {
var names = [], events, name;
if (this._eventsCount === 0) return names;
for (name in events = this._events) {
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
}
if (Object.getOwnPropertySymbols) {
return names.concat(Object.getOwnPropertySymbols(events));
}
return names;
};
EventEmitter4.prototype.listeners = function listeners(event) {
var evt = prefix ? prefix + event : event, handlers = this._events[evt];
if (!handlers) return [];
if (handlers.fn) return [handlers.fn];
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
ee[i] = handlers[i].fn;
}
return ee;
};
EventEmitter4.prototype.listenerCount = function listenerCount(event) {
var evt = prefix ? prefix + event : event, listeners = this._events[evt];
if (!listeners) return 0;
if (listeners.fn) return 1;
return listeners.length;
};
EventEmitter4.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
var evt = prefix ? prefix + event : event;
if (!this._events[evt]) return false;
var listeners = this._events[evt], len = arguments.length, args, i;
if (listeners.fn) {
if (listeners.once) this.removeListener(event, listeners.fn, void 0, true);
switch (len) {
case 1:
return listeners.fn.call(listeners.context), true;
case 2:
return listeners.fn.call(listeners.context, a1), true;
case 3:
return listeners.fn.call(listeners.context, a1, a2), true;
case 4:
return listeners.fn.call(listeners.context, a1, a2, a3), true;
case 5:
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
case 6:
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
}
for (i = 1, args = new Array(len - 1); i < len; i++) {
args[i - 1] = arguments[i];
}
listeners.fn.apply(listeners.context, args);
} else {
var length = listeners.length, j;
for (i = 0; i < length; i++) {
if (listeners[i].once) this.removeListener(event, listeners[i].fn, void 0, true);
switch (len) {
case 1:
listeners[i].fn.call(listeners[i].context);
break;
case 2:
listeners[i].fn.call(listeners[i].context, a1);
break;
case 3:
listeners[i].fn.call(listeners[i].context, a1, a2);
break;
case 4:
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
break;
default:
if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
args[j - 1] = arguments[j];
}
listeners[i].fn.apply(listeners[i].context, args);
}
}
}
return true;
};
EventEmitter4.prototype.on = function on(event, fn, context) {
return addListener(this, event, fn, context, false);
};
EventEmitter4.prototype.once = function once(event, fn, context) {
return addListener(this, event, fn, context, true);
};
EventEmitter4.prototype.removeListener = function removeListener(event, fn, context, once) {
var evt = prefix ? prefix + event : event;
if (!this._events[evt]) return this;
if (!fn) {
clearEvent(this, evt);
return this;
}
var listeners = this._events[evt];
if (listeners.fn) {
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
clearEvent(this, evt);
}
} else {
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
events.push(listeners[i]);
}
}
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
else clearEvent(this, evt);
}
return this;
};
EventEmitter4.prototype.removeAllListeners = function removeAllListeners(event) {
var evt;
if (event) {
evt = prefix ? prefix + event : event;
if (this._events[evt]) clearEvent(this, evt);
} else {
this._events = new Events();
this._eventsCount = 0;
}
return this;
};
EventEmitter4.prototype.off = EventEmitter4.prototype.removeListener;
EventEmitter4.prototype.addListener = EventEmitter4.prototype.on;
EventEmitter4.prefixed = prefix;
EventEmitter4.EventEmitter = EventEmitter4;
if ("undefined" !== typeof module) {
module.exports = EventEmitter4;
}
}
});
// src/constants.ts
init_esm_shims();
var VERSION = "__VERSION__";
var jsExtensions = ["ts", "js"];
var vueExtensions = ["vue"];
var configExtensions = [
"jsonc",
"json",
// 现在这个版本不推荐使用 json.ts 因为这会造成热更新缓慢
...jsExtensions.map((x) => `json.${x}`)
];
var supportedCssLangs = ["wxss", "css", "scss", "less", "sass", "styl"];
var templateExtensions = ["wxml", "html"];
// src/utils/version.ts
init_esm_shims();
var import_gte = __toESM(require_gte(), 1);
import process2 from "process";
// src/logger.ts
init_esm_shims();
import logger from "@weapp-core/logger";
var logger_default = logger;
// src/utils/version.ts
function getRuntime() {
if (typeof process2 !== "undefined" && process2.versions?.node) {
return {
runtime: "node",
version: process2.version.replace(/^v/, "")
// "v18.17.1" -> "18.17.1"
};
}
if (typeof globalThis.Deno !== "undefined" && "version" in Deno) {
return {
runtime: "deno",
version: Deno.version.deno
};
}
if (typeof globalThis.Bun !== "undefined") {
return {
runtime: "bun",
version: globalThis.Bun.version
};
}
throw new Error("Unknown runtime: cannot determine Node.js / Deno / Bun");
}
function checkRuntime(minVersions) {
const { runtime, version: version2 } = getRuntime();
const required = minVersions[runtime];
if (!required) {
logger_default.warn(`No minimum version specified for ${runtime}, skipping check.`);
return;
}
if (!(0, import_gte.default)(version2, required)) {
logger_default.warn(`\u5F53\u524D ${runtime} \u7248\u672C\u4E3A ${version2} \u65E0\u6CD5\u6EE1\u8DB3 \`weapp-vite\` \u6700\u4F4E\u8981\u6C42\u7684\u7248\u672C(>= ${required})`);
}
}
// src/utils/index.ts
init_esm_shims();
// src/utils/file.ts
init_esm_shims();
import fs from "fs-extra";
import path from "pathe";
function isJsOrTs(name) {
if (typeof name === "string") {
return /\.[jt]s$/.test(name);
}
return false;
}
function isTemplateRequest(request) {
return request.endsWith(".wxml") || request.endsWith(".html");
}
function changeFileExtension(filePath, extension) {
if (typeof filePath !== "string") {
throw new TypeError(`Expected \`filePath\` to be a string, got \`${typeof filePath}\`.`);
}
if (typeof extension !== "string") {
throw new TypeError(`Expected \`extension\` to be a string, got \`${typeof extension}\`.`);
}
if (filePath === "") {
return "";
}
extension = extension ? extension.startsWith(".") ? extension : `.${extension}` : "";
const basename4 = path.basename(filePath, path.extname(filePath));
return path.join(path.dirname(filePath), basename4 + extension);
}
async function findVueEntry(filepath) {
for (const ext2 of vueExtensions) {
const p = changeFileExtension(filepath, ext2);
if (await fs.exists(p)) {
return p;
}
}
}
async function findJsEntry(filepath) {
const predictions = jsExtensions.map((ext2) => {
return changeFileExtension(filepath, ext2);
});
for (const p of predictions) {
if (await fs.exists(p)) {
return {
path: p,
predictions
};
}
}
return {
predictions
};
}
async function findJsonEntry(filepath) {
const predictions = configExtensions.map((ext2) => {
return changeFileExtension(filepath, ext2);
});
for (const p of predictions) {
if (await fs.exists(p)) {
return {
predictions,
path: p
};
}
}
return {
predictions
};
}
async function findCssEntry(filepath) {
const predictions = supportedCssLangs.map((ext2) => {
return changeFileExtension(filepath, ext2);
});
for (const p of predictions) {
if (await fs.exists(p)) {
return {
predictions,
path: p
};
}
}
return {
predictions
};
}
async function findTemplateEntry(filepath) {
const predictions = templateExtensions.map((ext2) => {
return changeFileExtension(filepath, ext2);
});
for (const p of predictions) {
if (await fs.exists(p)) {
return {
predictions,
path: p
};
}
}
return {
predictions
};
}
function isTemplate(filepath) {
return templateExtensions.some((ext2) => filepath.endsWith(`.${ext2}`));
}
async function touch(filename) {
const time = /* @__PURE__ */ new Date();
try {
await fs.utimes(filename, time, time);
} catch {
await fs.close(await fs.open(filename, "w"));
}
}
// src/utils/json.ts
init_esm_shims();
import { get, isObject, set } from "@weapp-core/shared";
import { parse as parseJson, stringify } from "comment-json";
import path2 from "pathe";
function jsonFileRemoveJsExtension(fileName) {
return fileName.replace(/\.[jt]s$/, "");
}
function stringifyJson(value, replacer) {
return stringify(value, replacer, 2);
}
function matches(pattern, importee) {
if (pattern instanceof RegExp) {
return pattern.test(importee);
}
if (importee.length < pattern.length) {
return false;
}
if (importee === pattern) {
return true;
}
return importee.startsWith(pattern + "/");
}
function getAliasEntries({ entries } = {}) {
if (!entries) {
return [];
}
if (Array.isArray(entries)) {
return entries.map((entry) => {
return {
find: entry.find,
replacement: entry.replacement
};
});
}
return Object.entries(entries).map(([key, value]) => {
return { find: key, replacement: value };
});
}
function resolveImportee(importee, jsonPath, aliasEntries) {
if (Array.isArray(aliasEntries)) {
if (!jsonPath) {
return importee;
}
const matchedEntry = aliasEntries.find((x) => matches(x.find, importee));
if (!matchedEntry) {
return importee;
}
const updatedId = importee.replace(matchedEntry.find, matchedEntry.replacement);
return path2.relative(path2.dirname(jsonPath), updatedId);
}
return importee;
}
function resolveJson(entry, aliasEntries) {
if (entry.json) {
const json = structuredClone(entry.json);
if (entry.jsonPath && Array.isArray(aliasEntries)) {
const usingComponents = get(json, "usingComponents");
if (isObject(usingComponents)) {
for (const [key, importee] of Object.entries(usingComponents)) {
const resolvedId = resolveImportee(importee, entry.jsonPath, aliasEntries);
set(json, `usingComponents.${key}`, resolvedId);
}
set(json, "usingComponents", usingComponents);
}
if (entry.type === "app") {
const fields = ["subPackages", "subpackages"];
for (const field of fields) {
const subPackages = get(json, field);
if (Array.isArray(subPackages)) {
for (const subPackage of subPackages) {
if (subPackage.entry) {
subPackage.entry = changeFileExtension(subPackage.entry, "js");
}
}
}
}
}
}
if (Reflect.has(json, "$schema")) {
delete json.$schema;
}
return stringifyJson(json);
}
}
// src/utils/md5.ts
init_esm_shims();
import crypto from "crypto";
// src/utils/projectConfig.ts
init_esm_shims();
import fs2 from "fs-extra";
import path3 from "pathe";
async function getProjectConfig(root, options) {
const baseJsonPath = path3.resolve(root, "project.config.json");
const privateJsonPath = path3.resolve(root, "project.private.config.json");
let baseJson = {};
let privateJson = {};
if (await fs2.exists(baseJsonPath)) {
try {
baseJson = await fs2.readJson(baseJsonPath) || {};
} catch {
throw new Error(`\u89E3\u6790 json \u683C\u5F0F\u5931\u8D25, project.config.json \u4E3A\u975E\u6CD5\u7684 json \u683C\u5F0F`);
}
} else {
throw new Error(`\u5728 ${root} \u76EE\u5F55\u4E0B\u627E\u4E0D\u5230 project.config.json`);
}
if (!options?.ignorePrivate) {
if (await fs2.exists(privateJsonPath)) {
try {
privateJson = await fs2.readJson(privateJsonPath) || {};
} catch {
throw new Error(`\u89E3\u6790 json \u683C\u5F0F\u5931\u8D25, project.private.config.json \u4E3A\u975E\u6CD5\u7684 json \u683C\u5F0F`);
}
}
}
return Object.assign({}, privateJson, baseJson);
}
// src/utils/regexp.ts
init_esm_shims();
var CSS_LANGS_RE = /\.(wxss|css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
function isCSSRequest(request) {
return CSS_LANGS_RE.test(request);
}
function isRegexp(value) {
return Object.prototype.toString.call(value) === "[object RegExp]";
}
function regExpTest(arr, str, options) {
if (!Array.isArray(arr)) {
throw new TypeError("paramater 'arr' should be an Array of Regexp | String");
}
for (const item of arr) {
if (typeof item === "string") {
if (options?.exact) {
if (str === item) {
return true;
}
} else if (str.includes(item)) {
return true;
}
} else if (isRegexp(item)) {
item.lastIndex = 0;
if (item.test(str)) {
return true;
}
}
}
return false;
}
// src/utils/weappConfig.ts
init_esm_shims();
import fs3 from "fs-extra";
import path4 from "pathe";
var WEAPP_VITE_CONFIG_CANDIDATES = [
"weapp-vite.config.ts",
"weapp-vite.config.mts",
"weapp-vite.config.cts",
"weapp-vite.config.js",
"weapp-vite.config.mjs",
"weapp-vite.config.cjs",
"weapp-vite.config.json"
];
var WEAPP_VITE_CONFIG_SET = new Set(WEAPP_VITE_CONFIG_CANDIDATES);
async function findWeappConfigInDirectory(directory) {
for (const filename of WEAPP_VITE_CONFIG_CANDIDATES) {
const candidatePath = path4.resolve(directory, filename);
if (await fs3.pathExists(candidatePath)) {
return candidatePath;
}
}
return void 0;
}
async function resolveWeappConfigFile(options) {
const { root, specified } = options;
if (specified) {
const resolvedSpecified = path4.isAbsolute(specified) ? specified : path4.resolve(root, specified);
const specifiedBaseName = path4.basename(resolvedSpecified);
if (WEAPP_VITE_CONFIG_SET.has(specifiedBaseName)) {
if (await fs3.pathExists(resolvedSpecified)) {
return resolvedSpecified;
}
return void 0;
}
const fromSpecifiedDirectory = await findWeappConfigInDirectory(path4.dirname(resolvedSpecified));
if (fromSpecifiedDirectory) {
return fromSpecifiedDirectory;
}
}
return findWeappConfigInDirectory(root);
}
// src/context/getInstance.ts
init_esm_shims();
// src/context/createCompilerContextInstance.ts
init_esm_shims();
// src/runtime/autoImportPlugin.ts
init_esm_shims();
// src/runtime/autoImport/service.ts
init_esm_shims();
import { removeExtensionDeep } from "@weapp-core/shared";
import fs4 from "fs-extra";
// ../../node_modules/.pnpm/lru-cache@11.2.4/node_modules/lru-cache/dist/esm/index.js
init_esm_shims();
var defaultPerf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
var warned = /* @__PURE__ */ new Set();
var PROCESS = typeof process === "object" && !!process ? process : {};
var emitWarning = (msg, type, code, fn) => {
typeof PROCESS.emitWarning === "function" ? PROCESS.emitWarning(msg, type, code, fn) : console.error(`[${code}] ${type}: ${msg}`);
};
var AC = globalThis.AbortController;
var AS = globalThis.AbortSignal;
if (typeof AC === "undefined") {
AS = class AbortSignal {
onabort;
_onabort = [];
reason;
aborted = false;
addEventListener(_, fn) {
this._onabort.push(fn);
}
};
AC = class AbortController {
constructor() {
warnACPolyfill();
}
signal = new AS();
abort(reason) {
if (this.signal.aborted)
return;
this.signal.reason = reason;
this.signal.aborted = true;
for (const fn of this.signal._onabort) {
fn(reason);
}
this.signal.onabort?.(reason);
}
};
let printACPolyfillWarning = PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1";
const warnACPolyfill = () => {
if (!printACPolyfillWarning)
return;
printACPolyfillWarning = false;
emitWarning("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", warnACPolyfill);
};
}
var shouldWarn = (code) => !warned.has(code);
var isPosInt = (n2) => n2 && n2 === Math.floor(n2) && n2 > 0 && isFinite(n2);
var getUintArray = (max) => !isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null;
var ZeroArray = class extends Array {
constructor(size) {
super(size);
this.fill(0);
}
};
var Stack = class _Stack {
heap;
length;
// private constructor
static #constructing = false;
static create(max) {
const HeapCls = getUintArray(max);
if (!HeapCls)
return [];
_Stack.#constructing = true;
const s = new _Stack(max, HeapCls);
_Stack.#constructing = false;
return s;
}
constructor(max, HeapCls) {
if (!_Stack.#constructing) {
throw new TypeError("instantiate Stack using Stack.create(n)");
}
this.heap = new HeapCls(max);
this.length = 0;
}
push(n2) {
this.heap[this.length++] = n2;
}
pop() {
return this.heap[--this.length];
}
};
var LRUCache = class _LRUCache {
// options that cannot be changed without disaster
#max;
#maxSize;
#dispose;
#onInsert;
#disposeAfter;
#fetchMethod;
#memoMethod;
#perf;
/**
* {@link LRUCache.OptionsBase.perf}
*/
get perf() {
return this.#perf;
}
/**
* {@link LRUCache.OptionsBase.ttl}
*/
ttl;
/**
* {@link LRUCache.OptionsBase.ttlResolution}
*/
ttlResolution;
/**
* {@link LRUCache.OptionsBase.ttlAutopurge}
*/
ttlAutopurge;
/**
* {@link LRUCache.OptionsBase.updateAgeOnGet}
*/
updateAgeOnGet;
/**
* {@link LRUCache.OptionsBase.updateAgeOnHas}
*/
updateAgeOnHas;
/**
* {@link LRUCache.OptionsBase.allowStale}
*/
allowStale;
/**
* {@link LRUCache.OptionsBase.noDisposeOnSet}
*/
noDisposeOnSet;
/**
* {@link LRUCache.OptionsBase.noUpdateTTL}
*/
noUpdateTTL;
/**
* {@link LRUCache.OptionsBase.maxEntrySize}
*/
maxEntrySize;
/**
* {@link LRUCache.OptionsBase.sizeCalculation}
*/
sizeCalculation;
/**
* {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
*/
noDeleteOnFetchRejection;
/**
* {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
*/
noDeleteOnStaleGet;
/**
* {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
*/
allowStaleOnFetchAbort;
/**
* {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
*/
allowStaleOnFetchRejection;
/**
* {@link LRUCache.OptionsBase.ignoreFetchAbort}
*/
ignoreFetchAbort;
// computed properties
#size;
#calculatedSize;
#keyMap;
#keyList;
#valList;
#next;
#prev;
#head;
#tail;
#free;
#disposed;
#sizes;
#starts;
#ttls;
#autopurgeTimers;
#hasDispose;
#hasFetchMethod;
#hasDisposeAfter;
#hasOnInsert;
/**
* Do not call this method unless you need to inspect the
* inner workings of the cache. If anything returned by this
* object is modified in any way, strange breakage may occur.
*
* These fields are private for a reason!
*
* @internal
*/
static unsafeExposeInternals(c) {
return {
// properties
starts: c.#starts,
ttls: c.#ttls,
autopurgeTimers: c.#autopurgeTimers,
sizes: c.#sizes,
keyMap: c.#keyMap,
keyList: c.#keyList,
valList: c.#valList,
next: c.#next,
prev: c.#prev,
get head() {
return c.#head;
},
get tail() {
return c.#tail;
},
free: c.#free,
// methods
isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
moveToTail: (index) => c.#moveToTail(index),
indexes: (options) => c.#indexes(options),
rindexes: (options) => c.#rindexes(options),
isStale: (index) => c.#isStale(index)
};
}
// Protected read-only members
/**
* {@link LRUCache.OptionsBase.max} (read-only)
*/
get max() {
return this.#max;
}
/**
* {@link LRUCache.OptionsBase.maxSize} (read-only)
*/
get maxSize() {
return this.#maxSize;
}
/**
* The total computed size of items in the cache (read-only)
*/
get calculatedSize() {
return this.#calculatedSize;
}
/**
* The number of items stored in the cache (read-only)
*/
get size() {
return this.#size;
}
/**
* {@link LRUCache.OptionsBase.fetchMethod} (read-only)
*/
get fetchMethod() {
return this.#fetchMethod;
}
get memoMethod() {
return this.#memoMethod;
}
/**
* {@link LRUCache.OptionsBase.dispose} (read-only)
*/
get dispose() {
return this.#dispose;
}
/**
* {@link LRUCache.OptionsBase.onInsert} (read-only)
*/
get onInsert() {
return this.#onInsert;
}
/**
* {@link LRUCache.OptionsBase.disposeAfter} (read-only)
*/
get disposeAfter() {
return this.#disposeAfter;
}
constructor(options) {
const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, onInsert, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, perf } = options;
if (perf !== void 0) {
if (typeof perf?.now !== "function") {
throw new TypeError("perf option must have a now() method if specified");
}
}
this.#perf = perf ?? defaultPerf;
if (max !== 0 && !isPosInt(max)) {
throw new TypeError("max option must be a nonnegative integer");
}
const UintArray = max ? getUintArray(max) : Array;
if (!UintArray) {
throw new Error("invalid max value: " + max);
}
this.#max = max;
this.#maxSize = maxSize;
this.maxEntrySize = maxEntrySize || this.#maxSize;
this.sizeCalculation = sizeCalculation;
if (this.sizeCalculation) {
if (!this.#maxSize && !this.maxEntrySize) {
throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
}
if (typeof this.sizeCalculation !== "function") {
throw new TypeError("sizeCalculation set to non-function");
}
}
if (memoMethod !== void 0 && typeof memoMethod !== "function") {
throw new TypeError("memoMethod must be a function if defined");
}
this.#memoMethod = memoMethod;
if (fetchMethod !== void 0 && typeof fetchMethod !== "function") {
throw new TypeError("fetchMethod must be a function if specified");
}
this.#fetchMethod = fetchMethod;
this.#hasFetchMethod = !!fetchMethod;
this.#keyMap = /* @__PURE__ */ new Map();
this.#keyList = new Array(max).fill(void 0);
this.#valList = new Array(max).fill(void 0);
this.#next = new UintArray(max);
this.#prev = new UintArray(max);
this.#head = 0;
this.#tail = 0;
this.#free = Stack.create(max);
this.#size = 0;
this.#calculatedSize = 0;
if (typeof dispose === "function") {
this.#dispose = dispose;
}
if (typeof onInsert === "function") {
this.#onInsert = onInsert;
}
if (typeof disposeAfter === "function") {
this.#disposeAfter = disposeAfter;
this.#disposed = [];
} else {
this.#disposeAfter = void 0;
this.#disposed = void 0;
}
this.#hasDispose = !!this.#dispose;
this.#hasOnInsert = !!this.#onInsert;
this.#hasDisposeAfter = !!this.#disposeAfter;
this.noDisposeOnSet = !!noDisposeOnSet;
this.noUpdateTTL = !!noUpdateTTL;
this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
this.ignoreFetchAbort = !!ignoreFetchAbort;
if (this.maxEntrySize !== 0) {
if (this.#maxSize !== 0) {
if (!isPosInt(this.#maxSize)) {
throw new TypeError("maxSize must be a positive integer if specified");
}
}
if (!isPosInt(this.maxEntrySize)) {
throw new TypeError("maxEntrySize must be a positive integer if specified");
}
this.#initializeSizeTracking();
}
this.allowStale = !!allowStale;
this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
this.updateAgeOnGet = !!updateAgeOnGet;
this.updateAgeOnHas = !!updateAgeOnHas;
this.ttlResolution = isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
this.ttlAutopurge = !!ttlAutopurge;
this.ttl = ttl || 0;
if (this.ttl) {
if (!isPosInt(this.ttl)) {
throw new TypeError("ttl must be a positive integer if specified");
}
this.#initializeTTLTracking();
}
if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
throw new TypeError("At least one of max, maxSize, or ttl is required");
}
if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
const code = "LRU_CACHE_UNBOUNDED";
if (shouldWarn(code)) {
warned.add(code);
const msg = "TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.";
emitWarning(msg, "UnboundedCacheWarning", code, _LRUCache);
}
}
}
/**
* Return the number of ms left in the item's TTL. If item is not in cache,
* returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
*/
getRemainingTTL(key) {
return this.#keyMap.has(key) ? Infinity : 0;
}
#initializeTTLTracking() {
const ttls = new ZeroArray(this.#max);
const starts = new ZeroArray(this.#max);
this.#ttls = ttls;
this.#starts = starts;
const purgeTimers = this.ttlAutopurge ? new Array(this.#max) : void 0;
this.#autopurgeTimers = purgeTimers;
this.#setItemTTL = (index, ttl, start = this.#perf.now()) => {
starts[index] = ttl !== 0 ? start : 0;
ttls[index] = ttl;
if (purgeTimers?.[index]) {
clearTimeout(purgeTimers[index]);
purgeTimers[index] = void 0;
}
if (ttl !== 0 && purgeTimers) {
const t2 = setTimeout(() => {
if (this.#isStale(index)) {
this.#delete(this.#keyList[index], "expire");
}
}, ttl + 1);
if (t2.unref) {
t2.unref();
}
purgeTimers[index] = t2;
}
};
this.#updateItemAge = (index) => {
starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0;
};
this.#statusTTL = (status, index) => {
if (ttls[index]) {
const ttl = ttls[index];
const start = starts[index];
if (!ttl || !start)
return;
status.ttl = ttl;
status.start = start;
status.now = cachedNow || getNow();
const age = status.now - start;
status.remainingTTL = ttl - age;
}
};
let cachedNow = 0;
const getNow = () => {
const n2 = this.#perf.now();
if (this.ttlResolution > 0) {
cachedNow = n2;
const t2 = setTimeout(() => cachedNow = 0, this.ttlResolution);
if (t2.unref) {
t2.unref();
}
}
return n2;
};
this.getRemainingTTL = (key) => {
const index = this.#keyMap.get(key);
if (index === void 0) {
return 0;
}
const ttl = ttls[index];
const start = starts[index];
if (!ttl || !start) {
return Infinity;
}
const age = (cachedNow || getNow()) - start;
return ttl - age;
};
this.#isStale = (index) => {
const s = starts[index];
const t2 = ttls[index];
return !!t2 && !!s && (cachedNow || getNow()) - s > t2;
};
}
// conditionally set private methods related to TTL
#updateItemAge = () => {
};
#statusTTL = () => {
};
#setItemTTL = () => {
};
/* c8 ignore stop */
#isStale = () => false;
#initializeSizeTracking() {
const sizes = new ZeroArray(this.#max);
this.#calculatedSize = 0;
this.#sizes = sizes;
this.#removeItemSize = (index) => {
this.#calculatedSize -= sizes[index];
sizes[index] = 0;
};
this.#requireSize = (k, v, size, sizeCalculation) => {
if (this.#isBackgroundFetch(v)) {
return 0;
}
if (!isPosInt(size)) {
if (sizeCalculation) {
if (typeof sizeCalculation !== "function") {
throw new TypeError("sizeCalculation must be a function");
}
size