diff --git a/embed/polyfills/deno_std_node_path.js b/embed/polyfills/deno_std_node_path.js new file mode 100644 index 000000000..427f7236d --- /dev/null +++ b/embed/polyfills/deno_std_node_path.js @@ -0,0 +1,1494 @@ +/* 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 }) +} + +// ../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/embed/polyfills/deno_std_node_querystring.js b/embed/polyfills/deno_std_node_querystring.js new file mode 100644 index 000000000..ae29836ee --- /dev/null +++ b/embed/polyfills/deno_std_node_querystring.js @@ -0,0 +1,106 @@ +/* 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) +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..5d71a1adc --- /dev/null +++ b/embed/polyfills/deno_std_node_timers.js @@ -0,0 +1,25 @@ +/* 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 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..3cbb8e84a --- /dev/null +++ b/embed/polyfills/deno_std_node_url.js @@ -0,0 +1,1553 @@ +/* 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 }) +} + +// ../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 2537cdcb3..bc5a23a8c 100644 --- a/server/nodejs.go +++ b/server/nodejs.go @@ -81,6 +81,10 @@ var builtInNodeModules = map[string]bool{ 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