Skip to content
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

feat(devkit): add a flag to keep existing versions when calling addDependenciesToPackageJson #21123

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

jaysoo
Copy link
Member

@jaysoo jaysoo commented Jan 12, 2024

This PR adds a flag to addDependenciesToPackageJson function in devkit to prevent versions from being bumped. This will be used in init generators since using nx init and nx add should not bump versions and risk breaking existing projects.

Example:

If existing package.json already has [email protected], then calling this function:

addDependenciesToPackageJson(
  tree,
  {
    next: '~14.0.0'
  {},
  undefined,
  true // keepExistingVersions
);

Will leave next at existing version of 13.4.0.

Notes

  • There was discussion on converting the args to accept an options object, but this will break existing usages with signature addDependenciesToPackageJson(tree, {...}, {...}, customPackageJsonPath), unless we do function overrides.

Copy link

vercel bot commented Jan 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview Jan 16, 2024 6:40pm

@@ -227,12 +240,24 @@ function removeLowerVersions(
) {
return Object.keys(incomingDeps).reduce((acc, d) => {
if (
existingDeps?.[d] &&
!isIncomingVersionGreater(incomingDeps[d], existingDeps[d])
!existingDeps?.[d] ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not imagine this function should change at all in this change.

@jaysoo jaysoo force-pushed the feat/add-deps-enhancement branch from b31bbc2 to 7e27411 Compare January 15, 2024 19:06
@jaysoo jaysoo force-pushed the feat/add-deps-enhancement branch from c570219 to 4fa2cb2 Compare January 16, 2024 18:32
@jaysoo jaysoo enabled auto-merge (squash) January 16, 2024 18:37
@jaysoo jaysoo merged commit 253c0ff into nrwl:master Jan 16, 2024
6 checks passed
@jaysoo jaysoo deleted the feat/add-deps-enhancement branch January 16, 2024 19:48
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants