From b12d57b5d1f078dd0e52d681087e06dfce93bdfe Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 3 Feb 2023 15:45:56 -0800 Subject: [PATCH 1/2] Trace when executing a buggy resolution behavior --- src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/moduleNameResolver.ts | 3 +++ ...outExportsDiagnostic1(moduleresolution=bundler).trace.json | 2 ++ ...houtExportsDiagnostic1(moduleresolution=node16).trace.json | 2 ++ .../baselines/reference/selfNameModuleAugmentation.trace.json | 2 ++ .../module-resolutions-from-file-are-partially-used.js | 2 ++ .../moduleResolution/type-reference-resolutions-reuse.js | 1 + 7 files changed, 16 insertions(+) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e0e6f0077a976..0394d0103ffc8 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -5558,6 +5558,10 @@ "category": "Message", "code": 6412 }, + "Failed to resolve under condition '{0}'.": { + "category": "Message", + "code": 6413 + }, "The expected type comes from property '{0}' which is declared here on type '{1}'": { "category": "Message", diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 8263abea028ad..c7fa4a6d6e390 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -2592,6 +2592,9 @@ function getLoadModuleFromTargetImportOrExport(extensions: Extensions, state: Mo if (result) { return result; } + else { + traceIfEnabled(state, Diagnostics.Failed_to_resolve_under_condition_0, condition); + } } else { traceIfEnabled(state, Diagnostics.Saw_non_matching_condition_0, condition); diff --git a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json index 86b684ebdf505..9d561bc111b66 100644 --- a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json +++ b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json @@ -9,6 +9,7 @@ "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/foo/index.mts' does not exist.", "File '/node_modules/foo/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", "File '/node_modules/@types/foo.d.ts' does not exist.", "File '/node_modules/foo/package.json' exists according to earlier cached lookups.", @@ -39,6 +40,7 @@ "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/bar/index.mts' does not exist.", "File '/node_modules/bar/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", "Found 'package.json' at '/node_modules/@types/bar/package.json'.", "Saw non-matching condition 'require'.", diff --git a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json index 9312334354570..a9489d4385edb 100644 --- a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json +++ b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json @@ -12,6 +12,7 @@ "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/foo/index.mts' does not exist.", "File '/node_modules/foo/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", "File '/node_modules/foo/package.json' exists according to earlier cached lookups.", "Matched 'exports' condition 'import'.", @@ -39,6 +40,7 @@ "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/bar/index.mts' does not exist.", "File '/node_modules/bar/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", "File '/node_modules/@types/bar/package.json' exists according to earlier cached lookups.", "Saw non-matching condition 'require'.", diff --git a/tests/baselines/reference/selfNameModuleAugmentation.trace.json b/tests/baselines/reference/selfNameModuleAugmentation.trace.json index f9b4d54f55df1..f0e15fc951853 100644 --- a/tests/baselines/reference/selfNameModuleAugmentation.trace.json +++ b/tests/baselines/reference/selfNameModuleAugmentation.trace.json @@ -8,6 +8,7 @@ "File name '/node_modules/acorn-walk/dist/walk.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/acorn-walk/dist/walk.mts' does not exist.", "File '/node_modules/acorn-walk/dist/walk.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", "Matched 'exports' condition 'default'.", "Using 'exports' subpath '.' with target './dist/walk.js'.", @@ -27,6 +28,7 @@ "File name '/node_modules/acorn-walk/dist/walk.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/acorn-walk/dist/walk.mts' does not exist.", "File '/node_modules/acorn-walk/dist/walk.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", "Matched 'exports' condition 'default'.", "Using 'exports' subpath '.' with target './dist/walk.js'.", diff --git a/tests/baselines/reference/tscWatch/moduleResolution/module-resolutions-from-file-are-partially-used.js b/tests/baselines/reference/tscWatch/moduleResolution/module-resolutions-from-file-are-partially-used.js index a1db17bcd32d3..f5def1a3c2f1f 100644 --- a/tests/baselines/reference/tscWatch/moduleResolution/module-resolutions-from-file-are-partially-used.js +++ b/tests/baselines/reference/tscWatch/moduleResolution/module-resolutions-from-file-are-partially-used.js @@ -91,6 +91,7 @@ File name '/user/username/projects/myproject/node_modules/pkg1/require.js' has a File '/user/username/projects/myproject/node_modules/pkg1/require.ts' does not exist. File '/user/username/projects/myproject/node_modules/pkg1/require.tsx' does not exist. File '/user/username/projects/myproject/node_modules/pkg1/require.d.ts' does not exist. +Failed to resolve under condition 'require'. Directory '/user/username/projects/myproject/node_modules/@types' does not exist, skipping all lookups in it. Directory '/user/username/projects/node_modules' does not exist, skipping all lookups in it. Directory '/user/username/node_modules' does not exist, skipping all lookups in it. @@ -103,6 +104,7 @@ Using 'exports' subpath '.' with target './require.js'. File name '/user/username/projects/myproject/node_modules/pkg1/require.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg1/require.js' does not exist. File '/user/username/projects/myproject/node_modules/pkg1/require.jsx' does not exist. +Failed to resolve under condition 'require'. Directory '/user/username/projects/node_modules' does not exist, skipping all lookups in it. Directory '/user/username/node_modules' does not exist, skipping all lookups in it. Directory '/user/node_modules' does not exist, skipping all lookups in it. diff --git a/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js b/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js index fc84db6c07497..56d0d3aaae9b3 100644 --- a/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js +++ b/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js @@ -90,6 +90,7 @@ Matched 'exports' condition 'require'. Using 'exports' subpath '.' with target './require.js'. File name '/user/username/projects/myproject/node_modules/pkg1/require.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg1/require.d.ts' does not exist. +Failed to resolve under condition 'require'. File '/user/username/projects/myproject/node_modules/@types/pkg1.d.ts' does not exist. Directory '/user/username/projects/node_modules' does not exist, skipping all lookups in it. Directory '/user/username/node_modules' does not exist, skipping all lookups in it. From c3c7467ba05e8384f492866fe00059bee1cf1d37 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Fri, 3 Feb 2023 16:38:28 -0800 Subject: [PATCH 2/2] Make trace pattern parseable --- src/compiler/diagnosticMessages.json | 14 ++++++- src/compiler/moduleNameResolver.ts | 4 ++ .../reference/bundlerNodeModules1.trace.json | 3 ++ ...lback(moduleresolution=bundler).trace.json | 22 +++++++++++ ...llback(moduleresolution=node16).trace.json | 39 +++++++++++++++++++ ...back(moduleresolution=nodenext).trace.json | 39 +++++++++++++++++++ ...resolvepackagejsonexports=true).trace.json | 3 ++ ...cksTypesVersions(module=node16).trace.json | 20 ++++++++++ ...sTypesVersions(module=nodenext).trace.json | 20 ++++++++++ ...stic1(moduleresolution=bundler).trace.json | 12 ++++++ ...ostic1(moduleresolution=node16).trace.json | 12 ++++++ .../selfNameModuleAugmentation.trace.json | 6 +++ .../with-nodeNext-resolution.js | 6 +++ .../diagnostics-from-cache.js | 3 ++ ...esolutions-from-file-are-partially-used.js | 10 +++++ .../type-reference-resolutions-reuse.js | 8 ++++ .../conditionalExportsResolutionFallback.ts | 33 ++++++++++++++++ 17 files changed, 253 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=bundler).trace.json create mode 100644 tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=node16).trace.json create mode 100644 tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=nodenext).trace.json create mode 100644 tests/cases/conformance/moduleResolution/conditionalExportsResolutionFallback.ts diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0394d0103ffc8..843a5508bf706 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -5558,10 +5558,22 @@ "category": "Message", "code": 6412 }, - "Failed to resolve under condition '{0}'.": { + "Entering conditional exports.": { "category": "Message", "code": 6413 }, + "Resolved under condition '{0}'.": { + "category": "Message", + "code": 6414 + }, + "Failed to resolve under condition '{0}'.": { + "category": "Message", + "code": 6415 + }, + "Exiting conditional exports.": { + "category": "Message", + "code": 6416 + }, "The expected type comes from property '{0}' which is declared here on type '{1}'": { "category": "Message", diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index c7fa4a6d6e390..e042cf6512b0f 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -2584,12 +2584,15 @@ function getLoadModuleFromTargetImportOrExport(extensions: Extensions, state: Mo } else if (typeof target === "object" && target !== null) { // eslint-disable-line no-null/no-null if (!Array.isArray(target)) { + traceIfEnabled(state, Diagnostics.Entering_conditional_exports); for (const condition of getOwnKeys(target as MapLike)) { if (condition === "default" || state.conditions.indexOf(condition) >= 0 || isApplicableVersionedTypesKey(state.conditions, condition)) { traceIfEnabled(state, Diagnostics.Matched_0_condition_1, isImports ? "imports" : "exports", condition); const subTarget = (target as MapLike)[condition]; const result = loadModuleFromTargetImportOrExport(subTarget, subpath, pattern, key); if (result) { + traceIfEnabled(state, Diagnostics.Resolved_under_condition_0, condition); + traceIfEnabled(state, Diagnostics.Exiting_conditional_exports); return result; } else { @@ -2600,6 +2603,7 @@ function getLoadModuleFromTargetImportOrExport(extensions: Extensions, state: Mo traceIfEnabled(state, Diagnostics.Saw_non_matching_condition_0, condition); } } + traceIfEnabled(state, Diagnostics.Exiting_conditional_exports); return undefined; } else { diff --git a/tests/baselines/reference/bundlerNodeModules1.trace.json b/tests/baselines/reference/bundlerNodeModules1.trace.json index b8728c149e960..2d60a6f2765f4 100644 --- a/tests/baselines/reference/bundlerNodeModules1.trace.json +++ b/tests/baselines/reference/bundlerNodeModules1.trace.json @@ -4,12 +4,15 @@ "File '/package.json' does not exist.", "Loading module 'dual' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", "Found 'package.json' at '/node_modules/dual/package.json'.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.js'.", "File name '/node_modules/dual/index.js' has a '.js' extension - stripping it.", "File '/node_modules/dual/index.ts' does not exist.", "File '/node_modules/dual/index.tsx' does not exist.", "File '/node_modules/dual/index.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'import'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/dual/index.d.ts', result '/node_modules/dual/index.d.ts'.", "======== Module name 'dual' was successfully resolved to '/node_modules/dual/index.d.ts' with Package ID 'dual/index.d.ts@1.0.0'. ========", "======== Resolving module 'dual' from '/main.mts'. ========", diff --git a/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=bundler).trace.json b/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=bundler).trace.json new file mode 100644 index 0000000000000..4082b9545e345 --- /dev/null +++ b/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=bundler).trace.json @@ -0,0 +1,22 @@ +[ + "======== Resolving module 'dep' from '/index.mts'. ========", + "Explicitly specified module resolution kind: 'Bundler'.", + "File '/package.json' does not exist.", + "Loading module 'dep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", + "Found 'package.json' at '/node_modules/dep/package.json'.", + "Entering conditional exports.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './dist/index.mjs'.", + "File name '/node_modules/dep/dist/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/dep/dist/index.mts' does not exist.", + "File '/node_modules/dep/dist/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", + "Saw non-matching condition 'require'.", + "Matched 'exports' condition 'types'.", + "Using 'exports' subpath '.' with target './dist/index.d.ts'.", + "File '/node_modules/dep/dist/index.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", + "Resolving real path for '/node_modules/dep/dist/index.d.ts', result '/node_modules/dep/dist/index.d.ts'.", + "======== Module name 'dep' was successfully resolved to '/node_modules/dep/dist/index.d.ts' with Package ID 'dep/dist/index.d.ts@1.0.0'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=node16).trace.json b/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=node16).trace.json new file mode 100644 index 0000000000000..f99d7a4fa0516 --- /dev/null +++ b/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=node16).trace.json @@ -0,0 +1,39 @@ +[ + "File '/node_modules/dep/dist/package.json' does not exist.", + "Found 'package.json' at '/node_modules/dep/package.json'.", + "======== Resolving module 'dep' from '/index.mts'. ========", + "Explicitly specified module resolution kind: 'Node16'.", + "Resolving in ESM mode with conditions 'node', 'import', 'types'.", + "File '/package.json' does not exist.", + "Loading module 'dep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", + "File '/node_modules/dep/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './dist/index.mjs'.", + "File name '/node_modules/dep/dist/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/dep/dist/index.mts' does not exist.", + "File '/node_modules/dep/dist/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", + "Saw non-matching condition 'require'.", + "Matched 'exports' condition 'types'.", + "Using 'exports' subpath '.' with target './dist/index.d.ts'.", + "File '/node_modules/dep/dist/index.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", + "Resolving real path for '/node_modules/dep/dist/index.d.ts', result '/node_modules/dep/dist/index.d.ts'.", + "======== Module name 'dep' was successfully resolved to '/node_modules/dep/dist/index.d.ts' with Package ID 'dep/dist/index.d.ts@1.0.0'. ========", + "File 'package.json' does not exist.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups." +] \ No newline at end of file diff --git a/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=nodenext).trace.json b/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=nodenext).trace.json new file mode 100644 index 0000000000000..4c63ea4889b66 --- /dev/null +++ b/tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=nodenext).trace.json @@ -0,0 +1,39 @@ +[ + "File '/node_modules/dep/dist/package.json' does not exist.", + "Found 'package.json' at '/node_modules/dep/package.json'.", + "======== Resolving module 'dep' from '/index.mts'. ========", + "Explicitly specified module resolution kind: 'NodeNext'.", + "Resolving in ESM mode with conditions 'node', 'import', 'types'.", + "File '/package.json' does not exist.", + "Loading module 'dep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", + "File '/node_modules/dep/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", + "Matched 'exports' condition 'import'.", + "Using 'exports' subpath '.' with target './dist/index.mjs'.", + "File name '/node_modules/dep/dist/index.mjs' has a '.mjs' extension - stripping it.", + "File '/node_modules/dep/dist/index.mts' does not exist.", + "File '/node_modules/dep/dist/index.d.mts' does not exist.", + "Failed to resolve under condition 'import'.", + "Saw non-matching condition 'require'.", + "Matched 'exports' condition 'types'.", + "Using 'exports' subpath '.' with target './dist/index.d.ts'.", + "File '/node_modules/dep/dist/index.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", + "Resolving real path for '/node_modules/dep/dist/index.d.ts', result '/node_modules/dep/dist/index.d.ts'.", + "======== Module name 'dep' was successfully resolved to '/node_modules/dep/dist/index.d.ts' with Package ID 'dep/dist/index.d.ts@1.0.0'. ========", + "File 'package.json' does not exist.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups.", + "File 'package.json' does not exist according to earlier cached lookups.", + "File '/package.json' does not exist according to earlier cached lookups." +] \ No newline at end of file diff --git a/tests/baselines/reference/customConditions(resolvepackagejsonexports=true).trace.json b/tests/baselines/reference/customConditions(resolvepackagejsonexports=true).trace.json index 5b02129d63960..48028b7f755d7 100644 --- a/tests/baselines/reference/customConditions(resolvepackagejsonexports=true).trace.json +++ b/tests/baselines/reference/customConditions(resolvepackagejsonexports=true).trace.json @@ -4,6 +4,7 @@ "File '/package.json' does not exist.", "Loading module 'lodash' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", "Found 'package.json' at '/node_modules/lodash/package.json'.", + "Entering conditional exports.", "Saw non-matching condition 'browser'.", "Matched 'exports' condition 'webpack'.", "Using 'exports' subpath '.' with target './webpack.js'.", @@ -11,6 +12,8 @@ "File '/node_modules/lodash/webpack.ts' does not exist.", "File '/node_modules/lodash/webpack.tsx' does not exist.", "File '/node_modules/lodash/webpack.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'webpack'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/lodash/webpack.d.ts', result '/node_modules/lodash/webpack.d.ts'.", "======== Module name 'lodash' was successfully resolved to '/node_modules/lodash/webpack.d.ts' with Package ID 'lodash/webpack.d.ts@1.0.0'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json index a4d5f1584f99d..2de6e35148566 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json @@ -39,9 +39,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types'.", "Using 'exports' subpath './yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-yep' from '/main.cts'. ========", @@ -50,9 +53,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types@>=4'.", "Using 'exports' subpath './versioned-yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types@>=4'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/versioned-yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-nah' from '/main.cts'. ========", @@ -61,11 +67,15 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-nah' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "======== Module name 'exports-and-types-versions/versioned-nah' was not resolved. ========", "======== Resolving module 'just-types-versions/foo' from '/main.cts'. ========", @@ -126,9 +136,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types'.", "Using 'exports' subpath './yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-yep' from '/main.mts'. ========", @@ -137,9 +150,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types@>=4'.", "Using 'exports' subpath './versioned-yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types@>=4'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/versioned-yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-nah' from '/main.mts'. ========", @@ -148,11 +164,15 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-nah' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "======== Module name 'exports-and-types-versions/versioned-nah' was not resolved. ========", "======== Resolving module 'just-types-versions/foo' from '/main.mts'. ========", diff --git a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json index c3b4275e49cd0..6f42ddd75ee24 100644 --- a/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json +++ b/tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json @@ -39,9 +39,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types'.", "Using 'exports' subpath './yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-yep' from '/main.cts'. ========", @@ -50,9 +53,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types@>=4'.", "Using 'exports' subpath './versioned-yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types@>=4'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/versioned-yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-nah' from '/main.cts'. ========", @@ -61,11 +67,15 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-nah' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "======== Module name 'exports-and-types-versions/versioned-nah' was not resolved. ========", "======== Resolving module 'just-types-versions/foo' from '/main.cts'. ========", @@ -126,9 +136,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types'.", "Using 'exports' subpath './yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-yep' from '/main.mts'. ========", @@ -137,9 +150,12 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-yep' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'types@>=4'.", "Using 'exports' subpath './versioned-yep' with target './types/foo.d.ts'.", "File '/node_modules/exports-and-types-versions/types/foo.d.ts' exists - use it as a name resolution result.", + "Resolved under condition 'types@>=4'.", + "Exiting conditional exports.", "Resolving real path for '/node_modules/exports-and-types-versions/types/foo.d.ts', result '/node_modules/exports-and-types-versions/types/foo.d.ts'.", "======== Module name 'exports-and-types-versions/versioned-yep' was successfully resolved to '/node_modules/exports-and-types-versions/types/foo.d.ts' with Package ID 'exports-and-types-versions/types/foo.d.ts@1.0.0'. ========", "======== Resolving module 'exports-and-types-versions/versioned-nah' from '/main.mts'. ========", @@ -148,11 +164,15 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'exports-and-types-versions/versioned-nah' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "File '/node_modules/exports-and-types-versions/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'types@<4'.", + "Exiting conditional exports.", "Export specifier './versioned-nah' does not exist in package.json scope at path '/node_modules/exports-and-types-versions'.", "======== Module name 'exports-and-types-versions/versioned-nah' was not resolved. ========", "======== Resolving module 'just-types-versions/foo' from '/main.mts'. ========", diff --git a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json index 9d561bc111b66..2a50df0adeead 100644 --- a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json +++ b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=bundler).trace.json @@ -4,6 +4,7 @@ "File '/package.json' does not exist.", "Loading module 'foo' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", @@ -11,12 +12,16 @@ "File '/node_modules/foo/index.d.mts' does not exist.", "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", + "Exiting conditional exports.", "File '/node_modules/@types/foo.d.ts' does not exist.", "File '/node_modules/foo/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/foo/index.mjs' exists - use it as a name resolution result.", + "Resolved under condition 'import'.", + "Exiting conditional exports.", "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'foo' from 'node_modules' folder, target file types: TypeScript, Declaration.", @@ -35,6 +40,7 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'bar' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", "Found 'package.json' at '/node_modules/bar/package.json'.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", @@ -42,13 +48,19 @@ "File '/node_modules/bar/index.d.mts' does not exist.", "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", + "Exiting conditional exports.", "Found 'package.json' at '/node_modules/@types/bar/package.json'.", + "Entering conditional exports.", "Saw non-matching condition 'require'.", + "Exiting conditional exports.", "File '/node_modules/bar/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/bar/index.mjs' exists - use it as a name resolution result.", + "Resolved under condition 'import'.", + "Exiting conditional exports.", "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'bar' from 'node_modules' folder, target file types: TypeScript, Declaration.", diff --git a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json index a9489d4385edb..9c99e7dbe3ac8 100644 --- a/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json +++ b/tests/baselines/reference/resolvesWithoutExportsDiagnostic1(moduleresolution=node16).trace.json @@ -7,6 +7,7 @@ "File '/package.json' does not exist.", "Loading module 'foo' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "File '/node_modules/foo/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", @@ -14,11 +15,15 @@ "File '/node_modules/foo/index.d.mts' does not exist.", "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", + "Exiting conditional exports.", "File '/node_modules/foo/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/foo/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/foo/index.mjs' exists - use it as a name resolution result.", + "Resolved under condition 'import'.", + "Exiting conditional exports.", "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'foo' from 'node_modules' folder, target file types: TypeScript, Declaration.", @@ -35,6 +40,7 @@ "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'bar' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration.", "Found 'package.json' at '/node_modules/bar/package.json'.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", @@ -42,13 +48,19 @@ "File '/node_modules/bar/index.d.mts' does not exist.", "Failed to resolve under condition 'import'.", "Saw non-matching condition 'require'.", + "Exiting conditional exports.", "File '/node_modules/@types/bar/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Saw non-matching condition 'require'.", + "Exiting conditional exports.", "File '/node_modules/bar/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './index.mjs'.", "File name '/node_modules/bar/index.mjs' has a '.mjs' extension - stripping it.", "File '/node_modules/bar/index.mjs' exists - use it as a name resolution result.", + "Resolved under condition 'import'.", + "Exiting conditional exports.", "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", "File '/package.json' does not exist according to earlier cached lookups.", "Loading module 'bar' from 'node_modules' folder, target file types: TypeScript, Declaration.", diff --git a/tests/baselines/reference/selfNameModuleAugmentation.trace.json b/tests/baselines/reference/selfNameModuleAugmentation.trace.json index f0e15fc951853..fa0232b7c6ebf 100644 --- a/tests/baselines/reference/selfNameModuleAugmentation.trace.json +++ b/tests/baselines/reference/selfNameModuleAugmentation.trace.json @@ -3,6 +3,7 @@ "Explicitly specified module resolution kind: 'Bundler'.", "File '/node_modules/acorn-walk/dist/package.json' does not exist.", "Found 'package.json' at '/node_modules/acorn-walk/package.json'.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './dist/walk.mjs'.", "File name '/node_modules/acorn-walk/dist/walk.mjs' has a '.mjs' extension - stripping it.", @@ -16,6 +17,8 @@ "File '/node_modules/acorn-walk/dist/walk.ts' does not exist.", "File '/node_modules/acorn-walk/dist/walk.tsx' does not exist.", "File '/node_modules/acorn-walk/dist/walk.d.ts' exists - use it as a name resolution result.", + "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'. ========", @@ -23,6 +26,7 @@ "File '/package.json' does not exist.", "Loading module 'acorn-walk' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", "File '/node_modules/acorn-walk/package.json' exists according to earlier cached lookups.", + "Entering conditional exports.", "Matched 'exports' condition 'import'.", "Using 'exports' subpath '.' with target './dist/walk.mjs'.", "File name '/node_modules/acorn-walk/dist/walk.mjs' has a '.mjs' extension - stripping it.", @@ -36,6 +40,8 @@ "File '/node_modules/acorn-walk/dist/walk.ts' does not exist.", "File '/node_modules/acorn-walk/dist/walk.tsx' does not exist.", "File '/node_modules/acorn-walk/dist/walk.d.ts' exists - use it as a name resolution result.", + "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'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js index 02144e8380445..20deca3dbd2fb 100644 --- a/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js +++ b/tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/with-nodeNext-resolution.js @@ -54,11 +54,17 @@ File '/Users/name/projects/web/node_modules/yargs.ts' does not exist. File '/Users/name/projects/web/node_modules/yargs.tsx' does not exist. File '/Users/name/projects/web/node_modules/yargs.d.ts' does not exist. Found 'package.json' at '/Users/name/projects/web/node_modules/@types/yargs/package.json'. +Entering conditional exports. Matched 'exports' condition 'types'. +Entering conditional exports. Saw non-matching condition 'import'. Matched 'exports' condition 'default'. Using 'exports' subpath '.' with target './index.d.ts'. File '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' exists - use it as a name resolution result. +Resolved under condition 'default'. +Exiting conditional exports. +Resolved under condition 'types'. +Exiting conditional exports. Resolving real path for '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts', result '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts'. ======== Module name 'yargs' was successfully resolved to '/Users/name/projects/web/node_modules/@types/yargs/index.d.ts' with Package ID 'yargs/index.d.ts@17.0.12'. ======== File '/Users/name/projects/web/node_modules/@types/yargs/package.json' exists according to earlier cached lookups. diff --git a/tests/baselines/reference/tscWatch/moduleResolution/diagnostics-from-cache.js b/tests/baselines/reference/tscWatch/moduleResolution/diagnostics-from-cache.js index 5ef1629af560a..28a6ab7fd28d4 100644 --- a/tests/baselines/reference/tscWatch/moduleResolution/diagnostics-from-cache.js +++ b/tests/baselines/reference/tscWatch/moduleResolution/diagnostics-from-cache.js @@ -39,9 +39,12 @@ Found 'package.json' at '/user/username/projects/myproject/package.json'. Explicitly specified module resolution kind: 'NodeNext'. Resolving in ESM mode with conditions 'node', 'import', 'types'. File '/user/username/projects/myproject/package.json' exists according to earlier cached lookups. +Entering conditional exports. Matched 'exports' condition 'default'. 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. diff --git a/tests/baselines/reference/tscWatch/moduleResolution/module-resolutions-from-file-are-partially-used.js b/tests/baselines/reference/tscWatch/moduleResolution/module-resolutions-from-file-are-partially-used.js index f5def1a3c2f1f..7bc2102e1680d 100644 --- a/tests/baselines/reference/tscWatch/moduleResolution/module-resolutions-from-file-are-partially-used.js +++ b/tests/baselines/reference/tscWatch/moduleResolution/module-resolutions-from-file-are-partially-used.js @@ -66,12 +66,15 @@ File '/user/package.json' does not exist according to earlier cached lookups. File '/package.json' does not exist according to earlier cached lookups. Loading module 'pkg' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration. Found 'package.json' at '/user/username/projects/myproject/node_modules/pkg/package.json'. +Entering conditional exports. Matched 'exports' condition 'import'. Using 'exports' subpath '.' with target './import.js'. File name '/user/username/projects/myproject/node_modules/pkg/import.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg/import.ts' does not exist. File '/user/username/projects/myproject/node_modules/pkg/import.tsx' does not exist. File '/user/username/projects/myproject/node_modules/pkg/import.d.ts' exists - use it as a name resolution result. +Resolved under condition 'import'. +Exiting conditional exports. Resolving real path for '/user/username/projects/myproject/node_modules/pkg/import.d.ts', result '/user/username/projects/myproject/node_modules/pkg/import.d.ts'. ======== Module name 'pkg' was successfully resolved to '/user/username/projects/myproject/node_modules/pkg/import.d.ts' with Package ID 'pkg/import.d.ts@0.0.1'. ======== ======== Resolving module 'pkg1' from '/user/username/projects/myproject/index.ts'. ======== @@ -84,6 +87,7 @@ File '/user/package.json' does not exist according to earlier cached lookups. File '/package.json' does not exist according to earlier cached lookups. Loading module 'pkg1' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration. Found 'package.json' at '/user/username/projects/myproject/node_modules/pkg1/package.json'. +Entering conditional exports. Saw non-matching condition 'import'. Matched 'exports' condition 'require'. Using 'exports' subpath '.' with target './require.js'. @@ -92,12 +96,14 @@ File '/user/username/projects/myproject/node_modules/pkg1/require.ts' does not e File '/user/username/projects/myproject/node_modules/pkg1/require.tsx' does not exist. File '/user/username/projects/myproject/node_modules/pkg1/require.d.ts' does not exist. Failed to resolve under condition 'require'. +Exiting conditional exports. Directory '/user/username/projects/myproject/node_modules/@types' does not exist, skipping all lookups in it. Directory '/user/username/projects/node_modules' does not exist, skipping all lookups in it. Directory '/user/username/node_modules' does not exist, skipping all lookups in it. Directory '/user/node_modules' does not exist, skipping all lookups in it. Directory '/node_modules' does not exist, skipping all lookups in it. File '/user/username/projects/myproject/node_modules/pkg1/package.json' exists according to earlier cached lookups. +Entering conditional exports. Saw non-matching condition 'import'. Matched 'exports' condition 'require'. Using 'exports' subpath '.' with target './require.js'. @@ -105,6 +111,7 @@ File name '/user/username/projects/myproject/node_modules/pkg1/require.js' has a File '/user/username/projects/myproject/node_modules/pkg1/require.js' does not exist. File '/user/username/projects/myproject/node_modules/pkg1/require.jsx' does not exist. Failed to resolve under condition 'require'. +Exiting conditional exports. Directory '/user/username/projects/node_modules' does not exist, skipping all lookups in it. Directory '/user/username/node_modules' does not exist, skipping all lookups in it. Directory '/user/node_modules' does not exist, skipping all lookups in it. @@ -238,12 +245,15 @@ File '/user/package.json' does not exist according to earlier cached lookups. File '/package.json' does not exist according to earlier cached lookups. Loading module 'pkg' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration. File '/user/username/projects/myproject/node_modules/pkg/package.json' exists according to earlier cached lookups. +Entering conditional exports. Matched 'exports' condition 'import'. Using 'exports' subpath '.' with target './import.js'. File name '/user/username/projects/myproject/node_modules/pkg/import.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg/import.ts' does not exist. File '/user/username/projects/myproject/node_modules/pkg/import.tsx' does not exist. File '/user/username/projects/myproject/node_modules/pkg/import.d.ts' exists - use it as a name resolution result. +Resolved under condition 'import'. +Exiting conditional exports. Resolving real path for '/user/username/projects/myproject/node_modules/pkg/import.d.ts', result '/user/username/projects/myproject/node_modules/pkg/import.d.ts'. ======== Module name 'pkg' was successfully resolved to '/user/username/projects/myproject/node_modules/pkg/import.d.ts' with Package ID 'pkg/import.d.ts@0.0.1'. ======== File '/user/username/projects/myproject/node_modules/pkg/package.json' exists according to earlier cached lookups. diff --git a/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js b/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js index 56d0d3aaae9b3..827b58d73b992 100644 --- a/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js +++ b/tests/baselines/reference/tscWatch/moduleResolution/type-reference-resolutions-reuse.js @@ -75,22 +75,27 @@ File '/package.json' does not exist according to earlier cached lookups. Resolving with primary search path '/user/username/projects/myproject/node_modules/@types'. Looking up in 'node_modules' folder, initial location '/user/username/projects/myproject'. Found 'package.json' at '/user/username/projects/myproject/node_modules/pkg/package.json'. +Entering conditional exports. Matched 'exports' condition 'import'. Using 'exports' subpath '.' with target './import.js'. File name '/user/username/projects/myproject/node_modules/pkg/import.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg/import.d.ts' exists - use it as a name resolution result. +Resolved under condition 'import'. +Exiting conditional exports. Resolving real path for '/user/username/projects/myproject/node_modules/pkg/import.d.ts', result '/user/username/projects/myproject/node_modules/pkg/import.d.ts'. ======== Type reference directive 'pkg' was successfully resolved to '/user/username/projects/myproject/node_modules/pkg/import.d.ts' with Package ID 'pkg/import.d.ts@0.0.1', primary: false. ======== ======== Resolving type reference directive 'pkg1', containing file '/user/username/projects/myproject/index.ts', root directory '/user/username/projects/myproject/node_modules/@types'. ======== Resolving with primary search path '/user/username/projects/myproject/node_modules/@types'. Looking up in 'node_modules' folder, initial location '/user/username/projects/myproject'. Found 'package.json' at '/user/username/projects/myproject/node_modules/pkg1/package.json'. +Entering conditional exports. Saw non-matching condition 'import'. Matched 'exports' condition 'require'. Using 'exports' subpath '.' with target './require.js'. File name '/user/username/projects/myproject/node_modules/pkg1/require.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg1/require.d.ts' does not exist. Failed to resolve under condition 'require'. +Exiting conditional exports. File '/user/username/projects/myproject/node_modules/@types/pkg1.d.ts' does not exist. Directory '/user/username/projects/node_modules' does not exist, skipping all lookups in it. Directory '/user/username/node_modules' does not exist, skipping all lookups in it. @@ -252,10 +257,13 @@ File '/package.json' does not exist according to earlier cached lookups. Resolving with primary search path '/user/username/projects/myproject/node_modules/@types'. Looking up in 'node_modules' folder, initial location '/user/username/projects/myproject'. File '/user/username/projects/myproject/node_modules/pkg/package.json' exists according to earlier cached lookups. +Entering conditional exports. Matched 'exports' condition 'import'. Using 'exports' subpath '.' with target './import.js'. File name '/user/username/projects/myproject/node_modules/pkg/import.js' has a '.js' extension - stripping it. File '/user/username/projects/myproject/node_modules/pkg/import.d.ts' exists - use it as a name resolution result. +Resolved under condition 'import'. +Exiting conditional exports. Resolving real path for '/user/username/projects/myproject/node_modules/pkg/import.d.ts', result '/user/username/projects/myproject/node_modules/pkg/import.d.ts'. ======== Type reference directive 'pkg' was successfully resolved to '/user/username/projects/myproject/node_modules/pkg/import.d.ts' with Package ID 'pkg/import.d.ts@0.0.1', primary: false. ======== File '/user/username/projects/myproject/node_modules/pkg/package.json' exists according to earlier cached lookups. diff --git a/tests/cases/conformance/moduleResolution/conditionalExportsResolutionFallback.ts b/tests/cases/conformance/moduleResolution/conditionalExportsResolutionFallback.ts new file mode 100644 index 0000000000000..d9a1d480b8ef3 --- /dev/null +++ b/tests/cases/conformance/moduleResolution/conditionalExportsResolutionFallback.ts @@ -0,0 +1,33 @@ +// @moduleResolution: node16,nodenext,bundler +// @traceResolution: true +// @allowJs: true +// @noTypesAndSymbols: true +// @noEmit: true + +// This documents bug https://github.com/microsoft/TypeScript/issues/50762. + +// @Filename: /node_modules/dep/package.json +{ + "name": "dep", + "version": "1.0.0", + "exports": { + ".": { + "import": "./dist/index.mjs", + "require": "./dist/index.js", + "types": "./dist/index.d.ts", + } + } +} + +// @Filename: /node_modules/dep/dist/index.d.ts +export {}; + +// @Filename: /node_modules/dep/dist/index.mjs +export {}; + +// @Filename: /index.mts +import {} from "dep"; +// Should be an untyped resolution to dep/dist/index.mjs, +// but the first search is only for TS files, and when +// there's no dist/index.d.mts, it continues looking for +// matching conditions and resolves via `types`. \ No newline at end of file