Skip to content

Commit cc1a503

Browse files
edosreckiblakeembrey
authored andcommitted
Fix tsconfig.json not found with TS >= 5.3 (#2091)
1 parent 0e0da59 commit cc1a503

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

Diff for: src/test/regression.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ const exec = createExecTester({
1717
}),
1818
});
1919

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

Diff for: src/ts-compiler-types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ export interface TSInternal {
9999
host: _ts.ModuleResolutionHost,
100100
cache?: _ts.ModuleResolutionCache,
101101
redirectedReference?: _ts.ResolvedProjectReference,
102-
lookupConfig?: boolean
102+
conditionsOrIsConfigLookup?: string[] | boolean, // `conditions` parameter added in TS 5.3
103+
isConfigLookup?: boolean
103104
): _ts.ResolvedModuleWithFailedLookupLocations;
104105
// Added in TS 4.7
105106
getModeForFileReference?: (

Diff for: src/ts-internals.ts

+4-2
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

@@ -55,14 +55,16 @@ function createTsInternalsUncached(_ts: TSCommon) {
5555
return extendedConfigPath;
5656
}
5757
// If the path isn't a rooted or relative path, resolve like a module
58+
const tsGte5_3_0 = versionGteLt(ts.version, '5.3.0');
5859
const resolved = ts.nodeModuleNameResolver(
5960
extendedConfig,
6061
combinePaths(basePath, 'tsconfig.json'),
6162
{ moduleResolution: ts.ModuleResolutionKind.NodeJs },
6263
host,
6364
/*cache*/ undefined,
6465
/*projectRefs*/ undefined,
65-
/*lookupConfig*/ true
66+
/*conditionsOrIsConfigLookup*/ tsGte5_3_0 ? undefined : true,
67+
/*isConfigLookup*/ tsGte5_3_0 ? true : undefined
6668
);
6769
if (resolved.resolvedModule) {
6870
return resolved.resolvedModule.resolvedFileName;

Diff for: tests/2076/node_modules/custom-tsconfig/tsconfig.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/2076/tsconfig.json

+3
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)