diff --git a/dist/setup/index.js b/dist/setup/index.js index 4142d300..77fe658f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -558,7 +558,7 @@ class OidcClient { .catch(error => { throw new Error(`Failed to get ID Token. \n Error Code : ${error.statusCode}\n - Error Message: ${error.result.message}`); + Error Message: ${error.message}`); }); const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value; if (!id_token) { @@ -1825,7 +1825,11 @@ exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHand /* eslint-disable @typescript-eslint/no-explicit-any */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; @@ -1838,7 +1842,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; @@ -1857,6 +1861,7 @@ const http = __importStar(__nccwpck_require__(3685)); const https = __importStar(__nccwpck_require__(5687)); const pm = __importStar(__nccwpck_require__(9835)); const tunnel = __importStar(__nccwpck_require__(4294)); +const undici_1 = __nccwpck_require__(1773); var HttpCodes; (function (HttpCodes) { HttpCodes[HttpCodes["OK"] = 200] = "OK"; @@ -1886,16 +1891,16 @@ var HttpCodes; HttpCodes[HttpCodes["BadGateway"] = 502] = "BadGateway"; HttpCodes[HttpCodes["ServiceUnavailable"] = 503] = "ServiceUnavailable"; HttpCodes[HttpCodes["GatewayTimeout"] = 504] = "GatewayTimeout"; -})(HttpCodes = exports.HttpCodes || (exports.HttpCodes = {})); +})(HttpCodes || (exports.HttpCodes = HttpCodes = {})); var Headers; (function (Headers) { Headers["Accept"] = "accept"; Headers["ContentType"] = "content-type"; -})(Headers = exports.Headers || (exports.Headers = {})); +})(Headers || (exports.Headers = Headers = {})); var MediaTypes; (function (MediaTypes) { MediaTypes["ApplicationJson"] = "application/json"; -})(MediaTypes = exports.MediaTypes || (exports.MediaTypes = {})); +})(MediaTypes || (exports.MediaTypes = MediaTypes = {})); /** * Returns the proxy URL, depending upon the supplied url and proxy environment variables. * @param serverUrl The server URL where the request will be sent. For example, https://api.github.com @@ -1946,6 +1951,19 @@ class HttpClientResponse { })); }); } + readBodyBuffer() { + return __awaiter(this, void 0, void 0, function* () { + return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () { + const chunks = []; + this.message.on('data', (chunk) => { + chunks.push(chunk); + }); + this.message.on('end', () => { + resolve(Buffer.concat(chunks)); + }); + })); + }); + } } exports.HttpClientResponse = HttpClientResponse; function isHttps(requestUrl) { @@ -2251,6 +2269,15 @@ class HttpClient { const parsedUrl = new URL(serverUrl); return this._getAgent(parsedUrl); } + getAgentDispatcher(serverUrl) { + const parsedUrl = new URL(serverUrl); + const proxyUrl = pm.getProxyUrl(parsedUrl); + const useProxy = proxyUrl && proxyUrl.hostname; + if (!useProxy) { + return; + } + return this._getProxyAgentDispatcher(parsedUrl, proxyUrl); + } _prepareRequest(method, requestUrl, headers) { const info = {}; info.parsedUrl = requestUrl; @@ -2350,6 +2377,30 @@ class HttpClient { } return agent; } + _getProxyAgentDispatcher(parsedUrl, proxyUrl) { + let proxyAgent; + if (this._keepAlive) { + proxyAgent = this._proxyAgentDispatcher; + } + // if agent is already assigned use that agent. + if (proxyAgent) { + return proxyAgent; + } + const usingSsl = parsedUrl.protocol === 'https:'; + proxyAgent = new undici_1.ProxyAgent(Object.assign({ uri: proxyUrl.href, pipelining: !this._keepAlive ? 0 : 1 }, ((proxyUrl.username || proxyUrl.password) && { + token: `${proxyUrl.username}:${proxyUrl.password}` + }))); + this._proxyAgentDispatcher = proxyAgent; + if (usingSsl && this._ignoreSslError) { + // we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process + // http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options + // we have to cast it to any and change it directly + proxyAgent.options = Object.assign(proxyAgent.options.requestTls || {}, { + rejectUnauthorized: false + }); + } + return proxyAgent; + } _performExponentialBackoff(retryNumber) { return __awaiter(this, void 0, void 0, function* () { retryNumber = Math.min(ExponentialBackoffCeiling, retryNumber); @@ -2450,7 +2501,13 @@ function getProxyUrl(reqUrl) { } })(); if (proxyVar) { - return new URL(proxyVar); + try { + return new URL(proxyVar); + } + catch (_a) { + if (!proxyVar.startsWith('http://') && !proxyVar.startsWith('https://')) + return new URL(`http://${proxyVar}`); + } } else { return undefined; @@ -2461,6 +2518,10 @@ function checkBypass(reqUrl) { if (!reqUrl.hostname) { return false; } + const reqHost = reqUrl.hostname; + if (isLoopbackAddress(reqHost)) { + return true; + } const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || ''; if (!noProxy) { return false; @@ -2486,13 +2547,24 @@ function checkBypass(reqUrl) { .split(',') .map(x => x.trim().toUpperCase()) .filter(x => x)) { - if (upperReqHosts.some(x => x === upperNoProxyItem)) { + if (upperNoProxyItem === '*' || + upperReqHosts.some(x => x === upperNoProxyItem || + x.endsWith(`.${upperNoProxyItem}`) || + (upperNoProxyItem.startsWith('.') && + x.endsWith(`${upperNoProxyItem}`)))) { return true; } } return false; } exports.checkBypass = checkBypass; +function isLoopbackAddress(host) { + const hostLower = host.toLowerCase(); + return (hostLower === 'localhost' || + hostLower.startsWith('127.') || + hostLower.startsWith('[::1]') || + hostLower.startsWith('[0:0:0:0:0:0:0:1]')); +} //# sourceMappingURL=proxy.js.map /***/ }), @@ -2532,11 +2604,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; var _a; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getCmdPath = exports.tryGetExecutablePath = exports.isRooted = exports.isDirectory = exports.exists = exports.IS_WINDOWS = exports.unlink = exports.symlink = exports.stat = exports.rmdir = exports.rename = exports.readlink = exports.readdir = exports.mkdir = exports.lstat = exports.copyFile = exports.chmod = void 0; +exports.getCmdPath = exports.tryGetExecutablePath = exports.isRooted = exports.isDirectory = exports.exists = exports.READONLY = exports.UV_FS_O_EXLOCK = exports.IS_WINDOWS = exports.unlink = exports.symlink = exports.stat = exports.rmdir = exports.rm = exports.rename = exports.readlink = exports.readdir = exports.open = exports.mkdir = exports.lstat = exports.copyFile = exports.chmod = void 0; const fs = __importStar(__nccwpck_require__(7147)); const path = __importStar(__nccwpck_require__(1017)); -_a = fs.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink; +_a = fs.promises +// export const {open} = 'fs' +, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.open = _a.open, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rm = _a.rm, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink; +// export const {open} = 'fs' exports.IS_WINDOWS = process.platform === 'win32'; +// See https://github.com/nodejs/node/blob/d0153aee367422d0858105abec186da4dff0a0c5/deps/uv/include/uv/win.h#L691 +exports.UV_FS_O_EXLOCK = 0x10000000; +exports.READONLY = fs.constants.O_RDONLY; function exists(fsPath) { return __awaiter(this, void 0, void 0, function* () { try { @@ -2717,12 +2795,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", ({ value: true })); exports.findInPath = exports.which = exports.mkdirP = exports.rmRF = exports.mv = exports.cp = void 0; const assert_1 = __nccwpck_require__(9491); -const childProcess = __importStar(__nccwpck_require__(2081)); const path = __importStar(__nccwpck_require__(1017)); -const util_1 = __nccwpck_require__(3837); const ioUtil = __importStar(__nccwpck_require__(1962)); -const exec = util_1.promisify(childProcess.exec); -const execFile = util_1.promisify(childProcess.execFile); /** * Copies a file or folder. * Based off of shelljs - https://github.com/shelljs/shelljs/blob/9237f66c52e5daa40458f94f9565e18e8132f5a6/src/cp.js @@ -2803,61 +2877,23 @@ exports.mv = mv; function rmRF(inputPath) { return __awaiter(this, void 0, void 0, function* () { if (ioUtil.IS_WINDOWS) { - // Node doesn't provide a delete operation, only an unlink function. This means that if the file is being used by another - // program (e.g. antivirus), it won't be deleted. To address this, we shell out the work to rd/del. // Check for invalid characters // https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file if (/[*"<>|]/.test(inputPath)) { throw new Error('File path must not contain `*`, `"`, `<`, `>` or `|` on Windows'); } - try { - const cmdPath = ioUtil.getCmdPath(); - if (yield ioUtil.isDirectory(inputPath, true)) { - yield exec(`${cmdPath} /s /c "rd /s /q "%inputPath%""`, { - env: { inputPath } - }); - } - else { - yield exec(`${cmdPath} /s /c "del /f /a "%inputPath%""`, { - env: { inputPath } - }); - } - } - catch (err) { - // if you try to delete a file that doesn't exist, desired result is achieved - // other errors are valid - if (err.code !== 'ENOENT') - throw err; - } - // Shelling out fails to remove a symlink folder with missing source, this unlink catches that - try { - yield ioUtil.unlink(inputPath); - } - catch (err) { - // if you try to delete a file that doesn't exist, desired result is achieved - // other errors are valid - if (err.code !== 'ENOENT') - throw err; - } } - else { - let isDir = false; - try { - isDir = yield ioUtil.isDirectory(inputPath); - } - catch (err) { - // if you try to delete a file that doesn't exist, desired result is achieved - // other errors are valid - if (err.code !== 'ENOENT') - throw err; - return; - } - if (isDir) { - yield execFile(`rm`, [`-rf`, `${inputPath}`]); - } - else { - yield ioUtil.unlink(inputPath); - } + try { + // note if path does not exist, error is silent + yield ioUtil.rm(inputPath, { + force: true, + maxRetries: 3, + recursive: true, + retryDelay: 300 + }); + } + catch (err) { + throw new Error(`File was unable to be removed ${err}`); } }); } @@ -3957,8 +3993,11 @@ var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || // Max safe segment length for coercion. var MAX_SAFE_COMPONENT_LENGTH = 16 +var MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6 + // The actual regexps go on exports.re var re = exports.re = [] +var safeRe = exports.safeRe = [] var src = exports.src = [] var t = exports.tokens = {} var R = 0 @@ -3967,6 +4006,31 @@ function tok (n) { t[n] = R++ } +var LETTERDASHNUMBER = '[a-zA-Z0-9-]' + +// Replace some greedy regex tokens to prevent regex dos issues. These regex are +// used internally via the safeRe object since all inputs in this library get +// normalized first to trim and collapse all extra whitespace. The original +// regexes are exported for userland consumption and lower level usage. A +// future breaking change could export the safer regex only with a note that +// all input should have extra whitespace removed. +var safeRegexReplacements = [ + ['\\s', 1], + ['\\d', MAX_LENGTH], + [LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH], +] + +function makeSafeRe (value) { + for (var i = 0; i < safeRegexReplacements.length; i++) { + var token = safeRegexReplacements[i][0] + var max = safeRegexReplacements[i][1] + value = value + .split(token + '*').join(token + '{0,' + max + '}') + .split(token + '+').join(token + '{1,' + max + '}') + } + return value +} + // The following Regular Expressions can be used for tokenizing, // validating, and parsing SemVer version strings. @@ -3976,14 +4040,14 @@ function tok (n) { tok('NUMERICIDENTIFIER') src[t.NUMERICIDENTIFIER] = '0|[1-9]\\d*' tok('NUMERICIDENTIFIERLOOSE') -src[t.NUMERICIDENTIFIERLOOSE] = '[0-9]+' +src[t.NUMERICIDENTIFIERLOOSE] = '\\d+' // ## Non-numeric Identifier // Zero or more digits, followed by a letter or hyphen, and then zero or // more letters, digits, or hyphens. tok('NONNUMERICIDENTIFIER') -src[t.NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*' +src[t.NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-]' + LETTERDASHNUMBER + '*' // ## Main Version // Three dot-separated numeric identifiers. @@ -4025,7 +4089,7 @@ src[t.PRERELEASELOOSE] = '(?:-?(' + src[t.PRERELEASEIDENTIFIERLOOSE] + // Any combination of digits, letters, or hyphens. tok('BUILDIDENTIFIER') -src[t.BUILDIDENTIFIER] = '[0-9A-Za-z-]+' +src[t.BUILDIDENTIFIER] = LETTERDASHNUMBER + '+' // ## Build Metadata // Plus sign, followed by one or more period-separated build metadata @@ -4105,6 +4169,7 @@ src[t.COERCE] = '(^|[^\\d])' + '(?:$|[^\\d])' tok('COERCERTL') re[t.COERCERTL] = new RegExp(src[t.COERCE], 'g') +safeRe[t.COERCERTL] = new RegExp(makeSafeRe(src[t.COERCE]), 'g') // Tilde ranges. // Meaning is "reasonably at or greater than" @@ -4114,6 +4179,7 @@ src[t.LONETILDE] = '(?:~>?)' tok('TILDETRIM') src[t.TILDETRIM] = '(\\s*)' + src[t.LONETILDE] + '\\s+' re[t.TILDETRIM] = new RegExp(src[t.TILDETRIM], 'g') +safeRe[t.TILDETRIM] = new RegExp(makeSafeRe(src[t.TILDETRIM]), 'g') var tildeTrimReplace = '$1~' tok('TILDE') @@ -4129,6 +4195,7 @@ src[t.LONECARET] = '(?:\\^)' tok('CARETTRIM') src[t.CARETTRIM] = '(\\s*)' + src[t.LONECARET] + '\\s+' re[t.CARETTRIM] = new RegExp(src[t.CARETTRIM], 'g') +safeRe[t.CARETTRIM] = new RegExp(makeSafeRe(src[t.CARETTRIM]), 'g') var caretTrimReplace = '$1^' tok('CARET') @@ -4150,6 +4217,7 @@ src[t.COMPARATORTRIM] = '(\\s*)' + src[t.GTLT] + // this one has to use the /g flag re[t.COMPARATORTRIM] = new RegExp(src[t.COMPARATORTRIM], 'g') +safeRe[t.COMPARATORTRIM] = new RegExp(makeSafeRe(src[t.COMPARATORTRIM]), 'g') var comparatorTrimReplace = '$1$2$3' // Something like `1.2.3 - 1.2.4` @@ -4178,6 +4246,14 @@ for (var i = 0; i < R; i++) { debug(i, src[i]) if (!re[i]) { re[i] = new RegExp(src[i]) + + // Replace all greedy whitespace to prevent regex dos issues. These regex are + // used internally via the safeRe object since all inputs in this library get + // normalized first to trim and collapse all extra whitespace. The original + // regexes are exported for userland consumption and lower level usage. A + // future breaking change could export the safer regex only with a note that + // all input should have extra whitespace removed. + safeRe[i] = new RegExp(makeSafeRe(src[i])) } } @@ -4202,7 +4278,7 @@ function parse (version, options) { return null } - var r = options.loose ? re[t.LOOSE] : re[t.FULL] + var r = options.loose ? safeRe[t.LOOSE] : safeRe[t.FULL] if (!r.test(version)) { return null } @@ -4257,7 +4333,7 @@ function SemVer (version, options) { this.options = options this.loose = !!options.loose - var m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]) + var m = version.trim().match(options.loose ? safeRe[t.LOOSE] : safeRe[t.FULL]) if (!m) { throw new TypeError('Invalid Version: ' + version) @@ -4702,6 +4778,7 @@ function Comparator (comp, options) { return new Comparator(comp, options) } + comp = comp.trim().split(/\s+/).join(' ') debug('comparator', comp, options) this.options = options this.loose = !!options.loose @@ -4718,7 +4795,7 @@ function Comparator (comp, options) { var ANY = {} Comparator.prototype.parse = function (comp) { - var r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR] + var r = this.options.loose ? safeRe[t.COMPARATORLOOSE] : safeRe[t.COMPARATOR] var m = comp.match(r) if (!m) { @@ -4842,9 +4919,16 @@ function Range (range, options) { this.loose = !!options.loose this.includePrerelease = !!options.includePrerelease - // First, split based on boolean or || + // First reduce all whitespace as much as possible so we do not have to rely + // on potentially slow regexes like \s*. This is then stored and used for + // future error messages as well. this.raw = range - this.set = range.split(/\s*\|\|\s*/).map(function (range) { + .trim() + .split(/\s+/) + .join(' ') + + // First, split based on boolean or || + this.set = this.raw.split('||').map(function (range) { return this.parseRange(range.trim()) }, this).filter(function (c) { // throw out any that are not relevant for whatever reason @@ -4852,7 +4936,7 @@ function Range (range, options) { }) if (!this.set.length) { - throw new TypeError('Invalid SemVer Range: ' + range) + throw new TypeError('Invalid SemVer Range: ' + this.raw) } this.format() @@ -4871,20 +4955,19 @@ Range.prototype.toString = function () { Range.prototype.parseRange = function (range) { var loose = this.options.loose - range = range.trim() // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4` - var hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE] + var hr = loose ? safeRe[t.HYPHENRANGELOOSE] : safeRe[t.HYPHENRANGE] range = range.replace(hr, hyphenReplace) debug('hyphen replace', range) // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5` - range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace) - debug('comparator trim', range, re[t.COMPARATORTRIM]) + range = range.replace(safeRe[t.COMPARATORTRIM], comparatorTrimReplace) + debug('comparator trim', range, safeRe[t.COMPARATORTRIM]) // `~ 1.2.3` => `~1.2.3` - range = range.replace(re[t.TILDETRIM], tildeTrimReplace) + range = range.replace(safeRe[t.TILDETRIM], tildeTrimReplace) // `^ 1.2.3` => `^1.2.3` - range = range.replace(re[t.CARETTRIM], caretTrimReplace) + range = range.replace(safeRe[t.CARETTRIM], caretTrimReplace) // normalize spaces range = range.split(/\s+/).join(' ') @@ -4892,7 +4975,7 @@ Range.prototype.parseRange = function (range) { // At this point, the range is completely trimmed and // ready to be split into comparators. - var compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR] + var compRe = loose ? safeRe[t.COMPARATORLOOSE] : safeRe[t.COMPARATOR] var set = range.split(' ').map(function (comp) { return parseComparator(comp, this.options) }, this).join(' ').split(/\s+/) @@ -4992,7 +5075,7 @@ function replaceTildes (comp, options) { } function replaceTilde (comp, options) { - var r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE] + var r = options.loose ? safeRe[t.TILDELOOSE] : safeRe[t.TILDE] return comp.replace(r, function (_, M, m, p, pr) { debug('tilde', comp, _, M, m, p, pr) var ret @@ -5033,7 +5116,7 @@ function replaceCarets (comp, options) { function replaceCaret (comp, options) { debug('caret', comp, options) - var r = options.loose ? re[t.CARETLOOSE] : re[t.CARET] + var r = options.loose ? safeRe[t.CARETLOOSE] : safeRe[t.CARET] return comp.replace(r, function (_, M, m, p, pr) { debug('caret', comp, _, M, m, p, pr) var ret @@ -5092,7 +5175,7 @@ function replaceXRanges (comp, options) { function replaceXRange (comp, options) { comp = comp.trim() - var r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE] + var r = options.loose ? safeRe[t.XRANGELOOSE] : safeRe[t.XRANGE] return comp.replace(r, function (ret, gtlt, M, m, p, pr) { debug('xRange', comp, ret, gtlt, M, m, p, pr) var xM = isX(M) @@ -5167,7 +5250,7 @@ function replaceXRange (comp, options) { function replaceStars (comp, options) { debug('replaceStars', comp, options) // Looseness is ignored here. star is always as loose as it gets! - return comp.trim().replace(re[t.STAR], '') + return comp.trim().replace(safeRe[t.STAR], '') } // This function is passed to string.replace(re[t.HYPHENRANGE]) @@ -5493,7 +5576,7 @@ function coerce (version, options) { var match = null if (!options.rtl) { - match = version.match(re[t.COERCE]) + match = version.match(safeRe[t.COERCE]) } else { // Find the right-most coercible string that does not share // a terminus with a more left-ward coercible string. @@ -5504,17 +5587,17 @@ function coerce (version, options) { // Stop when we get a match that ends at the string end, since no // coercible string can be more right-ward without the same terminus. var next - while ((next = re[t.COERCERTL].exec(version)) && + while ((next = safeRe[t.COERCERTL].exec(version)) && (!match || match.index + match[0].length !== version.length) ) { if (!match || next.index + next[0].length !== match.index + match[0].length) { match = next } - re[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length + safeRe[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length } // leave it in a clean state - re[t.COERCERTL].lastIndex = -1 + safeRe[t.COERCERTL].lastIndex = -1 } if (match === null) { @@ -10955,7 +11038,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.stringify = exports.parse = exports.isTraversal = void 0; -__exportStar(__nccwpck_require__(8752), exports); +__exportStar(__nccwpck_require__(3172), exports); var parse_1 = __nccwpck_require__(7255); Object.defineProperty(exports, "isTraversal", ({ enumerable: true, get: function () { return parse_1.isTraversal; } })); Object.defineProperty(exports, "parse", ({ enumerable: true, get: function () { return parse_1.parse; } })); @@ -10972,7 +11055,7 @@ Object.defineProperty(exports, "stringify", ({ enumerable: true, get: function ( Object.defineProperty(exports, "__esModule", ({ value: true })); exports.parse = exports.isTraversal = void 0; -var types_1 = __nccwpck_require__(8752); +var types_1 = __nccwpck_require__(3172); var reName = /^[^\\#]?(?:\\(?:[\da-f]{1,6}\s?|.)|[\w\-\u00b0-\uFFFF])+/; var reEscape = /\\([\da-f]{1,6}\s?|(\s)|.)/gi; var actionTypes = new Map([ @@ -11414,7 +11497,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.stringify = void 0; -var types_1 = __nccwpck_require__(8752); +var types_1 = __nccwpck_require__(3172); var attribValChars = ["\\", '"']; var pseudoValChars = __spreadArray(__spreadArray([], attribValChars, true), ["(", ")"], false); var charsToEscapeInAttributeValue = new Set(attribValChars.map(function (c) { return c.charCodeAt(0); })); @@ -11544,7 +11627,7 @@ function escapeName(str, charsToEscape) { /***/ }), -/***/ 8752: +/***/ 3172: /***/ ((__unused_webpack_module, exports) => { "use strict"; @@ -12750,7 +12833,7 @@ function getRssFeed(feedRoot) { addConditionally(entry, "title", "title", children); addConditionally(entry, "link", "link", children); addConditionally(entry, "description", "description", children); - var pubDate = fetch("pubDate", children); + var pubDate = fetch("pubDate", children) || fetch("dc:date", children); if (pubDate) entry.pubDate = new Date(pubDate); return entry; @@ -12867,11 +12950,12 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.uniqueSort = exports.compareDocumentPosition = exports.DocumentPosition = exports.removeSubsets = void 0; var domhandler_1 = __nccwpck_require__(4038); /** - * Given an array of nodes, remove any member that is contained by another. + * Given an array of nodes, remove any member that is contained by another + * member. * * @category Helpers * @param nodes Nodes to filter. - * @returns Remaining nodes that aren't subtrees of each other. + * @returns Remaining nodes that aren't contained by other nodes. */ function removeSubsets(nodes) { var idx = nodes.length; @@ -12913,8 +12997,8 @@ var DocumentPosition; DocumentPosition[DocumentPosition["CONTAINED_BY"] = 16] = "CONTAINED_BY"; })(DocumentPosition = exports.DocumentPosition || (exports.DocumentPosition = {})); /** - * Compare the position of one node against another node in any other document. - * The return value is a bitmask with the values from {@link DocumentPosition}. + * Compare the position of one node against another node in any other document, + * returning a bitmask with the values from {@link DocumentPosition}. * * Document order: * > There is an ordering, document order, defined on all the nodes in the @@ -12979,9 +13063,9 @@ function compareDocumentPosition(nodeA, nodeB) { } exports.compareDocumentPosition = compareDocumentPosition; /** - * Sort an array of nodes based on their relative position in the document and - * remove any duplicate nodes. If the array contains nodes that do not belong to - * the same document, sort order is unspecified. + * Sort an array of nodes based on their relative position in the document, + * removing any duplicate nodes. If the array contains nodes that do not belong + * to the same document, sort order is unspecified. * * @category Helpers * @param nodes Array of DOM nodes. @@ -13055,6 +13139,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.getElementsByTagType = exports.getElementsByTagName = exports.getElementById = exports.getElements = exports.testElement = void 0; var domhandler_1 = __nccwpck_require__(4038); var querying_js_1 = __nccwpck_require__(9908); +/** + * A map of functions to check nodes against. + */ var Checks = { tag_name: function (name) { if (typeof name === "function") { @@ -13079,6 +13166,9 @@ var Checks = { }, }; /** + * Returns a function to check whether a node has an attribute with a particular + * value. + * * @param attrib Attribute to check. * @param value Attribute value to look for. * @returns A function to check whether the a node has an attribute with a @@ -13091,6 +13181,9 @@ function getAttribCheck(attrib, value) { return function (elem) { return (0, domhandler_1.isTag)(elem) && elem.attribs[attrib] === value; }; } /** + * Returns a function that returns `true` if either of the input functions + * returns `true` for a node. + * * @param a First function to combine. * @param b Second function to combine. * @returns A function taking a node and returning `true` if either of the input @@ -13100,9 +13193,12 @@ function combineFuncs(a, b) { return function (elem) { return a(elem) || b(elem); }; } /** + * Returns a function that executes all checks in `options` and returns `true` + * if any of them match a node. + * * @param options An object describing nodes to look for. - * @returns A function executing all checks in `options` and returning `true` if - * any of them match a node. + * @returns A function that executes all checks in `options` and returns `true` + * if any of them match a node. */ function compileTest(options) { var funcs = Object.keys(options).map(function (key) { @@ -13114,6 +13210,8 @@ function compileTest(options) { return funcs.length === 0 ? null : funcs.reduce(combineFuncs); } /** + * Checks whether a node matches the description in `options`. + * * @category Legacy Query Functions * @param options An object describing nodes to look for. * @param node The element to test. @@ -13125,6 +13223,8 @@ function testElement(options, node) { } exports.testElement = testElement; /** + * Returns all nodes that match `options`. + * * @category Legacy Query Functions * @param options An object describing nodes to look for. * @param nodes Nodes to search through. @@ -13139,6 +13239,8 @@ function getElements(options, nodes, recurse, limit) { } exports.getElements = getElements; /** + * Returns the node with the supplied ID. + * * @category Legacy Query Functions * @param id The unique ID attribute value to look for. * @param nodes Nodes to search through. @@ -13153,6 +13255,8 @@ function getElementById(id, nodes, recurse) { } exports.getElementById = getElementById; /** + * Returns all nodes with the supplied `tagName`. + * * @category Legacy Query Functions * @param tagName Tag name to search for. * @param nodes Nodes to search through. @@ -13167,6 +13271,8 @@ function getElementsByTagName(tagName, nodes, recurse, limit) { } exports.getElementsByTagName = getElementsByTagName; /** + * Returns all nodes with the supplied `type`. + * * @category Legacy Query Functions * @param type Element type to look for. * @param nodes Nodes to search through. @@ -13204,8 +13310,14 @@ function removeElement(elem) { elem.next.prev = elem.prev; if (elem.parent) { var childs = elem.parent.children; - childs.splice(childs.lastIndexOf(elem), 1); + var childsIndex = childs.lastIndexOf(elem); + if (childsIndex >= 0) { + childs.splice(childsIndex, 1); + } } + elem.next = null; + elem.prev = null; + elem.parent = null; } exports.removeElement = removeElement; /** @@ -13236,15 +13348,15 @@ exports.replaceElement = replaceElement; * Append a child to an element. * * @category Manipulation - * @param elem The element to append to. + * @param parent The element to append to. * @param child The element to be added as a child. */ -function appendChild(elem, child) { +function appendChild(parent, child) { removeElement(child); child.next = null; - child.parent = elem; - if (elem.children.push(child) > 1) { - var sibling = elem.children[elem.children.length - 2]; + child.parent = parent; + if (parent.children.push(child) > 1) { + var sibling = parent.children[parent.children.length - 2]; sibling.next = child; child.prev = sibling; } @@ -13284,15 +13396,15 @@ exports.append = append; * Prepend a child to an element. * * @category Manipulation - * @param elem The element to prepend before. + * @param parent The element to prepend before. * @param child The element to be added as a child. */ -function prependChild(elem, child) { +function prependChild(parent, child) { removeElement(child); - child.parent = elem; + child.parent = parent; child.prev = null; - if (elem.children.unshift(child) !== 1) { - var sibling = elem.children[1]; + if (parent.children.unshift(child) !== 1) { + var sibling = parent.children[1]; sibling.prev = child; child.next = sibling; } @@ -13337,7 +13449,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.findAll = exports.existsOne = exports.findOne = exports.findOneChild = exports.find = exports.filter = void 0; var domhandler_1 = __nccwpck_require__(4038); /** - * Search a node and its children for nodes passing a test function. + * Search a node and its children for nodes passing a test function. If `node` is not an array, it will be wrapped in one. * * @category Querying * @param test Function to test nodes on. @@ -13349,13 +13461,11 @@ var domhandler_1 = __nccwpck_require__(4038); function filter(test, node, recurse, limit) { if (recurse === void 0) { recurse = true; } if (limit === void 0) { limit = Infinity; } - if (!Array.isArray(node)) - node = [node]; - return find(test, node, recurse, limit); + return find(test, Array.isArray(node) ? node : [node], recurse, limit); } exports.filter = filter; /** - * Search an array of node and its children for nodes passing a test function. + * Search an array of nodes and their children for nodes passing a test function. * * @category Querying * @param test Function to test nodes on. @@ -13366,26 +13476,42 @@ exports.filter = filter; */ function find(test, nodes, recurse, limit) { var result = []; - for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) { - var elem = nodes_1[_i]; + /** Stack of the arrays we are looking at. */ + var nodeStack = [nodes]; + /** Stack of the indices within the arrays. */ + var indexStack = [0]; + for (;;) { + // First, check if the current array has any more elements to look at. + if (indexStack[0] >= nodeStack[0].length) { + // If we have no more arrays to look at, we are done. + if (indexStack.length === 1) { + return result; + } + // Otherwise, remove the current array from the stack. + nodeStack.shift(); + indexStack.shift(); + // Loop back to the start to continue with the next array. + continue; + } + var elem = nodeStack[0][indexStack[0]++]; if (test(elem)) { result.push(elem); if (--limit <= 0) - break; + return result; } if (recurse && (0, domhandler_1.hasChildren)(elem) && elem.children.length > 0) { - var children = find(test, elem.children, recurse, limit); - result.push.apply(result, children); - limit -= children.length; - if (limit <= 0) - break; + /* + * Add the children to the stack. We are depth-first, so this is + * the next array we look at. + */ + indexStack.unshift(0); + nodeStack.unshift(elem.children); } } - return result; } exports.find = find; /** - * Finds the first element inside of an array that matches a test function. + * Finds the first element inside of an array that matches a test function. This is an alias for `Array.prototype.find`. * * @category Querying * @param test Function to test nodes on. @@ -13402,29 +13528,31 @@ exports.findOneChild = findOneChild; * * @category Querying * @param test Function to test nodes on. - * @param nodes Array of nodes to search. + * @param nodes Node or array of nodes to search. * @param recurse Also consider child nodes. - * @returns The first child node that passes `test`. + * @returns The first node that passes `test`. */ function findOne(test, nodes, recurse) { if (recurse === void 0) { recurse = true; } var elem = null; for (var i = 0; i < nodes.length && !elem; i++) { - var checked = nodes[i]; - if (!(0, domhandler_1.isTag)(checked)) { + var node = nodes[i]; + if (!(0, domhandler_1.isTag)(node)) { continue; } - else if (test(checked)) { - elem = checked; + else if (test(node)) { + elem = node; } - else if (recurse && checked.children.length > 0) { - elem = findOne(test, checked.children, true); + else if (recurse && node.children.length > 0) { + elem = findOne(test, node.children, true); } } return elem; } exports.findOne = findOne; /** + * Checks if a tree of nodes contains at least one node passing a test. + * * @category Querying * @param test Function to test nodes on. * @param nodes Array of nodes to search. @@ -13433,14 +13561,12 @@ exports.findOne = findOne; function existsOne(test, nodes) { return nodes.some(function (checked) { return (0, domhandler_1.isTag)(checked) && - (test(checked) || - (checked.children.length > 0 && - existsOne(test, checked.children))); + (test(checked) || existsOne(test, checked.children)); }); } exports.existsOne = existsOne; /** - * Search and array of nodes and its children for elements passing a test function. + * Search an array of nodes and their children for elements passing a test function. * * Same as `find`, but limited to elements and with less options, leading to reduced complexity. * @@ -13450,19 +13576,30 @@ exports.existsOne = existsOne; * @returns All nodes passing `test`. */ function findAll(test, nodes) { - var _a; var result = []; - var stack = nodes.filter(domhandler_1.isTag); - var elem; - while ((elem = stack.shift())) { - var children = (_a = elem.children) === null || _a === void 0 ? void 0 : _a.filter(domhandler_1.isTag); - if (children && children.length > 0) { - stack.unshift.apply(stack, children); + var nodeStack = [nodes]; + var indexStack = [0]; + for (;;) { + if (indexStack[0] >= nodeStack[0].length) { + if (nodeStack.length === 1) { + return result; + } + // Otherwise, remove the current array from the stack. + nodeStack.shift(); + indexStack.shift(); + // Loop back to the start to continue with the next array. + continue; } + var elem = nodeStack[0][indexStack[0]++]; + if (!(0, domhandler_1.isTag)(elem)) + continue; if (test(elem)) result.push(elem); + if (elem.children.length > 0) { + indexStack.unshift(0); + nodeStack.unshift(elem.children); + } } - return result; } exports.findAll = findAll; //# sourceMappingURL=querying.js.map @@ -13507,7 +13644,7 @@ function getInnerHTML(node, options) { } exports.getInnerHTML = getInnerHTML; /** - * Get a node's inner text. Same as `textContent`, but inserts newlines for `
` tags. + * Get a node's inner text. Same as `textContent`, but inserts newlines for `
` tags. Ignores comments. * * @category Stringify * @deprecated Use `textContent` instead. @@ -13527,7 +13664,7 @@ function getText(node) { } exports.getText = getText; /** - * Get a node's text content. + * Get a node's text content. Ignores comments. * * @category Stringify * @param node Node to get the text content of. @@ -13546,7 +13683,7 @@ function textContent(node) { } exports.textContent = textContent; /** - * Get a node's inner text. + * Get a node's inner text, ignoring `