Skip to content

Commit c48982d

Browse files
committed
feat(@angular-devkit/build-angular): add buildTarget option to dev-server and extract-i18n builders
This is to better match the nature of the application builder where the target can be both browser and server. DEPRECATED: The `browserTarget` in the dev-server and extract-i18n builders have been deprecated in favor of `buildTarget`.
1 parent 258ccae commit c48982d

File tree

18 files changed

+190
-24
lines changed

18 files changed

+190
-24
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ export enum CrossOrigin {
107107
// @public
108108
export interface DevServerBuilderOptions {
109109
allowedHosts?: string[];
110-
browserTarget: string;
110+
// @deprecated
111+
browserTarget?: string;
112+
buildTarget?: string;
111113
disableHostCheck?: boolean;
112114
forceEsbuild?: boolean;
113115
headers?: {
@@ -176,7 +178,9 @@ export type ExecutionTransformer<T> = (input: T) => T | Promise<T>;
176178

177179
// @public
178180
export interface ExtractI18nBuilderOptions {
179-
browserTarget: string;
181+
// @deprecated
182+
browserTarget?: string;
183+
buildTarget?: string;
180184
format?: Format;
181185
outFile?: string;
182186
outputPath?: string;

packages/angular_devkit/build_angular/src/builders/application/tests/behavior/typescript-rebuild-lazy_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
4444

4545
const builderAbort = new AbortController();
4646
const buildCount = await firstValueFrom(
47-
harness.execute({ outputLogsOnFailure: true, signal: builderAbort.signal }).pipe(
47+
harness.execute({ outputLogsOnFailure: false, signal: builderAbort.signal }).pipe(
4848
timeout(20_000),
4949
concatMap(async ({ result, logs }, index) => {
5050
switch (index) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async function initialize(
7474
await purgeStaleBuildCache(context);
7575

7676
const normalizedOptions = await normalizeOptions(context, projectName, initialOptions);
77-
const builderName = await context.getBuilderNameForTarget(normalizedOptions.browserTarget);
77+
const builderName = await context.getBuilderNameForTarget(normalizedOptions.buildTarget);
7878

7979
if (
8080
!normalizedOptions.disableHostCheck &&

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export async function normalizeOptions(
3434

3535
const cacheOptions = normalizeCacheOptions(projectMetadata, workspaceRoot);
3636

37-
const browserTarget = targetFromTargetString(options.browserTarget);
37+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
38+
const buildTarget = targetFromTargetString(options.buildTarget ?? options.browserTarget!);
3839

3940
// Initial options to keep
4041
const {
@@ -60,7 +61,7 @@ export async function normalizeOptions(
6061

6162
// Return all the normalized options
6263
return {
63-
browserTarget,
64+
buildTarget,
6465
host: host ?? 'localhost',
6566
port: port ?? 4200,
6667
poll,

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
"browserTarget": {
88
"type": "string",
99
"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+
},
13+
"buildTarget": {
14+
"type": "string",
15+
"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`.",
1016
"pattern": "^[^:\\s]+:[^:\\s]+(:[^\\s]+)?$"
1117
},
1218
"port": {
@@ -103,5 +109,5 @@
103109
}
104110
},
105111
"additionalProperties": false,
106-
"required": ["browserTarget"]
112+
"anyOf": [{ "required": ["buildTarget"] }, { "required": ["browserTarget"] }]
107113
}

packages/angular_devkit/build_angular/src/builders/dev-server/tests/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const DEV_SERVER_BUILDER_INFO = Object.freeze({
3030
* supports parallel test execution.
3131
*/
3232
export const BASE_OPTIONS = Object.freeze<Schema>({
33-
browserTarget: 'test:build',
33+
buildTarget: 'test:build',
3434
port: 0,
3535
});
3636

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function* serveWithVite(
5151
): AsyncIterableIterator<DevServerBuilderOutput> {
5252
// Get the browser configuration from the target name.
5353
const rawBrowserOptions = (await context.getTargetOptions(
54-
serverOptions.browserTarget,
54+
serverOptions.buildTarget,
5555
)) as json.JsonObject & BrowserBuilderOptions;
5656

5757
const browserOptions = (await context.validateOptions(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function serveWebpackBrowser(
8686

8787
// Get the browser configuration from the target name.
8888
const rawBrowserOptions = (await context.getTargetOptions(
89-
options.browserTarget,
89+
options.buildTarget,
9090
)) as json.JsonObject & BrowserBuilderSchema;
9191

9292
if (rawBrowserOptions.outputHashing && rawBrowserOptions.outputHashing !== OutputHashing.None) {

packages/angular_devkit/build_angular/src/builders/extract-i18n/application-extraction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export async function extractMessages(
2929
}> {
3030
const messages: LocalizeMessage[] = [];
3131

32-
// Setup the build options for the application based on the browserTarget option
32+
// Setup the build options for the application based on the buildTarget option
3333
const buildOptions = (await context.validateOptions(
34-
await context.getTargetOptions(options.browserTarget),
34+
await context.getTargetOptions(options.buildTarget),
3535
builderName,
3636
)) as unknown as ApplicationBuilderInternalOptions;
3737
buildOptions.optimization = false;

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ export async function execute(
4343
// The package is a peer dependency and might not be present
4444
let localizeToolsModule;
4545
try {
46-
localizeToolsModule = await loadEsmModule<typeof import('@angular/localize/tools')>(
47-
'@angular/localize/tools',
48-
);
46+
localizeToolsModule =
47+
await loadEsmModule<typeof import('@angular/localize/tools')>('@angular/localize/tools');
4948
} catch {
5049
return {
5150
success: false,
@@ -57,7 +56,7 @@ export async function execute(
5756

5857
// Normalize options
5958
const normalizedOptions = await normalizeOptions(context, projectName, options);
60-
const builderName = await context.getBuilderNameForTarget(normalizedOptions.browserTarget);
59+
const builderName = await context.getBuilderNameForTarget(normalizedOptions.buildTarget);
6160

6261
// Extract messages based on configured builder
6362
let extractionResult;

0 commit comments

Comments
 (0)