Skip to content

Commit

Permalink
change req to resolve based on file path rather than directory (#231)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
43081j authored Feb 11, 2022
1 parent a9bcad0 commit fa6003c
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/req.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// eslint-disable-next-line node/no-deprecated-api
const { createRequire, createRequireFromPath } = require('module')
const path = require('path')

function req (name, rootFile) {
const create = createRequire || createRequireFromPath
const require = create(path.resolve(rootFile, '_'))
const require = create(rootFile)
return require(name)
}

Expand Down

0 comments on commit fa6003c

Please sign in to comment.