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
Change Request: Allow to patch ModuleResolver in ESLint 8 #15036
Comments
I support this. We generally don't support or encourage patching, but I wouldn't mind this small change on |
If all that’s needed is to change the Rollup config, I’m fine with that.
What is “something” here? A lint rule? A convention? |
I didn't have anything specific in mind, I just know that Rollup is smart and if you do an I can make a PR for the Rollup config, and check that second part as well |
We could add tests that replace |
This all feels a bit too hacky for my taste. Bending over backwards to support monkey patching doesn’t seem like the right solution here. I’d like us to take a step back and think this through a bit more. My understanding is that you are monkey patching ModuleResolver.resolve so that when ESLint uses it, it’s using the patched version rather than the default, is that correct? And you’re using ESLint via the JS API and not from the CLI? If that’s the case, adding a resolve option to the ESLint class constructor feels like the most appropriate approach to support this use case. It would go away with the new config system, but so will a bunch of other options we currently have. |
I agree that it's a bit hackish and having a proper solution would be much easier to handle. Yes your understanding is correct. Adding a resolve option to the ESLint class constructor would already fix 80% of my use case, that would be great. |
Is it feasible to use the There's definitely not a clean solution for the CLI use case as far as I can tell. |
Not perfect, but I can live with it I agree, I don't see a clean way to do it in the CLI either, other than passing an absolute path to a JS module but only automated tools would be able to use it correctly |
@eslint/eslint-tsc do we feel comfortable adding a resolve option to the ESLint class for this? |
Since it’d be temporary, and it’s less hacky than alternative solutions, I’m okay with it. |
I have concerns that this won't work for the other mentioned patch So we might end up with adding a new option on the public API and un-freezing
An alternative that wouldn't require |
I’m just not onboard with the monkey patching approach. This feels very, very fragile, and the folks who are already monkey patching should know that. Perpetuating that seems like a bad idea. I don’t think our goal here should be to support every hack that’s currently out there, but rather, come up with an approach that we can live with. If adding a new option solves most but not all of the problems, I think that’s where we should start. And anything we do to address this is temporary and likely will be obsolete in the next year, so I don’t think we should spend too much brainpower here. |
We don't support hacks but we're adding to our main ESLint API an option whose only purpose is to hack into ESLint's internal logic, and the option can solve only a small subset of problems that would be solved by unlocking one property on our legacy API. This doesn't make sense to me, but I won't block it. |
I don’t find this type of comment productive. We shouldn’t be thinking in terms of blocking anything. We should be thinking in terms of how to satisfy use cases in a way that we all can live with.
I don’t understand this argument. All of the options to the ESLint class change internal logic. Fundamentally, we are dealing with a messy situation where packages are modifying APIs that they shouldn’t be modifying to force ESLint to behave in a way it was never intended to behave. My main concern with unfreezing the API is this:
This feels like a constraint that is difficult to guarantee. However, given that the folks who are doing this are in a “void your warranty” situation, I’d be open to dropping this constraint in favor of letting the monkey-patchers submit PRs to fix anything that might break. I don’t want to be making guarantees that this approach will never break, but if they are willing to shoulder some of the maintenance cost, I’m open to unfreezing the API. |
I'll try to better explain my view on this option. The interface is |
I'm sympathetic to the argument that the |
@mdjermanovic thanks for explaining. I guess my point is that all of the options are fragile in some way, and I find explicit approaches to be favorable to implicit approaches in that case. @btmills I really don’t want to be changing existing internal APIs related to eslintrc at this point. The whole thing is a house of cards as it is. My main goal at this point is to find something that works until we can get to the new config system. If the path of least resistance right now is to unfreeze the resolve method, then let’s do that. I just want to be clear that this is in no way an officially supported feature and if it breaks in some other way in the future, we aren’t going to spend time fixing it. Fair? |
As I understand it, un-freezing |
No, but I’m not sure that’s needed. I don’t believe ConfigArrayFactory.prototype is frozen. |
ESLint version
8.0.0-beta.1
What problem do you want to solve?
In the current version of ESLint, it's currently not possible to have plugins as dependencies in shared configs (as detailed in #3458)
It is however possible to patch
ModuleResolver
to make this work :The patch isn't anything fancy:
https://github.com/swissquote/crafty/blob/master/packages/crafty-preset-eslint/src/patchModuleResolver.js#L78-L95
But it works better than
--resolve-plugins-relative-to
since it allows to have logic for more than one directory and doesn't require the end-user to add it to each of his calls toeslint
Now since this patching accesses the modules directly at their location inside the
eslint
or@eslint/eslintrc
package it won't be possible anymore asexports
inpackage.json
@eslint/eslintrc
is bundled so we can't refer to a module directlyObject.freeze
thus effectively blockingrequire("@eslint/eslintrc").Legacy.ModuleResolver.resolve = someNewResolver
resolve
function so it wouldn't take the patch into consideration anyway. ( Fix: ConfigArrayFactory was ignoring the resolver option in some places eslintrc#53 (comment) )What do you think is the correct solution?
The easiest solution I would see and was proposed by @mdjermanovic : disable the freezing of objects by Rollup : eslint/eslintrc#53 (comment)
That would need to be combined with something that makes sure to not refer to the function directly but to refer to the
ModuleResolver
object so that the patching works.This summary is a follow up of the discussion in eslint/eslintrc#53
Participation
The text was updated successfully, but these errors were encountered: