From 9308eb7830db35e30a900945d48229d71a2b4d70 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 12 Mar 2024 12:39:23 +0100 Subject: [PATCH] Update dev-dependencies --- lib/errors.js | 77 +++++++++++++++++++++++------------------------ lib/get-format.js | 10 +++--- lib/resolve.js | 28 ++++++++--------- package.json | 4 +-- 4 files changed, 59 insertions(+), 60 deletions(-) diff --git a/lib/errors.js b/lib/errors.js index 66e026e..83a1f68 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -10,7 +10,7 @@ */ /** - * @typedef {(...args: Array) => string} MessageFunction + * @typedef {(...parameters: Array) => string} MessageFunction */ // Manually “tree shaken” from: @@ -187,14 +187,14 @@ codes.ERR_INVALID_PACKAGE_CONFIG = createError( codes.ERR_INVALID_PACKAGE_TARGET = createError( 'ERR_INVALID_PACKAGE_TARGET', /** - * @param {string} pkgPath + * @param {string} packagePath * @param {string} key * @param {unknown} target * @param {boolean} [isImport=false] * @param {string} [base] */ - (pkgPath, key, target, isImport = false, base = undefined) => { - const relError = + (packagePath, key, target, isImport = false, base = undefined) => { + const relatedError = typeof target === 'string' && !isImport && target.length > 0 && @@ -203,9 +203,9 @@ codes.ERR_INVALID_PACKAGE_TARGET = createError( assert(isImport === false) return ( `Invalid "exports" main target ${JSON.stringify(target)} defined ` + - `in the package config ${pkgPath}package.json${ + `in the package config ${packagePath}package.json${ base ? ` imported from ${base}` : '' - }${relError ? '; targets must start with "./"' : ''}` + }${relatedError ? '; targets must start with "./"' : ''}` ) } @@ -213,9 +213,9 @@ codes.ERR_INVALID_PACKAGE_TARGET = createError( isImport ? 'imports' : 'exports' }" target ${JSON.stringify( target - )} defined for '${key}' in the package config ${pkgPath}package.json${ + )} defined for '${key}' in the package config ${packagePath}package.json${ base ? ` imported from ${base}` : '' - }${relError ? '; targets must start with "./"' : ''}` + }${relatedError ? '; targets must start with "./"' : ''}` }, Error ) @@ -259,16 +259,16 @@ codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError( codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError( 'ERR_PACKAGE_PATH_NOT_EXPORTED', /** - * @param {string} pkgPath + * @param {string} packagePath * @param {string} subpath * @param {string} [base] */ - (pkgPath, subpath, base = undefined) => { + (packagePath, subpath, base = undefined) => { if (subpath === '.') - return `No "exports" main defined in ${pkgPath}package.json${ + return `No "exports" main defined in ${packagePath}package.json${ base ? ` imported from ${base}` : '' }` - return `Package subpath '${subpath}' is not defined by "exports" in ${pkgPath}package.json${ + return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${ base ? ` imported from ${base}` : '' }` }, @@ -285,11 +285,11 @@ codes.ERR_UNSUPPORTED_DIR_IMPORT = createError( codes.ERR_UNKNOWN_FILE_EXTENSION = createError( 'ERR_UNKNOWN_FILE_EXTENSION', /** - * @param {string} ext + * @param {string} extension * @param {string} path */ - (ext, path) => { - return `Unknown file extension "${ext}" for ${path}` + (extension, path) => { + return `Unknown file extension "${extension}" for ${path}` }, TypeError ) @@ -322,15 +322,15 @@ codes.ERR_INVALID_ARG_VALUE = createError( * *only* to allow for testing. * @param {string} sym * @param {MessageFunction | string} value - * @param {ErrorConstructor} def - * @returns {new (...args: Array) => Error} + * @param {ErrorConstructor} constructor + * @returns {new (...parameters: Array) => Error} */ -function createError(sym, value, def) { +function createError(sym, value, constructor) { // Special case for SystemError that formats the error message differently // The SystemErrors only have SystemError as their base classes. messages.set(sym, value) - return makeNodeErrorWithCode(def, sym) + return makeNodeErrorWithCode(constructor, sym) } /** @@ -342,15 +342,15 @@ function makeNodeErrorWithCode(Base, key) { // @ts-expect-error It’s a Node error. return NodeError /** - * @param {Array} args + * @param {Array} parameters */ - function NodeError(...args) { + function NodeError(...parameters) { const limit = Error.stackTraceLimit if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0 const error = new Base() // Reset the limit and setting the name property. if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit - const message = getMessage(key, args, error) + const message = getMessage(key, parameters, error) Object.defineProperties(error, { // Note: no need to implement `kIsNodeError` symbol, would be hard, // probably. @@ -385,7 +385,6 @@ function isErrorStackTraceLimitWritable() { // Do no touch Error.stackTraceLimit as V8 would attempt to install // it again during deserialization. try { - // @ts-expect-error: not in types? if (v8.startupSnapshot.isBuildingSnapshot()) { return false } @@ -403,16 +402,16 @@ function isErrorStackTraceLimitWritable() { /** * This function removes unnecessary frames from Node.js core errors. - * @template {(...args: unknown[]) => unknown} T - * @param {T} fn + * @template {(...parameters: unknown[]) => unknown} T + * @param {T} wrappedFunction * @returns {T} */ -function hideStackFrames(fn) { +function hideStackFrames(wrappedFunction) { // We rename the functions that will be hidden to cut off the stacktrace // at the outermost one - const hidden = nodeInternalPrefix + fn.name - Object.defineProperty(fn, 'name', {value: hidden}) - return fn + const hidden = nodeInternalPrefix + wrappedFunction.name + Object.defineProperty(wrappedFunction, 'name', {value: hidden}) + return wrappedFunction } const captureLargerStackTrace = hideStackFrames( @@ -439,35 +438,35 @@ const captureLargerStackTrace = hideStackFrames( /** * @param {string} key - * @param {Array} args + * @param {Array} parameters * @param {Error} self * @returns {string} */ -function getMessage(key, args, self) { +function getMessage(key, parameters, self) { const message = messages.get(key) assert(message !== undefined, 'expected `message` to be found') if (typeof message === 'function') { assert( - message.length <= args.length, // Default options do not count. - `Code: ${key}; The provided arguments length (${args.length}) does not ` + + message.length <= parameters.length, // Default options do not count. + `Code: ${key}; The provided arguments length (${parameters.length}) does not ` + `match the required ones (${message.length}).` ) - return Reflect.apply(message, self, args) + return Reflect.apply(message, self, parameters) } const regex = /%[dfijoOs]/g let expectedLength = 0 while (regex.exec(message) !== null) expectedLength++ assert( - expectedLength === args.length, - `Code: ${key}; The provided arguments length (${args.length}) does not ` + + expectedLength === parameters.length, + `Code: ${key}; The provided arguments length (${parameters.length}) does not ` + `match the required ones (${expectedLength}).` ) - if (args.length === 0) return message + if (parameters.length === 0) return message - args.unshift(message) - return Reflect.apply(format, null, args) + parameters.unshift(message) + return Reflect.apply(format, null, parameters) } /** diff --git a/lib/get-format.js b/lib/get-format.js index a931fdf..e8c73cf 100644 --- a/lib/get-format.js +++ b/lib/get-format.js @@ -102,9 +102,9 @@ function extname(url) { * @type {ProtocolHandler} */ function getFileProtocolModuleFormat(url, _context, ignoreErrors) { - const ext = extname(url) + const value = extname(url) - if (ext === '.js') { + if (value === '.js') { const packageType = getPackageType(url) if (packageType !== 'none') { @@ -114,7 +114,7 @@ function getFileProtocolModuleFormat(url, _context, ignoreErrors) { return 'commonjs' } - if (ext === '') { + if (value === '') { const packageType = getPackageType(url) // Legacy behavior @@ -127,7 +127,7 @@ function getFileProtocolModuleFormat(url, _context, ignoreErrors) { return 'module' } - const format = extensionFormatMap[ext] + const format = extensionFormatMap[value] if (format) return format // Explicit undefined return indicates load hook should rerun format check @@ -136,7 +136,7 @@ function getFileProtocolModuleFormat(url, _context, ignoreErrors) { } const filepath = fileURLToPath(url) - throw new ERR_UNKNOWN_FILE_EXTENSION(ext, filepath) + throw new ERR_UNKNOWN_FILE_EXTENSION(value, filepath) } function getHttpProtocolModuleFormat() { diff --git a/lib/resolve.js b/lib/resolve.js index a1c87f5..59b6390 100644 --- a/lib/resolve.js +++ b/lib/resolve.js @@ -40,7 +40,7 @@ const deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i const invalidPackageNameRegEx = /^\.|%|\\/ const patternRegEx = /\*/g -const encodedSepRegEx = /%2f|%5c/i +const encodedSeparatorRegEx = /%2f|%5c/i /** @type {Set} */ const emittedPackageWarnings = new Set() @@ -104,21 +104,21 @@ function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) { const format = defaultGetFormatWithoutErrors(url, {parentURL: base.href}) if (format !== 'module') return const urlPath = fileURLToPath(url.href) - const pkgPath = fileURLToPath(new URL('.', packageJsonUrl)) + const packagePath = fileURLToPath(new URL('.', packageJsonUrl)) const basePath = fileURLToPath(base) if (!main) { process.emitWarning( - `No "main" or "exports" field defined in the package.json for ${pkgPath} resolving the main entry point "${urlPath.slice( - pkgPath.length + `No "main" or "exports" field defined in the package.json for ${packagePath} resolving the main entry point "${urlPath.slice( + packagePath.length )}", imported from ${basePath}.\nDefault "index" lookups for the main are deprecated for ES modules.`, 'DeprecationWarning', 'DEP0151' ) - } else if (path.resolve(pkgPath, main) !== urlPath) { + } else if (path.resolve(packagePath, main) !== urlPath) { process.emitWarning( - `Package ${pkgPath} has a "main" field set to "${main}", ` + + `Package ${packagePath} has a "main" field set to "${main}", ` + `excluding the full filename and extension to the resolved file at "${urlPath.slice( - pkgPath.length + packagePath.length )}", imported from ${basePath}.\n Automatic extension resolution of the "main" field is ` + 'deprecated for ES modules.', 'DeprecationWarning', @@ -227,7 +227,7 @@ function legacyMainResolve(packageJsonUrl, packageConfig, base) { * @returns {URL} */ function finalizeResolution(resolved, base, preserveSymlinks) { - if (encodedSepRegEx.exec(resolved.pathname) !== null) { + if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) { throw new ERR_INVALID_MODULE_SPECIFIER( resolved.pathname, 'must not include encoded "/" or "\\" characters', @@ -644,13 +644,13 @@ function isConditionalExportsMainSugar(exports, packageJsonUrl, base) { const keys = Object.getOwnPropertyNames(exports) let isConditionalSugar = false let i = 0 - let j = -1 - while (++j < keys.length) { - const key = keys[j] - const curIsConditionalSugar = key === '' || key[0] !== '.' + let keyIndex = -1 + while (++keyIndex < keys.length) { + const key = keys[keyIndex] + const currentIsConditionalSugar = key === '' || key[0] !== '.' if (i++ === 0) { - isConditionalSugar = curIsConditionalSugar - } else if (isConditionalSugar !== curIsConditionalSugar) { + isConditionalSugar = currentIsConditionalSugar + } else if (isConditionalSugar !== currentIsConditionalSugar) { throw new ERR_INVALID_PACKAGE_CONFIG( fileURLToPath(packageJsonUrl), base, diff --git a/package.json b/package.json index 75b229b..103d864 100644 --- a/package.json +++ b/package.json @@ -31,14 +31,14 @@ "devDependencies": { "@types/node": "^20.0.0", "@types/semver": "^7.0.0", - "c8": "^8.0.0", + "c8": "^9.0.0", "prettier": "^3.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", "semver": "^7.0.0", "type-coverage": "^2.0.0", "typescript": "^5.0.0", - "xo": "^0.56.0" + "xo": "^0.58.0" }, "scripts": { "prepack": "npm run generate && npm run build && npm run format",