Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 07f93b7

Browse files
committedJul 7, 2020
fix(@angular-devkit/build-angular): remove non-global locale import warning
We have not yet deprecated the non-global locale data modules (e.g. `@angular/common/locales/fr`) so we should not be issuing warnings about developers using them. We recently added warning suggesting that a "global" locale should be used instead, and the previous CommonJS/AMD warning about the format of these non-global modules are just confusing for the developer. Reference: TOOL-1388 Closes: #18123 (cherry picked from commit 0a573e7)
1 parent f989707 commit 07f93b7

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed
 

‎packages/angular_devkit/build_angular/src/angular-cli-files/plugins/common-js-usage-warn-plugin.ts

+12-19
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ export class CommonJsUsageWarnPlugin {
4747
if (
4848
!rawRequest ||
4949
rawRequest.startsWith('.') ||
50-
isAbsolute(rawRequest)
51-
) {
52-
// Skip if module is absolute or relative.
53-
continue;
54-
}
55-
56-
if (
50+
isAbsolute(rawRequest) ||
5751
this.allowedDepedencies.has(rawRequest) ||
58-
this.allowedDepedencies.has(this.rawRequestToPackageName(rawRequest))
52+
this.allowedDepedencies.has(this.rawRequestToPackageName(rawRequest)) ||
53+
rawRequest.startsWith('@angular/common/locales/')
5954
) {
60-
// Skip as this module is allowed even if it's a CommonJS.
55+
/**
56+
* Skip when:
57+
* - module is absolute or relative.
58+
* - module is allowed even if it's a CommonJS.
59+
* - module is a locale imported from '@angular/common'.
60+
*/
6161
continue;
6262
}
6363

@@ -81,16 +81,9 @@ export class CommonJsUsageWarnPlugin {
8181
// And if the issuer request is not from 'webpack-dev-server', as 'webpack-dev-server'
8282
// will require CommonJS libraries for live reloading such as 'sockjs-node'.
8383
if (mainIssuer?.name === 'main' && !issuer?.userRequest?.includes('webpack-dev-server')) {
84-
let warning = `${issuer?.userRequest} depends on '${rawRequest}'.`;
85-
86-
if (rawRequest.startsWith('@angular/common/locales')) {
87-
warning += `\nWhen using the 'localize' option this import is not needed. ` +
88-
`Did you mean to import '${rawRequest.replace(/locales(\/extra)?\//, 'locales/global/')}'?\n` +
89-
'For more info see: https://angular.io/guide/i18n#import-global-variants-of-the-locale-data';
90-
} else {
91-
warning += ' CommonJS or AMD dependencies can cause optimization bailouts.\n' +
92-
'For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies';
93-
}
84+
const warning = `${issuer?.userRequest} depends on '${rawRequest}'. ` +
85+
'CommonJS or AMD dependencies can cause optimization bailouts.\n' +
86+
'For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies';
9487

9588
// Avoid showing the same warning multiple times when in 'watch' mode.
9689
if (!this.shownWarnings.has(warning)) {

‎packages/angular_devkit/build_angular/src/browser/specs/common-js-warning_spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('Browser Builder commonjs warning', () => {
6464
await run.stop();
6565
});
6666

67-
it(`should show warning when importing non global '@angular/common/locale' data`, async () => {
67+
it(`should not show warning when importing non global local data '@angular/common/locale/fr'`, async () => {
6868
// Add a Common JS dependency
6969
host.appendToFile('src/app/app.component.ts', `
7070
import '@angular/common/locales/fr';
@@ -74,9 +74,7 @@ describe('Browser Builder commonjs warning', () => {
7474
const output = await run.result;
7575
expect(output.success).toBe(true);
7676

77-
const logMsg = logs.join();
78-
expect(logMsg).toMatch(/WARNING in.+app\.component\.ts depends on '@angular\/common\/locales\/fr'/);
79-
expect(logMsg).toContain(`Did you mean to import '@angular/common/locales/global/fr'`);
77+
expect(logs.join()).not.toContain('WARNING');
8078
await run.stop();
8179
});
8280
});

0 commit comments

Comments
 (0)
Please sign in to comment.