mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
feat: download progress bar (#15814)
This commit is contained in:
parent
3bce2af0eb
commit
f92bd986de
10 changed files with 244 additions and 25 deletions
|
@ -11,12 +11,12 @@ use deno_core::anyhow::Context;
|
|||
use deno_core::error::custom_error;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::url::Url;
|
||||
use deno_runtime::colors;
|
||||
use deno_runtime::deno_fetch::reqwest;
|
||||
|
||||
use crate::deno_dir::DenoDir;
|
||||
use crate::file_fetcher::CacheSetting;
|
||||
use crate::fs_util;
|
||||
use crate::progress_bar::ProgressBar;
|
||||
|
||||
use super::semver::NpmVersion;
|
||||
use super::tarball::verify_and_extract_tarball;
|
||||
|
@ -173,13 +173,19 @@ impl ReadonlyNpmCache {
|
|||
pub struct NpmCache {
|
||||
readonly: ReadonlyNpmCache,
|
||||
cache_setting: CacheSetting,
|
||||
progress_bar: ProgressBar,
|
||||
}
|
||||
|
||||
impl NpmCache {
|
||||
pub fn from_deno_dir(dir: &DenoDir, cache_setting: CacheSetting) -> Self {
|
||||
pub fn from_deno_dir(
|
||||
dir: &DenoDir,
|
||||
cache_setting: CacheSetting,
|
||||
progress_bar: ProgressBar,
|
||||
) -> Self {
|
||||
Self {
|
||||
readonly: ReadonlyNpmCache::from_deno_dir(dir),
|
||||
cache_setting,
|
||||
progress_bar,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,13 +217,7 @@ impl NpmCache {
|
|||
);
|
||||
}
|
||||
|
||||
log::log!(
|
||||
log::Level::Info,
|
||||
"{} {}",
|
||||
colors::green("Download"),
|
||||
dist.tarball,
|
||||
);
|
||||
|
||||
let _guard = self.progress_bar.update(&dist.tarball);
|
||||
let response = reqwest::get(&dist.tarball).await?;
|
||||
|
||||
if response.status() == 404 {
|
||||
|
|
|
@ -31,6 +31,7 @@ use resolution::NpmResolution;
|
|||
|
||||
use crate::deno_dir::DenoDir;
|
||||
use crate::file_fetcher::CacheSetting;
|
||||
use crate::progress_bar::ProgressBar;
|
||||
|
||||
use self::cache::ReadonlyNpmCache;
|
||||
use self::resolution::NpmResolutionSnapshot;
|
||||
|
@ -87,13 +88,15 @@ impl GlobalNpmPackageResolver {
|
|||
cache_setting: CacheSetting,
|
||||
unstable: bool,
|
||||
no_npm: bool,
|
||||
progress_bar: ProgressBar,
|
||||
) -> Self {
|
||||
Self::from_cache(
|
||||
NpmCache::from_deno_dir(dir, cache_setting.clone()),
|
||||
NpmCache::from_deno_dir(dir, cache_setting.clone(), progress_bar.clone()),
|
||||
reload,
|
||||
cache_setting,
|
||||
unstable,
|
||||
no_npm,
|
||||
progress_bar,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -103,8 +106,10 @@ impl GlobalNpmPackageResolver {
|
|||
cache_setting: CacheSetting,
|
||||
unstable: bool,
|
||||
no_npm: bool,
|
||||
progress_bar: ProgressBar,
|
||||
) -> Self {
|
||||
let api = NpmRegistryApi::new(cache.clone(), reload, cache_setting);
|
||||
let api =
|
||||
NpmRegistryApi::new(cache.clone(), reload, cache_setting, progress_bar);
|
||||
let registry_url = api.base_url().to_owned();
|
||||
let resolution = Arc::new(NpmResolution::new(api));
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ use serde::Serialize;
|
|||
use crate::file_fetcher::CacheSetting;
|
||||
use crate::fs_util;
|
||||
use crate::http_cache::CACHE_PERM;
|
||||
use crate::progress_bar::ProgressBar;
|
||||
|
||||
use super::cache::NpmCache;
|
||||
use super::semver::NpmVersionReq;
|
||||
|
@ -106,6 +107,7 @@ pub struct NpmRegistryApi {
|
|||
mem_cache: Arc<Mutex<HashMap<String, Option<NpmPackageInfo>>>>,
|
||||
reload: bool,
|
||||
cache_setting: CacheSetting,
|
||||
progress_bar: ProgressBar,
|
||||
}
|
||||
|
||||
impl NpmRegistryApi {
|
||||
|
@ -132,8 +134,15 @@ impl NpmRegistryApi {
|
|||
cache: NpmCache,
|
||||
reload: bool,
|
||||
cache_setting: CacheSetting,
|
||||
progress_bar: ProgressBar,
|
||||
) -> Self {
|
||||
Self::from_base(Self::default_url(), cache, reload, cache_setting)
|
||||
Self::from_base(
|
||||
Self::default_url(),
|
||||
cache,
|
||||
reload,
|
||||
cache_setting,
|
||||
progress_bar,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn from_base(
|
||||
|
@ -141,6 +150,7 @@ impl NpmRegistryApi {
|
|||
cache: NpmCache,
|
||||
reload: bool,
|
||||
cache_setting: CacheSetting,
|
||||
progress_bar: ProgressBar,
|
||||
) -> Self {
|
||||
Self {
|
||||
base_url,
|
||||
|
@ -148,6 +158,7 @@ impl NpmRegistryApi {
|
|||
mem_cache: Default::default(),
|
||||
reload,
|
||||
cache_setting,
|
||||
progress_bar,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,13 +305,7 @@ impl NpmRegistryApi {
|
|||
}
|
||||
|
||||
let package_url = self.get_package_url(name);
|
||||
|
||||
log::log!(
|
||||
log::Level::Info,
|
||||
"{} {}",
|
||||
colors::green("Download"),
|
||||
package_url,
|
||||
);
|
||||
let _guard = self.progress_bar.update(package_url.as_str());
|
||||
|
||||
let response = match reqwest::get(package_url).await {
|
||||
Ok(response) => response,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue