Skip to content

Commit 977654a

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.
1 parent a39a331 commit 977654a

File tree

1 file changed

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

1 file changed

+2
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,12 @@ export default class AddCommandModule
511511
// Avoid fully resolving the package version from the registry again in later steps
512512
if (context.packageIdentifier.registry) {
513513
assert(context.packageIdentifier.name, 'Registry package identifier must have a name');
514+
const isExactVersion = context.packageIdentifier.type === 'version';
514515
context.packageIdentifier = npa.resolve(
515516
context.packageIdentifier.name,
516517
// `save-prefix` option is ignored by some package managers so the caret is needed to ensure
517518
// that the value in the project package.json is correct.
518-
'^' + manifest.version,
519+
(isExactVersion ? '' : '^') + manifest.version,
519520
);
520521
}
521522

0 commit comments

Comments
 (0)