Skip to content

Commit

Permalink
feat(progress): optimize the progress bar style (#4197)
Browse files Browse the repository at this point in the history
* feat(progress): optimize the progress bar style

* chore: fix
  • Loading branch information
chenjiahan authored Sep 15, 2023
1 parent f90e92b commit 287bc09
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
18 changes: 13 additions & 5 deletions crates/rspack_plugin_progress/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ impl ProgressPlugin {
pub fn new(options: ProgressPluginOptions) -> Self {
let progress_bar = ProgressBar::with_draw_target(Some(100), ProgressDrawTarget::stdout());
progress_bar.set_style(
ProgressStyle::with_template("{prefix} {bar:40.cyan/blue} {percent}% {wide_msg}")
.expect("TODO:"),
ProgressStyle::with_template("{prefix:.bold} {bar:25.green/white.dim} {wide_msg:.dim}")
.expect("TODO:")
.progress_chars("━━"),
);
Self {
options,
Expand Down Expand Up @@ -84,14 +85,21 @@ impl Plugin for ProgressPlugin {
async fn succeed_module(&self, _module: &dyn Module) -> Result<()> {
let previous_modules_done = self.modules_done.fetch_add(1, SeqCst);
let modules_done = previous_modules_done + 1;

// Assume a minimum of 200 modules to avoid progress growing too quickly
let min_total_module: u32 = 200;

let percent = (modules_done as f32)
/ (cmp::max(
self.last_modules_count.read().expect("TODO:").unwrap_or(1),
self.modules_count.load(SeqCst),
cmp::max(
self.last_modules_count.read().expect("TODO:").unwrap_or(1),
self.modules_count.load(SeqCst),
),
min_total_module,
) as f32);
self
.progress_bar
.set_position((10.0 + 55.0 * percent) as u64);
.set_position((10.0 + 65.0 * percent) as u64);
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/src/stats/DefaultStatsPrinterPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const SIMPLE_PRINTERS: Record<
const builtAtMessage =
root && builtAt ? `${formatDateTime(builtAt)}: ` : "";
const versionMessage =
root && rspackVersion ? `rspack ${rspackVersion}` : "";
root && rspackVersion ? `Rspack ${rspackVersion}` : "";
const nameMessage =
root && name
? bold(name)
Expand All @@ -117,7 +117,7 @@ const SIMPLE_PRINTERS: Record<
const subjectMessage =
nameMessage && versionMessage
? `${nameMessage} (${versionMessage})`
: versionMessage || nameMessage || "rspack";
: versionMessage || nameMessage || "Rspack";
let statusMessage;
if (errorsMessage && warningsMessage) {
statusMessage = `compiled with ${errorsMessage} and ${warningsMessage}`;
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/tests/Stats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("Stats", () => {
entry ./fixtures/a
./fixtures/a.js [876] {main}
entry ./fixtures/a
rspack compiled successfully (224575f0bba4bc71b95f)"
Rspack compiled successfully (224575f0bba4bc71b95f)"
`);
});

Expand Down Expand Up @@ -79,7 +79,7 @@ describe("Stats", () => {
rspack compiled with 1 error (51da9544767033575b9e)"
Rspack compiled with 1 error (51da9544767033575b9e)"
`);
});

Expand Down
40 changes: 20 additions & 20 deletions packages/rspack/tests/__snapshots__/StatsTestCases.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ chunk {main} bundle.js (main) [entry]
entry ./index
./stringModule.js [363] {main}
esm import ./stringModule [10]
rspack compiled successfully (7a935a9f14af6fedd836)"
Rspack compiled successfully (7a935a9f14af6fedd836)"
`;

exports[`StatsTestCases should print correct stats for filename 1`] = `
Expand Down Expand Up @@ -602,7 +602,7 @@ chunk {main} main.xxxx.js (main) >{dynamic_js}< [entry]
entry ./index
./dynamic.js [426] {dynamic_js}
dynamic import ./dynamic [10]
rspack compiled successfully (6d7c52e50cefca7d30c4)"
Rspack compiled successfully (6d7c52e50cefca7d30c4)"
`;

exports[`StatsTestCases should print correct stats for hot+production 1`] = `
Expand Down Expand Up @@ -760,7 +760,7 @@ chunk {main} bundle.js (main) [entry]
entry ./index.js
./index.js [10] {main}
entry ./index.js
rspack compiled successfully (8b17e56c72949ef15048)"
Rspack compiled successfully (8b17e56c72949ef15048)"
`;

exports[`StatsTestCases should print correct stats for identifier-let-strict-mode 1`] = `
Expand Down Expand Up @@ -817,7 +817,7 @@ error[javascript]: JavaScript parsing error
rspack compiled with 2 errors"
Rspack compiled with 2 errors"
`;
exports[`StatsTestCases should print correct stats for ignore-plugin 1`] = `
Expand Down Expand Up @@ -929,7 +929,7 @@ exports[`StatsTestCases should print correct stats for ignore-warning 1`] = `
}
`;
exports[`StatsTestCases should print correct stats for ignore-warning 2`] = `"rspack compiled successfully"`;
exports[`StatsTestCases should print correct stats for ignore-warning 2`] = `"Rspack compiled successfully"`;
exports[`StatsTestCases should print correct stats for issue-3558 1`] = `
{
Expand All @@ -941,7 +941,7 @@ exports[`StatsTestCases should print correct stats for issue-3558 1`] = `
}
`;
exports[`StatsTestCases should print correct stats for issue-3558 2`] = `"rspack compiled successfully"`;
exports[`StatsTestCases should print correct stats for issue-3558 2`] = `"Rspack compiled successfully"`;
exports[`StatsTestCases should print correct stats for legacy-ie-css-warning 1`] = `
{
Expand All @@ -953,7 +953,7 @@ exports[`StatsTestCases should print correct stats for legacy-ie-css-warning 1`]
}
`;
exports[`StatsTestCases should print correct stats for legacy-ie-css-warning 2`] = `"rspack compiled successfully"`;
exports[`StatsTestCases should print correct stats for legacy-ie-css-warning 2`] = `"Rspack compiled successfully"`;
exports[`StatsTestCases should print correct stats for loader-builtin-swc-plugin-warn 1`] = `
{
Expand All @@ -977,7 +977,7 @@ exports[`StatsTestCases should print correct stats for loader-builtin-swc-plugin
rspack compiled with 1 warning"
Rspack compiled with 1 warning"
`;
exports[`StatsTestCases should print correct stats for logging 1`] = `
Expand Down Expand Up @@ -1066,7 +1066,7 @@ exports[`StatsTestCases should print correct stats for minify-error-recovery 2`]
rspack compiled with 1 error"
Rspack compiled with 1 error"
`;
exports[`StatsTestCases should print correct stats for named-chunk-group 1`] = `
Expand Down Expand Up @@ -1155,7 +1155,7 @@ exports[`StatsTestCases should print correct stats for normal-errors 2`] = `
rspack compiled with 1 error"
Rspack compiled with 1 error"
`;
exports[`StatsTestCases should print correct stats for optimization-runtime-chunk 1`] = `
Expand Down Expand Up @@ -1771,7 +1771,7 @@ exports[`StatsTestCases should print correct stats for parse-error 2`] = `
rspack compiled with 1 error"
Rspack compiled with 1 error"
`;
exports[`StatsTestCases should print correct stats for parse-error-builtin-swc-loader 1`] = `
Expand Down Expand Up @@ -1815,7 +1815,7 @@ exports[`StatsTestCases should print correct stats for parse-error-builtin-swc-l
rspack compiled with 1 error"
Rspack compiled with 1 error"
`;
exports[`StatsTestCases should print correct stats for reasons 1`] = `
Expand Down Expand Up @@ -2144,7 +2144,7 @@ error[internal]: Resolve error
rspack compiled with 1 error (745b7086c5177811e94a)"
Rspack compiled with 1 error (745b7086c5177811e94a)"
`;
exports[`StatsTestCases should print correct stats for resolve-unexpected-exports-in-pkg 1`] = `
Expand Down Expand Up @@ -2403,7 +2403,7 @@ error[internal]: Export should be relative path and start with "./", but got ../
rspack compiled with 1 error (4e3ebc05601fcb8c4e16)"
Rspack compiled with 1 error (4e3ebc05601fcb8c4e16)"
`;
exports[`StatsTestCases should print correct stats for simple 1`] = `
Expand Down Expand Up @@ -2561,7 +2561,7 @@ chunk {main} bundle.js (main) [entry]
entry ./index
./index.js [10] {main}
entry ./index
rspack compiled successfully (96a5acbdbd5061c8e5ac)"
Rspack compiled successfully (96a5acbdbd5061c8e5ac)"
`;
exports[`StatsTestCases should print correct stats for simple-module-source 1`] = `
Expand Down Expand Up @@ -2849,7 +2849,7 @@ Entrypoint main 631 bytes = bundle.js
./raw.png
./index.js
./stringModule.js
rspack compiled successfully (58ffc7a5ede4848a7209)"
Rspack compiled successfully (58ffc7a5ede4848a7209)"
`;
exports[`StatsTestCases should print correct stats for stats-hooks 1`] = `
Expand Down Expand Up @@ -3000,7 +3000,7 @@ exports[`StatsTestCases should print correct stats for stats-hooks 2`] = `
asset bundle.js 589 bytes [emitted111] (name: main) [testA: aaaaaa]
Entrypoint main 589 bytes = bundle.js
./index.js
rspack compiled successfully (96a5acbdbd5061c8e5ac)"
Rspack compiled successfully (96a5acbdbd5061c8e5ac)"
`;
exports[`StatsTestCases should print correct stats for try-require--module 1`] = `
Expand Down Expand Up @@ -3045,7 +3045,7 @@ exports[`StatsTestCases should print correct stats for try-require--module 2`] =
rspack compiled with 1 warning"
Rspack compiled with 1 warning"
`;
exports[`StatsTestCases should print correct stats for try-require-resolve-module 1`] = `
Expand Down Expand Up @@ -3090,7 +3090,7 @@ exports[`StatsTestCases should print correct stats for try-require-resolve-modul
rspack compiled with 1 warning"
Rspack compiled with 1 warning"
`;
exports[`StatsTestCases should print correct stats for try-require-resolve-weak-module 1`] = `
Expand Down Expand Up @@ -3135,5 +3135,5 @@ exports[`StatsTestCases should print correct stats for try-require-resolve-weak-
rspack compiled with 1 warning"
Rspack compiled with 1 warning"
`;

0 comments on commit 287bc09

Please sign in to comment.