@@ -1253,7 +1253,7 @@ export function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCom
1253
1253
* @returns `undefined` if the path has no relevant implied format, `ModuleKind.ESNext` for esm format, and `ModuleKind.CommonJS` for cjs format
1254
1254
*/
1255
1255
export function getImpliedNodeFormatForFile ( fileName : Path , packageJsonInfoCache : PackageJsonInfoCache | undefined , host : ModuleResolutionHost , options : CompilerOptions ) : ResolutionMode {
1256
- const result = getImpliedNodeFormatForFileWorker ( fileName , packageJsonInfoCache , host , options ) ;
1256
+ const result = getImpliedNodeFormatForFileWorker ( fileName , packageJsonInfoCache , host , options , /*oldBuildInfoProgram*/ undefined ) ;
1257
1257
return typeof result === "object" ? result . impliedNodeFormat : result ;
1258
1258
}
1259
1259
@@ -1263,6 +1263,7 @@ export function getImpliedNodeFormatForFileWorker(
1263
1263
packageJsonInfoCache : PackageJsonInfoCache | undefined ,
1264
1264
host : ModuleResolutionHost ,
1265
1265
options : CompilerOptions ,
1266
+ oldBuildInfoProgram : OldBuildInfoProgram | undefined ,
1266
1267
) {
1267
1268
switch ( getEmitModuleResolutionKind ( options ) ) {
1268
1269
case ModuleResolutionKind . Node16 :
@@ -1279,9 +1280,16 @@ export function getImpliedNodeFormatForFileWorker(
1279
1280
const packageJsonLocations : string [ ] = [ ] ;
1280
1281
state . failedLookupLocations = packageJsonLocations ;
1281
1282
state . affectingLocations = packageJsonLocations ;
1282
- const packageJsonScope = getPackageScopeForPath ( fileName , state ) ;
1283
+ const fromOld = oldBuildInfoProgram ?. getPackageJsonPath ( getDirectoryPath ( fileName ) ) ;
1284
+ const packageJsonScope = fromOld ?
1285
+ getPackageJsonInfo ( getDirectoryPath ( fromOld ) , /*onlyRecordFailures*/ false , state ) :
1286
+ getPackageScopeForPath ( fileName , state ) ;
1283
1287
const impliedNodeFormat = packageJsonScope ?. contents . packageJsonContent . type === "module" ? ModuleKind . ESNext : ModuleKind . CommonJS ;
1284
- return { impliedNodeFormat, packageJsonLocations, packageJsonScope } ;
1288
+ return {
1289
+ impliedNodeFormat,
1290
+ packageJsonLocations : packageJsonLocations . length ? packageJsonLocations : undefined ,
1291
+ packageJsonScope
1292
+ } ;
1285
1293
}
1286
1294
}
1287
1295
@@ -2374,7 +2382,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
2374
2382
if ( ! newSourceFile ) {
2375
2383
return StructureIsReused . Not ;
2376
2384
}
2377
- newSourceFile . packageJsonLocations = sourceFileOptions . packageJsonLocations ?. length ? sourceFileOptions . packageJsonLocations : undefined ;
2385
+ newSourceFile . packageJsonLocations = sourceFileOptions . packageJsonLocations ;
2378
2386
newSourceFile . packageJsonScope = sourceFileOptions . packageJsonScope ;
2379
2387
2380
2388
Debug . assert ( ! newSourceFile . redirectInfo , "Host should not return a redirect source file from `getSourceFile`" ) ;
@@ -3452,7 +3460,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3452
3460
redirect . resolvedPath = resolvedPath ;
3453
3461
redirect . originalFileName = originalFileName ;
3454
3462
redirect . redirectInfo = { redirectTarget, unredirected } ;
3455
- redirect . packageJsonLocations = sourceFileOptions . packageJsonLocations ?. length ? sourceFileOptions . packageJsonLocations : undefined ;
3463
+ redirect . packageJsonLocations = sourceFileOptions . packageJsonLocations ;
3456
3464
redirect . packageJsonScope = sourceFileOptions . packageJsonScope ;
3457
3465
sourceFilesFoundSearchingNodeModules . set ( path , currentNodeModulesDepth > 0 ) ;
3458
3466
Object . defineProperties ( redirect , {
@@ -3484,7 +3492,13 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3484
3492
// It's a _little odd_ that we can't set `impliedNodeFormat` until the program step - but it's the first and only time we have a resolution cache
3485
3493
// and a freshly made source file node on hand at the same time, and we need both to set the field. Persisting the resolution cache all the way
3486
3494
// to the check and emit steps would be bad - so we much prefer detecting and storing the format information on the source file node upfront.
3487
- const result = getImpliedNodeFormatForFileWorker ( getNormalizedAbsolutePath ( fileName , currentDirectory ) , moduleResolutionCache ?. getPackageJsonInfoCache ( ) , host , options ) ;
3495
+ const result = getImpliedNodeFormatForFileWorker (
3496
+ getNormalizedAbsolutePath ( fileName , currentDirectory ) ,
3497
+ moduleResolutionCache ?. getPackageJsonInfoCache ( ) ,
3498
+ host ,
3499
+ options ,
3500
+ oldBuildInfoProgram ,
3501
+ ) ;
3488
3502
const languageVersion = getEmitScriptTarget ( options ) ;
3489
3503
const setExternalModuleIndicator = getSetExternalModuleIndicator ( options ) ;
3490
3504
return typeof result === "object" ?
@@ -3618,7 +3632,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
3618
3632
file . path = path ;
3619
3633
file . resolvedPath = toPath ( fileName ) ;
3620
3634
file . originalFileName = originalFileName ;
3621
- file . packageJsonLocations = sourceFileOptions . packageJsonLocations ?. length ? sourceFileOptions . packageJsonLocations : undefined ;
3635
+ file . packageJsonLocations = sourceFileOptions . packageJsonLocations ;
3622
3636
file . packageJsonScope = sourceFileOptions . packageJsonScope ;
3623
3637
addFileIncludeReason ( file , reason ) ;
3624
3638
0 commit comments