summaryrefslogtreecommitdiff
path: root/cli/npm/managed
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-10-12 12:14:32 -0700
committerGitHub <noreply@github.com>2024-10-12 12:14:32 -0700
commit7a990d9d42b633ca70eca235df0f9ba09f876720 (patch)
tree8c7db663923f478b77cea37a8cae77d59eb27479 /cli/npm/managed
parent8b2c6fc2d22f0a62ceefa71ff739f81796142699 (diff)
feat(npm): support `--allow-scripts` on `deno run` (and `deno add`, `deno test`, etc) (#26075)
Fixes https://github.com/denoland/deno/issues/25533. Fixes https://github.com/denoland/deno/issues/25396. Previously we only supported it on `deno install` and `deno cache`, which is annoying if you're using `nodeModulesDir: auto`. Also changes from printing output of lifecycle scripts directly to capturing the output and only printing it on error.
Diffstat (limited to 'cli/npm/managed')
-rw-r--r--cli/npm/managed/resolvers/common/lifecycle_scripts.rs37
-rw-r--r--cli/npm/managed/resolvers/local.rs1
2 files changed, 36 insertions, 2 deletions
diff --git a/cli/npm/managed/resolvers/common/lifecycle_scripts.rs b/cli/npm/managed/resolvers/common/lifecycle_scripts.rs
index b358c3585..5735f5248 100644
--- a/cli/npm/managed/resolvers/common/lifecycle_scripts.rs
+++ b/cli/npm/managed/resolvers/common/lifecycle_scripts.rs
@@ -2,6 +2,8 @@
use super::bin_entries::BinEntries;
use crate::args::LifecycleScriptsConfig;
+use crate::task_runner::TaskStdio;
+use crate::util::progress_bar::ProgressBar;
use deno_core::anyhow::Context;
use deno_npm::resolution::NpmResolutionSnapshot;
use deno_runtime::deno_io::FromRawIoHandle;
@@ -148,6 +150,7 @@ impl<'a> LifecycleScripts<'a> {
snapshot: &NpmResolutionSnapshot,
packages: &[NpmResolutionPackage],
root_node_modules_dir_path: Option<&Path>,
+ progress_bar: &ProgressBar,
) -> Result<(), AnyError> {
self.warn_not_run_scripts()?;
let get_package_path =
@@ -201,7 +204,15 @@ impl<'a> LifecycleScripts<'a> {
{
continue;
}
- let exit_code = crate::task_runner::run_task(
+ let _guard = progress_bar.update_with_prompt(
+ crate::util::progress_bar::ProgressMessagePrompt::Initialize,
+ &format!("{}: running '{script_name}' script", package.id.nv),
+ );
+ let crate::task_runner::TaskResult {
+ exit_code,
+ stderr,
+ stdout,
+ } = crate::task_runner::run_task(
crate::task_runner::RunTaskOptions {
task_name: script_name,
script,
@@ -211,15 +222,37 @@ impl<'a> LifecycleScripts<'a> {
init_cwd,
argv: &[],
root_node_modules_dir: root_node_modules_dir_path,
+ stdio: Some(crate::task_runner::TaskIo {
+ stderr: TaskStdio::piped(),
+ stdout: TaskStdio::piped(),
+ }),
},
)
.await?;
+ let stdout = stdout.unwrap();
+ let stderr = stderr.unwrap();
if exit_code != 0 {
log::warn!(
- "error: script '{}' in '{}' failed with exit code {}",
+ "error: script '{}' in '{}' failed with exit code {}{}{}",
script_name,
package.id.nv,
exit_code,
+ if !stdout.trim_ascii().is_empty() {
+ format!(
+ "\nstdout:\n{}\n",
+ String::from_utf8_lossy(&stdout).trim()
+ )
+ } else {
+ String::new()
+ },
+ if !stderr.trim_ascii().is_empty() {
+ format!(
+ "\nstderr:\n{}\n",
+ String::from_utf8_lossy(&stderr).trim()
+ )
+ } else {
+ String::new()
+ },
);
failed_packages.push(&package.id.nv);
// assume if earlier script fails, later ones will fail too
diff --git a/cli/npm/managed/resolvers/local.rs b/cli/npm/managed/resolvers/local.rs
index 63a972a43..54f7576ad 100644
--- a/cli/npm/managed/resolvers/local.rs
+++ b/cli/npm/managed/resolvers/local.rs
@@ -713,6 +713,7 @@ async fn sync_resolution_with_fs(
snapshot,
&package_partitions.packages,
Some(root_node_modules_dir_path),
+ progress_bar,
)
.await?;