-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
module: createRequireFromPath missed docs #24763
Conversation
Fixes: nodejs#23710 Adding the missing documentation
/ping @guybedford |
```js | ||
const { createRequireFromPath } = require('module'); | ||
const requireUtil = createRequireFromPath('../src/utils'); | ||
const requireUtil = createRequireFromPath('../src/utils'); // can also be a file |
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.
Am I mistaken or won't the code fail if utils
is a directory unless it's like this?:
const requireUtil = createRequireFromPath('../src/utils'); // can also be a file | |
const requireUtil = createRequireFromPath('../src/utils/.'); |
And if so, then the comment is misleading because it implies that passing a directory without /.
at the end will work.
And explaining the /.
requirement is probably more trouble than it's worth.
Probably best to update this to point to a file and not a directory at all.
const requireUtil = createRequireFromPath('../src/utils'); // can also be a file | |
const requireUtil = createRequireFromPath('../src/utils/index.js'); |
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.
Yes we should likely go with this last suggestion please.
(Commit message subsystem should be |
Hi, @doertedev! Welcome, and thanks for the PR! I might be mistaken, but think the current code sample needs to be changed, and we probably don't want to try to document using directories instead of filenames until the PR that adds support for trailing-slash-without-a-.-after-it lands. /ping @guybedford @targos |
Eeer sorry in this case I must have misinterpreted #23710 (comment) which stated that a PR for dirs is already in place ??!? |
@doertedev the PR for dirs is not yet in place, so the example must be updated little differently, more in line with @Trott comment above. I went ahead and did that instead of your PR. Is that OK for you? |
module.createRequireFromPath() takes a filename as argument. But the accompanying code example in the documentation makes it seem like it can take a directory argument as well. However, if a directory is passed as argument instead of a filename, then the function does not work as expected. Therefore, the fix is to make explicit in the code example that only filenames could be passed to module.createRequireFromPath() and not directory names. Fixes: nodejs#23710 Refs: nodejs#24763 (comment)
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 with the suggestion from @Trott
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 for the PR! We just need to update the example as @Trott describes.
```js | ||
const { createRequireFromPath } = require('module'); | ||
const requireUtil = createRequireFromPath('../src/utils'); | ||
const requireUtil = createRequireFromPath('../src/utils'); // can also be a file |
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.
Yes we should likely go with this last suggestion please.
ping @doertedev - can address the review comments? |
I will pick this up. |
Looking further, I see that the required changes are actually realized through #23818 and hence there is nothing left to do in this PR |
8ae28ff
to
2935f72
Compare
Looks like this can be closed. |
Fixes: #23710
Adding the missing documentation
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes