diff --git a/package.json b/package.json index 6e5feac8a16a9..9996b216b1a6a 100644 --- a/package.json +++ b/package.json @@ -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", "backport-skip-ci": "backport --prDescription \"[skip-ci]\"", "storybook": "node scripts/storybook", diff --git a/src/dev/typescript/build_ts_refs_cli.ts b/src/dev/typescript/build_ts_refs_cli.ts index a073e58623278..63eb1a3da21ec 100644 --- a/src/dev/typescript/build_ts_refs_cli.ts +++ b/src/dev/typescript/build_ts_refs_cli.ts @@ -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 }) => { @@ -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')); @@ -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',