Skip to content

Commit fa6003c

Browse files
authored
change req to resolve based on file path rather than directory (#231)
We previously had a fabricated file name (`_`) to forcefully resolve a given directory path to a file path, so `createRequire` would be happy. Since we now pass the file path every time, we no longer need this. In future, if we need to `req` a directory, we should resolve the path at the call-site rather than inside `req`.
1 parent a9bcad0 commit fa6003c

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/req.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// eslint-disable-next-line node/no-deprecated-api
22
const { createRequire, createRequireFromPath } = require('module')
3-
const path = require('path')
43

54
function req (name, rootFile) {
65
const create = createRequire || createRequireFromPath
7-
const require = create(path.resolve(rootFile, '_'))
6+
const require = create(rootFile)
87
return require(name)
98
}
109

0 commit comments

Comments
 (0)