-
-
Notifications
You must be signed in to change notification settings - Fork 175
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 parsing-related dependencies to peer dependencies. #505
Conversation
Codecov Report
@@ Coverage Diff @@
## master #505 +/- ##
===========================================
- Coverage 100.00% 99.07% -0.93%
===========================================
Files 2 2
Lines 262 217 -45
Branches 67 43 -24
===========================================
- Hits 262 215 -47
- Misses 0 2 +2
Continue to review full report at Codecov.
|
All the "extra" parsers should also be marked as optional peer dependencies using |
[fix]: http://eslint.org/docs/user-guide/command-line-interface#fix | ||
[npm]: https://www.npmjs.com/ | ||
[node]: https://nodejs.org | ||
[all-contributors]: https://github.com/kentcdodds/all-contributors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you changed the order of the links
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alphabetized. No real reason for it. Just felt awkward slapping the first-defined links at the end of the list.
Just a quick note on dependencies in npm and my view of it. For this package I don't really think peer dependencies is the way to go because of my understanding of peer deps. If someone don't have prettier or eslint in their project, I want them to just be able to install this project and get the latest supported versions of eslint and prettier automatically. With npm 7+ this will actually be the case when using peer deps as they will be installed automatically unless they're marked as optional. However, my reservation of using peer deps is also based on the fact that this package doesn't produce any exports that are intended to be used by prettier or eslint unlike eslint-config-prettier. So from my understanding peer deps isn't about "bring your own <package>" but more about "I produce something that you will use in <package> so you need to use it in your project". It's a small difference but still a difference. Then a note on the optional dependencies. I don't really see what the problem with using optional dependencies based on your comment in #402. edit: PS. I'll leave this decision up to you as I don't really use this project any longer and is working on a more general way of using multiple linters/formatters together at https://github.com/linterjs, which I don't have time to work on either 🤦 |
I know this project isn't a focus for you, so I appreciate the attention you're giving it for us to get this PR out. I'm no expert on this, so I could totally be wrong, but I really feel like peerDeps is the correct place.
I feel like this is problematic, because we'll be left - as maintainers - to constantly update the shipped parsers.
With every other package manager, this is NOT the case. It was actually a large point of contention: https://twitter.com/housecor/status/1325524945334661121
Aside from my comment in #402, semantically "optionalDependencies" is incorrect.
Our project cannot work without those dependencies. |
This project can work without the ts and vue parser and those were the ones I was suggesting to go in optionalDependencies. |
Oh! I didn't realize. Okay, I agree those are optional, but I feel like we still have it right as-is. Let's say somebody wants to use their own version of |
Nope, it's an optional dependency for this package so this package won't crash and burn if it's not present, if they add it as a (dev)dependency in their project which is using this package, then we'll be able to pick it up and use it too. However I do believe you might need to look over the require logic for those dependencies if you're changing them to be optional (peer) dependencies as the current logic assumes it will be able to import them? |
if (['.ts', '.tsx'].includes(fileExtension)) {
formattingOptions.eslint.parser =
formattingOptions.eslint.parser ||
require.resolve('@typescript-eslint/parser');
}
if (['.vue'].includes(fileExtension)) {
formattingOptions.eslint.parser =
formattingOptions.eslint.parser || require.resolve('vue-eslint-parser');
} I've got nothing on this 😬 You're suggesting this might not work if I move them to optional deps? |
It will try and use any parser that the user provides via options (which might error, but then it's their responsibility) and fallback to using the one we've installed for them, as they're currently not optional, the require.resolve call will throw an error if it's not installed.
From the require.resolve docs. So this would need to be surrounded by a try catch that just ignores the MODULE_NOT_FOUND error. |
6df49c1
to
62a5fab
Compare
Pretty sure the commit that wraps require.resolve with try catch also removes the ability for users to specify their own parser. |
Shit. Duh. Sorry. Fix in the morning. |
Some updated dependency is logging a warning in test:
|
I believe we have a test that does not provide either a filepath or a parser, so prettier logs this warning as it can't use a specific parser or infer the parser based on file extension. Not sure if this is a prettier 1 or 2 warning though and maybe we should remove support for processing without either parser or filepath. |
I think this was supported to allow a new file in an editor, which haven't been saved yet and no syntax selected to be formatted with prettier as if it were a js file |
There's also still something wrong with this PR 🤔 On I like the idea of that breaking change in conjunction with this PR though. |
It's because of missing coverage, and I'm not quite sure how to get those last bits of coverage. Comments in test code. I'll take another stab at this and the breaking change some time later! |
Codecov Report
@@ Coverage Diff @@
## master #505 +/- ##
===========================================
- Coverage 100.00% 99.07% -0.93%
===========================================
Files 2 2
Lines 262 217 -45
Branches 67 43 -24
===========================================
- Hits 262 215 -47
- Misses 0 2 +2
Continue to review full report at Codecov.
|
Stale pull request |
#402