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 incorrect autofix for nested dependency #299

Merged
merged 3 commits into from
Jan 8, 2022

Conversation

tamslinn
Copy link
Contributor

@tamslinn tamslinn commented Jan 8, 2022

I discovered a bug when fixing dependencies with a slash in the name (e.g. @types/jest) - rather than updating them in place, it was adding properties in the format "devDependencies.@types/jest": "^27.0.2",

This PR fixes the issue. I had to upgrade the edit-json-file dependency to enable supplying options to set. Unfortunately typescript complains because @types/edit-json-file has not been updated to cover the new 3rd argument to set

I also updated a test to cover the bug which is being fixed.

@bmish
Copy link
Owner

bmish commented Jan 8, 2022

Thanks! Can you fix the lint errors?

UPDATE: fixed for you

@bmish bmish added the bug Something isn't working label Jan 8, 2022
fixedVersion
fixedVersion,
// @ts-ignore (@types/edit-json-file not available for 1.7)
{ preservePaths: false }
Copy link
Owner

@bmish bmish Jan 8, 2022

Choose a reason for hiding this comment

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

Can you add a comment to this line explaining what problem this preservePaths option fixes and how it fixes it?

UPDATE: merging now but maybe you can reply to this comment to explain it better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @bmish , sorry I didn't explain it very well. If I ran --fix and the dependency name had a slash in, the resulting package.json had a new entry outside of dependencies, which looked like this:

"dependencies: { ... },
"devDependencies": { ... },
"devDependencies.@types/jest": "^27.0.2",

The fix itself is a setting which is supplied to the set-value library, which is a dependency of edit-json-file, that you are using in your tool. You can see the doc for the preservePaths option here: https://github.com/jonschlinkert/set-value#optionspreservepaths - without this setting it assumes that if the property includes a /, it must be a url, so shouldn't be split even on dots. If that makes sense! It took me a while to track down.

Thanks for accepting the PR.

Copy link
Owner

Choose a reason for hiding this comment

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

That's pretty obscure, great find!

@bmish bmish changed the title Fix bug when fixing dependencies with slashes in name Fix incorrect autofix for nested dependency Jan 8, 2022
@bmish bmish merged commit 87dd6f9 into bmish:master Jan 8, 2022
@bmish
Copy link
Owner

bmish commented Jan 11, 2022

Thanks! Released in v1.5.0.

@bmish
Copy link
Owner

bmish commented Jan 11, 2022

@tamslinn I'm adding the missing TypeScript type for this to @types/edit-json-file so we can clean this up: DefinitelyTyped/DefinitelyTyped#58125

And use this: #313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants