diff options
Diffstat (limited to 'ext/node/polyfills/internal/errors.ts')
-rw-r--r-- | ext/node/polyfills/internal/errors.ts | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/ext/node/polyfills/internal/errors.ts b/ext/node/polyfills/internal/errors.ts index 2ba7ec28e..7f7ce9d3a 100644 --- a/ext/node/polyfills/internal/errors.ts +++ b/ext/node/polyfills/internal/errors.ts @@ -2421,7 +2421,7 @@ export class ERR_INVALID_PACKAGE_TARGET extends NodeError { if (key === ".") { assert(isImport === false); msg = `Invalid "exports" main target ${JSON.stringify(target)} defined ` + - `in the package config ${pkgPath}package.json${ + `in the package config ${displayJoin(pkgPath, "package.json")}${ base ? ` imported from ${base}` : "" }${relError ? '; targets must start with "./"' : ""}`; } else { @@ -2429,9 +2429,11 @@ export class ERR_INVALID_PACKAGE_TARGET extends NodeError { JSON.stringify( target, ) - } defined for '${key}' in the package config ${pkgPath}package.json${ - base ? ` imported from ${base}` : "" - }${relError ? '; targets must start with "./"' : ""}`; + } defined for '${key}' in the package config ${ + displayJoin(pkgPath, "package.json") + }${base ? ` imported from ${base}` : ""}${ + relError ? '; targets must start with "./"' : "" + }`; } super("ERR_INVALID_PACKAGE_TARGET", msg); } @@ -2444,7 +2446,9 @@ export class ERR_PACKAGE_IMPORT_NOT_DEFINED extends NodeTypeError { base: string, ) { const msg = `Package import specifier "${specifier}" is not defined${ - packagePath ? ` in package ${packagePath}package.json` : "" + packagePath + ? ` in package ${displayJoin(packagePath, "package.json")}` + : "" } imported from ${base}`; super("ERR_PACKAGE_IMPORT_NOT_DEFINED", msg); @@ -2455,14 +2459,13 @@ export class ERR_PACKAGE_PATH_NOT_EXPORTED extends NodeError { constructor(subpath: string, pkgPath: string, basePath?: string) { let msg: string; if (subpath === ".") { - msg = `No "exports" main defined in ${pkgPath}package.json${ - basePath ? ` imported from ${basePath}` : "" - }`; + msg = `No "exports" main defined in ${ + displayJoin(pkgPath, "package.json") + }${basePath ? ` imported from ${basePath}` : ""}`; } else { - msg = - `Package subpath '${subpath}' is not defined by "exports" in ${pkgPath}package.json${ - basePath ? ` imported from ${basePath}` : "" - }`; + msg = `Package subpath '${subpath}' is not defined by "exports" in ${ + displayJoin(pkgPath, "package.json") + }${basePath ? ` imported from ${basePath}` : ""}`; } super("ERR_PACKAGE_PATH_NOT_EXPORTED", msg); @@ -2621,6 +2624,12 @@ function determineSpecificType(value: any) { return `type ${typeof value} (${inspected})`; } +// Non-robust path join +function displayJoin(dir: string, fileName: string) { + const sep = dir.includes("\\") ? "\\" : "/"; + return dir.endsWith(sep) ? dir + fileName : dir + sep + fileName; +} + export { codes, genericNodeError, hideStackFrames }; export default { |