diff --git a/scripts/tasks/src/type-check.ts b/scripts/tasks/src/type-check.ts index b7763ad01f3b2..3c49c17225bd8 100644 --- a/scripts/tasks/src/type-check.ts +++ b/scripts/tasks/src/type-check.ts @@ -1,45 +1,52 @@ -import * as fs from 'fs'; - import { logger } from 'just-scripts'; // eslint-disable-next-line import/no-extraneous-dependencies import { exec } from 'just-scripts-utils'; -import { getTsPathAliasesConfig } from './utils'; +import { type TsConfig, getTsPathAliasesConfig } from './utils'; -export function typeCheck() { - const { isUsingTsSolutionConfigs, tsConfigFileContents, tsConfigs, tsConfigFilePaths } = getTsPathAliasesConfig(); +export async function typeCheck() { + const { isUsingTsSolutionConfigs, tsConfigs } = getTsPathAliasesConfig(); if (!isUsingTsSolutionConfigs) { logger.info('project is not using TS solution config. skipping...'); return; } - const content = tsConfigFileContents.root; const config = tsConfigs.root; - const configPath = tsConfigFilePaths.root; - if (!(content && config)) { + if (!config) { return; } - // turn off path aliases. - // @ts-expect-error - bad just-scripts ts types - config.compilerOptions.paths = {}; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8'); - - const cmd = 'tsc'; - const args = ['-b', '--pretty', configPath]; - const program = `${cmd} ${args.join(' ')}`; - - return exec(program) - .catch(err => { - console.error(err.stdout); - // restore original tsconfig.json - fs.writeFileSync(configPath, content, 'utf-8'); - process.exit(1); - }) - .finally(() => { - // restore original tsconfig.json - fs.writeFileSync(configPath, content, 'utf-8'); - }); + const tsConfigsRefs = getTsConfigs(config, { spec: false, e2e: false }); + + const asyncQueue = []; + + for (const ref of tsConfigsRefs) { + const program = `tsc -p ${ref} --pretty --baseUrl .`; + asyncQueue.push(exec(program)); + } + + return Promise.all(asyncQueue).catch(err => { + console.error(err.stdout); + process.exit(1); + }); +} + +function getTsConfigs(solutionConfig: TsConfig, exclude: { spec: boolean; e2e: boolean }) { + const refs = solutionConfig.references ?? []; + const refsPaths: string[] = []; + + for (const ref of refs) { + if (exclude.spec && ref.path.includes('spec')) { + continue; + } + if (exclude.e2e && ref.path.includes('cy')) { + continue; + } + + refsPaths.push(ref.path); + } + + return refsPaths; }