UNPKG

prettier

Version:

Prettier is an opinionated code formatter

1,407 lines (1,372 loc) 458 kB
import { createRequire as __prettierCreateRequire } from "module"; import { fileURLToPath as __prettierFileUrlToPath } from "url"; import { dirname as __prettierDirname } from "path"; const require = __prettierCreateRequire(import.meta.url); const __filename = __prettierFileUrlToPath(import.meta.url); const __dirname = __prettierDirname(__filename); var __defProp = Object.defineProperty; var __getOwnPropNames = Object.getOwnPropertyNames; var __esm = (fn, res, err) => function __init() { if (err) throw err[0]; try { return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; } catch (e) { throw err = [e], e; } }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; // node_modules/kasi/dist/to_space_case.js var separatorRe, splitRe, toSpaceCase, to_space_case_default; var init_to_space_case = __esm({ "node_modules/kasi/dist/to_space_case.js"() { separatorRe = /[.:/_-]/g; splitRe = /(^|[a-z ])([A-Z]+)(?=([a-z])?)/g; toSpaceCase = (value) => { return value.replace(separatorRe, " ").replace(splitRe, (_, $1, $2, $3) => $3 && $2.length > 1 ? `${$1.trim()} ${$2.slice(0, -1)} ${$2.slice(-1)}` : `${$1.trim()} ${$2}`).trim(); }; to_space_case_default = toSpaceCase; } }); // node_modules/kasi/dist/to_lower_case.js var toLowerCase, to_lower_case_default; var init_to_lower_case = __esm({ "node_modules/kasi/dist/to_lower_case.js"() { init_to_space_case(); toLowerCase = (value) => { return to_space_case_default(value).toLowerCase(); }; to_lower_case_default = toLowerCase; } }); // node_modules/kasi/dist/to_camel_case.js var upperRe, toCamelCase, to_camel_case_default; var init_to_camel_case = __esm({ "node_modules/kasi/dist/to_camel_case.js"() { init_to_lower_case(); upperRe = /\s(\w)/g; toCamelCase = (value) => { return to_lower_case_default(value).replace(upperRe, (_, char) => char.toUpperCase()); }; to_camel_case_default = toCamelCase; } }); // scripts/build/shims/shared.js var OPTIONAL_OBJECT, createMethodShim; var init_shared = __esm({ "scripts/build/shims/shared.js"() { OPTIONAL_OBJECT = 1; createMethodShim = (methodName, getImplementation) => (flags, object, ...arguments_) => { if (flags | OPTIONAL_OBJECT && (object === void 0 || object === null)) { return; } const implementation = getImplementation.call(object) ?? object[methodName]; return implementation.apply(object, arguments_); }; } }); // scripts/build/shims/method-replace-all.js var stringReplaceAll, replaceAll, method_replace_all_default; var init_method_replace_all = __esm({ "scripts/build/shims/method-replace-all.js"() { init_shared(); stringReplaceAll = String.prototype.replaceAll ?? function(pattern, replacement) { if (pattern.global) { return this.replace(pattern, replacement); } return this.split(pattern).join(replacement); }; replaceAll = /* @__PURE__ */ createMethodShim("replaceAll", function() { if (typeof this === "string") { return stringReplaceAll; } }); method_replace_all_default = replaceAll; } }); // node_modules/kasi/dist/to_kebab_case.js var toKebabCase, to_kebab_case_default; var init_to_kebab_case = __esm({ "node_modules/kasi/dist/to_kebab_case.js"() { init_method_replace_all(); init_to_lower_case(); toKebabCase = (value) => { return method_replace_all_default( /* OPTIONAL_OBJECT: false */ 0, to_lower_case_default(value), " ", "-" ); }; to_kebab_case_default = toKebabCase; } }); // node_modules/kasi/dist/index.js var init_dist = __esm({ "node_modules/kasi/dist/index.js"() { init_to_camel_case(); init_to_kebab_case(); } }); // node_modules/find-up-path/dist/index.js import fs from "fs"; import path from "path"; import process2 from "process"; var findUpPath, dist_default; var init_dist2 = __esm({ "node_modules/find-up-path/dist/index.js"() { findUpPath = (fileName, folderPath = process2.cwd(), maxDepth = 25) => { let filePath = path.normalize(path.join(folderPath, fileName)); let depth = 1; while (true) { if (depth > maxDepth) return; if (fs.existsSync(filePath)) return filePath; folderPath = path.resolve(folderPath, ".."); const filePathNext = path.normalize(path.join(folderPath, fileName)); if (filePathNext === filePath) return; filePath = filePathNext; depth += 1; } }; dist_default = findUpPath; } }); // node_modules/find-up-json/dist/utils.js var attempt; var init_utils = __esm({ "node_modules/find-up-json/dist/utils.js"() { attempt = (fn, fallback) => { try { return fn(); } catch { return fallback; } }; } }); // node_modules/find-up-json/dist/index.js import { Buffer as Buffer2 } from "buffer"; import fs2 from "fs"; import process3 from "process"; var findUp, dist_default2; var init_dist3 = __esm({ "node_modules/find-up-json/dist/index.js"() { init_dist2(); init_utils(); findUp = (fileName, folderPath = process3.cwd(), maxDepth = 25) => { const path18 = dist_default(fileName, folderPath, maxDepth); if (!path18) return; const buffer2 = attempt(() => fs2.readFileSync(path18), Buffer2.alloc(0)); const content = attempt(() => JSON.parse(buffer2.toString()), {}); return { path: path18, buffer: buffer2, content }; }; dist_default2 = findUp; } }); // node_modules/get-current-package/dist/index.js import fs3 from "fs"; import path2 from "path"; import process4 from "process"; var getCurrentPackage, dist_default3; var init_dist4 = __esm({ "node_modules/get-current-package/dist/index.js"() { init_dist3(); getCurrentPackage = () => { try { const filePath = fs3.realpathSync(process4.argv[1]); const folderPath = path2.dirname(filePath); const pkg = dist_default2("package.json", folderPath); return pkg?.content; } catch { return; } }; dist_default3 = getCurrentPackage; } }); // node_modules/tiny-colors/dist/constants.js var ENV, ARGV, ENABLED; var init_constants = __esm({ "node_modules/tiny-colors/dist/constants.js"() { ENV = globalThis.process?.env || {}; ARGV = globalThis.process?.argv || []; ENABLED = !("NO_COLOR" in ENV) && ENV.COLOR !== "0" && ENV.TERM !== "dumb" && !ARGV.includes("--no-color") && !ARGV.includes("--no-colors") && (ENV.COLOR === "1" || !globalThis.process?.stdout || globalThis.process?.stdout?.isTTY === true); } }); // node_modules/tiny-colors/dist/index.js var chain, wrap, colors, dist_default4; var init_dist5 = __esm({ "node_modules/tiny-colors/dist/index.js"() { init_constants(); chain = (modifier) => { return new Proxy(modifier, { get(target, prop) { if (prop in colors) { return chain((string2) => modifier(colors[prop](string2))); } else { return target[prop]; } } }); }; wrap = (start, end) => { return chain((string2) => { if (!ENABLED) return string2; return `\x1B[${start}m${string2}\x1B[${end}m`; }); }; colors = { /* MODIFIERS */ reset: wrap(0, 0), bold: wrap(1, 22), dim: wrap(2, 22), italic: wrap(3, 23), underline: wrap(4, 24), overline: wrap(53, 55), inverse: wrap(7, 27), hidden: wrap(8, 28), strikethrough: wrap(9, 29), /* FOREGOUND */ black: wrap(30, 39), red: wrap(31, 39), green: wrap(32, 39), yellow: wrap(33, 39), blue: wrap(34, 39), magenta: wrap(35, 39), cyan: wrap(36, 39), white: wrap(37, 39), gray: wrap(90, 39), /* BACKGROUND */ bgBlack: wrap(40, 49), bgRed: wrap(41, 49), bgGreen: wrap(42, 49), bgYellow: wrap(43, 49), bgBlue: wrap(44, 49), bgMagenta: wrap(45, 49), bgCyan: wrap(46, 49), bgWhite: wrap(47, 49), bgGray: wrap(100, 49) }; dist_default4 = colors; } }); // node_modules/tiny-bin/dist/objects/addon.js var Addon, addon_default; var init_addon = __esm({ "node_modules/tiny-bin/dist/objects/addon.js"() { Addon = class { /* CONSTRUCTOR */ constructor(bin2) { this.bin = bin2; this.stdout = bin2.stdout; this.stderr = bin2.stderr; } }; addon_default = Addon; } }); // node_modules/ansi-purge/dist/constants.js var ANSI_RE; var init_constants2 = __esm({ "node_modules/ansi-purge/dist/constants.js"() { ANSI_RE = /([\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c))/g; } }); // node_modules/ansi-purge/dist/index.js var purge, dist_default5; var init_dist6 = __esm({ "node_modules/ansi-purge/dist/index.js"() { init_constants2(); purge = (str) => { return str.replace(ANSI_RE, ""); }; dist_default5 = purge; } }); // node_modules/tiny-levenshtein/dist/matrix.js var Matrix, matrix_default; var init_matrix = __esm({ "node_modules/tiny-levenshtein/dist/matrix.js"() { Matrix = class { /* CONSTRUCTOR */ constructor(rows, columns, Buffer3 = Uint32Array) { this.rows = rows; this.columns = columns; this.buffer = new Buffer3(this.rows * this.columns); } /* API */ get(row, column2) { const index = row * this.columns + column2; return this.buffer[index]; } set(row, column2, value) { const index = row * this.columns + column2; return this.buffer[index] = value; } }; matrix_default = Matrix; } }); // node_modules/tiny-levenshtein/dist/index.js var levenshtein, dist_default6; var init_dist7 = __esm({ "node_modules/tiny-levenshtein/dist/index.js"() { init_matrix(); levenshtein = (a, b) => { if (a === b) return 0; let start = 0; let aEnd = a.length - 1; let bEnd = b.length - 1; while (start <= aEnd && start <= bEnd) { if (a[start] !== b[start]) break; start += 1; } while (aEnd >= start && bEnd >= start) { if (a[aEnd] !== b[bEnd]) break; aEnd -= 1; bEnd -= 1; } const aLength = aEnd - start + 1; const bLength = bEnd - start + 1; if (!aLength) return bLength; if (!bLength) return aLength; const maxDistance = Math.max(aLength, bLength); const Buffer3 = maxDistance < 255 ? Uint8Array : maxDistance < 65535 ? Uint16Array : Uint32Array; const matrix = new matrix_default(aLength + 1, bLength + 1, Buffer3); for (let i = 1, l = aLength; i <= l; i++) { matrix.set(i, 0, i); } for (let i = 1, l = bLength; i <= l; i++) { matrix.set(0, i, i); } for (let i = 1; i <= aLength; i++) { for (let j = 1; j <= bLength; j++) { const cost = a[start + i - 1] === b[start + j - 1] ? 0 : 1; const deletion = matrix.get(i - 1, j) + 1; const insertion = matrix.get(i, j - 1) + 1; const substitution = matrix.get(i - 1, j - 1) + cost; const value = Math.min(deletion, insertion, substitution); matrix.set(i, j, value); } } const distance = matrix.get(aLength, bLength); return distance; }; dist_default6 = levenshtein; } }); // node_modules/tiny-parse-argv/dist/utils.js var castArray, isBoolean, isNil, isNull, isOverridable, isUndefined, setNormal, setVariadic, uniq, uniqBy, without, zip; var init_utils2 = __esm({ "node_modules/tiny-parse-argv/dist/utils.js"() { castArray = (value) => { return Array.isArray(value) ? value : [value]; }; isBoolean = (value) => { return value === true || value === false; }; isNil = (value) => { return value === null || value === void 0; }; isNull = (value) => { return value === null; }; isOverridable = (value) => { return isNil(value) || isBoolean(value) || value === ""; }; isUndefined = (value) => { return value === void 0; }; setNormal = (target, key2, value, override) => { if (override) { target[key2] = value; } else if (Array.isArray(target[key2])) { target[key2].push(value); } else if (isOverridable(target[key2])) { target[key2] = value; } else { target[key2] = [target[key2], value]; } }; setVariadic = (target, key2, value, override) => { const values = castArray(value); if (override) { target[key2] = values; } else if (Array.isArray(target[key2])) { target[key2].push(...values); } else if (isOverridable(target[key2])) { target[key2] = values; } else { target[key2] = [target[key2], ...values]; } }; uniq = (values) => { return Array.from(new Set(values)); }; uniqBy = (values, iterator) => { const ids = /* @__PURE__ */ new Set(); return values.filter((value, index, arr) => { const id = iterator(value, index, arr); if (ids.has(id)) return false; ids.add(id); return true; }); }; without = (values, value) => { return values.filter((other) => other !== value); }; zip = (keys, value) => { return Object.fromEntries(Array.from(keys).map((key2) => [key2, value])); }; } }); // node_modules/tiny-parse-argv/dist/index.js var getAliasesMap, getAliasedMap, getAliasedSet, getAliasedDefaults, getAliasedIncompatibles, setAliased, parseDoubleHyphen, parseWithRegExp, parseCharSeparator, parseEqualsSeparator, parseImplicitSeparator, parseProto, parseOption, parseOptionNegation, parseValue, unquote, parseArgv, dist_default7; var init_dist8 = __esm({ "node_modules/tiny-parse-argv/dist/index.js"() { init_utils2(); getAliasesMap = (aliases = {}) => { const map = {}; for (const key2 in aliases) { const values = uniq([key2, ...aliases[key2] || []]); for (const value of values) { if (value in map) continue; map[value] = without(values, value); } } return map; }; getAliasedMap = (aliases, object) => { const map = /* @__PURE__ */ new Map(); for (const key2 in object) { const value = object[key2]; if (isUndefined(value)) continue; map.set(key2, value); const keyAliases = aliases[key2]; if (!keyAliases) continue; for (const key3 of keyAliases) { map.set(key3, value); } } return map; }; getAliasedSet = (aliases, values = []) => { const valuesAliases = values.flatMap((value) => aliases[value] || []); const valuesAliased = /* @__PURE__ */ new Set([...values, ...valuesAliases]); return valuesAliased; }; getAliasedDefaults = (aliases, defaults = {}) => { const defaultsAliased = {}; for (const key2 in defaults) { const value = defaults[key2]; const keys = uniq([key2, ...aliases[key2] || []]); for (const key3 of keys) { if (key3 in defaultsAliased) continue; defaultsAliased[key3] = value; } } return defaultsAliased; }; getAliasedIncompatibles = (aliases, incompatibles = {}) => { const incompatiblesAliased = {}; for (const source2 in incompatibles) { const sources = getAliasedSet(aliases, [source2]); const targets = getAliasedSet(aliases, incompatibles[source2]); for (const source3 of sources) { for (const target of targets) { const sourceSet = incompatiblesAliased[source3] || (incompatiblesAliased[source3] = /* @__PURE__ */ new Set()); const targetSet = incompatiblesAliased[target] || (incompatiblesAliased[target] = /* @__PURE__ */ new Set()); sourceSet.add(target); targetSet.add(source3); } } } return incompatiblesAliased; }; setAliased = (target, key2, value, unary, variadic, aliases) => { const set3 = variadic ? setVariadic : setNormal; set3(target, key2, value, unary); aliases[key2]?.forEach((alias) => { set3(target, alias, value, unary); }); }; parseDoubleHyphen = (argv) => { const index = argv.indexOf("--"); if (index < 0) return [argv, []]; const parse8 = argv.slice(0, index); const preserve = argv.slice(index + 1); return [parse8, preserve]; }; parseWithRegExp = (argv, re, callback) => { return argv.flatMap((arg) => { const match2 = re.exec(arg); if (!match2) return arg; return callback(...match2); }); }; parseCharSeparator = (argv) => { const re = /^-([a-zA-Z0-9\.]{2,})([^]*)$/; return parseWithRegExp(argv, re, (_, chars2) => chars2.split("").map((char) => `-${char}`)); }; parseEqualsSeparator = (argv) => { const re = /^(--?[^=][^=]*?)=([^]*)$/; const shieldValue = (value) => value.startsWith("-") ? `"${value}"` : value; return parseWithRegExp(argv, re, (_, key2, value) => [key2, shieldValue(value)]); }; parseImplicitSeparator = (argv) => { const re = /^(--?(?:no-)?\S*?[a-zA-Z]\S*?)((?:[0-9\/]|-(?=$))[^]*)$/; return parseWithRegExp(argv, re, (_, key2, value) => [key2, value]); }; parseProto = (argv) => { const re = /^--?(no-)?(__proto__|prototype|constructor)$/; return argv.filter((arg, index) => !re.test(arg) && !re.test(argv[index - 1])); }; parseOption = (arg) => { const optionRe = /^(--?)([^]+)$/; const match2 = optionRe.exec(arg); if (!match2) return; return match2[2]; }; parseOptionNegation = (arg) => { const negationRe = /^no-([^]+)$/; const match2 = negationRe.exec(arg); if (!match2) return [arg, true]; return [match2[1], false]; }; parseValue = (key2, valueRaw, booleans, integers, numbers, strings, validators) => { const value = unquote(String(valueRaw)); if (validators.get(key2)?.(value) === false) { return null; } if (booleans.has(key2)) { if (value === "true") return true; if (value === "false") return false; } if (integers.has(key2)) { const integer = Number(value); if (Number.isInteger(integer)) return integer; return null; } if (numbers.has(key2)) { const number = Number(value); if (!Number.isNaN(number)) return number; return null; } if (strings.has(key2) || value !== valueRaw) { return value; } const numberRe = /^0[xX][0-9a-fA-F]+$|^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][-+]?\d+)?$/; if (numberRe.test(value)) { return Number(value); } else { return value; } }; unquote = (value) => { return value.replace(/^(['"])(\1*)(.*)(\1\2)$/, "$3"); }; parseArgv = (argv, options = {}) => { const aliases = getAliasesMap(options.alias); const booleans = getAliasedSet(aliases, options.boolean); const integers = getAliasedSet(aliases, options.integer); const numbers = getAliasedSet(aliases, options.number); const strings = getAliasedSet(aliases, options.string); const eagers = getAliasedSet(aliases, options.eager); const unarys = getAliasedSet(aliases, options.unary); const variadics = getAliasedSet(aliases, options.variadic); const defaults = getAliasedDefaults(aliases, options.default); const incompatibles = getAliasedIncompatibles(aliases, options.incompatible); const validators = getAliasedMap(aliases, options.validators); const required = options.required || []; const known = /* @__PURE__ */ new Set([...booleans, ...integers, ...numbers, ...strings, ...Object.keys(defaults)]); const found = []; const onIncompatible = options.onIncompatible; const onInvalid = options.onInvalid; const onMissing = options.onMissing; const onUnknown = options.onUnknown; const [parse8, preserve] = parseDoubleHyphen(argv); const parsed = { _: [], "--": preserve }; const args = parseCharSeparator(parseImplicitSeparator(parseEqualsSeparator(parseProto(parse8)))); let optionPrev = ""; let optionEagerPrev = ""; for (let i = 0, l = args.length; i < l; i++) { const arg = args[i]; const option = parseOption(arg); if (option) { const [key2, positive] = parseOptionNegation(option); if (isOverridable(parsed[key2])) { if (!integers.has(key2) && !numbers.has(key2) && !strings.has(key2)) { const unary = unarys.has(key2); const variadic = variadics.has(key2); const value = variadic ? [positive] : positive; setAliased(parsed, key2, value, unary, variadic, aliases); } } found.push(key2); optionPrev = option; optionEagerPrev = eagers.has(key2) ? option : ""; } else { const value = parseValue(optionPrev, arg, booleans, integers, numbers, strings, validators); if (optionPrev && (!booleans.has(optionPrev) || isBoolean(value))) { if (!isNull(value)) { const unary = unarys.has(optionPrev); const variadic = variadics.has(optionPrev); setAliased(parsed, optionPrev, value, unary, variadic, aliases); } } else if (optionEagerPrev && !booleans.has(optionEagerPrev)) { if (!isNull(value)) { const unary = unarys.has(optionEagerPrev); const variadic = variadics.has(optionEagerPrev); setAliased(parsed, optionEagerPrev, value, unary, variadic, aliases); } } else { parsed._.push(String(value ?? arg)); optionEagerPrev = ""; } optionPrev = ""; } } const parsedWithDefaults = { ...defaults, ...parsed }; const parsedWithDefaultsAndBooleans = { ...zip(booleans, false), ...parsedWithDefaults }; if (onUnknown) { const unknowns = Object.keys(parsedWithDefaults).filter((key2) => key2 !== "_" && key2 !== "--" && !known.has(key2)); if (unknowns.length) { onUnknown(unknowns); } } if (onMissing) { const missings = required.filter((key2) => !(key2 in parsedWithDefaults)); if (missings.length) { onMissing(missings); } } if (onInvalid) { const invalids = found.filter((key2) => parsedWithDefaults[key2] === void 0); if (invalids.length) { onInvalid(invalids); } } if (onIncompatible) { const options2 = uniq(found); const pairs = []; for (let si = 0, sl = options2.length; si < sl; si++) { const source2 = options2[si]; const sourceIncompatibles = incompatibles[source2]; if (!sourceIncompatibles) continue; for (let ti = si + 1, tl = sl; ti < tl; ti++) { const target = options2[ti]; if (!sourceIncompatibles.has(target)) continue; pairs.push([source2, target]); } } if (pairs.length) { const pairsUnique = uniqBy(pairs, (pair) => [...pair].sort().join()); onIncompatible(pairsUnique); } } return parsedWithDefaultsAndBooleans; }; dist_default7 = parseArgv; } }); // node_modules/tiny-bin/dist/objects/utils.js var castArray2, getClosest, groupBy, identity, isArray, isObject, isUndefined2, pushBack, sum; var init_utils3 = __esm({ "node_modules/tiny-bin/dist/objects/utils.js"() { init_dist6(); init_dist(); init_dist7(); init_dist8(); castArray2 = (value) => { return Array.isArray(value) ? value : [value]; }; getClosest = (values, value, maxDistance = 3, caseInsensitive = false) => { if (!values.length) return; const target = caseInsensitive ? value.toLowerCase() : value; const targets = caseInsensitive ? values.map((value2) => value2.toLowerCase()) : values; const distances = targets.map((other) => dist_default6(target, other)); const minDistance = Math.min(...distances); if (minDistance > maxDistance) return; const minDistanceIndex = distances.indexOf(minDistance); const closest = values[minDistanceIndex]; return closest; }; groupBy = (values, iterator) => { const groups = /* @__PURE__ */ new Map(); for (let i = 0, l = values.length; i < l; i++) { const value = values[i]; const key2 = iterator(value, i, values); const group = groups.get(key2) || []; group.push(value); groups.set(key2, group); } return groups; }; identity = (value) => { return value; }; isArray = (value) => { return Array.isArray(value); }; isObject = (value) => { return typeof value === "object" && value !== null; }; isUndefined2 = (value) => { return value === void 0; }; pushBack = (map, key2) => { const value = map.get(key2); if (isUndefined2(value)) return map; map.delete(key2); map.set(key2, value); return map; }; sum = (numbers) => { return numbers.reduce((acc, value) => acc + value, 0); }; } }); // node_modules/tiny-bin/dist/objects/collection.js var Collection, collection_default; var init_collection = __esm({ "node_modules/tiny-bin/dist/objects/collection.js"() { init_addon(); init_utils3(); Collection = class extends addon_default { constructor() { super(...arguments); this.list = []; this.map = /* @__PURE__ */ new Map(); } /* API */ getAll() { return this.list; } getById(id) { return this.getByIds([id])?.value; } getByIdOrFail(id) { const value = this.getById(id); if (value) return value; const ids = Array.from(this.map.keys()); const closest = getClosest(ids, id, 3, true); this.bin.fail(`Not found "${id}"${closest ? `. Did you mean "${closest}"?` : ""}`); } getByIds(ids) { for (const id of ids) { const value = this.map.get(id); if (!value) continue; return { id, value }; } } register(value, override = false) { const existing = this.getByIds(value.ids); if (existing && override) { const index = this.list.indexOf(existing.value); existing.value.ids.forEach((id) => this.map.delete(id)); value.ids.forEach((id) => this.map.set(id, value)); this.list.splice(index, 1, value); } else { value.ids.forEach((id) => this.map.set(id, value)); this.list.push(value); } } }; collection_default = Collection; } }); // node_modules/tiny-bin/dist/objects/arguments.js var Arguments, arguments_default; var init_arguments = __esm({ "node_modules/tiny-bin/dist/objects/arguments.js"() { init_dist5(); init_collection(); Arguments = class extends collection_default { /* API */ print(mode) { const args = this.getAll(); if (!args.length) return; const table = args.map((arg) => [ dist_default4.yellow(arg.name), arg.description ]); this.stdout.group("ARGUMENTS", () => { this.stdout.table(table, mode); }); } }; arguments_default = Arguments; } }); // node_modules/tiny-bin/dist/objects/options.js var Options, options_default; var init_options = __esm({ "node_modules/tiny-bin/dist/objects/options.js"() { init_dist5(); init_collection(); init_utils3(); Options = class extends collection_default { /* API */ print(mode) { const options = this.getAll(); if (!options.length) return; const optionsVisible = options.filter((option) => !option.hidden); if (!optionsVisible.length) return; const withoutOther = (section) => section.toLowerCase() !== "other" ? section : ""; const optionsBySection = pushBack(groupBy(optionsVisible, (option) => withoutOther(option.section.toLowerCase())), ""); optionsBySection.forEach((options2, section) => { if (!options2.length) return; const title = section ? `${section.toUpperCase()} OPTIONS` : optionsBySection.size > 1 ? "OTHER OPTIONS" : "OPTIONS"; const table = options2.map((option) => { const withDeprecated = option.deprecated ? dist_default4.dim : identity; return [ [ [ ...option.data.longs.sort().map((long) => dist_default4.green(`--${long}`)), ...option.data.shorts.sort().map((short) => dist_default4.green(`-${short}`)) ].join(", "), [ ...option.data.args.sort().map((arg) => dist_default4.blue(`<${arg}${option.variadic ? "..." : ""}>`)) ].join(" ") ].join(" "), option.description ].map(withDeprecated); }); this.stdout.group(title, () => { this.stdout.table(table, mode); }); }); } }; options_default = Options; } }); // node_modules/tiny-bin/dist/objects/usage.js var Usage, usage_default; var init_usage = __esm({ "node_modules/tiny-bin/dist/objects/usage.js"() { init_dist5(); init_addon(); init_utils3(); Usage = class extends addon_default { constructor() { super(...arguments); this.usages = /* @__PURE__ */ new Set(); } /* API */ print(command) { this.stdout.group("USAGE", () => { if (this.usages.size) { this.usages.forEach((usage) => { this.stdout.print(usage); }); } else { const isCommandDefault = command === this.bin.command; const binName = this.bin.config.name; const commandName = isCommandDefault ? "" : dist_default4.magenta(command.name); const name = [binName, commandName].filter(identity).join(" "); const commands = isCommandDefault && !command.handler ? dist_default4.magenta("[command]") : ""; const args = command.arguments.getAll().map((arg) => dist_default4.yellow(arg.name)).join(" "); const isOptionRequired = (option) => option.required && isUndefined2(option.default) && !option.hidden; const optionsGlobalRequired = !isCommandDefault ? this.bin.command.options.getAll().filter(isOptionRequired) : []; const optionsLocalRequired = command.options.getAll().filter(isOptionRequired); const optionsRequired = [...optionsGlobalRequired, ...optionsLocalRequired]; const options = optionsRequired.map((option) => { const flagName = option.data.longs[0] || option.data.shorts[0]; const flag = dist_default4.green(`--${flagName}`); const argName = option.data.args[0]; const argVariadic = option.variadic ? "..." : ""; const arg = argName ? dist_default4.blue(`<${argName}${argVariadic}>`) : ""; return [flag, arg].filter(identity).join(" "); }).join(" "); const line2 = [name, commands, options, args].filter(identity).join(" "); this.stdout.print(line2); } }); } register(usage) { this.usages.add(usage); } }; usage_default = Usage; } }); // node_modules/tiny-bin/dist/objects/command.js var Command, command_default; var init_command = __esm({ "node_modules/tiny-bin/dist/objects/command.js"() { init_addon(); init_arguments(); init_options(); init_usage(); Command = class extends addon_default { /* CONSTRUCTOR */ constructor(bin2, options) { super(bin2); this.arguments = new arguments_default(this.bin); this.options = new options_default(this.bin); this.usage = new usage_default(this.bin); this.ids = [this.parse(options.name)]; this.name = options.name; this.description = options.description || ""; this.section = options.section || ""; this.deprecated = !!options.deprecated; this.hidden = !!options.hidden; } /* PRIVATE API */ parse(name) { const re = /^_?[a-z][a-z-]*$/; const isValid = re.test(name); if (!isValid) this.bin.fail(`Invalid command: "${name}"`); return name; } /* API */ async run(options, argv) { if (!this.handler) { this.bin.fail(`Command handler not defined for command: "${this.name}"`); } else { return this.handler(options, options._, options["--"]); } } }; command_default = Command; } }); // node_modules/tiny-bin/dist/objects/command_default.js var CommandDefault, command_default_default; var init_command_default = __esm({ "node_modules/tiny-bin/dist/objects/command_default.js"() { init_command(); init_utils3(); CommandDefault = class extends command_default { /* CONSTRUCTOR */ constructor(bin2) { super(bin2, { name: "_default", description: "Execute the default action", hidden: true }); } /* API */ async run(options, argv) { const name = this.bin.commands.getById(options._[0]) ? options._[0] : this.name; if (options["help"] || name === "help") { return this.bin.commands.run("help", options, argv); } else if (options["version"] || options["v"]) { return this.bin.commands.run("_version", options, argv); } else { const isDefault = name === this.name; if (isDefault && !this.handler) { this.bin.fail("Command handler not defined for default command"); } const command = this.bin.commands.getByIdOrFail(name); const options2 = [...this.bin.command.options.getAll(), ...command.options.getAll()]; const minArgs = command.arguments.getAll().filter((arg) => arg.required).length; const maxArgs = sum(command.arguments.getAll().map((arg) => arg.variadic ? Infinity : 1)); const parseArgvOptions = { known: [], boolean: [], integer: [], number: [], string: [], eager: [], required: [], unary: [], variadic: [], alias: {}, default: {}, incompatible: {}, validators: {}, onIncompatible: (options3) => { this.bin.fail(`Incompatible options: "${options3[0][0]}" and "${options3[0][1]}" cannot be used together`); }, onInvalid: (options3) => { this.bin.fail(`Invalid value for "${options3[0]}" option`); }, onMissing: (options3) => { this.bin.fail(`Missing required option: "${options3[0]}"`); }, onUnknown: (options3) => { const closest = getClosest(parseArgvOptions.known, options3[0], 3, true); this.bin.fail(`Unknown option: "${options3[0]}"${closest ? `. Did you mean "${closest}"?` : ""}`); } }; options2.forEach((option) => { var _a, _b; parseArgvOptions.known.push(...option.data.alls); if (option.data.type === "boolean") { parseArgvOptions.boolean.push(...option.data.alls); } if (option.data.type === "integer") { parseArgvOptions.integer.push(...option.data.alls); } if (option.data.type === "number") { parseArgvOptions.number.push(...option.data.alls); } if (option.data.type === "string") { parseArgvOptions.string.push(...option.data.alls); } if (option.eager) { parseArgvOptions.eager.push(...option.data.alls); } if (option.incompatible) { const incompatible = (_a = parseArgvOptions.incompatible)[_b = option.data.alls[0]] || (_a[_b] = []); incompatible.push(...option.incompatible); } if (option.required) { parseArgvOptions.required.push(...option.data.alls); } if (!option.variadic) { parseArgvOptions.unary.push(...option.data.alls); } if (option.variadic) { parseArgvOptions.variadic.push(...option.data.alls); } if (option.validate) { parseArgvOptions.validators[option.data.alls[0]] = option.validate; } if ("default" in option) { parseArgvOptions.default[option.data.alls[0]] = option.default; } const [first, ...rest] = option.data.alls; parseArgvOptions.alias[first] = rest; }); const parsed = dist_default7(argv, parseArgvOptions); options2.forEach((option) => { if (option.data.type !== "string") return; const name2 = option.data.alls[0]; const value = parsed[name2]; if (!value) return; const enums = option.enum; if (!enums) return; const values = castArray2(value); values.forEach((value2) => { if (enums.includes(value2)) return; this.bin.fail(`Invalid value for "${option.data.alls[0]}" option, received "${value2}" but only ${enums.map((e) => `"${e}"`).join(", ")} are supported`); }); }); options2.forEach((option) => { const name2 = option.data.alls[0]; const value = parsed[name2]; if (!isArray(value)) return; if (value.length < 2) return; if (option.variadic) return; this.bin.fail(`Expected 1 value for "${option.data.alls[0]}" option, but received "${value.length}" values`); }); Object.keys(parsed).forEach((key2) => { const camelKey = to_camel_case_default(key2); if (camelKey === key2) return; parsed[camelKey] = parsed[key2]; }); if (!isDefault) { parsed._.shift(); } const actualArgs = parsed._.length; if (actualArgs < minArgs || actualArgs > maxArgs) { if (minArgs === maxArgs) { this.bin.fail(`Expected ${minArgs} arguments, but received ${actualArgs} arguments`); } else { this.bin.fail(`Expected between ${minArgs} and ${maxArgs} arguments, but received ${actualArgs} arguments`); } } if (isDefault) { return this.handler(parsed, parsed._, parsed["--"]); } else { return command.run(parsed, argv); } } } }; command_default_default = CommandDefault; } }); // node_modules/tiny-bin/dist/objects/argument.js var Argument, argument_default; var init_argument = __esm({ "node_modules/tiny-bin/dist/objects/argument.js"() { init_addon(); Argument = class extends addon_default { /* CONSTRUCTOR */ constructor(bin2, options) { super(bin2); this.ids = [this.parse(options.name)]; this.name = options.name; this.description = options.description || ""; this.required = options.name[0] === "<"; this.variadic = options.name.includes("..."); } /* PRIVATE API */ parse(name) { const re = /^\[([^\].]+)(?:\.\.\.)?\]$|^<([^>.]+)(?:\.\.\.)?>$/; const match2 = re.exec(name); if (!match2) this.bin.fail(`Invalid argument: "${name}"`); const id = match2[1] || match2[2]; return id; } }; argument_default = Argument; } }); // node_modules/tiny-bin/dist/objects/command_help.js var CommandHelp, command_help_default; var init_command_help = __esm({ "node_modules/tiny-bin/dist/objects/command_help.js"() { init_collection(); init_command(); init_argument(); CommandHelp = class extends command_default { /* CONSTRUCTOR */ constructor(bin2) { super(bin2, { name: "help", description: "Display help for the command" }); this.arguments.register(new argument_default(bin2, { name: "[command]", description: "The command to display help for" })); } /* PRIVATE API */ getPrintMode(collections) { return collections.some((collection) => collection.getAll().some((item) => item.description.includes("\n"))) ? "lines" : "line"; } /* API */ async run(options, argv) { const [arg1, arg2] = options._; const hasCustomCommands = this.bin.commands.getAll().length > 3; const name = arg1 === "help" ? arg2 || (options["help"] ? arg1 : "") : hasCustomCommands ? arg1 : ""; if (name) { const command = this.bin.commands.getByIdOrFail(name); const mode = this.getPrintMode([command.arguments, command.options, this.bin.command.options]); this.stdout.indent(); this.stdout.print(); this.bin.config.print(); command.usage.print(command); command.arguments.print(mode); this.bin.command.options.print(mode); command.options.print(mode); this.stdout.dedent(); } else { const mode = this.getPrintMode([this.bin.command.arguments, this.bin.command.options, this.bin.commands]); this.stdout.indent(); this.stdout.print(); this.bin.config.print(); this.bin.command.usage.print(this.bin.command); this.bin.command.arguments.print(mode); this.bin.command.options.print(mode); if (hasCustomCommands) { this.bin.commands.print(mode); } this.stdout.dedent(); } } }; command_help_default = CommandHelp; } }); // node_modules/tiny-bin/dist/objects/command_version.js var CommandVersion, command_version_default; var init_command_version = __esm({ "node_modules/tiny-bin/dist/objects/command_version.js"() { init_command(); CommandVersion = class extends command_default { /* CONSTRUCTOR */ constructor(bin2) { super(bin2, { name: "_version", description: "Display the version number", hidden: true }); } /* API */ async run(options, argv) { this.stdout.print(this.bin.config.version); } }; command_version_default = CommandVersion; } }); // node_modules/tiny-bin/dist/objects/commands.js var Commands, commands_default; var init_commands = __esm({ "node_modules/tiny-bin/dist/objects/commands.js"() { init_dist5(); init_collection(); init_utils3(); Commands = class extends collection_default { /* API */ print(mode) { const commands = this.getAll(); if (!commands.length) return; const commandsVisible = commands.filter((command) => !command.hidden); if (!commandsVisible.length) return; const withoutOther = (section) => section.toLowerCase() !== "other" ? section : ""; const commandsBySection = pushBack(groupBy(commandsVisible, (command) => withoutOther(command.section.toLowerCase())), ""); commandsBySection.forEach((commands2, section) => { if (!commands2.length) return; const title = section ? `${section.toUpperCase()} COMMANDS` : commandsBySection.size > 1 ? "OTHER COMMANDS" : "COMMANDS"; const table = commands2.map((command) => { const withDeprecated = command.deprecated ? dist_default4.dim : identity; return [ [ dist_default4.magenta(command.name), ...command.arguments.getAll().map((arg) => dist_default4.yellow(arg.name)) ].join(" "), command.description ].map(withDeprecated); }); this.stdout.group(title, () => { this.stdout.table(table, mode); }); }); } run(name, options, argv) { const command = this.getByIdOrFail(name); return command.run(options, argv); } }; commands_default = Commands; } }); // node_modules/tiny-bin/dist/objects/config.js var Config, config_default; var init_config = __esm({ "node_modules/tiny-bin/dist/objects/config.js"() { init_dist5(); init_dist5(); init_addon(); Config = class extends addon_default { constructor() { super(...arguments); this.name = "bin"; this.description = ""; this.package = ""; this.version = ""; this.colors = ENABLED; this.autoExit = true; } /* API */ print() { this.stdout.print(`${dist_default4.cyan(this.name)} ${dist_default4.dim(this.version)}`); this.stdout.print(); } update(options) { Object.assign(this, options); } }; config_default = Config; } }); // node_modules/fast-string-truncated-width/dist/utils.js var getCodePointsLength, isFullWidth, isWideNotCJKTNotEmoji; var init_utils4 = __esm({ "node_modules/fast-string-truncated-width/dist/utils.js"() { getCodePointsLength = /* @__PURE__ */ (() => { const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g; return (input) => { let surrogatePairsNr = 0; SURROGATE_PAIR_RE.lastIndex = 0; while (SURROGATE_PAIR_RE.test(input)) { surrogatePairsNr += 1; } return input.length - surrogatePairsNr; }; })(); isFullWidth = (x) => { return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510; }; isWideNotCJKTNotEmoji = (x) => { return x === 8987 || x === 9001 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141; }; } }); // node_modules/fast-string-truncated-width/dist/index.js var ANSI_RE2, CONTROL_RE, CJKT_WIDE_RE, TAB_RE, EMOJI_RE, LATIN_RE, MODIFIER_RE, NO_TRUNCATION, getStringTruncatedWidth, dist_default8; var init_dist9 = __esm({ "node_modules/fast-string-truncated-width/dist/index.js"() { init_method_replace_all(); init_utils4(); ANSI_RE2 = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y; CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y; CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu; TAB_RE = /\t{1,1000}/y; EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu; LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y; MODIFIER_RE = /\p{M}+/gu; NO_TRUNCATION = { limit: Infinity, ellipsis: "" }; getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => { const LIMIT = truncationOptions.limit ?? Infinity; const ELLIPSIS2 = truncationOptions.ellipsis ?? ""; const ELLIPSIS_WIDTH2 = truncationOptions?.ellipsisWidth ?? (ELLIPSIS2 ? getStringTruncatedWidth(ELLIPSIS2, NO_TRUNCATION, widthOptions).width : 0); const ANSI_WIDTH = 0; const CONTROL_WIDTH = widthOptions.controlWidth ?? 0; const TAB_WIDTH = widthOptions.tabWidth ?? 8; const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2; const FULL_WIDTH_WIDTH = 2; const REGULAR_WIDTH = widthOptions.regularWidth ?? 1; const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH; const PARSE_BLOCKS = [[LATIN_RE, REGULAR_WIDTH], [ANSI_RE2, ANSI_WIDTH], [CONTROL_RE, CONTROL_WIDTH], [TAB_RE, TAB_WIDTH], [EMOJI_RE, EMOJI_WIDTH], [CJKT_WIDE_RE, WIDE_WIDTH]]; let indexPrev = 0; let index = 0; let length = input.length; let lengthExtra = 0; let truncationEnabled = false; let truncationIndex = length; let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH2); let unmatchedStart = 0; let unmatchedEnd = 0; let width = 0; let widthExtra = 0; outer: while (true) { if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) { const unmatched