summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-02-24 19:35:43 -0500
committerGitHub <noreply@github.com>2023-02-24 19:35:43 -0500
commit033b70af19300a4e34dcf19ab0031245bfc19625 (patch)
treeebcd8e9ebd85a974c9845af0291ab3bdb9765704 /cli/tools
parent5683daf1aa1c01f5f4d01879d6ce054b0922faf6 (diff)
fix(npm): lazily install package.json dependencies only when necessary (#17931)
This lazily does an "npm install" when any package name matches what's found in the package.json or when running a script from package.json with deno task. Part of #17916 Closes #17928
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/task.rs5
-rw-r--r--cli/tools/vendor/test.rs8
2 files changed, 12 insertions, 1 deletions
diff --git a/cli/tools/task.rs b/cli/tools/task.rs
index 721c47696..9b76f256c 100644
--- a/cli/tools/task.rs
+++ b/cli/tools/task.rs
@@ -60,6 +60,11 @@ pub async fn execute_script(
.await;
Ok(exit_code)
} else if let Some(script) = package_json_scripts.get(task_name) {
+ ps.package_json_deps_installer
+ .ensure_top_level_install()
+ .await?;
+ ps.npm_resolver.resolve_pending().await?;
+
let cwd = match task_flags.cwd {
Some(path) => canonicalize_path(&PathBuf::from(path))?,
None => maybe_package_json
diff --git a/cli/tools/vendor/test.rs b/cli/tools/vendor/test.rs
index aed2a852c..bf34fc185 100644
--- a/cli/tools/vendor/test.rs
+++ b/cli/tools/vendor/test.rs
@@ -22,6 +22,7 @@ use import_map::ImportMap;
use crate::cache::ParsedSourceCache;
use crate::npm::NpmRegistryApi;
use crate::npm::NpmResolution;
+use crate::npm::PackageJsonDepsInstaller;
use crate::resolver::CliGraphResolver;
use super::build::VendorEnvironment;
@@ -266,13 +267,18 @@ async fn build_test_graph(
let npm_registry_api = NpmRegistryApi::new_uninitialized();
let npm_resolution =
NpmResolution::new(npm_registry_api.clone(), None, None);
+ let deps_installer = PackageJsonDepsInstaller::new(
+ npm_registry_api.clone(),
+ npm_resolution.clone(),
+ None,
+ );
CliGraphResolver::new(
None,
Some(Arc::new(m)),
false,
npm_registry_api,
npm_resolution,
- None,
+ deps_installer,
)
});
let mut graph = ModuleGraph::default();