From 6d80953607cc4bb09ae79552ce86b0d2a68eca45 Mon Sep 17 00:00:00 2001 From: v1rtl Date: Wed, 8 Sep 2021 12:31:25 +0300 Subject: [PATCH 1/4] feat: use std/node/path instead of path-browserify --- embed/polyfills/deno_std_node_path.js | 1579 +++++++++++++++++++++++++ server/nodejs.go | 2 +- 2 files changed, 1580 insertions(+), 1 deletion(-) create mode 100644 embed/polyfills/deno_std_node_path.js diff --git a/embed/polyfills/deno_std_node_path.js b/embed/polyfills/deno_std_node_path.js new file mode 100644 index 000000000..f5c814611 --- /dev/null +++ b/embed/polyfills/deno_std_node_path.js @@ -0,0 +1,1579 @@ +var __defProp = Object.defineProperty; +var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); +var __export = (target, all) => { + __markAsModule(target); + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; + +// ../path/mod.ts +var mod_exports = {}; +__export(mod_exports, { + SEP: () => SEP, + SEP_PATTERN: () => SEP_PATTERN, + basename: () => basename3, + common: () => common, + delimiter: () => delimiter3, + dirname: () => dirname3, + extname: () => extname3, + format: () => format3, + fromFileUrl: () => fromFileUrl3, + globToRegExp: () => globToRegExp, + isAbsolute: () => isAbsolute3, + isGlob: () => isGlob, + join: () => join4, + joinGlobs: () => joinGlobs, + normalize: () => normalize4, + normalizeGlob: () => normalizeGlob, + parse: () => parse3, + posix: () => posix, + relative: () => relative3, + resolve: () => resolve3, + sep: () => sep3, + toFileUrl: () => toFileUrl3, + toNamespacedPath: () => toNamespacedPath3, + win32: () => win32 +}); + +// ../_util/os.ts +var osType = (() => { + const { Deno } = globalThis; + if (typeof Deno?.build?.os === "string") { + return Deno.build.os; + } + const { navigator } = globalThis; + if (navigator?.appVersion?.includes?.("Win") ?? false) { + return "windows"; + } + return "linux"; +})(); +var isWindows = osType === "windows"; + +// ../path/win32.ts +var win32_exports = {}; +__export(win32_exports, { + basename: () => basename, + delimiter: () => delimiter, + dirname: () => dirname, + extname: () => extname, + format: () => format, + fromFileUrl: () => fromFileUrl, + isAbsolute: () => isAbsolute, + join: () => join, + normalize: () => normalize, + parse: () => parse, + relative: () => relative, + resolve: () => resolve, + sep: () => sep, + toFileUrl: () => toFileUrl, + toNamespacedPath: () => toNamespacedPath +}); + +// ../path/_constants.ts +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; +var CHAR_QUESTION_MARK = 63; + +// ../path/_util.ts +function assertPath(path3) { + if (typeof path3 !== "string") { + throw new TypeError(`Path must be a string. Received ${JSON.stringify(path3)}`); + } +} +function isPosixPathSeparator(code) { + return code === CHAR_FORWARD_SLASH; +} +function isPathSeparator(code) { + return isPosixPathSeparator(code) || 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 normalizeString(path3, allowAboveRoot, separator, isPathSeparator2) { + let res = ""; + let lastSegmentLength = 0; + let lastSlash = -1; + let dots = 0; + let code; + for (let i = 0, len = path3.length; i <= len; ++i) { + if (i < len) + code = path3.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 + path3.slice(lastSlash + 1, i); + else + res = path3.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 _format(sep4, pathObject) { + const dir = pathObject.dir || pathObject.root; + const base = pathObject.base || (pathObject.name || "") + (pathObject.ext || ""); + if (!dir) + return base; + if (dir === pathObject.root) + return dir + base; + return dir + sep4 + base; +} +var WHITESPACE_ENCODINGS = { + " ": "%09", + "\n": "%0A", + "\v": "%0B", + "\f": "%0C", + "\r": "%0D", + " ": "%20" +}; +function encodeWhitespace(string) { + return string.replaceAll(/[\s]/g, (c) => { + return WHITESPACE_ENCODINGS[c] ?? c; + }); +} + +// ../_util/assert.ts +var DenoStdInternalError = class extends Error { + constructor(message) { + super(message); + this.name = "DenoStdInternalError"; + } +}; +function assert(expr, msg = "") { + if (!expr) { + throw new DenoStdInternalError(msg); + } +} + +// ../path/win32.ts +var sep = "\\"; +var delimiter = ";"; +function resolve(...pathSegments) { + let resolvedDevice = ""; + let resolvedTail = ""; + let resolvedAbsolute = false; + for (let i = pathSegments.length - 1; i >= -1; i--) { + let path3; + const { Deno } = globalThis; + if (i >= 0) { + path3 = pathSegments[i]; + } else if (!resolvedDevice) { + if (typeof Deno?.cwd !== "function") { + throw new TypeError("Resolved a drive-letter-less path without a CWD."); + } + path3 = Deno.cwd(); + } else { + if (typeof Deno?.env?.get !== "function" || typeof Deno?.cwd !== "function") { + throw new TypeError("Resolved a relative path without a CWD."); + } + path3 = Deno.env.get(`=${resolvedDevice}`) || Deno.cwd(); + if (path3 === void 0 || path3.slice(0, 3).toLowerCase() !== `${resolvedDevice.toLowerCase()}\\`) { + path3 = `${resolvedDevice}\\`; + } + } + assertPath(path3); + const len = path3.length; + if (len === 0) + continue; + let rootEnd = 0; + let device = ""; + let isAbsolute4 = false; + const code = path3.charCodeAt(0); + if (len > 1) { + if (isPathSeparator(code)) { + isAbsolute4 = true; + if (isPathSeparator(path3.charCodeAt(1))) { + let j = 2; + let last = j; + for (; j < len; ++j) { + if (isPathSeparator(path3.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + const firstPart = path3.slice(last, j); + last = j; + for (; j < len; ++j) { + if (!isPathSeparator(path3.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + last = j; + for (; j < len; ++j) { + if (isPathSeparator(path3.charCodeAt(j))) + break; + } + if (j === len) { + device = `\\\\${firstPart}\\${path3.slice(last)}`; + rootEnd = j; + } else if (j !== last) { + device = `\\\\${firstPart}\\${path3.slice(last, j)}`; + rootEnd = j; + } + } + } + } else { + rootEnd = 1; + } + } else if (isWindowsDeviceRoot(code)) { + if (path3.charCodeAt(1) === CHAR_COLON) { + device = path3.slice(0, 2); + rootEnd = 2; + if (len > 2) { + if (isPathSeparator(path3.charCodeAt(2))) { + isAbsolute4 = true; + rootEnd = 3; + } + } + } + } + } else if (isPathSeparator(code)) { + rootEnd = 1; + isAbsolute4 = true; + } + if (device.length > 0 && resolvedDevice.length > 0 && device.toLowerCase() !== resolvedDevice.toLowerCase()) { + continue; + } + if (resolvedDevice.length === 0 && device.length > 0) { + resolvedDevice = device; + } + if (!resolvedAbsolute) { + resolvedTail = `${path3.slice(rootEnd)}\\${resolvedTail}`; + resolvedAbsolute = isAbsolute4; + } + if (resolvedAbsolute && resolvedDevice.length > 0) + break; + } + resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, "\\", isPathSeparator); + return resolvedDevice + (resolvedAbsolute ? "\\" : "") + resolvedTail || "."; +} +function normalize(path3) { + assertPath(path3); + const len = path3.length; + if (len === 0) + return "."; + let rootEnd = 0; + let device; + let isAbsolute4 = false; + const code = path3.charCodeAt(0); + if (len > 1) { + if (isPathSeparator(code)) { + isAbsolute4 = true; + if (isPathSeparator(path3.charCodeAt(1))) { + let j = 2; + let last = j; + for (; j < len; ++j) { + if (isPathSeparator(path3.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + const firstPart = path3.slice(last, j); + last = j; + for (; j < len; ++j) { + if (!isPathSeparator(path3.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + last = j; + for (; j < len; ++j) { + if (isPathSeparator(path3.charCodeAt(j))) + break; + } + if (j === len) { + return `\\\\${firstPart}\\${path3.slice(last)}\\`; + } else if (j !== last) { + device = `\\\\${firstPart}\\${path3.slice(last, j)}`; + rootEnd = j; + } + } + } + } else { + rootEnd = 1; + } + } else if (isWindowsDeviceRoot(code)) { + if (path3.charCodeAt(1) === CHAR_COLON) { + device = path3.slice(0, 2); + rootEnd = 2; + if (len > 2) { + if (isPathSeparator(path3.charCodeAt(2))) { + isAbsolute4 = true; + rootEnd = 3; + } + } + } + } + } else if (isPathSeparator(code)) { + return "\\"; + } + let tail; + if (rootEnd < len) { + tail = normalizeString(path3.slice(rootEnd), !isAbsolute4, "\\", isPathSeparator); + } else { + tail = ""; + } + if (tail.length === 0 && !isAbsolute4) + tail = "."; + if (tail.length > 0 && isPathSeparator(path3.charCodeAt(len - 1))) { + tail += "\\"; + } + if (device === void 0) { + if (isAbsolute4) { + if (tail.length > 0) + return `\\${tail}`; + else + return "\\"; + } else if (tail.length > 0) { + return tail; + } else { + return ""; + } + } else if (isAbsolute4) { + if (tail.length > 0) + return `${device}\\${tail}`; + else + return `${device}\\`; + } else if (tail.length > 0) { + return device + tail; + } else { + return device; + } +} +function isAbsolute(path3) { + assertPath(path3); + const len = path3.length; + if (len === 0) + return false; + const code = path3.charCodeAt(0); + if (isPathSeparator(code)) { + return true; + } else if (isWindowsDeviceRoot(code)) { + if (len > 2 && path3.charCodeAt(1) === CHAR_COLON) { + if (isPathSeparator(path3.charCodeAt(2))) + return true; + } + } + return false; +} +function join(...paths) { + const pathsCount = paths.length; + if (pathsCount === 0) + return "."; + let joined; + let firstPart = null; + for (let i = 0; i < pathsCount; ++i) { + const path3 = paths[i]; + assertPath(path3); + if (path3.length > 0) { + if (joined === void 0) + joined = firstPart = path3; + else + joined += `\\${path3}`; + } + } + if (joined === void 0) + return "."; + let needsReplace = true; + let slashCount = 0; + assert(firstPart != null); + 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; + } + } + } + } + } + if (needsReplace) { + for (; slashCount < joined.length; ++slashCount) { + if (!isPathSeparator(joined.charCodeAt(slashCount))) + break; + } + if (slashCount >= 2) + joined = `\\${joined.slice(slashCount)}`; + } + return normalize(joined); +} +function relative(from, to) { + assertPath(from); + assertPath(to); + if (from === to) + return ""; + const fromOrig = resolve(from); + const toOrig = resolve(to); + if (fromOrig === toOrig) + return ""; + from = fromOrig.toLowerCase(); + to = toOrig.toLowerCase(); + if (from === to) + return ""; + let fromStart = 0; + let fromEnd = from.length; + for (; fromStart < fromEnd; ++fromStart) { + if (from.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH) + break; + } + for (; fromEnd - 1 > fromStart; --fromEnd) { + if (from.charCodeAt(fromEnd - 1) !== CHAR_BACKWARD_SLASH) + break; + } + const fromLen = fromEnd - fromStart; + let toStart = 0; + let toEnd = to.length; + for (; toStart < toEnd; ++toStart) { + if (to.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH) + break; + } + for (; toEnd - 1 > toStart; --toEnd) { + if (to.charCodeAt(toEnd - 1) !== CHAR_BACKWARD_SLASH) + 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 (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) { + return toOrig.slice(toStart + i + 1); + } else if (i === 2) { + return toOrig.slice(toStart + i); + } + } + if (fromLen > length) { + if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) { + lastCommonSep = i; + } else if (i === 2) { + lastCommonSep = 3; + } + } + break; + } + const fromCode = from.charCodeAt(fromStart + i); + const toCode = to.charCodeAt(toStart + i); + if (fromCode !== toCode) + break; + else if (fromCode === CHAR_BACKWARD_SLASH) + lastCommonSep = i; + } + if (i !== length && lastCommonSep === -1) { + return toOrig; + } + let out = ""; + if (lastCommonSep === -1) + lastCommonSep = 0; + for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { + if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) { + if (out.length === 0) + out += ".."; + else + out += "\\.."; + } + } + if (out.length > 0) { + return out + toOrig.slice(toStart + lastCommonSep, toEnd); + } else { + toStart += lastCommonSep; + if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) + ++toStart; + return toOrig.slice(toStart, toEnd); + } +} +function toNamespacedPath(path3) { + if (typeof path3 !== "string") + return path3; + if (path3.length === 0) + return ""; + const resolvedPath = resolve(path3); + if (resolvedPath.length >= 3) { + if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) { + if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) { + const code = resolvedPath.charCodeAt(2); + if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) { + return `\\\\?\\UNC\\${resolvedPath.slice(2)}`; + } + } + } else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0))) { + if (resolvedPath.charCodeAt(1) === CHAR_COLON && resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) { + return `\\\\?\\${resolvedPath}`; + } + } + } + return path3; +} +function dirname(path3) { + assertPath(path3); + const len = path3.length; + if (len === 0) + return "."; + let rootEnd = -1; + let end = -1; + let matchedSlash = true; + let offset = 0; + const code = path3.charCodeAt(0); + if (len > 1) { + if (isPathSeparator(code)) { + rootEnd = offset = 1; + if (isPathSeparator(path3.charCodeAt(1))) { + let j = 2; + let last = j; + for (; j < len; ++j) { + if (isPathSeparator(path3.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + last = j; + for (; j < len; ++j) { + if (!isPathSeparator(path3.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + last = j; + for (; j < len; ++j) { + if (isPathSeparator(path3.charCodeAt(j))) + break; + } + if (j === len) { + return path3; + } + if (j !== last) { + rootEnd = offset = j + 1; + } + } + } + } + } else if (isWindowsDeviceRoot(code)) { + if (path3.charCodeAt(1) === CHAR_COLON) { + rootEnd = offset = 2; + if (len > 2) { + if (isPathSeparator(path3.charCodeAt(2))) + rootEnd = offset = 3; + } + } + } + } else if (isPathSeparator(code)) { + return path3; + } + for (let i = len - 1; i >= offset; --i) { + if (isPathSeparator(path3.charCodeAt(i))) { + if (!matchedSlash) { + end = i; + break; + } + } else { + matchedSlash = false; + } + } + if (end === -1) { + if (rootEnd === -1) + return "."; + else + end = rootEnd; + } + return path3.slice(0, end); +} +function basename(path3, ext = "") { + if (ext !== void 0 && typeof ext !== "string") { + throw new TypeError('"ext" argument must be a string'); + } + assertPath(path3); + let start = 0; + let end = -1; + let matchedSlash = true; + let i; + if (path3.length >= 2) { + const drive = path3.charCodeAt(0); + if (isWindowsDeviceRoot(drive)) { + if (path3.charCodeAt(1) === CHAR_COLON) + start = 2; + } + } + if (ext !== void 0 && ext.length > 0 && ext.length <= path3.length) { + if (ext.length === path3.length && ext === path3) + return ""; + let extIdx = ext.length - 1; + let firstNonSlashEnd = -1; + for (i = path3.length - 1; i >= start; --i) { + const code = path3.charCodeAt(i); + if (isPathSeparator(code)) { + if (!matchedSlash) { + start = i + 1; + break; + } + } else { + if (firstNonSlashEnd === -1) { + matchedSlash = false; + firstNonSlashEnd = i + 1; + } + if (extIdx >= 0) { + if (code === ext.charCodeAt(extIdx)) { + if (--extIdx === -1) { + end = i; + } + } else { + extIdx = -1; + end = firstNonSlashEnd; + } + } + } + } + if (start === end) + end = firstNonSlashEnd; + else if (end === -1) + end = path3.length; + return path3.slice(start, end); + } else { + for (i = path3.length - 1; i >= start; --i) { + if (isPathSeparator(path3.charCodeAt(i))) { + if (!matchedSlash) { + start = i + 1; + break; + } + } else if (end === -1) { + matchedSlash = false; + end = i + 1; + } + } + if (end === -1) + return ""; + return path3.slice(start, end); + } +} +function extname(path3) { + assertPath(path3); + let start = 0; + let startDot = -1; + let startPart = 0; + let end = -1; + let matchedSlash = true; + let preDotState = 0; + if (path3.length >= 2 && path3.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path3.charCodeAt(0))) { + start = startPart = 2; + } + for (let i = path3.length - 1; i >= start; --i) { + const code = path3.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 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + return ""; + } + return path3.slice(startDot, end); +} +function format(pathObject) { + if (pathObject === null || typeof pathObject !== "object") { + throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`); + } + return _format("\\", pathObject); +} +function parse(path3) { + assertPath(path3); + const ret = { root: "", dir: "", base: "", ext: "", name: "" }; + const len = path3.length; + if (len === 0) + return ret; + let rootEnd = 0; + let code = path3.charCodeAt(0); + if (len > 1) { + if (isPathSeparator(code)) { + rootEnd = 1; + if (isPathSeparator(path3.charCodeAt(1))) { + let j = 2; + let last = j; + for (; j < len; ++j) { + if (isPathSeparator(path3.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + last = j; + for (; j < len; ++j) { + if (!isPathSeparator(path3.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + last = j; + for (; j < len; ++j) { + if (isPathSeparator(path3.charCodeAt(j))) + break; + } + if (j === len) { + rootEnd = j; + } else if (j !== last) { + rootEnd = j + 1; + } + } + } + } + } else if (isWindowsDeviceRoot(code)) { + if (path3.charCodeAt(1) === CHAR_COLON) { + rootEnd = 2; + if (len > 2) { + if (isPathSeparator(path3.charCodeAt(2))) { + if (len === 3) { + ret.root = ret.dir = path3; + return ret; + } + rootEnd = 3; + } + } else { + ret.root = ret.dir = path3; + return ret; + } + } + } + } else if (isPathSeparator(code)) { + ret.root = ret.dir = path3; + return ret; + } + if (rootEnd > 0) + ret.root = path3.slice(0, rootEnd); + let startDot = -1; + let startPart = rootEnd; + let end = -1; + let matchedSlash = true; + let i = path3.length - 1; + let preDotState = 0; + for (; i >= rootEnd; --i) { + code = path3.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 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + if (end !== -1) { + ret.base = ret.name = path3.slice(startPart, end); + } + } else { + ret.name = path3.slice(startPart, startDot); + ret.base = path3.slice(startPart, end); + ret.ext = path3.slice(startDot, end); + } + if (startPart > 0 && startPart !== rootEnd) { + ret.dir = path3.slice(0, startPart - 1); + } else + ret.dir = ret.root; + return ret; +} +function fromFileUrl(url) { + url = url instanceof URL ? url : new URL(url); + if (url.protocol != "file:") { + throw new TypeError("Must be a file URL."); + } + let path3 = decodeURIComponent(url.pathname.replace(/\//g, "\\").replace(/%(?![0-9A-Fa-f]{2})/g, "%25")).replace(/^\\*([A-Za-z]:)(\\|$)/, "$1\\"); + if (url.hostname != "") { + path3 = `\\\\${url.hostname}${path3}`; + } + return path3; +} +function toFileUrl(path3) { + if (!isAbsolute(path3)) { + throw new TypeError("Must be an absolute path."); + } + const [, hostname, pathname] = path3.match(/^(?:[/\\]{2}([^/\\]+)(?=[/\\](?:[^/\\]|$)))?(.*)/); + const url = new URL("file:///"); + url.pathname = encodeWhitespace(pathname.replace(/%/g, "%25")); + if (hostname != null && hostname != "localhost") { + url.hostname = hostname; + if (!url.hostname) { + throw new TypeError("Invalid hostname."); + } + } + return url; +} + +// ../path/posix.ts +var posix_exports = {}; +__export(posix_exports, { + basename: () => basename2, + delimiter: () => delimiter2, + dirname: () => dirname2, + extname: () => extname2, + format: () => format2, + fromFileUrl: () => fromFileUrl2, + isAbsolute: () => isAbsolute2, + join: () => join2, + normalize: () => normalize2, + parse: () => parse2, + relative: () => relative2, + resolve: () => resolve2, + sep: () => sep2, + toFileUrl: () => toFileUrl2, + toNamespacedPath: () => toNamespacedPath2 +}); +var sep2 = "/"; +var delimiter2 = ":"; +function resolve2(...pathSegments) { + let resolvedPath = ""; + let resolvedAbsolute = false; + for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) { + let path3; + if (i >= 0) + path3 = pathSegments[i]; + else { + const { Deno } = globalThis; + if (typeof Deno?.cwd !== "function") { + throw new TypeError("Resolved a relative path without a CWD."); + } + path3 = Deno.cwd(); + } + assertPath(path3); + if (path3.length === 0) { + continue; + } + resolvedPath = `${path3}/${resolvedPath}`; + resolvedAbsolute = path3.charCodeAt(0) === CHAR_FORWARD_SLASH; + } + 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 normalize2(path3) { + assertPath(path3); + if (path3.length === 0) + return "."; + const isAbsolute4 = path3.charCodeAt(0) === CHAR_FORWARD_SLASH; + const trailingSeparator = path3.charCodeAt(path3.length - 1) === CHAR_FORWARD_SLASH; + path3 = normalizeString(path3, !isAbsolute4, "/", isPosixPathSeparator); + if (path3.length === 0 && !isAbsolute4) + path3 = "."; + if (path3.length > 0 && trailingSeparator) + path3 += "/"; + if (isAbsolute4) + return `/${path3}`; + return path3; +} +function isAbsolute2(path3) { + assertPath(path3); + return path3.length > 0 && path3.charCodeAt(0) === CHAR_FORWARD_SLASH; +} +function join2(...paths) { + if (paths.length === 0) + return "."; + let joined; + for (let i = 0, len = paths.length; i < len; ++i) { + const path3 = paths[i]; + assertPath(path3); + if (path3.length > 0) { + if (!joined) + joined = path3; + else + joined += `/${path3}`; + } + } + if (!joined) + return "."; + return normalize2(joined); +} +function relative2(from, to) { + assertPath(from); + assertPath(to); + if (from === to) + return ""; + from = resolve2(from); + to = resolve2(to); + if (from === to) + return ""; + let fromStart = 1; + const fromEnd = from.length; + for (; fromStart < fromEnd; ++fromStart) { + if (from.charCodeAt(fromStart) !== CHAR_FORWARD_SLASH) + break; + } + const fromLen = fromEnd - fromStart; + let toStart = 1; + const toEnd = to.length; + for (; toStart < toEnd; ++toStart) { + if (to.charCodeAt(toStart) !== CHAR_FORWARD_SLASH) + 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 (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) { + return to.slice(toStart + i + 1); + } else if (i === 0) { + return to.slice(toStart + i); + } + } else if (fromLen > length) { + if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) { + 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 (fromCode === CHAR_FORWARD_SLASH) + lastCommonSep = i; + } + let out = ""; + for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { + if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) { + if (out.length === 0) + out += ".."; + else + out += "/.."; + } + } + if (out.length > 0) + return out + to.slice(toStart + lastCommonSep); + else { + toStart += lastCommonSep; + if (to.charCodeAt(toStart) === CHAR_FORWARD_SLASH) + ++toStart; + return to.slice(toStart); + } +} +function toNamespacedPath2(path3) { + return path3; +} +function dirname2(path3) { + assertPath(path3); + if (path3.length === 0) + return "."; + const hasRoot = path3.charCodeAt(0) === CHAR_FORWARD_SLASH; + let end = -1; + let matchedSlash = true; + for (let i = path3.length - 1; i >= 1; --i) { + if (path3.charCodeAt(i) === CHAR_FORWARD_SLASH) { + if (!matchedSlash) { + end = i; + break; + } + } else { + matchedSlash = false; + } + } + if (end === -1) + return hasRoot ? "/" : "."; + if (hasRoot && end === 1) + return "//"; + return path3.slice(0, end); +} +function basename2(path3, ext = "") { + if (ext !== void 0 && typeof ext !== "string") { + throw new TypeError('"ext" argument must be a string'); + } + assertPath(path3); + let start = 0; + let end = -1; + let matchedSlash = true; + let i; + if (ext !== void 0 && ext.length > 0 && ext.length <= path3.length) { + if (ext.length === path3.length && ext === path3) + return ""; + let extIdx = ext.length - 1; + let firstNonSlashEnd = -1; + for (i = path3.length - 1; i >= 0; --i) { + const code = path3.charCodeAt(i); + if (code === CHAR_FORWARD_SLASH) { + if (!matchedSlash) { + start = i + 1; + break; + } + } else { + if (firstNonSlashEnd === -1) { + matchedSlash = false; + firstNonSlashEnd = i + 1; + } + if (extIdx >= 0) { + if (code === ext.charCodeAt(extIdx)) { + if (--extIdx === -1) { + end = i; + } + } else { + extIdx = -1; + end = firstNonSlashEnd; + } + } + } + } + if (start === end) + end = firstNonSlashEnd; + else if (end === -1) + end = path3.length; + return path3.slice(start, end); + } else { + for (i = path3.length - 1; i >= 0; --i) { + if (path3.charCodeAt(i) === CHAR_FORWARD_SLASH) { + if (!matchedSlash) { + start = i + 1; + break; + } + } else if (end === -1) { + matchedSlash = false; + end = i + 1; + } + } + if (end === -1) + return ""; + return path3.slice(start, end); + } +} +function extname2(path3) { + assertPath(path3); + let startDot = -1; + let startPart = 0; + let end = -1; + let matchedSlash = true; + let preDotState = 0; + for (let i = path3.length - 1; i >= 0; --i) { + const code = path3.charCodeAt(i); + if (code === CHAR_FORWARD_SLASH) { + 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 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + return ""; + } + return path3.slice(startDot, end); +} +function format2(pathObject) { + if (pathObject === null || typeof pathObject !== "object") { + throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`); + } + return _format("/", pathObject); +} +function parse2(path3) { + assertPath(path3); + const ret = { root: "", dir: "", base: "", ext: "", name: "" }; + if (path3.length === 0) + return ret; + const isAbsolute4 = path3.charCodeAt(0) === CHAR_FORWARD_SLASH; + let start; + if (isAbsolute4) { + ret.root = "/"; + start = 1; + } else { + start = 0; + } + let startDot = -1; + let startPart = 0; + let end = -1; + let matchedSlash = true; + let i = path3.length - 1; + let preDotState = 0; + for (; i >= start; --i) { + const code = path3.charCodeAt(i); + if (code === CHAR_FORWARD_SLASH) { + 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 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + if (end !== -1) { + if (startPart === 0 && isAbsolute4) { + ret.base = ret.name = path3.slice(1, end); + } else { + ret.base = ret.name = path3.slice(startPart, end); + } + } + } else { + if (startPart === 0 && isAbsolute4) { + ret.name = path3.slice(1, startDot); + ret.base = path3.slice(1, end); + } else { + ret.name = path3.slice(startPart, startDot); + ret.base = path3.slice(startPart, end); + } + ret.ext = path3.slice(startDot, end); + } + if (startPart > 0) + ret.dir = path3.slice(0, startPart - 1); + else if (isAbsolute4) + ret.dir = "/"; + return ret; +} +function fromFileUrl2(url) { + url = url instanceof URL ? url : new URL(url); + if (url.protocol != "file:") { + throw new TypeError("Must be a file URL."); + } + return decodeURIComponent(url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25")); +} +function toFileUrl2(path3) { + if (!isAbsolute2(path3)) { + throw new TypeError("Must be an absolute path."); + } + const url = new URL("file:///"); + url.pathname = encodeWhitespace(path3.replace(/%/g, "%25").replace(/\\/g, "%5C")); + return url; +} + +// ../path/separator.ts +var SEP = isWindows ? "\\" : "/"; +var SEP_PATTERN = isWindows ? /[\\/]+/ : /\/+/; + +// ../path/common.ts +function common(paths, sep4 = SEP) { + const [first = "", ...remaining] = paths; + if (first === "" || remaining.length === 0) { + return first.substring(0, first.lastIndexOf(sep4) + 1); + } + const parts = first.split(sep4); + let endOfPrefix = parts.length; + for (const path3 of remaining) { + const compare = path3.split(sep4); + for (let i = 0; i < endOfPrefix; i++) { + if (compare[i] !== parts[i]) { + endOfPrefix = i; + } + } + if (endOfPrefix === 0) { + return ""; + } + } + const prefix = parts.slice(0, endOfPrefix).join(sep4); + return prefix.endsWith(sep4) ? prefix : `${prefix}${sep4}`; +} + +// ../path/glob.ts +var path = isWindows ? win32_exports : posix_exports; +var { join: join3, normalize: normalize3 } = path; +var regExpEscapeChars = ["!", "$", "(", ")", "*", "+", ".", "=", "?", "[", "\\", "^", "{", "|"]; +var rangeEscapeChars = ["-", "\\", "]"]; +function globToRegExp(glob, { + extended = true, + globstar: globstarOption = true, + os = osType, + caseInsensitive = false +} = {}) { + if (glob == "") { + return /(?!)/; + } + const sep4 = os == "windows" ? "(?:\\\\|/)+" : "/+"; + const sepMaybe = os == "windows" ? "(?:\\\\|/)*" : "/*"; + const seps = os == "windows" ? ["\\", "/"] : ["/"]; + const globstar = os == "windows" ? "(?:[^\\\\/]*(?:\\\\|/|$)+)*" : "(?:[^/]*(?:/|$)+)*"; + const wildcard = os == "windows" ? "[^\\\\/]*" : "[^/]*"; + const escapePrefix = os == "windows" ? "`" : "\\"; + let newLength = glob.length; + for (; newLength > 1 && seps.includes(glob[newLength - 1]); newLength--) + ; + glob = glob.slice(0, newLength); + let regExpString = ""; + for (let j = 0; j < glob.length; ) { + let segment = ""; + const groupStack = []; + let inRange = false; + let inEscape = false; + let endsWithSep = false; + let i = j; + for (; i < glob.length && !seps.includes(glob[i]); i++) { + if (inEscape) { + inEscape = false; + const escapeChars = inRange ? rangeEscapeChars : regExpEscapeChars; + segment += escapeChars.includes(glob[i]) ? `\\${glob[i]}` : glob[i]; + continue; + } + if (glob[i] == escapePrefix) { + inEscape = true; + continue; + } + if (glob[i] == "[") { + if (!inRange) { + inRange = true; + segment += "["; + if (glob[i + 1] == "!") { + i++; + segment += "^"; + } else if (glob[i + 1] == "^") { + i++; + segment += "\\^"; + } + continue; + } else if (glob[i + 1] == ":") { + let k = i + 1; + let value = ""; + while (glob[k + 1] != null && glob[k + 1] != ":") { + value += glob[k + 1]; + k++; + } + if (glob[k + 1] == ":" && glob[k + 2] == "]") { + i = k + 2; + if (value == "alnum") + segment += "\\dA-Za-z"; + else if (value == "alpha") + segment += "A-Za-z"; + else if (value == "ascii") + segment += "\0-\x7F"; + else if (value == "blank") + segment += " "; + else if (value == "cntrl") + segment += "\0-\x7F"; + else if (value == "digit") + segment += "\\d"; + else if (value == "graph") + segment += "!-~"; + else if (value == "lower") + segment += "a-z"; + else if (value == "print") + segment += " -~"; + else if (value == "punct") { + segment += `!"#$%&'()*+,\\-./:;<=>?@[\\\\\\]^_\u2018{|}~`; + } else if (value == "space") + segment += "\\s\v"; + else if (value == "upper") + segment += "A-Z"; + else if (value == "word") + segment += "\\w"; + else if (value == "xdigit") + segment += "\\dA-Fa-f"; + continue; + } + } + } + if (glob[i] == "]" && inRange) { + inRange = false; + segment += "]"; + continue; + } + if (inRange) { + if (glob[i] == "\\") { + segment += `\\\\`; + } else { + segment += glob[i]; + } + continue; + } + if (glob[i] == ")" && groupStack.length > 0 && groupStack[groupStack.length - 1] != "BRACE") { + segment += ")"; + const type = groupStack.pop(); + if (type == "!") { + segment += wildcard; + } else if (type != "@") { + segment += type; + } + continue; + } + if (glob[i] == "|" && groupStack.length > 0 && groupStack[groupStack.length - 1] != "BRACE") { + segment += "|"; + continue; + } + if (glob[i] == "+" && extended && glob[i + 1] == "(") { + i++; + groupStack.push("+"); + segment += "(?:"; + continue; + } + if (glob[i] == "@" && extended && glob[i + 1] == "(") { + i++; + groupStack.push("@"); + segment += "(?:"; + continue; + } + if (glob[i] == "?") { + if (extended && glob[i + 1] == "(") { + i++; + groupStack.push("?"); + segment += "(?:"; + } else { + segment += "."; + } + continue; + } + if (glob[i] == "!" && extended && glob[i + 1] == "(") { + i++; + groupStack.push("!"); + segment += "(?!"; + continue; + } + if (glob[i] == "{") { + groupStack.push("BRACE"); + segment += "(?:"; + continue; + } + if (glob[i] == "}" && groupStack[groupStack.length - 1] == "BRACE") { + groupStack.pop(); + segment += ")"; + continue; + } + if (glob[i] == "," && groupStack[groupStack.length - 1] == "BRACE") { + segment += "|"; + continue; + } + if (glob[i] == "*") { + if (extended && glob[i + 1] == "(") { + i++; + groupStack.push("*"); + segment += "(?:"; + } else { + const prevChar = glob[i - 1]; + let numStars = 1; + while (glob[i + 1] == "*") { + i++; + numStars++; + } + const nextChar = glob[i + 1]; + if (globstarOption && numStars == 2 && [...seps, void 0].includes(prevChar) && [...seps, void 0].includes(nextChar)) { + segment += globstar; + endsWithSep = true; + } else { + segment += wildcard; + } + } + continue; + } + segment += regExpEscapeChars.includes(glob[i]) ? `\\${glob[i]}` : glob[i]; + } + if (groupStack.length > 0 || inRange || inEscape) { + segment = ""; + for (const c of glob.slice(j, i)) { + segment += regExpEscapeChars.includes(c) ? `\\${c}` : c; + endsWithSep = false; + } + } + regExpString += segment; + if (!endsWithSep) { + regExpString += i < glob.length ? sep4 : sepMaybe; + endsWithSep = true; + } + while (seps.includes(glob[i])) + i++; + if (!(i > j)) { + throw new Error("Assertion failure: i > j (potential infinite loop)"); + } + j = i; + } + regExpString = `^${regExpString}$`; + return new RegExp(regExpString, caseInsensitive ? "i" : ""); +} +function isGlob(str) { + const chars = { "{": "}", "(": ")", "[": "]" }; + const regex = /\\(.)|(^!|\*|\?|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/; + if (str === "") { + return false; + } + let match; + while (match = regex.exec(str)) { + if (match[2]) + return true; + let idx = match.index + match[0].length; + const open = match[1]; + const close = open ? chars[open] : null; + if (open && close) { + const n = str.indexOf(close, idx); + if (n !== -1) { + idx = n + 1; + } + } + str = str.slice(idx); + } + return false; +} +function normalizeGlob(glob, { globstar = false } = {}) { + if (glob.match(/\0/g)) { + throw new Error(`Glob contains invalid characters: "${glob}"`); + } + if (!globstar) { + return normalize3(glob); + } + const s = SEP_PATTERN.source; + const badParentPattern = new RegExp(`(?<=(${s}|^)\\*\\*${s})\\.\\.(?=${s}|$)`, "g"); + return normalize3(glob.replace(badParentPattern, "\0")).replace(/\0/g, ".."); +} +function joinGlobs(globs, { extended = false, globstar = false } = {}) { + if (!globstar || globs.length == 0) { + return join3(...globs); + } + if (globs.length === 0) + return "."; + let joined; + for (const glob of globs) { + const path3 = glob; + if (path3.length > 0) { + if (!joined) + joined = path3; + else + joined += `${SEP}${path3}`; + } + } + if (!joined) + return "."; + return normalizeGlob(joined, { extended, globstar }); +} + +// ../path/mod.ts +var path2 = isWindows ? win32_exports : posix_exports; +var win32 = win32_exports; +var posix = posix_exports; +var { + basename: basename3, + delimiter: delimiter3, + dirname: dirname3, + extname: extname3, + format: format3, + fromFileUrl: fromFileUrl3, + isAbsolute: isAbsolute3, + join: join4, + normalize: normalize4, + parse: parse3, + relative: relative3, + resolve: resolve3, + sep: sep3, + toFileUrl: toFileUrl3, + toNamespacedPath: toNamespacedPath3 +} = path2; + +// path.ts +var path_default = { ...mod_exports }; +export { + SEP, + SEP_PATTERN, + basename3 as basename, + common, + path_default as default, + delimiter3 as delimiter, + dirname3 as dirname, + extname3 as extname, + format3 as format, + fromFileUrl3 as fromFileUrl, + globToRegExp, + isAbsolute3 as isAbsolute, + isGlob, + join4 as join, + joinGlobs, + normalize4 as normalize, + normalizeGlob, + parse3 as parse, + posix, + relative3 as relative, + resolve3 as resolve, + sep3 as sep, + toFileUrl3 as toFileUrl, + toNamespacedPath3 as toNamespacedPath, + win32 +}; diff --git a/server/nodejs.go b/server/nodejs.go index 2537cdcb3..d0e197982 100644 --- a/server/nodejs.go +++ b/server/nodejs.go @@ -81,6 +81,7 @@ var builtInNodeModules = map[string]bool{ var denoStdNodeModules = map[string]bool{ "fs": true, "child_process": true, + "path": true, } // copy from https://github.com/webpack/webpack/blob/master/lib/ModuleNotFoundError.js#L13 @@ -95,7 +96,6 @@ var polyfilledBuiltInNodeModules = map[string]string{ "http": "stream-http", "https": "https-browserify", "os": "os-browserify/browser", - "path": "path-browserify", "punycode": "punycode", "process": "process/browser", "querystring": "querystring-es3", From b4c8514af5ce3a55f12ecb349b211fdbc6b81609 Mon Sep 17 00:00:00 2001 From: v1rtl Date: Wed, 8 Sep 2021 12:45:45 +0300 Subject: [PATCH 2/4] add querystring, timers and url --- embed/polyfills/deno_std_node_querystring.js | 110 ++ embed/polyfills/deno_std_node_timers.js | 24 + embed/polyfills/deno_std_node_url.js | 1644 ++++++++++++++++++ server/nodejs.go | 6 +- 4 files changed, 1781 insertions(+), 3 deletions(-) create mode 100644 embed/polyfills/deno_std_node_querystring.js create mode 100644 embed/polyfills/deno_std_node_timers.js create mode 100644 embed/polyfills/deno_std_node_url.js diff --git a/embed/polyfills/deno_std_node_querystring.js b/embed/polyfills/deno_std_node_querystring.js new file mode 100644 index 000000000..a7ad0d12d --- /dev/null +++ b/embed/polyfills/deno_std_node_querystring.js @@ -0,0 +1,110 @@ +// querystring.ts +var hexTable = new Array(256); +for (let i = 0; i < 256; ++i) { + hexTable[i] = "%" + ((i < 16 ? "0" : "") + i.toString(16)).toUpperCase(); +} +function parse(str, sep = "&", eq = "=", { decodeURIComponent: decodeURIComponent2 = unescape, maxKeys = 1e3 } = {}) { + const entries = str.split(sep).map((entry) => entry.split(eq).map(decodeURIComponent2)); + const final = {}; + let i = 0; + while (true) { + if (Object.keys(final).length === maxKeys && !!maxKeys || !entries[i]) { + break; + } + const [key, val] = entries[i]; + if (final[key]) { + if (Array.isArray(final[key])) { + final[key].push(val); + } else { + final[key] = [final[key], val]; + } + } else { + final[key] = val; + } + i++; + } + return final; +} +function encodeStr(str, noEscapeTable, hexTable2) { + const len = str.length; + if (len === 0) + return ""; + let out = ""; + let lastPos = 0; + for (let i = 0; i < len; i++) { + let c = str.charCodeAt(i); + if (c < 128) { + if (noEscapeTable[c] === 1) + continue; + if (lastPos < i) + out += str.slice(lastPos, i); + lastPos = i + 1; + out += hexTable2[c]; + continue; + } + if (lastPos < i) + out += str.slice(lastPos, i); + if (c < 2048) { + lastPos = i + 1; + out += hexTable2[192 | c >> 6] + hexTable2[128 | c & 63]; + continue; + } + if (c < 55296 || c >= 57344) { + lastPos = i + 1; + out += hexTable2[224 | c >> 12] + hexTable2[128 | c >> 6 & 63] + hexTable2[128 | c & 63]; + continue; + } + ++i; + if (i >= len) + throw new Deno.errors.InvalidData("invalid URI"); + const c2 = str.charCodeAt(i) & 1023; + lastPos = i + 1; + c = 65536 + ((c & 1023) << 10 | c2); + out += hexTable2[240 | c >> 18] + hexTable2[128 | c >> 12 & 63] + hexTable2[128 | c >> 6 & 63] + hexTable2[128 | c & 63]; + } + if (lastPos === 0) + return str; + if (lastPos < len) + return out + str.slice(lastPos); + return out; +} +function stringify(obj, sep = "&", eq = "=", { encodeURIComponent: encodeURIComponent2 = escape } = {}) { + const final = []; + for (const entry of Object.entries(obj)) { + if (Array.isArray(entry[1])) { + for (const val of entry[1]) { + final.push(encodeURIComponent2(entry[0]) + eq + encodeURIComponent2(val)); + } + } else if (typeof entry[1] !== "object" && entry[1] !== void 0) { + final.push(entry.map(encodeURIComponent2).join(eq)); + } else { + final.push(encodeURIComponent2(entry[0]) + eq); + } + } + return final.join(sep); +} +var decode = parse; +var encode = stringify; +var unescape = decodeURIComponent; +var escape = encodeURIComponent; +var querystring_default = { + parse, + encodeStr, + stringify, + hexTable, + decode, + encode, + unescape, + escape +}; +export { + decode, + querystring_default as default, + encode, + encodeStr, + escape, + hexTable, + parse, + stringify, + unescape +}; diff --git a/embed/polyfills/deno_std_node_timers.js b/embed/polyfills/deno_std_node_timers.js new file mode 100644 index 000000000..388ebc3e9 --- /dev/null +++ b/embed/polyfills/deno_std_node_timers.js @@ -0,0 +1,24 @@ +// timers.ts +var setTimeout = globalThis.setTimeout; +var clearTimeout = globalThis.clearTimeout; +var setInterval = globalThis.setInterval; +var clearInterval = globalThis.clearInterval; +var setImmediate = (cb, ...args) => globalThis.setTimeout(cb, 0, ...args); +var clearImmediate = globalThis.clearTimeout; +var timers_default = { + setTimeout, + clearTimeout, + setInterval, + clearInterval, + setImmediate, + clearImmediate +}; +export { + clearImmediate, + clearInterval, + clearTimeout, + timers_default as default, + setImmediate, + setInterval, + setTimeout +}; diff --git a/embed/polyfills/deno_std_node_url.js b/embed/polyfills/deno_std_node_url.js new file mode 100644 index 000000000..887790c66 --- /dev/null +++ b/embed/polyfills/deno_std_node_url.js @@ -0,0 +1,1644 @@ +var __defProp = Object.defineProperty; +var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); +var __export = (target, all) => { + __markAsModule(target); + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; + +// ../path/_constants.ts +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; +var CHAR_QUESTION_MARK = 63; + +// ../path/mod.ts +var mod_exports = {}; +__export(mod_exports, { + SEP: () => SEP, + SEP_PATTERN: () => SEP_PATTERN, + basename: () => basename3, + common: () => common, + delimiter: () => delimiter3, + dirname: () => dirname3, + extname: () => extname3, + format: () => format3, + fromFileUrl: () => fromFileUrl3, + globToRegExp: () => globToRegExp, + isAbsolute: () => isAbsolute3, + isGlob: () => isGlob, + join: () => join4, + joinGlobs: () => joinGlobs, + normalize: () => normalize4, + normalizeGlob: () => normalizeGlob, + parse: () => parse3, + posix: () => posix, + relative: () => relative3, + resolve: () => resolve3, + sep: () => sep3, + toFileUrl: () => toFileUrl3, + toNamespacedPath: () => toNamespacedPath3, + win32: () => win32 +}); + +// ../_util/os.ts +var osType = (() => { + const { Deno: Deno2 } = globalThis; + if (typeof Deno2?.build?.os === "string") { + return Deno2.build.os; + } + const { navigator } = globalThis; + if (navigator?.appVersion?.includes?.("Win") ?? false) { + return "windows"; + } + return "linux"; +})(); +var isWindows = osType === "windows"; + +// ../path/win32.ts +var win32_exports = {}; +__export(win32_exports, { + basename: () => basename, + delimiter: () => delimiter, + dirname: () => dirname, + extname: () => extname, + format: () => format, + fromFileUrl: () => fromFileUrl, + isAbsolute: () => isAbsolute, + join: () => join, + normalize: () => normalize, + parse: () => parse, + relative: () => relative, + resolve: () => resolve, + sep: () => sep, + toFileUrl: () => toFileUrl, + toNamespacedPath: () => toNamespacedPath +}); + +// ../path/_util.ts +function assertPath(path4) { + if (typeof path4 !== "string") { + throw new TypeError(`Path must be a string. Received ${JSON.stringify(path4)}`); + } +} +function isPosixPathSeparator(code) { + return code === CHAR_FORWARD_SLASH; +} +function isPathSeparator(code) { + return isPosixPathSeparator(code) || 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 normalizeString(path4, allowAboveRoot, separator, isPathSeparator2) { + let res = ""; + let lastSegmentLength = 0; + let lastSlash = -1; + let dots = 0; + let code; + for (let i = 0, len = path4.length; i <= len; ++i) { + if (i < len) + code = path4.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 + path4.slice(lastSlash + 1, i); + else + res = path4.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 _format(sep4, pathObject) { + const dir = pathObject.dir || pathObject.root; + const base = pathObject.base || (pathObject.name || "") + (pathObject.ext || ""); + if (!dir) + return base; + if (dir === pathObject.root) + return dir + base; + return dir + sep4 + base; +} +var WHITESPACE_ENCODINGS = { + " ": "%09", + "\n": "%0A", + "\v": "%0B", + "\f": "%0C", + "\r": "%0D", + " ": "%20" +}; +function encodeWhitespace(string) { + return string.replaceAll(/[\s]/g, (c) => { + return WHITESPACE_ENCODINGS[c] ?? c; + }); +} + +// ../_util/assert.ts +var DenoStdInternalError = class extends Error { + constructor(message) { + super(message); + this.name = "DenoStdInternalError"; + } +}; +function assert(expr, msg = "") { + if (!expr) { + throw new DenoStdInternalError(msg); + } +} + +// ../path/win32.ts +var sep = "\\"; +var delimiter = ";"; +function resolve(...pathSegments) { + let resolvedDevice = ""; + let resolvedTail = ""; + let resolvedAbsolute = false; + for (let i = pathSegments.length - 1; i >= -1; i--) { + let path4; + const { Deno: Deno2 } = globalThis; + if (i >= 0) { + path4 = pathSegments[i]; + } else if (!resolvedDevice) { + if (typeof Deno2?.cwd !== "function") { + throw new TypeError("Resolved a drive-letter-less path without a CWD."); + } + path4 = Deno2.cwd(); + } else { + if (typeof Deno2?.env?.get !== "function" || typeof Deno2?.cwd !== "function") { + throw new TypeError("Resolved a relative path without a CWD."); + } + path4 = Deno2.env.get(`=${resolvedDevice}`) || Deno2.cwd(); + if (path4 === void 0 || path4.slice(0, 3).toLowerCase() !== `${resolvedDevice.toLowerCase()}\\`) { + path4 = `${resolvedDevice}\\`; + } + } + assertPath(path4); + const len = path4.length; + if (len === 0) + continue; + let rootEnd = 0; + let device = ""; + let isAbsolute4 = false; + const code = path4.charCodeAt(0); + if (len > 1) { + if (isPathSeparator(code)) { + isAbsolute4 = true; + if (isPathSeparator(path4.charCodeAt(1))) { + let j = 2; + let last = j; + for (; j < len; ++j) { + if (isPathSeparator(path4.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + const firstPart = path4.slice(last, j); + last = j; + for (; j < len; ++j) { + if (!isPathSeparator(path4.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + last = j; + for (; j < len; ++j) { + if (isPathSeparator(path4.charCodeAt(j))) + break; + } + if (j === len) { + device = `\\\\${firstPart}\\${path4.slice(last)}`; + rootEnd = j; + } else if (j !== last) { + device = `\\\\${firstPart}\\${path4.slice(last, j)}`; + rootEnd = j; + } + } + } + } else { + rootEnd = 1; + } + } else if (isWindowsDeviceRoot(code)) { + if (path4.charCodeAt(1) === CHAR_COLON) { + device = path4.slice(0, 2); + rootEnd = 2; + if (len > 2) { + if (isPathSeparator(path4.charCodeAt(2))) { + isAbsolute4 = true; + rootEnd = 3; + } + } + } + } + } else if (isPathSeparator(code)) { + rootEnd = 1; + isAbsolute4 = true; + } + if (device.length > 0 && resolvedDevice.length > 0 && device.toLowerCase() !== resolvedDevice.toLowerCase()) { + continue; + } + if (resolvedDevice.length === 0 && device.length > 0) { + resolvedDevice = device; + } + if (!resolvedAbsolute) { + resolvedTail = `${path4.slice(rootEnd)}\\${resolvedTail}`; + resolvedAbsolute = isAbsolute4; + } + if (resolvedAbsolute && resolvedDevice.length > 0) + break; + } + resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, "\\", isPathSeparator); + return resolvedDevice + (resolvedAbsolute ? "\\" : "") + resolvedTail || "."; +} +function normalize(path4) { + assertPath(path4); + const len = path4.length; + if (len === 0) + return "."; + let rootEnd = 0; + let device; + let isAbsolute4 = false; + const code = path4.charCodeAt(0); + if (len > 1) { + if (isPathSeparator(code)) { + isAbsolute4 = true; + if (isPathSeparator(path4.charCodeAt(1))) { + let j = 2; + let last = j; + for (; j < len; ++j) { + if (isPathSeparator(path4.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + const firstPart = path4.slice(last, j); + last = j; + for (; j < len; ++j) { + if (!isPathSeparator(path4.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + last = j; + for (; j < len; ++j) { + if (isPathSeparator(path4.charCodeAt(j))) + break; + } + if (j === len) { + return `\\\\${firstPart}\\${path4.slice(last)}\\`; + } else if (j !== last) { + device = `\\\\${firstPart}\\${path4.slice(last, j)}`; + rootEnd = j; + } + } + } + } else { + rootEnd = 1; + } + } else if (isWindowsDeviceRoot(code)) { + if (path4.charCodeAt(1) === CHAR_COLON) { + device = path4.slice(0, 2); + rootEnd = 2; + if (len > 2) { + if (isPathSeparator(path4.charCodeAt(2))) { + isAbsolute4 = true; + rootEnd = 3; + } + } + } + } + } else if (isPathSeparator(code)) { + return "\\"; + } + let tail; + if (rootEnd < len) { + tail = normalizeString(path4.slice(rootEnd), !isAbsolute4, "\\", isPathSeparator); + } else { + tail = ""; + } + if (tail.length === 0 && !isAbsolute4) + tail = "."; + if (tail.length > 0 && isPathSeparator(path4.charCodeAt(len - 1))) { + tail += "\\"; + } + if (device === void 0) { + if (isAbsolute4) { + if (tail.length > 0) + return `\\${tail}`; + else + return "\\"; + } else if (tail.length > 0) { + return tail; + } else { + return ""; + } + } else if (isAbsolute4) { + if (tail.length > 0) + return `${device}\\${tail}`; + else + return `${device}\\`; + } else if (tail.length > 0) { + return device + tail; + } else { + return device; + } +} +function isAbsolute(path4) { + assertPath(path4); + const len = path4.length; + if (len === 0) + return false; + const code = path4.charCodeAt(0); + if (isPathSeparator(code)) { + return true; + } else if (isWindowsDeviceRoot(code)) { + if (len > 2 && path4.charCodeAt(1) === CHAR_COLON) { + if (isPathSeparator(path4.charCodeAt(2))) + return true; + } + } + return false; +} +function join(...paths) { + const pathsCount = paths.length; + if (pathsCount === 0) + return "."; + let joined; + let firstPart = null; + for (let i = 0; i < pathsCount; ++i) { + const path4 = paths[i]; + assertPath(path4); + if (path4.length > 0) { + if (joined === void 0) + joined = firstPart = path4; + else + joined += `\\${path4}`; + } + } + if (joined === void 0) + return "."; + let needsReplace = true; + let slashCount = 0; + assert(firstPart != null); + 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; + } + } + } + } + } + if (needsReplace) { + for (; slashCount < joined.length; ++slashCount) { + if (!isPathSeparator(joined.charCodeAt(slashCount))) + break; + } + if (slashCount >= 2) + joined = `\\${joined.slice(slashCount)}`; + } + return normalize(joined); +} +function relative(from, to) { + assertPath(from); + assertPath(to); + if (from === to) + return ""; + const fromOrig = resolve(from); + const toOrig = resolve(to); + if (fromOrig === toOrig) + return ""; + from = fromOrig.toLowerCase(); + to = toOrig.toLowerCase(); + if (from === to) + return ""; + let fromStart = 0; + let fromEnd = from.length; + for (; fromStart < fromEnd; ++fromStart) { + if (from.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH) + break; + } + for (; fromEnd - 1 > fromStart; --fromEnd) { + if (from.charCodeAt(fromEnd - 1) !== CHAR_BACKWARD_SLASH) + break; + } + const fromLen = fromEnd - fromStart; + let toStart = 0; + let toEnd = to.length; + for (; toStart < toEnd; ++toStart) { + if (to.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH) + break; + } + for (; toEnd - 1 > toStart; --toEnd) { + if (to.charCodeAt(toEnd - 1) !== CHAR_BACKWARD_SLASH) + 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 (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) { + return toOrig.slice(toStart + i + 1); + } else if (i === 2) { + return toOrig.slice(toStart + i); + } + } + if (fromLen > length) { + if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) { + lastCommonSep = i; + } else if (i === 2) { + lastCommonSep = 3; + } + } + break; + } + const fromCode = from.charCodeAt(fromStart + i); + const toCode = to.charCodeAt(toStart + i); + if (fromCode !== toCode) + break; + else if (fromCode === CHAR_BACKWARD_SLASH) + lastCommonSep = i; + } + if (i !== length && lastCommonSep === -1) { + return toOrig; + } + let out = ""; + if (lastCommonSep === -1) + lastCommonSep = 0; + for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { + if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) { + if (out.length === 0) + out += ".."; + else + out += "\\.."; + } + } + if (out.length > 0) { + return out + toOrig.slice(toStart + lastCommonSep, toEnd); + } else { + toStart += lastCommonSep; + if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) + ++toStart; + return toOrig.slice(toStart, toEnd); + } +} +function toNamespacedPath(path4) { + if (typeof path4 !== "string") + return path4; + if (path4.length === 0) + return ""; + const resolvedPath = resolve(path4); + if (resolvedPath.length >= 3) { + if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) { + if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) { + const code = resolvedPath.charCodeAt(2); + if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) { + return `\\\\?\\UNC\\${resolvedPath.slice(2)}`; + } + } + } else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0))) { + if (resolvedPath.charCodeAt(1) === CHAR_COLON && resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) { + return `\\\\?\\${resolvedPath}`; + } + } + } + return path4; +} +function dirname(path4) { + assertPath(path4); + const len = path4.length; + if (len === 0) + return "."; + let rootEnd = -1; + let end = -1; + let matchedSlash = true; + let offset = 0; + const code = path4.charCodeAt(0); + if (len > 1) { + if (isPathSeparator(code)) { + rootEnd = offset = 1; + if (isPathSeparator(path4.charCodeAt(1))) { + let j = 2; + let last = j; + for (; j < len; ++j) { + if (isPathSeparator(path4.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + last = j; + for (; j < len; ++j) { + if (!isPathSeparator(path4.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + last = j; + for (; j < len; ++j) { + if (isPathSeparator(path4.charCodeAt(j))) + break; + } + if (j === len) { + return path4; + } + if (j !== last) { + rootEnd = offset = j + 1; + } + } + } + } + } else if (isWindowsDeviceRoot(code)) { + if (path4.charCodeAt(1) === CHAR_COLON) { + rootEnd = offset = 2; + if (len > 2) { + if (isPathSeparator(path4.charCodeAt(2))) + rootEnd = offset = 3; + } + } + } + } else if (isPathSeparator(code)) { + return path4; + } + for (let i = len - 1; i >= offset; --i) { + if (isPathSeparator(path4.charCodeAt(i))) { + if (!matchedSlash) { + end = i; + break; + } + } else { + matchedSlash = false; + } + } + if (end === -1) { + if (rootEnd === -1) + return "."; + else + end = rootEnd; + } + return path4.slice(0, end); +} +function basename(path4, ext = "") { + if (ext !== void 0 && typeof ext !== "string") { + throw new TypeError('"ext" argument must be a string'); + } + assertPath(path4); + let start = 0; + let end = -1; + let matchedSlash = true; + let i; + if (path4.length >= 2) { + const drive = path4.charCodeAt(0); + if (isWindowsDeviceRoot(drive)) { + if (path4.charCodeAt(1) === CHAR_COLON) + start = 2; + } + } + if (ext !== void 0 && ext.length > 0 && ext.length <= path4.length) { + if (ext.length === path4.length && ext === path4) + return ""; + let extIdx = ext.length - 1; + let firstNonSlashEnd = -1; + for (i = path4.length - 1; i >= start; --i) { + const code = path4.charCodeAt(i); + if (isPathSeparator(code)) { + if (!matchedSlash) { + start = i + 1; + break; + } + } else { + if (firstNonSlashEnd === -1) { + matchedSlash = false; + firstNonSlashEnd = i + 1; + } + if (extIdx >= 0) { + if (code === ext.charCodeAt(extIdx)) { + if (--extIdx === -1) { + end = i; + } + } else { + extIdx = -1; + end = firstNonSlashEnd; + } + } + } + } + if (start === end) + end = firstNonSlashEnd; + else if (end === -1) + end = path4.length; + return path4.slice(start, end); + } else { + for (i = path4.length - 1; i >= start; --i) { + if (isPathSeparator(path4.charCodeAt(i))) { + if (!matchedSlash) { + start = i + 1; + break; + } + } else if (end === -1) { + matchedSlash = false; + end = i + 1; + } + } + if (end === -1) + return ""; + return path4.slice(start, end); + } +} +function extname(path4) { + assertPath(path4); + let start = 0; + let startDot = -1; + let startPart = 0; + let end = -1; + let matchedSlash = true; + let preDotState = 0; + if (path4.length >= 2 && path4.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path4.charCodeAt(0))) { + start = startPart = 2; + } + for (let i = path4.length - 1; i >= start; --i) { + const code = path4.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 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + return ""; + } + return path4.slice(startDot, end); +} +function format(pathObject) { + if (pathObject === null || typeof pathObject !== "object") { + throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`); + } + return _format("\\", pathObject); +} +function parse(path4) { + assertPath(path4); + const ret = { root: "", dir: "", base: "", ext: "", name: "" }; + const len = path4.length; + if (len === 0) + return ret; + let rootEnd = 0; + let code = path4.charCodeAt(0); + if (len > 1) { + if (isPathSeparator(code)) { + rootEnd = 1; + if (isPathSeparator(path4.charCodeAt(1))) { + let j = 2; + let last = j; + for (; j < len; ++j) { + if (isPathSeparator(path4.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + last = j; + for (; j < len; ++j) { + if (!isPathSeparator(path4.charCodeAt(j))) + break; + } + if (j < len && j !== last) { + last = j; + for (; j < len; ++j) { + if (isPathSeparator(path4.charCodeAt(j))) + break; + } + if (j === len) { + rootEnd = j; + } else if (j !== last) { + rootEnd = j + 1; + } + } + } + } + } else if (isWindowsDeviceRoot(code)) { + if (path4.charCodeAt(1) === CHAR_COLON) { + rootEnd = 2; + if (len > 2) { + if (isPathSeparator(path4.charCodeAt(2))) { + if (len === 3) { + ret.root = ret.dir = path4; + return ret; + } + rootEnd = 3; + } + } else { + ret.root = ret.dir = path4; + return ret; + } + } + } + } else if (isPathSeparator(code)) { + ret.root = ret.dir = path4; + return ret; + } + if (rootEnd > 0) + ret.root = path4.slice(0, rootEnd); + let startDot = -1; + let startPart = rootEnd; + let end = -1; + let matchedSlash = true; + let i = path4.length - 1; + let preDotState = 0; + for (; i >= rootEnd; --i) { + code = path4.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 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + if (end !== -1) { + ret.base = ret.name = path4.slice(startPart, end); + } + } else { + ret.name = path4.slice(startPart, startDot); + ret.base = path4.slice(startPart, end); + ret.ext = path4.slice(startDot, end); + } + if (startPart > 0 && startPart !== rootEnd) { + ret.dir = path4.slice(0, startPart - 1); + } else + ret.dir = ret.root; + return ret; +} +function fromFileUrl(url) { + url = url instanceof URL ? url : new URL(url); + if (url.protocol != "file:") { + throw new TypeError("Must be a file URL."); + } + let path4 = decodeURIComponent(url.pathname.replace(/\//g, "\\").replace(/%(?![0-9A-Fa-f]{2})/g, "%25")).replace(/^\\*([A-Za-z]:)(\\|$)/, "$1\\"); + if (url.hostname != "") { + path4 = `\\\\${url.hostname}${path4}`; + } + return path4; +} +function toFileUrl(path4) { + if (!isAbsolute(path4)) { + throw new TypeError("Must be an absolute path."); + } + const [, hostname, pathname] = path4.match(/^(?:[/\\]{2}([^/\\]+)(?=[/\\](?:[^/\\]|$)))?(.*)/); + const url = new URL("file:///"); + url.pathname = encodeWhitespace(pathname.replace(/%/g, "%25")); + if (hostname != null && hostname != "localhost") { + url.hostname = hostname; + if (!url.hostname) { + throw new TypeError("Invalid hostname."); + } + } + return url; +} + +// ../path/posix.ts +var posix_exports = {}; +__export(posix_exports, { + basename: () => basename2, + delimiter: () => delimiter2, + dirname: () => dirname2, + extname: () => extname2, + format: () => format2, + fromFileUrl: () => fromFileUrl2, + isAbsolute: () => isAbsolute2, + join: () => join2, + normalize: () => normalize2, + parse: () => parse2, + relative: () => relative2, + resolve: () => resolve2, + sep: () => sep2, + toFileUrl: () => toFileUrl2, + toNamespacedPath: () => toNamespacedPath2 +}); +var sep2 = "/"; +var delimiter2 = ":"; +function resolve2(...pathSegments) { + let resolvedPath = ""; + let resolvedAbsolute = false; + for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) { + let path4; + if (i >= 0) + path4 = pathSegments[i]; + else { + const { Deno: Deno2 } = globalThis; + if (typeof Deno2?.cwd !== "function") { + throw new TypeError("Resolved a relative path without a CWD."); + } + path4 = Deno2.cwd(); + } + assertPath(path4); + if (path4.length === 0) { + continue; + } + resolvedPath = `${path4}/${resolvedPath}`; + resolvedAbsolute = path4.charCodeAt(0) === CHAR_FORWARD_SLASH; + } + 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 normalize2(path4) { + assertPath(path4); + if (path4.length === 0) + return "."; + const isAbsolute4 = path4.charCodeAt(0) === CHAR_FORWARD_SLASH; + const trailingSeparator = path4.charCodeAt(path4.length - 1) === CHAR_FORWARD_SLASH; + path4 = normalizeString(path4, !isAbsolute4, "/", isPosixPathSeparator); + if (path4.length === 0 && !isAbsolute4) + path4 = "."; + if (path4.length > 0 && trailingSeparator) + path4 += "/"; + if (isAbsolute4) + return `/${path4}`; + return path4; +} +function isAbsolute2(path4) { + assertPath(path4); + return path4.length > 0 && path4.charCodeAt(0) === CHAR_FORWARD_SLASH; +} +function join2(...paths) { + if (paths.length === 0) + return "."; + let joined; + for (let i = 0, len = paths.length; i < len; ++i) { + const path4 = paths[i]; + assertPath(path4); + if (path4.length > 0) { + if (!joined) + joined = path4; + else + joined += `/${path4}`; + } + } + if (!joined) + return "."; + return normalize2(joined); +} +function relative2(from, to) { + assertPath(from); + assertPath(to); + if (from === to) + return ""; + from = resolve2(from); + to = resolve2(to); + if (from === to) + return ""; + let fromStart = 1; + const fromEnd = from.length; + for (; fromStart < fromEnd; ++fromStart) { + if (from.charCodeAt(fromStart) !== CHAR_FORWARD_SLASH) + break; + } + const fromLen = fromEnd - fromStart; + let toStart = 1; + const toEnd = to.length; + for (; toStart < toEnd; ++toStart) { + if (to.charCodeAt(toStart) !== CHAR_FORWARD_SLASH) + 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 (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) { + return to.slice(toStart + i + 1); + } else if (i === 0) { + return to.slice(toStart + i); + } + } else if (fromLen > length) { + if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) { + 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 (fromCode === CHAR_FORWARD_SLASH) + lastCommonSep = i; + } + let out = ""; + for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { + if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) { + if (out.length === 0) + out += ".."; + else + out += "/.."; + } + } + if (out.length > 0) + return out + to.slice(toStart + lastCommonSep); + else { + toStart += lastCommonSep; + if (to.charCodeAt(toStart) === CHAR_FORWARD_SLASH) + ++toStart; + return to.slice(toStart); + } +} +function toNamespacedPath2(path4) { + return path4; +} +function dirname2(path4) { + assertPath(path4); + if (path4.length === 0) + return "."; + const hasRoot = path4.charCodeAt(0) === CHAR_FORWARD_SLASH; + let end = -1; + let matchedSlash = true; + for (let i = path4.length - 1; i >= 1; --i) { + if (path4.charCodeAt(i) === CHAR_FORWARD_SLASH) { + if (!matchedSlash) { + end = i; + break; + } + } else { + matchedSlash = false; + } + } + if (end === -1) + return hasRoot ? "/" : "."; + if (hasRoot && end === 1) + return "//"; + return path4.slice(0, end); +} +function basename2(path4, ext = "") { + if (ext !== void 0 && typeof ext !== "string") { + throw new TypeError('"ext" argument must be a string'); + } + assertPath(path4); + let start = 0; + let end = -1; + let matchedSlash = true; + let i; + if (ext !== void 0 && ext.length > 0 && ext.length <= path4.length) { + if (ext.length === path4.length && ext === path4) + return ""; + let extIdx = ext.length - 1; + let firstNonSlashEnd = -1; + for (i = path4.length - 1; i >= 0; --i) { + const code = path4.charCodeAt(i); + if (code === CHAR_FORWARD_SLASH) { + if (!matchedSlash) { + start = i + 1; + break; + } + } else { + if (firstNonSlashEnd === -1) { + matchedSlash = false; + firstNonSlashEnd = i + 1; + } + if (extIdx >= 0) { + if (code === ext.charCodeAt(extIdx)) { + if (--extIdx === -1) { + end = i; + } + } else { + extIdx = -1; + end = firstNonSlashEnd; + } + } + } + } + if (start === end) + end = firstNonSlashEnd; + else if (end === -1) + end = path4.length; + return path4.slice(start, end); + } else { + for (i = path4.length - 1; i >= 0; --i) { + if (path4.charCodeAt(i) === CHAR_FORWARD_SLASH) { + if (!matchedSlash) { + start = i + 1; + break; + } + } else if (end === -1) { + matchedSlash = false; + end = i + 1; + } + } + if (end === -1) + return ""; + return path4.slice(start, end); + } +} +function extname2(path4) { + assertPath(path4); + let startDot = -1; + let startPart = 0; + let end = -1; + let matchedSlash = true; + let preDotState = 0; + for (let i = path4.length - 1; i >= 0; --i) { + const code = path4.charCodeAt(i); + if (code === CHAR_FORWARD_SLASH) { + 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 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + return ""; + } + return path4.slice(startDot, end); +} +function format2(pathObject) { + if (pathObject === null || typeof pathObject !== "object") { + throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`); + } + return _format("/", pathObject); +} +function parse2(path4) { + assertPath(path4); + const ret = { root: "", dir: "", base: "", ext: "", name: "" }; + if (path4.length === 0) + return ret; + const isAbsolute4 = path4.charCodeAt(0) === CHAR_FORWARD_SLASH; + let start; + if (isAbsolute4) { + ret.root = "/"; + start = 1; + } else { + start = 0; + } + let startDot = -1; + let startPart = 0; + let end = -1; + let matchedSlash = true; + let i = path4.length - 1; + let preDotState = 0; + for (; i >= start; --i) { + const code = path4.charCodeAt(i); + if (code === CHAR_FORWARD_SLASH) { + 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 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + if (end !== -1) { + if (startPart === 0 && isAbsolute4) { + ret.base = ret.name = path4.slice(1, end); + } else { + ret.base = ret.name = path4.slice(startPart, end); + } + } + } else { + if (startPart === 0 && isAbsolute4) { + ret.name = path4.slice(1, startDot); + ret.base = path4.slice(1, end); + } else { + ret.name = path4.slice(startPart, startDot); + ret.base = path4.slice(startPart, end); + } + ret.ext = path4.slice(startDot, end); + } + if (startPart > 0) + ret.dir = path4.slice(0, startPart - 1); + else if (isAbsolute4) + ret.dir = "/"; + return ret; +} +function fromFileUrl2(url) { + url = url instanceof URL ? url : new URL(url); + if (url.protocol != "file:") { + throw new TypeError("Must be a file URL."); + } + return decodeURIComponent(url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25")); +} +function toFileUrl2(path4) { + if (!isAbsolute2(path4)) { + throw new TypeError("Must be an absolute path."); + } + const url = new URL("file:///"); + url.pathname = encodeWhitespace(path4.replace(/%/g, "%25").replace(/\\/g, "%5C")); + return url; +} + +// ../path/separator.ts +var SEP = isWindows ? "\\" : "/"; +var SEP_PATTERN = isWindows ? /[\\/]+/ : /\/+/; + +// ../path/common.ts +function common(paths, sep4 = SEP) { + const [first = "", ...remaining] = paths; + if (first === "" || remaining.length === 0) { + return first.substring(0, first.lastIndexOf(sep4) + 1); + } + const parts = first.split(sep4); + let endOfPrefix = parts.length; + for (const path4 of remaining) { + const compare = path4.split(sep4); + for (let i = 0; i < endOfPrefix; i++) { + if (compare[i] !== parts[i]) { + endOfPrefix = i; + } + } + if (endOfPrefix === 0) { + return ""; + } + } + const prefix = parts.slice(0, endOfPrefix).join(sep4); + return prefix.endsWith(sep4) ? prefix : `${prefix}${sep4}`; +} + +// ../path/glob.ts +var path = isWindows ? win32_exports : posix_exports; +var { join: join3, normalize: normalize3 } = path; +var regExpEscapeChars = ["!", "$", "(", ")", "*", "+", ".", "=", "?", "[", "\\", "^", "{", "|"]; +var rangeEscapeChars = ["-", "\\", "]"]; +function globToRegExp(glob, { + extended = true, + globstar: globstarOption = true, + os = osType, + caseInsensitive = false +} = {}) { + if (glob == "") { + return /(?!)/; + } + const sep4 = os == "windows" ? "(?:\\\\|/)+" : "/+"; + const sepMaybe = os == "windows" ? "(?:\\\\|/)*" : "/*"; + const seps = os == "windows" ? ["\\", "/"] : ["/"]; + const globstar = os == "windows" ? "(?:[^\\\\/]*(?:\\\\|/|$)+)*" : "(?:[^/]*(?:/|$)+)*"; + const wildcard = os == "windows" ? "[^\\\\/]*" : "[^/]*"; + const escapePrefix = os == "windows" ? "`" : "\\"; + let newLength = glob.length; + for (; newLength > 1 && seps.includes(glob[newLength - 1]); newLength--) + ; + glob = glob.slice(0, newLength); + let regExpString = ""; + for (let j = 0; j < glob.length; ) { + let segment = ""; + const groupStack = []; + let inRange = false; + let inEscape = false; + let endsWithSep = false; + let i = j; + for (; i < glob.length && !seps.includes(glob[i]); i++) { + if (inEscape) { + inEscape = false; + const escapeChars = inRange ? rangeEscapeChars : regExpEscapeChars; + segment += escapeChars.includes(glob[i]) ? `\\${glob[i]}` : glob[i]; + continue; + } + if (glob[i] == escapePrefix) { + inEscape = true; + continue; + } + if (glob[i] == "[") { + if (!inRange) { + inRange = true; + segment += "["; + if (glob[i + 1] == "!") { + i++; + segment += "^"; + } else if (glob[i + 1] == "^") { + i++; + segment += "\\^"; + } + continue; + } else if (glob[i + 1] == ":") { + let k = i + 1; + let value = ""; + while (glob[k + 1] != null && glob[k + 1] != ":") { + value += glob[k + 1]; + k++; + } + if (glob[k + 1] == ":" && glob[k + 2] == "]") { + i = k + 2; + if (value == "alnum") + segment += "\\dA-Za-z"; + else if (value == "alpha") + segment += "A-Za-z"; + else if (value == "ascii") + segment += "\0-\x7F"; + else if (value == "blank") + segment += " "; + else if (value == "cntrl") + segment += "\0-\x7F"; + else if (value == "digit") + segment += "\\d"; + else if (value == "graph") + segment += "!-~"; + else if (value == "lower") + segment += "a-z"; + else if (value == "print") + segment += " -~"; + else if (value == "punct") { + segment += `!"#$%&'()*+,\\-./:;<=>?@[\\\\\\]^_\u2018{|}~`; + } else if (value == "space") + segment += "\\s\v"; + else if (value == "upper") + segment += "A-Z"; + else if (value == "word") + segment += "\\w"; + else if (value == "xdigit") + segment += "\\dA-Fa-f"; + continue; + } + } + } + if (glob[i] == "]" && inRange) { + inRange = false; + segment += "]"; + continue; + } + if (inRange) { + if (glob[i] == "\\") { + segment += `\\\\`; + } else { + segment += glob[i]; + } + continue; + } + if (glob[i] == ")" && groupStack.length > 0 && groupStack[groupStack.length - 1] != "BRACE") { + segment += ")"; + const type = groupStack.pop(); + if (type == "!") { + segment += wildcard; + } else if (type != "@") { + segment += type; + } + continue; + } + if (glob[i] == "|" && groupStack.length > 0 && groupStack[groupStack.length - 1] != "BRACE") { + segment += "|"; + continue; + } + if (glob[i] == "+" && extended && glob[i + 1] == "(") { + i++; + groupStack.push("+"); + segment += "(?:"; + continue; + } + if (glob[i] == "@" && extended && glob[i + 1] == "(") { + i++; + groupStack.push("@"); + segment += "(?:"; + continue; + } + if (glob[i] == "?") { + if (extended && glob[i + 1] == "(") { + i++; + groupStack.push("?"); + segment += "(?:"; + } else { + segment += "."; + } + continue; + } + if (glob[i] == "!" && extended && glob[i + 1] == "(") { + i++; + groupStack.push("!"); + segment += "(?!"; + continue; + } + if (glob[i] == "{") { + groupStack.push("BRACE"); + segment += "(?:"; + continue; + } + if (glob[i] == "}" && groupStack[groupStack.length - 1] == "BRACE") { + groupStack.pop(); + segment += ")"; + continue; + } + if (glob[i] == "," && groupStack[groupStack.length - 1] == "BRACE") { + segment += "|"; + continue; + } + if (glob[i] == "*") { + if (extended && glob[i + 1] == "(") { + i++; + groupStack.push("*"); + segment += "(?:"; + } else { + const prevChar = glob[i - 1]; + let numStars = 1; + while (glob[i + 1] == "*") { + i++; + numStars++; + } + const nextChar = glob[i + 1]; + if (globstarOption && numStars == 2 && [...seps, void 0].includes(prevChar) && [...seps, void 0].includes(nextChar)) { + segment += globstar; + endsWithSep = true; + } else { + segment += wildcard; + } + } + continue; + } + segment += regExpEscapeChars.includes(glob[i]) ? `\\${glob[i]}` : glob[i]; + } + if (groupStack.length > 0 || inRange || inEscape) { + segment = ""; + for (const c of glob.slice(j, i)) { + segment += regExpEscapeChars.includes(c) ? `\\${c}` : c; + endsWithSep = false; + } + } + regExpString += segment; + if (!endsWithSep) { + regExpString += i < glob.length ? sep4 : sepMaybe; + endsWithSep = true; + } + while (seps.includes(glob[i])) + i++; + if (!(i > j)) { + throw new Error("Assertion failure: i > j (potential infinite loop)"); + } + j = i; + } + regExpString = `^${regExpString}$`; + return new RegExp(regExpString, caseInsensitive ? "i" : ""); +} +function isGlob(str) { + const chars = { "{": "}", "(": ")", "[": "]" }; + const regex = /\\(.)|(^!|\*|\?|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/; + if (str === "") { + return false; + } + let match; + while (match = regex.exec(str)) { + if (match[2]) + return true; + let idx = match.index + match[0].length; + const open = match[1]; + const close = open ? chars[open] : null; + if (open && close) { + const n = str.indexOf(close, idx); + if (n !== -1) { + idx = n + 1; + } + } + str = str.slice(idx); + } + return false; +} +function normalizeGlob(glob, { globstar = false } = {}) { + if (glob.match(/\0/g)) { + throw new Error(`Glob contains invalid characters: "${glob}"`); + } + if (!globstar) { + return normalize3(glob); + } + const s = SEP_PATTERN.source; + const badParentPattern = new RegExp(`(?<=(${s}|^)\\*\\*${s})\\.\\.(?=${s}|$)`, "g"); + return normalize3(glob.replace(badParentPattern, "\0")).replace(/\0/g, ".."); +} +function joinGlobs(globs, { extended = false, globstar = false } = {}) { + if (!globstar || globs.length == 0) { + return join3(...globs); + } + if (globs.length === 0) + return "."; + let joined; + for (const glob of globs) { + const path4 = glob; + if (path4.length > 0) { + if (!joined) + joined = path4; + else + joined += `${SEP}${path4}`; + } + } + if (!joined) + return "."; + return normalizeGlob(joined, { extended, globstar }); +} + +// ../path/mod.ts +var path2 = isWindows ? win32_exports : posix_exports; +var win32 = win32_exports; +var posix = posix_exports; +var { + basename: basename3, + delimiter: delimiter3, + dirname: dirname3, + extname: extname3, + format: format3, + fromFileUrl: fromFileUrl3, + isAbsolute: isAbsolute3, + join: join4, + normalize: normalize4, + parse: parse3, + relative: relative3, + resolve: resolve3, + sep: sep3, + toFileUrl: toFileUrl3, + toNamespacedPath: toNamespacedPath3 +} = path2; + +// path.ts +var path_default = { ...mod_exports }; + +// url.ts +var forwardSlashRegEx = /\//g; +var percentRegEx = /%/g; +var backslashRegEx = /\\/g; +var newlineRegEx = /\n/g; +var carriageReturnRegEx = /\r/g; +var tabRegEx = /\t/g; +var _url = URL; +function fileURLToPath(path4) { + if (typeof path4 === "string") + path4 = new URL(path4); + else if (!(path4 instanceof URL)) { + throw new Deno.errors.InvalidData("invalid argument path , must be a string or URL"); + } + if (path4.protocol !== "file:") { + throw new Deno.errors.InvalidData("invalid url scheme"); + } + return isWindows ? getPathFromURLWin(path4) : getPathFromURLPosix(path4); +} +function getPathFromURLWin(url) { + const hostname = url.hostname; + let pathname = url.pathname; + for (let n = 0; n < pathname.length; n++) { + if (pathname[n] === "%") { + const third = pathname.codePointAt(n + 2) || 32; + if (pathname[n + 1] === "2" && third === 102 || pathname[n + 1] === "5" && third === 99) { + throw new Deno.errors.InvalidData("must not include encoded \\ or / characters"); + } + } + } + pathname = pathname.replace(forwardSlashRegEx, "\\"); + pathname = decodeURIComponent(pathname); + if (hostname !== "") { + return `\\\\${hostname}${pathname}`; + } else { + const letter = pathname.codePointAt(1) | 32; + const sep4 = pathname[2]; + if (letter < CHAR_LOWERCASE_A || letter > CHAR_LOWERCASE_Z || sep4 !== ":") { + throw new Deno.errors.InvalidData("file url path must be absolute"); + } + return pathname.slice(1); + } +} +function getPathFromURLPosix(url) { + if (url.hostname !== "") { + throw new Deno.errors.InvalidData("invalid file url hostname"); + } + const pathname = url.pathname; + for (let n = 0; n < pathname.length; n++) { + if (pathname[n] === "%") { + const third = pathname.codePointAt(n + 2) || 32; + if (pathname[n + 1] === "2" && third === 102) { + throw new Deno.errors.InvalidData("must not include encoded / characters"); + } + } + } + return decodeURIComponent(pathname); +} +function pathToFileURL(filepath) { + let resolved = resolve3(filepath); + const filePathLast = filepath.charCodeAt(filepath.length - 1); + if ((filePathLast === CHAR_FORWARD_SLASH || isWindows && filePathLast === CHAR_BACKWARD_SLASH) && resolved[resolved.length - 1] !== sep3) { + resolved += "/"; + } + const outURL = new URL("file://"); + if (resolved.includes("%")) + resolved = resolved.replace(percentRegEx, "%25"); + if (!isWindows && resolved.includes("\\")) { + resolved = resolved.replace(backslashRegEx, "%5C"); + } + if (resolved.includes("\n")) + resolved = resolved.replace(newlineRegEx, "%0A"); + if (resolved.includes("\r")) { + resolved = resolved.replace(carriageReturnRegEx, "%0D"); + } + if (resolved.includes(" ")) + resolved = resolved.replace(tabRegEx, "%09"); + outURL.pathname = resolved; + return outURL; +} +var url_default = { + fileURLToPath, + pathToFileURL, + URL +}; +export { + _url as URL, + url_default as default, + fileURLToPath, + pathToFileURL +}; diff --git a/server/nodejs.go b/server/nodejs.go index d0e197982..a57e67ee3 100644 --- a/server/nodejs.go +++ b/server/nodejs.go @@ -82,6 +82,9 @@ var denoStdNodeModules = map[string]bool{ "fs": true, "child_process": true, "path": true, + "querystring": true, + "timers": true, + "url": true, } // copy from https://github.com/webpack/webpack/blob/master/lib/ModuleNotFoundError.js#L13 @@ -98,7 +101,6 @@ var polyfilledBuiltInNodeModules = map[string]string{ "os": "os-browserify/browser", "punycode": "punycode", "process": "process/browser", - "querystring": "querystring-es3", "stream": "stream-browserify", "_stream_duplex": "readable-stream/duplex", "_stream_passthrough": "readable-stream/passthrough", @@ -107,9 +109,7 @@ var polyfilledBuiltInNodeModules = map[string]string{ "_stream_writable": "readable-stream/writable", "string_decoder": "string_decoder", "sys": "util", - "timers": "timers-browserify", "tty": "tty-browserify", - "url": "url", "util": "util", "vm": "vm-browserify", "zlib": "browserify-zlib", From c08d0c6a8b4919aa98e23f6b4061615f88b1f14a Mon Sep 17 00:00:00 2001 From: v1rtl Date: Wed, 8 Sep 2021 13:01:23 +0300 Subject: [PATCH 3/4] return modules from polyfilledBuiltInModules --- server/nodejs.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/nodejs.go b/server/nodejs.go index a57e67ee3..bc5a23a8c 100644 --- a/server/nodejs.go +++ b/server/nodejs.go @@ -99,8 +99,10 @@ var polyfilledBuiltInNodeModules = map[string]string{ "http": "stream-http", "https": "https-browserify", "os": "os-browserify/browser", + "path": "path-browserify", "punycode": "punycode", "process": "process/browser", + "querystring": "querystring-es3", "stream": "stream-browserify", "_stream_duplex": "readable-stream/duplex", "_stream_passthrough": "readable-stream/passthrough", @@ -109,7 +111,9 @@ var polyfilledBuiltInNodeModules = map[string]string{ "_stream_writable": "readable-stream/writable", "string_decoder": "string_decoder", "sys": "util", + "timers": "timers-browserify", "tty": "tty-browserify", + "url": "url", "util": "util", "vm": "vm-browserify", "zlib": "browserify-zlib", From cf22f676dfe42d3e8aacf545dcc95a1715ed7868 Mon Sep 17 00:00:00 2001 From: v1rtl Date: Wed, 8 Sep 2021 16:14:23 +0300 Subject: [PATCH 4/4] add comments for bundling --- embed/polyfills/deno_std_node_path.js | 1701 ++++++++-------- embed/polyfills/deno_std_node_querystring.js | 136 +- embed/polyfills/deno_std_node_timers.js | 33 +- embed/polyfills/deno_std_node_url.js | 1819 +++++++++--------- 4 files changed, 1755 insertions(+), 1934 deletions(-) diff --git a/embed/polyfills/deno_std_node_path.js b/embed/polyfills/deno_std_node_path.js index f5c814611..427f7236d 100644 --- a/embed/polyfills/deno_std_node_path.js +++ b/embed/polyfills/deno_std_node_path.js @@ -1,13 +1,21 @@ -var __defProp = Object.defineProperty; -var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); +/* deno mod bundle + * entry: deno.land/std/node/path.ts + * version: 0.106.0 + * + * $ git clone https://github.com/denoland/deno_std + * $ cd deno_std/node + * $ esbuild path.ts --target=esnext --format=esm --bundle --outfile=deno_std_node_path.js + */ + +var __defProp = Object.defineProperty +var __markAsModule = (target) => __defProp(target, '__esModule', { value: true }) var __export = (target, all) => { - __markAsModule(target); - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; + __markAsModule(target) + for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }) +} // ../path/mod.ts -var mod_exports = {}; +var mod_exports = {} __export(mod_exports, { SEP: () => SEP, SEP_PATTERN: () => SEP_PATTERN, @@ -33,24 +41,24 @@ __export(mod_exports, { toFileUrl: () => toFileUrl3, toNamespacedPath: () => toNamespacedPath3, win32: () => win32 -}); +}) // ../_util/os.ts var osType = (() => { - const { Deno } = globalThis; - if (typeof Deno?.build?.os === "string") { - return Deno.build.os; + const { Deno } = globalThis + if (typeof Deno?.build?.os === 'string') { + return Deno.build.os } - const { navigator } = globalThis; - if (navigator?.appVersion?.includes?.("Win") ?? false) { - return "windows"; + const { navigator } = globalThis + if (navigator?.appVersion?.includes?.('Win') ?? false) { + return 'windows' } - return "linux"; -})(); -var isWindows = osType === "windows"; + return 'linux' +})() +var isWindows = osType === 'windows' // ../path/win32.ts -var win32_exports = {}; +var win32_exports = {} __export(win32_exports, { basename: () => basename, delimiter: () => delimiter, @@ -67,371 +75,348 @@ __export(win32_exports, { sep: () => sep, toFileUrl: () => toFileUrl, toNamespacedPath: () => toNamespacedPath -}); +}) // ../path/_constants.ts -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; -var CHAR_QUESTION_MARK = 63; +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 +var CHAR_QUESTION_MARK = 63 // ../path/_util.ts function assertPath(path3) { - if (typeof path3 !== "string") { - throw new TypeError(`Path must be a string. Received ${JSON.stringify(path3)}`); + if (typeof path3 !== 'string') { + throw new TypeError(`Path must be a string. Received ${JSON.stringify(path3)}`) } } function isPosixPathSeparator(code) { - return code === CHAR_FORWARD_SLASH; + return code === CHAR_FORWARD_SLASH } function isPathSeparator(code) { - return isPosixPathSeparator(code) || code === CHAR_BACKWARD_SLASH; + return isPosixPathSeparator(code) || code === CHAR_BACKWARD_SLASH } function isWindowsDeviceRoot(code) { - return code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z || code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z; + return ( + (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z) || (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) + ) } function normalizeString(path3, allowAboveRoot, separator, isPathSeparator2) { - let res = ""; - let lastSegmentLength = 0; - let lastSlash = -1; - let dots = 0; - let code; + let res = '' + let lastSegmentLength = 0 + let lastSlash = -1 + let dots = 0 + let code for (let i = 0, len = path3.length; i <= len; ++i) { - if (i < len) - code = path3.charCodeAt(i); - else if (isPathSeparator2(code)) - break; - else - code = CHAR_FORWARD_SLASH; + if (i < len) code = path3.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 || + 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); + const lastSlashIndex = res.lastIndexOf(separator) if (lastSlashIndex === -1) { - res = ""; - lastSegmentLength = 0; + res = '' + lastSegmentLength = 0 } else { - res = res.slice(0, lastSlashIndex); - lastSegmentLength = res.length - 1 - res.lastIndexOf(separator); + res = res.slice(0, lastSlashIndex) + lastSegmentLength = res.length - 1 - res.lastIndexOf(separator) } - lastSlash = i; - dots = 0; - continue; + lastSlash = i + dots = 0 + continue } else if (res.length === 2 || res.length === 1) { - res = ""; - lastSegmentLength = 0; - lastSlash = i; - dots = 0; - continue; + res = '' + lastSegmentLength = 0 + lastSlash = i + dots = 0 + continue } } if (allowAboveRoot) { - if (res.length > 0) - res += `${separator}..`; - else - res = ".."; - lastSegmentLength = 2; + if (res.length > 0) res += `${separator}..` + else res = '..' + lastSegmentLength = 2 } } else { - if (res.length > 0) - res += separator + path3.slice(lastSlash + 1, i); - else - res = path3.slice(lastSlash + 1, i); - lastSegmentLength = i - lastSlash - 1; + if (res.length > 0) res += separator + path3.slice(lastSlash + 1, i) + else res = path3.slice(lastSlash + 1, i) + lastSegmentLength = i - lastSlash - 1 } - lastSlash = i; - dots = 0; + lastSlash = i + dots = 0 } else if (code === CHAR_DOT && dots !== -1) { - ++dots; + ++dots } else { - dots = -1; + dots = -1 } } - return res; + return res } function _format(sep4, pathObject) { - const dir = pathObject.dir || pathObject.root; - const base = pathObject.base || (pathObject.name || "") + (pathObject.ext || ""); - if (!dir) - return base; - if (dir === pathObject.root) - return dir + base; - return dir + sep4 + base; + const dir = pathObject.dir || pathObject.root + const base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '') + if (!dir) return base + if (dir === pathObject.root) return dir + base + return dir + sep4 + base } var WHITESPACE_ENCODINGS = { - " ": "%09", - "\n": "%0A", - "\v": "%0B", - "\f": "%0C", - "\r": "%0D", - " ": "%20" -}; + ' ': '%09', + '\n': '%0A', + '\v': '%0B', + '\f': '%0C', + '\r': '%0D', + ' ': '%20' +} function encodeWhitespace(string) { return string.replaceAll(/[\s]/g, (c) => { - return WHITESPACE_ENCODINGS[c] ?? c; - }); + return WHITESPACE_ENCODINGS[c] ?? c + }) } // ../_util/assert.ts var DenoStdInternalError = class extends Error { constructor(message) { - super(message); - this.name = "DenoStdInternalError"; + super(message) + this.name = 'DenoStdInternalError' } -}; -function assert(expr, msg = "") { +} +function assert(expr, msg = '') { if (!expr) { - throw new DenoStdInternalError(msg); + throw new DenoStdInternalError(msg) } } // ../path/win32.ts -var sep = "\\"; -var delimiter = ";"; +var sep = '\\' +var delimiter = ';' function resolve(...pathSegments) { - let resolvedDevice = ""; - let resolvedTail = ""; - let resolvedAbsolute = false; + let resolvedDevice = '' + let resolvedTail = '' + let resolvedAbsolute = false for (let i = pathSegments.length - 1; i >= -1; i--) { - let path3; - const { Deno } = globalThis; + let path3 + const { Deno } = globalThis if (i >= 0) { - path3 = pathSegments[i]; + path3 = pathSegments[i] } else if (!resolvedDevice) { - if (typeof Deno?.cwd !== "function") { - throw new TypeError("Resolved a drive-letter-less path without a CWD."); + if (typeof Deno?.cwd !== 'function') { + throw new TypeError('Resolved a drive-letter-less path without a CWD.') } - path3 = Deno.cwd(); + path3 = Deno.cwd() } else { - if (typeof Deno?.env?.get !== "function" || typeof Deno?.cwd !== "function") { - throw new TypeError("Resolved a relative path without a CWD."); + if (typeof Deno?.env?.get !== 'function' || typeof Deno?.cwd !== 'function') { + throw new TypeError('Resolved a relative path without a CWD.') } - path3 = Deno.env.get(`=${resolvedDevice}`) || Deno.cwd(); + path3 = Deno.env.get(`=${resolvedDevice}`) || Deno.cwd() if (path3 === void 0 || path3.slice(0, 3).toLowerCase() !== `${resolvedDevice.toLowerCase()}\\`) { - path3 = `${resolvedDevice}\\`; + path3 = `${resolvedDevice}\\` } } - assertPath(path3); - const len = path3.length; - if (len === 0) - continue; - let rootEnd = 0; - let device = ""; - let isAbsolute4 = false; - const code = path3.charCodeAt(0); + assertPath(path3) + const len = path3.length + if (len === 0) continue + let rootEnd = 0 + let device = '' + let isAbsolute4 = false + const code = path3.charCodeAt(0) if (len > 1) { if (isPathSeparator(code)) { - isAbsolute4 = true; + isAbsolute4 = true if (isPathSeparator(path3.charCodeAt(1))) { - let j = 2; - let last = j; + let j = 2 + let last = j for (; j < len; ++j) { - if (isPathSeparator(path3.charCodeAt(j))) - break; + if (isPathSeparator(path3.charCodeAt(j))) break } if (j < len && j !== last) { - const firstPart = path3.slice(last, j); - last = j; + const firstPart = path3.slice(last, j) + last = j for (; j < len; ++j) { - if (!isPathSeparator(path3.charCodeAt(j))) - break; + if (!isPathSeparator(path3.charCodeAt(j))) break } if (j < len && j !== last) { - last = j; + last = j for (; j < len; ++j) { - if (isPathSeparator(path3.charCodeAt(j))) - break; + if (isPathSeparator(path3.charCodeAt(j))) break } if (j === len) { - device = `\\\\${firstPart}\\${path3.slice(last)}`; - rootEnd = j; + device = `\\\\${firstPart}\\${path3.slice(last)}` + rootEnd = j } else if (j !== last) { - device = `\\\\${firstPart}\\${path3.slice(last, j)}`; - rootEnd = j; + device = `\\\\${firstPart}\\${path3.slice(last, j)}` + rootEnd = j } } } } else { - rootEnd = 1; + rootEnd = 1 } } else if (isWindowsDeviceRoot(code)) { if (path3.charCodeAt(1) === CHAR_COLON) { - device = path3.slice(0, 2); - rootEnd = 2; + device = path3.slice(0, 2) + rootEnd = 2 if (len > 2) { if (isPathSeparator(path3.charCodeAt(2))) { - isAbsolute4 = true; - rootEnd = 3; + isAbsolute4 = true + rootEnd = 3 } } } } } else if (isPathSeparator(code)) { - rootEnd = 1; - isAbsolute4 = true; + rootEnd = 1 + isAbsolute4 = true } if (device.length > 0 && resolvedDevice.length > 0 && device.toLowerCase() !== resolvedDevice.toLowerCase()) { - continue; + continue } if (resolvedDevice.length === 0 && device.length > 0) { - resolvedDevice = device; + resolvedDevice = device } if (!resolvedAbsolute) { - resolvedTail = `${path3.slice(rootEnd)}\\${resolvedTail}`; - resolvedAbsolute = isAbsolute4; + resolvedTail = `${path3.slice(rootEnd)}\\${resolvedTail}` + resolvedAbsolute = isAbsolute4 } - if (resolvedAbsolute && resolvedDevice.length > 0) - break; + if (resolvedAbsolute && resolvedDevice.length > 0) break } - resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, "\\", isPathSeparator); - return resolvedDevice + (resolvedAbsolute ? "\\" : "") + resolvedTail || "."; + resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\', isPathSeparator) + return resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail || '.' } function normalize(path3) { - assertPath(path3); - const len = path3.length; - if (len === 0) - return "."; - let rootEnd = 0; - let device; - let isAbsolute4 = false; - const code = path3.charCodeAt(0); + assertPath(path3) + const len = path3.length + if (len === 0) return '.' + let rootEnd = 0 + let device + let isAbsolute4 = false + const code = path3.charCodeAt(0) if (len > 1) { if (isPathSeparator(code)) { - isAbsolute4 = true; + isAbsolute4 = true if (isPathSeparator(path3.charCodeAt(1))) { - let j = 2; - let last = j; + let j = 2 + let last = j for (; j < len; ++j) { - if (isPathSeparator(path3.charCodeAt(j))) - break; + if (isPathSeparator(path3.charCodeAt(j))) break } if (j < len && j !== last) { - const firstPart = path3.slice(last, j); - last = j; + const firstPart = path3.slice(last, j) + last = j for (; j < len; ++j) { - if (!isPathSeparator(path3.charCodeAt(j))) - break; + if (!isPathSeparator(path3.charCodeAt(j))) break } if (j < len && j !== last) { - last = j; + last = j for (; j < len; ++j) { - if (isPathSeparator(path3.charCodeAt(j))) - break; + if (isPathSeparator(path3.charCodeAt(j))) break } if (j === len) { - return `\\\\${firstPart}\\${path3.slice(last)}\\`; + return `\\\\${firstPart}\\${path3.slice(last)}\\` } else if (j !== last) { - device = `\\\\${firstPart}\\${path3.slice(last, j)}`; - rootEnd = j; + device = `\\\\${firstPart}\\${path3.slice(last, j)}` + rootEnd = j } } } } else { - rootEnd = 1; + rootEnd = 1 } } else if (isWindowsDeviceRoot(code)) { if (path3.charCodeAt(1) === CHAR_COLON) { - device = path3.slice(0, 2); - rootEnd = 2; + device = path3.slice(0, 2) + rootEnd = 2 if (len > 2) { if (isPathSeparator(path3.charCodeAt(2))) { - isAbsolute4 = true; - rootEnd = 3; + isAbsolute4 = true + rootEnd = 3 } } } } } else if (isPathSeparator(code)) { - return "\\"; + return '\\' } - let tail; + let tail if (rootEnd < len) { - tail = normalizeString(path3.slice(rootEnd), !isAbsolute4, "\\", isPathSeparator); + tail = normalizeString(path3.slice(rootEnd), !isAbsolute4, '\\', isPathSeparator) } else { - tail = ""; + tail = '' } - if (tail.length === 0 && !isAbsolute4) - tail = "."; + if (tail.length === 0 && !isAbsolute4) tail = '.' if (tail.length > 0 && isPathSeparator(path3.charCodeAt(len - 1))) { - tail += "\\"; + tail += '\\' } if (device === void 0) { if (isAbsolute4) { - if (tail.length > 0) - return `\\${tail}`; - else - return "\\"; + if (tail.length > 0) return `\\${tail}` + else return '\\' } else if (tail.length > 0) { - return tail; + return tail } else { - return ""; + return '' } } else if (isAbsolute4) { - if (tail.length > 0) - return `${device}\\${tail}`; - else - return `${device}\\`; + if (tail.length > 0) return `${device}\\${tail}` + else return `${device}\\` } else if (tail.length > 0) { - return device + tail; + return device + tail } else { - return device; + return device } } function isAbsolute(path3) { - assertPath(path3); - const len = path3.length; - if (len === 0) - return false; - const code = path3.charCodeAt(0); + assertPath(path3) + const len = path3.length + if (len === 0) return false + const code = path3.charCodeAt(0) if (isPathSeparator(code)) { - return true; + return true } else if (isWindowsDeviceRoot(code)) { if (len > 2 && path3.charCodeAt(1) === CHAR_COLON) { - if (isPathSeparator(path3.charCodeAt(2))) - return true; + if (isPathSeparator(path3.charCodeAt(2))) return true } } - return false; + return false } function join(...paths) { - const pathsCount = paths.length; - if (pathsCount === 0) - return "."; - let joined; - let firstPart = null; + const pathsCount = paths.length + if (pathsCount === 0) return '.' + let joined + let firstPart = null for (let i = 0; i < pathsCount; ++i) { - const path3 = paths[i]; - assertPath(path3); + const path3 = paths[i] + assertPath(path3) if (path3.length > 0) { - if (joined === void 0) - joined = firstPart = path3; - else - joined += `\\${path3}`; + if (joined === void 0) joined = firstPart = path3 + else joined += `\\${path3}` } } - if (joined === void 0) - return "."; - let needsReplace = true; - let slashCount = 0; - assert(firstPart != null); + if (joined === void 0) return '.' + let needsReplace = true + let slashCount = 0 + assert(firstPart != null) if (isPathSeparator(firstPart.charCodeAt(0))) { - ++slashCount; - const firstLen = firstPart.length; + ++slashCount + const firstLen = firstPart.length if (firstLen > 1) { if (isPathSeparator(firstPart.charCodeAt(1))) { - ++slashCount; + ++slashCount if (firstLen > 2) { - if (isPathSeparator(firstPart.charCodeAt(2))) - ++slashCount; + if (isPathSeparator(firstPart.charCodeAt(2))) ++slashCount else { - needsReplace = false; + needsReplace = false } } } @@ -439,437 +424,411 @@ function join(...paths) { } if (needsReplace) { for (; slashCount < joined.length; ++slashCount) { - if (!isPathSeparator(joined.charCodeAt(slashCount))) - break; + if (!isPathSeparator(joined.charCodeAt(slashCount))) break } - if (slashCount >= 2) - joined = `\\${joined.slice(slashCount)}`; + if (slashCount >= 2) joined = `\\${joined.slice(slashCount)}` } - return normalize(joined); + return normalize(joined) } function relative(from, to) { - assertPath(from); - assertPath(to); - if (from === to) - return ""; - const fromOrig = resolve(from); - const toOrig = resolve(to); - if (fromOrig === toOrig) - return ""; - from = fromOrig.toLowerCase(); - to = toOrig.toLowerCase(); - if (from === to) - return ""; - let fromStart = 0; - let fromEnd = from.length; + assertPath(from) + assertPath(to) + if (from === to) return '' + const fromOrig = resolve(from) + const toOrig = resolve(to) + if (fromOrig === toOrig) return '' + from = fromOrig.toLowerCase() + to = toOrig.toLowerCase() + if (from === to) return '' + let fromStart = 0 + let fromEnd = from.length for (; fromStart < fromEnd; ++fromStart) { - if (from.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH) - break; + if (from.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH) break } for (; fromEnd - 1 > fromStart; --fromEnd) { - if (from.charCodeAt(fromEnd - 1) !== CHAR_BACKWARD_SLASH) - break; + if (from.charCodeAt(fromEnd - 1) !== CHAR_BACKWARD_SLASH) break } - const fromLen = fromEnd - fromStart; - let toStart = 0; - let toEnd = to.length; + const fromLen = fromEnd - fromStart + let toStart = 0 + let toEnd = to.length for (; toStart < toEnd; ++toStart) { - if (to.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH) - break; + if (to.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH) break } for (; toEnd - 1 > toStart; --toEnd) { - if (to.charCodeAt(toEnd - 1) !== CHAR_BACKWARD_SLASH) - break; + if (to.charCodeAt(toEnd - 1) !== CHAR_BACKWARD_SLASH) break } - const toLen = toEnd - toStart; - const length = fromLen < toLen ? fromLen : toLen; - let lastCommonSep = -1; - let i = 0; + 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 (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) { - return toOrig.slice(toStart + i + 1); + return toOrig.slice(toStart + i + 1) } else if (i === 2) { - return toOrig.slice(toStart + i); + return toOrig.slice(toStart + i) } } if (fromLen > length) { if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) { - lastCommonSep = i; + lastCommonSep = i } else if (i === 2) { - lastCommonSep = 3; + lastCommonSep = 3 } } - break; + break } - const fromCode = from.charCodeAt(fromStart + i); - const toCode = to.charCodeAt(toStart + i); - if (fromCode !== toCode) - break; - else if (fromCode === CHAR_BACKWARD_SLASH) - lastCommonSep = i; + const fromCode = from.charCodeAt(fromStart + i) + const toCode = to.charCodeAt(toStart + i) + if (fromCode !== toCode) break + else if (fromCode === CHAR_BACKWARD_SLASH) lastCommonSep = i } if (i !== length && lastCommonSep === -1) { - return toOrig; + return toOrig } - let out = ""; - if (lastCommonSep === -1) - lastCommonSep = 0; + let out = '' + if (lastCommonSep === -1) lastCommonSep = 0 for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) { - if (out.length === 0) - out += ".."; - else - out += "\\.."; + if (out.length === 0) out += '..' + else out += '\\..' } } if (out.length > 0) { - return out + toOrig.slice(toStart + lastCommonSep, toEnd); + return out + toOrig.slice(toStart + lastCommonSep, toEnd) } else { - toStart += lastCommonSep; - if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) - ++toStart; - return toOrig.slice(toStart, toEnd); + toStart += lastCommonSep + if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) ++toStart + return toOrig.slice(toStart, toEnd) } } function toNamespacedPath(path3) { - if (typeof path3 !== "string") - return path3; - if (path3.length === 0) - return ""; - const resolvedPath = resolve(path3); + if (typeof path3 !== 'string') return path3 + if (path3.length === 0) return '' + const resolvedPath = resolve(path3) if (resolvedPath.length >= 3) { if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) { if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) { - const code = resolvedPath.charCodeAt(2); + const code = resolvedPath.charCodeAt(2) if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) { - return `\\\\?\\UNC\\${resolvedPath.slice(2)}`; + return `\\\\?\\UNC\\${resolvedPath.slice(2)}` } } } else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0))) { if (resolvedPath.charCodeAt(1) === CHAR_COLON && resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) { - return `\\\\?\\${resolvedPath}`; + return `\\\\?\\${resolvedPath}` } } } - return path3; + return path3 } function dirname(path3) { - assertPath(path3); - const len = path3.length; - if (len === 0) - return "."; - let rootEnd = -1; - let end = -1; - let matchedSlash = true; - let offset = 0; - const code = path3.charCodeAt(0); + assertPath(path3) + const len = path3.length + if (len === 0) return '.' + let rootEnd = -1 + let end = -1 + let matchedSlash = true + let offset = 0 + const code = path3.charCodeAt(0) if (len > 1) { if (isPathSeparator(code)) { - rootEnd = offset = 1; + rootEnd = offset = 1 if (isPathSeparator(path3.charCodeAt(1))) { - let j = 2; - let last = j; + let j = 2 + let last = j for (; j < len; ++j) { - if (isPathSeparator(path3.charCodeAt(j))) - break; + if (isPathSeparator(path3.charCodeAt(j))) break } if (j < len && j !== last) { - last = j; + last = j for (; j < len; ++j) { - if (!isPathSeparator(path3.charCodeAt(j))) - break; + if (!isPathSeparator(path3.charCodeAt(j))) break } if (j < len && j !== last) { - last = j; + last = j for (; j < len; ++j) { - if (isPathSeparator(path3.charCodeAt(j))) - break; + if (isPathSeparator(path3.charCodeAt(j))) break } if (j === len) { - return path3; + return path3 } if (j !== last) { - rootEnd = offset = j + 1; + rootEnd = offset = j + 1 } } } } } else if (isWindowsDeviceRoot(code)) { if (path3.charCodeAt(1) === CHAR_COLON) { - rootEnd = offset = 2; + rootEnd = offset = 2 if (len > 2) { - if (isPathSeparator(path3.charCodeAt(2))) - rootEnd = offset = 3; + if (isPathSeparator(path3.charCodeAt(2))) rootEnd = offset = 3 } } } } else if (isPathSeparator(code)) { - return path3; + return path3 } for (let i = len - 1; i >= offset; --i) { if (isPathSeparator(path3.charCodeAt(i))) { if (!matchedSlash) { - end = i; - break; + end = i + break } } else { - matchedSlash = false; + matchedSlash = false } } if (end === -1) { - if (rootEnd === -1) - return "."; - else - end = rootEnd; + if (rootEnd === -1) return '.' + else end = rootEnd } - return path3.slice(0, end); + return path3.slice(0, end) } -function basename(path3, ext = "") { - if (ext !== void 0 && typeof ext !== "string") { - throw new TypeError('"ext" argument must be a string'); - } - assertPath(path3); - let start = 0; - let end = -1; - let matchedSlash = true; - let i; +function basename(path3, ext = '') { + if (ext !== void 0 && typeof ext !== 'string') { + throw new TypeError('"ext" argument must be a string') + } + assertPath(path3) + let start = 0 + let end = -1 + let matchedSlash = true + let i if (path3.length >= 2) { - const drive = path3.charCodeAt(0); + const drive = path3.charCodeAt(0) if (isWindowsDeviceRoot(drive)) { - if (path3.charCodeAt(1) === CHAR_COLON) - start = 2; + if (path3.charCodeAt(1) === CHAR_COLON) start = 2 } } if (ext !== void 0 && ext.length > 0 && ext.length <= path3.length) { - if (ext.length === path3.length && ext === path3) - return ""; - let extIdx = ext.length - 1; - let firstNonSlashEnd = -1; + if (ext.length === path3.length && ext === path3) return '' + let extIdx = ext.length - 1 + let firstNonSlashEnd = -1 for (i = path3.length - 1; i >= start; --i) { - const code = path3.charCodeAt(i); + const code = path3.charCodeAt(i) if (isPathSeparator(code)) { if (!matchedSlash) { - start = i + 1; - break; + start = i + 1 + break } } else { if (firstNonSlashEnd === -1) { - matchedSlash = false; - firstNonSlashEnd = i + 1; + matchedSlash = false + firstNonSlashEnd = i + 1 } if (extIdx >= 0) { if (code === ext.charCodeAt(extIdx)) { if (--extIdx === -1) { - end = i; + end = i } } else { - extIdx = -1; - end = firstNonSlashEnd; + extIdx = -1 + end = firstNonSlashEnd } } } } - if (start === end) - end = firstNonSlashEnd; - else if (end === -1) - end = path3.length; - return path3.slice(start, end); + if (start === end) end = firstNonSlashEnd + else if (end === -1) end = path3.length + return path3.slice(start, end) } else { for (i = path3.length - 1; i >= start; --i) { if (isPathSeparator(path3.charCodeAt(i))) { if (!matchedSlash) { - start = i + 1; - break; + start = i + 1 + break } } else if (end === -1) { - matchedSlash = false; - end = i + 1; + matchedSlash = false + end = i + 1 } } - if (end === -1) - return ""; - return path3.slice(start, end); + if (end === -1) return '' + return path3.slice(start, end) } } function extname(path3) { - assertPath(path3); - let start = 0; - let startDot = -1; - let startPart = 0; - let end = -1; - let matchedSlash = true; - let preDotState = 0; + assertPath(path3) + let start = 0 + let startDot = -1 + let startPart = 0 + let end = -1 + let matchedSlash = true + let preDotState = 0 if (path3.length >= 2 && path3.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path3.charCodeAt(0))) { - start = startPart = 2; + start = startPart = 2 } for (let i = path3.length - 1; i >= start; --i) { - const code = path3.charCodeAt(i); + const code = path3.charCodeAt(i) if (isPathSeparator(code)) { if (!matchedSlash) { - startPart = i + 1; - break; + startPart = i + 1 + break } - continue; + continue } if (end === -1) { - matchedSlash = false; - end = i + 1; + matchedSlash = false + end = i + 1 } if (code === CHAR_DOT) { - if (startDot === -1) - startDot = i; - else if (preDotState !== 1) - preDotState = 1; + if (startDot === -1) startDot = i + else if (preDotState !== 1) preDotState = 1 } else if (startDot !== -1) { - preDotState = -1; + preDotState = -1 } } - if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { - return ""; + if ( + startDot === -1 || + end === -1 || + preDotState === 0 || + (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) + ) { + return '' } - return path3.slice(startDot, end); + return path3.slice(startDot, end) } function format(pathObject) { - if (pathObject === null || typeof pathObject !== "object") { - throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`); + if (pathObject === null || typeof pathObject !== 'object') { + throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`) } - return _format("\\", pathObject); + return _format('\\', pathObject) } function parse(path3) { - assertPath(path3); - const ret = { root: "", dir: "", base: "", ext: "", name: "" }; - const len = path3.length; - if (len === 0) - return ret; - let rootEnd = 0; - let code = path3.charCodeAt(0); + assertPath(path3) + const ret = { root: '', dir: '', base: '', ext: '', name: '' } + const len = path3.length + if (len === 0) return ret + let rootEnd = 0 + let code = path3.charCodeAt(0) if (len > 1) { if (isPathSeparator(code)) { - rootEnd = 1; + rootEnd = 1 if (isPathSeparator(path3.charCodeAt(1))) { - let j = 2; - let last = j; + let j = 2 + let last = j for (; j < len; ++j) { - if (isPathSeparator(path3.charCodeAt(j))) - break; + if (isPathSeparator(path3.charCodeAt(j))) break } if (j < len && j !== last) { - last = j; + last = j for (; j < len; ++j) { - if (!isPathSeparator(path3.charCodeAt(j))) - break; + if (!isPathSeparator(path3.charCodeAt(j))) break } if (j < len && j !== last) { - last = j; + last = j for (; j < len; ++j) { - if (isPathSeparator(path3.charCodeAt(j))) - break; + if (isPathSeparator(path3.charCodeAt(j))) break } if (j === len) { - rootEnd = j; + rootEnd = j } else if (j !== last) { - rootEnd = j + 1; + rootEnd = j + 1 } } } } } else if (isWindowsDeviceRoot(code)) { if (path3.charCodeAt(1) === CHAR_COLON) { - rootEnd = 2; + rootEnd = 2 if (len > 2) { if (isPathSeparator(path3.charCodeAt(2))) { if (len === 3) { - ret.root = ret.dir = path3; - return ret; + ret.root = ret.dir = path3 + return ret } - rootEnd = 3; + rootEnd = 3 } } else { - ret.root = ret.dir = path3; - return ret; + ret.root = ret.dir = path3 + return ret } } } } else if (isPathSeparator(code)) { - ret.root = ret.dir = path3; - return ret; - } - if (rootEnd > 0) - ret.root = path3.slice(0, rootEnd); - let startDot = -1; - let startPart = rootEnd; - let end = -1; - let matchedSlash = true; - let i = path3.length - 1; - let preDotState = 0; + ret.root = ret.dir = path3 + return ret + } + if (rootEnd > 0) ret.root = path3.slice(0, rootEnd) + let startDot = -1 + let startPart = rootEnd + let end = -1 + let matchedSlash = true + let i = path3.length - 1 + let preDotState = 0 for (; i >= rootEnd; --i) { - code = path3.charCodeAt(i); + code = path3.charCodeAt(i) if (isPathSeparator(code)) { if (!matchedSlash) { - startPart = i + 1; - break; + startPart = i + 1 + break } - continue; + continue } if (end === -1) { - matchedSlash = false; - end = i + 1; + matchedSlash = false + end = i + 1 } if (code === CHAR_DOT) { - if (startDot === -1) - startDot = i; - else if (preDotState !== 1) - preDotState = 1; + if (startDot === -1) startDot = i + else if (preDotState !== 1) preDotState = 1 } else if (startDot !== -1) { - preDotState = -1; + preDotState = -1 } } - if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + if ( + startDot === -1 || + end === -1 || + preDotState === 0 || + (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) + ) { if (end !== -1) { - ret.base = ret.name = path3.slice(startPart, end); + ret.base = ret.name = path3.slice(startPart, end) } } else { - ret.name = path3.slice(startPart, startDot); - ret.base = path3.slice(startPart, end); - ret.ext = path3.slice(startDot, end); + ret.name = path3.slice(startPart, startDot) + ret.base = path3.slice(startPart, end) + ret.ext = path3.slice(startDot, end) } if (startPart > 0 && startPart !== rootEnd) { - ret.dir = path3.slice(0, startPart - 1); - } else - ret.dir = ret.root; - return ret; + ret.dir = path3.slice(0, startPart - 1) + } else ret.dir = ret.root + return ret } function fromFileUrl(url) { - url = url instanceof URL ? url : new URL(url); - if (url.protocol != "file:") { - throw new TypeError("Must be a file URL."); - } - let path3 = decodeURIComponent(url.pathname.replace(/\//g, "\\").replace(/%(?![0-9A-Fa-f]{2})/g, "%25")).replace(/^\\*([A-Za-z]:)(\\|$)/, "$1\\"); - if (url.hostname != "") { - path3 = `\\\\${url.hostname}${path3}`; - } - return path3; + url = url instanceof URL ? url : new URL(url) + if (url.protocol != 'file:') { + throw new TypeError('Must be a file URL.') + } + let path3 = decodeURIComponent(url.pathname.replace(/\//g, '\\').replace(/%(?![0-9A-Fa-f]{2})/g, '%25')).replace( + /^\\*([A-Za-z]:)(\\|$)/, + '$1\\' + ) + if (url.hostname != '') { + path3 = `\\\\${url.hostname}${path3}` + } + return path3 } function toFileUrl(path3) { if (!isAbsolute(path3)) { - throw new TypeError("Must be an absolute path."); + throw new TypeError('Must be an absolute path.') } - const [, hostname, pathname] = path3.match(/^(?:[/\\]{2}([^/\\]+)(?=[/\\](?:[^/\\]|$)))?(.*)/); - const url = new URL("file:///"); - url.pathname = encodeWhitespace(pathname.replace(/%/g, "%25")); - if (hostname != null && hostname != "localhost") { - url.hostname = hostname; + const [, hostname, pathname] = path3.match(/^(?:[/\\]{2}([^/\\]+)(?=[/\\](?:[^/\\]|$)))?(.*)/) + const url = new URL('file:///') + url.pathname = encodeWhitespace(pathname.replace(/%/g, '%25')) + if (hostname != null && hostname != 'localhost') { + url.hostname = hostname if (!url.hostname) { - throw new TypeError("Invalid hostname."); + throw new TypeError('Invalid hostname.') } } - return url; + return url } // ../path/posix.ts -var posix_exports = {}; +var posix_exports = {} __export(posix_exports, { basename: () => basename2, delimiter: () => delimiter2, @@ -886,650 +845,606 @@ __export(posix_exports, { sep: () => sep2, toFileUrl: () => toFileUrl2, toNamespacedPath: () => toNamespacedPath2 -}); -var sep2 = "/"; -var delimiter2 = ":"; +}) +var sep2 = '/' +var delimiter2 = ':' function resolve2(...pathSegments) { - let resolvedPath = ""; - let resolvedAbsolute = false; + let resolvedPath = '' + let resolvedAbsolute = false for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) { - let path3; - if (i >= 0) - path3 = pathSegments[i]; + let path3 + if (i >= 0) path3 = pathSegments[i] else { - const { Deno } = globalThis; - if (typeof Deno?.cwd !== "function") { - throw new TypeError("Resolved a relative path without a CWD."); + const { Deno } = globalThis + if (typeof Deno?.cwd !== 'function') { + throw new TypeError('Resolved a relative path without a CWD.') } - path3 = Deno.cwd(); + path3 = Deno.cwd() } - assertPath(path3); + assertPath(path3) if (path3.length === 0) { - continue; + continue } - resolvedPath = `${path3}/${resolvedPath}`; - resolvedAbsolute = path3.charCodeAt(0) === CHAR_FORWARD_SLASH; + resolvedPath = `${path3}/${resolvedPath}` + resolvedAbsolute = path3.charCodeAt(0) === CHAR_FORWARD_SLASH } - resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, "/", isPosixPathSeparator); + resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator) if (resolvedAbsolute) { - if (resolvedPath.length > 0) - return `/${resolvedPath}`; - else - return "/"; - } else if (resolvedPath.length > 0) - return resolvedPath; - else - return "."; + if (resolvedPath.length > 0) return `/${resolvedPath}` + else return '/' + } else if (resolvedPath.length > 0) return resolvedPath + else return '.' } function normalize2(path3) { - assertPath(path3); - if (path3.length === 0) - return "."; - const isAbsolute4 = path3.charCodeAt(0) === CHAR_FORWARD_SLASH; - const trailingSeparator = path3.charCodeAt(path3.length - 1) === CHAR_FORWARD_SLASH; - path3 = normalizeString(path3, !isAbsolute4, "/", isPosixPathSeparator); - if (path3.length === 0 && !isAbsolute4) - path3 = "."; - if (path3.length > 0 && trailingSeparator) - path3 += "/"; - if (isAbsolute4) - return `/${path3}`; - return path3; + assertPath(path3) + if (path3.length === 0) return '.' + const isAbsolute4 = path3.charCodeAt(0) === CHAR_FORWARD_SLASH + const trailingSeparator = path3.charCodeAt(path3.length - 1) === CHAR_FORWARD_SLASH + path3 = normalizeString(path3, !isAbsolute4, '/', isPosixPathSeparator) + if (path3.length === 0 && !isAbsolute4) path3 = '.' + if (path3.length > 0 && trailingSeparator) path3 += '/' + if (isAbsolute4) return `/${path3}` + return path3 } function isAbsolute2(path3) { - assertPath(path3); - return path3.length > 0 && path3.charCodeAt(0) === CHAR_FORWARD_SLASH; + assertPath(path3) + return path3.length > 0 && path3.charCodeAt(0) === CHAR_FORWARD_SLASH } function join2(...paths) { - if (paths.length === 0) - return "."; - let joined; + if (paths.length === 0) return '.' + let joined for (let i = 0, len = paths.length; i < len; ++i) { - const path3 = paths[i]; - assertPath(path3); + const path3 = paths[i] + assertPath(path3) if (path3.length > 0) { - if (!joined) - joined = path3; - else - joined += `/${path3}`; + if (!joined) joined = path3 + else joined += `/${path3}` } } - if (!joined) - return "."; - return normalize2(joined); + if (!joined) return '.' + return normalize2(joined) } function relative2(from, to) { - assertPath(from); - assertPath(to); - if (from === to) - return ""; - from = resolve2(from); - to = resolve2(to); - if (from === to) - return ""; - let fromStart = 1; - const fromEnd = from.length; + assertPath(from) + assertPath(to) + if (from === to) return '' + from = resolve2(from) + to = resolve2(to) + if (from === to) return '' + let fromStart = 1 + const fromEnd = from.length for (; fromStart < fromEnd; ++fromStart) { - if (from.charCodeAt(fromStart) !== CHAR_FORWARD_SLASH) - break; + if (from.charCodeAt(fromStart) !== CHAR_FORWARD_SLASH) break } - const fromLen = fromEnd - fromStart; - let toStart = 1; - const toEnd = to.length; + const fromLen = fromEnd - fromStart + let toStart = 1 + const toEnd = to.length for (; toStart < toEnd; ++toStart) { - if (to.charCodeAt(toStart) !== CHAR_FORWARD_SLASH) - break; + if (to.charCodeAt(toStart) !== CHAR_FORWARD_SLASH) break } - const toLen = toEnd - toStart; - const length = fromLen < toLen ? fromLen : toLen; - let lastCommonSep = -1; - let i = 0; + 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 (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) { - return to.slice(toStart + i + 1); + return to.slice(toStart + i + 1) } else if (i === 0) { - return to.slice(toStart + i); + return to.slice(toStart + i) } } else if (fromLen > length) { if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) { - lastCommonSep = i; + lastCommonSep = i } else if (i === 0) { - lastCommonSep = 0; + lastCommonSep = 0 } } - break; + break } - const fromCode = from.charCodeAt(fromStart + i); - const toCode = to.charCodeAt(toStart + i); - if (fromCode !== toCode) - break; - else if (fromCode === CHAR_FORWARD_SLASH) - lastCommonSep = i; - } - let out = ""; + const fromCode = from.charCodeAt(fromStart + i) + const toCode = to.charCodeAt(toStart + i) + if (fromCode !== toCode) break + else if (fromCode === CHAR_FORWARD_SLASH) lastCommonSep = i + } + let out = '' for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) { - if (out.length === 0) - out += ".."; - else - out += "/.."; + if (out.length === 0) out += '..' + else out += '/..' } } - if (out.length > 0) - return out + to.slice(toStart + lastCommonSep); + if (out.length > 0) return out + to.slice(toStart + lastCommonSep) else { - toStart += lastCommonSep; - if (to.charCodeAt(toStart) === CHAR_FORWARD_SLASH) - ++toStart; - return to.slice(toStart); + toStart += lastCommonSep + if (to.charCodeAt(toStart) === CHAR_FORWARD_SLASH) ++toStart + return to.slice(toStart) } } function toNamespacedPath2(path3) { - return path3; + return path3 } function dirname2(path3) { - assertPath(path3); - if (path3.length === 0) - return "."; - const hasRoot = path3.charCodeAt(0) === CHAR_FORWARD_SLASH; - let end = -1; - let matchedSlash = true; + assertPath(path3) + if (path3.length === 0) return '.' + const hasRoot = path3.charCodeAt(0) === CHAR_FORWARD_SLASH + let end = -1 + let matchedSlash = true for (let i = path3.length - 1; i >= 1; --i) { if (path3.charCodeAt(i) === CHAR_FORWARD_SLASH) { if (!matchedSlash) { - end = i; - break; + end = i + break } } else { - matchedSlash = false; + matchedSlash = false } } - if (end === -1) - return hasRoot ? "/" : "."; - if (hasRoot && end === 1) - return "//"; - return path3.slice(0, end); + if (end === -1) return hasRoot ? '/' : '.' + if (hasRoot && end === 1) return '//' + return path3.slice(0, end) } -function basename2(path3, ext = "") { - if (ext !== void 0 && typeof ext !== "string") { - throw new TypeError('"ext" argument must be a string'); - } - assertPath(path3); - let start = 0; - let end = -1; - let matchedSlash = true; - let i; +function basename2(path3, ext = '') { + if (ext !== void 0 && typeof ext !== 'string') { + throw new TypeError('"ext" argument must be a string') + } + assertPath(path3) + let start = 0 + let end = -1 + let matchedSlash = true + let i if (ext !== void 0 && ext.length > 0 && ext.length <= path3.length) { - if (ext.length === path3.length && ext === path3) - return ""; - let extIdx = ext.length - 1; - let firstNonSlashEnd = -1; + if (ext.length === path3.length && ext === path3) return '' + let extIdx = ext.length - 1 + let firstNonSlashEnd = -1 for (i = path3.length - 1; i >= 0; --i) { - const code = path3.charCodeAt(i); + const code = path3.charCodeAt(i) if (code === CHAR_FORWARD_SLASH) { if (!matchedSlash) { - start = i + 1; - break; + start = i + 1 + break } } else { if (firstNonSlashEnd === -1) { - matchedSlash = false; - firstNonSlashEnd = i + 1; + matchedSlash = false + firstNonSlashEnd = i + 1 } if (extIdx >= 0) { if (code === ext.charCodeAt(extIdx)) { if (--extIdx === -1) { - end = i; + end = i } } else { - extIdx = -1; - end = firstNonSlashEnd; + extIdx = -1 + end = firstNonSlashEnd } } } } - if (start === end) - end = firstNonSlashEnd; - else if (end === -1) - end = path3.length; - return path3.slice(start, end); + if (start === end) end = firstNonSlashEnd + else if (end === -1) end = path3.length + return path3.slice(start, end) } else { for (i = path3.length - 1; i >= 0; --i) { if (path3.charCodeAt(i) === CHAR_FORWARD_SLASH) { if (!matchedSlash) { - start = i + 1; - break; + start = i + 1 + break } } else if (end === -1) { - matchedSlash = false; - end = i + 1; + matchedSlash = false + end = i + 1 } } - if (end === -1) - return ""; - return path3.slice(start, end); + if (end === -1) return '' + return path3.slice(start, end) } } function extname2(path3) { - assertPath(path3); - let startDot = -1; - let startPart = 0; - let end = -1; - let matchedSlash = true; - let preDotState = 0; + assertPath(path3) + let startDot = -1 + let startPart = 0 + let end = -1 + let matchedSlash = true + let preDotState = 0 for (let i = path3.length - 1; i >= 0; --i) { - const code = path3.charCodeAt(i); + const code = path3.charCodeAt(i) if (code === CHAR_FORWARD_SLASH) { if (!matchedSlash) { - startPart = i + 1; - break; + startPart = i + 1 + break } - continue; + continue } if (end === -1) { - matchedSlash = false; - end = i + 1; + matchedSlash = false + end = i + 1 } if (code === CHAR_DOT) { - if (startDot === -1) - startDot = i; - else if (preDotState !== 1) - preDotState = 1; + if (startDot === -1) startDot = i + else if (preDotState !== 1) preDotState = 1 } else if (startDot !== -1) { - preDotState = -1; + preDotState = -1 } } - if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { - return ""; + if ( + startDot === -1 || + end === -1 || + preDotState === 0 || + (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) + ) { + return '' } - return path3.slice(startDot, end); + return path3.slice(startDot, end) } function format2(pathObject) { - if (pathObject === null || typeof pathObject !== "object") { - throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`); + if (pathObject === null || typeof pathObject !== 'object') { + throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`) } - return _format("/", pathObject); + return _format('/', pathObject) } function parse2(path3) { - assertPath(path3); - const ret = { root: "", dir: "", base: "", ext: "", name: "" }; - if (path3.length === 0) - return ret; - const isAbsolute4 = path3.charCodeAt(0) === CHAR_FORWARD_SLASH; - let start; + assertPath(path3) + const ret = { root: '', dir: '', base: '', ext: '', name: '' } + if (path3.length === 0) return ret + const isAbsolute4 = path3.charCodeAt(0) === CHAR_FORWARD_SLASH + let start if (isAbsolute4) { - ret.root = "/"; - start = 1; + ret.root = '/' + start = 1 } else { - start = 0; - } - let startDot = -1; - let startPart = 0; - let end = -1; - let matchedSlash = true; - let i = path3.length - 1; - let preDotState = 0; + start = 0 + } + let startDot = -1 + let startPart = 0 + let end = -1 + let matchedSlash = true + let i = path3.length - 1 + let preDotState = 0 for (; i >= start; --i) { - const code = path3.charCodeAt(i); + const code = path3.charCodeAt(i) if (code === CHAR_FORWARD_SLASH) { if (!matchedSlash) { - startPart = i + 1; - break; + startPart = i + 1 + break } - continue; + continue } if (end === -1) { - matchedSlash = false; - end = i + 1; + matchedSlash = false + end = i + 1 } if (code === CHAR_DOT) { - if (startDot === -1) - startDot = i; - else if (preDotState !== 1) - preDotState = 1; + if (startDot === -1) startDot = i + else if (preDotState !== 1) preDotState = 1 } else if (startDot !== -1) { - preDotState = -1; + preDotState = -1 } } - if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + if ( + startDot === -1 || + end === -1 || + preDotState === 0 || + (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) + ) { if (end !== -1) { if (startPart === 0 && isAbsolute4) { - ret.base = ret.name = path3.slice(1, end); + ret.base = ret.name = path3.slice(1, end) } else { - ret.base = ret.name = path3.slice(startPart, end); + ret.base = ret.name = path3.slice(startPart, end) } } } else { if (startPart === 0 && isAbsolute4) { - ret.name = path3.slice(1, startDot); - ret.base = path3.slice(1, end); + ret.name = path3.slice(1, startDot) + ret.base = path3.slice(1, end) } else { - ret.name = path3.slice(startPart, startDot); - ret.base = path3.slice(startPart, end); + ret.name = path3.slice(startPart, startDot) + ret.base = path3.slice(startPart, end) } - ret.ext = path3.slice(startDot, end); + ret.ext = path3.slice(startDot, end) } - if (startPart > 0) - ret.dir = path3.slice(0, startPart - 1); - else if (isAbsolute4) - ret.dir = "/"; - return ret; + if (startPart > 0) ret.dir = path3.slice(0, startPart - 1) + else if (isAbsolute4) ret.dir = '/' + return ret } function fromFileUrl2(url) { - url = url instanceof URL ? url : new URL(url); - if (url.protocol != "file:") { - throw new TypeError("Must be a file URL."); + url = url instanceof URL ? url : new URL(url) + if (url.protocol != 'file:') { + throw new TypeError('Must be a file URL.') } - return decodeURIComponent(url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25")); + return decodeURIComponent(url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, '%25')) } function toFileUrl2(path3) { if (!isAbsolute2(path3)) { - throw new TypeError("Must be an absolute path."); + throw new TypeError('Must be an absolute path.') } - const url = new URL("file:///"); - url.pathname = encodeWhitespace(path3.replace(/%/g, "%25").replace(/\\/g, "%5C")); - return url; + const url = new URL('file:///') + url.pathname = encodeWhitespace(path3.replace(/%/g, '%25').replace(/\\/g, '%5C')) + return url } // ../path/separator.ts -var SEP = isWindows ? "\\" : "/"; -var SEP_PATTERN = isWindows ? /[\\/]+/ : /\/+/; +var SEP = isWindows ? '\\' : '/' +var SEP_PATTERN = isWindows ? /[\\/]+/ : /\/+/ // ../path/common.ts function common(paths, sep4 = SEP) { - const [first = "", ...remaining] = paths; - if (first === "" || remaining.length === 0) { - return first.substring(0, first.lastIndexOf(sep4) + 1); + const [first = '', ...remaining] = paths + if (first === '' || remaining.length === 0) { + return first.substring(0, first.lastIndexOf(sep4) + 1) } - const parts = first.split(sep4); - let endOfPrefix = parts.length; + const parts = first.split(sep4) + let endOfPrefix = parts.length for (const path3 of remaining) { - const compare = path3.split(sep4); + const compare = path3.split(sep4) for (let i = 0; i < endOfPrefix; i++) { if (compare[i] !== parts[i]) { - endOfPrefix = i; + endOfPrefix = i } } if (endOfPrefix === 0) { - return ""; + return '' } } - const prefix = parts.slice(0, endOfPrefix).join(sep4); - return prefix.endsWith(sep4) ? prefix : `${prefix}${sep4}`; + const prefix = parts.slice(0, endOfPrefix).join(sep4) + return prefix.endsWith(sep4) ? prefix : `${prefix}${sep4}` } // ../path/glob.ts -var path = isWindows ? win32_exports : posix_exports; -var { join: join3, normalize: normalize3 } = path; -var regExpEscapeChars = ["!", "$", "(", ")", "*", "+", ".", "=", "?", "[", "\\", "^", "{", "|"]; -var rangeEscapeChars = ["-", "\\", "]"]; -function globToRegExp(glob, { - extended = true, - globstar: globstarOption = true, - os = osType, - caseInsensitive = false -} = {}) { - if (glob == "") { - return /(?!)/; - } - const sep4 = os == "windows" ? "(?:\\\\|/)+" : "/+"; - const sepMaybe = os == "windows" ? "(?:\\\\|/)*" : "/*"; - const seps = os == "windows" ? ["\\", "/"] : ["/"]; - const globstar = os == "windows" ? "(?:[^\\\\/]*(?:\\\\|/|$)+)*" : "(?:[^/]*(?:/|$)+)*"; - const wildcard = os == "windows" ? "[^\\\\/]*" : "[^/]*"; - const escapePrefix = os == "windows" ? "`" : "\\"; - let newLength = glob.length; - for (; newLength > 1 && seps.includes(glob[newLength - 1]); newLength--) - ; - glob = glob.slice(0, newLength); - let regExpString = ""; +var path = isWindows ? win32_exports : posix_exports +var { join: join3, normalize: normalize3 } = path +var regExpEscapeChars = ['!', '$', '(', ')', '*', '+', '.', '=', '?', '[', '\\', '^', '{', '|'] +var rangeEscapeChars = ['-', '\\', ']'] +function globToRegExp( + glob, + { extended = true, globstar: globstarOption = true, os = osType, caseInsensitive = false } = {} +) { + if (glob == '') { + return /(?!)/ + } + const sep4 = os == 'windows' ? '(?:\\\\|/)+' : '/+' + const sepMaybe = os == 'windows' ? '(?:\\\\|/)*' : '/*' + const seps = os == 'windows' ? ['\\', '/'] : ['/'] + const globstar = os == 'windows' ? '(?:[^\\\\/]*(?:\\\\|/|$)+)*' : '(?:[^/]*(?:/|$)+)*' + const wildcard = os == 'windows' ? '[^\\\\/]*' : '[^/]*' + const escapePrefix = os == 'windows' ? '`' : '\\' + let newLength = glob.length + for (; newLength > 1 && seps.includes(glob[newLength - 1]); newLength--); + glob = glob.slice(0, newLength) + let regExpString = '' for (let j = 0; j < glob.length; ) { - let segment = ""; - const groupStack = []; - let inRange = false; - let inEscape = false; - let endsWithSep = false; - let i = j; + let segment = '' + const groupStack = [] + let inRange = false + let inEscape = false + let endsWithSep = false + let i = j for (; i < glob.length && !seps.includes(glob[i]); i++) { if (inEscape) { - inEscape = false; - const escapeChars = inRange ? rangeEscapeChars : regExpEscapeChars; - segment += escapeChars.includes(glob[i]) ? `\\${glob[i]}` : glob[i]; - continue; + inEscape = false + const escapeChars = inRange ? rangeEscapeChars : regExpEscapeChars + segment += escapeChars.includes(glob[i]) ? `\\${glob[i]}` : glob[i] + continue } if (glob[i] == escapePrefix) { - inEscape = true; - continue; + inEscape = true + continue } - if (glob[i] == "[") { + if (glob[i] == '[') { if (!inRange) { - inRange = true; - segment += "["; - if (glob[i + 1] == "!") { - i++; - segment += "^"; - } else if (glob[i + 1] == "^") { - i++; - segment += "\\^"; + inRange = true + segment += '[' + if (glob[i + 1] == '!') { + i++ + segment += '^' + } else if (glob[i + 1] == '^') { + i++ + segment += '\\^' } - continue; - } else if (glob[i + 1] == ":") { - let k = i + 1; - let value = ""; - while (glob[k + 1] != null && glob[k + 1] != ":") { - value += glob[k + 1]; - k++; + continue + } else if (glob[i + 1] == ':') { + let k = i + 1 + let value = '' + while (glob[k + 1] != null && glob[k + 1] != ':') { + value += glob[k + 1] + k++ } - if (glob[k + 1] == ":" && glob[k + 2] == "]") { - i = k + 2; - if (value == "alnum") - segment += "\\dA-Za-z"; - else if (value == "alpha") - segment += "A-Za-z"; - else if (value == "ascii") - segment += "\0-\x7F"; - else if (value == "blank") - segment += " "; - else if (value == "cntrl") - segment += "\0-\x7F"; - else if (value == "digit") - segment += "\\d"; - else if (value == "graph") - segment += "!-~"; - else if (value == "lower") - segment += "a-z"; - else if (value == "print") - segment += " -~"; - else if (value == "punct") { - segment += `!"#$%&'()*+,\\-./:;<=>?@[\\\\\\]^_\u2018{|}~`; - } else if (value == "space") - segment += "\\s\v"; - else if (value == "upper") - segment += "A-Z"; - else if (value == "word") - segment += "\\w"; - else if (value == "xdigit") - segment += "\\dA-Fa-f"; - continue; + if (glob[k + 1] == ':' && glob[k + 2] == ']') { + i = k + 2 + if (value == 'alnum') segment += '\\dA-Za-z' + else if (value == 'alpha') segment += 'A-Za-z' + else if (value == 'ascii') segment += '\0-\x7F' + else if (value == 'blank') segment += ' ' + else if (value == 'cntrl') segment += '\0-\x7F' + else if (value == 'digit') segment += '\\d' + else if (value == 'graph') segment += '!-~' + else if (value == 'lower') segment += 'a-z' + else if (value == 'print') segment += ' -~' + else if (value == 'punct') { + segment += `!"#$%&'()*+,\\-./:;<=>?@[\\\\\\]^_\u2018{|}~` + } else if (value == 'space') segment += '\\s\v' + else if (value == 'upper') segment += 'A-Z' + else if (value == 'word') segment += '\\w' + else if (value == 'xdigit') segment += '\\dA-Fa-f' + continue } } } - if (glob[i] == "]" && inRange) { - inRange = false; - segment += "]"; - continue; + if (glob[i] == ']' && inRange) { + inRange = false + segment += ']' + continue } if (inRange) { - if (glob[i] == "\\") { - segment += `\\\\`; + if (glob[i] == '\\') { + segment += `\\\\` } else { - segment += glob[i]; + segment += glob[i] } - continue; + continue } - if (glob[i] == ")" && groupStack.length > 0 && groupStack[groupStack.length - 1] != "BRACE") { - segment += ")"; - const type = groupStack.pop(); - if (type == "!") { - segment += wildcard; - } else if (type != "@") { - segment += type; + if (glob[i] == ')' && groupStack.length > 0 && groupStack[groupStack.length - 1] != 'BRACE') { + segment += ')' + const type = groupStack.pop() + if (type == '!') { + segment += wildcard + } else if (type != '@') { + segment += type } - continue; + continue } - if (glob[i] == "|" && groupStack.length > 0 && groupStack[groupStack.length - 1] != "BRACE") { - segment += "|"; - continue; + if (glob[i] == '|' && groupStack.length > 0 && groupStack[groupStack.length - 1] != 'BRACE') { + segment += '|' + continue } - if (glob[i] == "+" && extended && glob[i + 1] == "(") { - i++; - groupStack.push("+"); - segment += "(?:"; - continue; + if (glob[i] == '+' && extended && glob[i + 1] == '(') { + i++ + groupStack.push('+') + segment += '(?:' + continue } - if (glob[i] == "@" && extended && glob[i + 1] == "(") { - i++; - groupStack.push("@"); - segment += "(?:"; - continue; + if (glob[i] == '@' && extended && glob[i + 1] == '(') { + i++ + groupStack.push('@') + segment += '(?:' + continue } - if (glob[i] == "?") { - if (extended && glob[i + 1] == "(") { - i++; - groupStack.push("?"); - segment += "(?:"; + if (glob[i] == '?') { + if (extended && glob[i + 1] == '(') { + i++ + groupStack.push('?') + segment += '(?:' } else { - segment += "."; + segment += '.' } - continue; + continue } - if (glob[i] == "!" && extended && glob[i + 1] == "(") { - i++; - groupStack.push("!"); - segment += "(?!"; - continue; + if (glob[i] == '!' && extended && glob[i + 1] == '(') { + i++ + groupStack.push('!') + segment += '(?!' + continue } - if (glob[i] == "{") { - groupStack.push("BRACE"); - segment += "(?:"; - continue; + if (glob[i] == '{') { + groupStack.push('BRACE') + segment += '(?:' + continue } - if (glob[i] == "}" && groupStack[groupStack.length - 1] == "BRACE") { - groupStack.pop(); - segment += ")"; - continue; + if (glob[i] == '}' && groupStack[groupStack.length - 1] == 'BRACE') { + groupStack.pop() + segment += ')' + continue } - if (glob[i] == "," && groupStack[groupStack.length - 1] == "BRACE") { - segment += "|"; - continue; + if (glob[i] == ',' && groupStack[groupStack.length - 1] == 'BRACE') { + segment += '|' + continue } - if (glob[i] == "*") { - if (extended && glob[i + 1] == "(") { - i++; - groupStack.push("*"); - segment += "(?:"; + if (glob[i] == '*') { + if (extended && glob[i + 1] == '(') { + i++ + groupStack.push('*') + segment += '(?:' } else { - const prevChar = glob[i - 1]; - let numStars = 1; - while (glob[i + 1] == "*") { - i++; - numStars++; + const prevChar = glob[i - 1] + let numStars = 1 + while (glob[i + 1] == '*') { + i++ + numStars++ } - const nextChar = glob[i + 1]; - if (globstarOption && numStars == 2 && [...seps, void 0].includes(prevChar) && [...seps, void 0].includes(nextChar)) { - segment += globstar; - endsWithSep = true; + const nextChar = glob[i + 1] + if ( + globstarOption && + numStars == 2 && + [...seps, void 0].includes(prevChar) && + [...seps, void 0].includes(nextChar) + ) { + segment += globstar + endsWithSep = true } else { - segment += wildcard; + segment += wildcard } } - continue; + continue } - segment += regExpEscapeChars.includes(glob[i]) ? `\\${glob[i]}` : glob[i]; + segment += regExpEscapeChars.includes(glob[i]) ? `\\${glob[i]}` : glob[i] } if (groupStack.length > 0 || inRange || inEscape) { - segment = ""; + segment = '' for (const c of glob.slice(j, i)) { - segment += regExpEscapeChars.includes(c) ? `\\${c}` : c; - endsWithSep = false; + segment += regExpEscapeChars.includes(c) ? `\\${c}` : c + endsWithSep = false } } - regExpString += segment; + regExpString += segment if (!endsWithSep) { - regExpString += i < glob.length ? sep4 : sepMaybe; - endsWithSep = true; + regExpString += i < glob.length ? sep4 : sepMaybe + endsWithSep = true } - while (seps.includes(glob[i])) - i++; + while (seps.includes(glob[i])) i++ if (!(i > j)) { - throw new Error("Assertion failure: i > j (potential infinite loop)"); + throw new Error('Assertion failure: i > j (potential infinite loop)') } - j = i; + j = i } - regExpString = `^${regExpString}$`; - return new RegExp(regExpString, caseInsensitive ? "i" : ""); + regExpString = `^${regExpString}$` + return new RegExp(regExpString, caseInsensitive ? 'i' : '') } function isGlob(str) { - const chars = { "{": "}", "(": ")", "[": "]" }; - const regex = /\\(.)|(^!|\*|\?|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/; - if (str === "") { - return false; - } - let match; - while (match = regex.exec(str)) { - if (match[2]) - return true; - let idx = match.index + match[0].length; - const open = match[1]; - const close = open ? chars[open] : null; + const chars = { '{': '}', '(': ')', '[': ']' } + const regex = /\\(.)|(^!|\*|\?|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/ + if (str === '') { + return false + } + let match + while ((match = regex.exec(str))) { + if (match[2]) return true + let idx = match.index + match[0].length + const open = match[1] + const close = open ? chars[open] : null if (open && close) { - const n = str.indexOf(close, idx); + const n = str.indexOf(close, idx) if (n !== -1) { - idx = n + 1; + idx = n + 1 } } - str = str.slice(idx); + str = str.slice(idx) } - return false; + return false } function normalizeGlob(glob, { globstar = false } = {}) { if (glob.match(/\0/g)) { - throw new Error(`Glob contains invalid characters: "${glob}"`); + throw new Error(`Glob contains invalid characters: "${glob}"`) } if (!globstar) { - return normalize3(glob); + return normalize3(glob) } - const s = SEP_PATTERN.source; - const badParentPattern = new RegExp(`(?<=(${s}|^)\\*\\*${s})\\.\\.(?=${s}|$)`, "g"); - return normalize3(glob.replace(badParentPattern, "\0")).replace(/\0/g, ".."); + const s = SEP_PATTERN.source + const badParentPattern = new RegExp(`(?<=(${s}|^)\\*\\*${s})\\.\\.(?=${s}|$)`, 'g') + return normalize3(glob.replace(badParentPattern, '\0')).replace(/\0/g, '..') } function joinGlobs(globs, { extended = false, globstar = false } = {}) { if (!globstar || globs.length == 0) { - return join3(...globs); + return join3(...globs) } - if (globs.length === 0) - return "."; - let joined; + if (globs.length === 0) return '.' + let joined for (const glob of globs) { - const path3 = glob; + const path3 = glob if (path3.length > 0) { - if (!joined) - joined = path3; - else - joined += `${SEP}${path3}`; + if (!joined) joined = path3 + else joined += `${SEP}${path3}` } } - if (!joined) - return "."; - return normalizeGlob(joined, { extended, globstar }); + if (!joined) return '.' + return normalizeGlob(joined, { extended, globstar }) } // ../path/mod.ts -var path2 = isWindows ? win32_exports : posix_exports; -var win32 = win32_exports; -var posix = posix_exports; +var path2 = isWindows ? win32_exports : posix_exports +var win32 = win32_exports +var posix = posix_exports var { basename: basename3, delimiter: delimiter3, @@ -1546,10 +1461,10 @@ var { sep: sep3, toFileUrl: toFileUrl3, toNamespacedPath: toNamespacedPath3 -} = path2; +} = path2 // path.ts -var path_default = { ...mod_exports }; +var path_default = { ...mod_exports } export { SEP, SEP_PATTERN, @@ -1576,4 +1491,4 @@ export { toFileUrl3 as toFileUrl, toNamespacedPath3 as toNamespacedPath, win32 -}; +} diff --git a/embed/polyfills/deno_std_node_querystring.js b/embed/polyfills/deno_std_node_querystring.js index a7ad0d12d..ae29836ee 100644 --- a/embed/polyfills/deno_std_node_querystring.js +++ b/embed/polyfills/deno_std_node_querystring.js @@ -1,92 +1,98 @@ +/* deno mod bundle + * entry: deno.land/std/node/querystring.ts + * version: 0.106.0 + * + * $ git clone https://github.com/denoland/deno_std + * $ cd deno_std/node + * $ esbuild querystring.ts --target=esnext --format=esm --bundle --outfile=deno_std_node_querystring.js + */ + // querystring.ts -var hexTable = new Array(256); +var hexTable = new Array(256) for (let i = 0; i < 256; ++i) { - hexTable[i] = "%" + ((i < 16 ? "0" : "") + i.toString(16)).toUpperCase(); + hexTable[i] = '%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase() } -function parse(str, sep = "&", eq = "=", { decodeURIComponent: decodeURIComponent2 = unescape, maxKeys = 1e3 } = {}) { - const entries = str.split(sep).map((entry) => entry.split(eq).map(decodeURIComponent2)); - const final = {}; - let i = 0; +function parse(str, sep = '&', eq = '=', { decodeURIComponent: decodeURIComponent2 = unescape, maxKeys = 1e3 } = {}) { + const entries = str.split(sep).map((entry) => entry.split(eq).map(decodeURIComponent2)) + const final = {} + let i = 0 while (true) { - if (Object.keys(final).length === maxKeys && !!maxKeys || !entries[i]) { - break; + if ((Object.keys(final).length === maxKeys && !!maxKeys) || !entries[i]) { + break } - const [key, val] = entries[i]; + const [key, val] = entries[i] if (final[key]) { if (Array.isArray(final[key])) { - final[key].push(val); + final[key].push(val) } else { - final[key] = [final[key], val]; + final[key] = [final[key], val] } } else { - final[key] = val; + final[key] = val } - i++; + i++ } - return final; + return final } function encodeStr(str, noEscapeTable, hexTable2) { - const len = str.length; - if (len === 0) - return ""; - let out = ""; - let lastPos = 0; + const len = str.length + if (len === 0) return '' + let out = '' + let lastPos = 0 for (let i = 0; i < len; i++) { - let c = str.charCodeAt(i); + let c = str.charCodeAt(i) if (c < 128) { - if (noEscapeTable[c] === 1) - continue; - if (lastPos < i) - out += str.slice(lastPos, i); - lastPos = i + 1; - out += hexTable2[c]; - continue; + if (noEscapeTable[c] === 1) continue + if (lastPos < i) out += str.slice(lastPos, i) + lastPos = i + 1 + out += hexTable2[c] + continue } - if (lastPos < i) - out += str.slice(lastPos, i); + if (lastPos < i) out += str.slice(lastPos, i) if (c < 2048) { - lastPos = i + 1; - out += hexTable2[192 | c >> 6] + hexTable2[128 | c & 63]; - continue; + lastPos = i + 1 + out += hexTable2[192 | (c >> 6)] + hexTable2[128 | (c & 63)] + continue } if (c < 55296 || c >= 57344) { - lastPos = i + 1; - out += hexTable2[224 | c >> 12] + hexTable2[128 | c >> 6 & 63] + hexTable2[128 | c & 63]; - continue; + lastPos = i + 1 + out += hexTable2[224 | (c >> 12)] + hexTable2[128 | ((c >> 6) & 63)] + hexTable2[128 | (c & 63)] + continue } - ++i; - if (i >= len) - throw new Deno.errors.InvalidData("invalid URI"); - const c2 = str.charCodeAt(i) & 1023; - lastPos = i + 1; - c = 65536 + ((c & 1023) << 10 | c2); - out += hexTable2[240 | c >> 18] + hexTable2[128 | c >> 12 & 63] + hexTable2[128 | c >> 6 & 63] + hexTable2[128 | c & 63]; + ++i + if (i >= len) throw new Deno.errors.InvalidData('invalid URI') + const c2 = str.charCodeAt(i) & 1023 + lastPos = i + 1 + c = 65536 + (((c & 1023) << 10) | c2) + out += + hexTable2[240 | (c >> 18)] + + hexTable2[128 | ((c >> 12) & 63)] + + hexTable2[128 | ((c >> 6) & 63)] + + hexTable2[128 | (c & 63)] } - if (lastPos === 0) - return str; - if (lastPos < len) - return out + str.slice(lastPos); - return out; + if (lastPos === 0) return str + if (lastPos < len) return out + str.slice(lastPos) + return out } -function stringify(obj, sep = "&", eq = "=", { encodeURIComponent: encodeURIComponent2 = escape } = {}) { - const final = []; +function stringify(obj, sep = '&', eq = '=', { encodeURIComponent: encodeURIComponent2 = escape } = {}) { + const final = [] for (const entry of Object.entries(obj)) { if (Array.isArray(entry[1])) { for (const val of entry[1]) { - final.push(encodeURIComponent2(entry[0]) + eq + encodeURIComponent2(val)); + final.push(encodeURIComponent2(entry[0]) + eq + encodeURIComponent2(val)) } - } else if (typeof entry[1] !== "object" && entry[1] !== void 0) { - final.push(entry.map(encodeURIComponent2).join(eq)); + } else if (typeof entry[1] !== 'object' && entry[1] !== void 0) { + final.push(entry.map(encodeURIComponent2).join(eq)) } else { - final.push(encodeURIComponent2(entry[0]) + eq); + final.push(encodeURIComponent2(entry[0]) + eq) } } - return final.join(sep); + return final.join(sep) } -var decode = parse; -var encode = stringify; -var unescape = decodeURIComponent; -var escape = encodeURIComponent; +var decode = parse +var encode = stringify +var unescape = decodeURIComponent +var escape = encodeURIComponent var querystring_default = { parse, encodeStr, @@ -96,15 +102,5 @@ var querystring_default = { encode, unescape, escape -}; -export { - decode, - querystring_default as default, - encode, - encodeStr, - escape, - hexTable, - parse, - stringify, - unescape -}; +} +export { decode, querystring_default as default, encode, encodeStr, escape, hexTable, parse, stringify, unescape } diff --git a/embed/polyfills/deno_std_node_timers.js b/embed/polyfills/deno_std_node_timers.js index 388ebc3e9..5d71a1adc 100644 --- a/embed/polyfills/deno_std_node_timers.js +++ b/embed/polyfills/deno_std_node_timers.js @@ -1,10 +1,19 @@ +/* deno mod bundle + * entry: deno.land/std/node/timers.ts + * version: 0.106.0 + * + * $ git clone https://github.com/denoland/deno_std + * $ cd deno_std/node + * $ esbuild timers.ts --target=esnext --format=esm --bundle --outfile=deno_std_node_timers.js + */ + // timers.ts -var setTimeout = globalThis.setTimeout; -var clearTimeout = globalThis.clearTimeout; -var setInterval = globalThis.setInterval; -var clearInterval = globalThis.clearInterval; -var setImmediate = (cb, ...args) => globalThis.setTimeout(cb, 0, ...args); -var clearImmediate = globalThis.clearTimeout; +var setTimeout = globalThis.setTimeout +var clearTimeout = globalThis.clearTimeout +var setInterval = globalThis.setInterval +var clearInterval = globalThis.clearInterval +var setImmediate = (cb, ...args) => globalThis.setTimeout(cb, 0, ...args) +var clearImmediate = globalThis.clearTimeout var timers_default = { setTimeout, clearTimeout, @@ -12,13 +21,5 @@ var timers_default = { clearInterval, setImmediate, clearImmediate -}; -export { - clearImmediate, - clearInterval, - clearTimeout, - timers_default as default, - setImmediate, - setInterval, - setTimeout -}; +} +export { clearImmediate, clearInterval, clearTimeout, timers_default as default, setImmediate, setInterval, setTimeout } diff --git a/embed/polyfills/deno_std_node_url.js b/embed/polyfills/deno_std_node_url.js index 887790c66..3cbb8e84a 100644 --- a/embed/polyfills/deno_std_node_url.js +++ b/embed/polyfills/deno_std_node_url.js @@ -1,24 +1,32 @@ -var __defProp = Object.defineProperty; -var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); +/* deno mod bundle + * entry: deno.land/std/node/url.ts + * version: 0.106.0 + * + * $ git clone https://github.com/denoland/deno_std + * $ cd deno_std/node + * $ esbuild url.ts --target=esnext --format=esm --bundle --outfile=deno_std_node_url.js + */ + +var __defProp = Object.defineProperty +var __markAsModule = (target) => __defProp(target, '__esModule', { value: true }) var __export = (target, all) => { - __markAsModule(target); - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; + __markAsModule(target) + for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }) +} // ../path/_constants.ts -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; -var CHAR_QUESTION_MARK = 63; +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 +var CHAR_QUESTION_MARK = 63 // ../path/mod.ts -var mod_exports = {}; +var mod_exports = {} __export(mod_exports, { SEP: () => SEP, SEP_PATTERN: () => SEP_PATTERN, @@ -44,24 +52,24 @@ __export(mod_exports, { toFileUrl: () => toFileUrl3, toNamespacedPath: () => toNamespacedPath3, win32: () => win32 -}); +}) // ../_util/os.ts var osType = (() => { - const { Deno: Deno2 } = globalThis; - if (typeof Deno2?.build?.os === "string") { - return Deno2.build.os; + const { Deno: Deno2 } = globalThis + if (typeof Deno2?.build?.os === 'string') { + return Deno2.build.os } - const { navigator } = globalThis; - if (navigator?.appVersion?.includes?.("Win") ?? false) { - return "windows"; + const { navigator } = globalThis + if (navigator?.appVersion?.includes?.('Win') ?? false) { + return 'windows' } - return "linux"; -})(); -var isWindows = osType === "windows"; + return 'linux' +})() +var isWindows = osType === 'windows' // ../path/win32.ts -var win32_exports = {}; +var win32_exports = {} __export(win32_exports, { basename: () => basename, delimiter: () => delimiter, @@ -78,360 +86,337 @@ __export(win32_exports, { sep: () => sep, toFileUrl: () => toFileUrl, toNamespacedPath: () => toNamespacedPath -}); +}) // ../path/_util.ts function assertPath(path4) { - if (typeof path4 !== "string") { - throw new TypeError(`Path must be a string. Received ${JSON.stringify(path4)}`); + if (typeof path4 !== 'string') { + throw new TypeError(`Path must be a string. Received ${JSON.stringify(path4)}`) } } function isPosixPathSeparator(code) { - return code === CHAR_FORWARD_SLASH; + return code === CHAR_FORWARD_SLASH } function isPathSeparator(code) { - return isPosixPathSeparator(code) || code === CHAR_BACKWARD_SLASH; + return isPosixPathSeparator(code) || code === CHAR_BACKWARD_SLASH } function isWindowsDeviceRoot(code) { - return code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z || code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z; + return ( + (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z) || (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) + ) } function normalizeString(path4, allowAboveRoot, separator, isPathSeparator2) { - let res = ""; - let lastSegmentLength = 0; - let lastSlash = -1; - let dots = 0; - let code; + let res = '' + let lastSegmentLength = 0 + let lastSlash = -1 + let dots = 0 + let code for (let i = 0, len = path4.length; i <= len; ++i) { - if (i < len) - code = path4.charCodeAt(i); - else if (isPathSeparator2(code)) - break; - else - code = CHAR_FORWARD_SLASH; + if (i < len) code = path4.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 || + 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); + const lastSlashIndex = res.lastIndexOf(separator) if (lastSlashIndex === -1) { - res = ""; - lastSegmentLength = 0; + res = '' + lastSegmentLength = 0 } else { - res = res.slice(0, lastSlashIndex); - lastSegmentLength = res.length - 1 - res.lastIndexOf(separator); + res = res.slice(0, lastSlashIndex) + lastSegmentLength = res.length - 1 - res.lastIndexOf(separator) } - lastSlash = i; - dots = 0; - continue; + lastSlash = i + dots = 0 + continue } else if (res.length === 2 || res.length === 1) { - res = ""; - lastSegmentLength = 0; - lastSlash = i; - dots = 0; - continue; + res = '' + lastSegmentLength = 0 + lastSlash = i + dots = 0 + continue } } if (allowAboveRoot) { - if (res.length > 0) - res += `${separator}..`; - else - res = ".."; - lastSegmentLength = 2; + if (res.length > 0) res += `${separator}..` + else res = '..' + lastSegmentLength = 2 } } else { - if (res.length > 0) - res += separator + path4.slice(lastSlash + 1, i); - else - res = path4.slice(lastSlash + 1, i); - lastSegmentLength = i - lastSlash - 1; + if (res.length > 0) res += separator + path4.slice(lastSlash + 1, i) + else res = path4.slice(lastSlash + 1, i) + lastSegmentLength = i - lastSlash - 1 } - lastSlash = i; - dots = 0; + lastSlash = i + dots = 0 } else if (code === CHAR_DOT && dots !== -1) { - ++dots; + ++dots } else { - dots = -1; + dots = -1 } } - return res; + return res } function _format(sep4, pathObject) { - const dir = pathObject.dir || pathObject.root; - const base = pathObject.base || (pathObject.name || "") + (pathObject.ext || ""); - if (!dir) - return base; - if (dir === pathObject.root) - return dir + base; - return dir + sep4 + base; + const dir = pathObject.dir || pathObject.root + const base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '') + if (!dir) return base + if (dir === pathObject.root) return dir + base + return dir + sep4 + base } var WHITESPACE_ENCODINGS = { - " ": "%09", - "\n": "%0A", - "\v": "%0B", - "\f": "%0C", - "\r": "%0D", - " ": "%20" -}; + ' ': '%09', + '\n': '%0A', + '\v': '%0B', + '\f': '%0C', + '\r': '%0D', + ' ': '%20' +} function encodeWhitespace(string) { return string.replaceAll(/[\s]/g, (c) => { - return WHITESPACE_ENCODINGS[c] ?? c; - }); + return WHITESPACE_ENCODINGS[c] ?? c + }) } // ../_util/assert.ts var DenoStdInternalError = class extends Error { constructor(message) { - super(message); - this.name = "DenoStdInternalError"; + super(message) + this.name = 'DenoStdInternalError' } -}; -function assert(expr, msg = "") { +} +function assert(expr, msg = '') { if (!expr) { - throw new DenoStdInternalError(msg); + throw new DenoStdInternalError(msg) } } // ../path/win32.ts -var sep = "\\"; -var delimiter = ";"; +var sep = '\\' +var delimiter = ';' function resolve(...pathSegments) { - let resolvedDevice = ""; - let resolvedTail = ""; - let resolvedAbsolute = false; + let resolvedDevice = '' + let resolvedTail = '' + let resolvedAbsolute = false for (let i = pathSegments.length - 1; i >= -1; i--) { - let path4; - const { Deno: Deno2 } = globalThis; + let path4 + const { Deno: Deno2 } = globalThis if (i >= 0) { - path4 = pathSegments[i]; + path4 = pathSegments[i] } else if (!resolvedDevice) { - if (typeof Deno2?.cwd !== "function") { - throw new TypeError("Resolved a drive-letter-less path without a CWD."); + if (typeof Deno2?.cwd !== 'function') { + throw new TypeError('Resolved a drive-letter-less path without a CWD.') } - path4 = Deno2.cwd(); + path4 = Deno2.cwd() } else { - if (typeof Deno2?.env?.get !== "function" || typeof Deno2?.cwd !== "function") { - throw new TypeError("Resolved a relative path without a CWD."); + if (typeof Deno2?.env?.get !== 'function' || typeof Deno2?.cwd !== 'function') { + throw new TypeError('Resolved a relative path without a CWD.') } - path4 = Deno2.env.get(`=${resolvedDevice}`) || Deno2.cwd(); + path4 = Deno2.env.get(`=${resolvedDevice}`) || Deno2.cwd() if (path4 === void 0 || path4.slice(0, 3).toLowerCase() !== `${resolvedDevice.toLowerCase()}\\`) { - path4 = `${resolvedDevice}\\`; + path4 = `${resolvedDevice}\\` } } - assertPath(path4); - const len = path4.length; - if (len === 0) - continue; - let rootEnd = 0; - let device = ""; - let isAbsolute4 = false; - const code = path4.charCodeAt(0); + assertPath(path4) + const len = path4.length + if (len === 0) continue + let rootEnd = 0 + let device = '' + let isAbsolute4 = false + const code = path4.charCodeAt(0) if (len > 1) { if (isPathSeparator(code)) { - isAbsolute4 = true; + isAbsolute4 = true if (isPathSeparator(path4.charCodeAt(1))) { - let j = 2; - let last = j; + let j = 2 + let last = j for (; j < len; ++j) { - if (isPathSeparator(path4.charCodeAt(j))) - break; + if (isPathSeparator(path4.charCodeAt(j))) break } if (j < len && j !== last) { - const firstPart = path4.slice(last, j); - last = j; + const firstPart = path4.slice(last, j) + last = j for (; j < len; ++j) { - if (!isPathSeparator(path4.charCodeAt(j))) - break; + if (!isPathSeparator(path4.charCodeAt(j))) break } if (j < len && j !== last) { - last = j; + last = j for (; j < len; ++j) { - if (isPathSeparator(path4.charCodeAt(j))) - break; + if (isPathSeparator(path4.charCodeAt(j))) break } if (j === len) { - device = `\\\\${firstPart}\\${path4.slice(last)}`; - rootEnd = j; + device = `\\\\${firstPart}\\${path4.slice(last)}` + rootEnd = j } else if (j !== last) { - device = `\\\\${firstPart}\\${path4.slice(last, j)}`; - rootEnd = j; + device = `\\\\${firstPart}\\${path4.slice(last, j)}` + rootEnd = j } } } } else { - rootEnd = 1; + rootEnd = 1 } } else if (isWindowsDeviceRoot(code)) { if (path4.charCodeAt(1) === CHAR_COLON) { - device = path4.slice(0, 2); - rootEnd = 2; + device = path4.slice(0, 2) + rootEnd = 2 if (len > 2) { if (isPathSeparator(path4.charCodeAt(2))) { - isAbsolute4 = true; - rootEnd = 3; + isAbsolute4 = true + rootEnd = 3 } } } } } else if (isPathSeparator(code)) { - rootEnd = 1; - isAbsolute4 = true; + rootEnd = 1 + isAbsolute4 = true } if (device.length > 0 && resolvedDevice.length > 0 && device.toLowerCase() !== resolvedDevice.toLowerCase()) { - continue; + continue } if (resolvedDevice.length === 0 && device.length > 0) { - resolvedDevice = device; + resolvedDevice = device } if (!resolvedAbsolute) { - resolvedTail = `${path4.slice(rootEnd)}\\${resolvedTail}`; - resolvedAbsolute = isAbsolute4; + resolvedTail = `${path4.slice(rootEnd)}\\${resolvedTail}` + resolvedAbsolute = isAbsolute4 } - if (resolvedAbsolute && resolvedDevice.length > 0) - break; + if (resolvedAbsolute && resolvedDevice.length > 0) break } - resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, "\\", isPathSeparator); - return resolvedDevice + (resolvedAbsolute ? "\\" : "") + resolvedTail || "."; + resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\', isPathSeparator) + return resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail || '.' } function normalize(path4) { - assertPath(path4); - const len = path4.length; - if (len === 0) - return "."; - let rootEnd = 0; - let device; - let isAbsolute4 = false; - const code = path4.charCodeAt(0); + assertPath(path4) + const len = path4.length + if (len === 0) return '.' + let rootEnd = 0 + let device + let isAbsolute4 = false + const code = path4.charCodeAt(0) if (len > 1) { if (isPathSeparator(code)) { - isAbsolute4 = true; + isAbsolute4 = true if (isPathSeparator(path4.charCodeAt(1))) { - let j = 2; - let last = j; + let j = 2 + let last = j for (; j < len; ++j) { - if (isPathSeparator(path4.charCodeAt(j))) - break; + if (isPathSeparator(path4.charCodeAt(j))) break } if (j < len && j !== last) { - const firstPart = path4.slice(last, j); - last = j; + const firstPart = path4.slice(last, j) + last = j for (; j < len; ++j) { - if (!isPathSeparator(path4.charCodeAt(j))) - break; + if (!isPathSeparator(path4.charCodeAt(j))) break } if (j < len && j !== last) { - last = j; + last = j for (; j < len; ++j) { - if (isPathSeparator(path4.charCodeAt(j))) - break; + if (isPathSeparator(path4.charCodeAt(j))) break } if (j === len) { - return `\\\\${firstPart}\\${path4.slice(last)}\\`; + return `\\\\${firstPart}\\${path4.slice(last)}\\` } else if (j !== last) { - device = `\\\\${firstPart}\\${path4.slice(last, j)}`; - rootEnd = j; + device = `\\\\${firstPart}\\${path4.slice(last, j)}` + rootEnd = j } } } } else { - rootEnd = 1; + rootEnd = 1 } } else if (isWindowsDeviceRoot(code)) { if (path4.charCodeAt(1) === CHAR_COLON) { - device = path4.slice(0, 2); - rootEnd = 2; + device = path4.slice(0, 2) + rootEnd = 2 if (len > 2) { if (isPathSeparator(path4.charCodeAt(2))) { - isAbsolute4 = true; - rootEnd = 3; + isAbsolute4 = true + rootEnd = 3 } } } } } else if (isPathSeparator(code)) { - return "\\"; + return '\\' } - let tail; + let tail if (rootEnd < len) { - tail = normalizeString(path4.slice(rootEnd), !isAbsolute4, "\\", isPathSeparator); + tail = normalizeString(path4.slice(rootEnd), !isAbsolute4, '\\', isPathSeparator) } else { - tail = ""; + tail = '' } - if (tail.length === 0 && !isAbsolute4) - tail = "."; + if (tail.length === 0 && !isAbsolute4) tail = '.' if (tail.length > 0 && isPathSeparator(path4.charCodeAt(len - 1))) { - tail += "\\"; + tail += '\\' } if (device === void 0) { if (isAbsolute4) { - if (tail.length > 0) - return `\\${tail}`; - else - return "\\"; + if (tail.length > 0) return `\\${tail}` + else return '\\' } else if (tail.length > 0) { - return tail; + return tail } else { - return ""; + return '' } } else if (isAbsolute4) { - if (tail.length > 0) - return `${device}\\${tail}`; - else - return `${device}\\`; + if (tail.length > 0) return `${device}\\${tail}` + else return `${device}\\` } else if (tail.length > 0) { - return device + tail; + return device + tail } else { - return device; + return device } } function isAbsolute(path4) { - assertPath(path4); - const len = path4.length; - if (len === 0) - return false; - const code = path4.charCodeAt(0); + assertPath(path4) + const len = path4.length + if (len === 0) return false + const code = path4.charCodeAt(0) if (isPathSeparator(code)) { - return true; + return true } else if (isWindowsDeviceRoot(code)) { if (len > 2 && path4.charCodeAt(1) === CHAR_COLON) { - if (isPathSeparator(path4.charCodeAt(2))) - return true; + if (isPathSeparator(path4.charCodeAt(2))) return true } } - return false; + return false } function join(...paths) { - const pathsCount = paths.length; - if (pathsCount === 0) - return "."; - let joined; - let firstPart = null; + const pathsCount = paths.length + if (pathsCount === 0) return '.' + let joined + let firstPart = null for (let i = 0; i < pathsCount; ++i) { - const path4 = paths[i]; - assertPath(path4); + const path4 = paths[i] + assertPath(path4) if (path4.length > 0) { - if (joined === void 0) - joined = firstPart = path4; - else - joined += `\\${path4}`; + if (joined === void 0) joined = firstPart = path4 + else joined += `\\${path4}` } } - if (joined === void 0) - return "."; - let needsReplace = true; - let slashCount = 0; - assert(firstPart != null); + if (joined === void 0) return '.' + let needsReplace = true + let slashCount = 0 + assert(firstPart != null) if (isPathSeparator(firstPart.charCodeAt(0))) { - ++slashCount; - const firstLen = firstPart.length; + ++slashCount + const firstLen = firstPart.length if (firstLen > 1) { if (isPathSeparator(firstPart.charCodeAt(1))) { - ++slashCount; + ++slashCount if (firstLen > 2) { - if (isPathSeparator(firstPart.charCodeAt(2))) - ++slashCount; + if (isPathSeparator(firstPart.charCodeAt(2))) ++slashCount else { - needsReplace = false; + needsReplace = false } } } @@ -439,437 +424,411 @@ function join(...paths) { } if (needsReplace) { for (; slashCount < joined.length; ++slashCount) { - if (!isPathSeparator(joined.charCodeAt(slashCount))) - break; + if (!isPathSeparator(joined.charCodeAt(slashCount))) break } - if (slashCount >= 2) - joined = `\\${joined.slice(slashCount)}`; + if (slashCount >= 2) joined = `\\${joined.slice(slashCount)}` } - return normalize(joined); + return normalize(joined) } function relative(from, to) { - assertPath(from); - assertPath(to); - if (from === to) - return ""; - const fromOrig = resolve(from); - const toOrig = resolve(to); - if (fromOrig === toOrig) - return ""; - from = fromOrig.toLowerCase(); - to = toOrig.toLowerCase(); - if (from === to) - return ""; - let fromStart = 0; - let fromEnd = from.length; + assertPath(from) + assertPath(to) + if (from === to) return '' + const fromOrig = resolve(from) + const toOrig = resolve(to) + if (fromOrig === toOrig) return '' + from = fromOrig.toLowerCase() + to = toOrig.toLowerCase() + if (from === to) return '' + let fromStart = 0 + let fromEnd = from.length for (; fromStart < fromEnd; ++fromStart) { - if (from.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH) - break; + if (from.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH) break } for (; fromEnd - 1 > fromStart; --fromEnd) { - if (from.charCodeAt(fromEnd - 1) !== CHAR_BACKWARD_SLASH) - break; + if (from.charCodeAt(fromEnd - 1) !== CHAR_BACKWARD_SLASH) break } - const fromLen = fromEnd - fromStart; - let toStart = 0; - let toEnd = to.length; + const fromLen = fromEnd - fromStart + let toStart = 0 + let toEnd = to.length for (; toStart < toEnd; ++toStart) { - if (to.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH) - break; + if (to.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH) break } for (; toEnd - 1 > toStart; --toEnd) { - if (to.charCodeAt(toEnd - 1) !== CHAR_BACKWARD_SLASH) - break; + if (to.charCodeAt(toEnd - 1) !== CHAR_BACKWARD_SLASH) break } - const toLen = toEnd - toStart; - const length = fromLen < toLen ? fromLen : toLen; - let lastCommonSep = -1; - let i = 0; + 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 (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) { - return toOrig.slice(toStart + i + 1); + return toOrig.slice(toStart + i + 1) } else if (i === 2) { - return toOrig.slice(toStart + i); + return toOrig.slice(toStart + i) } } if (fromLen > length) { if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) { - lastCommonSep = i; + lastCommonSep = i } else if (i === 2) { - lastCommonSep = 3; + lastCommonSep = 3 } } - break; + break } - const fromCode = from.charCodeAt(fromStart + i); - const toCode = to.charCodeAt(toStart + i); - if (fromCode !== toCode) - break; - else if (fromCode === CHAR_BACKWARD_SLASH) - lastCommonSep = i; + const fromCode = from.charCodeAt(fromStart + i) + const toCode = to.charCodeAt(toStart + i) + if (fromCode !== toCode) break + else if (fromCode === CHAR_BACKWARD_SLASH) lastCommonSep = i } if (i !== length && lastCommonSep === -1) { - return toOrig; + return toOrig } - let out = ""; - if (lastCommonSep === -1) - lastCommonSep = 0; + let out = '' + if (lastCommonSep === -1) lastCommonSep = 0 for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) { - if (out.length === 0) - out += ".."; - else - out += "\\.."; + if (out.length === 0) out += '..' + else out += '\\..' } } if (out.length > 0) { - return out + toOrig.slice(toStart + lastCommonSep, toEnd); + return out + toOrig.slice(toStart + lastCommonSep, toEnd) } else { - toStart += lastCommonSep; - if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) - ++toStart; - return toOrig.slice(toStart, toEnd); + toStart += lastCommonSep + if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) ++toStart + return toOrig.slice(toStart, toEnd) } } function toNamespacedPath(path4) { - if (typeof path4 !== "string") - return path4; - if (path4.length === 0) - return ""; - const resolvedPath = resolve(path4); + if (typeof path4 !== 'string') return path4 + if (path4.length === 0) return '' + const resolvedPath = resolve(path4) if (resolvedPath.length >= 3) { if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) { if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) { - const code = resolvedPath.charCodeAt(2); + const code = resolvedPath.charCodeAt(2) if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) { - return `\\\\?\\UNC\\${resolvedPath.slice(2)}`; + return `\\\\?\\UNC\\${resolvedPath.slice(2)}` } } } else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0))) { if (resolvedPath.charCodeAt(1) === CHAR_COLON && resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) { - return `\\\\?\\${resolvedPath}`; + return `\\\\?\\${resolvedPath}` } } } - return path4; + return path4 } function dirname(path4) { - assertPath(path4); - const len = path4.length; - if (len === 0) - return "."; - let rootEnd = -1; - let end = -1; - let matchedSlash = true; - let offset = 0; - const code = path4.charCodeAt(0); + assertPath(path4) + const len = path4.length + if (len === 0) return '.' + let rootEnd = -1 + let end = -1 + let matchedSlash = true + let offset = 0 + const code = path4.charCodeAt(0) if (len > 1) { if (isPathSeparator(code)) { - rootEnd = offset = 1; + rootEnd = offset = 1 if (isPathSeparator(path4.charCodeAt(1))) { - let j = 2; - let last = j; + let j = 2 + let last = j for (; j < len; ++j) { - if (isPathSeparator(path4.charCodeAt(j))) - break; + if (isPathSeparator(path4.charCodeAt(j))) break } if (j < len && j !== last) { - last = j; + last = j for (; j < len; ++j) { - if (!isPathSeparator(path4.charCodeAt(j))) - break; + if (!isPathSeparator(path4.charCodeAt(j))) break } if (j < len && j !== last) { - last = j; + last = j for (; j < len; ++j) { - if (isPathSeparator(path4.charCodeAt(j))) - break; + if (isPathSeparator(path4.charCodeAt(j))) break } if (j === len) { - return path4; + return path4 } if (j !== last) { - rootEnd = offset = j + 1; + rootEnd = offset = j + 1 } } } } } else if (isWindowsDeviceRoot(code)) { if (path4.charCodeAt(1) === CHAR_COLON) { - rootEnd = offset = 2; + rootEnd = offset = 2 if (len > 2) { - if (isPathSeparator(path4.charCodeAt(2))) - rootEnd = offset = 3; + if (isPathSeparator(path4.charCodeAt(2))) rootEnd = offset = 3 } } } } else if (isPathSeparator(code)) { - return path4; + return path4 } for (let i = len - 1; i >= offset; --i) { if (isPathSeparator(path4.charCodeAt(i))) { if (!matchedSlash) { - end = i; - break; + end = i + break } } else { - matchedSlash = false; + matchedSlash = false } } if (end === -1) { - if (rootEnd === -1) - return "."; - else - end = rootEnd; + if (rootEnd === -1) return '.' + else end = rootEnd } - return path4.slice(0, end); + return path4.slice(0, end) } -function basename(path4, ext = "") { - if (ext !== void 0 && typeof ext !== "string") { - throw new TypeError('"ext" argument must be a string'); - } - assertPath(path4); - let start = 0; - let end = -1; - let matchedSlash = true; - let i; +function basename(path4, ext = '') { + if (ext !== void 0 && typeof ext !== 'string') { + throw new TypeError('"ext" argument must be a string') + } + assertPath(path4) + let start = 0 + let end = -1 + let matchedSlash = true + let i if (path4.length >= 2) { - const drive = path4.charCodeAt(0); + const drive = path4.charCodeAt(0) if (isWindowsDeviceRoot(drive)) { - if (path4.charCodeAt(1) === CHAR_COLON) - start = 2; + if (path4.charCodeAt(1) === CHAR_COLON) start = 2 } } if (ext !== void 0 && ext.length > 0 && ext.length <= path4.length) { - if (ext.length === path4.length && ext === path4) - return ""; - let extIdx = ext.length - 1; - let firstNonSlashEnd = -1; + if (ext.length === path4.length && ext === path4) return '' + let extIdx = ext.length - 1 + let firstNonSlashEnd = -1 for (i = path4.length - 1; i >= start; --i) { - const code = path4.charCodeAt(i); + const code = path4.charCodeAt(i) if (isPathSeparator(code)) { if (!matchedSlash) { - start = i + 1; - break; + start = i + 1 + break } } else { if (firstNonSlashEnd === -1) { - matchedSlash = false; - firstNonSlashEnd = i + 1; + matchedSlash = false + firstNonSlashEnd = i + 1 } if (extIdx >= 0) { if (code === ext.charCodeAt(extIdx)) { if (--extIdx === -1) { - end = i; + end = i } } else { - extIdx = -1; - end = firstNonSlashEnd; + extIdx = -1 + end = firstNonSlashEnd } } } } - if (start === end) - end = firstNonSlashEnd; - else if (end === -1) - end = path4.length; - return path4.slice(start, end); + if (start === end) end = firstNonSlashEnd + else if (end === -1) end = path4.length + return path4.slice(start, end) } else { for (i = path4.length - 1; i >= start; --i) { if (isPathSeparator(path4.charCodeAt(i))) { if (!matchedSlash) { - start = i + 1; - break; + start = i + 1 + break } } else if (end === -1) { - matchedSlash = false; - end = i + 1; + matchedSlash = false + end = i + 1 } } - if (end === -1) - return ""; - return path4.slice(start, end); + if (end === -1) return '' + return path4.slice(start, end) } } function extname(path4) { - assertPath(path4); - let start = 0; - let startDot = -1; - let startPart = 0; - let end = -1; - let matchedSlash = true; - let preDotState = 0; + assertPath(path4) + let start = 0 + let startDot = -1 + let startPart = 0 + let end = -1 + let matchedSlash = true + let preDotState = 0 if (path4.length >= 2 && path4.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path4.charCodeAt(0))) { - start = startPart = 2; + start = startPart = 2 } for (let i = path4.length - 1; i >= start; --i) { - const code = path4.charCodeAt(i); + const code = path4.charCodeAt(i) if (isPathSeparator(code)) { if (!matchedSlash) { - startPart = i + 1; - break; + startPart = i + 1 + break } - continue; + continue } if (end === -1) { - matchedSlash = false; - end = i + 1; + matchedSlash = false + end = i + 1 } if (code === CHAR_DOT) { - if (startDot === -1) - startDot = i; - else if (preDotState !== 1) - preDotState = 1; + if (startDot === -1) startDot = i + else if (preDotState !== 1) preDotState = 1 } else if (startDot !== -1) { - preDotState = -1; + preDotState = -1 } } - if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { - return ""; + if ( + startDot === -1 || + end === -1 || + preDotState === 0 || + (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) + ) { + return '' } - return path4.slice(startDot, end); + return path4.slice(startDot, end) } function format(pathObject) { - if (pathObject === null || typeof pathObject !== "object") { - throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`); + if (pathObject === null || typeof pathObject !== 'object') { + throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`) } - return _format("\\", pathObject); + return _format('\\', pathObject) } function parse(path4) { - assertPath(path4); - const ret = { root: "", dir: "", base: "", ext: "", name: "" }; - const len = path4.length; - if (len === 0) - return ret; - let rootEnd = 0; - let code = path4.charCodeAt(0); + assertPath(path4) + const ret = { root: '', dir: '', base: '', ext: '', name: '' } + const len = path4.length + if (len === 0) return ret + let rootEnd = 0 + let code = path4.charCodeAt(0) if (len > 1) { if (isPathSeparator(code)) { - rootEnd = 1; + rootEnd = 1 if (isPathSeparator(path4.charCodeAt(1))) { - let j = 2; - let last = j; + let j = 2 + let last = j for (; j < len; ++j) { - if (isPathSeparator(path4.charCodeAt(j))) - break; + if (isPathSeparator(path4.charCodeAt(j))) break } if (j < len && j !== last) { - last = j; + last = j for (; j < len; ++j) { - if (!isPathSeparator(path4.charCodeAt(j))) - break; + if (!isPathSeparator(path4.charCodeAt(j))) break } if (j < len && j !== last) { - last = j; + last = j for (; j < len; ++j) { - if (isPathSeparator(path4.charCodeAt(j))) - break; + if (isPathSeparator(path4.charCodeAt(j))) break } if (j === len) { - rootEnd = j; + rootEnd = j } else if (j !== last) { - rootEnd = j + 1; + rootEnd = j + 1 } } } } } else if (isWindowsDeviceRoot(code)) { if (path4.charCodeAt(1) === CHAR_COLON) { - rootEnd = 2; + rootEnd = 2 if (len > 2) { if (isPathSeparator(path4.charCodeAt(2))) { if (len === 3) { - ret.root = ret.dir = path4; - return ret; + ret.root = ret.dir = path4 + return ret } - rootEnd = 3; + rootEnd = 3 } } else { - ret.root = ret.dir = path4; - return ret; + ret.root = ret.dir = path4 + return ret } } } } else if (isPathSeparator(code)) { - ret.root = ret.dir = path4; - return ret; - } - if (rootEnd > 0) - ret.root = path4.slice(0, rootEnd); - let startDot = -1; - let startPart = rootEnd; - let end = -1; - let matchedSlash = true; - let i = path4.length - 1; - let preDotState = 0; + ret.root = ret.dir = path4 + return ret + } + if (rootEnd > 0) ret.root = path4.slice(0, rootEnd) + let startDot = -1 + let startPart = rootEnd + let end = -1 + let matchedSlash = true + let i = path4.length - 1 + let preDotState = 0 for (; i >= rootEnd; --i) { - code = path4.charCodeAt(i); + code = path4.charCodeAt(i) if (isPathSeparator(code)) { if (!matchedSlash) { - startPart = i + 1; - break; + startPart = i + 1 + break } - continue; + continue } if (end === -1) { - matchedSlash = false; - end = i + 1; + matchedSlash = false + end = i + 1 } if (code === CHAR_DOT) { - if (startDot === -1) - startDot = i; - else if (preDotState !== 1) - preDotState = 1; + if (startDot === -1) startDot = i + else if (preDotState !== 1) preDotState = 1 } else if (startDot !== -1) { - preDotState = -1; + preDotState = -1 } } - if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + if ( + startDot === -1 || + end === -1 || + preDotState === 0 || + (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) + ) { if (end !== -1) { - ret.base = ret.name = path4.slice(startPart, end); + ret.base = ret.name = path4.slice(startPart, end) } } else { - ret.name = path4.slice(startPart, startDot); - ret.base = path4.slice(startPart, end); - ret.ext = path4.slice(startDot, end); + ret.name = path4.slice(startPart, startDot) + ret.base = path4.slice(startPart, end) + ret.ext = path4.slice(startDot, end) } if (startPart > 0 && startPart !== rootEnd) { - ret.dir = path4.slice(0, startPart - 1); - } else - ret.dir = ret.root; - return ret; + ret.dir = path4.slice(0, startPart - 1) + } else ret.dir = ret.root + return ret } function fromFileUrl(url) { - url = url instanceof URL ? url : new URL(url); - if (url.protocol != "file:") { - throw new TypeError("Must be a file URL."); - } - let path4 = decodeURIComponent(url.pathname.replace(/\//g, "\\").replace(/%(?![0-9A-Fa-f]{2})/g, "%25")).replace(/^\\*([A-Za-z]:)(\\|$)/, "$1\\"); - if (url.hostname != "") { - path4 = `\\\\${url.hostname}${path4}`; - } - return path4; + url = url instanceof URL ? url : new URL(url) + if (url.protocol != 'file:') { + throw new TypeError('Must be a file URL.') + } + let path4 = decodeURIComponent(url.pathname.replace(/\//g, '\\').replace(/%(?![0-9A-Fa-f]{2})/g, '%25')).replace( + /^\\*([A-Za-z]:)(\\|$)/, + '$1\\' + ) + if (url.hostname != '') { + path4 = `\\\\${url.hostname}${path4}` + } + return path4 } function toFileUrl(path4) { if (!isAbsolute(path4)) { - throw new TypeError("Must be an absolute path."); + throw new TypeError('Must be an absolute path.') } - const [, hostname, pathname] = path4.match(/^(?:[/\\]{2}([^/\\]+)(?=[/\\](?:[^/\\]|$)))?(.*)/); - const url = new URL("file:///"); - url.pathname = encodeWhitespace(pathname.replace(/%/g, "%25")); - if (hostname != null && hostname != "localhost") { - url.hostname = hostname; + const [, hostname, pathname] = path4.match(/^(?:[/\\]{2}([^/\\]+)(?=[/\\](?:[^/\\]|$)))?(.*)/) + const url = new URL('file:///') + url.pathname = encodeWhitespace(pathname.replace(/%/g, '%25')) + if (hostname != null && hostname != 'localhost') { + url.hostname = hostname if (!url.hostname) { - throw new TypeError("Invalid hostname."); + throw new TypeError('Invalid hostname.') } } - return url; + return url } // ../path/posix.ts -var posix_exports = {}; +var posix_exports = {} __export(posix_exports, { basename: () => basename2, delimiter: () => delimiter2, @@ -886,650 +845,606 @@ __export(posix_exports, { sep: () => sep2, toFileUrl: () => toFileUrl2, toNamespacedPath: () => toNamespacedPath2 -}); -var sep2 = "/"; -var delimiter2 = ":"; +}) +var sep2 = '/' +var delimiter2 = ':' function resolve2(...pathSegments) { - let resolvedPath = ""; - let resolvedAbsolute = false; + let resolvedPath = '' + let resolvedAbsolute = false for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) { - let path4; - if (i >= 0) - path4 = pathSegments[i]; + let path4 + if (i >= 0) path4 = pathSegments[i] else { - const { Deno: Deno2 } = globalThis; - if (typeof Deno2?.cwd !== "function") { - throw new TypeError("Resolved a relative path without a CWD."); + const { Deno: Deno2 } = globalThis + if (typeof Deno2?.cwd !== 'function') { + throw new TypeError('Resolved a relative path without a CWD.') } - path4 = Deno2.cwd(); + path4 = Deno2.cwd() } - assertPath(path4); + assertPath(path4) if (path4.length === 0) { - continue; + continue } - resolvedPath = `${path4}/${resolvedPath}`; - resolvedAbsolute = path4.charCodeAt(0) === CHAR_FORWARD_SLASH; + resolvedPath = `${path4}/${resolvedPath}` + resolvedAbsolute = path4.charCodeAt(0) === CHAR_FORWARD_SLASH } - resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, "/", isPosixPathSeparator); + resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator) if (resolvedAbsolute) { - if (resolvedPath.length > 0) - return `/${resolvedPath}`; - else - return "/"; - } else if (resolvedPath.length > 0) - return resolvedPath; - else - return "."; + if (resolvedPath.length > 0) return `/${resolvedPath}` + else return '/' + } else if (resolvedPath.length > 0) return resolvedPath + else return '.' } function normalize2(path4) { - assertPath(path4); - if (path4.length === 0) - return "."; - const isAbsolute4 = path4.charCodeAt(0) === CHAR_FORWARD_SLASH; - const trailingSeparator = path4.charCodeAt(path4.length - 1) === CHAR_FORWARD_SLASH; - path4 = normalizeString(path4, !isAbsolute4, "/", isPosixPathSeparator); - if (path4.length === 0 && !isAbsolute4) - path4 = "."; - if (path4.length > 0 && trailingSeparator) - path4 += "/"; - if (isAbsolute4) - return `/${path4}`; - return path4; + assertPath(path4) + if (path4.length === 0) return '.' + const isAbsolute4 = path4.charCodeAt(0) === CHAR_FORWARD_SLASH + const trailingSeparator = path4.charCodeAt(path4.length - 1) === CHAR_FORWARD_SLASH + path4 = normalizeString(path4, !isAbsolute4, '/', isPosixPathSeparator) + if (path4.length === 0 && !isAbsolute4) path4 = '.' + if (path4.length > 0 && trailingSeparator) path4 += '/' + if (isAbsolute4) return `/${path4}` + return path4 } function isAbsolute2(path4) { - assertPath(path4); - return path4.length > 0 && path4.charCodeAt(0) === CHAR_FORWARD_SLASH; + assertPath(path4) + return path4.length > 0 && path4.charCodeAt(0) === CHAR_FORWARD_SLASH } function join2(...paths) { - if (paths.length === 0) - return "."; - let joined; + if (paths.length === 0) return '.' + let joined for (let i = 0, len = paths.length; i < len; ++i) { - const path4 = paths[i]; - assertPath(path4); + const path4 = paths[i] + assertPath(path4) if (path4.length > 0) { - if (!joined) - joined = path4; - else - joined += `/${path4}`; + if (!joined) joined = path4 + else joined += `/${path4}` } } - if (!joined) - return "."; - return normalize2(joined); + if (!joined) return '.' + return normalize2(joined) } function relative2(from, to) { - assertPath(from); - assertPath(to); - if (from === to) - return ""; - from = resolve2(from); - to = resolve2(to); - if (from === to) - return ""; - let fromStart = 1; - const fromEnd = from.length; + assertPath(from) + assertPath(to) + if (from === to) return '' + from = resolve2(from) + to = resolve2(to) + if (from === to) return '' + let fromStart = 1 + const fromEnd = from.length for (; fromStart < fromEnd; ++fromStart) { - if (from.charCodeAt(fromStart) !== CHAR_FORWARD_SLASH) - break; + if (from.charCodeAt(fromStart) !== CHAR_FORWARD_SLASH) break } - const fromLen = fromEnd - fromStart; - let toStart = 1; - const toEnd = to.length; + const fromLen = fromEnd - fromStart + let toStart = 1 + const toEnd = to.length for (; toStart < toEnd; ++toStart) { - if (to.charCodeAt(toStart) !== CHAR_FORWARD_SLASH) - break; + if (to.charCodeAt(toStart) !== CHAR_FORWARD_SLASH) break } - const toLen = toEnd - toStart; - const length = fromLen < toLen ? fromLen : toLen; - let lastCommonSep = -1; - let i = 0; + 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 (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) { - return to.slice(toStart + i + 1); + return to.slice(toStart + i + 1) } else if (i === 0) { - return to.slice(toStart + i); + return to.slice(toStart + i) } } else if (fromLen > length) { if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) { - lastCommonSep = i; + lastCommonSep = i } else if (i === 0) { - lastCommonSep = 0; + lastCommonSep = 0 } } - break; + break } - const fromCode = from.charCodeAt(fromStart + i); - const toCode = to.charCodeAt(toStart + i); - if (fromCode !== toCode) - break; - else if (fromCode === CHAR_FORWARD_SLASH) - lastCommonSep = i; - } - let out = ""; + const fromCode = from.charCodeAt(fromStart + i) + const toCode = to.charCodeAt(toStart + i) + if (fromCode !== toCode) break + else if (fromCode === CHAR_FORWARD_SLASH) lastCommonSep = i + } + let out = '' for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) { - if (out.length === 0) - out += ".."; - else - out += "/.."; + if (out.length === 0) out += '..' + else out += '/..' } } - if (out.length > 0) - return out + to.slice(toStart + lastCommonSep); + if (out.length > 0) return out + to.slice(toStart + lastCommonSep) else { - toStart += lastCommonSep; - if (to.charCodeAt(toStart) === CHAR_FORWARD_SLASH) - ++toStart; - return to.slice(toStart); + toStart += lastCommonSep + if (to.charCodeAt(toStart) === CHAR_FORWARD_SLASH) ++toStart + return to.slice(toStart) } } function toNamespacedPath2(path4) { - return path4; + return path4 } function dirname2(path4) { - assertPath(path4); - if (path4.length === 0) - return "."; - const hasRoot = path4.charCodeAt(0) === CHAR_FORWARD_SLASH; - let end = -1; - let matchedSlash = true; + assertPath(path4) + if (path4.length === 0) return '.' + const hasRoot = path4.charCodeAt(0) === CHAR_FORWARD_SLASH + let end = -1 + let matchedSlash = true for (let i = path4.length - 1; i >= 1; --i) { if (path4.charCodeAt(i) === CHAR_FORWARD_SLASH) { if (!matchedSlash) { - end = i; - break; + end = i + break } } else { - matchedSlash = false; + matchedSlash = false } } - if (end === -1) - return hasRoot ? "/" : "."; - if (hasRoot && end === 1) - return "//"; - return path4.slice(0, end); + if (end === -1) return hasRoot ? '/' : '.' + if (hasRoot && end === 1) return '//' + return path4.slice(0, end) } -function basename2(path4, ext = "") { - if (ext !== void 0 && typeof ext !== "string") { - throw new TypeError('"ext" argument must be a string'); - } - assertPath(path4); - let start = 0; - let end = -1; - let matchedSlash = true; - let i; +function basename2(path4, ext = '') { + if (ext !== void 0 && typeof ext !== 'string') { + throw new TypeError('"ext" argument must be a string') + } + assertPath(path4) + let start = 0 + let end = -1 + let matchedSlash = true + let i if (ext !== void 0 && ext.length > 0 && ext.length <= path4.length) { - if (ext.length === path4.length && ext === path4) - return ""; - let extIdx = ext.length - 1; - let firstNonSlashEnd = -1; + if (ext.length === path4.length && ext === path4) return '' + let extIdx = ext.length - 1 + let firstNonSlashEnd = -1 for (i = path4.length - 1; i >= 0; --i) { - const code = path4.charCodeAt(i); + const code = path4.charCodeAt(i) if (code === CHAR_FORWARD_SLASH) { if (!matchedSlash) { - start = i + 1; - break; + start = i + 1 + break } } else { if (firstNonSlashEnd === -1) { - matchedSlash = false; - firstNonSlashEnd = i + 1; + matchedSlash = false + firstNonSlashEnd = i + 1 } if (extIdx >= 0) { if (code === ext.charCodeAt(extIdx)) { if (--extIdx === -1) { - end = i; + end = i } } else { - extIdx = -1; - end = firstNonSlashEnd; + extIdx = -1 + end = firstNonSlashEnd } } } } - if (start === end) - end = firstNonSlashEnd; - else if (end === -1) - end = path4.length; - return path4.slice(start, end); + if (start === end) end = firstNonSlashEnd + else if (end === -1) end = path4.length + return path4.slice(start, end) } else { for (i = path4.length - 1; i >= 0; --i) { if (path4.charCodeAt(i) === CHAR_FORWARD_SLASH) { if (!matchedSlash) { - start = i + 1; - break; + start = i + 1 + break } } else if (end === -1) { - matchedSlash = false; - end = i + 1; + matchedSlash = false + end = i + 1 } } - if (end === -1) - return ""; - return path4.slice(start, end); + if (end === -1) return '' + return path4.slice(start, end) } } function extname2(path4) { - assertPath(path4); - let startDot = -1; - let startPart = 0; - let end = -1; - let matchedSlash = true; - let preDotState = 0; + assertPath(path4) + let startDot = -1 + let startPart = 0 + let end = -1 + let matchedSlash = true + let preDotState = 0 for (let i = path4.length - 1; i >= 0; --i) { - const code = path4.charCodeAt(i); + const code = path4.charCodeAt(i) if (code === CHAR_FORWARD_SLASH) { if (!matchedSlash) { - startPart = i + 1; - break; + startPart = i + 1 + break } - continue; + continue } if (end === -1) { - matchedSlash = false; - end = i + 1; + matchedSlash = false + end = i + 1 } if (code === CHAR_DOT) { - if (startDot === -1) - startDot = i; - else if (preDotState !== 1) - preDotState = 1; + if (startDot === -1) startDot = i + else if (preDotState !== 1) preDotState = 1 } else if (startDot !== -1) { - preDotState = -1; + preDotState = -1 } } - if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { - return ""; + if ( + startDot === -1 || + end === -1 || + preDotState === 0 || + (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) + ) { + return '' } - return path4.slice(startDot, end); + return path4.slice(startDot, end) } function format2(pathObject) { - if (pathObject === null || typeof pathObject !== "object") { - throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`); + if (pathObject === null || typeof pathObject !== 'object') { + throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`) } - return _format("/", pathObject); + return _format('/', pathObject) } function parse2(path4) { - assertPath(path4); - const ret = { root: "", dir: "", base: "", ext: "", name: "" }; - if (path4.length === 0) - return ret; - const isAbsolute4 = path4.charCodeAt(0) === CHAR_FORWARD_SLASH; - let start; + assertPath(path4) + const ret = { root: '', dir: '', base: '', ext: '', name: '' } + if (path4.length === 0) return ret + const isAbsolute4 = path4.charCodeAt(0) === CHAR_FORWARD_SLASH + let start if (isAbsolute4) { - ret.root = "/"; - start = 1; + ret.root = '/' + start = 1 } else { - start = 0; - } - let startDot = -1; - let startPart = 0; - let end = -1; - let matchedSlash = true; - let i = path4.length - 1; - let preDotState = 0; + start = 0 + } + let startDot = -1 + let startPart = 0 + let end = -1 + let matchedSlash = true + let i = path4.length - 1 + let preDotState = 0 for (; i >= start; --i) { - const code = path4.charCodeAt(i); + const code = path4.charCodeAt(i) if (code === CHAR_FORWARD_SLASH) { if (!matchedSlash) { - startPart = i + 1; - break; + startPart = i + 1 + break } - continue; + continue } if (end === -1) { - matchedSlash = false; - end = i + 1; + matchedSlash = false + end = i + 1 } if (code === CHAR_DOT) { - if (startDot === -1) - startDot = i; - else if (preDotState !== 1) - preDotState = 1; + if (startDot === -1) startDot = i + else if (preDotState !== 1) preDotState = 1 } else if (startDot !== -1) { - preDotState = -1; + preDotState = -1 } } - if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + if ( + startDot === -1 || + end === -1 || + preDotState === 0 || + (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) + ) { if (end !== -1) { if (startPart === 0 && isAbsolute4) { - ret.base = ret.name = path4.slice(1, end); + ret.base = ret.name = path4.slice(1, end) } else { - ret.base = ret.name = path4.slice(startPart, end); + ret.base = ret.name = path4.slice(startPart, end) } } } else { if (startPart === 0 && isAbsolute4) { - ret.name = path4.slice(1, startDot); - ret.base = path4.slice(1, end); + ret.name = path4.slice(1, startDot) + ret.base = path4.slice(1, end) } else { - ret.name = path4.slice(startPart, startDot); - ret.base = path4.slice(startPart, end); + ret.name = path4.slice(startPart, startDot) + ret.base = path4.slice(startPart, end) } - ret.ext = path4.slice(startDot, end); + ret.ext = path4.slice(startDot, end) } - if (startPart > 0) - ret.dir = path4.slice(0, startPart - 1); - else if (isAbsolute4) - ret.dir = "/"; - return ret; + if (startPart > 0) ret.dir = path4.slice(0, startPart - 1) + else if (isAbsolute4) ret.dir = '/' + return ret } function fromFileUrl2(url) { - url = url instanceof URL ? url : new URL(url); - if (url.protocol != "file:") { - throw new TypeError("Must be a file URL."); + url = url instanceof URL ? url : new URL(url) + if (url.protocol != 'file:') { + throw new TypeError('Must be a file URL.') } - return decodeURIComponent(url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25")); + return decodeURIComponent(url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, '%25')) } function toFileUrl2(path4) { if (!isAbsolute2(path4)) { - throw new TypeError("Must be an absolute path."); + throw new TypeError('Must be an absolute path.') } - const url = new URL("file:///"); - url.pathname = encodeWhitespace(path4.replace(/%/g, "%25").replace(/\\/g, "%5C")); - return url; + const url = new URL('file:///') + url.pathname = encodeWhitespace(path4.replace(/%/g, '%25').replace(/\\/g, '%5C')) + return url } // ../path/separator.ts -var SEP = isWindows ? "\\" : "/"; -var SEP_PATTERN = isWindows ? /[\\/]+/ : /\/+/; +var SEP = isWindows ? '\\' : '/' +var SEP_PATTERN = isWindows ? /[\\/]+/ : /\/+/ // ../path/common.ts function common(paths, sep4 = SEP) { - const [first = "", ...remaining] = paths; - if (first === "" || remaining.length === 0) { - return first.substring(0, first.lastIndexOf(sep4) + 1); + const [first = '', ...remaining] = paths + if (first === '' || remaining.length === 0) { + return first.substring(0, first.lastIndexOf(sep4) + 1) } - const parts = first.split(sep4); - let endOfPrefix = parts.length; + const parts = first.split(sep4) + let endOfPrefix = parts.length for (const path4 of remaining) { - const compare = path4.split(sep4); + const compare = path4.split(sep4) for (let i = 0; i < endOfPrefix; i++) { if (compare[i] !== parts[i]) { - endOfPrefix = i; + endOfPrefix = i } } if (endOfPrefix === 0) { - return ""; + return '' } } - const prefix = parts.slice(0, endOfPrefix).join(sep4); - return prefix.endsWith(sep4) ? prefix : `${prefix}${sep4}`; + const prefix = parts.slice(0, endOfPrefix).join(sep4) + return prefix.endsWith(sep4) ? prefix : `${prefix}${sep4}` } // ../path/glob.ts -var path = isWindows ? win32_exports : posix_exports; -var { join: join3, normalize: normalize3 } = path; -var regExpEscapeChars = ["!", "$", "(", ")", "*", "+", ".", "=", "?", "[", "\\", "^", "{", "|"]; -var rangeEscapeChars = ["-", "\\", "]"]; -function globToRegExp(glob, { - extended = true, - globstar: globstarOption = true, - os = osType, - caseInsensitive = false -} = {}) { - if (glob == "") { - return /(?!)/; - } - const sep4 = os == "windows" ? "(?:\\\\|/)+" : "/+"; - const sepMaybe = os == "windows" ? "(?:\\\\|/)*" : "/*"; - const seps = os == "windows" ? ["\\", "/"] : ["/"]; - const globstar = os == "windows" ? "(?:[^\\\\/]*(?:\\\\|/|$)+)*" : "(?:[^/]*(?:/|$)+)*"; - const wildcard = os == "windows" ? "[^\\\\/]*" : "[^/]*"; - const escapePrefix = os == "windows" ? "`" : "\\"; - let newLength = glob.length; - for (; newLength > 1 && seps.includes(glob[newLength - 1]); newLength--) - ; - glob = glob.slice(0, newLength); - let regExpString = ""; +var path = isWindows ? win32_exports : posix_exports +var { join: join3, normalize: normalize3 } = path +var regExpEscapeChars = ['!', '$', '(', ')', '*', '+', '.', '=', '?', '[', '\\', '^', '{', '|'] +var rangeEscapeChars = ['-', '\\', ']'] +function globToRegExp( + glob, + { extended = true, globstar: globstarOption = true, os = osType, caseInsensitive = false } = {} +) { + if (glob == '') { + return /(?!)/ + } + const sep4 = os == 'windows' ? '(?:\\\\|/)+' : '/+' + const sepMaybe = os == 'windows' ? '(?:\\\\|/)*' : '/*' + const seps = os == 'windows' ? ['\\', '/'] : ['/'] + const globstar = os == 'windows' ? '(?:[^\\\\/]*(?:\\\\|/|$)+)*' : '(?:[^/]*(?:/|$)+)*' + const wildcard = os == 'windows' ? '[^\\\\/]*' : '[^/]*' + const escapePrefix = os == 'windows' ? '`' : '\\' + let newLength = glob.length + for (; newLength > 1 && seps.includes(glob[newLength - 1]); newLength--); + glob = glob.slice(0, newLength) + let regExpString = '' for (let j = 0; j < glob.length; ) { - let segment = ""; - const groupStack = []; - let inRange = false; - let inEscape = false; - let endsWithSep = false; - let i = j; + let segment = '' + const groupStack = [] + let inRange = false + let inEscape = false + let endsWithSep = false + let i = j for (; i < glob.length && !seps.includes(glob[i]); i++) { if (inEscape) { - inEscape = false; - const escapeChars = inRange ? rangeEscapeChars : regExpEscapeChars; - segment += escapeChars.includes(glob[i]) ? `\\${glob[i]}` : glob[i]; - continue; + inEscape = false + const escapeChars = inRange ? rangeEscapeChars : regExpEscapeChars + segment += escapeChars.includes(glob[i]) ? `\\${glob[i]}` : glob[i] + continue } if (glob[i] == escapePrefix) { - inEscape = true; - continue; + inEscape = true + continue } - if (glob[i] == "[") { + if (glob[i] == '[') { if (!inRange) { - inRange = true; - segment += "["; - if (glob[i + 1] == "!") { - i++; - segment += "^"; - } else if (glob[i + 1] == "^") { - i++; - segment += "\\^"; + inRange = true + segment += '[' + if (glob[i + 1] == '!') { + i++ + segment += '^' + } else if (glob[i + 1] == '^') { + i++ + segment += '\\^' } - continue; - } else if (glob[i + 1] == ":") { - let k = i + 1; - let value = ""; - while (glob[k + 1] != null && glob[k + 1] != ":") { - value += glob[k + 1]; - k++; + continue + } else if (glob[i + 1] == ':') { + let k = i + 1 + let value = '' + while (glob[k + 1] != null && glob[k + 1] != ':') { + value += glob[k + 1] + k++ } - if (glob[k + 1] == ":" && glob[k + 2] == "]") { - i = k + 2; - if (value == "alnum") - segment += "\\dA-Za-z"; - else if (value == "alpha") - segment += "A-Za-z"; - else if (value == "ascii") - segment += "\0-\x7F"; - else if (value == "blank") - segment += " "; - else if (value == "cntrl") - segment += "\0-\x7F"; - else if (value == "digit") - segment += "\\d"; - else if (value == "graph") - segment += "!-~"; - else if (value == "lower") - segment += "a-z"; - else if (value == "print") - segment += " -~"; - else if (value == "punct") { - segment += `!"#$%&'()*+,\\-./:;<=>?@[\\\\\\]^_\u2018{|}~`; - } else if (value == "space") - segment += "\\s\v"; - else if (value == "upper") - segment += "A-Z"; - else if (value == "word") - segment += "\\w"; - else if (value == "xdigit") - segment += "\\dA-Fa-f"; - continue; + if (glob[k + 1] == ':' && glob[k + 2] == ']') { + i = k + 2 + if (value == 'alnum') segment += '\\dA-Za-z' + else if (value == 'alpha') segment += 'A-Za-z' + else if (value == 'ascii') segment += '\0-\x7F' + else if (value == 'blank') segment += ' ' + else if (value == 'cntrl') segment += '\0-\x7F' + else if (value == 'digit') segment += '\\d' + else if (value == 'graph') segment += '!-~' + else if (value == 'lower') segment += 'a-z' + else if (value == 'print') segment += ' -~' + else if (value == 'punct') { + segment += `!"#$%&'()*+,\\-./:;<=>?@[\\\\\\]^_\u2018{|}~` + } else if (value == 'space') segment += '\\s\v' + else if (value == 'upper') segment += 'A-Z' + else if (value == 'word') segment += '\\w' + else if (value == 'xdigit') segment += '\\dA-Fa-f' + continue } } } - if (glob[i] == "]" && inRange) { - inRange = false; - segment += "]"; - continue; + if (glob[i] == ']' && inRange) { + inRange = false + segment += ']' + continue } if (inRange) { - if (glob[i] == "\\") { - segment += `\\\\`; + if (glob[i] == '\\') { + segment += `\\\\` } else { - segment += glob[i]; + segment += glob[i] } - continue; + continue } - if (glob[i] == ")" && groupStack.length > 0 && groupStack[groupStack.length - 1] != "BRACE") { - segment += ")"; - const type = groupStack.pop(); - if (type == "!") { - segment += wildcard; - } else if (type != "@") { - segment += type; + if (glob[i] == ')' && groupStack.length > 0 && groupStack[groupStack.length - 1] != 'BRACE') { + segment += ')' + const type = groupStack.pop() + if (type == '!') { + segment += wildcard + } else if (type != '@') { + segment += type } - continue; + continue } - if (glob[i] == "|" && groupStack.length > 0 && groupStack[groupStack.length - 1] != "BRACE") { - segment += "|"; - continue; + if (glob[i] == '|' && groupStack.length > 0 && groupStack[groupStack.length - 1] != 'BRACE') { + segment += '|' + continue } - if (glob[i] == "+" && extended && glob[i + 1] == "(") { - i++; - groupStack.push("+"); - segment += "(?:"; - continue; + if (glob[i] == '+' && extended && glob[i + 1] == '(') { + i++ + groupStack.push('+') + segment += '(?:' + continue } - if (glob[i] == "@" && extended && glob[i + 1] == "(") { - i++; - groupStack.push("@"); - segment += "(?:"; - continue; + if (glob[i] == '@' && extended && glob[i + 1] == '(') { + i++ + groupStack.push('@') + segment += '(?:' + continue } - if (glob[i] == "?") { - if (extended && glob[i + 1] == "(") { - i++; - groupStack.push("?"); - segment += "(?:"; + if (glob[i] == '?') { + if (extended && glob[i + 1] == '(') { + i++ + groupStack.push('?') + segment += '(?:' } else { - segment += "."; + segment += '.' } - continue; + continue } - if (glob[i] == "!" && extended && glob[i + 1] == "(") { - i++; - groupStack.push("!"); - segment += "(?!"; - continue; + if (glob[i] == '!' && extended && glob[i + 1] == '(') { + i++ + groupStack.push('!') + segment += '(?!' + continue } - if (glob[i] == "{") { - groupStack.push("BRACE"); - segment += "(?:"; - continue; + if (glob[i] == '{') { + groupStack.push('BRACE') + segment += '(?:' + continue } - if (glob[i] == "}" && groupStack[groupStack.length - 1] == "BRACE") { - groupStack.pop(); - segment += ")"; - continue; + if (glob[i] == '}' && groupStack[groupStack.length - 1] == 'BRACE') { + groupStack.pop() + segment += ')' + continue } - if (glob[i] == "," && groupStack[groupStack.length - 1] == "BRACE") { - segment += "|"; - continue; + if (glob[i] == ',' && groupStack[groupStack.length - 1] == 'BRACE') { + segment += '|' + continue } - if (glob[i] == "*") { - if (extended && glob[i + 1] == "(") { - i++; - groupStack.push("*"); - segment += "(?:"; + if (glob[i] == '*') { + if (extended && glob[i + 1] == '(') { + i++ + groupStack.push('*') + segment += '(?:' } else { - const prevChar = glob[i - 1]; - let numStars = 1; - while (glob[i + 1] == "*") { - i++; - numStars++; + const prevChar = glob[i - 1] + let numStars = 1 + while (glob[i + 1] == '*') { + i++ + numStars++ } - const nextChar = glob[i + 1]; - if (globstarOption && numStars == 2 && [...seps, void 0].includes(prevChar) && [...seps, void 0].includes(nextChar)) { - segment += globstar; - endsWithSep = true; + const nextChar = glob[i + 1] + if ( + globstarOption && + numStars == 2 && + [...seps, void 0].includes(prevChar) && + [...seps, void 0].includes(nextChar) + ) { + segment += globstar + endsWithSep = true } else { - segment += wildcard; + segment += wildcard } } - continue; + continue } - segment += regExpEscapeChars.includes(glob[i]) ? `\\${glob[i]}` : glob[i]; + segment += regExpEscapeChars.includes(glob[i]) ? `\\${glob[i]}` : glob[i] } if (groupStack.length > 0 || inRange || inEscape) { - segment = ""; + segment = '' for (const c of glob.slice(j, i)) { - segment += regExpEscapeChars.includes(c) ? `\\${c}` : c; - endsWithSep = false; + segment += regExpEscapeChars.includes(c) ? `\\${c}` : c + endsWithSep = false } } - regExpString += segment; + regExpString += segment if (!endsWithSep) { - regExpString += i < glob.length ? sep4 : sepMaybe; - endsWithSep = true; + regExpString += i < glob.length ? sep4 : sepMaybe + endsWithSep = true } - while (seps.includes(glob[i])) - i++; + while (seps.includes(glob[i])) i++ if (!(i > j)) { - throw new Error("Assertion failure: i > j (potential infinite loop)"); + throw new Error('Assertion failure: i > j (potential infinite loop)') } - j = i; + j = i } - regExpString = `^${regExpString}$`; - return new RegExp(regExpString, caseInsensitive ? "i" : ""); + regExpString = `^${regExpString}$` + return new RegExp(regExpString, caseInsensitive ? 'i' : '') } function isGlob(str) { - const chars = { "{": "}", "(": ")", "[": "]" }; - const regex = /\\(.)|(^!|\*|\?|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/; - if (str === "") { - return false; - } - let match; - while (match = regex.exec(str)) { - if (match[2]) - return true; - let idx = match.index + match[0].length; - const open = match[1]; - const close = open ? chars[open] : null; + const chars = { '{': '}', '(': ')', '[': ']' } + const regex = /\\(.)|(^!|\*|\?|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/ + if (str === '') { + return false + } + let match + while ((match = regex.exec(str))) { + if (match[2]) return true + let idx = match.index + match[0].length + const open = match[1] + const close = open ? chars[open] : null if (open && close) { - const n = str.indexOf(close, idx); + const n = str.indexOf(close, idx) if (n !== -1) { - idx = n + 1; + idx = n + 1 } } - str = str.slice(idx); + str = str.slice(idx) } - return false; + return false } function normalizeGlob(glob, { globstar = false } = {}) { if (glob.match(/\0/g)) { - throw new Error(`Glob contains invalid characters: "${glob}"`); + throw new Error(`Glob contains invalid characters: "${glob}"`) } if (!globstar) { - return normalize3(glob); + return normalize3(glob) } - const s = SEP_PATTERN.source; - const badParentPattern = new RegExp(`(?<=(${s}|^)\\*\\*${s})\\.\\.(?=${s}|$)`, "g"); - return normalize3(glob.replace(badParentPattern, "\0")).replace(/\0/g, ".."); + const s = SEP_PATTERN.source + const badParentPattern = new RegExp(`(?<=(${s}|^)\\*\\*${s})\\.\\.(?=${s}|$)`, 'g') + return normalize3(glob.replace(badParentPattern, '\0')).replace(/\0/g, '..') } function joinGlobs(globs, { extended = false, globstar = false } = {}) { if (!globstar || globs.length == 0) { - return join3(...globs); + return join3(...globs) } - if (globs.length === 0) - return "."; - let joined; + if (globs.length === 0) return '.' + let joined for (const glob of globs) { - const path4 = glob; + const path4 = glob if (path4.length > 0) { - if (!joined) - joined = path4; - else - joined += `${SEP}${path4}`; + if (!joined) joined = path4 + else joined += `${SEP}${path4}` } } - if (!joined) - return "."; - return normalizeGlob(joined, { extended, globstar }); + if (!joined) return '.' + return normalizeGlob(joined, { extended, globstar }) } // ../path/mod.ts -var path2 = isWindows ? win32_exports : posix_exports; -var win32 = win32_exports; -var posix = posix_exports; +var path2 = isWindows ? win32_exports : posix_exports +var win32 = win32_exports +var posix = posix_exports var { basename: basename3, delimiter: delimiter3, @@ -1546,99 +1461,93 @@ var { sep: sep3, toFileUrl: toFileUrl3, toNamespacedPath: toNamespacedPath3 -} = path2; +} = path2 // path.ts -var path_default = { ...mod_exports }; +var path_default = { ...mod_exports } // url.ts -var forwardSlashRegEx = /\//g; -var percentRegEx = /%/g; -var backslashRegEx = /\\/g; -var newlineRegEx = /\n/g; -var carriageReturnRegEx = /\r/g; -var tabRegEx = /\t/g; -var _url = URL; +var forwardSlashRegEx = /\//g +var percentRegEx = /%/g +var backslashRegEx = /\\/g +var newlineRegEx = /\n/g +var carriageReturnRegEx = /\r/g +var tabRegEx = /\t/g +var _url = URL function fileURLToPath(path4) { - if (typeof path4 === "string") - path4 = new URL(path4); + if (typeof path4 === 'string') path4 = new URL(path4) else if (!(path4 instanceof URL)) { - throw new Deno.errors.InvalidData("invalid argument path , must be a string or URL"); + throw new Deno.errors.InvalidData('invalid argument path , must be a string or URL') } - if (path4.protocol !== "file:") { - throw new Deno.errors.InvalidData("invalid url scheme"); + if (path4.protocol !== 'file:') { + throw new Deno.errors.InvalidData('invalid url scheme') } - return isWindows ? getPathFromURLWin(path4) : getPathFromURLPosix(path4); + return isWindows ? getPathFromURLWin(path4) : getPathFromURLPosix(path4) } function getPathFromURLWin(url) { - const hostname = url.hostname; - let pathname = url.pathname; + const hostname = url.hostname + let pathname = url.pathname for (let n = 0; n < pathname.length; n++) { - if (pathname[n] === "%") { - const third = pathname.codePointAt(n + 2) || 32; - if (pathname[n + 1] === "2" && third === 102 || pathname[n + 1] === "5" && third === 99) { - throw new Deno.errors.InvalidData("must not include encoded \\ or / characters"); + if (pathname[n] === '%') { + const third = pathname.codePointAt(n + 2) || 32 + if ((pathname[n + 1] === '2' && third === 102) || (pathname[n + 1] === '5' && third === 99)) { + throw new Deno.errors.InvalidData('must not include encoded \\ or / characters') } } } - pathname = pathname.replace(forwardSlashRegEx, "\\"); - pathname = decodeURIComponent(pathname); - if (hostname !== "") { - return `\\\\${hostname}${pathname}`; + pathname = pathname.replace(forwardSlashRegEx, '\\') + pathname = decodeURIComponent(pathname) + if (hostname !== '') { + return `\\\\${hostname}${pathname}` } else { - const letter = pathname.codePointAt(1) | 32; - const sep4 = pathname[2]; - if (letter < CHAR_LOWERCASE_A || letter > CHAR_LOWERCASE_Z || sep4 !== ":") { - throw new Deno.errors.InvalidData("file url path must be absolute"); + const letter = pathname.codePointAt(1) | 32 + const sep4 = pathname[2] + if (letter < CHAR_LOWERCASE_A || letter > CHAR_LOWERCASE_Z || sep4 !== ':') { + throw new Deno.errors.InvalidData('file url path must be absolute') } - return pathname.slice(1); + return pathname.slice(1) } } function getPathFromURLPosix(url) { - if (url.hostname !== "") { - throw new Deno.errors.InvalidData("invalid file url hostname"); + if (url.hostname !== '') { + throw new Deno.errors.InvalidData('invalid file url hostname') } - const pathname = url.pathname; + const pathname = url.pathname for (let n = 0; n < pathname.length; n++) { - if (pathname[n] === "%") { - const third = pathname.codePointAt(n + 2) || 32; - if (pathname[n + 1] === "2" && third === 102) { - throw new Deno.errors.InvalidData("must not include encoded / characters"); + if (pathname[n] === '%') { + const third = pathname.codePointAt(n + 2) || 32 + if (pathname[n + 1] === '2' && third === 102) { + throw new Deno.errors.InvalidData('must not include encoded / characters') } } } - return decodeURIComponent(pathname); + return decodeURIComponent(pathname) } function pathToFileURL(filepath) { - let resolved = resolve3(filepath); - const filePathLast = filepath.charCodeAt(filepath.length - 1); - if ((filePathLast === CHAR_FORWARD_SLASH || isWindows && filePathLast === CHAR_BACKWARD_SLASH) && resolved[resolved.length - 1] !== sep3) { - resolved += "/"; - } - const outURL = new URL("file://"); - if (resolved.includes("%")) - resolved = resolved.replace(percentRegEx, "%25"); - if (!isWindows && resolved.includes("\\")) { - resolved = resolved.replace(backslashRegEx, "%5C"); - } - if (resolved.includes("\n")) - resolved = resolved.replace(newlineRegEx, "%0A"); - if (resolved.includes("\r")) { - resolved = resolved.replace(carriageReturnRegEx, "%0D"); - } - if (resolved.includes(" ")) - resolved = resolved.replace(tabRegEx, "%09"); - outURL.pathname = resolved; - return outURL; + let resolved = resolve3(filepath) + const filePathLast = filepath.charCodeAt(filepath.length - 1) + if ( + (filePathLast === CHAR_FORWARD_SLASH || (isWindows && filePathLast === CHAR_BACKWARD_SLASH)) && + resolved[resolved.length - 1] !== sep3 + ) { + resolved += '/' + } + const outURL = new URL('file://') + if (resolved.includes('%')) resolved = resolved.replace(percentRegEx, '%25') + if (!isWindows && resolved.includes('\\')) { + resolved = resolved.replace(backslashRegEx, '%5C') + } + if (resolved.includes('\n')) resolved = resolved.replace(newlineRegEx, '%0A') + if (resolved.includes('\r')) { + resolved = resolved.replace(carriageReturnRegEx, '%0D') + } + if (resolved.includes(' ')) resolved = resolved.replace(tabRegEx, '%09') + outURL.pathname = resolved + return outURL } var url_default = { fileURLToPath, pathToFileURL, URL -}; -export { - _url as URL, - url_default as default, - fileURLToPath, - pathToFileURL -}; +} +export { _url as URL, url_default as default, fileURLToPath, pathToFileURL }