Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export default function localizeExtractLoader(
content: string,
map: LoaderSourceMap,
) {
// This loader is not cacheable due to how message extraction works.
// Extracted messages are not part of webpack pipeline and hence they cannot be retrieved from cache.
// TODO: We should investigate in the future on making this deterministic and more cacheable.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we file an issue or project about this? I'm always hesitant about TODO's in the code which tend to be forgotten about. Issues are more easily triaged, assignable, and actionable IMHO.

Copy link
Collaborator Author

@alan-agius4 alan-agius4 Dec 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

this.cacheable(false);

const options = this.getOptions();
const callback = this.async();

Expand Down
36 changes: 36 additions & 0 deletions tests/legacy-cli/e2e/tests/i18n/extract-ivy-disk-cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { join } from 'path';
import { getGlobalVariable } from '../../utils/env';
import { expectFileToMatch, rimraf, writeFile } from '../../utils/fs';
import { installPackage, uninstallPackage } from '../../utils/packages';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { readNgVersion } from '../../utils/version';

export default async function () {
// Enable disk cache
updateJsonFile('angular.json', (config) => {
config.cli ??= {};
config.cli.cache = { environment: 'all' };
});

// Setup an i18n enabled component
await ng('generate', 'component', 'i18n-test');
await writeFile(join('src/app/i18n-test', 'i18n-test.component.html'), '<p i18n>Hello world</p>');

// Install correct version
let localizeVersion = '@angular/localize@' + readNgVersion();
if (getGlobalVariable('argv')['ng-snapshots']) {
localizeVersion = require('../../ng-snapshot/package.json').dependencies['@angular/localize'];
}

await installPackage(localizeVersion);

for (let i = 0; i < 2; i++) {
// Run the extraction twice and make sure the second time round works with cache.
await rimraf('messages.xlf');
await ng('extract-i18n');
await expectFileToMatch('messages.xlf', 'Hello world');
}

await uninstallPackage('@angular/localize');
}
4 changes: 3 additions & 1 deletion tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'path';
import { getGlobalVariable } from '../../utils/env';
import { writeFile } from '../../utils/fs';
import { expectFileToMatch, writeFile } from '../../utils/fs';
import { installPackage, uninstallPackage } from '../../utils/packages';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
Expand Down Expand Up @@ -31,5 +31,7 @@ export default async function () {
throw new Error('Expected no warnings to be shown');
}

expectFileToMatch('messages.xlf', 'Hello world');

await uninstallPackage('@angular/localize');
}