| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
What about just having prepend and append contain the paths themselves? |
Sorry, something went wrong.
There was a problem hiding this comment.
How about having just append, with append on true, prepend on false, discard override defaults on undefined?
Sorry, something went wrong.
There was a problem hiding this comment.
Alternatively, we could go with an approach like
{
paths: [ 'these', 'replace', 'the', 'existing', 'path'],
prepend: [ 'these', 'prepend', 'to', 'the', 'path'],
append: [ 'these', 'append', 'to', 'the', 'path']
}
Sorry, something went wrong.
There was a problem hiding this comment.
(heh, just saw that @mscdex suggested the same thing above :-) ...)
Sorry, something went wrong.
There was a problem hiding this comment.
I think that is the suggestion that @mscdex made. I plan to update to that.
Sorry, something went wrong.
There was a problem hiding this comment.
Is there a way to get the default resolution paths? If yes, require.resolve could just accept options.paths. Appending/prepending/replacing can be done outside of require.resolve
Sorry, something went wrong.
There was a problem hiding this comment.
Module._resolveLookupPaths() gives the paths, but it is not public API. It does seem simplest and most flexible to provide a way to get and set the paths. I could update resolve() in this PR to only overwrite the paths with what is passed in, dropping the append and prepend functionality. Then, add require.resolve.paths(request) which returns the default paths for that request.
Sorry, something went wrong.
There was a problem hiding this comment.
Thinking about it further, that's likely the easiest approach... specifically, have a public API for getting the current resolve path, and an option only for overriding it... e.g.
const paths = resolve.getLookupPaths(); // returns a mutable *copy*
paths.unshift('/some/other/path'); // prepend
paths.push('/another/path'); // append
resolve(name, { paths });
Sorry, something went wrong.
There was a problem hiding this comment.
Updating this PR now...
Sorry, something went wrong.
There was a problem hiding this comment.
something wrong here? bar.js is not present under nestedIndex so can you double-check this check?
This is what I get for bar.js and three.js:
#find . -name bar.js ./test/fixtures/node_modules/bar.js ./test/fixtures/node_modules/node_modules/bar.js #find . -name three.js ./test/fixtures/json-with-directory-name-module/module-stub/one/two/three.js ./test/fixtures/json-with-directory-name-module/module-stub/one-trailing-slash/two/three.js ./test/fixtures/nested-index/three.js #
Sorry, something went wrong.
There was a problem hiding this comment.
The require() machinery checks the node_modules directory in the parent, which is how it finds bar.js.
Sorry, something went wrong.
There was a problem hiding this comment.
ah, ok - got it, thanks!
Sorry, something went wrong.
SGTM. I really like that idea. |
Sorry, something went wrong.
There was a problem hiding this comment.
Should this be something like #### require.resolve(name[, options]), with name type and meaning description? It seems to be missing in the previous variant.
Sorry, something went wrong.
There was a problem hiding this comment.
+ It seems, till we automate this, we should check possible links in all docs if we change headers. Currently, we have one for this header, so it also needs updating.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks for pointing this out. I've updated the documentation and searched for relevant links.
Sorry, something went wrong.
|
big +1 to this idea, left a suggestion on the impl tho. |
Sorry, something went wrong.
There was a problem hiding this comment.
Seems like this should not be executed if options.prepend or options.append is true
Sorry, something went wrong.
|
Updated with the discussed implementation of having separate set and get functionality. Also added duplicate path removal logic. |
Sorry, something went wrong.
There was a problem hiding this comment.
A nit: String -> string
Sorry, something went wrong.
There was a problem hiding this comment.
I'm not sure it matters to compare strictly with a boolean like this like we do for other special values? /cc @bmeurer
Sorry, something went wrong.
There was a problem hiding this comment.
This will generate the same code as if (!paths.includes(path)), since TurboFan knows that Array#includes returns a boolean.
Sorry, something went wrong.
There was a problem hiding this comment.
Ah ok, then yes, let's switch these to the if (!paths.includes(path)) style here and elsewhere.
Sorry, something went wrong.
There was a problem hiding this comment.
@mscdex done.
Sorry, something went wrong.
There was a problem hiding this comment.
Generally LGTM so long as others are happy with it. I didn't see anything that stood out as problematic.
Sorry, something went wrong.
Sorry, something went wrong.
|
LGTM |
Sorry, something went wrong.
This commit allows custom lookup paths to be passed to require.resolve(). It also adds require.resolve.paths() which retrieves the default resolution paths. Fixes: nodejs#5963 Fixes: nodejs#16389 PR-URL: nodejs#16397 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This commit allows custom lookup paths to be passed to require.resolve(). It also adds require.resolve.paths() which retrieves the default resolution paths. Fixes: nodejs/node#5963 Fixes: nodejs/node#16389 PR-URL: nodejs/node#16397 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This commit allows custom lookup paths to be passed to require.resolve(). It also adds require.resolve.paths() which retrieves the default resolution paths. Fixes: #5963 Fixes: #16389 PR-URL: #16397 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This commit allows custom lookup paths to be passed to require.resolve(). It also adds require.resolve.paths() which retrieves the default resolution paths. Fixes: #5963 Fixes: #16389 PR-URL: #16397 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This commit allows custom lookup paths to be passed to require.resolve(). It also adds require.resolve.paths() which retrieves the default resolution paths. Fixes: #5963 Fixes: #16389 PR-URL: #16397 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This LTS release comes with 87 commits. This includes 30 that are
updates to lib/ or src/, 20 that are test related, 13 that are doc
related, 19 which are build / tools related, and 4 commits which are
updates to dependencies.
Notable Changes:
* doc:
- add Gibson Fahnestock to Release team (Gibson Fahnestock)
#16620
* deps:
- update npm to 5.5.1 (Myles Borins)
#16509
* http2:
- The exposed http2 socket is no longer manipulatable
(Anatoli Papirovski)
#16330
* module:
- support custom paths to require.resolve() (cjihrig)
#16397
* util:
- util.TextEncoder and util.TextDecoder are no longer experimental.
There will no longer be a warning when they are used
(James M Snell)
#15743
PR-URL: #16630
This LTS release comes with 87 commits. This includes 30 that are
updates to lib/ or src/, 20 that are test related, 13 that are doc
related, 19 which are build / tools related, and 4 commits which are
updates to dependencies.
Notable Changes:
* doc:
- add Gibson Fahnestock to Release team (Gibson Fahnestock)
#16620
* deps:
- update npm to 5.5.1 (Myles Borins)
#16509
* http2:
- The exposed http2 socket is no longer manipulatable
(Anatoli Papirovski)
#16330
* module:
- support custom paths to require.resolve() (cjihrig)
#16397
* util:
- util.TextEncoder and util.TextDecoder are no longer experimental.
There will no longer be a warning when they are used
(James M Snell)
#15743
PR-URL: #16630
This LTS release comes with 87 commits. This includes 30 that are
updates to lib/ or src/, 20 that are test related, 13 that are doc
related, 19 which are build / tools related, and 4 commits which are
updates to dependencies.
Notable Changes:
* doc:
- add Gibson Fahnestock to Release team (Gibson Fahnestock)
#16620
* deps:
- update npm to 5.5.1 (Myles Borins)
#16509
* http2:
- The exposed http2 socket is no longer manipulatable
(Anatoli Papirovski)
#16330
* module:
- support custom paths to require.resolve() (cjihrig)
#16397
* util:
- util.TextEncoder and util.TextDecoder are no longer experimental.
There will no longer be a warning when they are used
(James M Snell)
#15743
PR-URL: #16630
This LTS release comes with 87 commits. This includes 30 that are
updates to lib/ or src/, 20 that are test related, 13 that are doc
related, 19 which are build / tools related, and 4 commits which are
updates to dependencies.
Notable Changes:
* doc:
- add Gibson Fahnestock to Release team (Gibson Fahnestock)
#16620
* deps:
- update npm to 5.5.1 (Myles Borins)
#16509
* http2:
- The exposed http2 socket is no longer manipulatable
(Anatoli Papirovski)
#16330
* module:
- support custom paths to require.resolve() (cjihrig)
#16397
* util:
- util.TextEncoder and util.TextDecoder are no longer experimental.
There will no longer be a warning when they are used
(James M Snell)
#15743
PR-URL: #16630
This LTS release comes with 87 commits. This includes 30 that are
updates to lib/ or src/, 20 that are test related, 13 that are doc
related, 19 which are build / tools related, and 4 commits which are
updates to dependencies.
Notable Changes:
* doc:
- add Gibson Fahnestock to Release team (Gibson Fahnestock)
nodejs/node#16620
* deps:
- update npm to 5.5.1 (Myles Borins)
nodejs/node#16509
* http2:
- The exposed http2 socket is no longer manipulatable
(Anatoli Papirovski)
nodejs/node#16330
* module:
- support custom paths to require.resolve() (cjihrig)
nodejs/node#16397
* util:
- util.TextEncoder and util.TextDecoder are no longer experimental.
There will no longer be a warning when they are used
(James M Snell)
nodejs/node#15743
PR-URL: nodejs/node#16630
This LTS release comes with 87 commits. This includes 30 that are
updates to lib/ or src/, 20 that are test related, 13 that are doc
related, 19 which are build / tools related, and 4 commits which are
updates to dependencies.
Notable Changes:
* doc:
- add Gibson Fahnestock to Release team (Gibson Fahnestock)
nodejs/node#16620
* deps:
- update npm to 5.5.1 (Myles Borins)
nodejs/node#16509
* http2:
- The exposed http2 socket is no longer manipulatable
(Anatoli Papirovski)
nodejs/node#16330
* module:
- support custom paths to require.resolve() (cjihrig)
nodejs/node#16397
* util:
- util.TextEncoder and util.TextDecoder are no longer experimental.
There will no longer be a warning when they are used
(James M Snell)
nodejs/node#15743
PR-URL: nodejs/node#16630
This commit allows custom lookup paths to be passed to require.resolve(). It also adds require.resolve.paths() which retrieves the default resolution paths. Fixes: nodejs/node#5963 Fixes: nodejs/node#16389 PR-URL: nodejs/node#16397 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This LTS release comes with 87 commits. This includes 30 that are
updates to lib/ or src/, 20 that are test related, 13 that are doc
related, 19 which are build / tools related, and 4 commits which are
updates to dependencies.
Notable Changes:
* doc:
- add Gibson Fahnestock to Release team (Gibson Fahnestock)
nodejs/node#16620
* deps:
- update npm to 5.5.1 (Myles Borins)
nodejs/node#16509
* http2:
- The exposed http2 socket is no longer manipulatable
(Anatoli Papirovski)
nodejs/node#16330
* module:
- support custom paths to require.resolve() (cjihrig)
nodejs/node#16397
* util:
- util.TextEncoder and util.TextDecoder are no longer experimental.
There will no longer be a warning when they are used
(James M Snell)
nodejs/node#15743
PR-URL: nodejs/node#16630
|
Release team were -1 on landing on v6.x, if you disagree let us know. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
I originally wrote this for #5963, but didn't open a PR. Today, it was requested again in #16389, so I thought I'd open a PR. I'm not sure how it will be received.
This PR supports passing custom paths to require.resolve(). The custom paths can replace the default paths, be prepended to the default paths, or be appended to the default paths. All of the functionality is isolated to a single if statement, so the impact on code that doesn't use this feature should be extremely minimal.
Checklist
Affected core subsystem(s)
module