fix(vendor): strip jsr version meta module graph data (#29120)

This removes the `moduleGraphX` data from the `<version>_meta.json`
files for jsr packages when copying from the global cache to the local
one. This property is not really useful to vendor because it's just a
performance optimization when downloading the files and someone may be
changing the data in the files leading to the `moduleGraph` data to be
out of date.
This commit is contained in:
David Sherret 2025-05-01 11:05:23 -04:00 committed by GitHub
parent 9fd7d463bd
commit 2bc8b9b7c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 24 deletions

4
Cargo.lock generated
View file

@ -1687,9 +1687,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_cache_dir" name = "deno_cache_dir"
version = "0.19.2" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "502c5f3120fe5b32908e9a4b3af95b7e1a35e8fa758d87155b03a3810655c9f0" checksum = "869a62459ded73382e018c7c58a07df170ba5f5befb67e18ee10494e769efe2a"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"base32", "base32",

View file

@ -56,7 +56,7 @@ repository = "https://github.com/denoland/deno"
deno_ast = { version = "=0.46.6", features = ["transpiling"] } deno_ast = { version = "=0.46.6", features = ["transpiling"] }
deno_core = { version = "0.345.0" } deno_core = { version = "0.345.0" }
deno_cache_dir = "=0.19.2" deno_cache_dir = "=0.20.0"
deno_config = { version = "=0.54.2", features = ["workspace"] } deno_config = { version = "=0.54.2", features = ["workspace"] }
deno_doc = "=0.172.0" deno_doc = "=0.172.0"
deno_error = "=0.5.6" deno_error = "=0.5.6"

View file

@ -47,6 +47,7 @@ use deno_lib::args::NPM_PROCESS_STATE;
use deno_lib::version::DENO_VERSION_INFO; use deno_lib::version::DENO_VERSION_INFO;
use deno_lib::worker::StorageKeyResolver; use deno_lib::worker::StorageKeyResolver;
use deno_npm::NpmSystemInfo; use deno_npm::NpmSystemInfo;
use deno_resolver::factory::resolve_jsr_url;
use deno_runtime::deno_permissions::PermissionsOptions; use deno_runtime::deno_permissions::PermissionsOptions;
use deno_runtime::inspector_server::InspectorServer; use deno_runtime::inspector_server::InspectorServer;
use deno_semver::npm::NpmPackageReqReference; use deno_semver::npm::NpmPackageReqReference;
@ -67,27 +68,7 @@ use thiserror::Error;
use crate::sys::CliSys; use crate::sys::CliSys;
pub fn jsr_url() -> &'static Url { pub fn jsr_url() -> &'static Url {
static JSR_URL: Lazy<Url> = Lazy::new(|| { static JSR_URL: Lazy<Url> = Lazy::new(|| resolve_jsr_url(&CliSys::default()));
let env_var_name = "JSR_URL";
if let Ok(registry_url) = std::env::var(env_var_name) {
// ensure there is a trailing slash for the directory
let registry_url = format!("{}/", registry_url.trim_end_matches('/'));
match Url::parse(&registry_url) {
Ok(url) => {
return url;
}
Err(err) => {
log::debug!(
"Invalid {} environment variable: {:#}",
env_var_name,
err,
);
}
}
}
Url::parse("https://jsr.io/").unwrap()
});
&JSR_URL &JSR_URL
} }

View file

@ -45,6 +45,7 @@ use sys_traits::SystemRandom;
use sys_traits::SystemTimeNow; use sys_traits::SystemTimeNow;
use sys_traits::ThreadSleep; use sys_traits::ThreadSleep;
use thiserror::Error; use thiserror::Error;
use url::Url;
use crate::npm::managed::ManagedInNpmPkgCheckerCreateOptions; use crate::npm::managed::ManagedInNpmPkgCheckerCreateOptions;
use crate::npm::managed::ManagedNpmResolverCreateOptions; use crate::npm::managed::ManagedNpmResolverCreateOptions;
@ -127,6 +128,25 @@ pub enum ConfigDiscoveryOption {
Disabled, Disabled,
} }
/// Resolves the JSR regsitry URL to use for the given system.
pub fn resolve_jsr_url(sys: &impl sys_traits::EnvVar) -> Url {
let env_var_name = "JSR_URL";
if let Ok(registry_url) = sys.env_var(env_var_name) {
// ensure there is a trailing slash for the directory
let registry_url = format!("{}/", registry_url.trim_end_matches('/'));
match Url::parse(&registry_url) {
Ok(url) => {
return url;
}
Err(err) => {
log::debug!("Invalid {} environment variable: {:#}", env_var_name, err,);
}
}
}
Url::parse("https://jsr.io/").unwrap()
}
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
pub trait SpecifiedImportMapProvider: pub trait SpecifiedImportMapProvider:
std::fmt::Debug + MaybeSend + MaybeSync std::fmt::Debug + MaybeSend + MaybeSync
@ -259,6 +279,7 @@ pub struct WorkspaceFactory<TSys: WorkspaceFactorySys + sys_traits::ThreadSleep>
deno_dir_path: DenoDirPathProviderRc<TSys>, deno_dir_path: DenoDirPathProviderRc<TSys>,
global_http_cache: Deferred<GlobalHttpCacheRc<TSys>>, global_http_cache: Deferred<GlobalHttpCacheRc<TSys>>,
http_cache: Deferred<GlobalOrLocalHttpCache<TSys>>, http_cache: Deferred<GlobalOrLocalHttpCache<TSys>>,
jsr_url: Deferred<Url>,
node_modules_dir_path: Deferred<Option<PathBuf>>, node_modules_dir_path: Deferred<Option<PathBuf>>,
npm_cache_dir: Deferred<NpmCacheDirRc>, npm_cache_dir: Deferred<NpmCacheDirRc>,
npmrc: Deferred<ResolvedNpmRcRc>, npmrc: Deferred<ResolvedNpmRcRc>,
@ -288,6 +309,7 @@ impl<TSys: WorkspaceFactorySys> WorkspaceFactory<TSys> {
sys, sys,
global_http_cache: Default::default(), global_http_cache: Default::default(),
http_cache: Default::default(), http_cache: Default::default(),
jsr_url: Default::default(),
node_modules_dir_path: Default::default(), node_modules_dir_path: Default::default(),
npm_cache_dir: Default::default(), npm_cache_dir: Default::default(),
npmrc: Default::default(), npmrc: Default::default(),
@ -305,6 +327,10 @@ impl<TSys: WorkspaceFactorySys> WorkspaceFactory<TSys> {
self.workspace_directory = Deferred::from(workspace_directory); self.workspace_directory = Deferred::from(workspace_directory);
} }
pub fn jsr_url(&self) -> &Url {
self.jsr_url.get_or_init(|| resolve_jsr_url(&self.sys))
}
pub fn initial_cwd(&self) -> &PathBuf { pub fn initial_cwd(&self) -> &PathBuf {
&self.initial_cwd &self.initial_cwd
} }
@ -453,6 +479,7 @@ impl<TSys: WorkspaceFactorySys> WorkspaceFactory<TSys> {
local_path.clone(), local_path.clone(),
global_cache, global_cache,
deno_cache_dir::GlobalToLocalCopy::Allow, deno_cache_dir::GlobalToLocalCopy::Allow,
self.jsr_url().clone(),
); );
Ok(new_rc(local_cache).into()) Ok(new_rc(local_cache).into())
} }