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

Move eslint to a peer dependency #52

Merged
merged 4 commits into from
Oct 15, 2018
Merged

Move eslint to a peer dependency #52

merged 4 commits into from
Oct 15, 2018

Conversation

IanVS
Copy link
Owner

@IanVS IanVS commented Oct 14, 2018

Fixes #40
Closes #50

This package has always bundled eslint as a dependency because I wanted it to be easy to get up and running. The more-proper thing to do is to specify eslint as a peer dependency. Even though peer dependencies can be a bit confusing, I think it's likely that users of this package will generally already have eslint installed, and it makes a lot of sense to use their version, instead of bundling our own.

IanVS added 3 commits October 13, 2018 21:24
Users will need to install eslint at some point anyway, and in reality
this tool might be used more often by those who have installed eslint,
and then realized that they have tons of linting errors.  Instead of
bundling our own version of eslint, let’s just use the version they
already have installed.
@@ -37,7 +37,6 @@
},
"dependencies": {
"chalk": "^2.4.1",
"eslint": "^4.2.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that you can make it both a dep and a peer dep, and it’s still easy for users, but the peer dep will prevent conflicts with a higher level eslint.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks for commenting. Honestly, it feels weird for it to be both. Is there any documentation for how exactly the resolution is determined in such a case? Is it simply that eslint will be conditionally installed depending on whether or not an eslint which satisfies the version in peerDependencies is found at the time of eslint-nibble installation? If so, does that work in both yarn and npm?

Copy link
Contributor

Choose a reason for hiding this comment

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

It will be installed if it’s not already in the tree and requireable; if it results in a duplicate, the one up the tree will fail the peer dep requirement.

I’m not sure how it works in yarn, but how it works in npm is the standard, so if it doesn’t work in yarn, yarn is broken :-)

package.json Outdated
@@ -37,7 +37,7 @@
},
"dependencies": {
"chalk": "^2.4.1",
"eslint": "^4.2.0",
"eslint": "^5.7.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

You’ll want the dep and peer dep range to be identical - as is, eslint 4 users will always get a conflict.

@IanVS IanVS force-pushed the 40-eslint-peer-dep branch 2 times, most recently from cb9f058 to 53adabb Compare October 15, 2018 02:53
@IanVS
Copy link
Owner Author

IanVS commented Oct 15, 2018

I took eslint back out of dependencies for a few reasons:

  • I think it's reasonable to expect users to install their own eslint. After all, they're planning to use eslint, which is why they're turning to this tool, to help them out.
  • Including a package in both dependencies and peerDependencies feels very non-standard and opens us up to bugs or inconsistencies in how package managers choose to behave, which brings us to:
  • Yarn doesn't seem to behave nicely in this case. After having installed eslint with npm, trying to install eslint-nibble with yarn was throwing fatal errors. I wiped everything out, installed eslint@4 with yarn, and then installed eslint-nibble with yarn as well, but it ended up putting [email protected] into eslint-nibble's node_modules. Neither of which is a great outcome.

Hopefully the readme is clear enough for people to know they need eslint to be installed. And if they try to install and run eslint-nibble without having eslint, they'll get errors that pretty clearly tell them they need to install eslint.

All that to say, I'm going to stick with just peerDependencies for now, and if I get a bunch of issues from confused users, I'll re-evaluate.

If no arguments are provided, recent versions of npm will automatically
save the package to `dependencies`, which we don’t want.
@ljharb
Copy link
Contributor

ljharb commented Oct 15, 2018

Up to you; we do it in almost every package we author at airbnb - it works perfectly, as long as any peerDep range always has an identical range in either deps, or devDeps.

If yarn doesn't work with it, I'd file a bug on yarn, but it's fair not to do it if yarn is something that matters to you for some reason.

@IanVS
Copy link
Owner Author

IanVS commented Oct 15, 2018

Thanks for the feedback. Do you have any particular reasons that you think including eslint in dependencies would be an advantage?

The fact that it doesn't work well on yarn is a bummer, but isn't a showstopper on its own. And I could open an issue with them, but it seems similar to yarnpkg/yarn#3951, and I'd wager my issue would be a wontfix for them as well (see also yarnpkg/yarn#4125 (comment)).

Aside from all that, using plain peer dependency has an advantage in simplicity. I'll be able to say, "'eslint-nibble' uses the version of eslint you have already installed in your project." without the complexity of figuring out whether this package installed its own version or not.

@ljharb
Copy link
Contributor

ljharb commented Oct 15, 2018

npm already handles that complexity - by adding it as a dep, someone without eslint installed at all can use your package without any additional work, but for someone who already has a compatible eslint installed, eslint-nibble will happily use that one.

In the event of someone having eslint 3, or eslint 6, npm ls or npm ls -g will print out an error, and they'll hopefully be able to address it.

@IanVS
Copy link
Owner Author

IanVS commented Oct 15, 2018

someone without eslint installed at all can use your package without any additional work

That's true, but they'd also need to create an eslint config file for this tool to do any good, and for that, they'd need to know what version of eslint would be used, since config files have changed between many of the major versions. Yes they could use npm ls eslint to figure it out, but now we've taken something that was supposed to be easy, and made it more complicated again.

I'm sure that using the hybrid approach you suggested works great in a lot of cases. I'm just not convinced it's the right thing for this project. But thanks again for the suggestion and discussion!

@IanVS IanVS merged commit aad0929 into master Oct 15, 2018
@IanVS IanVS deleted the 40-eslint-peer-dep branch October 15, 2018 03:30
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.

2 participants