Skip to content

Commit e192874

Browse files
committed
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. (cherry picked from commit 7049482)
1 parent 8795536 commit e192874

File tree

2 files changed

+11
-11
lines changed
  • packages/angular_devkit/build_angular/src/builders/extract-i18n
  • tests/legacy-cli/e2e/tests/i18n

2 files changed

+11
-11
lines changed

packages/angular_devkit/build_angular/src/builders/extract-i18n/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ export async function execute(
156156
throw new Error('The builder requires a target.');
157157
}
158158

159+
try {
160+
require.resolve('@angular/localize');
161+
} catch {
162+
return {
163+
success: false,
164+
error: `i18n extraction requires the '@angular/localize' package.`,
165+
outputPath: outFile,
166+
};
167+
}
168+
159169
const metadata = await context.getProjectMetadata(context.target);
160170
const i18n = createI18nOptions(metadata);
161171

@@ -230,16 +240,6 @@ export async function execute(
230240
},
231241
);
232242

233-
try {
234-
require.resolve('@angular/localize');
235-
} catch {
236-
return {
237-
success: false,
238-
error: `Ivy extraction requires the '@angular/localize' package.`,
239-
outputPath: outFile,
240-
};
241-
}
242-
243243
// All the localize usages are setup to first try the ESM entry point then fallback to the deep imports.
244244
// This provides interim compatibility while the framework is transitioned to bundled ESM packages.
245245
const localizeToolsModule = await loadEsmModule<typeof import('@angular/localize/tools')>(

tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default async function () {
1414

1515
// Should fail if `@angular/localize` is missing
1616
const { message: message1 } = await expectToFail(() => ng('extract-i18n'));
17-
if (!message1.includes(`Ivy extraction requires the '@angular/localize' package.`)) {
17+
if (!message1.includes(`i18n extraction requires the '@angular/localize' package.`)) {
1818
throw new Error('Expected localize package error message when missing');
1919
}
2020

0 commit comments

Comments
 (0)