mirror of
https://github.com/denoland/deno.git
synced 2025-07-07 21:35:07 +00:00
refactor(npm_cache): fix Wasm build to not use tokio code (#29641)
Some checks are pending
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / build wasm32 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
Some checks are pending
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / build wasm32 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
This commit is contained in:
parent
74b73b3c9f
commit
1323aca15e
7 changed files with 58 additions and 12 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -8400,9 +8400,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "sys_traits"
|
||||
version = "0.1.15"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "110a9308163844c6ce51149737dbcea372f101bffbc0ef05d5de06acb4a4128f"
|
||||
checksum = "dc4707edf3196e8037ee45018d1bb1bfb233b0e4fc440fa3d3f25bc69bfdaf26"
|
||||
dependencies = [
|
||||
"filetime",
|
||||
"getrandom",
|
||||
|
|
|
@ -72,7 +72,7 @@ deno_path_util = "=0.4.0"
|
|||
deno_semver = "=0.8.0"
|
||||
deno_task_shell = "=0.24.0"
|
||||
deno_terminal = "=0.2.2"
|
||||
deno_unsync = "0.4.4"
|
||||
deno_unsync = { version = "0.4.4", default-features = false }
|
||||
deno_whoami = "0.1.0"
|
||||
eszip = "=0.92.0"
|
||||
|
||||
|
@ -237,7 +237,7 @@ simd-json = "0.14.0"
|
|||
slab = "0.4"
|
||||
smallvec = "1.8"
|
||||
socket2 = { version = "0.5.3", features = ["all"] }
|
||||
sys_traits = "=0.1.15"
|
||||
sys_traits = "=0.1.16"
|
||||
tar = "=0.4.43"
|
||||
# temporarily using until https://github.com/harryfei/which-rs/pull/109 is released
|
||||
temp_deno_which = { version = "0.1.0", default-features = false }
|
||||
|
|
|
@ -11,7 +11,6 @@ use deno_npm::registry::NpmPackageInfo;
|
|||
use deno_npm::registry::NpmRegistryApi;
|
||||
use deno_npm::registry::NpmRegistryPackageInfoLoadError;
|
||||
use deno_unsync::sync::AtomicFlag;
|
||||
use deno_unsync::sync::MultiRuntimeAsyncValueCreator;
|
||||
use futures::future::LocalBoxFuture;
|
||||
use futures::FutureExt;
|
||||
use parking_lot::Mutex;
|
||||
|
@ -21,6 +20,7 @@ use url::Url;
|
|||
|
||||
use crate::remote::maybe_auth_header_value_for_npm_registry;
|
||||
use crate::rt::spawn_blocking;
|
||||
use crate::rt::MultiRuntimeAsyncValueCreator;
|
||||
use crate::NpmCache;
|
||||
use crate::NpmCacheHttpClient;
|
||||
use crate::NpmCacheHttpClientResponse;
|
||||
|
|
|
@ -22,3 +22,39 @@ pub fn spawn_blocking<
|
|||
deno_unsync::spawn_blocking(f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use deno_unsync::sync::MultiRuntimeAsyncValueCreator;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
mod wasm {
|
||||
use futures::future::LocalBoxFuture;
|
||||
|
||||
type CreateFutureFn<TResult> =
|
||||
Box<dyn Fn() -> LocalBoxFuture<'static, TResult> + Send + Sync>;
|
||||
|
||||
pub struct MultiRuntimeAsyncValueCreator<TResult: Send + Clone + 'static> {
|
||||
create_future: CreateFutureFn<TResult>,
|
||||
}
|
||||
|
||||
impl<TResult: Send + Clone + 'static> std::fmt::Debug
|
||||
for MultiRuntimeAsyncValueCreator<TResult>
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("MultiRuntimeAsyncValueCreator").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<TResult: Send + Clone + 'static> MultiRuntimeAsyncValueCreator<TResult> {
|
||||
pub fn new(create_future: CreateFutureFn<TResult>) -> Self {
|
||||
Self { create_future }
|
||||
}
|
||||
|
||||
pub async fn get(&self) -> TResult {
|
||||
(self.create_future)().await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub use wasm::MultiRuntimeAsyncValueCreator;
|
||||
|
|
|
@ -7,7 +7,6 @@ use deno_error::JsErrorBox;
|
|||
use deno_npm::npm_rc::ResolvedNpmRc;
|
||||
use deno_npm::registry::NpmPackageVersionDistInfo;
|
||||
use deno_semver::package::PackageNv;
|
||||
use deno_unsync::sync::MultiRuntimeAsyncValueCreator;
|
||||
use futures::future::LocalBoxFuture;
|
||||
use futures::FutureExt;
|
||||
use parking_lot::Mutex;
|
||||
|
@ -15,6 +14,7 @@ use url::Url;
|
|||
|
||||
use crate::remote::maybe_auth_header_value_for_npm_registry;
|
||||
use crate::rt::spawn_blocking;
|
||||
use crate::rt::MultiRuntimeAsyncValueCreator;
|
||||
use crate::tarball_extract::verify_and_extract_tarball;
|
||||
use crate::tarball_extract::TarballExtractionMode;
|
||||
use crate::NpmCache;
|
||||
|
|
|
@ -49,6 +49,8 @@ url.workspace = true
|
|||
sys_traits = { workspace = true, features = ["real", "wasm"] }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
deno_error = { workspace = true, features = ["serde", "serde_json", "tokio"] }
|
||||
deno_unsync = { workspace = true, features = ["tokio"] }
|
||||
tokio.workspace = true
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
|
|
|
@ -53,12 +53,20 @@ impl<TNpmCacheHttpClient: NpmCacheHttpClient, TSys: NpmInstallerSys>
|
|||
for NpmDenoGraphResolver<TNpmCacheHttpClient, TSys>
|
||||
{
|
||||
fn load_and_cache_npm_package_info(&self, package_name: &str) {
|
||||
if let Some(npm_installer) = &self.npm_installer {
|
||||
let npm_installer = npm_installer.clone();
|
||||
let package_name = package_name.to_string();
|
||||
deno_unsync::spawn(async move {
|
||||
let _ignore = npm_installer.cache_package_info(&package_name).await;
|
||||
});
|
||||
// ok not to do this in Wasm because this is just an optimization
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
_ = package_name;
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
if let Some(npm_installer) = &self.npm_installer {
|
||||
let npm_installer = npm_installer.clone();
|
||||
let package_name = package_name.to_string();
|
||||
deno_unsync::spawn(async move {
|
||||
let _ignore = npm_installer.cache_package_info(&package_name).await;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue