diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 75dd9a54657..2b0b37d5878 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -1910,25 +1910,31 @@ function nodeModuleNameResolverWorker( } if (!isExternalModuleNameRelative(moduleName)) { - let resolved: SearchResult | undefined; if (features & NodeResolutionFeatures.Imports && startsWith(moduleName, "#")) { - resolved = loadModuleFromImports(extensions, moduleName, containingDirectory, state, cache, redirectedReference); - } - if (!resolved && features & NodeResolutionFeatures.SelfName) { - resolved = loadModuleFromSelfNameReference(extensions, moduleName, containingDirectory, state, cache, redirectedReference); - } - if (!resolved) { - if (moduleName.includes(":")) { - if (traceEnabled) { - trace(host, Diagnostics.Skipping_module_0_that_looks_like_an_absolute_URI_target_file_types_Colon_1, moduleName, formatExtensions(extensions)); - } - return undefined; + const resolved = loadModuleFromImports(extensions, moduleName, containingDirectory, state, cache, redirectedReference); + if (resolved) { + return resolved.value && { value: { resolved: resolved.value, isExternalLibraryImport: false } }; } + } + + if (features & NodeResolutionFeatures.SelfName) { + const resolved = loadModuleFromSelfNameReference(extensions, moduleName, containingDirectory, state, cache, redirectedReference); + if (resolved) { + return resolved.value && { value: { resolved: resolved.value, isExternalLibraryImport: false } }; + } + } + + if (moduleName.includes(":")) { if (traceEnabled) { - trace(host, Diagnostics.Loading_module_0_from_node_modules_folder_target_file_types_Colon_1, moduleName, formatExtensions(extensions)); + trace(host, Diagnostics.Skipping_module_0_that_looks_like_an_absolute_URI_target_file_types_Colon_1, moduleName, formatExtensions(extensions)); } - resolved = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference); + return undefined; } + + if (traceEnabled) { + trace(host, Diagnostics.Loading_module_0_from_node_modules_folder_target_file_types_Colon_1, moduleName, formatExtensions(extensions)); + } + let resolved = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference); if (extensions & Extensions.Declaration) { resolved ??= resolveFromTypeRoot(moduleName, state); } diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node16).js b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node16).js index bd0f2a77807..c117ac16cc8 100644 --- a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node16).js +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node16).js @@ -122,22 +122,6 @@ export const cjsSource = true; } } -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/a"; -import * as mjsi from "inner/b"; -import * as typei from "inner"; -import * as ts from "inner/types"; -cjsi.mjsSource; -mjsi.mjsSource; -typei.mjsSource; -ts.mjsSource; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -195,11 +179,27 @@ cjsi.cjsSource; mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/a"; +import * as mjsi from "inner/b"; +import * as typei from "inner"; +import * as ts from "inner/types"; +cjsi.mjsSource; +mjsi.mjsSource; +typei.mjsSource; +ts.mjsSource; -//// [index.d.ts] -export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; +//// [index.d.ts] +export {}; diff --git a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js index bd0f2a77807..c117ac16cc8 100644 --- a/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js @@ -122,22 +122,6 @@ export const cjsSource = true; } } -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/a"; -import * as mjsi from "inner/b"; -import * as typei from "inner"; -import * as ts from "inner/types"; -cjsi.mjsSource; -mjsi.mjsSource; -typei.mjsSource; -ts.mjsSource; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -195,11 +179,27 @@ cjsi.cjsSource; mjsi.cjsSource; typei.implicitCjsSource; ts.cjsSource; +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/a"; +import * as mjsi from "inner/b"; +import * as typei from "inner"; +import * as ts from "inner/types"; +cjsi.mjsSource; +mjsi.mjsSource; +typei.mjsSource; +ts.mjsSource; -//// [index.d.ts] -export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; +//// [index.d.ts] +export {}; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node16).js b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node16).js index cce457e2d41..e3375b612b2 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node16).js +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=node16).js @@ -88,20 +88,6 @@ export { type }; } } -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/cjs"; -import * as mjsi from "inner/mjs"; -import * as typei from "inner"; -cjsi; -mjsi; -typei; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -155,11 +141,25 @@ const typei = __importStar(require("inner")); cjsi; mjsi; typei; +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/cjs"; +import * as mjsi from "inner/mjs"; +import * as typei from "inner"; +cjsi; +mjsi; +typei; -//// [index.d.ts] -export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; +//// [index.d.ts] +export {}; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).js index cce457e2d41..e3375b612b2 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesAllowJsPackageExports(module=nodenext).js @@ -88,20 +88,6 @@ export { type }; } } -//// [index.js] -// esm format file -import * as cjs from "package/cjs"; -import * as mjs from "package/mjs"; -import * as type from "package"; -cjs; -mjs; -type; -import * as cjsi from "inner/cjs"; -import * as mjsi from "inner/mjs"; -import * as typei from "inner"; -cjsi; -mjsi; -typei; //// [index.mjs] // esm format file import * as cjs from "package/cjs"; @@ -155,11 +141,25 @@ const typei = __importStar(require("inner")); cjsi; mjsi; typei; +//// [index.js] +// esm format file +import * as cjs from "package/cjs"; +import * as mjs from "package/mjs"; +import * as type from "package"; +cjs; +mjs; +type; +import * as cjsi from "inner/cjs"; +import * as mjsi from "inner/mjs"; +import * as typei from "inner"; +cjsi; +mjsi; +typei; -//// [index.d.ts] -export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; +//// [index.d.ts] +export {}; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node16).js b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node16).js index 634e532de49..e0863137eee 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node16).js +++ b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=node16).js @@ -37,14 +37,6 @@ type; } } -//// [index.js] -// esm format file -import * as cjs from "#cjs"; -import * as mjs from "#mjs"; -import * as type from "#type"; -cjs; -mjs; -type; //// [index.mjs] // esm format file import * as cjs from "#cjs"; @@ -86,11 +78,19 @@ const type = __importStar(require("#type")); cjs; mjs; type; +//// [index.js] +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; -//// [index.d.ts] -export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; +//// [index.d.ts] +export {}; diff --git a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).js b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).js index 634e532de49..e0863137eee 100644 --- a/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).js +++ b/tests/baselines/reference/nodeModulesAllowJsPackageImports(module=nodenext).js @@ -37,14 +37,6 @@ type; } } -//// [index.js] -// esm format file -import * as cjs from "#cjs"; -import * as mjs from "#mjs"; -import * as type from "#type"; -cjs; -mjs; -type; //// [index.mjs] // esm format file import * as cjs from "#cjs"; @@ -86,11 +78,19 @@ const type = __importStar(require("#type")); cjs; mjs; type; +//// [index.js] +// esm format file +import * as cjs from "#cjs"; +import * as mjs from "#mjs"; +import * as type from "#type"; +cjs; +mjs; +type; -//// [index.d.ts] -export {}; //// [index.d.mts] export {}; //// [index.d.cts] export {}; +//// [index.d.ts] +export {}; diff --git a/tests/baselines/reference/nodeModulesPackageImports(module=node16).trace.json b/tests/baselines/reference/nodeModulesPackageImports(module=node16).trace.json index bf539475a7a..1fc306a0c6b 100644 --- a/tests/baselines/reference/nodeModulesPackageImports(module=node16).trace.json +++ b/tests/baselines/reference/nodeModulesPackageImports(module=node16).trace.json @@ -7,7 +7,6 @@ "Using 'imports' subpath '#cjs' with target './index.cjs'.", "File name '/.src/index.cjs' has a '.cjs' extension - stripping it.", "File '/.src/index.cts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/index.cts', result '/.src/index.cts'.", "======== Module name '#cjs' was successfully resolved to '/.src/index.cts'. ========", "======== Resolving module '#mjs' from '/.src/index.ts'. ========", "Module resolution kind is not specified, using 'Node16'.", @@ -16,7 +15,6 @@ "Using 'imports' subpath '#mjs' with target './index.mjs'.", "File name '/.src/index.mjs' has a '.mjs' extension - stripping it.", "File '/.src/index.mts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/index.mts', result '/.src/index.mts'.", "======== Module name '#mjs' was successfully resolved to '/.src/index.mts'. ========", "======== Resolving module '#type' from '/.src/index.ts'. ========", "Module resolution kind is not specified, using 'Node16'.", @@ -25,7 +23,6 @@ "Using 'imports' subpath '#type' with target './index.js'.", "File name '/.src/index.js' has a '.js' extension - stripping it.", "File '/.src/index.ts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/index.ts', result '/.src/index.ts'.", "======== Module name '#type' was successfully resolved to '/.src/index.ts'. ========", "======== Resolving module '#cjs' from '/.src/index.cts'. ========", "Module resolution kind is not specified, using 'Node16'.", @@ -34,7 +31,6 @@ "Using 'imports' subpath '#cjs' with target './index.cjs'.", "File name '/.src/index.cjs' has a '.cjs' extension - stripping it.", "File '/.src/index.cts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/index.cts', result '/.src/index.cts'.", "======== Module name '#cjs' was successfully resolved to '/.src/index.cts'. ========", "======== Resolving module '#mjs' from '/.src/index.cts'. ========", "Module resolution kind is not specified, using 'Node16'.", @@ -43,7 +39,6 @@ "Using 'imports' subpath '#mjs' with target './index.mjs'.", "File name '/.src/index.mjs' has a '.mjs' extension - stripping it.", "File '/.src/index.mts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/index.mts', result '/.src/index.mts'.", "======== Module name '#mjs' was successfully resolved to '/.src/index.mts'. ========", "======== Resolving module '#type' from '/.src/index.cts'. ========", "Module resolution kind is not specified, using 'Node16'.", @@ -52,7 +47,6 @@ "Using 'imports' subpath '#type' with target './index.js'.", "File name '/.src/index.js' has a '.js' extension - stripping it.", "File '/.src/index.ts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/index.ts', result '/.src/index.ts'.", "======== Module name '#type' was successfully resolved to '/.src/index.ts'. ========", "======== Resolving module '#cjs' from '/.src/index.mts'. ========", "Resolution for module '#cjs' was found in cache from location '/.src'.", @@ -63,24 +57,6 @@ "======== Resolving module '#type' from '/.src/index.mts'. ========", "Resolution for module '#type' was found in cache from location '/.src'.", "======== Module name '#type' was successfully resolved to '/.src/index.ts'. ========", - "======== Resolving module '#cjs' from '/.src/index.mts'. ========", - "Resolution for module '#cjs' was found in cache from location '/.src'.", - "======== Module name '#cjs' was successfully resolved to '/.src/index.cts'. ========", - "======== Resolving module '#mjs' from '/.src/index.mts'. ========", - "Resolution for module '#mjs' was found in cache from location '/.src'.", - "======== Module name '#mjs' was successfully resolved to '/.src/index.mts'. ========", - "======== Resolving module '#type' from '/.src/index.mts'. ========", - "Resolution for module '#type' was found in cache from location '/.src'.", - "======== Module name '#type' was successfully resolved to '/.src/index.ts'. ========", - "======== Resolving module '#cjs' from '/.src/index.cts'. ========", - "Resolution for module '#cjs' was found in cache from location '/.src'.", - "======== Module name '#cjs' was successfully resolved to '/.src/index.cts'. ========", - "======== Resolving module '#mjs' from '/.src/index.cts'. ========", - "Resolution for module '#mjs' was found in cache from location '/.src'.", - "======== Module name '#mjs' was successfully resolved to '/.src/index.mts'. ========", - "======== Resolving module '#type' from '/.src/index.cts'. ========", - "Resolution for module '#type' was found in cache from location '/.src'.", - "======== Module name '#type' was successfully resolved to '/.src/index.ts'. ========", "File '/.ts/package.json' does not exist.", "File '/package.json' does not exist.", "======== Resolving module '@typescript/lib-es2022' from '/.src/__lib_node_modules_lookup_lib.es2022.d.ts__.ts'. ========", diff --git a/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).trace.json b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).trace.json index 8d3d19610e9..a8fe93ee301 100644 --- a/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).trace.json +++ b/tests/baselines/reference/nodeModulesPackageImports(module=nodenext).trace.json @@ -7,7 +7,6 @@ "Using 'imports' subpath '#cjs' with target './index.cjs'.", "File name '/.src/index.cjs' has a '.cjs' extension - stripping it.", "File '/.src/index.cts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/index.cts', result '/.src/index.cts'.", "======== Module name '#cjs' was successfully resolved to '/.src/index.cts'. ========", "======== Resolving module '#mjs' from '/.src/index.ts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", @@ -16,7 +15,6 @@ "Using 'imports' subpath '#mjs' with target './index.mjs'.", "File name '/.src/index.mjs' has a '.mjs' extension - stripping it.", "File '/.src/index.mts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/index.mts', result '/.src/index.mts'.", "======== Module name '#mjs' was successfully resolved to '/.src/index.mts'. ========", "======== Resolving module '#type' from '/.src/index.ts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", @@ -25,7 +23,6 @@ "Using 'imports' subpath '#type' with target './index.js'.", "File name '/.src/index.js' has a '.js' extension - stripping it.", "File '/.src/index.ts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/index.ts', result '/.src/index.ts'.", "======== Module name '#type' was successfully resolved to '/.src/index.ts'. ========", "======== Resolving module '#cjs' from '/.src/index.cts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", @@ -34,7 +31,6 @@ "Using 'imports' subpath '#cjs' with target './index.cjs'.", "File name '/.src/index.cjs' has a '.cjs' extension - stripping it.", "File '/.src/index.cts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/index.cts', result '/.src/index.cts'.", "======== Module name '#cjs' was successfully resolved to '/.src/index.cts'. ========", "======== Resolving module '#mjs' from '/.src/index.cts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", @@ -43,7 +39,6 @@ "Using 'imports' subpath '#mjs' with target './index.mjs'.", "File name '/.src/index.mjs' has a '.mjs' extension - stripping it.", "File '/.src/index.mts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/index.mts', result '/.src/index.mts'.", "======== Module name '#mjs' was successfully resolved to '/.src/index.mts'. ========", "======== Resolving module '#type' from '/.src/index.cts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", @@ -52,7 +47,6 @@ "Using 'imports' subpath '#type' with target './index.js'.", "File name '/.src/index.js' has a '.js' extension - stripping it.", "File '/.src/index.ts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/index.ts', result '/.src/index.ts'.", "======== Module name '#type' was successfully resolved to '/.src/index.ts'. ========", "======== Resolving module '#cjs' from '/.src/index.mts'. ========", "Resolution for module '#cjs' was found in cache from location '/.src'.", @@ -63,24 +57,6 @@ "======== Resolving module '#type' from '/.src/index.mts'. ========", "Resolution for module '#type' was found in cache from location '/.src'.", "======== Module name '#type' was successfully resolved to '/.src/index.ts'. ========", - "======== Resolving module '#cjs' from '/.src/index.mts'. ========", - "Resolution for module '#cjs' was found in cache from location '/.src'.", - "======== Module name '#cjs' was successfully resolved to '/.src/index.cts'. ========", - "======== Resolving module '#mjs' from '/.src/index.mts'. ========", - "Resolution for module '#mjs' was found in cache from location '/.src'.", - "======== Module name '#mjs' was successfully resolved to '/.src/index.mts'. ========", - "======== Resolving module '#type' from '/.src/index.mts'. ========", - "Resolution for module '#type' was found in cache from location '/.src'.", - "======== Module name '#type' was successfully resolved to '/.src/index.ts'. ========", - "======== Resolving module '#cjs' from '/.src/index.cts'. ========", - "Resolution for module '#cjs' was found in cache from location '/.src'.", - "======== Module name '#cjs' was successfully resolved to '/.src/index.cts'. ========", - "======== Resolving module '#mjs' from '/.src/index.cts'. ========", - "Resolution for module '#mjs' was found in cache from location '/.src'.", - "======== Module name '#mjs' was successfully resolved to '/.src/index.mts'. ========", - "======== Resolving module '#type' from '/.src/index.cts'. ========", - "Resolution for module '#type' was found in cache from location '/.src'.", - "======== Module name '#type' was successfully resolved to '/.src/index.ts'. ========", "File '/.ts/package.json' does not exist.", "File '/package.json' does not exist.", "======== Resolving module '@typescript/lib-esnext' from '/.src/__lib_node_modules_lookup_lib.esnext.d.ts__.ts'. ========", diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node16).trace.json b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node16).trace.json index 6ea07562493..4d02f9365e3 100644 --- a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node16).trace.json +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=node16).trace.json @@ -48,7 +48,6 @@ "File name '/.src/node_modules/inner/index.cjs' has a '.cjs' extension - stripping it.", "File '/.src/node_modules/inner/index.cts' does not exist.", "File '/.src/node_modules/inner/index.d.cts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/node_modules/inner/index.d.cts', result '/.src/node_modules/inner/index.d.cts'.", "======== Module name 'inner/cjs/index.cjs' was successfully resolved to '/.src/node_modules/inner/index.d.cts'. ========", "======== Resolving module 'inner/mjs/index.mjs' from '/.src/node_modules/inner/index.d.cts'. ========", "Module resolution kind is not specified, using 'Node16'.", @@ -58,7 +57,6 @@ "File name '/.src/node_modules/inner/index.mjs' has a '.mjs' extension - stripping it.", "File '/.src/node_modules/inner/index.mts' does not exist.", "File '/.src/node_modules/inner/index.d.mts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/node_modules/inner/index.d.mts', result '/.src/node_modules/inner/index.d.mts'.", "======== Module name 'inner/mjs/index.mjs' was successfully resolved to '/.src/node_modules/inner/index.d.mts'. ========", "======== Resolving module 'inner/js/index.js' from '/.src/node_modules/inner/index.d.cts'. ========", "Module resolution kind is not specified, using 'Node16'.", @@ -69,7 +67,6 @@ "File '/.src/node_modules/inner/index.ts' does not exist.", "File '/.src/node_modules/inner/index.tsx' does not exist.", "File '/.src/node_modules/inner/index.d.ts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/node_modules/inner/index.d.ts', result '/.src/node_modules/inner/index.d.ts'.", "======== Module name 'inner/js/index.js' was successfully resolved to '/.src/node_modules/inner/index.d.ts'. ========", "======== Resolving module 'inner/cjs/index.cjs' from '/.src/node_modules/inner/index.d.mts'. ========", "Module resolution kind is not specified, using 'Node16'.", @@ -79,7 +76,6 @@ "File name '/.src/node_modules/inner/index.cjs' has a '.cjs' extension - stripping it.", "File '/.src/node_modules/inner/index.cts' does not exist.", "File '/.src/node_modules/inner/index.d.cts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/node_modules/inner/index.d.cts', result '/.src/node_modules/inner/index.d.cts'.", "======== Module name 'inner/cjs/index.cjs' was successfully resolved to '/.src/node_modules/inner/index.d.cts'. ========", "======== Resolving module 'inner/mjs/index.mjs' from '/.src/node_modules/inner/index.d.mts'. ========", "Module resolution kind is not specified, using 'Node16'.", @@ -89,7 +85,6 @@ "File name '/.src/node_modules/inner/index.mjs' has a '.mjs' extension - stripping it.", "File '/.src/node_modules/inner/index.mts' does not exist.", "File '/.src/node_modules/inner/index.d.mts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/node_modules/inner/index.d.mts', result '/.src/node_modules/inner/index.d.mts'.", "======== Module name 'inner/mjs/index.mjs' was successfully resolved to '/.src/node_modules/inner/index.d.mts'. ========", "======== Resolving module 'inner/js/index.js' from '/.src/node_modules/inner/index.d.mts'. ========", "Module resolution kind is not specified, using 'Node16'.", @@ -100,7 +95,6 @@ "File '/.src/node_modules/inner/index.ts' does not exist.", "File '/.src/node_modules/inner/index.tsx' does not exist.", "File '/.src/node_modules/inner/index.d.ts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/node_modules/inner/index.d.ts', result '/.src/node_modules/inner/index.d.ts'.", "======== Module name 'inner/js/index.js' was successfully resolved to '/.src/node_modules/inner/index.d.ts'. ========", "File '/.src/node_modules/inner/package.json' exists according to earlier cached lookups.", "======== Resolving module 'inner/cjs/index.cjs' from '/.src/node_modules/inner/index.d.ts'. ========", @@ -170,15 +164,6 @@ "======== Resolving module 'inner/js/index.js' from '/.src/node_modules/inner/index.d.ts'. ========", "Resolution for module 'inner/js/index.js' was found in cache from location '/.src/node_modules/inner'.", "======== Module name 'inner/js/index.js' was successfully resolved to '/.src/node_modules/inner/index.d.ts'. ========", - "======== Resolving module 'inner/cjs/index.cjs' from '/.src/node_modules/inner/index.d.mts'. ========", - "Resolution for module 'inner/cjs/index.cjs' was found in cache from location '/.src/node_modules/inner'.", - "======== Module name 'inner/cjs/index.cjs' was successfully resolved to '/.src/node_modules/inner/index.d.cts'. ========", - "======== Resolving module 'inner/mjs/index.mjs' from '/.src/node_modules/inner/index.d.mts'. ========", - "Resolution for module 'inner/mjs/index.mjs' was found in cache from location '/.src/node_modules/inner'.", - "======== Module name 'inner/mjs/index.mjs' was successfully resolved to '/.src/node_modules/inner/index.d.mts'. ========", - "======== Resolving module 'inner/js/index.js' from '/.src/node_modules/inner/index.d.mts'. ========", - "Resolution for module 'inner/js/index.js' was found in cache from location '/.src/node_modules/inner'.", - "======== Module name 'inner/js/index.js' was successfully resolved to '/.src/node_modules/inner/index.d.ts'. ========", "======== Resolving module 'inner/cjs/index.cjs' from '/.src/node_modules/inner/index.d.cts'. ========", "Resolution for module 'inner/cjs/index.cjs' was found in cache from location '/.src/node_modules/inner'.", "======== Module name 'inner/cjs/index.cjs' was successfully resolved to '/.src/node_modules/inner/index.d.cts'. ========", @@ -188,6 +173,15 @@ "======== Resolving module 'inner/js/index.js' from '/.src/node_modules/inner/index.d.cts'. ========", "Resolution for module 'inner/js/index.js' was found in cache from location '/.src/node_modules/inner'.", "======== Module name 'inner/js/index.js' was successfully resolved to '/.src/node_modules/inner/index.d.ts'. ========", + "======== Resolving module 'inner/cjs/index.cjs' from '/.src/node_modules/inner/index.d.mts'. ========", + "Resolution for module 'inner/cjs/index.cjs' was found in cache from location '/.src/node_modules/inner'.", + "======== Module name 'inner/cjs/index.cjs' was successfully resolved to '/.src/node_modules/inner/index.d.cts'. ========", + "======== Resolving module 'inner/mjs/index.mjs' from '/.src/node_modules/inner/index.d.mts'. ========", + "Resolution for module 'inner/mjs/index.mjs' was found in cache from location '/.src/node_modules/inner'.", + "======== Module name 'inner/mjs/index.mjs' was successfully resolved to '/.src/node_modules/inner/index.d.mts'. ========", + "======== Resolving module 'inner/js/index.js' from '/.src/node_modules/inner/index.d.mts'. ========", + "Resolution for module 'inner/js/index.js' was found in cache from location '/.src/node_modules/inner'.", + "======== Module name 'inner/js/index.js' was successfully resolved to '/.src/node_modules/inner/index.d.ts'. ========", "File '/.ts/package.json' does not exist.", "File '/package.json' does not exist.", "======== Resolving module '@typescript/lib-es2022' from '/.src/__lib_node_modules_lookup_lib.es2022.d.ts__.ts'. ========", diff --git a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).trace.json b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).trace.json index 120ddd2efeb..b39696da67c 100644 --- a/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).trace.json +++ b/tests/baselines/reference/nodeModulesPackagePatternExportsTrailers(module=nodenext).trace.json @@ -48,7 +48,6 @@ "File name '/.src/node_modules/inner/index.cjs' has a '.cjs' extension - stripping it.", "File '/.src/node_modules/inner/index.cts' does not exist.", "File '/.src/node_modules/inner/index.d.cts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/node_modules/inner/index.d.cts', result '/.src/node_modules/inner/index.d.cts'.", "======== Module name 'inner/cjs/index.cjs' was successfully resolved to '/.src/node_modules/inner/index.d.cts'. ========", "======== Resolving module 'inner/mjs/index.mjs' from '/.src/node_modules/inner/index.d.cts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", @@ -58,7 +57,6 @@ "File name '/.src/node_modules/inner/index.mjs' has a '.mjs' extension - stripping it.", "File '/.src/node_modules/inner/index.mts' does not exist.", "File '/.src/node_modules/inner/index.d.mts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/node_modules/inner/index.d.mts', result '/.src/node_modules/inner/index.d.mts'.", "======== Module name 'inner/mjs/index.mjs' was successfully resolved to '/.src/node_modules/inner/index.d.mts'. ========", "======== Resolving module 'inner/js/index.js' from '/.src/node_modules/inner/index.d.cts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", @@ -69,7 +67,6 @@ "File '/.src/node_modules/inner/index.ts' does not exist.", "File '/.src/node_modules/inner/index.tsx' does not exist.", "File '/.src/node_modules/inner/index.d.ts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/node_modules/inner/index.d.ts', result '/.src/node_modules/inner/index.d.ts'.", "======== Module name 'inner/js/index.js' was successfully resolved to '/.src/node_modules/inner/index.d.ts'. ========", "======== Resolving module 'inner/cjs/index.cjs' from '/.src/node_modules/inner/index.d.mts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", @@ -79,7 +76,6 @@ "File name '/.src/node_modules/inner/index.cjs' has a '.cjs' extension - stripping it.", "File '/.src/node_modules/inner/index.cts' does not exist.", "File '/.src/node_modules/inner/index.d.cts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/node_modules/inner/index.d.cts', result '/.src/node_modules/inner/index.d.cts'.", "======== Module name 'inner/cjs/index.cjs' was successfully resolved to '/.src/node_modules/inner/index.d.cts'. ========", "======== Resolving module 'inner/mjs/index.mjs' from '/.src/node_modules/inner/index.d.mts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", @@ -89,7 +85,6 @@ "File name '/.src/node_modules/inner/index.mjs' has a '.mjs' extension - stripping it.", "File '/.src/node_modules/inner/index.mts' does not exist.", "File '/.src/node_modules/inner/index.d.mts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/node_modules/inner/index.d.mts', result '/.src/node_modules/inner/index.d.mts'.", "======== Module name 'inner/mjs/index.mjs' was successfully resolved to '/.src/node_modules/inner/index.d.mts'. ========", "======== Resolving module 'inner/js/index.js' from '/.src/node_modules/inner/index.d.mts'. ========", "Module resolution kind is not specified, using 'NodeNext'.", @@ -100,7 +95,6 @@ "File '/.src/node_modules/inner/index.ts' does not exist.", "File '/.src/node_modules/inner/index.tsx' does not exist.", "File '/.src/node_modules/inner/index.d.ts' exists - use it as a name resolution result.", - "Resolving real path for '/.src/node_modules/inner/index.d.ts', result '/.src/node_modules/inner/index.d.ts'.", "======== Module name 'inner/js/index.js' was successfully resolved to '/.src/node_modules/inner/index.d.ts'. ========", "File '/.src/node_modules/inner/package.json' exists according to earlier cached lookups.", "======== Resolving module 'inner/cjs/index.cjs' from '/.src/node_modules/inner/index.d.ts'. ========", @@ -170,15 +164,6 @@ "======== Resolving module 'inner/js/index.js' from '/.src/node_modules/inner/index.d.ts'. ========", "Resolution for module 'inner/js/index.js' was found in cache from location '/.src/node_modules/inner'.", "======== Module name 'inner/js/index.js' was successfully resolved to '/.src/node_modules/inner/index.d.ts'. ========", - "======== Resolving module 'inner/cjs/index.cjs' from '/.src/node_modules/inner/index.d.mts'. ========", - "Resolution for module 'inner/cjs/index.cjs' was found in cache from location '/.src/node_modules/inner'.", - "======== Module name 'inner/cjs/index.cjs' was successfully resolved to '/.src/node_modules/inner/index.d.cts'. ========", - "======== Resolving module 'inner/mjs/index.mjs' from '/.src/node_modules/inner/index.d.mts'. ========", - "Resolution for module 'inner/mjs/index.mjs' was found in cache from location '/.src/node_modules/inner'.", - "======== Module name 'inner/mjs/index.mjs' was successfully resolved to '/.src/node_modules/inner/index.d.mts'. ========", - "======== Resolving module 'inner/js/index.js' from '/.src/node_modules/inner/index.d.mts'. ========", - "Resolution for module 'inner/js/index.js' was found in cache from location '/.src/node_modules/inner'.", - "======== Module name 'inner/js/index.js' was successfully resolved to '/.src/node_modules/inner/index.d.ts'. ========", "======== Resolving module 'inner/cjs/index.cjs' from '/.src/node_modules/inner/index.d.cts'. ========", "Resolution for module 'inner/cjs/index.cjs' was found in cache from location '/.src/node_modules/inner'.", "======== Module name 'inner/cjs/index.cjs' was successfully resolved to '/.src/node_modules/inner/index.d.cts'. ========", @@ -188,6 +173,15 @@ "======== Resolving module 'inner/js/index.js' from '/.src/node_modules/inner/index.d.cts'. ========", "Resolution for module 'inner/js/index.js' was found in cache from location '/.src/node_modules/inner'.", "======== Module name 'inner/js/index.js' was successfully resolved to '/.src/node_modules/inner/index.d.ts'. ========", + "======== Resolving module 'inner/cjs/index.cjs' from '/.src/node_modules/inner/index.d.mts'. ========", + "Resolution for module 'inner/cjs/index.cjs' was found in cache from location '/.src/node_modules/inner'.", + "======== Module name 'inner/cjs/index.cjs' was successfully resolved to '/.src/node_modules/inner/index.d.cts'. ========", + "======== Resolving module 'inner/mjs/index.mjs' from '/.src/node_modules/inner/index.d.mts'. ========", + "Resolution for module 'inner/mjs/index.mjs' was found in cache from location '/.src/node_modules/inner'.", + "======== Module name 'inner/mjs/index.mjs' was successfully resolved to '/.src/node_modules/inner/index.d.mts'. ========", + "======== Resolving module 'inner/js/index.js' from '/.src/node_modules/inner/index.d.mts'. ========", + "Resolution for module 'inner/js/index.js' was found in cache from location '/.src/node_modules/inner'.", + "======== Module name 'inner/js/index.js' was successfully resolved to '/.src/node_modules/inner/index.d.ts'. ========", "File '/.ts/package.json' does not exist.", "File '/package.json' does not exist.", "======== Resolving module '@typescript/lib-esnext' from '/.src/__lib_node_modules_lookup_lib.esnext.d.ts__.ts'. ========", diff --git a/tests/baselines/reference/selfNameAndImportsEmitInclusion.js b/tests/baselines/reference/selfNameAndImportsEmitInclusion.js new file mode 100644 index 00000000000..e8e1e014ab4 --- /dev/null +++ b/tests/baselines/reference/selfNameAndImportsEmitInclusion.js @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/selfNameAndImportsEmitInclusion.ts] //// + +//// [package.json] +{ + "name": "pkg", + "type": "module", + "imports": { + "#indirect1": "./src/indirect1.ts" + }, + "exports": { + "./*": "./dist/*" + } +} + +//// [indirect1.ts] +export const indirect1 = 0; + +//// [indirect2.ts] +export const indirect2 = 0; + +//// [main.ts] +import { indirect1 } from "#indirect1"; +import { indirect2 } from "pkg/indirect2.js"; +console.log(indirect1, indirect2); + + +//// [indirect1.js] +export const indirect1 = 0; +//// [indirect2.js] +export const indirect2 = 0; +//// [main.js] +import { indirect1 } from "#indirect1"; +import { indirect2 } from "pkg/indirect2.js"; +console.log(indirect1, indirect2); diff --git a/tests/baselines/reference/selfNameModuleAugmentation.trace.json b/tests/baselines/reference/selfNameModuleAugmentation.trace.json index c02409bd734..bdb18897065 100644 --- a/tests/baselines/reference/selfNameModuleAugmentation.trace.json +++ b/tests/baselines/reference/selfNameModuleAugmentation.trace.json @@ -23,7 +23,6 @@ "'package.json' does not have a 'peerDependencies' field.", "Resolved under condition 'default'.", "Exiting conditional exports.", - "Resolving real path for '/node_modules/acorn-walk/dist/walk.d.ts', result '/node_modules/acorn-walk/dist/walk.d.ts'.", "======== Module name 'acorn-walk' was successfully resolved to '/node_modules/acorn-walk/dist/walk.d.ts' with Package ID 'acorn-walk/dist/walk.d.ts@8.2.0'. ========", "======== Resolving module 'acorn-walk' from '/index.ts'. ========", "Explicitly specified module resolution kind: 'Bundler'.", diff --git a/tests/baselines/reference/tsbuild/moduleResolution/shared-resolution-should-not-report-error.js b/tests/baselines/reference/tsbuild/moduleResolution/shared-resolution-should-not-report-error.js index 0a4281d7009..fa310f31cae 100644 --- a/tests/baselines/reference/tsbuild/moduleResolution/shared-resolution-should-not-report-error.js +++ b/tests/baselines/reference/tsbuild/moduleResolution/shared-resolution-should-not-report-error.js @@ -103,7 +103,6 @@ File '/home/src/workspaces/project/packages/a/index.js' exists - use it as a nam 'package.json' does not have a 'peerDependencies' field. Resolved under condition 'types'. Exiting conditional exports. -Resolving real path for '/home/src/workspaces/project/packages/a/index.js', result '/home/src/workspaces/project/packages/a/index.js'. ======== Module name 'a' was successfully resolved to '/home/src/workspaces/project/packages/a/index.js' with Package ID 'a/index.js@0.0.0'. ======== File '/home/src/tslibs/TS/Lib/package.json' does not exist. File '/home/src/tslibs/TS/package.json' does not exist. @@ -115,6 +114,7 @@ File '/package.json' does not exist. Default library for target 'esnext' packages/a/index.js Matched by default include pattern '**/*' + Imported via 'a' from file 'packages/a/test/index.js' with packageId 'a/index.js@0.0.0' File is ECMAScript module because 'packages/a/package.json' has field "type" with value "module" packages/a/test/index.js Matched by default include pattern '**/*' diff --git a/tests/baselines/reference/tsbuild/moduleResolution/when-resolution-is-not-shared.js b/tests/baselines/reference/tsbuild/moduleResolution/when-resolution-is-not-shared.js index 7ef24e05216..f101000471b 100644 --- a/tests/baselines/reference/tsbuild/moduleResolution/when-resolution-is-not-shared.js +++ b/tests/baselines/reference/tsbuild/moduleResolution/when-resolution-is-not-shared.js @@ -102,7 +102,6 @@ File '/home/src/workspaces/project/packages/a/index.js' exists - use it as a nam 'package.json' does not have a 'peerDependencies' field. Resolved under condition 'types'. Exiting conditional exports. -Resolving real path for '/home/src/workspaces/project/packages/a/index.js', result '/home/src/workspaces/project/packages/a/index.js'. ======== Module name 'a' was successfully resolved to '/home/src/workspaces/project/packages/a/index.js' with Package ID 'a/index.js@0.0.0'. ======== File '/home/src/tslibs/TS/Lib/package.json' does not exist. File '/home/src/tslibs/TS/package.json' does not exist. @@ -114,6 +113,7 @@ File '/package.json' does not exist. Default library for target 'esnext' packages/a/index.js Matched by default include pattern '**/*' + Imported via 'a' from file 'packages/a/test/index.js' with packageId 'a/index.js@0.0.0' File is ECMAScript module because 'packages/a/package.json' has field "type" with value "module" packages/a/test/index.js Matched by default include pattern '**/*' diff --git a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/package-json-is-looked-up-for-file.js b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/package-json-is-looked-up-for-file.js index beca01c633d..71d47a724d7 100644 --- a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/package-json-is-looked-up-for-file.js +++ b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/package-json-is-looked-up-for-file.js @@ -59,7 +59,6 @@ File '/Users/name/projects/lib-boilerplate/package.json' exists according to ear Using 'exports' subpath '.' with target './src/index.ts'. File '/Users/name/projects/lib-boilerplate/src/index.ts' exists - use it as a name resolution result. 'package.json' does not have a 'peerDependencies' field. -Resolving real path for '/Users/name/projects/lib-boilerplate/src/index.ts', result '/Users/name/projects/lib-boilerplate/src/index.ts'. ======== Module name 'lib-boilerplate' was successfully resolved to '/Users/name/projects/lib-boilerplate/src/index.ts' with Package ID 'lib-boilerplate/src/index.ts@0.0.2'. ======== File '/home/src/tslibs/TS/Lib/package.json' does not exist. File '/home/src/tslibs/TS/package.json' does not exist. diff --git a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js index 0105455c35d..b8270ff4a22 100644 --- a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js +++ b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/self-name-package-reference.js @@ -55,7 +55,6 @@ Resolving in ESM mode with conditions 'import', 'types', 'node'. File '/Users/name/projects/web/package.json' exists according to earlier cached lookups. Using 'exports' subpath '.' with target './dist/index.js'. File '/Users/name/projects/web/index.ts' exists - use it as a name resolution result. -Resolving real path for '/Users/name/projects/web/index.ts', result '/Users/name/projects/web/index.ts'. ======== Module name '@this/package' was successfully resolved to '/Users/name/projects/web/index.ts'. ======== File '/home/src/tslibs/TS/Lib/package.json' does not exist. File '/home/src/tslibs/TS/package.json' does not exist. diff --git a/tests/baselines/reference/tscWatch/moduleResolution/diagnostics-from-cache.js b/tests/baselines/reference/tscWatch/moduleResolution/diagnostics-from-cache.js index 75b26665bb6..ba1110fbcc6 100644 --- a/tests/baselines/reference/tscWatch/moduleResolution/diagnostics-from-cache.js +++ b/tests/baselines/reference/tscWatch/moduleResolution/diagnostics-from-cache.js @@ -64,7 +64,6 @@ Using 'exports' subpath '.' with target './dist/index.js'. File '/user/username/projects/myproject/index.ts' exists - use it as a name resolution result. Resolved under condition 'default'. Exiting conditional exports. -Resolving real path for '/user/username/projects/myproject/index.ts', result '/user/username/projects/myproject/index.ts'. ======== Module name '@this/package' was successfully resolved to '/user/username/projects/myproject/index.ts'. ======== File '/user/username/projects/myproject/package.json' exists according to earlier cached lookups. File '/home/src/tslibs/TS/Lib/package.json' does not exist. diff --git a/tests/cases/compiler/selfNameAndImportsEmitInclusion.ts b/tests/cases/compiler/selfNameAndImportsEmitInclusion.ts new file mode 100644 index 00000000000..40cf548adea --- /dev/null +++ b/tests/cases/compiler/selfNameAndImportsEmitInclusion.ts @@ -0,0 +1,34 @@ +// @noTypesAndSymbols: true + +// @Filename: /tsconfig.json +{ + "compilerOptions": { + "module": "nodenext", + "outDir": "dist", + "rootDir": "src", + }, + "files": ["src/main.ts"] +} + +// @Filename: /package.json +{ + "name": "pkg", + "type": "module", + "imports": { + "#indirect1": "./src/indirect1.ts" + }, + "exports": { + "./*": "./dist/*" + } +} + +// @Filename: /src/indirect1.ts +export const indirect1 = 0; + +// @Filename: /src/indirect2.ts +export const indirect2 = 0; + +// @Filename: /src/main.ts +import { indirect1 } from "#indirect1"; +import { indirect2 } from "pkg/indirect2.js"; +console.log(indirect1, indirect2);