Skip to content

Commit

Permalink
[dev/build_ts_refs] ignore type checking failures when building ts re…
Browse files Browse the repository at this point in the history
…fs (elastic#93473)

Co-authored-by: spalger <[email protected]>
  • Loading branch information
2 people authored and kibanamachine committed Mar 3, 2021
1 parent 5ef8a6f commit d7db79b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"kbn:watch": "node scripts/kibana --dev --logging.json=false",
"build:types": "rm -rf ./target/types && tsc --p tsconfig.types.json",
"docs:acceptApiChanges": "node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept",
"kbn:bootstrap": "node scripts/build_ts_refs",
"kbn:bootstrap": "node scripts/build_ts_refs --ignore-type-failures",
"spec_to_console": "node scripts/spec_to_console",
"storybook": "node scripts/storybook"
},
Expand Down
30 changes: 28 additions & 2 deletions src/dev/typescript/build_ts_refs_cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import { concurrentMap } from './concurrent_map';

const CACHE_WORKING_DIR = Path.resolve(REPO_ROOT, 'data/ts_refs_output_cache');

const TS_ERROR_REF = /\sTS\d{1,6}:\s/;

const isTypeFailure = (error: any) =>
error.exitCode === 1 &&
error.stderr === '' &&
typeof error.stdout === 'string' &&
TS_ERROR_REF.test(error.stdout);

export async function runBuildRefsCli() {
run(
async ({ log, flags }) => {
Expand Down Expand Up @@ -48,7 +56,20 @@ export async function runBuildRefsCli() {
await outputCache.initCaches();
}

await buildAllTsRefs(log);
try {
await buildAllTsRefs(log);
log.success('ts refs build successfully');
} catch (error) {
const typeFailure = isTypeFailure(error);

if (flags['ignore-type-failures'] && typeFailure) {
log.warning(
'tsc reported type errors but we are ignoring them for now, to see them please run `node scripts/type_check` or `node scripts/build_ts_refs` without the `--ignore-type-failures` flag.'
);
} else {
throw error;
}
}

if (outputCache && doCapture) {
await outputCache.captureCache(Path.resolve(REPO_ROOT, 'target/ts_refs_cache'));
Expand All @@ -61,10 +82,15 @@ export async function runBuildRefsCli() {
{
description: 'Build TypeScript projects',
flags: {
boolean: ['clean', 'cache'],
boolean: ['clean', 'cache', 'ignore-type-failures'],
default: {
cache: true,
},
help: `
--clean Delete outDirs for each ts project before building
--no-cache Disable fetching/extracting outDir caches based on the mergeBase with upstream
--ignore-type-failures If tsc reports type errors, ignore them and just log a small warning.
`,
},
log: {
defaultLevel: 'debug',
Expand Down

0 comments on commit d7db79b

Please sign in to comment.