Skip to content

Commit 012700a

Browse files
clydinfilipesilva
authored andcommitted
fix(@angular-devkit/build-angular): remove deprecated View Engine support for i18n extraction
BREAKING CHANGE: Removal of View Engine support from i18n extraction With the removal of the deprecated View Engine compiler in Angular version 12 for applications, the `ng extract-i18n` command will now always use the Ivy compiler. The `--ivy` option has also been removed as Ivy-based extraction is always enabled. The default behavior for applications is to use the Ivy compiler for building/extraction and no changes are required for these applications. For applications that have opted-out of Ivy, a warning will be shown and Ivy-based extraction will be attempted. If the extraction fails, the application may need to be updated to become Ivy compatible.
1 parent 3388418 commit 012700a

File tree

11 files changed

+33
-283
lines changed

11 files changed

+33
-283
lines changed

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

+28-46
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ export async function execute(
170170
const metadata = await context.getProjectMetadata(context.target);
171171
const i18n = createI18nOptions(metadata);
172172

173-
let usingIvy = false;
174173
let useLegacyIds = true;
175174

176175
const ivyMessages: LocalizeMessage[] = [];
@@ -198,52 +197,37 @@ export async function execute(
198197
},
199198
context,
200199
(wco) => {
201-
const isIvyApplication = wco.tsConfig.options.enableIvy !== false;
202-
203-
// Default value for legacy message ids is currently true
204-
useLegacyIds = wco.tsConfig.options.enableI18nLegacyMessageIdFormat ?? true;
205-
206-
// Ivy extraction is the default for Ivy applications.
207-
usingIvy = (isIvyApplication && options.ivy === undefined) || !!options.ivy;
208-
209-
if (usingIvy) {
210-
if (!isIvyApplication) {
211-
context.logger.warn(
212-
'Ivy extraction enabled but application is not Ivy enabled. Extraction may fail.',
213-
);
214-
}
215-
} else if (isIvyApplication) {
200+
if (wco.tsConfig.options.enableIvy === false) {
216201
context.logger.warn(
217-
'Ivy extraction not enabled but application is Ivy enabled. ' +
218-
'If the extraction fails, the `--ivy` flag will enable Ivy extraction.',
202+
'Ivy extraction enabled but application is not Ivy enabled. Extraction may fail.',
219203
);
220204
}
221205

206+
// Default value for legacy message ids is currently true
207+
useLegacyIds = wco.tsConfig.options.enableI18nLegacyMessageIdFormat ?? true;
208+
222209
const partials = [
223210
{ plugins: [new NoEmitPlugin()] },
224211
getCommonConfig(wco),
225212
getBrowserConfig(wco),
226-
// Only use VE extraction if not using Ivy
227-
getAotConfig(wco, !usingIvy),
213+
getAotConfig(wco),
228214
getStatsConfig(wco),
229215
];
230216

231217
// Add Ivy application file extractor support
232-
if (usingIvy) {
233-
partials.unshift({
234-
module: {
235-
rules: [
236-
{
237-
test: /\.[t|j]s$/,
238-
loader: require.resolve('./ivy-extract-loader'),
239-
options: {
240-
messageHandler: (messages: LocalizeMessage[]) => ivyMessages.push(...messages),
241-
},
218+
partials.unshift({
219+
module: {
220+
rules: [
221+
{
222+
test: /\.[t|j]s$/,
223+
loader: require.resolve('./ivy-extract-loader'),
224+
options: {
225+
messageHandler: (messages: LocalizeMessage[]) => ivyMessages.push(...messages),
242226
},
243-
],
244-
},
245-
});
246-
}
227+
},
228+
],
229+
},
230+
});
247231

248232
// Replace all stylesheets with an empty default export
249233
partials.push({
@@ -259,16 +243,14 @@ export async function execute(
259243
},
260244
);
261245

262-
if (usingIvy) {
263-
try {
264-
require.resolve('@angular/localize');
265-
} catch {
266-
return {
267-
success: false,
268-
error: `Ivy extraction requires the '@angular/localize' package.`,
269-
outputPath: outFile,
270-
};
271-
}
246+
try {
247+
require.resolve('@angular/localize');
248+
} catch {
249+
return {
250+
success: false,
251+
error: `Ivy extraction requires the '@angular/localize' package.`,
252+
outputPath: outFile,
253+
};
272254
}
273255

274256
const webpackResult = await runWebpack(
@@ -283,8 +265,8 @@ export async function execute(
283265
// Set the outputPath to the extraction output location for downstream consumers
284266
webpackResult.outputPath = outFile;
285267

286-
// Complete if using VE or if Webpack build failed
287-
if (!usingIvy || !webpackResult.success) {
268+
// Complete if Webpack build failed
269+
if (!webpackResult.success) {
288270
return webpackResult;
289271
}
290272

packages/angular_devkit/build_angular/src/extract-i18n/schema.json

-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@
4747
"description": "Specifies the source language of the application.",
4848
"x-deprecated": "Use 'i18n' project level sub-option 'sourceLocale' instead."
4949
},
50-
"ivy": {
51-
"type": "boolean",
52-
"description": "Use Ivy compiler to extract translations. The default for Ivy applications."
53-
},
5450
"progress": {
5551
"type": "boolean",
5652
"description": "Log progress to the console.",

tests/legacy-cli/e2e/tests/i18n/build-locale.ts

-24
This file was deleted.

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

-21
This file was deleted.

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

-28
This file was deleted.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default async function() {
6161
await installPackage(localizeVersion);
6262

6363
// Extract messages
64-
await ng('extract-i18n', '--ivy');
64+
await ng('extract-i18n');
6565
await expectFileToMatch('messages.xlf', 'Hello world');
6666
await expectFileToMatch('messages.xlf', 'i18n-lib-test works!');
6767
await expectFileToMatch('messages.xlf', 'src/app/app.component.html');

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

+4-15
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,14 @@ import { expectToFail } from '../../utils/utils';
88
import { readNgVersion } from '../../utils/version';
99

1010
export default async function() {
11-
// Ivy only test
12-
if (getGlobalVariable('argv')['ve']) {
13-
return;
14-
}
15-
1611
// Setup an i18n enabled component
1712
await ng('generate', 'component', 'i18n-test');
1813
await writeFile(
1914
join('src/app/i18n-test', 'i18n-test.component.html'),
2015
'<p i18n>Hello world</p>',
2116
);
2217

23-
// Should fail with --ivy flag if `@angular/localize` is missing
18+
// Should fail if `@angular/localize` is missing
2419
const { message: message1 } = await expectToFail(() => ng('extract-i18n'));
2520
if (!message1.includes(`Ivy extraction requires the '@angular/localize' package.`)) {
2621
throw new Error('Expected localize package error message when missing');
@@ -33,14 +28,8 @@ export default async function() {
3328
}
3429
await installPackage(localizeVersion);
3530

36-
// Should show ivy enabled application warning without --ivy flag
37-
const { stderr: message3 } = await ng('extract-i18n', '--no-ivy');
38-
if (!message3.includes(`Ivy extraction not enabled but application is Ivy enabled.`)) {
39-
throw new Error('Expected ivy enabled application warning');
40-
}
41-
4231
// Should not show any warnings when extracting
43-
const { stderr: message5 } = await ng('extract-i18n', '--ivy');
32+
const { stderr: message5 } = await ng('extract-i18n');
4433
if (message5.includes('WARNING')) {
4534
throw new Error('Expected no warnings to be shown');
4635
}
@@ -52,8 +41,8 @@ export default async function() {
5241
config.angularCompilerOptions = angularCompilerOptions;
5342
});
5443

55-
// Should show ivy disabled application warning with --ivy flag and enableIvy false
56-
const { message: message4 } = await expectToFail(() => ng('extract-i18n', '--ivy'));
44+
// Should show ivy disabled application warning with enableIvy false
45+
const { message: message4 } = await expectToFail(() => ng('extract-i18n'));
5746
if (!message4.includes(`Ivy extraction enabled but application is not Ivy enabled.`)) {
5847
throw new Error('Expected ivy disabled application warning');
5948
}

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

-23
This file was deleted.

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

-19
This file was deleted.

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

-23
This file was deleted.

0 commit comments

Comments
 (0)