Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tsconfig not found with TS >= 5.3 #2091

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/test/regression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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 @@ -90,7 +90,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 @@ -40,14 +40,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"
}
Loading