@@ -82,7 +82,7 @@ function tryStatSync(path) {
82
82
}
83
83
}
84
84
85
- function getPackageConfig ( path ) {
85
+ function getPackageConfig ( path , specifier , base ) {
86
86
const existing = packageJSONCache . get ( path ) ;
87
87
if ( existing !== undefined ) {
88
88
return existing ;
@@ -106,7 +106,11 @@ function getPackageConfig(path) {
106
106
try {
107
107
packageJSON = JSONParse ( source ) ;
108
108
} catch ( error ) {
109
- throw new ERR_INVALID_PACKAGE_CONFIG ( path , null , error . message ) ;
109
+ throw new ERR_INVALID_PACKAGE_CONFIG (
110
+ path ,
111
+ ( base ? `"${ specifier } " from ` : '' ) + fileURLToPath ( base || specifier ) ,
112
+ error . message
113
+ ) ;
110
114
}
111
115
112
116
let { imports, main, name, type } = packageJSON ;
@@ -130,13 +134,14 @@ function getPackageConfig(path) {
130
134
return packageConfig ;
131
135
}
132
136
133
- function getPackageScopeConfig ( resolved , base ) {
137
+ function getPackageScopeConfig ( resolved ) {
134
138
let packageJSONUrl = new URL ( './package.json' , resolved ) ;
135
139
while ( true ) {
136
140
const packageJSONPath = packageJSONUrl . pathname ;
137
141
if ( StringPrototypeEndsWith ( packageJSONPath , 'node_modules/package.json' ) )
138
142
break ;
139
- const packageConfig = getPackageConfig ( fileURLToPath ( packageJSONUrl ) , base ) ;
143
+ const packageConfig = getPackageConfig ( fileURLToPath ( packageJSONUrl ) ,
144
+ resolved ) ;
140
145
if ( packageConfig . exists ) return packageConfig ;
141
146
142
147
const lastPackageJSONUrl = packageJSONUrl ;
@@ -497,7 +502,7 @@ function packageImportsResolve(name, base, conditions) {
497
502
throw new ERR_INVALID_MODULE_SPECIFIER ( name , reason , fileURLToPath ( base ) ) ;
498
503
}
499
504
let packageJSONUrl ;
500
- const packageConfig = getPackageScopeConfig ( base , base ) ;
505
+ const packageConfig = getPackageScopeConfig ( base ) ;
501
506
if ( packageConfig . exists ) {
502
507
packageJSONUrl = pathToFileURL ( packageConfig . pjsonPath ) ;
503
508
const imports = packageConfig . imports ;
@@ -535,7 +540,7 @@ function packageImportsResolve(name, base, conditions) {
535
540
}
536
541
537
542
function getPackageType ( url ) {
538
- const packageConfig = getPackageScopeConfig ( url , url ) ;
543
+ const packageConfig = getPackageScopeConfig ( url ) ;
539
544
return packageConfig . type ;
540
545
}
541
546
@@ -580,7 +585,7 @@ function packageResolve(specifier, base, conditions) {
580
585
StringPrototypeSlice ( specifier , separatorIndex ) ) ;
581
586
582
587
// ResolveSelf
583
- const packageConfig = getPackageScopeConfig ( base , base ) ;
588
+ const packageConfig = getPackageScopeConfig ( base ) ;
584
589
if ( packageConfig . exists ) {
585
590
const packageJSONUrl = pathToFileURL ( packageConfig . pjsonPath ) ;
586
591
if ( packageConfig . name === packageName &&
@@ -608,7 +613,7 @@ function packageResolve(specifier, base, conditions) {
608
613
}
609
614
610
615
// Package match.
611
- const packageConfig = getPackageConfig ( packageJSONPath , base ) ;
616
+ const packageConfig = getPackageConfig ( packageJSONPath , specifier , base ) ;
612
617
if ( packageConfig . exports !== undefined && packageConfig . exports !== null )
613
618
return packageExportsResolve (
614
619
packageJSONUrl , packageSubpath , packageConfig , base , conditions
0 commit comments