| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ca5ebcf commit eaf841d
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ const { | |||
| 20 | 20 | ObjectDefineProperty, | |
| 21 | 21 | ObjectKeys, | |
| 22 | 22 | StringPrototypeSlice, | |
| 23 | + StringPrototypeStartsWith, | ||
| 23 | 24 | Symbol, | |
| 24 | 25 | SymbolFor, | |
| 25 | 26 | WeakMap, | |
@@ -1104,18 +1105,28 @@ E('ERR_INVALID_PACKAGE_CONFIG', (path, message, hasMessage = true) => { | |||
| 1104 | 1105 | }, Error); | |
| 1105 | 1106 | E('ERR_INVALID_PACKAGE_TARGET', | |
| 1106 | 1107 | (pkgPath, key, subpath, target, base = undefined) => { | |
| 1108 | + const relError = typeof target === 'string' && | ||
| 1109 | + target.length && !StringPrototypeStartsWith(target, './'); | ||
| 1107 | 1110 | if (key === null) { | |
| 1108 | 1111 | if (subpath !== '') { | |
| 1109 | 1112 | return `Invalid "exports" target ${JSONStringify(target)} defined ` + | |
| 1110 | 1113 | `for '${subpath}' in the package config ${pkgPath} imported from ` + | |
| 1111 | - base; | ||
| 1114 | + `${base}.${relError ? '; targets must start with "./"' : ''}`; | ||
| 1112 | 1115 | } else { | |
| 1113 | 1116 | return `Invalid "exports" main target ${target} defined in the ` + | |
| 1114 | - `package config ${pkgPath} imported from ${base}.`; | ||
| 1117 | + `package config ${pkgPath} imported from ${base}${relError ? | ||
| 1118 | + '; targets must start with "./"' : ''}`; | ||
| 1115 | 1119 | } | |
| 1116 | 1120 | } else if (key === '.') { | |
| 1117 | 1121 | return `Invalid "exports" main target ${JSONStringify(target)} defined ` + | |
| 1118 | - `in the package config ${pkgPath}${sep}package.json`; | ||
| 1122 | + `in the package config ${pkgPath}${sep}package.json${relError ? | ||
| 1123 | + '; targets must start with "./"' : ''}`; | ||
| 1124 | + } else if (typeof target === 'string' && target !== '' && | ||
| 1125 | + !StringPrototypeStartsWith(target, './')) { | ||
| 1126 | + return `Invalid "exports" target ${JSONStringify(target)} defined for '${ | ||
| 1127 | + StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` + | ||
| 1128 | + `package config ${pkgPath}${sep}package.json; ` + | ||
| 1129 | + 'targets must start with "./"'; | ||
| 1119 | 1130 | } else { | |
| 1120 | 1131 | return `Invalid "exports" target ${JSONStringify(target)} defined for '${ | |
| 1121 | 1132 | StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,6 +78,7 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; | |||
| 78 | 78 | ['pkgexports/null', './null'], | |
| 79 | 79 | ['pkgexports/invalid2', './invalid2'], | |
| 80 | 80 | ['pkgexports/invalid3', './invalid3'], | |
| 81 | + ['pkgexports/invalid5', 'invalid5'], | ||
| 81 | 82 | // Missing / invalid fallbacks | |
| 82 | 83 | ['pkgexports/nofallback1', './nofallback1'], | |
| 83 | 84 | ['pkgexports/nofallback2', './nofallback2'], | |
@@ -106,6 +107,9 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; | |||
| 106 | 107 | strictEqual(err.code, 'ERR_INVALID_PACKAGE_TARGET'); | |
| 107 | 108 | assertStartsWith(err.message, 'Invalid "exports"'); | |
| 108 | 109 | assertIncludes(err.message, subpath); | |
| 110 | + if (!subpath.startsWith('./')) { | ||
| 111 | + assertIncludes(err.message, 'targets must start with'); | ||
| 112 | + } | ||
| 109 | 113 | })); | |
| 110 | 114 | } | |
| 111 | 115 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments