Skip to content

Commit a49bf6b

Browse files
committed
Search the cwd first, then existing module paths
1 parent 95fb649 commit a49bf6b

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

dist/index.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,20 +2899,16 @@ const wrapRequire = new Proxy(require, {
28992899
moduleID = path__WEBPACK_IMPORTED_MODULE_0__.resolve(moduleID);
29002900
return target.apply(thisArg, [moduleID]);
29012901
}
2902-
try {
2903-
return target.apply(thisArg, [moduleID]);
2904-
}
2905-
catch (err) {
2906-
const modulePath = target.resolve.apply(thisArg, [
2907-
moduleID,
2908-
{
2909-
// Webpack does not have an escape hatch for getting the actual
2910-
// module, other than `eval`.
2911-
paths: eval('module').paths.concat(process.cwd())
2912-
}
2913-
]);
2914-
return target.apply(thisArg, [modulePath]);
2915-
}
2902+
const modulePath = target.resolve.apply(thisArg, [
2903+
moduleID,
2904+
{
2905+
// Search the current working directory first, then the existing paths.
2906+
// Webpack does not have an escape hatch for getting the actual
2907+
// module, other than `eval`.
2908+
paths: [process.cwd(), ...eval('module').paths]
2909+
}
2910+
]);
2911+
return target.apply(thisArg, [modulePath]);
29162912
},
29172913
get: (target, prop, receiver) => {
29182914
Reflect.get(target, prop, receiver);

src/wrap-require.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,17 @@ export const wrapRequire = new Proxy(__non_webpack_require__, {
77
return target.apply(thisArg, [moduleID])
88
}
99

10-
try {
11-
return target.apply(thisArg, [moduleID])
12-
} catch (err) {
13-
const modulePath = target.resolve.apply(thisArg, [
14-
moduleID,
15-
{
16-
// Webpack does not have an escape hatch for getting the actual
17-
// module, other than `eval`.
18-
paths: eval('module').paths.concat(process.cwd())
19-
}
20-
])
10+
const modulePath = target.resolve.apply(thisArg, [
11+
moduleID,
12+
{
13+
// Search the current working directory first, then the existing paths.
14+
// Webpack does not have an escape hatch for getting the actual
15+
// module, other than `eval`.
16+
paths: [process.cwd(), ...eval('module').paths]
17+
}
18+
])
2119

22-
return target.apply(thisArg, [modulePath])
23-
}
20+
return target.apply(thisArg, [modulePath])
2421
},
2522

2623
get: (target, prop, receiver) => {

0 commit comments

Comments
 (0)