Skip to content

Commit 7b77e92

Browse files
committed
refactor(@angular-devkit/build-angular): remove allowed webpack and @angular-devkit/build-angular from CommonJsUsageWarnPlugin
These are no longer needed
1 parent ea1325e commit 7b77e92

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import { Architect } from '@angular-devkit/architect';
9+
import { logging } from '@angular-devkit/core';
10+
import { createArchitect, host } from '../test-utils';
11+
12+
describe('Dev Server Builder commonjs warning', () => {
13+
const targetSpec = { project: 'app', target: 'serve' };
14+
15+
let architect: Architect;
16+
let logger: logging.Logger;
17+
let logs: string[];
18+
19+
beforeEach(async () => {
20+
await host.initialize().toPromise();
21+
architect = (await createArchitect(host.root())).architect;
22+
23+
// Create logger
24+
logger = new logging.Logger('');
25+
logs = [];
26+
logger.subscribe(e => logs.push(e.message));
27+
});
28+
29+
afterEach(async () => host.restore().toPromise());
30+
31+
it('should not show warning when using HMR', async () => {
32+
const run = await architect.scheduleTarget(targetSpec, { hmr: true }, { logger });
33+
const output = await run.result;
34+
expect(output.success).toBe(true);
35+
expect(logs.join()).not.toContain('Warning');
36+
await run.stop();
37+
});
38+
39+
it('should not show warning when using live-reload', async () => {
40+
const run = await architect.scheduleTarget(targetSpec, { liveReload: true}, { logger });
41+
const output = await run.result;
42+
expect(output.success).toBe(true);
43+
expect(logs.join()).not.toContain('Warning');
44+
await run.stop();
45+
});
46+
});

packages/angular_devkit/build_angular/src/webpack/plugins/common-js-usage-warn-plugin.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,10 @@ export interface CommonJsUsageWarnPluginOptions {
3333

3434
export class CommonJsUsageWarnPlugin {
3535
private shownWarnings = new Set<string>();
36-
37-
// Allow the below dependency for HMR
38-
// tslint:disable-next-line: max-line-length
39-
// https://github.com/angular/angular-cli/blob/1e258317b1f6ec1e957ee3559cc3b28ba602f3ba/packages/angular_devkit/build_angular/src/dev-server/index.ts#L605-L638
40-
private allowedDependencies = new Set<string>([
41-
'webpack/hot/dev-server',
42-
'webpack/hot/only-dev-server',
43-
'@angular-devkit/build-angular',
44-
]);
36+
private allowedDependencies: Set<string>;
4537

4638
constructor(private options: CommonJsUsageWarnPluginOptions = {}) {
47-
this.options.allowedDependencies?.forEach(d => this.allowedDependencies.add(d));
39+
this.allowedDependencies = new Set(this.options.allowedDependencies);
4840
}
4941

5042
apply(compiler: Compiler) {
@@ -90,7 +82,7 @@ export class CommonJsUsageWarnPlugin {
9082
// Only show warnings for modules from main entrypoint.
9183
// And if the issuer request is not from 'webpack-dev-server', as 'webpack-dev-server'
9284
// will require CommonJS libraries for live reloading such as 'sockjs-node'.
93-
if (mainIssuer?.name === 'main' && !issuer?.userRequest?.includes('webpack-dev-server')) {
85+
if (mainIssuer?.name === 'main') {
9486
const warning = `${issuer?.userRequest} depends on '${rawRequest}'. ` +
9587
'CommonJS or AMD dependencies can cause optimization bailouts.\n' +
9688
'For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies';

0 commit comments

Comments
 (0)