Skip to content

fix(@angular-devkit/build-angular): add actionable error when file replacement is missing #26367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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