diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-05-08 20:34:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-08 12:34:46 -0700 |
commit | 4e23a5b1fc2ba0e26f1832a2c374a1f3aef9e7ff (patch) | |
tree | 4e71d07cce253b3a8035285e11999c1294643074 /cli/module_loader.rs | |
parent | 525b3c8d746b8eb358ed6466cd4b68ebd6542392 (diff) |
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 <pkg>` 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 <bin>` installs a package as a globally available
binary (the same as `deno install <bin>` in 1.0)
---------
Co-authored-by: Nathan Whitaker <nathan@deno.com>
Diffstat (limited to 'cli/module_loader.rs')
-rw-r--r-- | cli/module_loader.rs | 35 |
1 files changed, 35 insertions, 0 deletions
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<CliOptions>, graph_container: Arc<ModuleGraphContainer>, |