Skip to content

Commit d7123ad

Browse files
committed
feat(@angular-devkit/build-angular): add deployUrl to application builder
This commit adds the deployUrl option ot the application builder. Closes #26411
1 parent 5759cde commit d7123ad

File tree

7 files changed

+91
-40
lines changed

7 files changed

+91
-40
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface ApplicationBuilderOptions {
3636
[key: string]: string;
3737
};
3838
deleteOutputPath?: boolean;
39+
deployUrl?: string;
3940
externalDependencies?: string[];
4041
extractLicenses?: boolean;
4142
fileReplacements?: FileReplacement_2[];
@@ -94,7 +95,6 @@ export interface BrowserBuilderOptions {
9495
commonChunk?: boolean;
9596
crossOrigin?: CrossOrigin;
9697
deleteOutputPath?: boolean;
97-
// @deprecated
9898
deployUrl?: string;
9999
extractLicenses?: boolean;
100100
fileReplacements?: FileReplacement[];

packages/angular_devkit/build_angular/src/builders/application/options.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ interface InternalOptions {
6565
* This is only used by the development server which currently only supports a single locale per build.
6666
*/
6767
forceI18nFlatOutput?: boolean;
68-
69-
/**
70-
* Allows for usage of the deprecated `deployUrl` option with the compatibility builder `browser-esbuild`.
71-
*/
72-
deployUrl?: string;
7368
}
7469

7570
/** Full set of options for `application` builder. */
@@ -345,7 +340,7 @@ export async function normalizeOptions(
345340
i18nOptions,
346341
namedChunks,
347342
budgets: budgets?.length ? budgets : undefined,
348-
publicPath: deployUrl ? deployUrl : undefined,
343+
publicPath: deployUrl,
349344
plugins: extensions?.codePlugins?.length ? extensions?.codePlugins : undefined,
350345
loaderExtensions,
351346
jsonLogs: useJSONBuildLogs,

packages/angular_devkit/build_angular/src/builders/application/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
"type": "string",
3434
"description": "The full path for the TypeScript configuration file, relative to the current workspace."
3535
},
36+
"deployUrl": {
37+
"type": "string",
38+
"description": "URL where files will be deployed."
39+
},
3640
"scripts": {
3741
"description": "Global scripts to be included in the build.",
3842
"type": "array",
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import { buildApplication } from '../../index';
10+
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup';
11+
12+
describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
13+
describe('Option: "deployUrl"', () => {
14+
beforeEach(async () => {
15+
// Application code is not needed for asset tests
16+
await harness.writeFile('src/main.ts', 'console.log("TEST");');
17+
18+
// Add a global stylesheet to test link elements
19+
await harness.writeFile('src/styles.css', '/* Global styles */');
20+
21+
// Reduce the input index HTML to a single line to simplify comparing
22+
await harness.writeFile(
23+
'src/index.html',
24+
'<html><head><base href="/"></head><body><app-root></app-root></body></html>',
25+
);
26+
});
27+
28+
it('should update script src and link href attributes when option is set to relative URL', async () => {
29+
harness.useTarget('build', {
30+
...BASE_OPTIONS,
31+
styles: ['src/styles.css'],
32+
deployUrl: 'deployUrl/',
33+
});
34+
35+
const { result } = await harness.executeOnce();
36+
expect(result?.success).toBe(true);
37+
harness
38+
.expectFile('dist/browser/index.html')
39+
.content.toEqual(
40+
`<html><head><base href="/"><link rel="stylesheet" href="deployUrl/styles.css"></head>` +
41+
`<body><app-root></app-root>` +
42+
`<script src="deployUrl/main.js" type="module"></script></body></html>`,
43+
);
44+
});
45+
46+
it('should update script src and link href attributes when option is set to absolute URL', async () => {
47+
harness.useTarget('build', {
48+
...BASE_OPTIONS,
49+
styles: ['src/styles.css'],
50+
deployUrl: 'https://example.com/some/path/',
51+
});
52+
53+
const { result } = await harness.executeOnce();
54+
expect(result?.success).toBe(true);
55+
harness
56+
.expectFile('dist/browser/index.html')
57+
.content.toEqual(
58+
`<html><head><base href="/"><link rel="stylesheet" href="https://example.com/some/path/styles.css"></head>` +
59+
`<body><app-root></app-root>` +
60+
`<script src="https://example.com/some/path/main.js" type="module"></script></body></html>`,
61+
);
62+
});
63+
64+
it('should update dynamic import statements when option is set', async () => {
65+
harness.useTarget('build', {
66+
...BASE_OPTIONS,
67+
styles: ['src/styles.css'],
68+
deployUrl: 'https://example.com/some/path/',
69+
namedChunks: true,
70+
});
71+
72+
await harness.writeFile('src/main.ts', 'console.log("TEST");\nimport("./a");\nexport {}');
73+
await harness.writeFile('src/a.ts', 'console.log("A");\nexport {}');
74+
75+
const { result } = await harness.executeOnce();
76+
expect(result?.success).toBe(true);
77+
harness
78+
.expectFile('dist/browser/main.js')
79+
.content.toContain('import("https://example.com/some/path/a');
80+
});
81+
});
82+
});

