Skip to content

Commit e40384e

Browse files
committed
refactor(@angular-devkit/build-angular): remove deprecated browserTarget
The `browserTarget` option has been removed as part of the refactoring process. This option was part of a private API and is no longer used. Projects relying on this option should migrate to using the `buildTarget` option. BREAKING CHANGE: The `browserTarget` option has been removed from the DevServer and ExtractI18n builders. `buildTarget` is to be used instead.
1 parent 9692a90 commit e40384e

File tree

12 files changed

+71
-70
lines changed

12 files changed

+71
-70
lines changed

goldens/public-api/angular_devkit/build_angular/index.api.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ export enum CrossOrigin {
116116
// @public
117117
export interface DevServerBuilderOptions {
118118
allowedHosts?: string[];
119-
// @deprecated
120-
browserTarget?: string;
121-
buildTarget?: string;
119+
buildTarget: string;
122120
disableHostCheck?: boolean;
123121
forceEsbuild?: boolean;
124122
headers?: {
@@ -192,8 +190,6 @@ export type ExecutionTransformer<T> = (input: T) => T | Promise<T>;
192190

193191
// @public
194192
export interface ExtractI18nBuilderOptions {
195-
// @deprecated
196-
browserTarget?: string;
197193
buildTarget?: string;
198194
format?: Format;
199195
outFile?: string;

modules/testing/builder/projects/hello-world-app/angular.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,19 @@
102102
"serve": {
103103
"builder": "@angular-devkit/build-angular:dev-server",
104104
"options": {
105-
"browserTarget": "app:build",
105+
"buildTarget": "app:build",
106106
"watch": false
107107
},
108108
"configurations": {
109109
"production": {
110-
"browserTarget": "app:build:production"
110+
"buildTarget": "app:build:production"
111111
}
112112
}
113113
},
114114
"extract-i18n": {
115115
"builder": "@angular-devkit/build-angular:extract-i18n",
116116
"options": {
117-
"browserTarget": "app:build",
117+
"buildTarget": "app:build",
118118
"progress": false,
119119
"outputPath": "src"
120120
}

packages/angular/build/src/builders/dev-server/tests/behavior/build-inline-critical-css_spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupT
3232
await harness.writeFile('src/main.ts', '');
3333
});
3434

35-
it('inlines critical css when enabled in the "browserTarget" options', async () => {
35+
it('inlines critical css when enabled in the "buildTarget" options', async () => {
3636
harness.useTarget('serve', {
3737
...BASE_OPTIONS,
3838
});

packages/angular_devkit/build_angular/src/builders/dev-server/options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function normalizeOptions(
3737
const cacheOptions = normalizeCacheOptions(projectMetadata, workspaceRoot);
3838

3939
// Target specifier defaults to the current project's build target using a development configuration
40-
const buildTargetSpecifier = options.buildTarget ?? options.browserTarget ?? `::development`;
40+
const buildTargetSpecifier = options.buildTarget ?? `::development`;
4141
const buildTarget = targetFromTargetString(buildTargetSpecifier, projectName, 'build');
4242

4343
// Get the application builder options.

packages/angular_devkit/build_angular/src/builders/dev-server/schema.json

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
"description": "Dev Server target options for Build Facade.",
55
"type": "object",
66
"properties": {
7-
"browserTarget": {
8-
"type": "string",
9-
"description": "A browser builder target to serve in the format of `project:target[:configuration]`. You can also pass in more than one configuration name as a comma-separated list. Example: `project:target:production,staging`.",
10-
"pattern": "^[^:\\s]+:[^:\\s]+(:[^\\s]+)?$",
11-
"x-deprecated": "Use 'buildTarget' instead."
12-
},
137
"buildTarget": {
148
"type": "string",
159
"description": "A build builder target to serve in the format of `project:target[:configuration]`. You can also pass in more than one configuration name as a comma-separated list. Example: `project:target:production,staging`.",
@@ -138,5 +132,5 @@
138132
}
139133
},
140134
"additionalProperties": false,
141-
"anyOf": [{ "required": ["buildTarget"] }, { "required": ["browserTarget"] }]
135+
"required": ["buildTarget"]
142136
}

packages/angular_devkit/build_angular/src/builders/dev-server/tests/behavior/build-inline-critical-css_spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupT
3232
await harness.writeFile('src/main.ts', '');
3333
});
3434

35-
it('inlines critical css when enabled in the "browserTarget" options', async () => {
35+
it('inlines critical css when enabled in the "buildTarget" options', async () => {
3636
harness.useTarget('serve', {
3737
...BASE_OPTIONS,
3838
});

packages/angular_devkit/build_angular/src/builders/dev-server/tests/behavior/serve-live-reload-proxies_spec.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ import puppeteer, { Browser, Page } from 'puppeteer';
1515
import { count, debounceTime, finalize, switchMap, take, timeout } from 'rxjs';
1616
import { executeDevServer } from '../../index';
1717
import { describeServeBuilder } from '../jasmine-helpers';
18-
import {
19-
BASE_OPTIONS,
20-
BUILD_TIMEOUT,
21-
DEV_SERVER_BUILDER_INFO,
22-
describeBuilder,
23-
setupBrowserTarget,
24-
} from '../setup';
18+
import { BASE_OPTIONS, BUILD_TIMEOUT, DEV_SERVER_BUILDER_INFO } from '../setup';
2519

2620
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2721
declare const document: any;

packages/angular_devkit/build_angular/src/builders/extract-i18n/options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function normalizeOptions(
3434
const projectRoot = path.join(workspaceRoot, (projectMetadata.root as string | undefined) ?? '');
3535

3636
// Target specifier defaults to the current project's build target with no specified configuration
37-
const buildTargetSpecifier = options.buildTarget ?? options.browserTarget ?? ':';
37+
const buildTargetSpecifier = options.buildTarget ?? ':';
3838
const buildTarget = targetFromTargetString(buildTargetSpecifier, projectName, 'build');
3939

4040
const i18nOptions = createI18nOptions(projectMetadata);

packages/angular_devkit/build_angular/src/builders/extract-i18n/schema.json

-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
"description": "Extract i18n target options for Build Facade.",
55
"type": "object",
66
"properties": {
7-
"browserTarget": {
8-
"type": "string",
9-
"description": "A browser builder target to extract i18n messages in the format of `project:target[:configuration]`. You can also pass in more than one configuration name as a comma-separated list. Example: `project:target:production,staging`.",
10-
"pattern": "^[^:\\s]+:[^:\\s]+(:[^\\s]+)?$",
11-
"x-deprecated": "Use 'buildTarget' instead."
12-
},
137
"buildTarget": {
148
"type": "string",
159
"description": "A builder target to extract i18n messages in the format of `project:target[:configuration]`. You can also pass in more than one configuration name as a comma-separated list. Example: `project:target:production,staging`.",

packages/schematics/angular/migrations/update-workspace-config/migration.ts

+58-30
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,26 @@ import { Builders, ProjectType } from '../../utility/workspace-models';
1313
/**
1414
* Main entry point for the migration rule.
1515
*
16-
* This migration performs the following tasks:
17-
* - Loops through all application projects in the workspace.
18-
* - Identifies the build target for each application.
19-
* - If the `localize` option is enabled but the polyfill `@angular/localize/init` is not present,
20-
* it adds the polyfill to the `polyfills` option of the build target.
16+
* This schematic migration performs updates to the Angular workspace configuration
17+
* to ensure that application projects are properly configured with polyfills
18+
* required for internationalization (`localize`).
19+
*
20+
* It specifically targets application projects that use either the `application`
21+
* or `browser-esbuild` builders.
22+
*
23+
* The migration process involves:
24+
*
25+
* 1. Iterating over all projects in the workspace.
26+
* 2. Checking each project to determine if it is an application-type project.
27+
* 3. For each application project, examining the associated build targets.
28+
* 4. If a build target's `localize` option is enabled but the polyfill
29+
* `@angular/localize/init` is missing from the `polyfills` array, the polyfill
30+
* is automatically added to ensure proper internationalization support.
31+
*
32+
* Additionally, this migration updates projects that use the `dev-server` or `extract-i18n`
33+
* builders to ensure that deprecated `browserTarget` options are migrated to the
34+
* newer `buildTarget` field.
2135
*
22-
* This migration is specifically for application projects that use either the `application` or `browser-esbuild` builders.
2336
*/
2437
export default function (): Rule {
2538
return updateWorkspace((workspace) => {
@@ -28,32 +41,47 @@ export default function (): Rule {
2841
continue;
2942
}
3043

31-
const buildTarget = project.targets.get('build');
32-
if (
33-
!buildTarget ||
34-
(buildTarget.builder !== Builders.BuildApplication &&
35-
buildTarget.builder !== Builders.Application &&
36-
buildTarget.builder !== Builders.BrowserEsbuild)
37-
) {
38-
continue;
39-
}
44+
for (const target of project.targets.values()) {
45+
if (target.builder === Builders.DevServer || target.builder === Builders.ExtractI18n) {
46+
// Migrate `browserTarget` to `buildTarget`
4047

41-
const polyfills = buildTarget.options?.['polyfills'];
42-
if (
43-
Array.isArray(polyfills) &&
44-
polyfills.some(
45-
(polyfill) => typeof polyfill === 'string' && polyfill.startsWith('@angular/localize'),
46-
)
47-
) {
48-
// Skip the polyfill is already added
49-
continue;
50-
}
48+
for (const [, options] of allTargetOptions(target, false)) {
49+
if (options['browserTarget'] && !options['buildTarget']) {
50+
options['buildTarget'] = options['browserTarget'];
51+
}
52+
53+
delete options['browserTarget'];
54+
}
55+
}
56+
57+
// Check if the target uses application-related builders
58+
if (
59+
target.builder !== Builders.BuildApplication &&
60+
target.builder !== Builders.Application &&
61+
target.builder !== Builders.BrowserEsbuild
62+
) {
63+
continue;
64+
}
65+
66+
// Check if polyfills include '@angular/localize/init'
67+
const polyfills = target.options?.['polyfills'];
68+
if (
69+
Array.isArray(polyfills) &&
70+
polyfills.some(
71+
(polyfill) => typeof polyfill === 'string' && polyfill.startsWith('@angular/localize'),
72+
)
73+
) {
74+
// Skip if the polyfill is already present
75+
continue;
76+
}
5177

52-
for (const [, options] of allTargetOptions(buildTarget, false)) {
53-
if (options['localize']) {
54-
buildTarget.options ??= {};
55-
((buildTarget.options['polyfills'] ??= []) as string[]).push('@angular/localize/init');
56-
break;
78+
// Add '@angular/localize/init' polyfill if localize option is enabled
79+
for (const [, options] of allTargetOptions(target, false)) {
80+
if (options['localize']) {
81+
target.options ??= {};
82+
((target.options['polyfills'] ??= []) as string[]).push('@angular/localize/init');
83+
break;
84+
}
5785
}
5886
}
5987
}

packages/schematics/angular/utility/workspace-models.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,9 @@ export interface BrowserBuilderOptions extends BrowserBuilderBaseOptions {
7474
}
7575

7676
export interface ServeBuilderOptions {
77-
/**
78-
* @deprecated not used since version 17.0.0. Use the property "buildTarget" instead.
79-
*/
80-
browserTarget: string;
81-
82-
// TODO: make it required, when the deprecated property "browserTarget" is removed.
83-
buildTarget?: string;
77+
buildTarget: string;
8478
}
79+
8580
export interface LibraryBuilderOptions {
8681
tsConfig: string;
8782
project: string;

tests/legacy-cli/e2e/tests/i18n/setup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export async function setupI18nConfig() {
243243
}
244244

245245
buildConfigs[lang] = { localize: [lang] };
246-
serveConfigs[lang] = { browserTarget: `test-project:build:${lang}` };
246+
serveConfigs[lang] = { buildTarget: `test-project:build:${lang}` };
247247
e2eConfigs[lang] = {
248248
specs: [`./src/app.${lang}.e2e-spec.ts`],
249249
devServerTarget: `test-project:serve:${lang}`,

0 commit comments

Comments
 (0)