Skip to content

Commit f112a0a

Browse files
committed
refactor(@angular-devkit/build-angular): add warnings for unsupported vite options
This commit adds warnings when using unsupported dev-server options with vite.
1 parent 034639b commit f112a0a

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function execute(
5454
// Determine project name from builder context target
5555
const projectName = context.target?.project;
5656
if (!projectName) {
57-
context.logger.error(`The 'dev-server' builder requires a target to be specified.`);
57+
context.logger.error(`The "dev-server" builder requires a target to be specified.`);
5858

5959
return EMPTY;
6060
}
@@ -65,7 +65,7 @@ export function execute(
6565
if (isEsbuildBased(builderName)) {
6666
if (transforms?.logging || transforms?.webpackConfiguration) {
6767
throw new Error(
68-
'The `application` and `browser-esbuild` builders do not support Webpack transforms.',
68+
`The "application" and "browser-esbuild" builders do not support Webpack transforms.`,
6969
);
7070
}
7171

@@ -76,6 +76,24 @@ export function execute(
7676
);
7777
}
7878

79+
if (options.allowedHosts?.length) {
80+
context.logger.warn(
81+
`The "allowedHost" option will not be used because it is not supported by the "${builderName}" builder.`,
82+
);
83+
}
84+
85+
if (options.publicHost) {
86+
context.logger.warn(
87+
`The "publicHost" option will not be used because it is not supported by the "${builderName}" builder.`,
88+
);
89+
}
90+
91+
if (options.disableHostCheck) {
92+
context.logger.warn(
93+
`The "disableHostCheck" option will not be used because it is not supported by the "${builderName}" builder.`,
94+
);
95+
}
96+
7997
return defer(() => import('./vite-server')).pipe(
8098
switchMap(({ serveWithVite }) =>
8199
serveWithVite(normalizedOptions, builderName, context, transforms, extensions),
@@ -91,11 +109,11 @@ export function execute(
91109
}
92110

93111
if (extensions?.buildPlugins?.length) {
94-
throw new Error('Only the `application` and `browser-esbuild` builders support plugins.');
112+
throw new Error('Only the "application" and "browser-esbuild" builders support plugins.');
95113
}
96114
if (extensions?.middleware?.length) {
97115
throw new Error(
98-
'Only the `application` and `browser-esbuild` builders support middleware.',
116+
'Only the "application" and "browser-esbuild" builders support middleware.',
99117
);
100118
}
101119

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@
6969
},
7070
"publicHost": {
7171
"type": "string",
72-
"description": "The URL that the browser client (or live-reload client, if enabled) should use to connect to the development server. Use for a complex dev server setup, such as one with reverse proxies."
72+
"description": "The URL that the browser client (or live-reload client, if enabled) should use to connect to the development server. Use for a complex dev server setup, such as one with reverse proxies. This option has no effect when using the 'application' or other esbuild-based builders."
7373
},
7474
"allowedHosts": {
7575
"type": "array",
76-
"description": "List of hosts that are allowed to access the dev server.",
76+
"description": "List of hosts that are allowed to access the dev server. This option has no effect when using the 'application' or other esbuild-based builders.",
7777
"default": [],
7878
"items": {
7979
"type": "string"
@@ -85,7 +85,7 @@
8585
},
8686
"disableHostCheck": {
8787
"type": "boolean",
88-
"description": "Don't verify connected clients are part of allowed hosts.",
88+
"description": "Don't verify connected clients are part of allowed hosts. This option has no effect when using the 'application' or other esbuild-based builders.",
8989
"default": false
9090
},
9191
"hmr": {

packages/angular_devkit/build_angular/src/builders/dev-server/tests/options/disable-host-check_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describeServeBuilder(
1717
executeDevServer,
1818
DEV_SERVER_BUILDER_INFO,
1919
(harness, setupTarget, isViteRun) => {
20-
// TODO(fix-vite): currently this is broken in vite.
20+
// This option is not used when using vite.
2121
(isViteRun ? xdescribe : describe)('option: "disableHostCheck"', () => {
2222
beforeEach(async () => {
2323
setupTarget(harness);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describeServeBuilder(
1717
executeDevServer,
1818
DEV_SERVER_BUILDER_INFO,
1919
(harness, setupTarget, isViteRun) => {
20-
// TODO(fix-vite): currently this is broken in vite.
20+
// This option is not used when using vite.
2121
(isViteRun ? xdescribe : describe)('option: "publicHost"', () => {
2222
beforeEach(async () => {
2323
setupTarget(harness);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,6 @@ export async function setupServer(
550550
external: externalMetadata.explicit,
551551
indexHtmlTransformer,
552552
extensionMiddleware,
553-
extraHeaders: serverOptions.headers,
554553
normalizePath,
555554
}),
556555
],

0 commit comments

Comments
 (0)