Skip to content

Commit 86eb746

Browse files
author
maruthan
committed
fix(@angular/build): correct zoneless app detection with polyfills array
The isZonelessApp check incorrectly treated any polyfill entry with a file extension as zone.js being present. This caused apps with custom polyfill files (e.g., ./polyfill-buffer.ts) but no zone.js to be incorrectly detected as non-zoneless. Now only checks for the literal 'zone.js' string. Fixes #30689
1 parent f1ed025 commit 86eb746

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

packages/angular/build/src/tools/esbuild/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,13 @@ export async function logMessages(
471471

472472
/**
473473
* Ascertain whether the application operates without `zone.js`, we currently rely on the polyfills setting to determine its status.
474-
* If a file with an extension is provided or if `zone.js` is included in the polyfills, the application is deemed as not zoneless.
474+
* If `zone.js` is included in the polyfills, the application is deemed as not zoneless.
475475
* @param polyfills An array of polyfills
476476
* @returns true, when the application is considered as zoneless.
477477
*/
478478
export function isZonelessApp(polyfills: string[] | undefined): boolean {
479479
// TODO: Instead, we should rely on the presence of zone.js in the polyfills build metadata.
480-
return !polyfills?.some((p) => p === 'zone.js' || /\.[mc]?[jt]s$/.test(p));
480+
return !polyfills?.some((p) => p === 'zone.js');
481481
}
482482

483483
export function getEntryPointName(entryPoint: string): string {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC 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.dev/license
7+
*/
8+
9+
import { isZonelessApp } from './utils';
10+
11+
describe('isZonelessApp', () => {
12+
it('should return true when polyfills is undefined', () => {
13+
expect(isZonelessApp(undefined)).toBeTrue();
14+
});
15+
16+
it('should return true when polyfills is an empty array', () => {
17+
expect(isZonelessApp([])).toBeTrue();
18+
});
19+
20+
it('should return false when polyfills contains "zone.js"', () => {
21+
expect(isZonelessApp(['zone.js'])).toBeFalse();
22+
});
23+
24+
it('should return false when polyfills contains "zone.js" among other entries', () => {
25+
expect(isZonelessApp(['some-polyfill', 'zone.js'])).toBeFalse();
26+
});
27+
28+
it('should return true when polyfills contains only non-zone.js package names', () => {
29+
expect(isZonelessApp(['some-polyfill'])).toBeTrue();
30+
});
31+
32+
it('should return true when polyfills contains custom .ts files without zone.js', () => {
33+
expect(isZonelessApp(['./polyfill-buffer.ts'])).toBeTrue();
34+
});
35+
36+
it('should return true when polyfills contains custom .js files without zone.js', () => {
37+
expect(isZonelessApp(['./custom-polyfill.js'])).toBeTrue();
38+
});
39+
40+
it('should return true when polyfills contains custom .mjs files without zone.js', () => {
41+
expect(isZonelessApp(['./polyfill.mjs'])).toBeTrue();
42+
});
43+
44+
it('should return true when polyfills contains a mix of file polyfills and package names without zone.js', () => {
45+
expect(isZonelessApp(['./polyfill-buffer.ts', 'some-polyfill', './other.js'])).toBeTrue();
46+
});
47+
48+
it('should return false when polyfills contains file polyfills and zone.js', () => {
49+
expect(isZonelessApp(['./polyfill-buffer.ts', 'zone.js'])).toBeFalse();
50+
});
51+
});

0 commit comments

Comments
 (0)