Skip to content

Commit 6c9a0e3

Browse files
authored
fix(angular): sync missing schema changes in builders (#15600)
1 parent 5b8a663 commit 6c9a0e3

File tree

11 files changed

+125
-48
lines changed

11 files changed

+125
-48
lines changed

docs/generated/packages/angular/executors/webpack-browser.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@
330330
},
331331
"vendorChunk": {
332332
"type": "boolean",
333-
"description": "Generate a seperate bundle containing only vendor libraries. This option should only used for development.",
333+
"description": "Generate a seperate bundle containing only vendor libraries. This option should only be used for development to reduce the incremental compilation time.",
334334
"default": false
335335
},
336336
"commonChunk": {

docs/generated/packages/angular/executors/webpack-server.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@
185185
"description": "URL where files will be deployed.",
186186
"x-deprecated": "Use \"baseHref\" browser builder option, \"APP_BASE_HREF\" DI token or a combination of both instead. For more information, see https://angular.io/guide/deployment#the-deploy-url."
187187
},
188+
"vendorChunk": {
189+
"type": "boolean",
190+
"description": "Generate a seperate bundle containing only vendor libraries. This option should only be used for development to reduce the incremental compilation time. _Note: supported in Angular versions >= 15.1.0_",
191+
"default": false
192+
},
188193
"verbose": {
189194
"type": "boolean",
190195
"description": "Adds more details to output logging.",

packages/angular/plugins/component-testing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from '@nrwl/devkit';
2424
import { existsSync, lstatSync, mkdirSync, writeFileSync } from 'fs';
2525
import { dirname, join, relative, sep } from 'path';
26-
import type { BrowserBuilderSchema } from '../src/builders/webpack-browser/webpack-browser.impl';
26+
import type { BrowserBuilderSchema } from '../src/builders/webpack-browser/schema';
2727

2828
/**
2929
* Angular nx preset for Cypress Component Testing
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Schema } from '@angular-devkit/build-angular/src/builders/browser/schema';
2+
3+
export type BrowserBuilderSchema = Schema & {
4+
customWebpackConfig?: {
5+
path: string;
6+
};
7+
indexFileTransformer?: string;
8+
buildLibsFromSource?: boolean;
9+
};

packages/angular/src/builders/webpack-browser/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
},
279279
"vendorChunk": {
280280
"type": "boolean",
281-
"description": "Generate a seperate bundle containing only vendor libraries. This option should only used for development.",
281+
"description": "Generate a seperate bundle containing only vendor libraries. This option should only be used for development to reduce the incremental compilation time.",
282282
"default": false
283283
},
284284
"commonChunk": {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { stripIndents } from '@nrwl/devkit';
2+
import { extname } from 'path';
3+
import type { VersionInfo } from '../../executors/utilities/angular-version-utils';
4+
import { getInstalledAngularVersionInfo } from '../../executors/utilities/angular-version-utils';
5+
import type { BrowserBuilderSchema } from './schema';
6+
7+
export function validateOptions(options: BrowserBuilderSchema): void {
8+
const angularVersionInfo = getInstalledAngularVersionInfo();
9+
validatePolyfills(options, angularVersionInfo);
10+
validateStyles(options, angularVersionInfo);
11+
}
12+
13+
function validatePolyfills(
14+
options: BrowserBuilderSchema,
15+
{ major, version }: VersionInfo
16+
): void {
17+
if (major < 15 && Array.isArray(options.polyfills)) {
18+
throw new Error(stripIndents`The array syntax for the "polyfills" option is supported from Angular >= 15.0.0. You are currently using "${version}".
19+
You can resolve this error by removing the "polyfills" option, setting it to a string value or migrating to Angular 15.0.0.`);
20+
}
21+
}
22+
23+
function validateStyles(
24+
options: BrowserBuilderSchema,
25+
{ major, version }: VersionInfo
26+
): void {
27+
if (!options.styles || !options.styles.length) {
28+
return;
29+
}
30+
31+
if (major < 15) {
32+
return;
33+
}
34+
35+
const stylusFiles = [];
36+
options.styles.forEach((style) => {
37+
const styleFile = typeof style === 'string' ? style : style.input;
38+
if (extname(styleFile) === '.styl') {
39+
stylusFiles.push(styleFile);
40+
}
41+
});
42+
43+
if (stylusFiles.length) {
44+
throw new Error(stripIndents`Stylus is not supported since Angular v15. You're currently using "${version}".
45+
You have the "styles" option with the following file(s) using the ".styl" extension: ${stylusFiles
46+
.map((x) => `"${x}"`)
47+
.join(', ')}.
48+
Make sure to convert them to a supported extension (".css", ".scss", ".sass", ".less").`);
49+
}
50+
}

packages/angular/src/builders/webpack-browser/webpack-browser.impl.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,22 @@ import {
22
joinPathFragments,
33
ProjectGraph,
44
readCachedProjectGraph,
5-
stripIndents,
65
} from '@nrwl/devkit';
6+
import type { DependentBuildableProjectNode } from '@nrwl/js/src/utils/buildable-libs-utils';
77
import { WebpackNxBuildCoordinationPlugin } from '@nrwl/webpack/src/plugins/webpack-nx-build-coordination-plugin';
8-
import { DependentBuildableProjectNode } from '@nrwl/js/src/utils/buildable-libs-utils';
98
import { existsSync } from 'fs';
109
import { readNxJson } from 'nx/src/project-graph/file-utils';
1110
import { isNpmProject } from 'nx/src/project-graph/operators';
1211
import { getDependencyConfigs } from 'nx/src/tasks-runner/utils';
1312
import { from, Observable } from 'rxjs';
1413
import { switchMap } from 'rxjs/operators';
15-
import { getInstalledAngularVersionInfo } from '../../executors/utilities/angular-version-utils';
1614
import { createTmpTsConfigForBuildableLibs } from '../utilities/buildable-libs';
1715
import {
1816
mergeCustomWebpackConfig,
1917
resolveIndexHtmlTransformer,
2018
} from '../utilities/webpack';
21-
22-
export type BrowserBuilderSchema =
23-
import('@angular-devkit/build-angular/src/builders/browser/schema').Schema & {
24-
customWebpackConfig?: {
25-
path: string;
26-
};
27-
indexFileTransformer?: string;
28-
buildLibsFromSource?: boolean;
29-
};
30-
31-
function validateOptions(options: BrowserBuilderSchema): void {
32-
const { major, version } = getInstalledAngularVersionInfo();
33-
if (major < 15 && Array.isArray(options.polyfills)) {
34-
throw new Error(stripIndents`The array syntax for the "polyfills" option is supported from Angular >= 15.0.0. You are currently using ${version}.
35-
You can resolve this error by removing the "polyfills" option, setting it to a string value or migrating to Angular 15.0.0.`);
36-
}
37-
}
19+
import type { BrowserBuilderSchema } from './schema';
20+
import { validateOptions } from './validate-options';
3821

3922
function shouldSkipInitialTargetRun(
4023
projectGraph: ProjectGraph,

packages/angular/src/builders/webpack-server/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@
126126
"description": "URL where files will be deployed.",
127127
"x-deprecated": "Use \"baseHref\" browser builder option, \"APP_BASE_HREF\" DI token or a combination of both instead. For more information, see https://angular.io/guide/deployment#the-deploy-url."
128128
},
129+
"vendorChunk": {
130+
"type": "boolean",
131+
"description": "Generate a seperate bundle containing only vendor libraries. This option should only be used for development to reduce the incremental compilation time. _Note: supported in Angular versions >= 15.1.0_",
132+
"default": false
133+
},
129134
"verbose": {
130135
"type": "boolean",
131136
"description": "Adds more details to output logging.",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { stripIndents } from '@nrwl/devkit';
2+
import { lt } from 'semver';
3+
import type { VersionInfo } from '../../executors/utilities/angular-version-utils';
4+
import { getInstalledAngularVersionInfo } from '../../executors/utilities/angular-version-utils';
5+
import type { Schema } from './schema';
6+
7+
export function validateOptions(options: Schema): void {
8+
const angularVersionInfo = getInstalledAngularVersionInfo();
9+
validateAssets(options, angularVersionInfo);
10+
validateBundleDependencies(options, angularVersionInfo);
11+
validateVendorChunk(options, angularVersionInfo);
12+
}
13+
14+
function validateAssets(options: Schema, { version }: VersionInfo): void {
15+
if (
16+
lt(version, '15.1.0') &&
17+
Array.isArray(options.assets) &&
18+
options.assets.length > 0
19+
) {
20+
throw new Error(stripIndents`The "assets" option is supported from Angular >= 15.1.0. You are currently using "${version}".
21+
You can resolve this error by removing the "assets" option or by migrating to Angular 15.1.0.`);
22+
}
23+
}
24+
25+
function validateBundleDependencies(
26+
options: Schema,
27+
{ major, version }: VersionInfo
28+
): void {
29+
if (major >= 15 && options.bundleDependencies) {
30+
throw new Error(stripIndents`The "bundleDependencies" option was removed in Angular version 15. You are currently using "${version}".
31+
You can resolve this error by removing the "bundleDependencies" option.`);
32+
}
33+
}
34+
35+
function validateVendorChunk(options: Schema, { version }: VersionInfo): void {
36+
if (lt(version, '15.1.0') && options.vendorChunk) {
37+
throw new Error(stripIndents`The "vendorChunk" option is supported from Angular >= 15.1.0. You are currently using "${version}".
38+
You can resolve this error by removing the "vendorChunk" option or by migrating to Angular 15.1.0.`);
39+
}
40+
}

packages/angular/src/builders/webpack-server/webpack-server.impl.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { joinPathFragments, stripIndents } from '@nrwl/devkit';
1+
import { joinPathFragments } from '@nrwl/devkit';
22
import { existsSync } from 'fs';
3-
import { from, Observable } from 'rxjs';
4-
import { mergeCustomWebpackConfig } from '../utilities/webpack';
5-
import { Schema } from './schema';
6-
import { createTmpTsConfigForBuildableLibs } from '../utilities/buildable-libs';
3+
import { Observable, from } from 'rxjs';
74
import { switchMap } from 'rxjs/operators';
5+
import { lt } from 'semver';
86
import { getInstalledAngularVersionInfo } from '../../executors/utilities/angular-version-utils';
9-
import { gte, lt } from 'semver';
7+
import { createTmpTsConfigForBuildableLibs } from '../utilities/buildable-libs';
8+
import { mergeCustomWebpackConfig } from '../utilities/webpack';
9+
import { Schema } from './schema';
10+
import { validateOptions } from './validate-options';
1011

1112
function buildServerApp(
1213
options: Schema,
@@ -92,25 +93,9 @@ export function executeWebpackServerBuilder(
9293
options: Schema,
9394
context: import('@angular-devkit/architect').BuilderContext
9495
): Observable<import('@angular-devkit/build-angular').ServerBuilderOutput> {
95-
const installedAngularVersionInfo = getInstalledAngularVersionInfo();
96-
97-
if (
98-
lt(installedAngularVersionInfo.version, '15.1.0') &&
99-
Array.isArray(options.assets) &&
100-
options.assets.length > 0
101-
) {
102-
throw new Error(stripIndents`The "assets" option is only supported in Angular >= 15.1.0. You are currently using ${installedAngularVersionInfo.version}.
103-
You can resolve this error by removing the "assets" option or by migrating to Angular 15.1.0.`);
104-
}
105-
106-
if (
107-
gte(installedAngularVersionInfo.version, '15.0.0') &&
108-
options.bundleDependencies
109-
) {
110-
throw new Error(stripIndents`The "bundleDependencies" option was removed in Angular version 15. You are currently using ${installedAngularVersionInfo.version}.
111-
You can resolve this error by removing the "bundleDependencies" option.`);
112-
}
96+
validateOptions(options);
11397

98+
const installedAngularVersionInfo = getInstalledAngularVersionInfo();
11499
// default bundleDependencies to true if supported by Angular version
115100
if (
116101
lt(installedAngularVersionInfo.version, '15.0.0') &&

0 commit comments

Comments
 (0)