Skip to content

Commit fa4d8ff

Browse files
alan-agius4clydin
authored andcommitted
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 (cherry picked from commit 155341f)
1 parent 8837719 commit fa4d8ff

File tree

1 file changed

+10
-4
lines changed
  • packages/angular_devkit/build_angular/src/builders/application

1 file changed

+10
-4
lines changed

packages/angular_devkit/build_angular/src/builders/application/options.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import { BuilderContext } from '@angular-devkit/architect';
1010
import type { Plugin } from 'esbuild';
11+
import { access, constants } from 'node:fs/promises';
1112
import { createRequire } from 'node:module';
1213
import path from 'node:path';
1314
import {
@@ -129,11 +130,16 @@ export async function normalizeOptions(
129130
let fileReplacements: Record<string, string> | undefined;
130131
if (options.fileReplacements) {
131132
for (const replacement of options.fileReplacements) {
133+
const fileReplaceWith = path.join(workspaceRoot, replacement.with);
134+
135+
try {
136+
await access(fileReplaceWith, constants.F_OK);
137+
} catch {
138+
throw new Error(`The ${fileReplaceWith} path in file replacements does not exist.`);
139+
}
140+
132141
fileReplacements ??= {};
133-
fileReplacements[path.join(workspaceRoot, replacement.replace)] = path.join(
134-
workspaceRoot,
135-
replacement.with,
136-
);
142+
fileReplacements[path.join(workspaceRoot, replacement.replace)] = fileReplaceWith;
137143
}
138144
}
139145

0 commit comments

Comments
 (0)