@@ -77,7 +77,7 @@ function tryStatSync(path) {
77
77
}
78
78
}
79
79
80
- function getPackageConfig ( path ) {
80
+ function getPackageConfig ( path , specifier , base ) {
81
81
const existing = packageJSONCache . get ( path ) ;
82
82
if ( existing !== undefined ) {
83
83
return existing ;
@@ -101,7 +101,11 @@ function getPackageConfig(path) {
101
101
try {
102
102
packageJSON = JSONParse ( source ) ;
103
103
} catch ( error ) {
104
- throw new ERR_INVALID_PACKAGE_CONFIG ( path , null , error . message ) ;
104
+ throw new ERR_INVALID_PACKAGE_CONFIG (
105
+ path ,
106
+ ( base ? `"${ specifier } " from ` : '' ) + fileURLToPath ( base || specifier ) ,
107
+ error . message
108
+ ) ;
105
109
}
106
110
107
111
let { imports, main, name, type } = packageJSON ;
@@ -125,13 +129,14 @@ function getPackageConfig(path) {
125
129
return packageConfig ;
126
130
}
127
131
128
- function getPackageScopeConfig ( resolved , base ) {
132
+ function getPackageScopeConfig ( resolved ) {
129
133
let packageJSONUrl = new URL ( './package.json' , resolved ) ;
130
134
while ( true ) {
131
135
const packageJSONPath = packageJSONUrl . pathname ;
132
136
if ( StringPrototypeEndsWith ( packageJSONPath , 'node_modules/package.json' ) )
133
137
break ;
134
- const packageConfig = getPackageConfig ( fileURLToPath ( packageJSONUrl ) , base ) ;
138
+ const packageConfig = getPackageConfig ( fileURLToPath ( packageJSONUrl ) ,
139
+ resolved ) ;
135
140
if ( packageConfig . exists ) return packageConfig ;
136
141
137
142
const lastPackageJSONUrl = packageJSONUrl ;
@@ -492,7 +497,7 @@ function packageImportsResolve(name, base, conditions) {
492
497
throw new ERR_INVALID_MODULE_SPECIFIER ( name , reason , fileURLToPath ( base ) ) ;
493
498
}
494
499
let packageJSONUrl ;
495
- const packageConfig = getPackageScopeConfig ( base , base ) ;
500
+ const packageConfig = getPackageScopeConfig ( base ) ;
496
501
if ( packageConfig . exists ) {
497
502
packageJSONUrl = pathToFileURL ( packageConfig . pjsonPath ) ;
498
503
const imports = packageConfig . imports ;
@@ -530,7 +535,7 @@ function packageImportsResolve(name, base, conditions) {
530
535
}
531
536
532
537
function getPackageType ( url ) {
533
- const packageConfig = getPackageScopeConfig ( url , url ) ;
538
+ const packageConfig = getPackageScopeConfig ( url ) ;
534
539
return packageConfig . type ;
535
540
}
536
541
@@ -575,7 +580,7 @@ function packageResolve(specifier, base, conditions) {
575
580
StringPrototypeSlice ( specifier , separatorIndex ) ) ;
576
581
577
582
// ResolveSelf
578
- const packageConfig = getPackageScopeConfig ( base , base ) ;
583
+ const packageConfig = getPackageScopeConfig ( base ) ;
579
584
if ( packageConfig . exists ) {
580
585
const packageJSONUrl = pathToFileURL ( packageConfig . pjsonPath ) ;
581
586
if ( packageConfig . name === packageName &&
@@ -603,7 +608,7 @@ function packageResolve(specifier, base, conditions) {
603
608
}
604
609
605
610
// Package match.
606
- const packageConfig = getPackageConfig ( packageJSONPath , base ) ;
611
+ const packageConfig = getPackageConfig ( packageJSONPath , specifier , base ) ;
607
612
if ( packageConfig . exports !== undefined && packageConfig . exports !== null )
608
613
return packageExportsResolve (
609
614
packageJSONUrl , packageSubpath , packageConfig , base , conditions
0 commit comments