Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(@angular-devkit/build-angular): remove unneeded 10.1 localize checks #18996

Merged
merged 1 commit into from Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 3 additions & 8 deletions packages/angular_devkit/build_angular/src/extract-i18n/index.ts
Expand Up @@ -15,7 +15,6 @@ import { JsonObject } from '@angular-devkit/core';
import type { ɵParsedMessage as LocalizeMessage } from '@angular/localize';
import * as fs from 'fs';
import * as path from 'path';
import { gte as semverGte } from 'semver';
import * as webpack from 'webpack';
import { Schema as BrowserBuilderOptions } from '../browser/schema';
import { ExecutionTransformer } from '../transforms';
Expand Down Expand Up @@ -212,16 +211,12 @@ export async function execute(
);

if (usingIvy) {
let validLocalizePackage = false;
try {
const { version: localizeVersion } = require('@angular/localize/package.json');
validLocalizePackage = semverGte(localizeVersion, '10.1.0-next.0', { includePrerelease: true });
} catch {}

if (!validLocalizePackage) {
require.resolve('@angular/localize');
} catch {
return {
success: false,
error: `Ivy extraction requires the '@angular/localize' package version 10.1.0 or higher.`,
error: `Ivy extraction requires the '@angular/localize' package.`,
};
}
}
Expand Down
33 changes: 0 additions & 33 deletions packages/angular_devkit/build_angular/src/utils/process-bundle.ts
Expand Up @@ -19,7 +19,6 @@ import templateBuilder from '@babel/template';
import { createHash } from 'crypto';
import * as fs from 'fs';
import * as path from 'path';
import { lt as semverLt } from 'semver';
import { RawSourceMap, SourceMapConsumer, SourceMapGenerator } from 'source-map';
import { minify } from 'terser';
import * as v8 from 'v8';
Expand Down Expand Up @@ -884,26 +883,10 @@ function findLocalizePositions(
return positions;
}

// TODO: Remove this for v11.
// This check allows the CLI to support both FW 10.0 and 10.1
let localizeOld: boolean | undefined;

function unwrapTemplateLiteral(
path: NodePath<types.TaggedTemplateExpression>,
utils: LocalizeUtilities,
): [TemplateStringsArray, types.Expression[]] {
if (localizeOld === undefined) {
const { version: localizeVersion } = require('@angular/localize/package.json');
localizeOld = semverLt(localizeVersion, '10.1.0-rc.0', { includePrerelease: true });
}

if (localizeOld) {
// tslint:disable-next-line: no-any
const messageParts = utils.unwrapMessagePartsFromTemplateLiteral(path.node.quasi.quasis as any);

return [(messageParts as unknown) as TemplateStringsArray, path.node.quasi.expressions];
}

const [messageParts] = utils.unwrapMessagePartsFromTemplateLiteral(
path.get('quasi').get('quasis'),
);
Expand All @@ -916,22 +899,6 @@ function unwrapLocalizeCall(
path: NodePath<types.CallExpression>,
utils: LocalizeUtilities,
): [TemplateStringsArray, types.Expression[]] {
if (localizeOld === undefined) {
const { version: localizeVersion } = require('@angular/localize/package.json');
localizeOld = semverLt(localizeVersion, '10.1.0-rc.0', { includePrerelease: true });
}

if (localizeOld) {
const messageParts = utils.unwrapMessagePartsFromLocalizeCall(path);
// tslint:disable-next-line: no-any
const expressions = utils.unwrapSubstitutionsFromLocalizeCall(path.node as any);

return [
(messageParts as unknown) as TemplateStringsArray,
(expressions as unknown) as types.Expression[],
];
}

const [messageParts] = utils.unwrapMessagePartsFromLocalizeCall(path);
const [expressions] = utils.unwrapSubstitutionsFromLocalizeCall(path);

Expand Down
9 changes: 1 addition & 8 deletions tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts
Expand Up @@ -21,17 +21,10 @@ export default async function() {

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

// Should fail with --ivy flag if `@angular/localize` is wrong version
await npm('install', '@angular/localize@9');
const { message: message2 } = await expectToFail(() => ng('xi18n', '--ivy'));
if (!message2.includes(`Ivy extraction requires the '@angular/localize' package version 10.1.0 or higher.`)) {
throw new Error('Expected localize package error message when wrong version');
}

// Install correct version
let localizeVersion = '@angular/localize@' + readNgVersion();
if (getGlobalVariable('argv')['ng-snapshots']) {
Expand Down