diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 63997dc9ce..22117990d2 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -109,6 +109,25 @@ pub fn graph_valid( } } +pub fn fill_graph_from_lockfile( + graph: &mut ModuleGraph, + lockfile: &deno_lockfile::Lockfile, +) { + graph.fill_from_lockfile(FillFromLockfileOptions { + redirects: lockfile + .content + .redirects + .iter() + .map(|(from, to)| (from.as_str(), to.as_str())), + package_specifiers: lockfile + .content + .packages + .specifiers + .iter() + .map(|(dep, id)| (dep, id.as_str())), + }); +} + #[derive(Clone)] pub struct GraphWalkErrorsOptions { pub check_js: bool, @@ -603,19 +622,7 @@ impl ModuleGraphBuilder { // populate the information from the lockfile if let Some(lockfile) = &self.lockfile { let lockfile = lockfile.lock(); - graph.fill_from_lockfile(FillFromLockfileOptions { - redirects: lockfile - .content - .redirects - .iter() - .map(|(from, to)| (from.as_str(), to.as_str())), - package_specifiers: lockfile - .content - .packages - .specifiers - .iter() - .map(|(dep, id)| (dep, id.as_str())), - }); + fill_graph_from_lockfile(graph, &lockfile); } } diff --git a/cli/tools/registry/pm/cache_deps.rs b/cli/tools/registry/pm/cache_deps.rs index f9d67e4d4f..dbec8a3b3f 100644 --- a/cli/tools/registry/pm/cache_deps.rs +++ b/cli/tools/registry/pm/cache_deps.rs @@ -1,5 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; use std::sync::Arc; use crate::factory::CliFactory; @@ -37,6 +38,16 @@ pub async fn cache_top_level_deps( factory.file_fetcher()?.clone(), )) }; + let mut graph_permit = factory + .main_module_graph_container() + .await? + .acquire_update_permit() + .await; + let graph = graph_permit.graph_mut(); + if let Some(lockfile) = cli_options.maybe_lockfile() { + let lockfile = lockfile.lock(); + crate::graph_util::fill_graph_from_lockfile(graph, &lockfile); + } let mut roots = Vec::new(); @@ -67,13 +78,16 @@ pub async fn cache_top_level_deps( if !seen_reqs.insert(req.req().clone()) { continue; } + let resolved_req = graph.packages.mappings().get(req.req()); let jsr_resolver = jsr_resolver.clone(); info_futures.push(async move { - if let Some(nv) = jsr_resolver.req_to_nv(req.req()).await { - if let Some(info) = jsr_resolver.package_version_info(&nv).await - { - return Some((specifier.clone(), info)); - } + let nv = if let Some(req) = resolved_req { + Cow::Borrowed(req) + } else { + Cow::Owned(jsr_resolver.req_to_nv(req.req()).await?) + }; + if let Some(info) = jsr_resolver.package_version_info(&nv).await { + return Some((specifier.clone(), info)); } None }); @@ -106,12 +120,8 @@ pub async fn cache_top_level_deps( } } } - let mut graph_permit = factory - .main_module_graph_container() - .await? - .acquire_update_permit() - .await; - let graph = graph_permit.graph_mut(); + drop(info_futures); + factory .module_load_preparer() .await? diff --git a/cli/tools/registry/pm/deps.rs b/cli/tools/registry/pm/deps.rs index b7e1c0f0d4..d82e9954cd 100644 --- a/cli/tools/registry/pm/deps.rs +++ b/cli/tools/registry/pm/deps.rs @@ -18,7 +18,6 @@ use deno_core::futures::stream::FuturesUnordered; use deno_core::futures::FutureExt; use deno_core::futures::StreamExt; use deno_core::serde_json; -use deno_graph::FillFromLockfileOptions; use deno_package_json::PackageJsonDepsMap; use deno_package_json::PackageJsonRc; use deno_runtime::deno_permissions::PermissionsContainer; @@ -533,19 +532,8 @@ impl DepManager { // populate the information from the lockfile if let Some(lockfile) = &self.lockfile { let lockfile = lockfile.lock(); - graph.fill_from_lockfile(FillFromLockfileOptions { - redirects: lockfile - .content - .redirects - .iter() - .map(|(from, to)| (from.as_str(), to.as_str())), - package_specifiers: lockfile - .content - .packages - .specifiers - .iter() - .map(|(dep, id)| (dep, id.as_str())), - }); + + crate::graph_util::fill_graph_from_lockfile(graph, &lockfile); } let npm_resolver = self.npm_resolver.as_managed().unwrap(); diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.7.0/add.ts b/tests/registry/jsr/@denotest/multiple-exports/0.7.0/add.ts new file mode 100644 index 0000000000..de02f69024 --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.7.0/add.ts @@ -0,0 +1 @@ +export * from "jsr:@denotest/add@1"; diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.7.0/data.json b/tests/registry/jsr/@denotest/multiple-exports/0.7.0/data.json new file mode 100644 index 0000000000..885e71c6cc --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.7.0/data.json @@ -0,0 +1,3 @@ +{ + "a": 1 +} \ No newline at end of file diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.7.0/subtract.ts b/tests/registry/jsr/@denotest/multiple-exports/0.7.0/subtract.ts new file mode 100644 index 0000000000..215c42310d --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.7.0/subtract.ts @@ -0,0 +1 @@ +export * from "jsr:@denotest/subtract@1"; diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.7.0_meta.json b/tests/registry/jsr/@denotest/multiple-exports/0.7.0_meta.json new file mode 100644 index 0000000000..d9f58b9a61 --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.7.0_meta.json @@ -0,0 +1,7 @@ +{ + "exports": { + "./add": "./add.ts", + "./subtract": "./subtract.ts", + "./data-json": "./data.json" + } +} diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.7.1/add.ts b/tests/registry/jsr/@denotest/multiple-exports/0.7.1/add.ts new file mode 100644 index 0000000000..de02f69024 --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.7.1/add.ts @@ -0,0 +1 @@ +export * from "jsr:@denotest/add@1"; diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.7.1/data.json b/tests/registry/jsr/@denotest/multiple-exports/0.7.1/data.json new file mode 100644 index 0000000000..885e71c6cc --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.7.1/data.json @@ -0,0 +1,3 @@ +{ + "a": 1 +} \ No newline at end of file diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.7.1/multiply.ts b/tests/registry/jsr/@denotest/multiple-exports/0.7.1/multiply.ts new file mode 100644 index 0000000000..ce87b38fc8 --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.7.1/multiply.ts @@ -0,0 +1,3 @@ +export function multiply(a: number, b: number): number { + return a * b; +} \ No newline at end of file diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.7.1/subtract.ts b/tests/registry/jsr/@denotest/multiple-exports/0.7.1/subtract.ts new file mode 100644 index 0000000000..215c42310d --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.7.1/subtract.ts @@ -0,0 +1 @@ +export * from "jsr:@denotest/subtract@1"; diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.7.1_meta.json b/tests/registry/jsr/@denotest/multiple-exports/0.7.1_meta.json new file mode 100644 index 0000000000..2897812168 --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.7.1_meta.json @@ -0,0 +1,8 @@ +{ + "exports": { + "./add": "./add.ts", + "./subtract": "./subtract.ts", + "./data-json": "./data.json", + "./multiply": "./multiply.ts" + } +} diff --git a/tests/registry/jsr/@denotest/multiple-exports/meta.json b/tests/registry/jsr/@denotest/multiple-exports/meta.json index aaaf18a184..c545ae8f46 100644 --- a/tests/registry/jsr/@denotest/multiple-exports/meta.json +++ b/tests/registry/jsr/@denotest/multiple-exports/meta.json @@ -1,6 +1,8 @@ { "versions": { "1.0.0": {}, + "0.7.1": {}, + "0.7.0": {}, "0.5.0": {}, "0.2.0": {} } diff --git a/tests/specs/install/jsr_exports_uses_locked/__test__.jsonc b/tests/specs/install/jsr_exports_uses_locked/__test__.jsonc new file mode 100644 index 0000000000..254fe8b989 --- /dev/null +++ b/tests/specs/install/jsr_exports_uses_locked/__test__.jsonc @@ -0,0 +1,9 @@ +{ + "tempDir": true, + "steps": [ + { + "args": "install", + "output": "install.out" + } + ] +} diff --git a/tests/specs/install/jsr_exports_uses_locked/deno.json b/tests/specs/install/jsr_exports_uses_locked/deno.json new file mode 100644 index 0000000000..0ede5a3a1d --- /dev/null +++ b/tests/specs/install/jsr_exports_uses_locked/deno.json @@ -0,0 +1,5 @@ +{ + "imports": { + "@denotest/multiple-exports": "jsr:@denotest/multiple-exports@^0.7.0" + } +} diff --git a/tests/specs/install/jsr_exports_uses_locked/deno.lock b/tests/specs/install/jsr_exports_uses_locked/deno.lock new file mode 100644 index 0000000000..cd27474396 --- /dev/null +++ b/tests/specs/install/jsr_exports_uses_locked/deno.lock @@ -0,0 +1,28 @@ +{ + "version": "4", + "specifiers": { + "jsr:@denotest/add@1": "1.0.0", + "jsr:@denotest/multiple-exports@0.7": "0.7.0", + "jsr:@denotest/subtract@1": "1.0.0" + }, + "jsr": { + "@denotest/add@1.0.0": { + "integrity": "3b2e675c1ad7fba2a45bc251992e01aff08a3c974ac09079b11e6a5b95d4bfcb" + }, + "@denotest/multiple-exports@0.7.0": { + "integrity": "efe9748a0c0939c7ac245fee04acc0c42bd7a61874ff71a360c4543e4f5f6b36", + "dependencies": [ + "jsr:@denotest/add", + "jsr:@denotest/subtract" + ] + }, + "@denotest/subtract@1.0.0": { + "integrity": "e178a7101c073e93d9efa6833d5cbf83bc1bc8d509b7c2a5ecbf74265e917597" + } + }, + "workspace": { + "dependencies": [ + "jsr:@denotest/multiple-exports@0.7" + ] + } +} diff --git a/tests/specs/install/jsr_exports_uses_locked/install.out b/tests/specs/install/jsr_exports_uses_locked/install.out new file mode 100644 index 0000000000..b4e8b640f6 --- /dev/null +++ b/tests/specs/install/jsr_exports_uses_locked/install.out @@ -0,0 +1,13 @@ +[UNORDERED_START] +Download http://127.0.0.1:4250/@denotest/multiple-exports/0.7.0_meta.json +Download http://127.0.0.1:4250/@denotest/multiple-exports/meta.json +Download http://127.0.0.1:4250/@denotest/multiple-exports/0.7.0/add.ts +Download http://127.0.0.1:4250/@denotest/multiple-exports/0.7.0/subtract.ts +Download http://127.0.0.1:4250/@denotest/multiple-exports/0.7.0/data.json +Download http://127.0.0.1:4250/@denotest/add/meta.json +Download http://127.0.0.1:4250/@denotest/subtract/meta.json +Download http://127.0.0.1:4250/@denotest/add/1.0.0_meta.json +Download http://127.0.0.1:4250/@denotest/subtract/1.0.0_meta.json +Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts +Download http://127.0.0.1:4250/@denotest/subtract/1.0.0/mod.ts +[UNORDERED_END]