forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scripts-tasks): implement ~36% faster type-check task (microsoft…
- Loading branch information
1 parent
55f4605
commit 6559a24
Showing
1 changed file
with
35 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |