Skip to content

Commit 3cabf78

Browse files
devversionmmalerba
authored andcommitted
refactor(ng-add): inserted version should align with other Angular dependencies. (#13704)
In favor of consistency, the versions that will be inserted when running `ng-add`, should be aligned with the default Angular dependencies in a new CLI project. This means that we should not provide the version with a leading caret because that means that NPM can automatically/ and magically update to the most recent minor version. This shouldn't cause any problems but is just not in sync with other Angular dependencies. All other Angular dependencies (e.g. `@angular/core') will be installed with a leading tilde. This means that it can only happen that NPM automatically updates to the most recent patch release. We should do the same in order to be consistent.
1 parent e6a25f4 commit 3cabf78

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/cdk/schematics/ng-add/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ export const cdkVersion = loadPackageVersionGracefully('@angular/cdk');
1515
/**
1616
* Schematic factory entry-point for the `ng-add` schematic. The ng-add schematic will be
1717
* automatically executed if developers run `ng add @angular/cdk`.
18+
*
19+
* By default, the CLI already installs the package that has been specified with `ng add`.
20+
* We just store the version in the `package.json` in case the package manager didn't. Also
21+
* this ensures that there will be no error that says that the CDK does not support `ng add`.
1822
*/
1923
export default function(): Rule {
2024
return (host: Tree) => {
21-
// By default, the CLI already installs the package that has been installed through `ng add`.
22-
// We just store the version in the `package.json` in case the package manager didn't.
23-
addPackageToPackageJson(host, '@angular/cdk', `^${cdkVersion}`);
25+
// In order to align the CDK version with the other Angular dependencies, we use tilde
26+
// instead of caret. This is default for Angular dependencies in new CLI projects.
27+
addPackageToPackageJson(host, '@angular/cdk', `~${cdkVersion}`);
2428
};
2529
}
2630

src/lib/schematics/ng-add/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ export default function(options: Schema): Rule {
2626
// have the same version tag if possible.
2727
const ngCoreVersionTag = getPackageVersionFromPackageJson(host, '@angular/core');
2828

29-
addPackageToPackageJson(host, '@angular/cdk', `^${materialVersion}`);
30-
addPackageToPackageJson(host, '@angular/material', `^${materialVersion}`);
29+
// In order to align the Material and CDK version with the other Angular dependencies,
30+
// we use tilde instead of caret. This is default for Angular dependencies in new CLI projects.
31+
addPackageToPackageJson(host, '@angular/cdk', `~${materialVersion}`);
32+
addPackageToPackageJson(host, '@angular/material', `~${materialVersion}`);
3133
addPackageToPackageJson(host, '@angular/animations',
3234
ngCoreVersionTag || requiredAngularVersionRange);
3335

0 commit comments

Comments
 (0)