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

fix: check if dependencies & devDependencies exist before deleting dep #30224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GrandSchtroumpf
Copy link

@GrandSchtroumpf GrandSchtroumpf commented Feb 28, 2025

Current Behavior

removeDependenciesFromPackageJson tries to delete dep from undefined if there is no dependencies or devDependencies in package.json

Expected Behavior

First check if dependencies or devDependencies exists

Related Issue(s)

Fixes #30222

@GrandSchtroumpf GrandSchtroumpf requested a review from a team as a code owner February 28, 2025 15:09
Copy link

vercel bot commented Feb 28, 2025

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

Name Status Preview Updated (UTC)
nx-dev 🔄 Building (Inspect) Visit Preview Feb 28, 2025 3:09pm

@samir-ajdarpasic
Copy link

@GrandSchtroumpf I think the linked issue is not the correct one.

@GrandSchtroumpf
Copy link
Author

@samir-ajdarpasic I have updated thx

for (const dep of dependencies) {
delete json.dependencies[dep];
}
json.dependencies = sortObjectByKeys(json.dependencies);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are improving this code if there are no dependencies we could also remove the dependencies instead of attempting to sort it.

for (const devDep of devDependencies) {
delete json.devDependencies[devDep];
}
json.devDependencies = sortObjectByKeys(json.devDependencies);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

removeDependenciesFromPackageJson: Ensure dependencies field exist
3 participants