Skip to content

Commit ad5370f

Browse files
committed
feat(@Angular-devkit): asterisk option for allowedCommonJsDependencies
1 parent 8a47ddb commit ad5370f

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
7777
);
7878
});
7979

80+
it('should not show warning when all dependencies are allowed by asterisk', async () => {
81+
// Add a Common JS dependency
82+
await harness.appendToFile(
83+
'src/app/app.component.ts',
84+
`
85+
import 'buffer';
86+
`,
87+
);
88+
89+
harness.useTarget('build', {
90+
...BASE_OPTIONS,
91+
allowedCommonJsDependencies: ['*'],
92+
optimization: true,
93+
});
94+
95+
const { result, logs } = await harness.executeOnce();
96+
97+
expect(result?.success).toBe(true);
98+
expect(logs).not.toContain(
99+
jasmine.objectContaining<logging.LogEntry>({
100+
message: jasmine.stringMatching(/CommonJS or AMD dependencies/),
101+
}),
102+
);
103+
});
104+
80105
it('should not show warning when depending on zone.js', async () => {
81106
// Add a Common JS dependency
82107
await harness.appendToFile(

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,31 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
7171
);
7272
});
7373

74+
it('should not show warning when all dependencies are allowed by asterisk', async () => {
75+
// Add a Common JS dependency
76+
await harness.appendToFile(
77+
'src/app/app.component.ts',
78+
`
79+
import 'bootstrap';
80+
import 'zone.js';
81+
`,
82+
);
83+
84+
harness.useTarget('build', {
85+
...BASE_OPTIONS,
86+
allowedCommonJsDependencies: ['*'],
87+
});
88+
89+
const { result, logs } = await harness.executeOnce();
90+
91+
expect(result?.success).toBe(true);
92+
expect(logs).not.toContain(
93+
jasmine.objectContaining<logging.LogEntry>({
94+
message: jasmine.stringMatching(/CommonJS or AMD dependencies/),
95+
}),
96+
);
97+
});
98+
7499
it(`should not show warning when importing non global local data '@angular/common/locale/fr'`, async () => {
75100
await harness.appendToFile(
76101
'src/app/app.component.ts',

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

Lines changed: 2 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.
20+
* diagnostic will be generated. Use `'*'` as entry to allow all dependencies.
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
@@ -83,7 +83,7 @@ export function checkCommonJSModules(
8383
const request = imported.original;
8484

8585
let notAllowed = true;
86-
if (allowedRequests.has(request)) {
86+
if (allowedRequests.has('*') || allowedRequests.has(request)) {
8787
notAllowed = false;
8888
} else {
8989
// Check for deep imports of allowed requests

0 commit comments

Comments
 (0)