Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): move @angular/localize detectio…
Browse files Browse the repository at this point in the history
…n 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.

(cherry picked from commit 7049482)
  • Loading branch information
alan-agius4 committed Oct 28, 2021
1 parent 8795536 commit e192874
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Expand Up @@ -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);

Expand Down Expand Up @@ -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')>(
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts
Expand Up @@ -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');
}

Expand Down

0 comments on commit e192874

Please sign in to comment.