Skip to content

Commit

Permalink
Update dev-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Mar 12, 2024
1 parent 411516a commit 9308eb7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 60 deletions.
77 changes: 38 additions & 39 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

/**
* @typedef {(...args: Array<any>) => string} MessageFunction
* @typedef {(...parameters: Array<any>) => string} MessageFunction
*/

// Manually “tree shaken” from:
Expand Down Expand Up @@ -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 &&
Expand All @@ -203,19 +203,19 @@ 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 "./"' : ''}`
)
}

return `Invalid "${
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
)
Expand Down Expand Up @@ -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}` : ''
}`
},
Expand All @@ -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
)
Expand Down Expand Up @@ -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<any>) => Error}
* @param {ErrorConstructor} constructor
* @returns {new (...parameters: Array<any>) => 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)
}

/**
Expand All @@ -342,15 +342,15 @@ function makeNodeErrorWithCode(Base, key) {
// @ts-expect-error It’s a Node error.
return NodeError
/**
* @param {Array<unknown>} args
* @param {Array<unknown>} 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.
Expand Down Expand Up @@ -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
}
Expand All @@ -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(
Expand All @@ -439,35 +438,35 @@ const captureLargerStackTrace = hideStackFrames(

/**
* @param {string} key
* @param {Array<unknown>} args
* @param {Array<unknown>} 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)
}

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/get-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -114,7 +114,7 @@ function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
return 'commonjs'
}

if (ext === '') {
if (value === '') {
const packageType = getPackageType(url)

// Legacy behavior
Expand All @@ -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
Expand All @@ -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() {
Expand Down
28 changes: 14 additions & 14 deletions lib/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} */
const emittedPackageWarnings = new Set()

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9308eb7

Please # to comment.