1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 13:00:36 -05:00

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

Fixes #27193.
This commit is contained in:
Nathan Whitaker 2024-12-05 13:55:35 -05:00 committed by GitHub
parent f098dd02f7
commit ffac282805
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 128 additions and 38 deletions

View file

@ -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)] #[derive(Clone)]
pub struct GraphWalkErrorsOptions { pub struct GraphWalkErrorsOptions {
pub check_js: bool, pub check_js: bool,
@ -603,19 +622,7 @@ impl ModuleGraphBuilder {
// populate the information from the lockfile // populate the information from the lockfile
if let Some(lockfile) = &self.lockfile { if let Some(lockfile) = &self.lockfile {
let lockfile = lockfile.lock(); let lockfile = lockfile.lock();
graph.fill_from_lockfile(FillFromLockfileOptions { fill_graph_from_lockfile(graph, &lockfile);
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())),
});
} }
} }

View file

@ -1,5 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use std::borrow::Cow;
use std::sync::Arc; use std::sync::Arc;
use crate::factory::CliFactory; use crate::factory::CliFactory;
@ -37,6 +38,16 @@ pub async fn cache_top_level_deps(
factory.file_fetcher()?.clone(), 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(); let mut roots = Vec::new();
@ -67,13 +78,16 @@ pub async fn cache_top_level_deps(
if !seen_reqs.insert(req.req().clone()) { if !seen_reqs.insert(req.req().clone()) {
continue; continue;
} }
let resolved_req = graph.packages.mappings().get(req.req());
let jsr_resolver = jsr_resolver.clone(); let jsr_resolver = jsr_resolver.clone();
info_futures.push(async move { info_futures.push(async move {
if let Some(nv) = jsr_resolver.req_to_nv(req.req()).await { let nv = if let Some(req) = resolved_req {
if let Some(info) = jsr_resolver.package_version_info(&nv).await Cow::Borrowed(req)
{ } else {
return Some((specifier.clone(), info)); 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 None
}); });
@ -106,12 +120,8 @@ pub async fn cache_top_level_deps(
} }
} }
} }
let mut graph_permit = factory drop(info_futures);
.main_module_graph_container()
.await?
.acquire_update_permit()
.await;
let graph = graph_permit.graph_mut();
factory factory
.module_load_preparer() .module_load_preparer()
.await? .await?

View file

@ -18,7 +18,6 @@ use deno_core::futures::stream::FuturesUnordered;
use deno_core::futures::FutureExt; use deno_core::futures::FutureExt;
use deno_core::futures::StreamExt; use deno_core::futures::StreamExt;
use deno_core::serde_json; use deno_core::serde_json;
use deno_graph::FillFromLockfileOptions;
use deno_package_json::PackageJsonDepsMap; use deno_package_json::PackageJsonDepsMap;
use deno_package_json::PackageJsonRc; use deno_package_json::PackageJsonRc;
use deno_runtime::deno_permissions::PermissionsContainer; use deno_runtime::deno_permissions::PermissionsContainer;
@ -533,19 +532,8 @@ impl DepManager {
// populate the information from the lockfile // populate the information from the lockfile
if let Some(lockfile) = &self.lockfile { if let Some(lockfile) = &self.lockfile {
let lockfile = lockfile.lock(); let lockfile = lockfile.lock();
graph.fill_from_lockfile(FillFromLockfileOptions {
redirects: lockfile crate::graph_util::fill_graph_from_lockfile(graph, &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())),
});
} }
let npm_resolver = self.npm_resolver.as_managed().unwrap(); let npm_resolver = self.npm_resolver.as_managed().unwrap();

View file

@ -0,0 +1 @@
export * from "jsr:@denotest/add@1";

View file

@ -0,0 +1,3 @@
{
"a": 1
}

View file

@ -0,0 +1 @@
export * from "jsr:@denotest/subtract@1";

View file

@ -0,0 +1,7 @@
{
"exports": {
"./add": "./add.ts",
"./subtract": "./subtract.ts",
"./data-json": "./data.json"
}
}

View file

@ -0,0 +1 @@
export * from "jsr:@denotest/add@1";

View file

@ -0,0 +1,3 @@
{
"a": 1
}

View file

@ -0,0 +1,3 @@
export function multiply(a: number, b: number): number {
return a * b;
}

View file

@ -0,0 +1 @@
export * from "jsr:@denotest/subtract@1";

View file

@ -0,0 +1,8 @@
{
"exports": {
"./add": "./add.ts",
"./subtract": "./subtract.ts",
"./data-json": "./data.json",
"./multiply": "./multiply.ts"
}
}

View file

@ -1,6 +1,8 @@
{ {
"versions": { "versions": {
"1.0.0": {}, "1.0.0": {},
"0.7.1": {},
"0.7.0": {},
"0.5.0": {}, "0.5.0": {},
"0.2.0": {} "0.2.0": {}
} }

View file

@ -0,0 +1,9 @@
{
"tempDir": true,
"steps": [
{
"args": "install",
"output": "install.out"
}
]
}

View file

@ -0,0 +1,5 @@
{
"imports": {
"@denotest/multiple-exports": "jsr:@denotest/multiple-exports@^0.7.0"
}
}

View file

@ -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"
]
}
}

View file

@ -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]