summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/npm/cache.rs42
-rw-r--r--cli/npm/mod.rs8
-rw-r--r--cli/proc_state.rs2
3 files changed, 30 insertions, 22 deletions
diff --git a/cli/npm/cache.rs b/cli/npm/cache.rs
index 4ab39f6bd..e5193c77c 100644
--- a/cli/npm/cache.rs
+++ b/cli/npm/cache.rs
@@ -2,6 +2,7 @@
use std::borrow::Cow;
use std::fs;
+use std::path::Path;
use std::path::PathBuf;
use deno_ast::ModuleSpecifier;
@@ -41,23 +42,33 @@ impl Default for ReadonlyNpmCache {
// This only gets used when creating the tsc runtime and for testing, and so
// it shouldn't ever actually access the DenoDir, so it doesn't support a
// custom root.
- Self::from_deno_dir(&crate::deno_dir::DenoDir::new(None).unwrap()).unwrap()
+ Self::from_deno_dir(&crate::deno_dir::DenoDir::new(None).unwrap())
}
}
impl ReadonlyNpmCache {
- pub fn new(root_dir: PathBuf) -> Result<Self, AnyError> {
- std::fs::create_dir_all(&root_dir)
- .with_context(|| format!("Error creating {}", root_dir.display()))?;
- let root_dir = crate::fs_util::canonicalize_path(&root_dir)?;
+ pub fn new(root_dir: PathBuf) -> Self {
+ fn try_get_canonicalized_root_dir(
+ root_dir: &Path,
+ ) -> Result<PathBuf, AnyError> {
+ if !root_dir.exists() {
+ std::fs::create_dir_all(&root_dir)
+ .with_context(|| format!("Error creating {}", root_dir.display()))?;
+ }
+ Ok(crate::fs_util::canonicalize_path(root_dir)?)
+ }
+
+ // this may fail on readonly file systems, so just ignore if so
+ let root_dir =
+ try_get_canonicalized_root_dir(&root_dir).unwrap_or(root_dir);
let root_dir_url = Url::from_directory_path(&root_dir).unwrap();
- Ok(Self {
+ Self {
root_dir,
root_dir_url,
- })
+ }
}
- pub fn from_deno_dir(dir: &DenoDir) -> Result<Self, AnyError> {
+ pub fn from_deno_dir(dir: &DenoDir) -> Self {
Self::new(dir.root.join("npm"))
}
@@ -161,14 +172,11 @@ pub struct NpmCache {
}
impl NpmCache {
- pub fn from_deno_dir(
- dir: &DenoDir,
- cache_setting: CacheSetting,
- ) -> Result<Self, AnyError> {
- Ok(Self {
- readonly: ReadonlyNpmCache::from_deno_dir(dir)?,
+ pub fn from_deno_dir(dir: &DenoDir, cache_setting: CacheSetting) -> Self {
+ Self {
+ readonly: ReadonlyNpmCache::from_deno_dir(dir),
cache_setting,
- })
+ }
}
pub fn as_readonly(&self) -> ReadonlyNpmCache {
@@ -288,7 +296,7 @@ mod test {
#[test]
fn should_get_lowercase_package_folder() {
let root_dir = crate::deno_dir::DenoDir::new(None).unwrap().root;
- let cache = ReadonlyNpmCache::new(root_dir.clone()).unwrap();
+ let cache = ReadonlyNpmCache::new(root_dir.clone());
let registry_url = Url::parse("https://registry.npmjs.org/").unwrap();
// all lowercase should be as-is
@@ -311,7 +319,7 @@ mod test {
fn should_handle_non_all_lowercase_package_names() {
// it was possible at one point for npm packages to not just be lowercase
let root_dir = crate::deno_dir::DenoDir::new(None).unwrap().root;
- let cache = ReadonlyNpmCache::new(root_dir.clone()).unwrap();
+ let cache = ReadonlyNpmCache::new(root_dir.clone());
let registry_url = Url::parse("https://registry.npmjs.org/").unwrap();
let json_uppercase_hash =
"db1a21a0bc2ef8fbe13ac4cf044e8c9116d29137d5ed8b916ab63dcb2d4290df";
diff --git a/cli/npm/mod.rs b/cli/npm/mod.rs
index 7bb515e9e..5b49afb3d 100644
--- a/cli/npm/mod.rs
+++ b/cli/npm/mod.rs
@@ -85,13 +85,13 @@ impl GlobalNpmPackageResolver {
reload: bool,
cache_setting: CacheSetting,
unstable: bool,
- ) -> Result<Self, AnyError> {
- Ok(Self::from_cache(
- NpmCache::from_deno_dir(dir, cache_setting.clone())?,
+ ) -> Self {
+ Self::from_cache(
+ NpmCache::from_deno_dir(dir, cache_setting.clone()),
reload,
cache_setting,
unstable,
- ))
+ )
}
fn from_cache(
diff --git a/cli/proc_state.rs b/cli/proc_state.rs
index 7175f18e1..42c34686f 100644
--- a/cli/proc_state.rs
+++ b/cli/proc_state.rs
@@ -229,7 +229,7 @@ impl ProcState {
cli_options.unstable()
// don't do the unstable error when in the lsp
|| matches!(cli_options.sub_command(), DenoSubcommand::Lsp),
- )?;
+ );
Ok(ProcState(Arc::new(Inner {
dir,