summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/args/flags.rs2
-rw-r--r--cli/args/mod.rs6
-rw-r--r--cli/npm/managed/resolvers/common/lifecycle_scripts.rs2
-rw-r--r--tests/specs/npm/lifecycle_scripts/__test__.jsonc14
-rw-r--r--tests/specs/npm/lifecycle_scripts/all_lifecycles_global.js3
-rw-r--r--tests/specs/npm/lifecycle_scripts/all_lifecycles_not_run_global_cached.out7
-rw-r--r--tests/specs/npm/lifecycle_scripts/warns_again_on_install.out6
7 files changed, 37 insertions, 3 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 74ccb512f..4e151d7d9 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -548,6 +548,8 @@ pub struct LifecycleScriptsConfig {
pub allowed: PackagesAllowedScripts,
pub initial_cwd: PathBuf,
pub root_dir: PathBuf,
+ /// Part of an explicit `deno install`
+ pub explicit_install: bool,
}
#[derive(Debug, Clone, Eq, PartialEq, Default)]
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index 80b9afb24..a11d3bc10 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -1686,6 +1686,12 @@ impl CliOptions {
allowed: self.flags.allow_scripts.clone(),
initial_cwd: self.initial_cwd.clone(),
root_dir: self.workspace().root_dir_path(),
+ explicit_install: matches!(
+ self.sub_command(),
+ DenoSubcommand::Install(_)
+ | DenoSubcommand::Cache(_)
+ | DenoSubcommand::Add(_)
+ ),
}
}
}
diff --git a/cli/npm/managed/resolvers/common/lifecycle_scripts.rs b/cli/npm/managed/resolvers/common/lifecycle_scripts.rs
index a3c72634b..35040386c 100644
--- a/cli/npm/managed/resolvers/common/lifecycle_scripts.rs
+++ b/cli/npm/managed/resolvers/common/lifecycle_scripts.rs
@@ -111,7 +111,7 @@ impl<'a> LifecycleScripts<'a> {
.push((package, package_path.into_owned()));
}
} else if !self.strategy.has_run(package)
- && !self.strategy.has_warned(package)
+ && (self.config.explicit_install || !self.strategy.has_warned(package))
{
self
.packages_with_scripts_not_run
diff --git a/tests/specs/npm/lifecycle_scripts/__test__.jsonc b/tests/specs/npm/lifecycle_scripts/__test__.jsonc
index 201e42497..b798b968f 100644
--- a/tests/specs/npm/lifecycle_scripts/__test__.jsonc
+++ b/tests/specs/npm/lifecycle_scripts/__test__.jsonc
@@ -64,12 +64,17 @@
},
{
// should not warn
- "args": "install -e all_lifecycles.js",
+ "args": "run all_lifecycles_global.js",
"output": ""
+ },
+ {
+ // should warn still
+ "args": "install -e all_lifecycles.js",
+ "output": "all_lifecycles_not_run_global_cached.out"
}
]
},
- "only_warns_first": {
+ "only_warns_first_run": {
"steps": [
{
// without running scripts (should warn)
@@ -82,6 +87,11 @@
"args": "run all_lifecycles.js",
"output": "only_warns_first2.out",
"exitCode": 1
+ },
+ {
+ // should warn because this is an explicit install
+ "args": "install -e all_lifecycles.js",
+ "output": "warns_again_on_install.out"
}
]
},
diff --git a/tests/specs/npm/lifecycle_scripts/all_lifecycles_global.js b/tests/specs/npm/lifecycle_scripts/all_lifecycles_global.js
new file mode 100644
index 000000000..eccf11a6d
--- /dev/null
+++ b/tests/specs/npm/lifecycle_scripts/all_lifecycles_global.js
@@ -0,0 +1,3 @@
+try {
+ const _ = await import("npm:@denotest/node-lifecycle-scripts");
+} catch (_) {}
diff --git a/tests/specs/npm/lifecycle_scripts/all_lifecycles_not_run_global_cached.out b/tests/specs/npm/lifecycle_scripts/all_lifecycles_not_run_global_cached.out
new file mode 100644
index 000000000..789c9346a
--- /dev/null
+++ b/tests/specs/npm/lifecycle_scripts/all_lifecycles_not_run_global_cached.out
@@ -0,0 +1,7 @@
+Warning The following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed:
+┠─ npm:@denotest/node-lifecycle-scripts@1.0.0
+┃
+┠─ This may cause the packages to not work correctly.
+┠─ Lifecycle scripts are only supported when using a `node_modules` directory.
+┠─ Enable it in your deno config file:
+┖─ "nodeModulesDir": "auto"
diff --git a/tests/specs/npm/lifecycle_scripts/warns_again_on_install.out b/tests/specs/npm/lifecycle_scripts/warns_again_on_install.out
new file mode 100644
index 000000000..fe7eedc56
--- /dev/null
+++ b/tests/specs/npm/lifecycle_scripts/warns_again_on_install.out
@@ -0,0 +1,6 @@
+Warning The following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed:
+┠─ npm:@denotest/node-lifecycle-scripts@1.0.0
+┃
+┠─ This may cause the packages to not work correctly.
+┖─ To run lifecycle scripts, use the `--allow-scripts` flag with `deno install`:
+ deno install --allow-scripts=npm:@denotest/node-lifecycle-scripts@1.0.0