From db803d8e83db876b8b47536189e9dc0853fd03b7 Mon Sep 17 00:00:00 2001 From: Agustin Mendez Date: Thu, 20 May 2021 17:40:27 -0300 Subject: [PATCH] feat: fail compilation if there are errors --- kernel/packages/build-ecs/index.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/kernel/packages/build-ecs/index.ts b/kernel/packages/build-ecs/index.ts index 844b81a353..2eb17b2c32 100644 --- a/kernel/packages/build-ecs/index.ts +++ b/kernel/packages/build-ecs/index.ts @@ -124,7 +124,11 @@ async function compile() { } // First time around, emit all files - await emitFile(cfg.fileNames[0], services, cfg) + const diagnostics = await emitFile(cfg.fileNames[0], services, cfg) + + if (!WATCH && diagnostics.length) { + throw new Error(`! Error: compilation finished with ${diagnostics.length} errors`) + } } function watchFile(fileName: string, services: ts.LanguageService, files: FileMap, cfg: ProjectConfig) { @@ -184,7 +188,7 @@ async function emitFile(fileName: string, services: ts.LanguageService, cfg: Pro console.log(`> processing ${fileName.replace(ts.sys.getCurrentDirectory(), '')} failed`) } - logErrors(services) + const diagnostics = logErrors(services) type OutFile = { readonly path: string @@ -335,6 +339,8 @@ async function emitFile(fileName: string, services: ts.LanguageService, cfg: Pro if (WATCH) { console.log('\nThe compiler is watching file changes...\n') } + + return diagnostics } function logErrors(services: ts.LanguageService) { @@ -345,6 +351,8 @@ function logErrors(services: ts.LanguageService) { .concat(services.getProgram()!.getSyntacticDiagnostics()) allDiagnostics.forEach(printDiagnostic) + + return allDiagnostics } function getConfiguration(packageJson: PackageJson | null, sceneJson: SceneJson | null): ProjectConfig { @@ -471,7 +479,7 @@ function getConfiguration(packageJson: PackageJson | null, sceneJson: SceneJson if (resolved) { try { const libPackageJson = JSON.parse(ts.sys.readFile(resolved)!) - const decentralandLibrary = libPackageJson.decentralandLibrary; + const decentralandLibrary = libPackageJson.decentralandLibrary let main: string | null = null let typings: string | null = null