diff --git a/packages/angular_devkit/build_angular/src/extract-i18n/index.ts b/packages/angular_devkit/build_angular/src/extract-i18n/index.ts index 8522f028807c..4008c182dfbc 100644 --- a/packages/angular_devkit/build_angular/src/extract-i18n/index.ts +++ b/packages/angular_devkit/build_angular/src/extract-i18n/index.ts @@ -170,7 +170,6 @@ export async function execute( const metadata = await context.getProjectMetadata(context.target); const i18n = createI18nOptions(metadata); - let usingIvy = false; let useLegacyIds = true; const ivyMessages: LocalizeMessage[] = []; @@ -198,52 +197,37 @@ export async function execute( }, context, (wco) => { - const isIvyApplication = wco.tsConfig.options.enableIvy !== false; - - // Default value for legacy message ids is currently true - useLegacyIds = wco.tsConfig.options.enableI18nLegacyMessageIdFormat ?? true; - - // Ivy extraction is the default for Ivy applications. - usingIvy = (isIvyApplication && options.ivy === undefined) || !!options.ivy; - - if (usingIvy) { - if (!isIvyApplication) { - context.logger.warn( - 'Ivy extraction enabled but application is not Ivy enabled. Extraction may fail.', - ); - } - } else if (isIvyApplication) { + if (wco.tsConfig.options.enableIvy === false) { context.logger.warn( - 'Ivy extraction not enabled but application is Ivy enabled. ' + - 'If the extraction fails, the `--ivy` flag will enable Ivy extraction.', + 'Ivy extraction enabled but application is not Ivy enabled. Extraction may fail.', ); } + // Default value for legacy message ids is currently true + useLegacyIds = wco.tsConfig.options.enableI18nLegacyMessageIdFormat ?? true; + const partials = [ { plugins: [new NoEmitPlugin()] }, getCommonConfig(wco), getBrowserConfig(wco), - // Only use VE extraction if not using Ivy - getAotConfig(wco, !usingIvy), + getAotConfig(wco), getStatsConfig(wco), ]; // Add Ivy application file extractor support - if (usingIvy) { - partials.unshift({ - module: { - rules: [ - { - test: /\.[t|j]s$/, - loader: require.resolve('./ivy-extract-loader'), - options: { - messageHandler: (messages: LocalizeMessage[]) => ivyMessages.push(...messages), - }, + partials.unshift({ + module: { + rules: [ + { + test: /\.[t|j]s$/, + loader: require.resolve('./ivy-extract-loader'), + options: { + messageHandler: (messages: LocalizeMessage[]) => ivyMessages.push(...messages), }, - ], - }, - }); - } + }, + ], + }, + }); // Replace all stylesheets with an empty default export partials.push({ @@ -259,16 +243,14 @@ export async function execute( }, ); - if (usingIvy) { - try { - require.resolve('@angular/localize'); - } catch { - return { - success: false, - error: `Ivy extraction requires the '@angular/localize' package.`, - outputPath: outFile, - }; - } + try { + require.resolve('@angular/localize'); + } catch { + return { + success: false, + error: `Ivy extraction requires the '@angular/localize' package.`, + outputPath: outFile, + }; } const webpackResult = await runWebpack( @@ -283,8 +265,8 @@ export async function execute( // Set the outputPath to the extraction output location for downstream consumers webpackResult.outputPath = outFile; - // Complete if using VE or if Webpack build failed - if (!usingIvy || !webpackResult.success) { + // Complete if Webpack build failed + if (!webpackResult.success) { return webpackResult; } diff --git a/packages/angular_devkit/build_angular/src/extract-i18n/schema.json b/packages/angular_devkit/build_angular/src/extract-i18n/schema.json index 6ea25c29856f..492e02f596af 100644 --- a/packages/angular_devkit/build_angular/src/extract-i18n/schema.json +++ b/packages/angular_devkit/build_angular/src/extract-i18n/schema.json @@ -47,10 +47,6 @@ "description": "Specifies the source language of the application.", "x-deprecated": "Use 'i18n' project level sub-option 'sourceLocale' instead." }, - "ivy": { - "type": "boolean", - "description": "Use Ivy compiler to extract translations. The default for Ivy applications." - }, "progress": { "type": "boolean", "description": "Log progress to the console.", diff --git a/tests/legacy-cli/e2e/tests/i18n/build-locale.ts b/tests/legacy-cli/e2e/tests/i18n/build-locale.ts deleted file mode 100644 index 61d792d32261..000000000000 --- a/tests/legacy-cli/e2e/tests/i18n/build-locale.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { getGlobalVariable } from '../../utils/env'; -import { expectFileToMatch, rimraf } from '../../utils/fs'; -import { ng } from '../../utils/process'; - -export default async function () { - const argv = getGlobalVariable('argv'); - const veEnabled = argv['ve']; - if (!veEnabled) { - return; - } - - // tests for register_locale_data transformer - await ng('build', '--aot', '--i18n-locale=fr', '--configuration=development'); - await expectFileToMatch('dist/test-project/main.js', /registerLocaleData/); - await expectFileToMatch('dist/test-project/main.js', /angular_common_locales_fr/); - await expectFileToMatch('dist/test-project/index.html', /lang="fr"/); - - await rimraf('dist'); - await ng('build', '--aot', '--i18n-locale=fr_FR', '--configuration=development'); - await expectFileToMatch('dist/test-project/main.js', /registerLocaleData/); - await expectFileToMatch('dist/test-project/main.js', /angular_common_locales_fr/); - await expectFileToMatch('dist/test-project/index.html', /lang="fr_FR"/); - await rimraf('dist'); -} diff --git a/tests/legacy-cli/e2e/tests/i18n/extract-default.ts b/tests/legacy-cli/e2e/tests/i18n/extract-default.ts deleted file mode 100644 index c37427d4ddfa..000000000000 --- a/tests/legacy-cli/e2e/tests/i18n/extract-default.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { join } from 'path'; -import { getGlobalVariable } from '../../utils/env'; -import { expectFileToExist, expectFileToMatch, writeFile } from '../../utils/fs'; -import { ng } from '../../utils/process'; - - -export default async function() { - // TODO(architect): Delete this test. It is now in devkit/build-angular. - if (!getGlobalVariable('argv')['ve']) { - return; - } - - await ng('generate', 'component', 'i18n-test'); - await writeFile( - join('src/app/i18n-test', 'i18n-test.component.html'), - '
Hello world
', - ); - await ng('extract-i18n'); - await expectFileToExist('messages.xlf'); - await expectFileToMatch('messages.xlf', /Hello world/); -} diff --git a/tests/legacy-cli/e2e/tests/i18n/extract-errors.ts b/tests/legacy-cli/e2e/tests/i18n/extract-errors.ts deleted file mode 100644 index 479fe4b94432..000000000000 --- a/tests/legacy-cli/e2e/tests/i18n/extract-errors.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { ng } from '../../utils/process'; -import { writeFile } from '../../utils/fs'; -import { expectToFail } from '../../utils/utils'; -import { join } from 'path'; -import { getGlobalVariable } from '../../utils/env'; - -export default async function () { - // TODO(architect): Delete this test. It is now in devkit/build-angular. - if (!getGlobalVariable('argv')['ve']) { - return; - } - - await ng('generate', 'component', 'i18n-test'); - await writeFile( - join('src/app/i18n-test', 'i18n-test.component.html'), - 'Hello world inner
', - ); - - const { message } = await expectToFail(() => ng('extract-i18n')); - - const veProject = getGlobalVariable('argv')['ve']; - const msg = veProject - ? 'Could not mark an element as translatable inside a translatable section' - : 'Cannot mark an element as translatable inside of a translatable section'; - if (!message.includes(msg)) { - throw new Error(`Expected i18n extraction error, got this instead:\n${message}`); - } -} diff --git a/tests/legacy-cli/e2e/tests/i18n/extract-ivy-libraries.ts b/tests/legacy-cli/e2e/tests/i18n/extract-ivy-libraries.ts index 007bb442df77..9a4f5e7be7cc 100644 --- a/tests/legacy-cli/e2e/tests/i18n/extract-ivy-libraries.ts +++ b/tests/legacy-cli/e2e/tests/i18n/extract-ivy-libraries.ts @@ -61,7 +61,7 @@ export default async function() { await installPackage(localizeVersion); // Extract messages - await ng('extract-i18n', '--ivy'); + await ng('extract-i18n'); await expectFileToMatch('messages.xlf', 'Hello world'); await expectFileToMatch('messages.xlf', 'i18n-lib-test works!'); await expectFileToMatch('messages.xlf', 'src/app/app.component.html'); diff --git a/tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts b/tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts index a3cd8c93dbe8..28aeba318fbe 100644 --- a/tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts +++ b/tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts @@ -8,11 +8,6 @@ import { expectToFail } from '../../utils/utils'; import { readNgVersion } from '../../utils/version'; export default async function() { - // Ivy only test - if (getGlobalVariable('argv')['ve']) { - return; - } - // Setup an i18n enabled component await ng('generate', 'component', 'i18n-test'); await writeFile( @@ -20,7 +15,7 @@ export default async function() { 'Hello world
', ); - // Should fail with --ivy flag if `@angular/localize` is missing + // Should fail if `@angular/localize` is missing const { message: message1 } = await expectToFail(() => ng('extract-i18n')); if (!message1.includes(`Ivy extraction requires the '@angular/localize' package.`)) { throw new Error('Expected localize package error message when missing'); @@ -33,14 +28,8 @@ export default async function() { } await installPackage(localizeVersion); - // Should show ivy enabled application warning without --ivy flag - const { stderr: message3 } = await ng('extract-i18n', '--no-ivy'); - if (!message3.includes(`Ivy extraction not enabled but application is Ivy enabled.`)) { - throw new Error('Expected ivy enabled application warning'); - } - // Should not show any warnings when extracting - const { stderr: message5 } = await ng('extract-i18n', '--ivy'); + const { stderr: message5 } = await ng('extract-i18n'); if (message5.includes('WARNING')) { throw new Error('Expected no warnings to be shown'); } @@ -52,8 +41,8 @@ export default async function() { config.angularCompilerOptions = angularCompilerOptions; }); - // Should show ivy disabled application warning with --ivy flag and enableIvy false - const { message: message4 } = await expectToFail(() => ng('extract-i18n', '--ivy')); + // Should show ivy disabled application warning with enableIvy false + const { message: message4 } = await expectToFail(() => ng('extract-i18n')); if (!message4.includes(`Ivy extraction enabled but application is not Ivy enabled.`)) { throw new Error('Expected ivy disabled application warning'); } diff --git a/tests/legacy-cli/e2e/tests/i18n/extract-locale.ts b/tests/legacy-cli/e2e/tests/i18n/extract-locale.ts deleted file mode 100644 index dc6a4df3787a..000000000000 --- a/tests/legacy-cli/e2e/tests/i18n/extract-locale.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { join } from 'path'; -import { ng } from '../../utils/process'; -import { writeFile, expectFileToMatch } from '../../utils/fs'; -import { getGlobalVariable } from '../../utils/env'; - - -export default function() { - // TODO(architect): Delete this test. It is now in devkit/build-angular. - if (!getGlobalVariable('argv')['ve']) { - return; - } - - return ng('generate', 'component', 'i18n-test') - .then(() => writeFile( - join('src/app/i18n-test', 'i18n-test.component.html'), - 'Hello world
')) - .then(() => ng('extract-i18n', '--i18n-locale', 'fr')) - .then((output) => { - if (!output.stderr.match(/starting from Angular v4/)) { - return expectFileToMatch('messages.xlf', 'source-language="fr"'); - } - }); -} diff --git a/tests/legacy-cli/e2e/tests/i18n/extract-outfile.ts b/tests/legacy-cli/e2e/tests/i18n/extract-outfile.ts deleted file mode 100644 index c4454bbcbe31..000000000000 --- a/tests/legacy-cli/e2e/tests/i18n/extract-outfile.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { join } from 'path'; -import { ng } from '../../utils/process'; -import { writeFile, expectFileToMatch } from '../../utils/fs'; -import { getGlobalVariable } from '../../utils/env'; - - -export default async function () { - if (!getGlobalVariable('argv')['ve']) { - return; - } - - await ng('generate', 'component', 'i18n-test'); - await writeFile( - join('src/app/i18n-test', 'i18n-test.component.html'), - 'Hello world
', - ); - await ng('extract-i18n', '--out-file', 'messages.fr.xlf'); - await expectFileToMatch('messages.fr.xlf', 'Hello world'); -} diff --git a/tests/legacy-cli/e2e/tests/i18n/extract-xmb.ts b/tests/legacy-cli/e2e/tests/i18n/extract-xmb.ts deleted file mode 100644 index 3677c7f01662..000000000000 --- a/tests/legacy-cli/e2e/tests/i18n/extract-xmb.ts +++ /dev/null @@ -1,23 +0,0 @@ -import {join} from 'path'; -import {ng} from '../../utils/process'; -import { - expectFileToExist, writeFile, - expectFileToMatch -} from '../../utils/fs'; -import { getGlobalVariable } from '../../utils/env'; - - -export default function() { - // TODO(architect): Delete this test. It is now in devkit/build-angular. - if (!getGlobalVariable('argv')['ve']) { - return; - } - - return ng('generate', 'component', 'i18n-test') - .then(() => - writeFile(join('src/app/i18n-test', 'i18n-test.component.html'), 'Hello world
'), - ) - .then(() => ng('extract-i18n', '--format', 'xmb')) - .then(() => expectFileToExist('messages.xmb')) - .then(() => expectFileToMatch('messages.xmb', /Hello world/)); -} diff --git a/tests/legacy-cli/e2e/tests/i18n/ve-localize-es2015.ts b/tests/legacy-cli/e2e/tests/i18n/ve-localize-es2015.ts deleted file mode 100644 index cd4e2817a8cc..000000000000 --- a/tests/legacy-cli/e2e/tests/i18n/ve-localize-es2015.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { getGlobalVariable } from '../../utils/env'; -import { expectFileToMatch, writeFile } from '../../utils/fs'; -import { installPackage } from '../../utils/packages'; -import { execAndWaitForOutputToMatch, ng } from '../../utils/process'; -import { updateJsonFile } from '../../utils/project'; -import { expectToFail } from '../../utils/utils'; -import { readNgVersion } from '../../utils/version'; -import { externalServer, langTranslations, setupI18nConfig } from './legacy'; - -export default async function() { - if (!getGlobalVariable('argv')['ve']) { - return; - } - - // Setup i18n tests and config. - await setupI18nConfig(); - - // Using localize-based options requires the @angular/locale package - let localizeVersion = '@angular/localize@' + readNgVersion(); - if (getGlobalVariable('argv')['ng-snapshots']) { - localizeVersion = require('../../ng-snapshot/package.json').dependencies['@angular/localize']; - } - await installPackage(localizeVersion); - - // Ensure a es2017 build is used. - await writeFile('.browserslistrc', 'Chrome 65'); - await updateJsonFile('tsconfig.json', config => { - config.compilerOptions.target = 'es2017'; - if (!config.angularCompilerOptions) { - config.angularCompilerOptions = {}; - } - config.angularCompilerOptions.disableTypeScriptVersionCheck = true; - }); - - // Attempts to build multiple locales with VE should fail - await expectToFail(() => ng('build', '--configuration=development')); - - for (const { lang, outputPath, translation } of langTranslations) { - await ng('build', `--configuration=${lang}`); - - await expectFileToMatch(`${outputPath}/main.js`, translation.helloPartial); - await expectToFail(() => expectFileToMatch(`${outputPath}/main.js`, '$localize`')); - - // Verify the HTML lang attribute is present - await expectFileToMatch(`${outputPath}/index.html`, `lang="${lang}"`); - - // Execute Application E2E tests with dev server - await ng('e2e', `--configuration=${lang}`, '--port=0'); - - // Execute Application E2E tests for a production build without dev server - const server = externalServer(outputPath, `/${lang}/`); - try { - await ng( - 'e2e', - `--configuration=${lang}`, - '--devServerTarget=', - `--baseUrl=http://localhost:4200/${lang}/`, - ); - } finally { - server.close(); - } - } - - await execAndWaitForOutputToMatch( - 'ng', - ['build', '--configuration=fr', '--i18n-locale=en-US'], - /Option 'localize' and deprecated 'i18nLocale' found. Using 'localize'./, - ); - await execAndWaitForOutputToMatch( - 'ng', - ['build', '--configuration=fr', '--i18n-format=xmb'], - /Option 'localize' and deprecated 'i18nFormat' found. Using 'localize'./, - ); - await execAndWaitForOutputToMatch( - 'ng', - ['build', '--configuration=fr', '--i18n-file=error.json'], - /Option 'localize' and deprecated 'i18nFile' found. Using 'localize'./, - ); -}