Skip to content

Commit

Permalink
utils: [fix] prefer createRequire if available
Browse files Browse the repository at this point in the history
  • Loading branch information
iamnapo authored and ljharb committed Jan 11, 2020
1 parent d8c6795 commit bcd9fe8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## Unreleased

- Use `createRequire` instead of `createRequireFromPath` if available ([#1602], thanks [@iamnapo])

## v2.5.1 - 2020-01-11

### Fixed
- Uses createRequireFromPath to resolve loaders ([#1591], thanks [@arcanis])
- report the error stack on a resolution error ([#599], thanks [@sompylasar])
Expand Down Expand Up @@ -62,7 +66,7 @@ Yanked due to critical issue with cache key resulting from #839.
### Fixed
- `unambiguous.test()` regex is now properly in multiline mode


[#1602]: https://github.com/benmosher/eslint-plugin-import/pull/1602
[#1591]: https://github.com/benmosher/eslint-plugin-import/pull/1591
[#1551]: https://github.com/benmosher/eslint-plugin-import/pull/1551
[#1435]: https://github.com/benmosher/eslint-plugin-import/pull/1435
Expand All @@ -84,3 +88,4 @@ Yanked due to critical issue with cache key resulting from #839.
[@JounQin]: https://github.com/JounQin
[@arcanis]: https://github.com/arcanis
[@sompylasar]: https://github.com/sompylasar
[@iamnapo]: https://github.com/iamnapo
5 changes: 3 additions & 2 deletions utils/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const ERROR_NAME = 'EslintPluginImportResolveError'
const fileExistsCache = new ModuleCache()

// Polyfill Node's `Module.createRequireFromPath` if not present (added in Node v10.12.0)
const createRequireFromPath = Module.createRequireFromPath || function (filename) {
// Use `Module.createRequire` if available (added in Node v12.2.0)
const createRequire = Module.createRequire || Module.createRequireFromPath || function (filename) {
const mod = new Module(filename, null)
mod.filename = filename
mod.paths = Module._nodeModulePaths(path.dirname(filename))
Expand All @@ -33,7 +34,7 @@ function tryRequire(target, sourceFile) {
try {
// Check if the target exists
if (sourceFile != null) {
resolved = createRequireFromPath(sourceFile).resolve(target)
resolved = createRequire(path.resolve(sourceFile)).resolve(target)
} else {
resolved = require.resolve(target)
}
Expand Down

0 comments on commit bcd9fe8

Please sign in to comment.