From 12fff86d29a603da41d68e5243194eb7624913ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Fri, 24 Feb 2023 10:20:10 +0000 Subject: [PATCH] fix(angular): show actionable error when component resource is not found in ng-packagr executors (#15217) --- .../ng-packagr-adjustments/ts/cache-compiler-host.ts | 8 ++++---- .../ng-packagr-adjustments/ts/cache-compiler-host.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/angular/src/executors/ng-packagr-lite/ng-packagr-adjustments/ts/cache-compiler-host.ts b/packages/angular/src/executors/ng-packagr-lite/ng-packagr-adjustments/ts/cache-compiler-host.ts index abe9a0e4fb1c2..2aed7cfc0dfe4 100644 --- a/packages/angular/src/executors/ng-packagr-lite/ng-packagr-adjustments/ts/cache-compiler-host.ts +++ b/packages/angular/src/executors/ng-packagr-lite/ng-packagr-adjustments/ts/cache-compiler-host.ts @@ -174,6 +174,10 @@ export function cacheCompilerHost( const cache = sourcesFileCache.getOrCreate(fileName); if (cache.content === undefined) { + if (!compilerHost.fileExists(fileName)) { + throw new Error(`Cannot read file ${fileName}.`); + } + if (/(?:html?|svg)$/.test(path.extname(fileName))) { // template cache.content = compilerHost.readFile.call(this, fileName); @@ -185,10 +189,6 @@ export function cacheCompilerHost( }); } - if (cache.content === undefined) { - throw new Error(`Cannot read file ${fileName}.`); - } - cache.exists = true; } diff --git a/packages/angular/src/executors/package/ng-packagr-adjustments/ts/cache-compiler-host.ts b/packages/angular/src/executors/package/ng-packagr-adjustments/ts/cache-compiler-host.ts index d8215e3f69519..ebd7e61747388 100644 --- a/packages/angular/src/executors/package/ng-packagr-adjustments/ts/cache-compiler-host.ts +++ b/packages/angular/src/executors/package/ng-packagr-adjustments/ts/cache-compiler-host.ts @@ -198,6 +198,10 @@ export function cacheCompilerHost( const cache = sourcesFileCache.getOrCreate(fileName); if (cache.content === undefined) { + if (!compilerHost.fileExists(fileName)) { + throw new Error(`Cannot read file ${fileName}.`); + } + if (/(?:html?|svg)$/.test(path.extname(fileName))) { // template cache.content = compilerHost.readFile.call(this, fileName); @@ -209,10 +213,6 @@ export function cacheCompilerHost( }); } - if (cache.content === undefined) { - throw new Error(`Cannot read file ${fileName}.`); - } - cache.exists = true; }