-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
module: allow passing a directory to createRequireFromPath #23818
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
Changes from all commits
a734696
676cc00
c2eff11
2b1f48e
5942747
9ec4cb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
|
||
const { createRequireFromPath } = require('module'); | ||
|
||
const fixPath = path.resolve(__dirname, '..', 'fixtures'); | ||
const p = path.join(fixPath, path.sep); | ||
|
||
const req = createRequireFromPath(p); | ||
const reqFromNotDir = createRequireFromPath(fixPath); | ||
|
||
assert.strictEqual(req('./baz'), 'perhaps I work'); | ||
assert.throws(() => { | ||
reqFromNotDir('./baz'); | ||
}, { code: 'MODULE_NOT_FOUND' }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd expect both of this to pass. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be a very different approach to this function, but it could work. //cc @devsnek There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to change the implementation to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we want to get this merged, I'd suggest we stick with the current behaviour which matches the behaviour of path resolution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 to sticking to behavior that matches path... we should change this behavior in the path module if we want to fix it imho There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally think calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to land this to improve the behavior and introduce the stat separately in a follow up. Is that reasonable for you @BridgeAR ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has three different open comments at the moment (actually four but two are about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BridgeAR afaict all open comments are about stat, which I think should be an incremental improvement discussed separately. Did I miss any other open comments? |
Uh oh!
There was an error while loading. Please reload this page.