Skip to content

Commit

Permalink
Search the cwd first, then existing module paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jclem committed Apr 21, 2021
1 parent 95fb649 commit a49bf6b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
24 changes: 10 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2899,20 +2899,16 @@ const wrapRequire = new Proxy(require, {
moduleID = path__WEBPACK_IMPORTED_MODULE_0__.resolve(moduleID);
return target.apply(thisArg, [moduleID]);
}
try {
return target.apply(thisArg, [moduleID]);
}
catch (err) {
const modulePath = target.resolve.apply(thisArg, [
moduleID,
{
// Webpack does not have an escape hatch for getting the actual
// module, other than `eval`.
paths: eval('module').paths.concat(process.cwd())
}
]);
return target.apply(thisArg, [modulePath]);
}
const modulePath = target.resolve.apply(thisArg, [
moduleID,
{
// Search the current working directory first, then the existing paths.
// Webpack does not have an escape hatch for getting the actual
// module, other than `eval`.
paths: [process.cwd(), ...eval('module').paths]
}
]);
return target.apply(thisArg, [modulePath]);
},
get: (target, prop, receiver) => {
Reflect.get(target, prop, receiver);
Expand Down
23 changes: 10 additions & 13 deletions src/wrap-require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@ export const wrapRequire = new Proxy(__non_webpack_require__, {
return target.apply(thisArg, [moduleID])
}

try {
return target.apply(thisArg, [moduleID])
} catch (err) {
const modulePath = target.resolve.apply(thisArg, [
moduleID,
{
// Webpack does not have an escape hatch for getting the actual
// module, other than `eval`.
paths: eval('module').paths.concat(process.cwd())
}
])
const modulePath = target.resolve.apply(thisArg, [
moduleID,
{
// Search the current working directory first, then the existing paths.
// Webpack does not have an escape hatch for getting the actual
// module, other than `eval`.
paths: [process.cwd(), ...eval('module').paths]
}
])

return target.apply(thisArg, [modulePath])
}
return target.apply(thisArg, [modulePath])
},

get: (target, prop, receiver) => {
Expand Down

0 comments on commit a49bf6b

Please sign in to comment.