From 4e23a5b1fc2ba0e26f1832a2c374a1f3aef9e7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 8 May 2024 20:34:46 +0100 Subject: FUTURE: `deno install` changes (#23498) This PR implements the changes we plan to make to `deno install` in deno 2.0. - `deno install` without arguments caches dependencies from `package.json` / `deno.json` and sets up the `node_modules` folder - `deno install ` adds the package to the config file (either `package.json` or `deno.json`), i.e. it aliases `deno add` - `deno add` can also add deps to `package.json` (this is gated behind `DENO_FUTURE` due to uncertainty around handling projects with both `deno.json` and `package.json`) - `deno install -g ` installs a package as a globally available binary (the same as `deno install ` in 1.0) --------- Co-authored-by: Nathan Whitaker --- cli/module_loader.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'cli/module_loader.rs') diff --git a/cli/module_loader.rs b/cli/module_loader.rs index a6c8d1338..7d8cb130b 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -8,6 +8,7 @@ use crate::cache::CodeCache; use crate::cache::ModuleInfoCache; use crate::cache::ParsedSourceCache; use crate::emit::Emitter; +use crate::factory::CliFactory; use crate::graph_util::graph_lock_or_exit; use crate::graph_util::CreateGraphOptions; use crate::graph_util::ModuleGraphBuilder; @@ -64,6 +65,40 @@ use std::rc::Rc; use std::str; use std::sync::Arc; +pub async fn load_top_level_deps(factory: &CliFactory) -> Result<(), AnyError> { + let npm_resolver = factory.npm_resolver().await?; + if let Some(npm_resolver) = npm_resolver.as_managed() { + npm_resolver.ensure_top_level_package_json_install().await?; + npm_resolver.resolve_pending().await?; + } + // cache as many entries in the import map as we can + if let Some(import_map) = factory.maybe_import_map().await? { + let roots = import_map + .imports() + .entries() + .filter_map(|entry| { + if entry.key.ends_with('/') { + None + } else { + entry.value.cloned() + } + }) + .collect(); + factory + .module_load_preparer() + .await? + .prepare_module_load( + roots, + false, + factory.cli_options().ts_type_lib_window(), + deno_runtime::permissions::PermissionsContainer::allow_all(), + ) + .await?; + } + + Ok(()) +} + pub struct ModuleLoadPreparer { options: Arc, graph_container: Arc, -- cgit v1.2.3