diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-12-16 23:41:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-16 23:41:51 +0100 |
commit | efcb93f8b9610bff896f21ecb5add7d17de40156 (patch) | |
tree | b8805ba050821a8cdfc2a9305587556afdc638af /cli/node/mod.rs | |
parent | 058610b458bfbc361f9a4bef62152465bf72d2c3 (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 'cli/node/mod.rs')
-rw-r--r-- | cli/node/mod.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/cli/node/mod.rs b/cli/node/mod.rs index 64e08becb..190f386a7 100644 --- a/cli/node/mod.rs +++ b/cli/node/mod.rs @@ -391,14 +391,19 @@ static RESERVED_WORDS: Lazy<HashSet<&str>> = Lazy::new(|| { pub async fn initialize_runtime( js_runtime: &mut JsRuntime, + uses_local_node_modules_dir: bool, ) -> Result<(), AnyError> { let source_code = &format!( - r#"(async function loadBuiltinNodeModules(moduleAllUrl, nodeGlobalThisName) {{ + r#"(async function loadBuiltinNodeModules(moduleAllUrl, nodeGlobalThisName, usesLocalNodeModulesDir) {{ const moduleAll = await import(moduleAllUrl); Deno[Deno.internal].node.initialize(moduleAll.default, nodeGlobalThisName); - }})('{}', '{}');"#, + if (usesLocalNodeModulesDir) {{ + Deno[Deno.internal].require.setUsesLocalNodeModulesDir(); + }} + }})('{}', '{}', {});"#, MODULE_ALL_URL.as_str(), NODE_GLOBAL_THIS_NAME.as_str(), + uses_local_node_modules_dir, ); let value = |