summaryrefslogtreecommitdiff
path: root/cli/graph_util.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-05-23 18:51:48 -0400
committerGitHub <noreply@github.com>2023-05-23 18:51:48 -0400
commitcacc8c9a4debe6a7d32f743ab9b2f636ae51dec1 (patch)
tree96738ecddb72a2f54a0a7f57b478d774d0882dee /cli/graph_util.rs
parent01a95d677f897776e6478ef6c728f85a8d44002c (diff)
feat: top level package.json install when node_modules dir is explicitly opted into (#19233)
When someone explicitly opts into using the node_modules dir via `--node-modules-dir` or setting `"nodeModulesDir": true` in the deno.json file, we should eagerly ensure a top level package.json install is done on startup. This was initially always done when we added package.json support and a package.json was auto-discovered, but scaled it back to be lazily done when a bare specifier matched an entry in the package.json because of how disruptive it was for people using Deno scripts in Node projects. That said, it does not make sense for someone to opt-into having deno control and use their node_modules directory and not want a package.json install to occur. If such a rare scenario exists, the `DENO_NO_PACKAGE_JSON=1` environment variable can be set. Ideally, we would only ever use a node_modules directory with this explicit opt-in so everything is very clear, but we still have this automatic scenario when there's a package.json in order to make more node projects work out of the box.
Diffstat (limited to 'cli/graph_util.rs')
-rw-r--r--cli/graph_util.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/cli/graph_util.rs b/cli/graph_util.rs
index 53d06071c..90c4f8b38 100644
--- a/cli/graph_util.rs
+++ b/cli/graph_util.rs
@@ -296,6 +296,12 @@ impl ModuleGraphBuilder {
loader: &mut dyn deno_graph::source::Loader,
options: deno_graph::BuildOptions<'a>,
) -> Result<(), AnyError> {
+ // ensure an "npm install" is done if the user has explicitly
+ // opted into using a node_modules directory
+ if self.options.node_modules_dir_enablement() == Some(true) {
+ self.resolver.force_top_level_package_json_install().await?;
+ }
+
graph.build(roots, loader, options).await;
// ensure that the top level package.json is installed if a