Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces a 'disableHostCheck' option to the dev-server builder, updates the schema to support this change, and adds relevant unit tests. The review feedback highlights opportunities to simplify type definitions by removing redundant assertions and Omit operations, as well as recommendations to improve the robustness of file path resolution in tests by using 'import.meta.url' instead of 'process.cwd()'.
| purgeStaleBuildCache, | ||
| } from './internal'; | ||
| import { normalizeOptions } from './options'; | ||
| import { normalizeOptions, type NormalizedDevServerOptions } from './options'; |
There was a problem hiding this comment.
| const normalizedOptions = (await normalizeOptions( | ||
| context, | ||
| projectName, | ||
| initialOptions, | ||
| )) as NormalizedDevServerOptions; |
There was a problem hiding this comment.
The type assertion as NormalizedDevServerOptions is redundant here. The return type of normalizeOptions is already fully compatible with NormalizedDevServerOptions (since strictPort: boolean is assignable to strictPort?: boolean and allowedHosts matches exactly). Removing this assertion simplifies the code and avoids potential future type-safety issues if the types diverge.
| const normalizedOptions = (await normalizeOptions( | |
| context, | |
| projectName, | |
| initialOptions, | |
| )) as NormalizedDevServerOptions; | |
| const normalizedOptions = await normalizeOptions( | |
| context, | |
| projectName, | |
| initialOptions, | |
| ); |
| export type NormalizedDevServerOptions = Omit< | ||
| Awaited<ReturnType<typeof normalizeOptions>>, | ||
| 'strictPort' | ||
| 'strictPort' | 'allowedHosts' | ||
| > & { | ||
| strictPort?: boolean; | ||
| allowedHosts: true | string[]; | ||
| }; |
There was a problem hiding this comment.
Omitting and re-adding allowedHosts in NormalizedDevServerOptions is redundant because normalizeOptions already returns allowedHosts with the type true | string[]. We can simplify this definition by only omitting and overriding strictPort.
export type NormalizedDevServerOptions = Omit<
Awaited<ReturnType<typeof normalizeOptions>>,
'strictPort'
> & {
strictPort?: boolean;
};| import { readFileSync } from 'node:fs'; | ||
| import path from 'node:path'; |
There was a problem hiding this comment.
| const devServerSchemaPath = path.join( | ||
| process.cwd(), | ||
| '../build/src/builders/dev-server/schema.json', | ||
| ); |
There was a problem hiding this comment.
Using process.cwd() to resolve the schema path is fragile because it depends on the current working directory of the test runner (which can vary between Bazel, local IDE test runners, or running from the workspace root). Using import.meta.url with fileURLToPath is a robust, location-independent way to resolve paths relative to the test file.
const devServerSchemaPath = fileURLToPath(
new URL('../../../../build/src/builders/dev-server/schema.json', import.meta.url),
);eeec444 to
93fcd18
Compare
93fcd18 to
eae16aa
Compare
|
Hi @ant1quar, Thank you for taking the time to contribute to the Angular CLI! Unfortunately, modifying the Because breaking schema changes cannot be accepted at this time in a minor release, we cannot accept this pull request as proposed. Thank you again for your efforts and understanding! |
Summary
@angular/builddev-serverallowedHostsschema to a string array (matching@angular-devkit/build-angular) so the CLI parses--allowed-hosts example.comcorrectly.disableHostCheckand map it to ViteallowedHosts: trueduring option normalization.Fixes #33955
Test plan
pnpm bazel test //packages/angular/cli:test --test_filter="*dev-server schema*"pnpm bazel test //packages/angular/build:dev-server_integration_tests --test_filter="*allowedHosts*|*disableHostCheck*"Made with Cursor