Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(install): use locked version of jsr package when fetching exports #27237

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions cli/graph_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}

Expand Down
32 changes: 21 additions & 11 deletions cli/tools/registry/pm/cache_deps.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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?
Expand Down
16 changes: 2 additions & 14 deletions cli/tools/registry/pm/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions tests/registry/jsr/@denotest/multiple-exports/0.7.0/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "jsr:@denotest/add@1";
3 changes: 3 additions & 0 deletions tests/registry/jsr/@denotest/multiple-exports/0.7.0/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"a": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "jsr:@denotest/subtract@1";
7 changes: 7 additions & 0 deletions tests/registry/jsr/@denotest/multiple-exports/0.7.0_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"exports": {
"./add": "./add.ts",
"./subtract": "./subtract.ts",
"./data-json": "./data.json"
}
}
1 change: 1 addition & 0 deletions tests/registry/jsr/@denotest/multiple-exports/0.7.1/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "jsr:@denotest/add@1";
3 changes: 3 additions & 0 deletions tests/registry/jsr/@denotest/multiple-exports/0.7.1/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"a": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function multiply(a: number, b: number): number {
return a * b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "jsr:@denotest/subtract@1";
8 changes: 8 additions & 0 deletions tests/registry/jsr/@denotest/multiple-exports/0.7.1_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"exports": {
"./add": "./add.ts",
"./subtract": "./subtract.ts",
"./data-json": "./data.json",
"./multiply": "./multiply.ts"
}
}
2 changes: 2 additions & 0 deletions tests/registry/jsr/@denotest/multiple-exports/meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"versions": {
"1.0.0": {},
"0.7.1": {},
"0.7.0": {},
"0.5.0": {},
"0.2.0": {}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/specs/install/jsr_exports_uses_locked/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tempDir": true,
"steps": [
{
"args": "install",
"output": "install.out"
}
]
}
5 changes: 5 additions & 0 deletions tests/specs/install/jsr_exports_uses_locked/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"imports": {
"@denotest/multiple-exports": "jsr:@denotest/multiple-exports@^0.7.0"
}
}
28 changes: 28 additions & 0 deletions tests/specs/install/jsr_exports_uses_locked/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/specs/install/jsr_exports_uses_locked/install.out
Original file line number Diff line number Diff line change
@@ -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]
Loading