summaryrefslogtreecommitdiff
path: root/ext/node/02_require.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-12-16 23:41:51 +0100
committerGitHub <noreply@github.com>2022-12-16 23:41:51 +0100
commitefcb93f8b9610bff896f21ecb5add7d17de40156 (patch)
treeb8805ba050821a8cdfc2a9305587556afdc638af /ext/node/02_require.js
parent058610b458bfbc361f9a4bef62152465bf72d2c3 (diff)
fix(npm): fix require resolution if using --node-modules-dir (#17087)
In our `require()` implementation we use a special logic to resolve "base path" when looking for matching packages, however this logic is in contradiction to what needs to happen if there's a local "node_modules" directory used. This commit changes require implementation to be aware if we're running off of global node modules cache or a local one.
Diffstat (limited to 'ext/node/02_require.js')
-rw-r--r--ext/node/02_require.js13
1 files changed, 9 insertions, 4 deletions
diff --git a/ext/node/02_require.js b/ext/node/02_require.js
index 53921c242..2174ff8a9 100644
--- a/ext/node/02_require.js
+++ b/ext/node/02_require.js
@@ -71,6 +71,8 @@
let mainModule = null;
let hasBrokenOnInspectBrk = false;
let hasInspectBrk = false;
+ // Are we running with --node-modules-dir flag?
+ let usesLocalNodeModulesDir = false;
function stat(filename) {
// TODO: required only on windows
@@ -359,10 +361,10 @@
const isRelative = ops.op_require_is_request_relative(
request,
);
- // TODO(bartlomieju): could be a single op
- const basePath = (isDenoDirPackage && !isRelative)
- ? pathResolve(curPath, packageSpecifierSubPath(request))
- : pathResolve(curPath, request);
+ const basePath =
+ (isDenoDirPackage && !isRelative && !usesLocalNodeModulesDir)
+ ? pathResolve(curPath, packageSpecifierSubPath(request))
+ : pathResolve(curPath, request);
let filename;
const rc = stat(basePath);
@@ -915,6 +917,9 @@
window.__bootstrap.internals = {
...window.__bootstrap.internals ?? {},
require: {
+ setUsesLocalNodeModulesDir() {
+ usesLocalNodeModulesDir = true;
+ },
setInspectBrk() {
hasInspectBrk = true;
},