Skip to content

Commit 97ba359

Browse files
committed
refactor(@angular-devkit/build-angular): remove unneeded 10.1 localize checks
Now that 11.0 is the minimum supported version, the 10.1 support checks for the `@angular/localize` package can be removed.
1 parent 81d7cd5 commit 97ba359

File tree

3 files changed

+4
-49
lines changed

3 files changed

+4
-49
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { JsonObject } from '@angular-devkit/core';
1515
import type { ɵParsedMessage as LocalizeMessage } from '@angular/localize';
1616
import * as fs from 'fs';
1717
import * as path from 'path';
18-
import { gte as semverGte } from 'semver';
1918
import * as webpack from 'webpack';
2019
import { Schema as BrowserBuilderOptions } from '../browser/schema';
2120
import { ExecutionTransformer } from '../transforms';
@@ -212,16 +211,12 @@ export async function execute(
212211
);
213212

214213
if (usingIvy) {
215-
let validLocalizePackage = false;
216214
try {
217-
const { version: localizeVersion } = require('@angular/localize/package.json');
218-
validLocalizePackage = semverGte(localizeVersion, '10.1.0-next.0', { includePrerelease: true });
219-
} catch {}
220-
221-
if (!validLocalizePackage) {
215+
require.resolve('@angular/localize');
216+
} catch {
222217
return {
223218
success: false,
224-
error: `Ivy extraction requires the '@angular/localize' package version 10.1.0 or higher.`,
219+
error: `Ivy extraction requires the '@angular/localize' package.`,
225220
};
226221
}
227222
}

packages/angular_devkit/build_angular/src/utils/process-bundle.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import templateBuilder from '@babel/template';
1919
import { createHash } from 'crypto';
2020
import * as fs from 'fs';
2121
import * as path from 'path';
22-
import { lt as semverLt } from 'semver';
2322
import { RawSourceMap, SourceMapConsumer, SourceMapGenerator } from 'source-map';
2423
import { minify } from 'terser';
2524
import * as v8 from 'v8';
@@ -884,26 +883,10 @@ function findLocalizePositions(
884883
return positions;
885884
}
886885

887-
// TODO: Remove this for v11.
888-
// This check allows the CLI to support both FW 10.0 and 10.1
889-
let localizeOld: boolean | undefined;
890-
891886
function unwrapTemplateLiteral(
892887
path: NodePath<types.TaggedTemplateExpression>,
893888
utils: LocalizeUtilities,
894889
): [TemplateStringsArray, types.Expression[]] {
895-
if (localizeOld === undefined) {
896-
const { version: localizeVersion } = require('@angular/localize/package.json');
897-
localizeOld = semverLt(localizeVersion, '10.1.0-rc.0', { includePrerelease: true });
898-
}
899-
900-
if (localizeOld) {
901-
// tslint:disable-next-line: no-any
902-
const messageParts = utils.unwrapMessagePartsFromTemplateLiteral(path.node.quasi.quasis as any);
903-
904-
return [(messageParts as unknown) as TemplateStringsArray, path.node.quasi.expressions];
905-
}
906-
907890
const [messageParts] = utils.unwrapMessagePartsFromTemplateLiteral(
908891
path.get('quasi').get('quasis'),
909892
);
@@ -916,22 +899,6 @@ function unwrapLocalizeCall(
916899
path: NodePath<types.CallExpression>,
917900
utils: LocalizeUtilities,
918901
): [TemplateStringsArray, types.Expression[]] {
919-
if (localizeOld === undefined) {
920-
const { version: localizeVersion } = require('@angular/localize/package.json');
921-
localizeOld = semverLt(localizeVersion, '10.1.0-rc.0', { includePrerelease: true });
922-
}
923-
924-
if (localizeOld) {
925-
const messageParts = utils.unwrapMessagePartsFromLocalizeCall(path);
926-
// tslint:disable-next-line: no-any
927-
const expressions = utils.unwrapSubstitutionsFromLocalizeCall(path.node as any);
928-
929-
return [
930-
(messageParts as unknown) as TemplateStringsArray,
931-
(expressions as unknown) as types.Expression[],
932-
];
933-
}
934-
935902
const [messageParts] = utils.unwrapMessagePartsFromLocalizeCall(path);
936903
const [expressions] = utils.unwrapSubstitutionsFromLocalizeCall(path);
937904

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,10 @@ export default async function() {
2121

2222
// Should fail with --ivy flag if `@angular/localize` is missing
2323
const { message: message1 } = await expectToFail(() => ng('xi18n'));
24-
if (!message1.includes(`Ivy extraction requires the '@angular/localize' package version 10.1.0 or higher.`)) {
24+
if (!message1.includes(`Ivy extraction requires the '@angular/localize' package.`)) {
2525
throw new Error('Expected localize package error message when missing');
2626
}
2727

28-
// Should fail with --ivy flag if `@angular/localize` is wrong version
29-
await npm('install', '@angular/localize@9');
30-
const { message: message2 } = await expectToFail(() => ng('xi18n', '--ivy'));
31-
if (!message2.includes(`Ivy extraction requires the '@angular/localize' package version 10.1.0 or higher.`)) {
32-
throw new Error('Expected localize package error message when wrong version');
33-
}
34-
3528
// Install correct version
3629
let localizeVersion = '@angular/localize@' + readNgVersion();
3730
if (getGlobalVariable('argv')['ng-snapshots']) {

0 commit comments

Comments
 (0)