@@ -1629,6 +1629,11 @@ export function nodeModuleNameResolver(moduleName: string, containingFile: strin
1629
1629
return nodeModuleNameResolverWorker ( NodeResolutionFeatures . None , moduleName , getDirectoryPath ( containingFile ) , compilerOptions , host , cache , extensions , ! ! isConfigLookup , redirectedReference ) ;
1630
1630
}
1631
1631
1632
+ /** @internal */
1633
+ export function nodeNextJsonConfigResolver ( moduleName : string , containingFile : string , host : ModuleResolutionHost ) : ResolvedModuleWithFailedLookupLocations {
1634
+ return nodeModuleNameResolverWorker ( NodeResolutionFeatures . Exports , moduleName , getDirectoryPath ( containingFile ) , { moduleResolution : ModuleResolutionKind . NodeNext } , host , /*cache*/ undefined , Extensions . Json , /*isConfigLookup*/ true , /*redirectedReference*/ undefined ) ;
1635
+ }
1636
+
1632
1637
function nodeModuleNameResolverWorker ( features : NodeResolutionFeatures , moduleName : string , containingDirectory : string , compilerOptions : CompilerOptions , host : ModuleResolutionHost , cache : ModuleResolutionCache | undefined , extensions : Extensions , isConfigLookup : boolean , redirectedReference : ResolvedProjectReference | undefined ) : ResolvedModuleWithFailedLookupLocations {
1633
1638
const traceEnabled = isTraceEnabled ( compilerOptions , host ) ;
1634
1639
@@ -1868,14 +1873,25 @@ function loadModuleFromFileNoImplicitExtensions(extensions: Extensions, candidat
1868
1873
}
1869
1874
}
1870
1875
1871
- function loadJSOrExactTSFileName ( extensions : Extensions , candidate : string , onlyRecordFailures : boolean , state : ModuleResolutionState ) : PathAndExtension | undefined {
1876
+ /**
1877
+ * This function is only ever called with paths written in package.json files - never
1878
+ * module specifiers written in source files - and so it always allows the
1879
+
1880
+ * candidate to end with a TS extension (but will also try substituting a JS extension for a TS extension).
1881
+ */
1882
+ function loadFileNameFromPackageJsonField ( extensions : Extensions , candidate : string , onlyRecordFailures : boolean , state : ModuleResolutionState ) : PathAndExtension | undefined {
1872
1883
if ( extensions & Extensions . TypeScript && fileExtensionIsOneOf ( candidate , supportedTSImplementationExtensions ) ||
1873
1884
extensions & Extensions . Declaration && fileExtensionIsOneOf ( candidate , supportedDeclarationExtensions )
1874
1885
) {
1875
1886
const result = tryFile ( candidate , onlyRecordFailures , state ) ;
1876
1887
return result !== undefined ? { path : candidate , ext : tryExtractTSExtension ( candidate ) as Extension , resolvedUsingTsExtension : undefined } : undefined ;
1877
1888
}
1878
1889
1890
+ if ( state . isConfigLookup && extensions === Extensions . Json && fileExtensionIs ( candidate , Extension . Json ) ) {
1891
+ const result = tryFile ( candidate , onlyRecordFailures , state ) ;
1892
+ return result !== undefined ? { path : candidate , ext : Extension . Json , resolvedUsingTsExtension : undefined } : undefined ;
1893
+ }
1894
+
1879
1895
return loadModuleFromFileNoImplicitExtensions ( extensions , candidate , onlyRecordFailures , state ) ;
1880
1896
}
1881
1897
@@ -2058,7 +2074,7 @@ function loadEntrypointsFromExportMap(
2058
2074
}
2059
2075
const resolvedTarget = combinePaths ( scope . packageDirectory , target ) ;
2060
2076
const finalPath = getNormalizedAbsolutePath ( resolvedTarget , state . host . getCurrentDirectory ?.( ) ) ;
2061
- const result = loadJSOrExactTSFileName ( extensions , finalPath , /*recordOnlyFailures*/ false , state ) ;
2077
+ const result = loadFileNameFromPackageJsonField ( extensions , finalPath , /*recordOnlyFailures*/ false , state ) ;
2062
2078
if ( result ) {
2063
2079
entrypoints = appendIfUnique ( entrypoints , result , ( a , b ) => a . path === b . path ) ;
2064
2080
return true ;
@@ -2488,7 +2504,7 @@ function getLoadModuleFromTargetImportOrExport(extensions: Extensions, state: Mo
2488
2504
const finalPath = toAbsolutePath ( pattern ? resolvedTarget . replace ( / \* / g, subpath ) : resolvedTarget + subpath ) ;
2489
2505
const inputLink = tryLoadInputFileForPath ( finalPath , subpath , combinePaths ( scope . packageDirectory , "package.json" ) , isImports ) ;
2490
2506
if ( inputLink ) return inputLink ;
2491
- return toSearchResult ( withPackageId ( scope , loadJSOrExactTSFileName ( extensions , finalPath , /*onlyRecordFailures*/ false , state ) ) ) ;
2507
+ return toSearchResult ( withPackageId ( scope , loadFileNameFromPackageJsonField ( extensions , finalPath , /*onlyRecordFailures*/ false , state ) ) ) ;
2492
2508
}
2493
2509
else if ( typeof target === "object" && target !== null ) { // eslint-disable-line no-null/no-null
2494
2510
if ( ! Array . isArray ( target ) ) {
@@ -2632,7 +2648,7 @@ function getLoadModuleFromTargetImportOrExport(extensions: Extensions, state: Mo
2632
2648
if ( ! extensionIsOk ( extensions , possibleExt ) ) continue ;
2633
2649
const possibleInputWithInputExtension = changeAnyExtension ( possibleInputBase , possibleExt , ext , ! useCaseSensitiveFileNames ( ) ) ;
2634
2650
if ( state . host . fileExists ( possibleInputWithInputExtension ) ) {
2635
- return toSearchResult ( withPackageId ( scope , loadJSOrExactTSFileName ( extensions , possibleInputWithInputExtension , /*onlyRecordFailures*/ false , state ) ) ) ;
2651
+ return toSearchResult ( withPackageId ( scope , loadFileNameFromPackageJsonField ( extensions , possibleInputWithInputExtension , /*onlyRecordFailures*/ false , state ) ) ) ;
2636
2652
}
2637
2653
}
2638
2654
}
0 commit comments