-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: allow passing a directory to createRequireFromPath
Fixes: #23710 PR-URL: #23818 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
1 parent
a0353fd
commit be9a1ec
Showing
3 changed files
with
31 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
test/parallel/test-module-create-require-from-directory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }); |