Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(task): do not error if node_modules folder not exists #23920

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions cli/npm/managed/resolvers/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::sync::Mutex;

use async_trait::async_trait;
use deno_ast::ModuleSpecifier;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use deno_core::futures;
use deno_core::unsync::spawn;
Expand Down Expand Up @@ -94,9 +95,23 @@ impl RegistryReadPermissionChecker {
let registry_path_canon = match cache.get(&self.registry_path) {
Some(canon) => canon.clone(),
None => {
let canon = self.fs.realpath_sync(&self.registry_path)?;
cache.insert(self.registry_path.to_path_buf(), canon.clone());
canon
match self.fs.realpath_sync(&self.registry_path) {
Ok(canon) => {
cache.insert(self.registry_path.to_path_buf(), canon.clone());
canon
}
Err(e) => {
if e.kind() == ErrorKind::NotFound {
return Ok(()); // root doesn't exist, so allow
}
return Err(AnyError::from(e)).with_context(|| {
format!(
"failed canonicalizing '{}'",
self.registry_path.display()
)
});
}
}
}
};

Expand Down
3 changes: 2 additions & 1 deletion cli/tools/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ pub async fn execute_script(
bail!("Only local configuration files are supported")
};
let cwd = match task_flags.cwd {
Some(path) => canonicalize_path(&PathBuf::from(path))?,
Some(path) => canonicalize_path(&PathBuf::from(path))
.context("failed canonicalizing --cwd")?,
None => config_file_path.parent().unwrap().to_owned(),
};

Expand Down
16 changes: 16 additions & 0 deletions tests/specs/task/node_modules_dir_false/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"tempDir": true,
"steps": [{
"args": "cache npm:@denotest/esm-basic",
"output": "[WILDCARD]"
}, {
"args": [
"eval",
"Deno.removeSync('./node_modules', { recursive: true });"
],
"output": "[WILDCARD]"
}, {
"args": "task --quiet repro",
"output": "hi\n"
}]
}
6 changes: 6 additions & 0 deletions tests/specs/task/node_modules_dir_false/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"nodeModulesDir": true,
"tasks": {
"repro": "echo hi"
}
}