fix(@angular/cli): skip CLI version check for migrate-only updates#32942
fix(@angular/cli): skip CLI version check for migrate-only updates#32942maruthang wants to merge 2 commits intoangular:mainfrom
Conversation
The dev server was ignoring the `sourceMap` configuration from angular.json, always injecting inline source maps into all served files. This affected both CSS (hardcoded `devSourcemap: true`) and JavaScript (prebundle transformer hardcoded `sourcemap: true`), causing 2-3x file size inflation even when source maps were explicitly disabled. The fix passes the normalized `scripts` and `styles` source map settings through to the Vite configuration, so that `css.devSourcemap` and the prebundle transformer respect the user's `sourceMap` setting. Closes angular#31331
When running `ng update @angular/cli --name=use-application-builder`, the CLI would fetch and install the latest version (e.g., v20) as a temporary CLI to perform the update, even though migrate-only mode operates on the currently installed package version. This caused incompatible packages to be installed (e.g., @angular/build@20 on an Angular 18/19 project). The fix skips the CLI version check when in migrate-only mode (--name or --migrate-only), since migrations run against the installed version and don't need a different CLI version. Closes angular#30696
There was a problem hiding this comment.
Code Review
This pull request introduces granular sourcemap configuration for the Vite dev server, specifically adding support for style sourcemaps, and updates the ng update command to skip version checks during migrate-only operations. Feedback indicates that the current implementation might inadvertently disable CSS sourcemaps by default, which would be a regression in developer experience. Additionally, it was noted that the JavaScriptTransformer for third-party dependencies should use the thirdPartySourcemaps setting instead of scriptsSourcemaps to ensure logical consistency and maintain existing behavior for prebundled files.
| const { | ||
| vendor: thirdPartySourcemaps, | ||
| scripts: scriptsSourcemaps, | ||
| styles: stylesSourcemaps, | ||
| } = normalizeSourceMaps(browserOptions.sourceMap ?? false); |
There was a problem hiding this comment.
Defaulting sourceMap to false here (via ?? false) causes stylesSourcemaps to be false by default. Since stylesSourcemaps is now used to control devSourcemap in the Vite server (which was previously hardcoded to true), this change disables CSS sourcemaps by default in ng serve. To maintain the existing developer experience where CSS sourcemaps are enabled by default even if not explicitly configured in the build options, consider using a default that preserves this behavior for styles.
| const { | |
| vendor: thirdPartySourcemaps, | |
| scripts: scriptsSourcemaps, | |
| styles: stylesSourcemaps, | |
| } = normalizeSourceMaps(browserOptions.sourceMap ?? false); | |
| const { | |
| vendor: thirdPartySourcemaps, | |
| scripts: scriptsSourcemaps, | |
| styles: stylesSourcemaps, | |
| } = normalizeSourceMaps(browserOptions.sourceMap ?? { styles: true }); |
References
- When refactoring code that handles configuration properties, ensure that any implicit type validation previously performed is still maintained, especially if the configuration is guaranteed to be type-safe by an upstream process.
| // In a development environment the additional scope information does not | ||
| // have a negative effect unlike production where final output size is relevant. | ||
| { sourcemap: true, jit: true, thirdPartySourcemaps }, | ||
| { sourcemap: scriptsSourcemaps, jit: true, thirdPartySourcemaps }, |
There was a problem hiding this comment.
The JavaScriptTransformer created here is specifically intended for prebundling third-party dependencies (as noted in the comment on line 186). Using scriptsSourcemaps (which corresponds to the application's script sourcemap setting) as the primary sourcemap toggle is logically incorrect for this purpose; it should use thirdPartySourcemaps to correctly respect the configuration for dependencies. Additionally, changing this from a hardcoded true to a variable that defaults to false (when sourceMap is undefined) disables sourcemaps for prebundled files by default, which is a regression in the development experience.
| { sourcemap: scriptsSourcemaps, jit: true, thirdPartySourcemaps }, | |
| { sourcemap: thirdPartySourcemaps, jit: true, thirdPartySourcemaps }, |
References
- When refactoring code that handles configuration properties, ensure that any implicit type validation previously performed is still maintained, especially if the configuration is guaranteed to be type-safe by an upstream process.
Summary
ng update @angular/cli --name=use-application-builder, the CLI fetched and installed the latest version (e.g., v20) as a temporary CLI, even though migrate-only mode operates on the currently installed package version@angular/build@20on an Angular 18/19 project)!options.migrateOnlyto the CLI version check condition, skipping it when using--nameor--migrate-onlysince migrations run against the installed versionCloses #30696
Test plan
ng update @angular/cli --name=use-application-builderon an Angular 19 project — should use the installed CLI, not fetch latestng update @angular/cli(without --name) — should still check for newer CLI version as beforeng update @angular/cli --migrate-only— should skip CLI version check