diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-02-24 19:35:43 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-24 19:35:43 -0500 |
commit | 033b70af19300a4e34dcf19ab0031245bfc19625 (patch) | |
tree | ebcd8e9ebd85a974c9845af0291ab3bdb9765704 /cli/node/mod.rs | |
parent | 5683daf1aa1c01f5f4d01879d6ce054b0922faf6 (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/node/mod.rs')
-rw-r--r-- | cli/node/mod.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/cli/node/mod.rs b/cli/node/mod.rs index 470003057..e45694fd6 100644 --- a/cli/node/mod.rs +++ b/cli/node/mod.rs @@ -40,6 +40,7 @@ use regex::Regex; use crate::cache::NodeAnalysisCache; use crate::file_fetcher::FileFetcher; use crate::npm::NpmPackageResolver; +use crate::util::fs::canonicalize_path_maybe_not_exists; mod analyze; @@ -285,6 +286,25 @@ pub fn node_resolve_npm_reference( Ok(Some(resolve_response)) } +/// Resolves a specifier that is pointing into a node_modules folder. +/// +/// Note: This should be called whenever getting the specifier from +/// a Module::External(module) reference because that module might +/// not be fully resolved at the time deno_graph is analyzing it +/// because the node_modules folder might not exist at that time. +pub fn resolve_specifier_into_node_modules( + specifier: &ModuleSpecifier, +) -> ModuleSpecifier { + specifier + .to_file_path() + .ok() + // this path might not exist at the time the graph is being created + // because the node_modules folder might not yet exist + .and_then(|path| canonicalize_path_maybe_not_exists(&path).ok()) + .and_then(|path| ModuleSpecifier::from_file_path(path).ok()) + .unwrap_or_else(|| specifier.clone()) +} + pub fn node_resolve_binary_commands( pkg_nv: &NpmPackageNv, npm_resolver: &NpmPackageResolver, |