From f02d0e4d1a2f57c93c72fdfdf067c92a031885b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Wed, 1 Feb 2023 17:34:39 +0100 Subject: [PATCH] fix(angular): throw when polyfills is provided with an array for webpack-browser and angular 14 (#14742) --- .../angular/executors/webpack-browser.json | 2 +- .../src/builders/webpack-browser/schema.json | 2 +- .../webpack-browser/webpack-browser.impl.ts | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/generated/packages/angular/executors/webpack-browser.json b/docs/generated/packages/angular/executors/webpack-browser.json index b6eb6294d6..60c53c9843 100644 --- a/docs/generated/packages/angular/executors/webpack-browser.json +++ b/docs/generated/packages/angular/executors/webpack-browser.json @@ -75,7 +75,7 @@ "oneOf": [ { "type": "array", - "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'.", + "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'. _Note: supported in Angular versions >= 15.0.0_.", "items": { "type": "string", "uniqueItems": true }, "default": [] }, diff --git a/packages/angular/src/builders/webpack-browser/schema.json b/packages/angular/src/builders/webpack-browser/schema.json index 2a42198dff..2752b04cd4 100644 --- a/packages/angular/src/builders/webpack-browser/schema.json +++ b/packages/angular/src/builders/webpack-browser/schema.json @@ -41,7 +41,7 @@ "oneOf": [ { "type": "array", - "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'.", + "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'. _Note: supported in Angular versions >= 15.0.0_.", "items": { "type": "string", "uniqueItems": true diff --git a/packages/angular/src/builders/webpack-browser/webpack-browser.impl.ts b/packages/angular/src/builders/webpack-browser/webpack-browser.impl.ts index 23fde4e137..c306600218 100644 --- a/packages/angular/src/builders/webpack-browser/webpack-browser.impl.ts +++ b/packages/angular/src/builders/webpack-browser/webpack-browser.impl.ts @@ -1,12 +1,13 @@ -import { joinPathFragments } from '@nrwl/devkit'; +import { joinPathFragments, stripIndents } from '@nrwl/devkit'; import { existsSync } from 'fs'; import { from, Observable } from 'rxjs'; +import { switchMap } from 'rxjs/operators'; +import { getInstalledAngularVersionInfo } from '../../executors/utilities/angular-version-utils'; +import { createTmpTsConfigForBuildableLibs } from '../utilities/buildable-libs'; import { mergeCustomWebpackConfig, resolveIndexHtmlTransformer, } from '../utilities/webpack'; -import { createTmpTsConfigForBuildableLibs } from '../utilities/buildable-libs'; -import { switchMap } from 'rxjs/operators'; export type BrowserBuilderSchema = import('@angular-devkit/build-angular/src/builders/browser/schema').Schema & { @@ -108,10 +109,19 @@ function buildAppWithCustomWebpackConfiguration( ); } +function validateOptions(options: BrowserBuilderSchema): void { + const { major, version } = getInstalledAngularVersionInfo(); + if (major < 15 && Array.isArray(options.polyfills)) { + throw new Error(stripIndents`The array syntax for the "polyfills" option is supported from Angular >= 15.0.0. You are currently using ${version}. + You can resolve this error by removing the "polyfills" option, setting it to a string value or migrating to Angular 15.0.0.`); + } +} + export function executeWebpackBrowserBuilder( options: BrowserBuilderSchema, context: import('@angular-devkit/architect').BuilderContext ): Observable { + validateOptions(options); options.buildLibsFromSource ??= true; if (!options.buildLibsFromSource) {