-
-
Notifications
You must be signed in to change notification settings - Fork 43
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: ConfigArrayFactory was ignoring the resolver option in some places #53
Conversation
|
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.
Nice catch! Can you add some tests to verify this change?
Sure no problem. I don't know how extensively I have to test this, I went for a simple happy case test for parser, plugin and extends. A regression in those tests would catch that the custom resolver isn't used anymore. All other tests already cover all other cases from the existing methods. |
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.
LGTM. Thanks! Just need another review before merging.
@onigoetz can you please elaborate more on this, is there something that doesn't work well in ESLint 8 Beta because of this issue? |
I'm not sure why |
Hi @mdjermanovic. to answer your question, yes there is something that doesn't work well with ESLint 8 beta. It's related to the loading of plugins when they aren't declared as dependencies from the main package.json : There was a workaround : https://github.com/microsoft/rushstack/tree/master/stack/eslint-patch I experimented with the idea of having a custom resolver : Along with a new I wanted to land this PR first before starting to open a discussion on ESLint on the possibility to do this but then ... well, life happened :) Where would you recommend me opening the discussion on ESLint's side ? and who should I involve ? But since that isn't planned for now, we would need an escape hatch before the future configuration model lands ( eslint/rfcs#9 / eslint/eslint#13481 ) Another possibility : add a special What do you think of this ? |
@mdjermanovic we have this because I was having trouble resolving some modules from the eslint repo. It turned out to be something else, but I did design these constructors to accept a resolver option. Given that, I think it should work. :) @onigoetz please keep in mind that this is not an officially supported API. It is intended only for use within ESLint, so it’s not recommended to rely on. Additionally, we will be moving away from using this config system in the future, so you’ll likely need to change what you’re doing when that happens. |
@nzakas Thanks for the clarifications, yes I totally understand that these APIs are internal and shouldn't be relied upon. I also know that a future configuration system will replace this. However, the current workaround won't work anymore and the future configuration system isn't ready yet, which creates a gap for all users who would want (need?) this feature (quite a few according to the number of subscriptions in the issues listed in RFC 9) and means all these users will have to skip ESLint 8 for the time being. |
I think this can work with ESLint 8, the objects it needs are available in the main export. e.g. |
Yes, but I'm trying to modify the |
I understand that you have a different use case, my note was about the patch you linked to with concerns that it can't work with ESLint 8 - I think it can work by using a different way to access the objects it wants to patch. |
Yes, it's possible to retrive or use the ModuleResolver using this method:
But as And since my patch would be |
You're right, we're re-exporting a namespace object and rollup by default freezes it. Okay, I'm not opposed to this change if it will help (though, I'm not sure how, it seems that it would be more helpful if we would un-freeze the |
If your concerns are that https://github.com/microsoft/rushstack/tree/master/stack/eslint-patch (or its copies) will stop working, we can discuss that. I'm not sure if this fix helps since it's unlikely that we'll add a |
I understand.
Yes I would like to discuss this, where can we continue this discussions? |
@onigoetz by looking at modern-module-resolution.ts and patchModuleResolver.js, I believe the only blocker for supporting ESLint 8 is the fact that @nzakas would you agree with that? It seems that packages like |
That would help a lot, one small thing to keep in mind though. When generating the bundle the function references are flattened. so if the input is: import * as ModuleResolver from "./shared/relative-module-resolver.js"
class ConfigArrayFactory {
_loadParser() {
ModuleResolver.resolve(...)
}
}
// ...
const Legacy = { ModuleResolver };
export { Legacy } Will be bundled as function resolve() {}
const ModuleResolver = Object.freeze({ resolve });
// ...
class ConfigArrayFactory {
_loadParser() {
resolve(...)
}
}
// ...
const Legacy = { ModuleResolver };
export { Legacy } Because of tree shaking and other minification, By merging this PR, the variable would refer to the full ModuleResolver stored in the slot, which is a reference to the original ModuleResolver and thus would allow patching. |
Sorry, this conversation has gone in too many directions for me to follow. Can we merge this and can we open a separate issue to discuss any remaining concerns? |
Good catch! I didn't notice that. |
Agreed, @onigoetz can you please open a new issue to discuss further steps? |
Sure, should I create it in this repository or in eslint/eslint ? |
Yes, it might be the best place. |
Sorry, I misread the question. I think it would be better to discuss this in eslint/eslint |
I have to admit I was confused by the answer but was going to create it in eslint/eslint |
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.
LGTM, thanks!
Hi,
I was experimenting with ESLint 8 Beta and wanted to create a pull-request, but saw that there was an issue when using the
resolver
option onConfigArrayFactory
as it was ignored in some functions.This PR uses the
resolver
in the slot instead ofModuleResolver.resolve