summaryrefslogtreecommitdiff
path: root/cli/args/mod.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-06-26 23:17:00 +0100
committerGitHub <noreply@github.com>2024-06-27 00:17:00 +0200
commit2a2ff96be13047cb50612fde0f12e5f6df374ad3 (patch)
tree655ec1d1308db13c1faa917fd02321ee30c85efe /cli/args/mod.rs
parent0da01c0ca6b537f74be32126e567bdfc2c73ed16 (diff)
fix(ext/node): discover .npmrc in user's homedir (#24021)
This commit adds discovery of `.npmrc` files in user's homedir. This is not a perfect fix as it doesn't merge multiple `.npmrc` files together as per https://github.com/denoland/deno/issues/23954 but allows to fallback if no `.npmrc` file is discovered in the project root.
Diffstat (limited to 'cli/args/mod.rs')
-rw-r--r--cli/args/mod.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index ccf00425b..9e63ce889 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -72,6 +72,7 @@ use std::sync::Arc;
use thiserror::Error;
use crate::args::import_map::enhance_import_map_value_with_workspace_members;
+use crate::cache;
use crate::file_fetcher::FileFetcher;
use crate::util::fs::canonicalize_path_maybe_not_exists;
use crate::version;
@@ -592,6 +593,7 @@ pub fn discover_npmrc(
Ok(Arc::new(resolved))
}
+ // 1. Try `.npmrc` next to `package.json`
if let Some(package_json_path) = maybe_package_json_path {
if let Some(package_json_dir) = package_json_path.parent() {
if let Some((source, path)) = try_to_read_npmrc(package_json_dir)? {
@@ -600,6 +602,7 @@ pub fn discover_npmrc(
}
}
+ // 2. Try `.npmrc` next to `deno.json(c)`
if let Some(deno_json_path) = maybe_deno_json_path {
if let Some(deno_json_dir) = deno_json_path.parent() {
if let Some((source, path)) = try_to_read_npmrc(deno_json_dir)? {
@@ -608,6 +611,15 @@ pub fn discover_npmrc(
}
}
+ // TODO(bartlomieju): update to read both files - one in the project root and one and
+ // home dir and then merge them.
+ // 3. Try `.npmrc` in the user's home directory
+ if let Some(home_dir) = cache::home_dir() {
+ if let Some((source, path)) = try_to_read_npmrc(&home_dir)? {
+ return try_to_parse_npmrc(source, &path).map(|r| (r, Some(path)));
+ }
+ }
+
log::debug!("No .npmrc file found");
Ok((create_default_npmrc(), None))
}