diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-09-18 10:46:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-18 10:46:44 -0400 |
commit | 0709c051f83c181206f6653396f5428df66ed74f (patch) | |
tree | 9360ce6cfc2c3f3f53a8a7af0f9d3bdc9e1ee553 /cli/graph_util.rs | |
parent | 4fcd9a0de815a756e5f173e1bc1f84d90ba39ec7 (diff) |
feat(unstable): package manager (#20517)
Adds an experimental unstable built-in package manager to Deno, but it is
currently not usable because the registry infrastructure hasn't been
setup and it points to a non-existent url by default. The default
registry url can be configured via the `DENO_REGISTRY_URL` environment
variable.
Diffstat (limited to 'cli/graph_util.rs')
-rw-r--r-- | cli/graph_util.rs | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 1a5a293a7..e567bebb5 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -32,6 +32,8 @@ use deno_graph::ResolutionError; use deno_graph::SpecifierError; use deno_runtime::deno_node; use deno_runtime::permissions::PermissionsContainer; +use deno_semver::package::PackageNv; +use deno_semver::package::PackageReq; use import_map::ImportMapError; use std::collections::HashMap; use std::collections::HashSet; @@ -331,9 +333,7 @@ impl ModuleGraphBuilder { for (from, to) in &lockfile.content.redirects { if let Ok(from) = ModuleSpecifier::parse(from) { if let Ok(to) = ModuleSpecifier::parse(to) { - if !matches!(from.scheme(), "file" | "npm") - && !matches!(to.scheme(), "file" | "npm") - { + if !matches!(from.scheme(), "file" | "npm" | "jsr") { graph.redirects.insert(from, to); } } @@ -342,26 +342,25 @@ impl ModuleGraphBuilder { } } - // todo(dsherret): uncomment when adding deno: specifier support - // add the deno specifiers to the graph if it's the first time executing - // if graph.deno_specifiers.is_empty() { - // if let Some(lockfile) = &self.lockfile { - // let lockfile = lockfile.lock(); - // for (key, value) in &lockfile.content.packages.specifiers { - // if let Some(key) = key - // .strip_prefix("deno:") - // .and_then(|key| PackageReq::from_str(key)) - // { - // if let Ok(value) = value - // .strip_prefix("deno:") - // .and_then(|value| PackageNv::from_str(value)) - // { - // graph.deno_specifiers.add(key, value); - // } - // } - // } - // } - // } + // add the jsr specifiers to the graph if it's the first time executing + if graph.packages.is_empty() { + if let Some(lockfile) = &self.lockfile { + let lockfile = lockfile.lock(); + for (key, value) in &lockfile.content.packages.specifiers { + if let Some(key) = key + .strip_prefix("jsr:") + .and_then(|key| PackageReq::from_str(key).ok()) + { + if let Some(value) = value + .strip_prefix("jsr:") + .and_then(|value| PackageNv::from_str(value).ok()) + { + graph.packages.add(key, value); + } + } + } + } + } graph.build(roots, loader, options).await; @@ -378,20 +377,19 @@ impl ModuleGraphBuilder { } } - // todo(dsherret): uncomment when adding support for deno specifiers - // add the deno specifiers in the graph to the lockfile - // if !graph.deno_specifiers.is_empty() { - // if let Some(lockfile) = &self.lockfile { - // let mappings = graph.deno_specifiers.mappings(); - // let mut lockfile = lockfile.lock(); - // for (from, to) in mappings { - // lockfile.insert_package_specifier( - // format!("deno:{}", from), - // format!("deno:{}", to), - // ); - // } - // } - // } + // add the jsr specifiers in the graph to the lockfile + if !graph.packages.is_empty() { + if let Some(lockfile) = &self.lockfile { + let mappings = graph.packages.mappings(); + let mut lockfile = lockfile.lock(); + for (from, to) in mappings { + lockfile.insert_package_specifier( + format!("jsr:{}", from), + format!("jsr:{}", to), + ); + } + } + } // ensure that the top level package.json is installed if a // specifier was matched in the package.json |