diff --git a/packages/angular/build/src/tools/esbuild/utils.ts b/packages/angular/build/src/tools/esbuild/utils.ts index 2730dafae97c..b19c1950a401 100644 --- a/packages/angular/build/src/tools/esbuild/utils.ts +++ b/packages/angular/build/src/tools/esbuild/utils.ts @@ -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 { diff --git a/packages/angular/build/src/tools/esbuild/utils_spec.ts b/packages/angular/build/src/tools/esbuild/utils_spec.ts new file mode 100644 index 000000000000..ad7ead47a506 --- /dev/null +++ b/packages/angular/build/src/tools/esbuild/utils_spec.ts @@ -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(); + }); +});