fix(@angular-devkit/build-angular): move @angular/localize detection prior to webpack initialization

Fail faster if `@angular/localize` is not installed and update the error message since now there is a single extraction mode.
This commit is contained in:
Alan Agius 2021-10-27 12:05:30 +02:00
parent 9b32066e88
commit 70494824df
2 changed files with 11 additions and 11 deletions

View File

@ -156,6 +156,16 @@ export async function execute(
throw new Error('The builder requires a target.');
}
try {
require.resolve('@angular/localize');
} catch {
return {
success: false,
error: `i18n extraction requires the '@angular/localize' package.`,
outputPath: outFile,
};
}
const metadata = await context.getProjectMetadata(context.target);
const i18n = createI18nOptions(metadata);
@ -230,16 +240,6 @@ export async function execute(
},
);
try {
require.resolve('@angular/localize');
} catch {
return {
success: false,
error: `Ivy extraction requires the '@angular/localize' package.`,
outputPath: outFile,
};
}
// All the localize usages are setup to first try the ESM entry point then fallback to the deep imports.
// This provides interim compatibility while the framework is transitioned to bundled ESM packages.
const localizeToolsModule = await loadEsmModule<typeof import('@angular/localize/tools')>(

View File

@ -14,7 +14,7 @@ export default async function () {
// Should fail if `@angular/localize` is missing
const { message: message1 } = await expectToFail(() => ng('extract-i18n'));
if (!message1.includes(`Ivy extraction requires the '@angular/localize' package.`)) {
if (!message1.includes(`i18n extraction requires the '@angular/localize' package.`)) {
throw new Error('Expected localize package error message when missing');
}