-
Notifications
You must be signed in to change notification settings - Fork 204
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
Expose resolvePath #194
Expose resolvePath #194
Conversation
Codecov Report
|
I'm adding the docs, will need a review of them. |
Thanks, I'll review this tomorrow. |
Do you think it make sense to expose I'm just saying that because |
Makes sense. Let me sleep on that :) |
Ok, I think I'm for including normalization in |
Yep we can do that too |
It turned out that the options are also used before |
Both cases were already covered by the tests, so I didn't have to add any 😉 |
@tleunen If you're ok, I'd go ahead and merge it. |
I'm checking it that now. Thanks for the update @fatfisz |
src/utils.js
Outdated
const currentFile = state.file.opts.filename; | ||
const opts = state.opts; | ||
|
||
const modulePath = resolvePath.call(state, sourcePath, currentFile, opts); |
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.
I'm not sure I'm a fan of using resolvePath
with a state context.
I believe I'd prefer that the function we export for the external use would be a new one that normalize and then use the internal resolvePath
.
In a way, it feels weird to have resolvePath
requiring to be called on a speficic context, it should be stateless.
Let me know what you think, we can discuss about it :)
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.
Technically it can be stateless; this is just a crutch so that the original resolvePath
can reuse the normalized options if they are there. Without state
as this
the function will just normalize by itself.
I agree that it may be over-optimized (normalizing seems to be quite cheap). Do you think it's better to get rid of this for clarity?
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.
I was thinking of calling it with resolvePath(sourcePath, currentFile, state.normalizedOpts)
.
And then the function we export in index.js
would be a custom function doing:
export {
resolvePath: (sourcePath, currentFile, opts) => {
const normalizedOpts = normalizeOptions(currentFile, opts);
return resolvePath(sourcePath, currentFile, normalizedOpts);
}
};
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.
But later (with the new resolvePath
option) this call will need opts
as opposed to normalizedOpts
:
const modulePath = opts.resolvePath(sourcePath, currentFile, opts);
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.
I'll go ahead and eliminate the context then, since we seem to agree on that 😃
I think there's a value in having the same singature for the internal |
I see your point, but forcing to normalize the options again and again might impact the performance, especially since it might not be needed. The If this is really the way we want to go, to keep the same signature for the internal and external |
Yes, I was thinking the same thing - that's why I've added the |
Yes, and I believe we could also optimize |
Brilliant! |
I settled on reselect because it required less configuration to use (lodash.memoize would need a special resolver function and a modified storage, because by default it handles only the first argument). |
cf1b755
to
ca9fd9e
Compare
This will require a new version for the eslint plugin too. I will see if I can move the eslint plugin in this repo too. It will be easier to maintain. |
As discussed in #189, there is a need for exposing some of the internal methods (importing from
package/lib/*
is not really a future-proof solution, because this is an undocumented API).Also
normalizeOptions
is rewritten to prevent modifying the passed options object.