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 deprecated i18n options from server and browser builder #20412

Merged
merged 2 commits into from Apr 3, 2021
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
2 changes: 1 addition & 1 deletion packages/angular_devkit/build_angular/src/browser/index.ts
Expand Up @@ -668,7 +668,7 @@ export function buildWebpackBrowser(
const { content, warnings, errors } = await indexHtmlGenerator.process({
baseHref: getLocaleBaseHref(i18n, locale) || options.baseHref,
// i18nLocale is used when Ivy is disabled
lang: locale || options.i18nLocale,
lang: locale || undefined,
clydin marked this conversation as resolved.
Show resolved Hide resolved
outputPath,
files: mapEmittedFilesToFileInfo(files),
noModuleFiles: mapEmittedFilesToFileInfo(noModuleFiles),
Expand Down
15 changes: 0 additions & 15 deletions packages/angular_devkit/build_angular/src/browser/schema.json
Expand Up @@ -208,21 +208,6 @@
"description": "Log progress to the console while building.",
"default": true
},
"i18nFile": {
"type": "string",
"description": "Localization file to use for i18n.",
"x-deprecated": "Use 'locales' object in the project metadata instead."
},
"i18nFormat": {
"type": "string",
"description": "Format of the localization file specified with --i18n-file.",
"x-deprecated": "No longer needed as the format will be determined automatically."
},
"i18nLocale": {
"type": "string",
"description": "Locale to use for i18n.",
"x-deprecated": "Use 'localize' instead."
},
"i18nMissingTranslation": {
"type": "string",
"description": "How to handle missing translations for i18n.",
Expand Down
Expand Up @@ -218,10 +218,7 @@ export function serveWebpackBrowser(
}

let locale: string | undefined;
if (browserOptions.i18nLocale) {
// Deprecated VE option
locale = browserOptions.i18nLocale;
} else if (i18n.shouldInline) {
if (i18n.shouldInline) {
// Dev-server only supports one locale
locale = [...i18n.inlineLocales][0];
} else if (i18n.hasDefinedSourceLocale) {
Expand Down
Expand Up @@ -167,9 +167,6 @@ export async function execute(
vendor: true,
},
buildOptimizer: false,
i18nLocale: i18n.sourceLocale,
i18nFormat: format,
i18nFile: outFile,
aot: true,
progress: options.progress,
assets: [],
Expand Down
15 changes: 0 additions & 15 deletions packages/angular_devkit/build_angular/src/server/schema.json
Expand Up @@ -120,21 +120,6 @@
"description": "Log progress to the console while building.",
"default": true
},
"i18nFile": {
"type": "string",
"description": "Localization file to use for i18n.",
"x-deprecated": "Use 'locales' object in the project metadata instead."
},
"i18nFormat": {
"type": "string",
"description": "Format of the localization file specified with --i18n-file.",
"x-deprecated": "No longer needed as the format will be determined automatically."
},
"i18nLocale": {
"type": "string",
"description": "Locale to use for i18n.",
"x-deprecated": "Use 'localize' instead."
},
"i18nMissingTranslation": {
"type": "string",
"description": "How to handle missing translations for i18n.",
Expand Down
Expand Up @@ -35,12 +35,6 @@ export interface BuildOptions {
deployUrl?: string;
verbose?: boolean;
progress?: boolean;
/** @deprecated since version 9. Use 'locales' object in the project metadata instead.*/
i18nFile?: string;
/** @deprecated since version 9. No longer needed as the format will be determined automatically.*/
i18nFormat?: string;
/** @deprecated since version 9. Use 'localize' instead.*/
i18nLocale?: string;
localize?: Localize;
i18nMissingTranslation?: I18NMissingTranslation;
/** @deprecated since version 11.0. No longer required to disable CSS extraction for HMR.*/
Expand Down
95 changes: 0 additions & 95 deletions packages/angular_devkit/build_angular/src/utils/i18n-options.ts
Expand Up @@ -30,7 +30,6 @@ export interface I18nOptions {
>;
flatOutput?: boolean;
readonly shouldInline: boolean;
veCompatLocale?: string;
hasDefinedSourceLocale?: boolean;
}

Expand Down Expand Up @@ -160,50 +159,9 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server

const buildOptions = { ...options };
const tsConfig = readTsconfig(buildOptions.tsConfig, context.workspaceRoot);
const usingIvy = tsConfig.options.enableIvy !== false;
const metadata = await context.getProjectMetadata(context.target);
const i18n = createI18nOptions(metadata, buildOptions.localize);

// Until 11.0, support deprecated i18n options when not using new localize option
// i18nFormat is automatically calculated
if (buildOptions.localize === undefined && usingIvy) {
mergeDeprecatedI18nOptions(i18n, buildOptions.i18nLocale, buildOptions.i18nFile);
} else if (buildOptions.localize !== undefined && !usingIvy) {
if (
buildOptions.localize === true ||
(Array.isArray(buildOptions.localize) && buildOptions.localize.length > 1)
) {
throw new Error(
`Localization with multiple locales in one build is not supported with View Engine.`,
);
}

for (const deprecatedOption of ['i18nLocale', 'i18nFormat', 'i18nFile']) {
// tslint:disable-next-line: no-any
if (typeof (buildOptions as any)[deprecatedOption] !== 'undefined') {
context.logger.warn(
`Option 'localize' and deprecated '${deprecatedOption}' found. Using 'localize'.`,
);
}
}

if (
buildOptions.localize === false ||
(Array.isArray(buildOptions.localize) && buildOptions.localize.length === 0)
) {
buildOptions.i18nFile = undefined;
buildOptions.i18nLocale = undefined;
buildOptions.i18nFormat = undefined;
}
}

// Clear deprecated options when using Ivy to prevent unintended behavior
if (usingIvy) {
buildOptions.i18nFile = undefined;
buildOptions.i18nFormat = undefined;
buildOptions.i18nLocale = undefined;
}

// No additional processing needed if no inlining requested and no source locale defined.
if (!i18n.shouldInline && !i18n.hasDefinedSourceLocale) {
return { buildOptions, i18n };
Expand Down Expand Up @@ -298,31 +256,6 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
desc.translation = loadResult.translations;
}
}

// Legacy message id's require the format of the translations
if (usedFormats.size > 0) {
buildOptions.i18nFormat = [...usedFormats][0];
}

// Provide support for using the Ivy i18n options with VE
if (!usingIvy) {
i18n.veCompatLocale = buildOptions.i18nLocale = [...i18n.inlineLocales][0];

if (buildOptions.i18nLocale !== i18n.sourceLocale) {
if (i18n.locales[buildOptions.i18nLocale].files.length > 1) {
throw new Error(
'Localization with View Engine only supports using a single translation file per locale.',
);
}
buildOptions.i18nFile = i18n.locales[buildOptions.i18nLocale].files[0].path;
}

// Clear inline locales to prevent any new i18n related processing
i18n.inlineLocales.clear();

// Update the output path to include the locale to mimic Ivy localize behavior
buildOptions.outputPath = path.join(buildOptions.outputPath, buildOptions.i18nLocale);
}
}

// If inlining store the output in a temporary location to facilitate post-processing
Expand All @@ -341,34 +274,6 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
return { buildOptions, i18n };
}

function mergeDeprecatedI18nOptions(
i18n: I18nOptions,
i18nLocale: string | undefined,
i18nFile: string | undefined,
): I18nOptions {
if (i18nFile !== undefined && i18nLocale === undefined) {
throw new Error(`Option 'i18nFile' cannot be used without the 'i18nLocale' option.`);
}

if (i18nLocale !== undefined) {
i18n.inlineLocales.clear();
i18n.inlineLocales.add(i18nLocale);

if (i18nFile !== undefined) {
i18n.locales[i18nLocale] = { files: [{ path: i18nFile }], baseHref: '' };
} else {
// If no file, treat the locale as the source locale
// This mimics deprecated behavior
i18n.sourceLocale = i18nLocale;
i18n.locales[i18nLocale] = { files: [], baseHref: '' };
}

i18n.flatOutput = true;
}

return i18n;
}

function findLocaleDataBasePath(projectRoot: string): string | null {
try {
const commonPath = path.dirname(
Expand Down
11 changes: 3 additions & 8 deletions packages/angular_devkit/build_angular/src/utils/output-paths.ts
Expand Up @@ -10,14 +10,9 @@ import { join } from 'path';
import { I18nOptions } from './i18n-options';

export function ensureOutputPaths(baseOutputPath: string, i18n: I18nOptions): Map<string, string> {
const outputPaths: [string, string][] =
i18n.shouldInline
? [...i18n.inlineLocales].map(l => [l, i18n.flatOutput ? baseOutputPath : join(baseOutputPath, l)])
: [
i18n.veCompatLocale
? [i18n.veCompatLocale, join(baseOutputPath, i18n.veCompatLocale)]
: ['', baseOutputPath],
];
const outputPaths: [string, string][] = i18n.shouldInline
? [...i18n.inlineLocales].map(l => [l, i18n.flatOutput ? baseOutputPath : join(baseOutputPath, l)])
: [['', baseOutputPath]];

for (const [, outputPath] of outputPaths) {
if (!existsSync(outputPath)) {
Expand Down
Expand Up @@ -29,7 +29,7 @@ export function updateI18nConfig(): Rule {
for (const [, target] of allWorkspaceTargets(workspace)) {
switch (target.builder) {
case Builders.Browser:
case Builders.Karma:
case Builders.Server:
updateBaseHrefs(target);
removeFormatOption(target);
addBuilderI18NOptions(target, logger);
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-basehref.ts
Expand Up @@ -8,7 +8,7 @@
import { expectFileToMatch } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { externalServer, langTranslations, setupI18nConfig } from './legacy';
import { externalServer, langTranslations, setupI18nConfig } from './setup';

const baseHrefs = {
'en-US': '/en/',
Expand All @@ -18,7 +18,7 @@ const baseHrefs = {

export default async function() {
// Setup i18n tests and config.
await setupI18nConfig(true);
await setupI18nConfig();

// Update angular.json
await updateJsonFile('angular.json', workspaceJson => {
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl-arb.ts
@@ -1,9 +1,9 @@
import { executeTest } from './ivy-localize-dl-xliff2';
import { setupI18nConfig } from './legacy';
import { setupI18nConfig } from './setup';

export default async function() {
// Setup i18n tests and config.
await setupI18nConfig(true, 'arb');
await setupI18nConfig('arb');

// Execute the tests
await executeTest();
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl-json.ts
@@ -1,9 +1,9 @@
import { executeTest } from './ivy-localize-dl-xliff2';
import { setupI18nConfig } from './legacy';
import { setupI18nConfig } from './setup';

export default async function() {
// Setup i18n tests and config.
await setupI18nConfig(true, 'json');
await setupI18nConfig('json');

// Execute the tests
await executeTest();
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl-xliff1.ts
@@ -1,9 +1,9 @@
import { executeTest } from './ivy-localize-dl-xliff2';
import { setupI18nConfig } from './legacy';
import { setupI18nConfig } from './setup';

export default async function() {
// Setup i18n tests and config.
await setupI18nConfig(true, 'xlf');
await setupI18nConfig('xlf');

// Execute the tests
await executeTest();
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl-xliff2.ts
Expand Up @@ -2,11 +2,11 @@ import { appendToFile, expectFileToMatch, replaceInFile } from '../../utils/fs';
import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';
import { baseDir, externalServer, langTranslations, setupI18nConfig } from './legacy';
import { baseDir, externalServer, langTranslations, setupI18nConfig } from './setup';

export default async function() {
// Setup i18n tests and config.
await setupI18nConfig(true, 'xlf2');
await setupI18nConfig('xlf2');

// Execute the tests
await executeTest();
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl-xmb.ts
@@ -1,9 +1,9 @@
import { executeTest } from './ivy-localize-dl-xliff2';
import { setupI18nConfig } from './legacy';
import { setupI18nConfig } from './setup';

export default async function() {
// Setup i18n tests and config.
await setupI18nConfig(true, 'xmb');
await setupI18nConfig('xmb');

// Execute the tests
await executeTest();
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/i18n/ivy-localize-es2015.ts
Expand Up @@ -2,7 +2,7 @@ import { expectFileNotToExist, expectFileToMatch, readFile, writeFile } from '..
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';
import { externalServer, langTranslations, setupI18nConfig } from './legacy';
import { externalServer, langTranslations, setupI18nConfig } from './setup';

export default async function() {
// Setup i18n tests and config.
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/i18n/ivy-localize-es5.ts
Expand Up @@ -2,7 +2,7 @@ import { expectFileNotToExist, expectFileToMatch, readFile } from '../../utils/f
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';
import { externalServer, langTranslations, setupI18nConfig } from './legacy';
import { externalServer, langTranslations, setupI18nConfig } from './setup';

export default async function() {
// Setup i18n tests and config.
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-hashes.ts
Expand Up @@ -8,13 +8,13 @@
import * as fs from 'fs';
import { appendToFile } from '../../utils/fs';
import { ng } from '../../utils/process';
import { langTranslations, setupI18nConfig } from './legacy';
import { langTranslations, setupI18nConfig } from './setup';

const OUTPUT_RE = /^(?<name>(?:main|vendor|\d+))\.(?<hash>[a-z0-9]+)\.js$/i;

export default async function() {
// Setup i18n tests and config.
await setupI18nConfig(true);
await setupI18nConfig();

// Build each locale and record output file hashes
const hashes = new Map<string, string>();
Expand Down
@@ -1,7 +1,7 @@
import { expectFileToMatch, prependToFile, readFile, replaceInFile, writeFile } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { externalServer, langTranslations, setupI18nConfig } from './legacy';
import { externalServer, langTranslations, setupI18nConfig } from './setup';

export default async function() {
// Setup i18n tests and config.
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-locale-data.ts
Expand Up @@ -7,11 +7,11 @@
*/
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { setupI18nConfig } from './legacy';
import { setupI18nConfig } from './setup';

export default async function() {
// Setup i18n tests and config.
await setupI18nConfig(true);
await setupI18nConfig();

// Update angular.json
await updateJsonFile('angular.json', workspaceJson => {
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-merging.ts
Expand Up @@ -7,11 +7,11 @@
*/
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { setupI18nConfig } from './legacy';
import { setupI18nConfig } from './setup';

export default async function() {
// Setup i18n tests and config.
await setupI18nConfig(true);
await setupI18nConfig();

// Update angular.json
await updateJsonFile('angular.json', workspaceJson => {
Expand Down