Skip to content

Commit

Permalink
chore(resolver): simplify local require
Browse files Browse the repository at this point in the history
Module#createRequire is supported since Node@12.x.
  • Loading branch information
nikku committed Feb 15, 2025
1 parent a0cf881 commit 80a5a01
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions lib/resolver/node-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,5 @@ NodeResolver.prototype.normalizePkg = function(pkg) {
// helpers ////////////////////

function createScopedRequire(cwd) {

// shim createRequireFromPath for Node < 10.12
// shim createRequireFromPath for Node < 12.2.0
const createRequireFromPath = Module.createRequire || Module.createRequireFromPath || (filename => {
const mod = new Module(filename, null);

mod.filename = filename;
mod.paths = Module._nodeModulePaths(path.dirname(filename));
mod._compile('module.exports = require;', filename);

return mod.exports;
});

return createRequireFromPath(path.join(cwd, '__placeholder__.js'));
return Module.createRequire(path.join(cwd, '__placeholder__.js'));
}

0 comments on commit 80a5a01

Please sign in to comment.