Skip to content

Commit d2f2098

Browse files
committed
fix(@angular/cli): preserve exact version in ng add when requested
The `ng add` command would previously always add a caret (`^`) prefix to the resolved package version, even if the user explicitly requested an exact version. This change ensures that the exact version is preserved in the package identifier if requested, while maintaining the caret prefix for general requests to ensure consistent behavior with package managers. (cherry picked from commit b5fb457)
1 parent 3af71f9 commit d2f2098

File tree

1 file changed

+3
-1
lines changed
  • packages/angular/cli/src/commands/add

1 file changed

+3
-1
lines changed

packages/angular/cli/src/commands/add/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ interface AddCommandArgs extends SchematicsCommandArgs {
4444

4545
interface AddCommandTaskContext {
4646
packageIdentifier: npa.Result;
47+
isExactVersion: boolean;
4748
savePackage?: NgAddSaveDependency;
4849
collectionName?: string;
4950
executeSchematic: AddCommandModule['executeSchematic'];
@@ -185,6 +186,7 @@ export default class AddCommandModule
185186

186187
const taskContext = {
187188
packageIdentifier,
189+
isExactVersion: packageIdentifier.type === 'version',
188190
executeSchematic: this.executeSchematic.bind(this),
189191
getPeerDependencyConflicts: this.getPeerDependencyConflicts.bind(this),
190192
dryRun: options.dryRun,
@@ -512,7 +514,7 @@ export default class AddCommandModule
512514
context.packageIdentifier.name,
513515
// `save-prefix` option is ignored by some package managers so the caret is needed to ensure
514516
// that the value in the project package.json is correct.
515-
'^' + manifest.version,
517+
(context.isExactVersion ? '' : '^') + manifest.version,
516518
);
517519
}
518520

0 commit comments

Comments
 (0)