mirror of https://github.com/status-im/metro.git
Debounce progress updates
Summary: This shows at max 5 progress updates per second on the terminal, which results in a minor speedup of reloads. Reviewed By: bestander Differential Revision: D3620164 fbshipit-source-id: d1a30f2f29f7088602d276b8ad3fc8ff1b74c79d
This commit is contained in:
parent
69e0375fb9
commit
e0f6dfdadf
|
@ -351,14 +351,13 @@ class Bundler {
|
||||||
if (!resolutionResponse) {
|
if (!resolutionResponse) {
|
||||||
let onProgress = noop;
|
let onProgress = noop;
|
||||||
if (process.stdout.isTTY && !this._opts.silent) {
|
if (process.stdout.isTTY && !this._opts.silent) {
|
||||||
const bar = new ProgressBar(
|
const bar = new ProgressBar('transformed :current/:total (:percent)', {
|
||||||
'transformed :current/:total (:percent)',
|
complete: '=',
|
||||||
{complete: '=', incomplete: ' ', width: 40, total: 1},
|
incomplete: ' ',
|
||||||
);
|
width: 40,
|
||||||
onProgress = (_, total) => {
|
total: 1,
|
||||||
bar.total = total;
|
});
|
||||||
bar.tick();
|
onProgress = debouncedTick(bar);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resolutionResponse = this.getDependencies({
|
resolutionResponse = this.getDependencies({
|
||||||
|
@ -708,4 +707,23 @@ function getMainModule({dependencies, numPrependedDependencies = 0}) {
|
||||||
return dependencies[numPrependedDependencies];
|
return dependencies[numPrependedDependencies];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function debouncedTick(progressBar) {
|
||||||
|
let n = 0;
|
||||||
|
let start, total;
|
||||||
|
|
||||||
|
return (_, t) => {
|
||||||
|
total = t;
|
||||||
|
n += 1;
|
||||||
|
if (start) {
|
||||||
|
if (progressBar.curr + n >= total || Date.now() - start > 200) {
|
||||||
|
progressBar.total = total;
|
||||||
|
progressBar.tick(n);
|
||||||
|
start = n = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
start = Date.now();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Bundler;
|
module.exports = Bundler;
|
||||||
|
|
Loading…
Reference in New Issue