summaryrefslogtreecommitdiff
path: root/cli/util
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-03-13 14:18:29 -0400
committerGitHub <noreply@github.com>2023-03-13 18:18:29 +0000
commit44b0d4cb11853bcdc7aa61c1412719a13d572b24 (patch)
tree074bcf6b77b4174343c4d0f3c239c53b7adf8350 /cli/util
parente8f22c076525c2fa55115349157f67085df287bf (diff)
fix(npm): show a progress bar when initializing the node_modules folder (#18136)
Creating the node_modules folder when the packages are already downloaded can take a bit of time and not knowing what is going on can be confusing. It's better to show a progress bar.
Diffstat (limited to 'cli/util')
-rw-r--r--cli/util/progress_bar/mod.rs56
1 files changed, 26 insertions, 30 deletions
diff --git a/cli/util/progress_bar/mod.rs b/cli/util/progress_bar/mod.rs
index 256871079..65bc00efd 100644
--- a/cli/util/progress_bar/mod.rs
+++ b/cli/util/progress_bar/mod.rs
@@ -27,6 +27,7 @@ mod renderer;
pub enum ProgressMessagePrompt {
Download,
Blocking,
+ Initialize,
}
impl ProgressMessagePrompt {
@@ -34,6 +35,9 @@ impl ProgressMessagePrompt {
match self {
ProgressMessagePrompt::Download => colors::green("Download").to_string(),
ProgressMessagePrompt::Blocking => colors::cyan("Blocking").to_string(),
+ ProgressMessagePrompt::Initialize => {
+ colors::green("Initialize").to_string()
+ }
}
}
}
@@ -251,7 +255,7 @@ impl DrawThreadRenderer for ProgressBarInner {
#[derive(Clone, Debug)]
pub struct ProgressBar {
- inner: Option<ProgressBarInner>,
+ inner: ProgressBarInner,
}
impl ProgressBar {
@@ -262,17 +266,14 @@ impl ProgressBar {
pub fn new(style: ProgressBarStyle) -> Self {
Self {
- inner: match Self::are_supported() {
- true => Some(ProgressBarInner::new(match style {
- ProgressBarStyle::DownloadBars => {
- Arc::new(renderer::BarProgressBarRenderer)
- }
- ProgressBarStyle::TextOnly => {
- Arc::new(renderer::TextOnlyProgressBarRenderer)
- }
- })),
- false => None,
- },
+ inner: ProgressBarInner::new(match style {
+ ProgressBarStyle::DownloadBars => {
+ Arc::new(renderer::BarProgressBarRenderer)
+ }
+ ProgressBarStyle::TextOnly => {
+ Arc::new(renderer::TextOnlyProgressBarRenderer)
+ }
+ }),
}
}
@@ -285,34 +286,29 @@ impl ProgressBar {
kind: ProgressMessagePrompt,
msg: &str,
) -> UpdateGuard {
- match &self.inner {
- Some(inner) => {
- let entry = inner.add_entry(kind, msg.to_string());
- UpdateGuard {
- maybe_entry: Some(entry),
- }
+ // only check if progress bars are supported once we go
+ // to update so that we lazily initialize the progress bar
+ if ProgressBar::are_supported() {
+ let entry = self.inner.add_entry(kind, msg.to_string());
+ UpdateGuard {
+ maybe_entry: Some(entry),
}
- None => {
- // if we're not running in TTY, fallback to using logger crate
- if !msg.is_empty() {
- log::log!(log::Level::Info, "{} {}", kind.as_text(), msg);
- }
- UpdateGuard { maybe_entry: None }
+ } else {
+ // if we're not running in TTY, fallback to using logger crate
+ if !msg.is_empty() {
+ log::log!(log::Level::Info, "{} {}", kind.as_text(), msg);
}
+ UpdateGuard { maybe_entry: None }
}
}
pub fn clear_guard(&self) -> ClearGuard {
- if let Some(inner) = &self.inner {
- inner.increment_clear();
- }
+ self.inner.increment_clear();
ClearGuard { pb: self.clone() }
}
fn decrement_clear(&self) {
- if let Some(inner) = &self.inner {
- inner.decrement_clear();
- }
+ self.inner.decrement_clear();
}
}