fix(angular): add missing forceEsbuild option to dev-server executor (#21753)

This commit is contained in:
Leosvel Pérez Espinosa 2024-02-09 17:29:44 +01:00 committed by GitHub
parent a8dfc299e8
commit 3e193b94b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 33 additions and 10 deletions

View File

@ -105,6 +105,11 @@
"type": "number", "type": "number",
"description": "Enable and define the file watching poll time period in milliseconds." "description": "Enable and define the file watching poll time period in milliseconds."
}, },
"forceEsbuild": {
"type": "boolean",
"description": "Force the development server to use the 'browser-esbuild' builder when building. This is a developer preview option for the esbuild-based build system. _Note: this is only supported in Angular versions >= 16.1.0_.",
"default": false
},
"buildLibsFromSource": { "buildLibsFromSource": {
"type": "boolean", "type": "boolean",
"description": "Read buildable libraries from source instead of building them separately. If not set, it will take the value specified in the `browserTarget` options, or it will default to `true` if it's also not set in the `browserTarget` options.", "description": "Read buildable libraries from source instead of building them separately. If not set, it will take the value specified in the `browserTarget` options, or it will default to `true` if it's also not set in the `browserTarget` options.",

View File

@ -10,7 +10,6 @@ import {
normalizePath, normalizePath,
parseTargetString, parseTargetString,
readCachedProjectGraph, readCachedProjectGraph,
stripIndents,
type Target, type Target,
} from '@nx/devkit'; } from '@nx/devkit';
import { getRootTsConfigPath } from '@nx/js'; import { getRootTsConfigPath } from '@nx/js';
@ -34,7 +33,7 @@ import {
mergeCustomWebpackConfig, mergeCustomWebpackConfig,
resolveIndexHtmlTransformer, resolveIndexHtmlTransformer,
} from '../utilities/webpack'; } from '../utilities/webpack';
import { normalizeOptions } from './lib'; import { normalizeOptions, validateOptions } from './lib';
import type { import type {
NormalizedSchema, NormalizedSchema,
Schema, Schema,
@ -55,14 +54,7 @@ export function executeDevServerBuilder(
rawOptions: Schema, rawOptions: Schema,
context: import('@angular-devkit/architect').BuilderContext context: import('@angular-devkit/architect').BuilderContext
) { ) {
if (rawOptions.esbuildMiddleware?.length > 0) { validateOptions(rawOptions);
const { major: angularMajorVersion, version: angularVersion } =
getInstalledAngularVersionInfo();
if (angularMajorVersion < 17) {
throw new Error(stripIndents`The "esbuildMiddleware" option is only supported in Angular >= 17.0.0. You are currently using "${angularVersion}".
You can resolve this error by removing the "esbuildMiddleware" option or by migrating to Angular 17.0.0.`);
}
}
process.env.NX_TSCONFIG_PATH = getRootTsConfigPath(); process.env.NX_TSCONFIG_PATH = getRootTsConfigPath();

View File

@ -1 +1,2 @@
export * from './normalize-options'; export * from './normalize-options';
export * from './validate-options';

View File

@ -0,0 +1,19 @@
import { stripIndents } from '@nx/devkit';
import { lt } from 'semver';
import { getInstalledAngularVersionInfo } from '../../../executors/utilities/angular-version-utils';
import type { Schema } from '../schema';
export function validateOptions(options: Schema): void {
const { major: angularMajorVersion, version: angularVersion } =
getInstalledAngularVersionInfo();
if (lt(angularVersion, '16.1.0') && options.forceEsbuild !== undefined) {
throw new Error(stripIndents`The "forceEsbuild" option is only supported in Angular >= 16.1.0. You are currently using "${angularVersion}".
You can resolve this error by removing the "forceEsbuild" option or by migrating to Angular 16.1.0.`);
}
if (angularMajorVersion < 17 && options.esbuildMiddleware?.length > 0) {
throw new Error(stripIndents`The "esbuildMiddleware" option is only supported in Angular >= 17.0.0. You are currently using "${angularVersion}".
You can resolve this error by removing the "esbuildMiddleware" option or by migrating to Angular 17.0.0.`);
}
}

View File

@ -16,6 +16,7 @@ interface BaseSchema {
hmr?: boolean; hmr?: boolean;
watch?: boolean; watch?: boolean;
poll?: number; poll?: number;
forceEsbuild?: boolean;
buildLibsFromSource?: boolean; buildLibsFromSource?: boolean;
esbuildMiddleware?: string[]; esbuildMiddleware?: string[];
} }

View File

@ -111,6 +111,11 @@
"type": "number", "type": "number",
"description": "Enable and define the file watching poll time period in milliseconds." "description": "Enable and define the file watching poll time period in milliseconds."
}, },
"forceEsbuild": {
"type": "boolean",
"description": "Force the development server to use the 'browser-esbuild' builder when building. This is a developer preview option for the esbuild-based build system. _Note: this is only supported in Angular versions >= 16.1.0_.",
"default": false
},
"buildLibsFromSource": { "buildLibsFromSource": {
"type": "boolean", "type": "boolean",
"description": "Read buildable libraries from source instead of building them separately. If not set, it will take the value specified in the `browserTarget` options, or it will default to `true` if it's also not set in the `browserTarget` options.", "description": "Read buildable libraries from source instead of building them separately. If not set, it will take the value specified in the `browserTarget` options, or it will default to `true` if it's also not set in the `browserTarget` options.",