1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

fix(npm): only warn about lifecycle scripts not being run when setting up directory (#24530)

Closes #24518
This commit is contained in:
David Sherret 2024-07-11 12:41:42 -04:00 committed by GitHub
parent de30f7c188
commit f950f59983
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 41 additions and 3 deletions

View file

@ -506,6 +506,7 @@ async fn sync_resolution_with_fs(
if has_lifecycle_scripts(package) { if has_lifecycle_scripts(package) {
let scripts_run = folder_path.join(".scripts-run"); let scripts_run = folder_path.join(".scripts-run");
let has_warned = folder_path.join(".scripts-warned");
if can_run_scripts(&lifecycle_scripts.allowed, &package.id.nv) { if can_run_scripts(&lifecycle_scripts.allowed, &package.id.nv) {
if !scripts_run.exists() { if !scripts_run.exists() {
let sub_node_modules = folder_path.join("node_modules"); let sub_node_modules = folder_path.join("node_modules");
@ -517,8 +518,8 @@ async fn sync_resolution_with_fs(
scripts_run, scripts_run,
)); ));
} }
} else if !scripts_run.exists() { } else if !scripts_run.exists() && !has_warned.exists() {
packages_with_scripts_not_run.push(package.id.nv.clone()); packages_with_scripts_not_run.push((has_warned, package.id.nv.clone()));
} }
} }
} }
@ -721,12 +722,15 @@ async fn sync_resolution_with_fs(
}; };
let packages = packages_with_scripts_not_run let packages = packages_with_scripts_not_run
.iter() .iter()
.map(|p| format!("npm:{p}")) .map(|(_, p)| format!("npm:{p}"))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "); .join(", ");
log::warn!("{}: Packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed. log::warn!("{}: Packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed.
This may cause the packages to not work correctly. To run them, use the `--allow-scripts` flag with `deno cache`{maybe_install} This may cause the packages to not work correctly. To run them, use the `--allow-scripts` flag with `deno cache`{maybe_install}
(e.g. `deno cache --allow-scripts=pkg1,pkg2 <entrypoint>`{maybe_install_example}):\n {packages}", crate::colors::yellow("warning")); (e.g. `deno cache --allow-scripts=pkg1,pkg2 <entrypoint>`{maybe_install_example}):\n {packages}", crate::colors::yellow("warning"));
for (scripts_warned_path, _) in packages_with_scripts_not_run {
let _ignore_err = fs::write(scripts_warned_path, "");
}
} }
setup_cache.save(); setup_cache.save();

View file

@ -55,6 +55,23 @@
} }
] ]
}, },
"only_warns_first": {
"tempDir": true,
"steps": [
{
// without running scripts (should warn)
"args": "run all_lifecycles.js",
"output": "only_warns_first1.out",
"exitCode": 1
},
{
// without running scripts (does not warn)
"args": "run all_lifecycles.js",
"output": "only_warns_first2.out",
"exitCode": 1
}
]
},
"future_install_lifecycle_scripts": { "future_install_lifecycle_scripts": {
"tempDir": true, "tempDir": true,
"envs": { "envs": {

View file

@ -0,0 +1,14 @@
[UNORDERED_START]
Download http://localhost:4260/@denotest/node-lifecycle-scripts
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
Initialize @denotest/node-lifecycle-scripts@1.0.0
Initialize @denotest/bin@1.0.0
[UNORDERED_END]
warning: Packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed.
This may cause the packages to not work correctly. To run them, use the `--allow-scripts` flag with `deno cache`
(e.g. `deno cache --allow-scripts=pkg1,pkg2 <entrypoint>`):
npm:@denotest/node-lifecycle-scripts@1.0.0
error: Uncaught SyntaxError: The requested module 'npm:@denotest/node-lifecycle-scripts' does not provide an export named 'value'
[WILDCARD]

View file

@ -0,0 +1,3 @@
[# note no warning]
error: Uncaught SyntaxError: The requested module 'npm:@denotest/node-lifecycle-scripts' does not provide an export named 'value'
[WILDCARD]