Skip to content

Commit 2ee80a8

Browse files
authored
Fix tsconfig.json not found with TS >= 5.3 (#2091)
1 parent 9f36df2 commit 2ee80a8

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

src/test/regression.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ const exec = createExecTester({
1414
}),
1515
});
1616

17+
test('#2076 regression test', async () => {
18+
const r = await exec({
19+
exec: createExec({
20+
cwd: join(TEST_DIR, '2076'),
21+
}),
22+
cmd: `${CMD_TS_NODE_WITHOUT_PROJECT_FLAG} --showConfig`,
23+
});
24+
25+
exp(r.err).toBeNull();
26+
});
27+
1728
test('#1488 regression test', async () => {
1829
// Scenario that caused the bug:
1930
// `allowJs` turned on

src/ts-compiler-types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ export interface TSInternal {
9090
host: _ts.ModuleResolutionHost,
9191
cache?: _ts.ModuleResolutionCache,
9292
redirectedReference?: _ts.ResolvedProjectReference,
93-
lookupConfig?: boolean
93+
conditionsOrIsConfigLookup?: string[] | boolean, // `conditions` parameter added in TS 5.3
94+
isConfigLookup?: boolean
9495
): _ts.ResolvedModuleWithFailedLookupLocations;
9596
// Added in TS 4.7
9697
getModeForFileReference?: (

src/ts-internals.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isAbsolute, resolve } from 'path';
2-
import { cachedLookup, normalizeSlashes } from './util';
2+
import { cachedLookup, normalizeSlashes, versionGteLt } from './util';
33
import type * as _ts from 'typescript';
44
import type { TSCommon, TSInternal } from './ts-compiler-types';
55

@@ -40,14 +40,16 @@ function createTsInternalsUncached(_ts: TSCommon) {
4040
return extendedConfigPath;
4141
}
4242
// If the path isn't a rooted or relative path, resolve like a module
43+
const tsGte5_3_0 = versionGteLt(ts.version, '5.3.0');
4344
const resolved = ts.nodeModuleNameResolver(
4445
extendedConfig,
4546
combinePaths(basePath, 'tsconfig.json'),
4647
{ moduleResolution: ts.ModuleResolutionKind.NodeJs },
4748
host,
4849
/*cache*/ undefined,
4950
/*projectRefs*/ undefined,
50-
/*lookupConfig*/ true
51+
/*conditionsOrIsConfigLookup*/ tsGte5_3_0 ? undefined : true,
52+
/*isConfigLookup*/ tsGte5_3_0 ? true : undefined
5153
);
5254
if (resolved.resolvedModule) {
5355
return resolved.resolvedModule.resolvedFileName;

tests/2076/node_modules/custom-tsconfig/tsconfig.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/2076/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "custom-tsconfig/tsconfig.json"
3+
}

0 commit comments

Comments
 (0)