Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/angular/build/src/tools/esbuild/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,13 @@ export async function logMessages(

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

export function getEntryPointName(entryPoint: string): string {
Expand Down
51 changes: 51 additions & 0 deletions packages/angular/build/src/tools/esbuild/utils_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import { isZonelessApp } from './utils';

describe('isZonelessApp', () => {
it('should return true when polyfills is undefined', () => {
expect(isZonelessApp(undefined)).toBeTrue();
});

it('should return true when polyfills is an empty array', () => {
expect(isZonelessApp([])).toBeTrue();
});

it('should return false when polyfills contains "zone.js"', () => {
expect(isZonelessApp(['zone.js'])).toBeFalse();
});

it('should return false when polyfills contains "zone.js" among other entries', () => {
expect(isZonelessApp(['some-polyfill', 'zone.js'])).toBeFalse();
});

it('should return true when polyfills contains only non-zone.js package names', () => {
expect(isZonelessApp(['some-polyfill'])).toBeTrue();
});

it('should return true when polyfills contains custom .ts files without zone.js', () => {
expect(isZonelessApp(['./polyfill-buffer.ts'])).toBeTrue();
});

it('should return true when polyfills contains custom .js files without zone.js', () => {
expect(isZonelessApp(['./custom-polyfill.js'])).toBeTrue();
});

it('should return true when polyfills contains custom .mjs files without zone.js', () => {
expect(isZonelessApp(['./polyfill.mjs'])).toBeTrue();
});

it('should return true when polyfills contains a mix of file polyfills and package names without zone.js', () => {
expect(isZonelessApp(['./polyfill-buffer.ts', 'some-polyfill', './other.js'])).toBeTrue();
});

it('should return false when polyfills contains file polyfills and zone.js', () => {
expect(isZonelessApp(['./polyfill-buffer.ts', 'zone.js'])).toBeFalse();
});
});
Loading