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(cli): Warn on not-run lifecycle scripts with global cache #25786

Merged
merged 18 commits into from
Sep 24, 2024
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
Prev Previous commit
Next Next commit
Match style of local resolver warning + tweak box drawing
  • Loading branch information
nathanwhit committed Sep 21, 2024
commit d8e3d505ba78a6311ab4197a62741ddafa3dac73
6 changes: 0 additions & 6 deletions cli/npm/managed/resolvers/common/lifecycle_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ impl<'a> LifecycleScripts<'a> {
package_path: Cow<Path>,
) {
if has_lifecycle_scripts(package, &package_path) {
eprintln!(
"has lifecycle scripts! {} {}",
package.id.nv,
std::backtrace::Backtrace::capture()
);
if self.can_run_scripts(&package.id.nv) {
if !self.strategy.has_run(package) {
self
Expand All @@ -116,7 +111,6 @@ impl<'a> LifecycleScripts<'a> {
} else if !self.strategy.has_run(package)
&& !self.strategy.has_warned(package)
{
eprintln!("packages with scripts not run: {}", package.id.nv);
self
.packages_with_scripts_not_run
.push((package, package_path.into_owned()));
Expand Down
24 changes: 17 additions & 7 deletions cli/npm/managed/resolvers/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;

use crate::colors;
use async_trait::async_trait;
use deno_ast::ModuleSpecifier;
use deno_core::error::AnyError;
Expand Down Expand Up @@ -230,13 +231,22 @@ impl<'a> super::common::lifecycle_scripts::LifecycleScriptsStrategy
&self,
packages: &[(&NpmResolutionPackage, PathBuf)],
) -> std::result::Result<(), deno_core::anyhow::Error> {
let packages_str = packages
.iter()
.map(|(package, _)| package.id.nv.to_string())
.collect::<Vec<String>>()
.join(", ");
log::warn!("{}: The following packages contained npm lifecycle scripts that were not executed: {}
Lifecycle scripts are only supported when using a local `node_modules` directory. Add `{}` to your deno config to enable it.", crate::colors::yellow("warning"), crate::colors::cyan(&packages_str), crate::colors::cyan("\"nodeModulesDir\": \"auto\""));
log::warn!("{} The following packages contained npm lifecycle scripts ({}) that were not executed:", colors::yellow("Warning"), colors::gray("preinstall/install/postinstall"));
for (package, _) in packages {
log::warn!("┠─ {}", colors::gray(format!("npm:{}", package.id.nv)));
}
log::warn!("┃");
log::warn!(
"┠─ {}",
colors::italic("This may cause the packages to not work correctly.")
);
log::warn!("┠─ {}", colors::italic("Lifecycle scripts are only supported when using a `node_modules` directory."));
log::warn!(
"┠─ {}",
colors::italic("Enable it in your deno config file:")
);
log::warn!("┖─ {}", colors::bold("\"nodeModulesDir\": \"auto\""));

for (package, _) in packages {
std::fs::write(self.warned_scripts_file(package), "")?;
}
Expand Down
4 changes: 2 additions & 2 deletions cli/npm/managed/resolvers/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ async fn sync_resolution_with_fs(
);
} else {
log::warn!(
"─ {}",
"─ {}",
colors::gray(format!("npm:{:?} ({})", package_id, msg))
);
}
Expand Down Expand Up @@ -747,7 +747,7 @@ impl<'a> super::common::lifecycle_scripts::LifecycleScriptsStrategy
"┠─ {}",
colors::italic("This may cause the packages to not work correctly.")
);
log::warn!("─ {}", colors::italic("To run lifecycle scripts, use the `--allow-scripts` flag with `deno install`:"));
log::warn!("─ {}", colors::italic("To run lifecycle scripts, use the `--allow-scripts` flag with `deno install`:"));
let packages_comma_separated = packages
.iter()
.map(|(p, _)| format!("npm:{}", p.id.nv))
Expand Down
4 changes: 2 additions & 2 deletions tests/specs/install/install_deprecated_package/install.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Add npm:@denotest/[email protected]
Download http://localhost:4260/@denotest/deprecated-package
Download http://localhost:4260/@denotest/deprecated-package/1.0.0.tgz
Initialize @denotest/[email protected]
Warning Following packages are deprecated:
─ npm:@denotest/[email protected] (Deprecated version)
Warning The following packages are deprecated:
─ npm:@denotest/[email protected] (Deprecated version)
4 changes: 2 additions & 2 deletions tests/specs/npm/lifecycle_scripts/all_lifecycles_not_run.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Download http://localhost:4260/@denotest/bin/1.0.0.tgz
Initialize @denotest/[email protected]
Initialize @denotest/[email protected]
[UNORDERED_END]
Warning Following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed:
Warning The following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed:
┠─ npm:@denotest/[email protected]
┠─ This may cause the packages to not work correctly.
─ To run lifecycle scripts, use the `--allow-scripts` flag with `deno install`:
─ To run lifecycle scripts, use the `--allow-scripts` flag with `deno install`:
deno install --allow-scripts=npm:@denotest/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ Download http://localhost:4260/@denotest/bin
Download http://localhost:4260/@denotest/node-lifecycle-scripts/1.0.0.tgz
Download http://localhost:4260/@denotest/bin/1.0.0.tgz
[UNORDERED_END]
warning: The following packages contained npm lifecycle scripts that were not executed: @denotest/[email protected]
Lifecycle scripts are only supported when using a local `node_modules` directory. Add `"nodeModulesDir": "auto"` to your deno config to enable it.
Warning The following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed:
┠─ npm:@denotest/[email protected]
┠─ 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"
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Download http://localhost:4260/@denotest/bin/1.0.0.tgz
Initialize @denotest/[email protected]
Initialize @denotest/[email protected]
[UNORDERED_END]
Warning Following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed:
Warning The following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed:
┠─ npm:@denotest/[email protected]
┠─ This may cause the packages to not work correctly.
─ To run lifecycle scripts, use the `--allow-scripts` flag with `deno install`:
─ To run lifecycle scripts, use the `--allow-scripts` flag with `deno install`:
deno install --allow-scripts=npm:@denotest/[email protected]
4 changes: 2 additions & 2 deletions tests/specs/npm/lifecycle_scripts/node_gyp_not_run.out
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Download http://localhost:4260/@denotest/node-addon
Download http://localhost:4260/node-gyp
[WILDCARD]
Warning Following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed:
Warning The following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed:
┠─ npm:@denotest/[email protected]
┠─ This may cause the packages to not work correctly.
─ To run lifecycle scripts, use the `--allow-scripts` flag with `deno install`:
─ To run lifecycle scripts, use the `--allow-scripts` flag with `deno install`:
deno install --allow-scripts=npm:@denotest/[email protected]
error: Uncaught (in promise) Error: Cannot find module './build/Release/node_addon'
[WILDCARD]
4 changes: 2 additions & 2 deletions tests/specs/npm/lifecycle_scripts/only_warns_first1.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Download http://localhost:4260/@denotest/bin/1.0.0.tgz
Initialize @denotest/[email protected]
Initialize @denotest/[email protected]
[UNORDERED_END]
Warning Following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed:
Warning The following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed:
┠─ npm:@denotest/[email protected]
┠─ This may cause the packages to not work correctly.
─ To run lifecycle scripts, use the `--allow-scripts` flag with `deno install`:
─ To run lifecycle scripts, use the `--allow-scripts` flag with `deno install`:
deno install --allow-scripts=npm:@denotest/[email protected]
error: Uncaught SyntaxError: The requested module 'npm:@denotest/node-lifecycle-scripts' does not provide an export named 'value'
[WILDCARD]