UNPKG

dax

Version:

Cross platform shell tools inspired by zx.

1,562 lines (1,557 loc) 736 kB
"use strict"; var __getOwnPropNames = Object.getOwnPropertyNames; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; // npm/script/_dnt.polyfills.js var require_dnt_polyfills = __commonJS({ "npm/script/_dnt.polyfills.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); if (!Object.hasOwn) { Object.defineProperty(Object, "hasOwn", { value: function(object, property) { if (object == null) { throw new TypeError("Cannot convert undefined or null to object"); } return Object.prototype.hasOwnProperty.call(Object(object), property); }, configurable: true, enumerable: false, writable: true }); } if (Promise.withResolvers === void 0) { Promise.withResolvers = () => { const out = {}; out.promise = new Promise((resolve_, reject_) => { out.resolve = resolve_; out.reject = reject_; }); return out; }; } function findLastIndex(self, callbackfn, that) { const boundFunc = that === void 0 ? callbackfn : callbackfn.bind(that); let index = self.length - 1; while (index >= 0) { const result = boundFunc(self[index], index, self); if (result) { return index; } index--; } return -1; } function findLast(self, callbackfn, that) { const index = self.findLastIndex(callbackfn, that); return index === -1 ? void 0 : self[index]; } if (!Array.prototype.findLastIndex) { Array.prototype.findLastIndex = function(callbackfn, that) { return findLastIndex(this, callbackfn, that); }; } if (!Array.prototype.findLast) { Array.prototype.findLast = function(callbackfn, that) { return findLast(this, callbackfn, that); }; } if (!Uint8Array.prototype.findLastIndex) { Uint8Array.prototype.findLastIndex = function(callbackfn, that) { return findLastIndex(this, callbackfn, that); }; } if (!Uint8Array.prototype.findLast) { Uint8Array.prototype.findLast = function(callbackfn, that) { return findLast(this, callbackfn, that); }; } var { MAX_SAFE_INTEGER } = Number; var iteratorSymbol = Symbol.iterator; var asyncIteratorSymbol = Symbol.asyncIterator; var IntrinsicArray = Array; var tooLongErrorMessage = "Input is too long and exceeded Number.MAX_SAFE_INTEGER times."; function isConstructor(obj) { if (obj != null) { const prox = new Proxy(obj, { construct() { return prox; } }); try { new prox(); return true; } catch (err) { return false; } } else { return false; } } async function fromAsync(items, mapfn, thisArg) { const itemsAreIterable = asyncIteratorSymbol in items || iteratorSymbol in items; if (itemsAreIterable) { const result = isConstructor(this) ? new this() : IntrinsicArray(0); let i = 0; for await (const v of items) { if (i > MAX_SAFE_INTEGER) { throw TypeError(tooLongErrorMessage); } else if (mapfn) { result[i] = await mapfn.call(thisArg, v, i); } else { result[i] = v; } i++; } result.length = i; return result; } else { const { length } = items; const result = isConstructor(this) ? new this(length) : IntrinsicArray(length); let i = 0; while (i < length) { if (i > MAX_SAFE_INTEGER) { throw TypeError(tooLongErrorMessage); } const v = await items[i]; if (mapfn) { result[i] = await mapfn.call(thisArg, v, i); } else { result[i] = v; } i++; } result.length = i; return result; } } if (!Array.fromAsync) { Array.fromAsync = fromAsync; } } }); // npm/script/_dnt.shims.js var require_dnt_shims = __commonJS({ "npm/script/_dnt.shims.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.dntGlobalThis = exports2.TransformStream = exports2.TextDecoderStream = exports2.WritableStream = exports2.ReadableStream = exports2.TextDecoder = void 0; var node_util_12 = require("node:util"); var node_util_2 = require("node:util"); Object.defineProperty(exports2, "TextDecoder", { enumerable: true, get: function() { return node_util_2.TextDecoder; } }); var web_1 = require("node:stream/web"); var web_2 = require("node:stream/web"); Object.defineProperty(exports2, "ReadableStream", { enumerable: true, get: function() { return web_2.ReadableStream; } }); Object.defineProperty(exports2, "WritableStream", { enumerable: true, get: function() { return web_2.WritableStream; } }); Object.defineProperty(exports2, "TextDecoderStream", { enumerable: true, get: function() { return web_2.TextDecoderStream; } }); Object.defineProperty(exports2, "TransformStream", { enumerable: true, get: function() { return web_2.TransformStream; } }); var dntGlobals = { TextDecoder: node_util_12.TextDecoder, ReadableStream: web_1.ReadableStream, WritableStream: web_1.WritableStream, TextDecoderStream: web_1.TextDecoderStream, TransformStream: web_1.TransformStream }; exports2.dntGlobalThis = createMergeProxy(globalThis, dntGlobals); function createMergeProxy(baseObj, extObj) { return new Proxy(baseObj, { get(_target, prop, _receiver) { if (prop in extObj) { return extObj[prop]; } else { return baseObj[prop]; } }, set(_target, prop, value) { if (prop in extObj) { delete extObj[prop]; } baseObj[prop] = value; return true; }, deleteProperty(_target, prop) { let success = false; if (prop in extObj) { delete extObj[prop]; success = true; } if (prop in baseObj) { delete baseObj[prop]; success = true; } return success; }, ownKeys(_target) { const baseKeys = Reflect.ownKeys(baseObj); const extKeys = Reflect.ownKeys(extObj); const extKeysSet = new Set(extKeys); return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys]; }, defineProperty(_target, prop, desc) { if (prop in extObj) { delete extObj[prop]; } Reflect.defineProperty(baseObj, prop, desc); return true; }, getOwnPropertyDescriptor(_target, prop) { if (prop in extObj) { return Reflect.getOwnPropertyDescriptor(extObj, prop); } else { return Reflect.getOwnPropertyDescriptor(baseObj, prop); } }, has(_target, prop) { return prop in extObj || prop in baseObj; } }); } } }); // npm/script/deps/jsr.io/@std/fmt/1.0.10/colors.js var require_colors = __commonJS({ "npm/script/deps/jsr.io/@std/fmt/1.0.10/colors.js"(exports2) { "use strict"; var __createBinding2 = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); } : function(o, m, k, k2) { if (k2 === void 0) k2 = k; o[k2] = m[k]; }); var __setModuleDefault2 = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); } : function(o, v) { o["default"] = v; }); var __importStar2 = exports2 && exports2.__importStar || /* @__PURE__ */ function() { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function(o2) { var ar = []; for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) { for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding2(result, mod, k[i]); } __setModuleDefault2(result, mod); return result; }; }(); Object.defineProperty(exports2, "__esModule", { value: true }); exports2.setColorEnabled = setColorEnabled; exports2.getColorEnabled = getColorEnabled; exports2.reset = reset; exports2.bold = bold; exports2.dim = dim; exports2.italic = italic; exports2.underline = underline; exports2.inverse = inverse; exports2.hidden = hidden; exports2.strikethrough = strikethrough; exports2.black = black; exports2.red = red; exports2.green = green; exports2.yellow = yellow; exports2.blue = blue; exports2.magenta = magenta; exports2.cyan = cyan; exports2.white = white; exports2.gray = gray; exports2.brightBlack = brightBlack; exports2.brightRed = brightRed; exports2.brightGreen = brightGreen; exports2.brightYellow = brightYellow; exports2.brightBlue = brightBlue; exports2.brightMagenta = brightMagenta; exports2.brightCyan = brightCyan; exports2.brightWhite = brightWhite; exports2.bgBlack = bgBlack; exports2.bgRed = bgRed; exports2.bgGreen = bgGreen; exports2.bgYellow = bgYellow; exports2.bgBlue = bgBlue; exports2.bgMagenta = bgMagenta; exports2.bgCyan = bgCyan; exports2.bgWhite = bgWhite; exports2.bgBrightBlack = bgBrightBlack; exports2.bgBrightRed = bgBrightRed; exports2.bgBrightGreen = bgBrightGreen; exports2.bgBrightYellow = bgBrightYellow; exports2.bgBrightBlue = bgBrightBlue; exports2.bgBrightMagenta = bgBrightMagenta; exports2.bgBrightCyan = bgBrightCyan; exports2.bgBrightWhite = bgBrightWhite; exports2.rgb8 = rgb8; exports2.bgRgb8 = bgRgb8; exports2.rgb24 = rgb24; exports2.bgRgb24 = bgRgb24; exports2.stripAnsiCode = stripAnsiCode; var dntShim = __importStar2(require_dnt_shims()); var { Deno } = dntShim.dntGlobalThis; var noColor = typeof Deno?.noColor === "boolean" ? Deno.noColor : false; var enabled = !noColor; function setColorEnabled(value) { if (Deno?.noColor) { return; } enabled = value; } function getColorEnabled() { return enabled; } function code(open, close) { return { open: `\x1B[${open.join(";")}m`, close: `\x1B[${close}m`, regexp: new RegExp(`\\x1b\\[${close}m`, "g") }; } function run(str, code2) { return enabled ? `${code2.open}${str.replace(code2.regexp, code2.open)}${code2.close}` : str; } function reset(str) { return run(str, code([0], 0)); } function bold(str) { return run(str, code([1], 22)); } function dim(str) { return run(str, code([2], 22)); } function italic(str) { return run(str, code([3], 23)); } function underline(str) { return run(str, code([4], 24)); } function inverse(str) { return run(str, code([7], 27)); } function hidden(str) { return run(str, code([8], 28)); } function strikethrough(str) { return run(str, code([9], 29)); } function black(str) { return run(str, code([30], 39)); } function red(str) { return run(str, code([31], 39)); } function green(str) { return run(str, code([32], 39)); } function yellow(str) { return run(str, code([33], 39)); } function blue(str) { return run(str, code([34], 39)); } function magenta(str) { return run(str, code([35], 39)); } function cyan(str) { return run(str, code([36], 39)); } function white(str) { return run(str, code([37], 39)); } function gray(str) { return brightBlack(str); } function brightBlack(str) { return run(str, code([90], 39)); } function brightRed(str) { return run(str, code([91], 39)); } function brightGreen(str) { return run(str, code([92], 39)); } function brightYellow(str) { return run(str, code([93], 39)); } function brightBlue(str) { return run(str, code([94], 39)); } function brightMagenta(str) { return run(str, code([95], 39)); } function brightCyan(str) { return run(str, code([96], 39)); } function brightWhite(str) { return run(str, code([97], 39)); } function bgBlack(str) { return run(str, code([40], 49)); } function bgRed(str) { return run(str, code([41], 49)); } function bgGreen(str) { return run(str, code([42], 49)); } function bgYellow(str) { return run(str, code([43], 49)); } function bgBlue(str) { return run(str, code([44], 49)); } function bgMagenta(str) { return run(str, code([45], 49)); } function bgCyan(str) { return run(str, code([46], 49)); } function bgWhite(str) { return run(str, code([47], 49)); } function bgBrightBlack(str) { return run(str, code([100], 49)); } function bgBrightRed(str) { return run(str, code([101], 49)); } function bgBrightGreen(str) { return run(str, code([102], 49)); } function bgBrightYellow(str) { return run(str, code([103], 49)); } function bgBrightBlue(str) { return run(str, code([104], 49)); } function bgBrightMagenta(str) { return run(str, code([105], 49)); } function bgBrightCyan(str) { return run(str, code([106], 49)); } function bgBrightWhite(str) { return run(str, code([107], 49)); } function clampAndTruncate(n, max = 255, min = 0) { return Math.trunc(Math.max(Math.min(n, max), min)); } function rgb8(str, color) { return run(str, code([38, 5, clampAndTruncate(color)], 39)); } function bgRgb8(str, color) { return run(str, code([48, 5, clampAndTruncate(color)], 49)); } function rgb24(str, color) { if (typeof color === "number") { return run(str, code([38, 2, color >> 16 & 255, color >> 8 & 255, color & 255], 39)); } return run(str, code([ 38, 2, clampAndTruncate(color.r), clampAndTruncate(color.g), clampAndTruncate(color.b) ], 39)); } function bgRgb24(str, color) { if (typeof color === "number") { return run(str, code([48, 2, color >> 16 & 255, color >> 8 & 255, color & 255], 49)); } return run(str, code([ 48, 2, clampAndTruncate(color.r), clampAndTruncate(color.g), clampAndTruncate(color.b) ], 49)); } var ANSI_REGEXP = new RegExp([ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TXZcf-nq-uy=><~]))" ].join("|"), "g"); function stripAnsiCode(string) { return string.replace(ANSI_REGEXP, ""); } } }); // npm/script/deps/jsr.io/@david/which/0.7.1/mod.js var require_mod = __commonJS({ "npm/script/deps/jsr.io/@david/which/0.7.1/mod.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.RealEnvironment = void 0; exports2.which = which; exports2.whichSync = whichSync; var denoGlobal = globalThis.Deno; var nodeProcess = globalThis.process; var nodeFs; function getNodeFs() { return nodeFs ??= nodeProcess.getBuiltinModule("node:fs"); } var RealEnvironment = class { env(key) { if (denoGlobal?.env) { return denoGlobal.env.get(key); } return nodeProcess.env[key]; } async stat(path) { if (denoGlobal?.stat) { return await denoGlobal.stat(path); } const info = await getNodeFs().promises.stat(path); return { isFile: info.isFile() }; } statSync(path) { if (denoGlobal?.statSync) { return denoGlobal.statSync(path); } const info = getNodeFs().statSync(path); return { isFile: info.isFile() }; } async lstat(path) { if (denoGlobal?.lstat) { return await denoGlobal.lstat(path); } const info = await getNodeFs().promises.lstat(path); return { isFile: info.isFile(), isSymlink: info.isSymbolicLink() }; } lstatSync(path) { if (denoGlobal?.lstatSync) { return denoGlobal.lstatSync(path); } const info = getNodeFs().lstatSync(path); return { isFile: info.isFile(), isSymlink: info.isSymbolicLink() }; } async readLink(path) { if (denoGlobal?.readLink) { return await denoGlobal.readLink(path); } return await getNodeFs().promises.readlink(path); } readLinkSync(path) { if (denoGlobal?.readLinkSync) { return denoGlobal.readLinkSync(path); } return getNodeFs().readlinkSync(path); } get isWindows() { if (denoGlobal?.build?.os) { return denoGlobal.build.os === "windows"; } return nodeProcess.platform === "win32"; } }; exports2.RealEnvironment = RealEnvironment; async function which(command, environment = new RealEnvironment()) { if (commandHasPathSeparator(command, environment.isWindows)) { if (await pathMatches(environment, command)) { return command; } const pathExts = getPathExts(command, environment); if (pathExts == null) { return void 0; } for (const pathExt of pathExts) { const filePath = command + pathExt; if (await pathMatches(environment, filePath)) { return filePath; } } return void 0; } const systemInfo = getSystemInfo(command, environment); if (systemInfo == null) { return void 0; } for (const pathItem of systemInfo.pathItems) { const filePath = pathItem + command; if (systemInfo.pathExts) { environment.requestPermission?.(pathItem); for (const pathExt of systemInfo.pathExts) { const filePath2 = pathItem + command + pathExt; if (await pathMatches(environment, filePath2)) { return filePath2; } } } else if (await pathMatches(environment, filePath)) { return filePath; } } return void 0; } async function pathMatches(environment, path) { try { return (await environment.stat(path)).isFile; } catch (statErr) { if (isDenoPermissionDeniedError(statErr)) { throw statErr; } if (environment.isWindows && isEaccesError(statErr)) { return await followSymlinkChain(environment, path); } return false; } } async function followSymlinkChain(environment, path) { let current = path; for (let hops = 0; hops < 40; hops++) { let info; try { info = await environment.lstat(current); } catch (err) { if (isDenoPermissionDeniedError(err)) { throw err; } return false; } if (info.isFile) return true; if (!info.isSymlink) return false; let target; try { target = await environment.readLink(current); } catch (err) { if (isDenoPermissionDeniedError(err)) { throw err; } return false; } current = resolveLinkTarget(current, target); } return false; } function whichSync(command, environment = new RealEnvironment()) { if (commandHasPathSeparator(command, environment.isWindows)) { if (pathMatchesSync(environment, command)) { return command; } const pathExts = getPathExts(command, environment); if (pathExts == null) { return void 0; } for (const pathExt of pathExts) { const filePath = command + pathExt; if (pathMatchesSync(environment, filePath)) { return filePath; } } return void 0; } const systemInfo = getSystemInfo(command, environment); if (systemInfo == null) { return void 0; } for (const pathItem of systemInfo.pathItems) { const filePath = pathItem + command; if (systemInfo.pathExts) { environment.requestPermission?.(pathItem); for (const pathExt of systemInfo.pathExts) { const filePath2 = pathItem + command + pathExt; if (pathMatchesSync(environment, filePath2)) { return filePath2; } } } else if (pathMatchesSync(environment, filePath)) { return filePath; } } return void 0; } function pathMatchesSync(environment, path) { try { return environment.statSync(path).isFile; } catch (statErr) { if (isDenoPermissionDeniedError(statErr)) { throw statErr; } if (environment.isWindows && isEaccesError(statErr)) { return followSymlinkChainSync(environment, path); } return false; } } function followSymlinkChainSync(environment, path) { let current = path; for (let hops = 0; hops < 40; hops++) { let info; try { info = environment.lstatSync(current); } catch (err) { if (isDenoPermissionDeniedError(err)) { throw err; } return false; } if (info.isFile) return true; if (!info.isSymlink) return false; let target; try { target = environment.readLinkSync(current); } catch (err) { if (isDenoPermissionDeniedError(err)) { throw err; } return false; } current = resolveLinkTarget(current, target); } return false; } function resolveLinkTarget(linkPath, target) { if (isAbsolutePath(target)) { return target; } const sepIdx = Math.max(linkPath.lastIndexOf("/"), linkPath.lastIndexOf("\\")); const dir = sepIdx >= 0 ? linkPath.slice(0, sepIdx + 1) : ""; return dir + target; } function isAbsolutePath(p) { if (p.startsWith("/") || p.startsWith("\\")) return true; return /^[A-Za-z]:[\\/]/.test(p); } function isEaccesError(err) { return err != null && typeof err === "object" && "code" in err && err.code === "EACCES"; } function isDenoPermissionDeniedError(err) { const permissionDeniedError = denoGlobal?.errors?.PermissionDenied; return permissionDeniedError != null && err instanceof permissionDeniedError; } function getSystemInfo(command, environment) { const isWindows = environment.isWindows; const path = environment.env("PATH"); const pathSeparator = isWindows ? "\\" : "/"; if (path == null) { return void 0; } return { pathItems: splitEnvValue(path, isWindows).map((item) => normalizeDir(item, pathSeparator)), pathExts: getPathExts(command, environment), isNameMatch: isWindows ? (a, b) => a.toLowerCase() === b.toLowerCase() : (a, b) => a === b }; } function getPathExts(command, environment) { if (!environment.isWindows) { return void 0; } const pathExtText = environment.env("PATHEXT") ?? ".EXE;.CMD;.BAT;.COM"; const pathExts = splitEnvValue(pathExtText, true); const lowerCaseCommand = command.toLowerCase(); for (const pathExt of pathExts) { if (lowerCaseCommand.endsWith(pathExt.toLowerCase())) { return void 0; } } return pathExts; } function commandHasPathSeparator(command, isWindows) { return command.includes("/") || isWindows && command.includes("\\"); } function splitEnvValue(value, isWindows) { const envValueSeparator = isWindows ? ";" : ":"; return value.split(envValueSeparator).map((item) => item.trim()).filter((item) => item.length > 0); } function normalizeDir(dirPath, pathSeparator) { if (pathSeparator === "\\" && dirPath.includes("/")) { dirPath = normalizeWindowsSeparators(dirPath, pathSeparator); } if (!dirPath.endsWith(pathSeparator)) { dirPath += pathSeparator; } return dirPath; } function normalizeWindowsSeparators(dirPath, pathSeparator) { const isUncRoot = /^[/\\]{2}/.test(dirPath); const head = isUncRoot ? pathSeparator + pathSeparator : ""; const rest = isUncRoot ? dirPath.slice(2) : dirPath; return head + rest.replaceAll("/", pathSeparator).replace(/\\+/g, pathSeparator); } } }); // npm/script/deps/jsr.io/@david/path/0.3.2/path.js var require_path = __commonJS({ "npm/script/deps/jsr.io/@david/path/0.3.2/path.js"(exports2) { "use strict"; var __createBinding2 = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { if (k2 === void 0) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); } : function(o, m, k, k2) { if (k2 === void 0) k2 = k; o[k2] = m[k]; }); var __setModuleDefault2 = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); } : function(o, v) { o["default"] = v; }); var __importStar2 = exports2 && exports2.__importStar || /* @__PURE__ */ function() { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function(o2) { var ar = []; for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) { for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding2(result, mod, k[i]); } __setModuleDefault2(result, mod); return result; }; }(); Object.defineProperty(exports2, "__esModule", { value: true }); exports2.basename = basename3; exports2.dirname = dirname3; exports2.extname = extname3; exports2.fromFileUrl = fromFileUrl3; exports2.isAbsolute = isAbsolute3; exports2.join = join3; exports2.normalize = normalize3; exports2.relative = relative3; exports2.resolve = resolve3; exports2.toFileUrl = toFileUrl3; var dntShim = __importStar2(require_dnt_shims()); function checkWindows() { const global = dntShim.dntGlobalThis; const platform = global.process?.platform; if (typeof platform === "string") return platform.startsWith("win"); const os = global.Deno?.build?.os; if (typeof os === "string") return os === "windows"; return global.navigator?.platform?.startsWith("Win") ?? false; } var isWindows = checkWindows(); function assertPath(path) { if (typeof path !== "string") { throw new TypeError(`Path must be a string, received "${JSON.stringify(path)}"`); } } function stripSuffix(name, suffix) { if (suffix.length >= name.length) { return name; } const lenDiff = name.length - suffix.length; for (let i = suffix.length - 1; i >= 0; --i) { if (name.charCodeAt(lenDiff + i) !== suffix.charCodeAt(i)) { return name; } } return name.slice(0, -suffix.length); } function lastPathSegment(path, isSep, start = 0) { let matchedNonSeparator = false; let end = path.length; for (let i = path.length - 1; i >= start; --i) { if (isSep(path.charCodeAt(i))) { if (matchedNonSeparator) { start = i + 1; break; } } else if (!matchedNonSeparator) { matchedNonSeparator = true; end = i + 1; } } return path.slice(start, end); } function assertArgs(path, suffix) { assertPath(path); if (path.length === 0) return path; if (typeof suffix !== "string") { throw new TypeError(`Suffix must be a string, received "${JSON.stringify(suffix)}"`); } } function assertArg(url) { url = url instanceof URL ? url : new URL(url); if (url.protocol !== "file:") { throw new TypeError(`URL must be a file URL: received "${url.protocol}"`); } return url; } function fromFileUrl(url) { url = assertArg(url); return decodeURIComponent(url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25")); } function stripTrailingSeparators(segment, isSep) { if (segment.length <= 1) { return segment; } let end = segment.length; for (let i = segment.length - 1; i > 0; i--) { if (isSep(segment.charCodeAt(i))) { end = i; } else { break; } } return segment.slice(0, end); } var CHAR_UPPERCASE_A = 65; var CHAR_LOWERCASE_A = 97; var CHAR_UPPERCASE_Z = 90; var CHAR_LOWERCASE_Z = 122; var CHAR_DOT = 46; var CHAR_FORWARD_SLASH = 47; var CHAR_BACKWARD_SLASH = 92; var CHAR_COLON = 58; function isPosixPathSeparator(code) { return code === CHAR_FORWARD_SLASH; } function basename(path, suffix = "") { if (path instanceof URL) { path = fromFileUrl(path); } assertArgs(path, suffix); const lastSegment = lastPathSegment(path, isPosixPathSeparator); const strippedSegment = stripTrailingSeparators(lastSegment, isPosixPathSeparator); return suffix ? stripSuffix(strippedSegment, suffix) : strippedSegment; } function isPosixPathSeparator2(code) { return code === CHAR_FORWARD_SLASH; } function isPathSeparator(code) { return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH; } function isWindowsDeviceRoot(code) { return code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z || code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z; } function fromFileUrl2(url) { url = assertArg(url); let path = decodeURIComponent(url.pathname.replace(/\//g, "\\").replace(/%(?![0-9A-Fa-f]{2})/g, "%25")).replace(/^\\*([A-Za-z]:)(\\|$)/, "$1\\"); if (url.hostname !== "") { path = `\\\\${url.hostname}${path}`; } return path; } function basename2(path, suffix = "") { if (path instanceof URL) { path = fromFileUrl2(path); } assertArgs(path, suffix); let start = 0; if (path.length >= 2) { const drive = path.charCodeAt(0); if (isWindowsDeviceRoot(drive)) { if (path.charCodeAt(1) === CHAR_COLON) start = 2; } } const lastSegment = lastPathSegment(path, isPathSeparator, start); const strippedSegment = stripTrailingSeparators(lastSegment, isPathSeparator); return suffix ? stripSuffix(strippedSegment, suffix) : strippedSegment; } function basename3(path, suffix = "") { return isWindows ? basename2(path, suffix) : basename(path, suffix); } function assertArg2(path) { assertPath(path); if (path.length === 0) return "."; } function dirname(path) { if (path instanceof URL) { path = fromFileUrl(path); } assertArg2(path); let end = -1; let matchedNonSeparator = false; for (let i = path.length - 1; i >= 1; --i) { if (isPosixPathSeparator(path.charCodeAt(i))) { if (matchedNonSeparator) { end = i; break; } } else { matchedNonSeparator = true; } } if (end === -1) { return isPosixPathSeparator(path.charCodeAt(0)) ? "/" : "."; } return stripTrailingSeparators(path.slice(0, end), isPosixPathSeparator); } function dirname2(path) { if (path instanceof URL) { path = fromFileUrl2(path); } assertArg2(path); const len = path.length; let rootEnd = -1; let end = -1; let matchedSlash = true; let offset = 0; const code = path.charCodeAt(0); if (len > 1) { if (isPathSeparator(code)) { rootEnd = offset = 1; if (isPathSeparator(path.charCodeAt(1))) { let j = 2; let last = j; for (; j < len; ++j) { if (isPathSeparator(path.charCodeAt(j))) break; } if (j < len && j !== last) { last = j; for (; j < len; ++j) { if (!isPathSeparator(path.charCodeAt(j))) break; } if (j < len && j !== last) { last = j; for (; j < len; ++j) { if (isPathSeparator(path.charCodeAt(j))) break; } if (j === len) { return path; } if (j !== last) { rootEnd = offset = j + 1; } } } } } else if (isWindowsDeviceRoot(code)) { if (path.charCodeAt(1) === CHAR_COLON) { rootEnd = offset = 2; if (len > 2) { if (isPathSeparator(path.charCodeAt(2))) rootEnd = offset = 3; } } } } else if (isPathSeparator(code)) { return path; } for (let i = len - 1; i >= offset; --i) { if (isPathSeparator(path.charCodeAt(i))) { if (!matchedSlash) { end = i; break; } } else { matchedSlash = false; } } if (end === -1) { if (rootEnd === -1) return "."; else end = rootEnd; } return stripTrailingSeparators(path.slice(0, end), isPosixPathSeparator2); } function dirname3(path) { return isWindows ? dirname2(path) : dirname(path); } function extname(path) { if (path instanceof URL) { path = fromFileUrl(path); } assertPath(path); let startDot = -1; let startPart = 0; let end = -1; let matchedSlash = true; let preDotState = 0; for (let i = path.length - 1; i >= 0; --i) { const code = path.charCodeAt(i); if (isPosixPathSeparator(code)) { if (!matchedSlash) { startPart = i + 1; break; } continue; } if (end === -1) { matchedSlash = false; end = i + 1; } if (code === CHAR_DOT) { if (startDot === -1) startDot = i; else if (preDotState !== 1) preDotState = 1; } else if (startDot !== -1) { preDotState = -1; } } if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot preDotState === 0 || // The (right-most) trimmed path component is exactly '..' preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { return ""; } return path.slice(startDot, end); } function extname2(path) { if (path instanceof URL) { path = fromFileUrl2(path); } assertPath(path); let start = 0; let startDot = -1; let startPart = 0; let end = -1; let matchedSlash = true; let preDotState = 0; if (path.length >= 2 && path.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path.charCodeAt(0))) { start = startPart = 2; } for (let i = path.length - 1; i >= start; --i) { const code = path.charCodeAt(i); if (isPathSeparator(code)) { if (!matchedSlash) { startPart = i + 1; break; } continue; } if (end === -1) { matchedSlash = false; end = i + 1; } if (code === CHAR_DOT) { if (startDot === -1) startDot = i; else if (preDotState !== 1) preDotState = 1; } else if (startDot !== -1) { preDotState = -1; } } if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot preDotState === 0 || // The (right-most) trimmed path component is exactly '..' preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { return ""; } return path.slice(startDot, end); } function extname3(path) { return isWindows ? extname2(path) : extname(path); } function fromFileUrl3(url) { return isWindows ? fromFileUrl2(url) : fromFileUrl(url); } function isAbsolute(path) { assertPath(path); return path.length > 0 && isPosixPathSeparator(path.charCodeAt(0)); } function isAbsolute2(path) { assertPath(path); const len = path.length; if (len === 0) return false; const code = path.charCodeAt(0); if (isPathSeparator(code)) { return true; } else if (isWindowsDeviceRoot(code)) { if (len > 2 && path.charCodeAt(1) === CHAR_COLON) { if (isPathSeparator(path.charCodeAt(2))) return true; } } return false; } function isAbsolute3(path) { return isWindows ? isAbsolute2(path) : isAbsolute(path); } function assertArg4(path) { assertPath(path); if (path.length === 0) return "."; } function normalizeString(path, allowAboveRoot, separator, isPathSeparator2) { let res = ""; let lastSegmentLength = 0; let lastSlash = -1; let dots = 0; let code; for (let i = 0; i <= path.length; ++i) { if (i < path.length) code = path.charCodeAt(i); else if (isPathSeparator2(code)) break; else code = CHAR_FORWARD_SLASH; if (isPathSeparator2(code)) { if (lastSlash === i - 1 || dots === 1) { } else if (lastSlash !== i - 1 && dots === 2) { if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== CHAR_DOT || res.charCodeAt(res.length - 2) !== CHAR_DOT) { if (res.length > 2) { const lastSlashIndex = res.lastIndexOf(separator); if (lastSlashIndex === -1) { res = ""; lastSegmentLength = 0; } else { res = res.slice(0, lastSlashIndex); lastSegmentLength = res.length - 1 - res.lastIndexOf(separator); } lastSlash = i; dots = 0; continue; } else if (res.length === 2 || res.length === 1) { res = ""; lastSegmentLength = 0; lastSlash = i; dots = 0; continue; } } if (allowAboveRoot) { if (res.length > 0) res += `${separator}..`; else res = ".."; lastSegmentLength = 2; } } else { if (res.length > 0) res += separator + path.slice(lastSlash + 1, i); else res = path.slice(lastSlash + 1, i); lastSegmentLength = i - lastSlash - 1; } lastSlash = i; dots = 0; } else if (code === CHAR_DOT && dots !== -1) { ++dots; } else { dots = -1; } } return res; } function normalize(path) { if (path instanceof URL) { path = fromFileUrl(path); } assertArg4(path); const isAbsolute4 = isPosixPathSeparator(path.charCodeAt(0)); const trailingSeparator = isPosixPathSeparator(path.charCodeAt(path.length - 1)); path = normalizeString(path, !isAbsolute4, "/", isPosixPathSeparator); if (path.length === 0 && !isAbsolute4) path = "."; if (path.length > 0 && trailingSeparator) path += "/"; if (isAbsolute4) return `/${path}`; return path; } function join(path, ...paths) { if (path === void 0) return "."; if (path instanceof URL) { path = fromFileUrl(path); } paths = path ? [ path, ...paths ] : paths; paths.forEach((path2) => assertPath(path2)); const joined = paths.filter((path2) => path2.length > 0).join("/"); return joined === "" ? "." : normalize(joined); } function normalize2(path) { if (path instanceof URL) { path = fromFileUrl2(path); } assertArg4(path); const len = path.length; let rootEnd = 0; let device; let isAbsolute4 = false; const code = path.charCodeAt(0); if (len > 1) { if (isPathSeparator(code)) { isAbsolute4 = true; if (isPathSeparator(path.charCodeAt(1))) { let j = 2; let last = j; for (; j < len; ++j) { if (isPathSeparator(path.charCodeAt(j))) break; } if (j < len && j !== last) { const firstPart = path.slice(last, j); last = j; for (; j < len; ++j) { if (!isPathSeparator(path.charCodeAt(j))) break; } if (j < len && j !== last) { last = j; for (; j < len; ++j) { if (isPathSeparator(path.charCodeAt(j))) break; } if (j === len) { return `\\\\${firstPart}\\${path.slice(last)}\\`; } else if (j !== last) { device = `\\\\${firstPart}\\${path.slice(last, j)}`; rootEnd = j; } } } } else { rootEnd = 1; } } else if (isWindowsDeviceRoot(code)) { if (path.charCodeAt(1) === CHAR_COLON) { device = path.slice(0, 2); rootEnd = 2; if (len > 2) { if (isPathSeparator(path.charCodeAt(2))) { isAbsolute4 = true; rootEnd = 3; } } } } } else if (isPathSeparator(code)) { return "\\"; } let tail; if (rootEnd < len) { tail = normalizeString(path.slice(rootEnd), !isAbsolute4, "\\", isPathSeparator); } else { tail = ""; } if (tail.length === 0 && !isAbsolute4) tail = "."; if (tail.length > 0 && isPathSeparator(path.charCodeAt(len - 1))) { tail += "\\"; } if (device === void 0) { if (isAbsolute4) { if (tail.length > 0) return `\\${tail}`; else return "\\"; } return tail; } else if (isAbsolute4) { if (tail.length > 0) return `${device}\\${tail}`; else return `${device}\\`; } return device + tail; } function join2(path, ...paths) { if (path instanceof URL) { path = fromFileUrl2(path); } paths = path ? [ path, ...paths ] : paths; paths.forEach((path2) => assertPath(path2)); paths = paths.filter((path2) => path2.length > 0); if (paths.length === 0) return "."; let needsReplace = true; let slashCount = 0; const firstPart = paths[0]; if (isPathSeparator(firstPart.charCodeAt(0))) { ++slashCount; const firstLen = firstPart.length; if (firstLen > 1) { if (isPathSeparator(firstPart.charCodeAt(1))) { ++slashCount; if (firstLen > 2) { if (isPathSeparator(firstPart.charCodeAt(2))) ++slashCount; else { needsReplace = false; } } } } } let joined = paths.join("\\"); if (needsReplace) { for (; slashCount < joined.length; ++slashCount) { if (!isPathSeparator(joined.charCodeAt(slashCount))) break; } if (slashCount >= 2) joined = `\\${joined.slice(slashCount)}`; } return normalize2(joined); } function join3(path, ...paths) { return isWindows ? join2(path, ...paths) : join(path, ...paths); } function normalize3(path) { return isWindows ? normalize2(path) : normalize(path); } function cwd(errorMessage) { const global = dntShim.dntGlobalThis; const getCwd = global.process?.cwd ?? global.Deno?.cwd; if (typeof getCwd !== "function") { throw new TypeError(errorMessage); } return getCwd(); } function resolve(...pathSegments) { let resolvedPath = ""; let resolvedAbsolute = false; for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) { let path; if (i >= 0) path = pathSegments[i]; else { path = cwd("Resolved a relative path without a current working directory (CWD)"); } assertPath(path); if (path.length === 0) { continue; } resolvedPath = `${path}/${resolvedPath}`; resolvedAbsolute = isPosixPathSeparator(path.charCodeAt(0)); } resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, "/", isPosixPathSeparator); if (resolvedAbsolute) { if (resolvedPath.length > 0) return `/${resolvedPath}`; else return "/"; } else if (resolvedPath.length > 0) return resolvedPath; else return "."; } function assertArgs2(from, to) { assertPath(from); assertPath(to); if (from === to) return ""; } function relative(from, to) { assertArgs2(from, to); from = resolve(from); to = resolve(to); if (from === to) return ""; let fromStart = 1; const fromEnd = from.length; for (; fromStart < fromEnd; ++fromStart) { if (!isPosixPathSeparator(from.charCodeAt(fromStart))) break; } const fromLen = fromEnd - fromStart; let toStart = 1; const toEnd = to.length; for (; toStart < toEnd; ++toStart) { if (!isPosixPathSeparator(to.charCodeAt(toStart))) break; } const toLen = toEnd - toStart; const length = fromLen < toLen ? fromLen : toLen; let lastCommonSep = -1; let i = 0; for (; i <= length; ++i) { if (i === length) { if (toLen > length) { if (isPosixPathSeparator(to.charCodeAt(toStart + i))) { return to.slice(toStart + i + 1); } else if (i === 0) { return to.slice(toStart + i); } } else if (fromLen > length) { if (isPosixPathSeparator(from.charCodeAt(fromStart + i))) { lastCommonSep = i; } else if (i === 0) { lastCommonSep = 0; } } break; } const fromCode = from.charCodeAt(fromStart + i); const toCode = to.charCodeAt(toStart + i); if (fromCode !== toCode) break; else if (isPosixPathSeparator(fromCode)) lastCommonSep = i; } let out = ""; for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { if (i === fromEnd || isPosixPathSeparator(from.charCodeAt(i))) { if (out.length === 0) out += ".."; else out += "/.."; } } if (out.length > 0) return out + to.slice(toStart + lastCommonSep); else { toStart += lastCommonSep; if (isPosixPathSeparator(to.charCodeAt(toStart))) ++toStart; return to.slice(toStart); } } function resolve2(...pathSegments) { let resolvedDevice = ""; let resolvedTail = ""; let resolvedAbsolute = false; for (let i = pathSegments.length - 1; i >= -1; i--) { let path; if (i >= 0) { path = pathSegments[i]; } else if (!r