Skip to content

Commit

Permalink
Fix tsconfig.json not found with TS >= 5.3 (#2091)
Browse files Browse the repository at this point in the history
  • Loading branch information
edosrecki authored and blakeembrey committed Dec 8, 2023
1 parent 0e0da59 commit cc1a503
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/test/regression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ const exec = createExecTester({
}),
});

test('#2076 regression test', async () => {
const r = await exec({
exec: createExec({
cwd: join(TEST_DIR, '2076'),
}),
cmd: `${CMD_TS_NODE_WITHOUT_PROJECT_FLAG} --showConfig`,
});

exp(r.err).toBeNull();
});

test('#1488 regression test', async () => {
// Scenario that caused the bug:
// `allowJs` turned on
Expand Down
3 changes: 2 additions & 1 deletion src/ts-compiler-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ export interface TSInternal {
host: _ts.ModuleResolutionHost,
cache?: _ts.ModuleResolutionCache,
redirectedReference?: _ts.ResolvedProjectReference,
lookupConfig?: boolean
conditionsOrIsConfigLookup?: string[] | boolean, // `conditions` parameter added in TS 5.3
isConfigLookup?: boolean
): _ts.ResolvedModuleWithFailedLookupLocations;
// Added in TS 4.7
getModeForFileReference?: (
Expand Down
6 changes: 4 additions & 2 deletions src/ts-internals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isAbsolute, resolve } from 'path';
import { cachedLookup, normalizeSlashes } from './util';
import { cachedLookup, normalizeSlashes, versionGteLt } from './util';
import type * as _ts from 'typescript';
import type { TSCommon, TSInternal } from './ts-compiler-types';

Expand Down Expand Up @@ -55,14 +55,16 @@ function createTsInternalsUncached(_ts: TSCommon) {
return extendedConfigPath;
}
// If the path isn't a rooted or relative path, resolve like a module
const tsGte5_3_0 = versionGteLt(ts.version, '5.3.0');
const resolved = ts.nodeModuleNameResolver(
extendedConfig,
combinePaths(basePath, 'tsconfig.json'),
{ moduleResolution: ts.ModuleResolutionKind.NodeJs },
host,
/*cache*/ undefined,
/*projectRefs*/ undefined,
/*lookupConfig*/ true
/*conditionsOrIsConfigLookup*/ tsGte5_3_0 ? undefined : true,
/*isConfigLookup*/ tsGte5_3_0 ? true : undefined
);
if (resolved.resolvedModule) {
return resolved.resolvedModule.resolvedFileName;
Expand Down
3 changes: 3 additions & 0 deletions tests/2076/node_modules/custom-tsconfig/tsconfig.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/2076/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "custom-tsconfig/tsconfig.json"
}

0 comments on commit cc1a503

Please sign in to comment.