summaryrefslogtreecommitdiff
path: root/cli/lsp
diff options
context:
space:
mode:
authorBartek Iwańczuk <biwanczuk@gmail.com>2024-05-23 22:26:23 +0100
committerGitHub <noreply@github.com>2024-05-23 23:26:23 +0200
commit959739f609dddacde3bbe9ecede2f409214fb34c (patch)
tree04d1776efbd3561205829f78288d26b6e14c3429 /cli/lsp
parent5de30c53239ac74843725d981afc0bb8c45bdf16 (diff)
FUTURE: initial support for .npmrc file (#23560)
This commit adds initial support for ".npmrc" files. Currently we only discover ".npmrc" files next to "package.json" files and discovering these files in user home dir is left for a follow up. This pass supports "_authToken" and "_auth" configuration for providing authentication. LSP support has been left for a follow up PR. Towards https://github.com/denoland/deno/issues/16105
Diffstat (limited to 'cli/lsp')
-rw-r--r--cli/lsp/config.rs5
-rw-r--r--cli/lsp/language_server.rs4
-rw-r--r--cli/lsp/resolver.rs6
3 files changed, 14 insertions, 1 deletions
diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs
index 597f45688..89ecb84d8 100644
--- a/cli/lsp/config.rs
+++ b/cli/lsp/config.rs
@@ -24,6 +24,7 @@ use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::ModuleSpecifier;
use deno_lockfile::Lockfile;
+use deno_npm::npm_rc::ResolvedNpmRc;
use deno_runtime::deno_node::PackageJson;
use deno_runtime::fs_util::specifier_to_file_path;
use deno_runtime::permissions::PermissionsContainer;
@@ -1090,6 +1091,7 @@ pub struct ConfigData {
pub vendor_dir: Option<PathBuf>,
pub lockfile: Option<Arc<Mutex<Lockfile>>>,
pub package_json: Option<Arc<PackageJson>>,
+ pub npmrc: Option<Arc<ResolvedNpmRc>>,
pub import_map: Option<Arc<ImportMap>>,
pub import_map_from_settings: bool,
watched_files: HashMap<ModuleSpecifier, ConfigWatchedFileType>,
@@ -1274,6 +1276,8 @@ impl ConfigData {
// Load package.json
let mut package_json = None;
+ // TODO(bartlomieju): support discovering .npmrc
+ let npmrc = None;
if let Ok(path) = specifier_to_file_path(scope) {
let path = path.join("package.json");
if let Ok(specifier) = ModuleSpecifier::from_file_path(&path) {
@@ -1429,6 +1433,7 @@ impl ConfigData {
vendor_dir,
lockfile: lockfile.map(Mutex::new).map(Arc::new),
package_json: package_json.map(Arc::new),
+ npmrc: npmrc.map(Arc::new),
import_map: import_map.map(Arc::new),
import_map_from_settings,
watched_files,
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 17ed02cd6..8f37d8b9c 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -83,6 +83,7 @@ use super::tsc::ChangeKind;
use super::tsc::GetCompletionDetailsArgs;
use super::tsc::TsServer;
use super::urls;
+use crate::args::create_default_npmrc;
use crate::args::get_root_cert_store;
use crate::args::CaData;
use crate::args::CacheSetting;
@@ -3318,6 +3319,9 @@ impl Inner {
config_data.and_then(|d| d.config_file.as_deref().cloned()),
config_data.and_then(|d| d.lockfile.clone()),
config_data.and_then(|d| d.package_json.as_deref().cloned()),
+ config_data
+ .and_then(|d| d.npmrc.clone())
+ .unwrap_or_else(create_default_npmrc),
force_global_cache,
)?;
diff --git a/cli/lsp/resolver.rs b/cli/lsp/resolver.rs
index c4d97177f..0567bba86 100644
--- a/cli/lsp/resolver.rs
+++ b/cli/lsp/resolver.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+use crate::args::create_default_npmrc;
use crate::args::package_json;
use crate::args::CacheSetting;
use crate::cache::FastInsecureHasher;
@@ -363,7 +364,10 @@ async fn create_npm_resolver(
// do not install while resolving in the lsp—leave that to the cache command
package_json_installer:
CliNpmResolverManagedPackageJsonInstallerOption::NoInstall,
- npm_registry_url: crate::args::npm_registry_url().to_owned(),
+ npmrc: config_data
+ .npmrc
+ .clone()
+ .unwrap_or_else(create_default_npmrc),
npm_system_info: NpmSystemInfo::default(),
})
};