Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): add actionable error when file re…
Browse files Browse the repository at this point in the history
…placement is missing

This commits adds an actionable error when the file to replace with is missing.

Closes #26333

(cherry picked from commit 155341f)
  • Loading branch information
alan-agius4 authored and clydin committed Nov 15, 2023
1 parent 8837719 commit fa4d8ff
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -129,11 +130,16 @@ export async function normalizeOptions(
let fileReplacements: Record<string, string> | 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;
}
}

Expand Down

0 comments on commit fa4d8ff

Please sign in to comment.