Skip to content

Commit

Permalink
fix(@schematics/angular): when migrating do not set base localize opt…
Browse files Browse the repository at this point in the history
…ion for builder

This can cause unnecesary rebuild time increases and is unneeded when using the new multi-locale builds.
  • Loading branch information
clydin authored and vikerman committed Nov 27, 2019
1 parent 807eae2 commit 51d90bc
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ function addProjectI18NOptions(
function addBuilderI18NOptions(recorder: UpdateRecorder, builderConfig: JsonAstObject, projectConfig: JsonAstObject) {
const options = getAllOptions(builderConfig);

let hasi18n = false;
for (const option of options) {
const localeId = findPropertyInAstObject(option, 'i18nLocale');
if (localeId && localeId.kind === 'string') {
Expand All @@ -146,37 +145,6 @@ function addBuilderI18NOptions(recorder: UpdateRecorder, builderConfig: JsonAstO
if (i18nFormat) {
removePropertyInAstObject(recorder, option, 'i18nFormat');
}

hasi18n = !!(hasi18n || i18nFormat || i18nFile || localeId);
}

if (hasi18n) {
const options = findPropertyInAstObject(builderConfig, 'options');
if (!options || options.kind !== 'object') {
return;
}

// Don't add localize option of it's already present in the main options
if (findPropertyInAstObject(options, 'i18nLocale') || findPropertyInAstObject(options, 'localize')) {
return;
}

// Get sourceLocale from extract-i18n builder
const extractI18nConfig = getProjectTarget(projectConfig, 'extract-i18n', Builders.ExtractI18n);
let sourceLocale: string | undefined;

if (extractI18nConfig && extractI18nConfig.kind === 'object') {
const i18nOptions = getAllOptions(extractI18nConfig);
sourceLocale = i18nOptions
.map(o => {
const sourceLocale = findPropertyInAstObject(o, 'i18nLocale');

return sourceLocale && sourceLocale.value;
})
.find(x => !!x) as string;
}

insertPropertyInAstObjectInOrder(recorder, options, 'localize', [sourceLocale || 'en-US'], 12);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,6 @@ describe('Migration to version 9', () => {
expect(config.configurations.de.localize).toEqual(['de']);
});

it(`should add 'localize' option in main options`, async () => {
let config = getWorkspaceTargets(tree);
config.build.options.aot = false;
config.build.configurations.de = getI18NConfig('de');
config['extract-i18n'].options.i18nFormat = 'xmb';
config['extract-i18n'].options.i18nLocale = 'en-GB';
updateWorkspaceTargets(tree, config);

const tree2 = await schematicRunner.runSchematicAsync('workspace-version-9', {}, tree.branch()).toPromise();
config = getWorkspaceTargets(tree2).build;
expect(config.options.localize).toEqual(['en-GB']);
expect(config.configurations.de.localize).toEqual(['de']);
});

it('should remove deprecated i18n options', async () => {
let config = getWorkspaceTargets(tree);
config.build.options.aot = false;
Expand Down

0 comments on commit 51d90bc

Please sign in to comment.