From 0c874bde1d2c923b2bbaa2243c81fdc3ff211324 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 15 Nov 2023 15:06:37 +0000 Subject: [PATCH] fix(@angular-devkit/build-angular): add actionable error when file replacement is missing This commits adds an actionable error when the file to replace with is missing. Closes #26333 --- .../src/builders/application/options.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/builders/application/options.ts b/packages/angular_devkit/build_angular/src/builders/application/options.ts index 88ee9d8e9db2..d0dd336a9f79 100644 --- a/packages/angular_devkit/build_angular/src/builders/application/options.ts +++ b/packages/angular_devkit/build_angular/src/builders/application/options.ts @@ -8,6 +8,7 @@ import { BuilderContext } from '@angular-devkit/architect'; import type { Plugin } from 'esbuild'; +import { access, constants } from 'node:fs/promises'; import { createRequire } from 'node:module'; import path from 'node:path'; import { @@ -129,11 +130,16 @@ export async function normalizeOptions( let fileReplacements: Record | undefined; if (options.fileReplacements) { for (const replacement of options.fileReplacements) { + const fileReplaceWith = path.join(workspaceRoot, replacement.with); + + try { + await access(fileReplaceWith, constants.F_OK); + } catch { + throw new Error(`The ${fileReplaceWith} path in file replacements does not exist.`); + } + fileReplacements ??= {}; - fileReplacements[path.join(workspaceRoot, replacement.replace)] = path.join( - workspaceRoot, - replacement.with, - ); + fileReplacements[path.join(workspaceRoot, replacement.replace)] = fileReplaceWith; } }