packages/angular_devkit/build_angular/src/builders/browser-esbuild/schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@
277277
},
278278
"deployUrl": {
279279
"type": "string",
280-
"description": "URL where files will be deployed.",
281-
"x-deprecated": "Use \"baseHref\" option, \"APP_BASE_HREF\" DI token or a combination of both instead. For more information, see https://angular.io/guide/deployment#the-deploy-url."
280+
"description": "URL where files will be deployed."
282281
},
283282
"verbose": {
284283
"type": "boolean",

packages/angular_devkit/build_angular/src/builders/browser/schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@
270270
},
271271
"deployUrl": {
272272
"type": "string",
273-
"description": "URL where files will be deployed.",
274-
"x-deprecated": "Use \"baseHref\" option, \"APP_BASE_HREF\" DI token or a combination of both instead. For more information, see https://angular.io/guide/deployment#the-deploy-url."
273+
"description": "URL where files will be deployed."
275274
},
276275
"verbose": {
277276
"type": "boolean",

packages/schematics/angular/migrations/update-17/use-application-builder.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
*/
88

99
import { workspaces } from '@angular-devkit/core';
10-
import {
11-
Rule,
12-
SchematicContext,
13-
SchematicsException,
14-
chain,
15-
externalSchematic,
16-
} from '@angular-devkit/schematics';
10+
import { Rule, SchematicsException, chain, externalSchematic } from '@angular-devkit/schematics';
1711
import { dirname, join } from 'node:path/posix';
1812
import { JSONFile } from '../../utility/json-file';
1913
import { TreeWorkspaceHost, allTargetOptions, getWorkspace } from '../../utility/workspace';
@@ -52,11 +46,6 @@ export default function (): Rule {
5246
const hasServerTarget = project.targets.has('server');
5347

5448
for (const [, options] of allTargetOptions(buildTarget, false)) {
55-
// Show warnings for using no longer supported options
56-
if (usesNoLongerSupportedOptions(options, context, name)) {
57-
continue;
58-
}
59-
6049
if (options['index'] === '') {
6150
options['index'] = false;
6251
}
@@ -102,7 +91,6 @@ export default function (): Rule {
10291
}
10392

10493
// Delete removed options
105-
delete options['deployUrl'];
10694
delete options['vendorChunk'];
10795
delete options['commonChunk'];
10896
delete options['resourcesOutputPath'];
@@ -204,19 +192,3 @@ export default function (): Rule {
204192
return chain(rules);
205193
};
206194
}
207-
208-
function usesNoLongerSupportedOptions(
209-
{ deployUrl, resourcesOutputPath }: Record<string, unknown>,
210-
context: SchematicContext,
211-
projectName: string,
212-
): boolean {
213-
let hasUsage = false;
214-
if (typeof deployUrl === 'string') {
215-
hasUsage = true;
216-
context.logger.warn(
217-
`Skipping migration for project "${projectName}". "deployUrl" option is not available in the application builder.`,
218-
);
219-
}
220-
221-
return hasUsage;
222-
}

0 commit comments

Comments
 (0)