-
-
Notifications
You must be signed in to change notification settings - Fork 594
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
feat(node-resolve): add new option, modulePaths #1104
Conversation
f558fe8
to
56c0679
Compare
@tjenkinson please have a peek at this one |
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.
thanks @ajhyndman!
Looks good. Got a few suggestions
packages/node-resolve/test/test.js
Outdated
@@ -257,6 +257,36 @@ test('allows custom moduleDirectories with legacy customResolveOptions.moduleDir | |||
t.snapshot(warnings); | |||
}); | |||
|
|||
test('custom moduleDirectories do not support nested dependencies', async (t) => { |
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 think it's good to test this but it would be nice to also actually flag this as a proper error if the user tries to provide a path instead of name for this option.
Please could we update the code to something like:
if (moduleDirectories.some((name) => name.includes('/'))) {
throw new Error(
'`moduleDirectories` option must only contain directory names. If you want to load modules from a custom directory see `modulePaths`.'
);
}
in index.js
Then this test can just check that
nodeResolve({
moduleDirectories: ['some/path']
})
throws that error
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.
Yeah, that sounds awesome! Would this change be breaking though? Should it require a major version bump? I'm concerned that there may be a large subset of users (like us) relying on the existing behaviour.
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.
If you use a path doesn’t it just get ignored currently?
If that’s the case and it silently fails (with the warning when module not found) IMO this doesn’t need to be a breaking change as it’s highlighting an invalid config
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.
What’s the existing behaviour you’re relying on?
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.
If you pass a relative path, it appears that the same logic for folder names is applied. i.e. When searching for node modules, rollup will recursively walk up the filesystem, at each level looking for the full subpath specified.
I think we inadvertently assumed that moduleDirectories would allow us to specify a NODE_PATH, and for a little while we were accidentally getting away with 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.
Interesting. This readme says it's meant to just contain directory names, and the doc for the resolve
package we use says
opts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: "node_modules"
and the tests for it are only for names.
Given that, I think the fact that it did kind of work with a path was unintentional/undocumented, and therefore IMO erroring would be better and this would be fine as a patch. Especially given if people were misusing moduleDirectories
when they see the error there will be the correct option available for them to to move too.
@shellscape might have a different opinion though :)
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.
sounds reasonable to me
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 have rebased and pushed a change addressing this feedback. Let me know what you think!
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.
Sorry missed your reply
2393801
to
8d4921c
Compare
@tjenkinson PR is awaiting your review of most recent changes in response to your comments. please take a look. |
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!
Co-authored-by: Tom Jenkinson <tjenkinson@users.noreply.github.com>
Co-authored-by: Tom Jenkinson <tjenkinson@users.noreply.github.com>
5c76d5d
to
d142bc6
Compare
* [node-resolve] Implement new modulePaths option * Add unit tests distinguishing modulePaths from moduleDirectories * Document new option * Update packages/node-resolve/test/test.js Co-authored-by: Tom Jenkinson <tjenkinson@users.noreply.github.com> * Update packages/node-resolve/README.md Co-authored-by: Tom Jenkinson <tjenkinson@users.noreply.github.com> * fixup! Update packages/node-resolve/test/test.js * Reject moduleDirectories containing a slash * chore: arbitrary edit to kick github's actions ui Co-authored-by: Andrew Hyndman <ahyndman@dropbox.com> Co-authored-by: Tom Jenkinson <tjenkinson@users.noreply.github.com> Co-authored-by: Andrew Powell <shellscape@users.noreply.github.com>
Rollup Plugin Name:
plugin-node-resolve
This PR contains:
Are tests included?
Breaking Changes?
If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.
List any relevant issue numbers:
Description
This change introduces a new option for @rollup/plugin-node-resolve:
modulePaths
.Unlike
moduleDirectories
,modulePaths
allows the user to specify an absolute path to alternative locations (in addition to the importer's local directory) that should be searched for node modules.This can be useful (for example) to support a CI system that caches node_modules in a non-standard location.
In node, this is supported via the
NODE_PATH
environment variable. Conveniently, this also brings @rollup/plugin-node-resolve into alignment with Jest's configuration options. See: https://jestjs.io/docs/configuration#modulepaths-arraystring