UNPKG

jspm

Version:

Import Map Package Manager

1,411 lines (1,399 loc) 5.03 MB
import { createRequire } from 'node:module'; import { fileURLToPath as __fileURLToPath } from 'node:url'; import { dirname as __dirname_ } from 'node:path'; var __require = createRequire(import.meta.url); var __filename = __fileURLToPath(import.meta.url); var __dirname = __dirname_(__filename); 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 __esm = (fn, res) => function __init() { return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; }; var __commonJS = (cb, mod) => function __require2() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); // src/logger.ts import { createWriteStream } from "node:fs"; import os2 from "node:os"; import c from "picocolors"; function log(type, message) { _log && _log(type, message); } function withType(type) { return (message) => log(type, message); } function createLogger() { let resolveQueue; let queuePromise = new Promise((resolve6) => resolveQueue = resolve6); let queue = []; const logStream = async function* () { while (true) { while (queue.length) yield queue.shift(); await queuePromise; } }; function log2(type, message) { if (queue.length) { queue.push({ type, message }); } else { queue = [{ type, message }]; const _resolveQueue = resolveQueue; queuePromise = new Promise((resolve6) => resolveQueue = resolve6); _resolveQueue(); } } return { log: log2, logStream }; } var logEnabled, logToStdout, _log, _logStream; var init_logger = __esm({ "src/logger.ts"() { logEnabled = !!process.env.JSPM_CLI_LOG; logToStdout = process.env.JSPM_CLI_LOG === "1"; if (logEnabled) { ({ log: _log, logStream: _logStream } = createLogger()); try { let logPath; let logFileStream = null; if (logToStdout) { console.log(c.red(`Debug logging enabled - outputting to stdout`)); } else { if (process.env.JSPM_CLI_LOG === "true" || process.env.JSPM_CLI_LOG?.toLowerCase() === "true") { logPath = `${os2.tmpdir()}/jspm-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 19)}.log`; } else { logPath = process.env.JSPM_CLI_LOG; } logFileStream = createWriteStream(logPath, { flags: "a", encoding: "utf8", mode: 438 }); console.log(c.red(`Debug logging enabled - writing to ${logPath}`)); } (async () => { if (logFileStream) { logFileStream.write(`JSPM CLI Log started at ${(/* @__PURE__ */ new Date()).toISOString()} `); } for await (const { type, message } of _logStream()) { const time = (/* @__PURE__ */ new Date()).toISOString().slice(11, 23); const formattedMessage = `${time} ${type}: ${message} `; if (logToStdout) { const prefix = c.bold(`${time} ${type}:`); console.log(`${prefix} ${message}`); } else if (logFileStream) { logFileStream.write(formattedMessage); } } })(); } catch (e) { console.error(c.red(`Failed to create debug logger: ${e.message}`)); } } } }); // ../node_modules/balanced-match/dist/esm/index.js var balanced, maybeMatch, range; var init_esm = __esm({ "../node_modules/balanced-match/dist/esm/index.js"() { balanced = (a, b, str) => { const ma = a instanceof RegExp ? maybeMatch(a, str) : a; const mb = b instanceof RegExp ? maybeMatch(b, str) : b; const r = ma !== null && mb != null && range(ma, mb, str); return r && { start: r[0], end: r[1], pre: str.slice(0, r[0]), body: str.slice(r[0] + ma.length, r[1]), post: str.slice(r[1] + mb.length) }; }; maybeMatch = (reg, str) => { const m = str.match(reg); return m ? m[0] : null; }; range = (a, b, str) => { let begs, beg, left, right = void 0, result; let ai = str.indexOf(a); let bi = str.indexOf(b, ai + 1); let i = ai; if (ai >= 0 && bi > 0) { if (a === b) { return [ai, bi]; } begs = []; left = str.length; while (i >= 0 && !result) { if (i === ai) { begs.push(i); ai = str.indexOf(a, i + 1); } else if (begs.length === 1) { const r = begs.pop(); if (r !== void 0) result = [r, bi]; } else { beg = begs.pop(); if (beg !== void 0 && beg < left) { left = beg; right = bi; } bi = str.indexOf(b, i + 1); } i = ai < bi && ai >= 0 ? ai : bi; } if (begs.length && right !== void 0) { result = [left, right]; } } return result; }; } }); // ../node_modules/brace-expansion/dist/esm/index.js function numeric(str) { return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0); } function escapeBraces(str) { return str.replace(slashPattern, escSlash).replace(openPattern, escOpen).replace(closePattern, escClose).replace(commaPattern, escComma).replace(periodPattern, escPeriod); } function unescapeBraces(str) { return str.replace(escSlashPattern, "\\").replace(escOpenPattern, "{").replace(escClosePattern, "}").replace(escCommaPattern, ",").replace(escPeriodPattern, "."); } function parseCommaParts(str) { if (!str) { return [""]; } const parts = []; const m = balanced("{", "}", str); if (!m) { return str.split(","); } const { pre, body, post } = m; const p = pre.split(","); p[p.length - 1] += "{" + body + "}"; const postParts = parseCommaParts(post); if (post.length) { ; p[p.length - 1] += postParts.shift(); p.push.apply(p, postParts); } parts.push.apply(parts, p); return parts; } function expand(str, options = {}) { if (!str) { return []; } const { max = EXPANSION_MAX } = options; if (str.slice(0, 2) === "{}") { str = "\\{\\}" + str.slice(2); } return expand_(escapeBraces(str), max, true).map(unescapeBraces); } function embrace(str) { return "{" + str + "}"; } function isPadded(el) { return /^-?0\d/.test(el); } function lte(i, y) { return i <= y; } function gte(i, y) { return i >= y; } function expand_(str, max, isTop) { const expansions = []; const m = balanced("{", "}", str); if (!m) return [str]; const pre = m.pre; const post = m.post.length ? expand_(m.post, max, false) : [""]; if (/\$$/.test(m.pre)) { for (let k = 0; k < post.length && k < max; k++) { const expansion = pre + "{" + m.body + "}" + post[k]; expansions.push(expansion); } } else { const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body); const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body); const isSequence = isNumericSequence || isAlphaSequence; const isOptions = m.body.indexOf(",") >= 0; if (!isSequence && !isOptions) { if (m.post.match(/,(?!,).*\}/)) { str = m.pre + "{" + m.body + escClose + m.post; return expand_(str, max, true); } return [str]; } let n2; if (isSequence) { n2 = m.body.split(/\.\./); } else { n2 = parseCommaParts(m.body); if (n2.length === 1 && n2[0] !== void 0) { n2 = expand_(n2[0], max, false).map(embrace); if (n2.length === 1) { return post.map((p) => m.pre + n2[0] + p); } } } let N; if (isSequence && n2[0] !== void 0 && n2[1] !== void 0) { const x = numeric(n2[0]); const y = numeric(n2[1]); const width = Math.max(n2[0].length, n2[1].length); let incr = n2.length === 3 && n2[2] !== void 0 ? Math.max(Math.abs(numeric(n2[2])), 1) : 1; let test = lte; const reverse = y < x; if (reverse) { incr *= -1; test = gte; } const pad = n2.some(isPadded); N = []; for (let i = x; test(i, y) && N.length < max; i += incr) { let c17; if (isAlphaSequence) { c17 = String.fromCharCode(i); if (c17 === "\\") { c17 = ""; } } else { c17 = String(i); if (pad) { const need = width - c17.length; if (need > 0) { const z = new Array(need + 1).join("0"); if (i < 0) { c17 = "-" + z + c17.slice(1); } else { c17 = z + c17; } } } } N.push(c17); } } else { N = []; for (let j = 0; j < n2.length; j++) { N.push.apply(N, expand_(n2[j], max, false)); } } for (let j = 0; j < N.length; j++) { for (let k = 0; k < post.length && expansions.length < max; k++) { const expansion = pre + N[j] + post[k]; if (!isTop || isSequence || expansion) { expansions.push(expansion); } } } } return expansions; } var escSlash, escOpen, escClose, escComma, escPeriod, escSlashPattern, escOpenPattern, escClosePattern, escCommaPattern, escPeriodPattern, slashPattern, openPattern, closePattern, commaPattern, periodPattern, EXPANSION_MAX; var init_esm2 = __esm({ "../node_modules/brace-expansion/dist/esm/index.js"() { init_esm(); escSlash = "\0SLASH" + Math.random() + "\0"; escOpen = "\0OPEN" + Math.random() + "\0"; escClose = "\0CLOSE" + Math.random() + "\0"; escComma = "\0COMMA" + Math.random() + "\0"; escPeriod = "\0PERIOD" + Math.random() + "\0"; escSlashPattern = new RegExp(escSlash, "g"); escOpenPattern = new RegExp(escOpen, "g"); escClosePattern = new RegExp(escClose, "g"); escCommaPattern = new RegExp(escComma, "g"); escPeriodPattern = new RegExp(escPeriod, "g"); slashPattern = /\\\\/g; openPattern = /\\{/g; closePattern = /\\}/g; commaPattern = /\\,/g; periodPattern = /\\\./g; EXPANSION_MAX = 1e5; } }); // ../node_modules/minimatch/dist/esm/assert-valid-pattern.js var MAX_PATTERN_LENGTH, assertValidPattern; var init_assert_valid_pattern = __esm({ "../node_modules/minimatch/dist/esm/assert-valid-pattern.js"() { MAX_PATTERN_LENGTH = 1024 * 64; assertValidPattern = (pattern) => { if (typeof pattern !== "string") { throw new TypeError("invalid pattern"); } if (pattern.length > MAX_PATTERN_LENGTH) { throw new TypeError("pattern is too long"); } }; } }); // ../node_modules/minimatch/dist/esm/brace-expressions.js var posixClasses, braceEscape, regexpEscape, rangesToString, parseClass; var init_brace_expressions = __esm({ "../node_modules/minimatch/dist/esm/brace-expressions.js"() { posixClasses = { "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true], "[:alpha:]": ["\\p{L}\\p{Nl}", true], "[:ascii:]": ["\\x00-\\x7f", false], "[:blank:]": ["\\p{Zs}\\t", true], "[:cntrl:]": ["\\p{Cc}", true], "[:digit:]": ["\\p{Nd}", true], "[:graph:]": ["\\p{Z}\\p{C}", true, true], "[:lower:]": ["\\p{Ll}", true], "[:print:]": ["\\p{C}", true], "[:punct:]": ["\\p{P}", true], "[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true], "[:upper:]": ["\\p{Lu}", true], "[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true], "[:xdigit:]": ["A-Fa-f0-9", false] }; braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&"); regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); rangesToString = (ranges) => ranges.join(""); parseClass = (glob, position) => { const pos = position; if (glob.charAt(pos) !== "[") { throw new Error("not in a brace expression"); } const ranges = []; const negs = []; let i = pos + 1; let sawStart = false; let uflag = false; let escaping = false; let negate = false; let endPos = pos; let rangeStart = ""; WHILE: while (i < glob.length) { const c17 = glob.charAt(i); if ((c17 === "!" || c17 === "^") && i === pos + 1) { negate = true; i++; continue; } if (c17 === "]" && sawStart && !escaping) { endPos = i + 1; break; } sawStart = true; if (c17 === "\\") { if (!escaping) { escaping = true; i++; continue; } } if (c17 === "[" && !escaping) { for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) { if (glob.startsWith(cls, i)) { if (rangeStart) { return ["$.", false, glob.length - pos, true]; } i += cls.length; if (neg) negs.push(unip); else ranges.push(unip); uflag = uflag || u; continue WHILE; } } } escaping = false; if (rangeStart) { if (c17 > rangeStart) { ranges.push(braceEscape(rangeStart) + "-" + braceEscape(c17)); } else if (c17 === rangeStart) { ranges.push(braceEscape(c17)); } rangeStart = ""; i++; continue; } if (glob.startsWith("-]", i + 1)) { ranges.push(braceEscape(c17 + "-")); i += 2; continue; } if (glob.startsWith("-", i + 1)) { rangeStart = c17; i += 2; continue; } ranges.push(braceEscape(c17)); i++; } if (endPos < i) { return ["", false, 0, false]; } if (!ranges.length && !negs.length) { return ["$.", false, glob.length - pos, true]; } if (negs.length === 0 && ranges.length === 1 && /^\\?.$/.test(ranges[0]) && !negate) { const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0]; return [regexpEscape(r), false, endPos - pos, false]; } const sranges = "[" + (negate ? "^" : "") + rangesToString(ranges) + "]"; const snegs = "[" + (negate ? "" : "^") + rangesToString(negs) + "]"; const comb = ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs; return [comb, uflag, endPos - pos, true]; }; } }); // ../node_modules/minimatch/dist/esm/unescape.js var unescape2; var init_unescape = __esm({ "../node_modules/minimatch/dist/esm/unescape.js"() { unescape2 = (s, { windowsPathsNoEscape = false, magicalBraces = true } = {}) => { if (magicalBraces) { return windowsPathsNoEscape ? s.replace(/\[([^/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\])\]/g, "$1$2").replace(/\\([^/])/g, "$1"); } return windowsPathsNoEscape ? s.replace(/\[([^/\\{}])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\{}])\]/g, "$1$2").replace(/\\([^/{}])/g, "$1"); }; } }); // ../node_modules/minimatch/dist/esm/ast.js var _a, types, isExtglobType, isExtglobAST, adoptionMap, adoptionWithSpaceMap, adoptionAnyMap, usurpMap, startNoTraversal, startNoDot, addPatternStart, justDots, reSpecials, regExpEscape, qmark, star, starNoEmpty, ID, AST; var init_ast = __esm({ "../node_modules/minimatch/dist/esm/ast.js"() { init_brace_expressions(); init_unescape(); types = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]); isExtglobType = (c17) => types.has(c17); isExtglobAST = (c17) => isExtglobType(c17.type); adoptionMap = /* @__PURE__ */ new Map([ ["!", ["@"]], ["?", ["?", "@"]], ["@", ["@"]], ["*", ["*", "+", "?", "@"]], ["+", ["+", "@"]] ]); adoptionWithSpaceMap = /* @__PURE__ */ new Map([ ["!", ["?"]], ["@", ["?"]], ["+", ["?", "*"]] ]); adoptionAnyMap = /* @__PURE__ */ new Map([ ["!", ["?", "@"]], ["?", ["?", "@"]], ["@", ["?", "@"]], ["*", ["*", "+", "?", "@"]], ["+", ["+", "@", "?", "*"]] ]); usurpMap = /* @__PURE__ */ new Map([ ["!", /* @__PURE__ */ new Map([["!", "@"]])], [ "?", /* @__PURE__ */ new Map([ ["*", "*"], ["+", "*"] ]) ], [ "@", /* @__PURE__ */ new Map([ ["!", "!"], ["?", "?"], ["@", "@"], ["*", "*"], ["+", "+"] ]) ], [ "+", /* @__PURE__ */ new Map([ ["?", "*"], ["*", "*"] ]) ] ]); startNoTraversal = "(?!(?:^|/)\\.\\.?(?:$|/))"; startNoDot = "(?!\\.)"; addPatternStart = /* @__PURE__ */ new Set(["[", "."]); justDots = /* @__PURE__ */ new Set(["..", "."]); reSpecials = new Set("().*{}+?[]^$\\!"); regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); qmark = "[^/]"; star = qmark + "*?"; starNoEmpty = qmark + "+?"; ID = 0; AST = class { type; #root; #hasMagic; #uflag = false; #parts = []; #parent; #parentIndex; #negs; #filledNegs = false; #options; #toString; // set to true if it's an extglob with no children // (which really means one child of '') #emptyExt = false; id = ++ID; get depth() { return (this.#parent?.depth ?? -1) + 1; } [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() { return { "@@type": "AST", id: this.id, type: this.type, root: this.#root.id, parent: this.#parent?.id, depth: this.depth, partsLength: this.#parts.length, parts: this.#parts }; } constructor(type, parent, options = {}) { this.type = type; if (type) this.#hasMagic = true; this.#parent = parent; this.#root = this.#parent ? this.#parent.#root : this; this.#options = this.#root === this ? options : this.#root.#options; this.#negs = this.#root === this ? [] : this.#root.#negs; if (type === "!" && !this.#root.#filledNegs) this.#negs.push(this); this.#parentIndex = this.#parent ? this.#parent.#parts.length : 0; } get hasMagic() { if (this.#hasMagic !== void 0) return this.#hasMagic; for (const p of this.#parts) { if (typeof p === "string") continue; if (p.type || p.hasMagic) return this.#hasMagic = true; } return this.#hasMagic; } // reconstructs the pattern toString() { return this.#toString !== void 0 ? this.#toString : !this.type ? this.#toString = this.#parts.map((p) => String(p)).join("") : this.#toString = this.type + "(" + this.#parts.map((p) => String(p)).join("|") + ")"; } #fillNegs() { if (this !== this.#root) throw new Error("should only call on root"); if (this.#filledNegs) return this; this.toString(); this.#filledNegs = true; let n2; while (n2 = this.#negs.pop()) { if (n2.type !== "!") continue; let p = n2; let pp = p.#parent; while (pp) { for (let i = p.#parentIndex + 1; !pp.type && i < pp.#parts.length; i++) { for (const part of n2.#parts) { if (typeof part === "string") { throw new Error("string part in extglob AST??"); } part.copyIn(pp.#parts[i]); } } p = pp; pp = p.#parent; } } return this; } push(...parts) { for (const p of parts) { if (p === "") continue; if (typeof p !== "string" && !(p instanceof _a && p.#parent === this)) { throw new Error("invalid part: " + p); } this.#parts.push(p); } } toJSON() { const ret = this.type === null ? this.#parts.slice().map((p) => typeof p === "string" ? p : p.toJSON()) : [this.type, ...this.#parts.map((p) => p.toJSON())]; if (this.isStart() && !this.type) ret.unshift([]); if (this.isEnd() && (this === this.#root || this.#root.#filledNegs && this.#parent?.type === "!")) { ret.push({}); } return ret; } isStart() { if (this.#root === this) return true; if (!this.#parent?.isStart()) return false; if (this.#parentIndex === 0) return true; const p = this.#parent; for (let i = 0; i < this.#parentIndex; i++) { const pp = p.#parts[i]; if (!(pp instanceof _a && pp.type === "!")) { return false; } } return true; } isEnd() { if (this.#root === this) return true; if (this.#parent?.type === "!") return true; if (!this.#parent?.isEnd()) return false; if (!this.type) return this.#parent?.isEnd(); const pl = this.#parent ? this.#parent.#parts.length : 0; return this.#parentIndex === pl - 1; } copyIn(part) { if (typeof part === "string") this.push(part); else this.push(part.clone(this)); } clone(parent) { const c17 = new _a(this.type, parent); for (const p of this.#parts) { c17.copyIn(p); } return c17; } static #parseAST(str, ast, pos, opt, extDepth) { const maxDepth = opt.maxExtglobRecursion ?? 2; let escaping = false; let inBrace = false; let braceStart = -1; let braceNeg = false; if (ast.type === null) { let i2 = pos; let acc2 = ""; while (i2 < str.length) { const c17 = str.charAt(i2++); if (escaping || c17 === "\\") { escaping = !escaping; acc2 += c17; continue; } if (inBrace) { if (i2 === braceStart + 1) { if (c17 === "^" || c17 === "!") { braceNeg = true; } } else if (c17 === "]" && !(i2 === braceStart + 2 && braceNeg)) { inBrace = false; } acc2 += c17; continue; } else if (c17 === "[") { inBrace = true; braceStart = i2; braceNeg = false; acc2 += c17; continue; } const doRecurse = !opt.noext && isExtglobType(c17) && str.charAt(i2) === "(" && extDepth <= maxDepth; if (doRecurse) { ast.push(acc2); acc2 = ""; const ext2 = new _a(c17, ast); i2 = _a.#parseAST(str, ext2, i2, opt, extDepth + 1); ast.push(ext2); continue; } acc2 += c17; } ast.push(acc2); return i2; } let i = pos + 1; let part = new _a(null, ast); const parts = []; let acc = ""; while (i < str.length) { const c17 = str.charAt(i++); if (escaping || c17 === "\\") { escaping = !escaping; acc += c17; continue; } if (inBrace) { if (i === braceStart + 1) { if (c17 === "^" || c17 === "!") { braceNeg = true; } } else if (c17 === "]" && !(i === braceStart + 2 && braceNeg)) { inBrace = false; } acc += c17; continue; } else if (c17 === "[") { inBrace = true; braceStart = i; braceNeg = false; acc += c17; continue; } const doRecurse = !opt.noext && isExtglobType(c17) && str.charAt(i) === "(" && /* c8 ignore start - the maxDepth is sufficient here */ (extDepth <= maxDepth || ast && ast.#canAdoptType(c17)); if (doRecurse) { const depthAdd = ast && ast.#canAdoptType(c17) ? 0 : 1; part.push(acc); acc = ""; const ext2 = new _a(c17, part); part.push(ext2); i = _a.#parseAST(str, ext2, i, opt, extDepth + depthAdd); continue; } if (c17 === "|") { part.push(acc); acc = ""; parts.push(part); part = new _a(null, ast); continue; } if (c17 === ")") { if (acc === "" && ast.#parts.length === 0) { ast.#emptyExt = true; } part.push(acc); acc = ""; ast.push(...parts, part); return i; } acc += c17; } ast.type = null; ast.#hasMagic = void 0; ast.#parts = [str.substring(pos - 1)]; return i; } #canAdoptWithSpace(child) { return this.#canAdopt(child, adoptionWithSpaceMap); } #canAdopt(child, map = adoptionMap) { if (!child || typeof child !== "object" || child.type !== null || child.#parts.length !== 1 || this.type === null) { return false; } const gc = child.#parts[0]; if (!gc || typeof gc !== "object" || gc.type === null) { return false; } return this.#canAdoptType(gc.type, map); } #canAdoptType(c17, map = adoptionAnyMap) { return !!map.get(this.type)?.includes(c17); } #adoptWithSpace(child, index) { const gc = child.#parts[0]; const blank = new _a(null, gc, this.options); blank.#parts.push(""); gc.push(blank); this.#adopt(child, index); } #adopt(child, index) { const gc = child.#parts[0]; this.#parts.splice(index, 1, ...gc.#parts); for (const p of gc.#parts) { if (typeof p === "object") p.#parent = this; } this.#toString = void 0; } #canUsurpType(c17) { const m = usurpMap.get(this.type); return !!m?.has(c17); } #canUsurp(child) { if (!child || typeof child !== "object" || child.type !== null || child.#parts.length !== 1 || this.type === null || this.#parts.length !== 1) { return false; } const gc = child.#parts[0]; if (!gc || typeof gc !== "object" || gc.type === null) { return false; } return this.#canUsurpType(gc.type); } #usurp(child) { const m = usurpMap.get(this.type); const gc = child.#parts[0]; const nt = m?.get(gc.type); if (!nt) return false; this.#parts = gc.#parts; for (const p of this.#parts) { if (typeof p === "object") { p.#parent = this; } } this.type = nt; this.#toString = void 0; this.#emptyExt = false; } static fromGlob(pattern, options = {}) { const ast = new _a(null, void 0, options); _a.#parseAST(pattern, ast, 0, options, 0); return ast; } // returns the regular expression if there's magic, or the unescaped // string if not. toMMPattern() { if (this !== this.#root) return this.#root.toMMPattern(); const glob = this.toString(); const [re, body, hasMagic, uflag] = this.toRegExpSource(); const anyMagic = hasMagic || this.#hasMagic || this.#options.nocase && !this.#options.nocaseMagicOnly && glob.toUpperCase() !== glob.toLowerCase(); if (!anyMagic) { return body; } const flags = (this.#options.nocase ? "i" : "") + (uflag ? "u" : ""); return Object.assign(new RegExp(`^${re}$`, flags), { _src: re, _glob: glob }); } get options() { return this.#options; } // returns the string match, the regexp source, whether there's magic // in the regexp (so a regular expression is required) and whether or // not the uflag is needed for the regular expression (for posix classes) // TODO: instead of injecting the start/end at this point, just return // the BODY of the regexp, along with the start/end portions suitable // for binding the start/end in either a joined full-path makeRe context // (where we bind to (^|/), or a standalone matchPart context (where // we bind to ^, and not /). Otherwise slashes get duped! // // In part-matching mode, the start is: // - if not isStart: nothing // - if traversal possible, but not allowed: ^(?!\.\.?$) // - if dots allowed or not possible: ^ // - if dots possible and not allowed: ^(?!\.) // end is: // - if not isEnd(): nothing // - else: $ // // In full-path matching mode, we put the slash at the START of the // pattern, so start is: // - if first pattern: same as part-matching mode // - if not isStart(): nothing // - if traversal possible, but not allowed: /(?!\.\.?(?:$|/)) // - if dots allowed or not possible: / // - if dots possible and not allowed: /(?!\.) // end is: // - if last pattern, same as part-matching mode // - else nothing // // Always put the (?:$|/) on negated tails, though, because that has to be // there to bind the end of the negated pattern portion, and it's easier to // just stick it in now rather than try to inject it later in the middle of // the pattern. // // We can just always return the same end, and leave it up to the caller // to know whether it's going to be used joined or in parts. // And, if the start is adjusted slightly, can do the same there: // - if not isStart: nothing // - if traversal possible, but not allowed: (?:/|^)(?!\.\.?$) // - if dots allowed or not possible: (?:/|^) // - if dots possible and not allowed: (?:/|^)(?!\.) // // But it's better to have a simpler binding without a conditional, for // performance, so probably better to return both start options. // // Then the caller just ignores the end if it's not the first pattern, // and the start always gets applied. // // But that's always going to be $ if it's the ending pattern, or nothing, // so the caller can just attach $ at the end of the pattern when building. // // So the todo is: // - better detect what kind of start is needed // - return both flavors of starting pattern // - attach $ at the end of the pattern when creating the actual RegExp // // Ah, but wait, no, that all only applies to the root when the first pattern // is not an extglob. If the first pattern IS an extglob, then we need all // that dot prevention biz to live in the extglob portions, because eg // +(*|.x*) can match .xy but not .yx. // // So, return the two flavors if it's #root and the first child is not an // AST, otherwise leave it to the child AST to handle it, and there, // use the (?:^|/) style of start binding. // // Even simplified further: // - Since the start for a join is eg /(?!\.) and the start for a part // is ^(?!\.), we can just prepend (?!\.) to the pattern (either root // or start or whatever) and prepend ^ or / at the Regexp construction. toRegExpSource(allowDot) { const dot = allowDot ?? !!this.#options.dot; if (this.#root === this) { this.#flatten(); this.#fillNegs(); } if (!isExtglobAST(this)) { const noEmpty = this.isStart() && this.isEnd() && !this.#parts.some((s) => typeof s !== "string"); const src = this.#parts.map((p) => { const [re, _, hasMagic, uflag] = typeof p === "string" ? _a.#parseGlob(p, this.#hasMagic, noEmpty) : p.toRegExpSource(allowDot); this.#hasMagic = this.#hasMagic || hasMagic; this.#uflag = this.#uflag || uflag; return re; }).join(""); let start2 = ""; if (this.isStart()) { if (typeof this.#parts[0] === "string") { const dotTravAllowed = this.#parts.length === 1 && justDots.has(this.#parts[0]); if (!dotTravAllowed) { const aps = addPatternStart; const needNoTrav = ( // dots are allowed, and the pattern starts with [ or . dot && aps.has(src.charAt(0)) || // the pattern starts with \., and then [ or . src.startsWith("\\.") && aps.has(src.charAt(2)) || // the pattern starts with \.\., and then [ or . src.startsWith("\\.\\.") && aps.has(src.charAt(4)) ); const needNoDot = !dot && !allowDot && aps.has(src.charAt(0)); start2 = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : ""; } } } let end = ""; if (this.isEnd() && this.#root.#filledNegs && this.#parent?.type === "!") { end = "(?:$|\\/)"; } const final2 = start2 + src + end; return [ final2, unescape2(src), this.#hasMagic = !!this.#hasMagic, this.#uflag ]; } const repeated = this.type === "*" || this.type === "+"; const start = this.type === "!" ? "(?:(?!(?:" : "(?:"; let body = this.#partsToRegExp(dot); if (this.isStart() && this.isEnd() && !body && this.type !== "!") { const s = this.toString(); const me = this; me.#parts = [s]; me.type = null; me.#hasMagic = void 0; return [s, unescape2(this.toString()), false, false]; } let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot ? "" : this.#partsToRegExp(true); if (bodyDotAllowed === body) { bodyDotAllowed = ""; } if (bodyDotAllowed) { body = `(?:${body})(?:${bodyDotAllowed})*?`; } let final = ""; if (this.type === "!" && this.#emptyExt) { final = (this.isStart() && !dot ? startNoDot : "") + starNoEmpty; } else { const close = this.type === "!" ? ( // !() must match something,but !(x) can match '' "))" + (this.isStart() && !dot && !allowDot ? startNoDot : "") + star + ")" ) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && bodyDotAllowed ? ")" : this.type === "*" && bodyDotAllowed ? `)?` : `)${this.type}`; final = start + body + close; } return [ final, unescape2(body), this.#hasMagic = !!this.#hasMagic, this.#uflag ]; } #flatten() { if (!isExtglobAST(this)) { for (const p of this.#parts) { if (typeof p === "object") { p.#flatten(); } } } else { let iterations = 0; let done = false; do { done = true; for (let i = 0; i < this.#parts.length; i++) { const c17 = this.#parts[i]; if (typeof c17 === "object") { c17.#flatten(); if (this.#canAdopt(c17)) { done = false; this.#adopt(c17, i); } else if (this.#canAdoptWithSpace(c17)) { done = false; this.#adoptWithSpace(c17, i); } else if (this.#canUsurp(c17)) { done = false; this.#usurp(c17); } } } } while (!done && ++iterations < 10); } this.#toString = void 0; } #partsToRegExp(dot) { return this.#parts.map((p) => { if (typeof p === "string") { throw new Error("string type in extglob ast??"); } const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot); this.#uflag = this.#uflag || uflag; return re; }).filter((p) => !(this.isStart() && this.isEnd()) || !!p).join("|"); } static #parseGlob(glob, hasMagic, noEmpty = false) { let escaping = false; let re = ""; let uflag = false; let inStar = false; for (let i = 0; i < glob.length; i++) { const c17 = glob.charAt(i); if (escaping) { escaping = false; re += (reSpecials.has(c17) ? "\\" : "") + c17; continue; } if (c17 === "*") { if (inStar) continue; inStar = true; re += noEmpty && /^[*]+$/.test(glob) ? starNoEmpty : star; hasMagic = true; continue; } else { inStar = false; } if (c17 === "\\") { if (i === glob.length - 1) { re += "\\\\"; } else { escaping = true; } continue; } if (c17 === "[") { const [src, needUflag, consumed, magic] = parseClass(glob, i); if (consumed) { re += src; uflag = uflag || needUflag; i += consumed - 1; hasMagic = hasMagic || magic; continue; } } if (c17 === "?") { re += qmark; hasMagic = true; continue; } re += regExpEscape(c17); } return [re, unescape2(glob), !!hasMagic, uflag]; } }; _a = AST; } }); // ../node_modules/minimatch/dist/esm/escape.js var escape; var init_escape = __esm({ "../node_modules/minimatch/dist/esm/escape.js"() { escape = (s, { windowsPathsNoEscape = false, magicalBraces = false } = {}) => { if (magicalBraces) { return windowsPathsNoEscape ? s.replace(/[?*()[\]{}]/g, "[$&]") : s.replace(/[?*()[\]\\{}]/g, "\\$&"); } return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&"); }; } }); // ../node_modules/minimatch/dist/esm/index.js var minimatch, starDotExtRE, starDotExtTest, starDotExtTestDot, starDotExtTestNocase, starDotExtTestNocaseDot, starDotStarRE, starDotStarTest, starDotStarTestDot, dotStarRE, dotStarTest, starRE, starTest, starTestDot, qmarksRE, qmarksTestNocase, qmarksTestNocaseDot, qmarksTestDot, qmarksTest, qmarksTestNoExt, qmarksTestNoExtDot, defaultPlatform, path2, sep, GLOBSTAR, qmark2, star2, twoStarDot, twoStarNoDot, filter, ext, defaults, braceExpand, makeRe, match, globMagic, regExpEscape2, Minimatch; var init_esm3 = __esm({ "../node_modules/minimatch/dist/esm/index.js"() { init_esm2(); init_assert_valid_pattern(); init_ast(); init_escape(); init_unescape(); init_ast(); init_escape(); init_unescape(); minimatch = (p, pattern, options = {}) => { assertValidPattern(pattern); if (!options.nocomment && pattern.charAt(0) === "#") { return false; } return new Minimatch(pattern, options).match(p); }; starDotExtRE = /^\*+([^+@!?*[(]*)$/; starDotExtTest = (ext2) => (f) => !f.startsWith(".") && f.endsWith(ext2); starDotExtTestDot = (ext2) => (f) => f.endsWith(ext2); starDotExtTestNocase = (ext2) => { ext2 = ext2.toLowerCase(); return (f) => !f.startsWith(".") && f.toLowerCase().endsWith(ext2); }; starDotExtTestNocaseDot = (ext2) => { ext2 = ext2.toLowerCase(); return (f) => f.toLowerCase().endsWith(ext2); }; starDotStarRE = /^\*+\.\*+$/; starDotStarTest = (f) => !f.startsWith(".") && f.includes("."); starDotStarTestDot = (f) => f !== "." && f !== ".." && f.includes("."); dotStarRE = /^\.\*+$/; dotStarTest = (f) => f !== "." && f !== ".." && f.startsWith("."); starRE = /^\*+$/; starTest = (f) => f.length !== 0 && !f.startsWith("."); starTestDot = (f) => f.length !== 0 && f !== "." && f !== ".."; qmarksRE = /^\?+([^+@!?*[(]*)?$/; qmarksTestNocase = ([$0, ext2 = ""]) => { const noext = qmarksTestNoExt([$0]); if (!ext2) return noext; ext2 = ext2.toLowerCase(); return (f) => noext(f) && f.toLowerCase().endsWith(ext2); }; qmarksTestNocaseDot = ([$0, ext2 = ""]) => { const noext = qmarksTestNoExtDot([$0]); if (!ext2) return noext; ext2 = ext2.toLowerCase(); return (f) => noext(f) && f.toLowerCase().endsWith(ext2); }; qmarksTestDot = ([$0, ext2 = ""]) => { const noext = qmarksTestNoExtDot([$0]); return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2); }; qmarksTest = ([$0, ext2 = ""]) => { const noext = qmarksTestNoExt([$0]); return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2); }; qmarksTestNoExt = ([$0]) => { const len = $0.length; return (f) => f.length === len && !f.startsWith("."); }; qmarksTestNoExtDot = ([$0]) => { const len = $0.length; return (f) => f.length === len && f !== "." && f !== ".."; }; defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix"; path2 = { win32: { sep: "\\" }, posix: { sep: "/" } }; sep = defaultPlatform === "win32" ? path2.win32.sep : path2.posix.sep; minimatch.sep = sep; GLOBSTAR = /* @__PURE__ */ Symbol("globstar **"); minimatch.GLOBSTAR = GLOBSTAR; qmark2 = "[^/]"; star2 = qmark2 + "*?"; twoStarDot = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?"; twoStarNoDot = "(?:(?!(?:\\/|^)\\.).)*?"; filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options); minimatch.filter = filter; ext = (a, b = {}) => Object.assign({}, a, b); defaults = (def) => { if (!def || typeof def !== "object" || !Object.keys(def).length) { return minimatch; } const orig = minimatch; const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options)); return Object.assign(m, { Minimatch: class Minimatch extends orig.Minimatch { constructor(pattern, options = {}) { super(pattern, ext(def, options)); } static defaults(options) { return orig.defaults(ext(def, options)).Minimatch; } }, AST: class AST extends orig.AST { /* c8 ignore start */ constructor(type, parent, options = {}) { super(type, parent, ext(def, options)); } /* c8 ignore stop */ static fromGlob(pattern, options = {}) { return orig.AST.fromGlob(pattern, ext(def, options)); } }, unescape: (s, options = {}) => orig.unescape(s, ext(def, options)), escape: (s, options = {}) => orig.escape(s, ext(def, options)), filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)), defaults: (options) => orig.defaults(ext(def, options)), makeRe: (pattern, options = {}) => orig.makeRe(pattern, ext(def, options)), braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)), match: (list2, pattern, options = {}) => orig.match(list2, pattern, ext(def, options)), sep: orig.sep, GLOBSTAR }); }; minimatch.defaults = defaults; braceExpand = (pattern, options = {}) => { assertValidPattern(pattern); if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) { return [pattern]; } return expand(pattern, { max: options.braceExpandMax }); }; minimatch.braceExpand = braceExpand; makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe(); minimatch.makeRe = makeRe; match = (list2, pattern, options = {}) => { const mm = new Minimatch(pattern, options); list2 = list2.filter((f) => mm.match(f)); if (mm.options.nonull && !list2.length) { list2.push(pattern); } return list2; }; minimatch.match = match; globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/; regExpEscape2 = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); Minimatch = class { options; set; pattern; windowsPathsNoEscape; nonegate; negate; comment; empty; preserveMultipleSlashes; partial; globSet; globParts; nocase; isWindows; platform; windowsNoMagicRoot; maxGlobstarRecursion; regexp; constructor(pattern, options = {}) { assertValidPattern(pattern); options = options || {}; this.options = options; this.maxGlobstarRecursion = options.maxGlobstarRecursion ?? 200; this.pattern = pattern; this.platform = options.platform || defaultPlatform; this.isWindows = this.platform === "win32"; const awe = "allowWindowsEscape"; this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options[awe] === false; if (this.windowsPathsNoEscape) { this.pattern = this.pattern.replace(/\\/g, "/"); } this.preserveMultipleSlashes = !!options.preserveMultipleSlashes; this.regexp = null; this.negate = false; this.nonegate = !!options.nonegate; this.comment = false; this.empty = false; this.partial = !!options.partial; this.nocase = !!this.options.nocase; this.windowsNoMagicRoot = options.windowsNoMagicRoot !== void 0 ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase); this.globSet = []; this.globParts = []; this.set = []; this.make(); } hasMagic() { if (this.options.magicalBraces && this.set.length > 1) { return true; } for (const pattern of this.set) { for (const part of pattern) { if (typeof part !== "string") return true; } } return false; } debug(..._) { } make() { const pattern = this.pattern; const options = this.options; if (!options.nocomment && pattern.charAt(0) === "#") { this.comment = true; return; } if (!pattern) { this.empty = true; return; } this.parseNegate(); this.globSet = [...new Set(this.braceExpand())]; if (options.debug) { this.debug = (...args) => console.error(...args); } this.debug(this.pattern, this.globSet); const rawGlobParts = this.globSet.map((s) => this.slashSplit(s)); this.globParts = this.preprocess(rawGlobParts); this.debug(this.pattern, this.globParts); let set = this.globParts.map((s, _, __) => { if (this.isWindows && this.windowsNoMagicRoot) { const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]); const isDrive = /^[a-z]:/i.test(s[0]); if (isUNC) { return [ ...s.slice(0, 4), ...s.slice(4).map((ss) => this.parse(ss)) ]; } else if (isDrive) { return [s[0], ...s.slice(1).map((ss) => this.parse(ss))]; } } return s.map((ss) => this.parse(ss)); }); this.debug(this.pattern, set); this.set = set.filter((s) => s.indexOf(false) === -1); if (this.isWindows) { for (let i = 0; i < this.set.length; i++) { const p = this.set[i]; if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && typeof p[3] === "string" && /^[a-z]:$/i.test(p[3])) { p[2] = "?"; } } } this.debug(this.pattern, this.set); } // various transforms to equivalent pattern sets that are // faster to process in a filesystem walk. The goal is to // eliminate what we can, and push all ** patterns as far // to the right as possible, even if it increases the number // of patterns that we have to process. preprocess(globParts) { if (this.options.noglobstar) { for (const partset of globParts) {