Skip to content

Commit

Permalink
chore(react-conformance): hardcode resolving proper tsconfig for conf…
Browse files Browse the repository at this point in the history
…ormance execution
  • Loading branch information
Hotell committed Mar 8, 2023
1 parent 5466766 commit 6d22197
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/react-conformance/src/utils/createTsProgram.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import * as path from 'path';
import * as fs from 'fs';
import * as ts from 'typescript';
import { dirname } from 'path/posix';

let program: ts.Program;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
function temporaryTsconfigV9resolve(tsconfigPath: string | undefined) {
if (!tsconfigPath) {
return;
}

const tsConfigDir = dirname(tsconfigPath);
const solutionLibConfigPath = path.join(tsConfigDir, 'tsconfig.lib.json');
const hasSolutionConfig = fs.existsSync(solutionLibConfigPath);
if (hasSolutionConfig) {
return solutionLibConfigPath;
}

return tsconfigPath;
}

/**
* Creates a ~cached~ TS Program.
* @remarks this will be never cached with current use/setup as jest creates this for every it/describe() block 🐌
Expand All @@ -18,7 +36,10 @@ export function createTsProgram(
// which can take multiple seconds in a large project. For better performance, we create a single
// ts.Program per package and pass it to parseWithProgramProvider().

const tsconfigPath = ts.findConfigFile(configDir ?? sourcePath, fs.existsSync, configName);
// const tsconfigPath = ts.findConfigFile(configDir ?? sourcePath, fs.existsSync, configName);
const tsconfigPath = temporaryTsconfigV9resolve(
ts.findConfigFile(configDir ?? sourcePath, fs.existsSync, configName),
);

if (!tsconfigPath) {
throw new Error(`Cannot find ${configName}`);
Expand Down

0 comments on commit 6d22197

Please sign in to comment.