Skip to content

refactor(ng-add): inserted version should align with other Angular dependencies #13704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/cdk/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ export const cdkVersion = loadPackageVersionGracefully('@angular/cdk');
/**
* Schematic factory entry-point for the `ng-add` schematic. The ng-add schematic will be
* automatically executed if developers run `ng add @angular/cdk`.
*
* By default, the CLI already installs the package that has been specified with `ng add`.
* We just store the version in the `package.json` in case the package manager didn't. Also
* this ensures that there will be no error that says that the CDK does not support `ng add`.
*/
export default function(): Rule {
return (host: Tree) => {
// By default, the CLI already installs the package that has been installed through `ng add`.
// We just store the version in the `package.json` in case the package manager didn't.
addPackageToPackageJson(host, '@angular/cdk', `^${cdkVersion}`);
// In order to align the CDK version with the other Angular dependencies, we use tilde
// instead of caret. This is default for Angular dependencies in new CLI projects.
addPackageToPackageJson(host, '@angular/cdk', `~${cdkVersion}`);
};
}

Expand Down
6 changes: 4 additions & 2 deletions src/lib/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export default function(options: Schema): Rule {
// have the same version tag if possible.
const ngCoreVersionTag = getPackageVersionFromPackageJson(host, '@angular/core');

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

Expand Down