Skip to content

Commit 4822c6e

Browse files
committed
feat(@angular-devkit/build-angular): add wildcard option for allowedCommonJsDependencies
This commit adds the functionality to that when a wildcard `*` is provided to `allowedCommonJsDependencies` CJS/AMD warnings usages is skipped. Closes #25784
1 parent ad5370f commit 4822c6e

File tree

7 files changed

+16
-8
lines changed

7 files changed

+16
-8
lines changed

packages/angular_devkit/build_angular/src/builders/application/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@
406406
"enum": ["none", "anonymous", "use-credentials"]
407407
},
408408
"allowedCommonJsDependencies": {
409-
"description": "A list of CommonJS packages that are allowed to be used without a build time warning.",
409+
"description": "A list of CommonJS or AMD packages that are allowed to be used without a build time warning. Use `'*'` to allow all.",
410410
"type": "array",
411411
"items": {
412412
"type": "string"

packages/angular_devkit/build_angular/src/builders/application/tests/options/allowed-common-js-dependencies_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
7777
);
7878
});
7979

80-
it('should not show warning when all dependencies are allowed by asterisk', async () => {
80+
it('should not show warning when all dependencies are allowed by wildcard', async () => {
8181
// Add a Common JS dependency
8282
await harness.appendToFile(
8383
'src/app/app.component.ts',

packages/angular_devkit/build_angular/src/builders/browser-esbuild/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@
429429
"enum": ["none", "anonymous", "use-credentials"]
430430
},
431431
"allowedCommonJsDependencies": {
432-
"description": "A list of CommonJS packages that are allowed to be used without a build time warning.",
432+
"description": "A list of CommonJS or AMD packages that are allowed to be used without a build time warning. Use `'*'` to allow all.",
433433
"type": "array",
434434
"items": {
435435
"type": "string"

packages/angular_devkit/build_angular/src/builders/browser/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@
417417
"enum": ["none", "anonymous", "use-credentials"]
418418
},
419419
"allowedCommonJsDependencies": {
420-
"description": "A list of CommonJS packages that are allowed to be used without a build time warning.",
420+
"description": "A list of CommonJS or AMD packages that are allowed to be used without a build time warning. Use `'*'` to allow all.",
421421
"type": "array",
422422
"items": {
423423
"type": "string"

packages/angular_devkit/build_angular/src/builders/browser/tests/options/allowed-common-js-dependencies_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
7171
);
7272
});
7373

74-
it('should not show warning when all dependencies are allowed by asterisk', async () => {
74+
it('should not show warning when all dependencies are allowed by wildcard', async () => {
7575
// Add a Common JS dependency
7676
await harness.appendToFile(
7777
'src/app/app.component.ts',

packages/angular_devkit/build_angular/src/tools/esbuild/commonjs-checker.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type { Metafile, PartialMessage } from 'esbuild';
1717
*
1818
* If any allowed dependencies are provided via the `allowedCommonJsDependencies`
1919
* parameter, both the direct import and any deep imports will be ignored and no
20-
* diagnostic will be generated. Use `'*'` as entry to allow all dependencies.
20+
* diagnostic will be generated. Use `'*'` as entry to skip the check.
2121
*
2222
* If a module has been issued a diagnostic message, then all descendant modules
2323
* will not be checked. This prevents a potential massive amount of inactionable
@@ -34,6 +34,10 @@ export function checkCommonJSModules(
3434
const messages: PartialMessage[] = [];
3535
const allowedRequests = new Set(allowedCommonJsDependencies);
3636

37+
if (allowedRequests.has('*')) {
38+
return messages;
39+
}
40+
3741
// Ignore Angular locale definitions which are currently UMD
3842
allowedRequests.add('@angular/common/locales');
3943

@@ -83,7 +87,7 @@ export function checkCommonJSModules(
8387
const request = imported.original;
8488

8589
let notAllowed = true;
86-
if (allowedRequests.has('*') || allowedRequests.has(request)) {
90+
if (allowedRequests.has(request)) {
8791
notAllowed = false;
8892
} else {
8993
// Check for deep imports of allowed requests

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const CommonJsRequireDependency = require('webpack/lib/dependencies/CommonJsRequ
1717
const CommonJsSelfReferenceDependency = require('webpack/lib/dependencies/CommonJsSelfReferenceDependency');
1818

1919
export interface CommonJsUsageWarnPluginOptions {
20-
/** A list of CommonJS packages that are allowed to be used without a warning. */
20+
/** A list of CommonJS or AMD packages that are allowed to be used without a warning. Use `'*'` to allow all. */
2121
allowedDependencies?: string[];
2222
}
2323

@@ -30,6 +30,10 @@ export class CommonJsUsageWarnPlugin {
3030
}
3131

3232
apply(compiler: Compiler) {
33+
if (this.allowedDependencies.has('*')) {
34+
return;
35+
}
36+
3337
compiler.hooks.compilation.tap('CommonJsUsageWarnPlugin', (compilation) => {
3438
compilation.hooks.finishModules.tap('CommonJsUsageWarnPlugin', (modules) => {
3539
const mainEntry = compilation.entries.get('main');

0 commit comments

Comments
 (0)