mirror of https://github.com/status-im/metro.git
[react-packager] Implement transformer progress bar
Summary: The transform step in currently the longest one in the bundling process. This adds a progress bar to track the transform progress. {F23096660}
This commit is contained in:
parent
c675840fd9
commit
1ff4e914f8
|
@ -26,6 +26,7 @@ describe('Bundler', function() {
|
|||
var bundler;
|
||||
var assetServer;
|
||||
var modules;
|
||||
var ProgressBar;
|
||||
|
||||
beforeEach(function() {
|
||||
getDependencies = jest.genMockFn();
|
||||
|
@ -49,6 +50,8 @@ describe('Bundler', function() {
|
|||
callback(null, '{"json":true}');
|
||||
});
|
||||
|
||||
ProgressBar = require('progress');
|
||||
|
||||
assetServer = {
|
||||
getAssetData: jest.genMockFn(),
|
||||
};
|
||||
|
@ -221,6 +224,8 @@ describe('Bundler', function() {
|
|||
expect(p.addAsset.mock.calls[1]).toEqual([
|
||||
imgModule
|
||||
]);
|
||||
|
||||
expect(ProgressBar.prototype.tick.mock.calls.length).toEqual(modules.length);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ const assert = require('assert');
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Promise = require('promise');
|
||||
const ProgressBar = require('progress');
|
||||
const Cache = require('../Cache');
|
||||
const Transformer = require('../JSTransformer');
|
||||
const DependencyResolver = require('../DependencyResolver');
|
||||
|
@ -124,8 +125,6 @@ class Bundler {
|
|||
|
||||
bundle(main, runModule, sourceMapUrl, isDev, platform) {
|
||||
const bundle = new Bundle(sourceMapUrl);
|
||||
|
||||
const transformModule = this._transformModule.bind(this, bundle);
|
||||
const findEventId = Activity.startEvent('find dependencies');
|
||||
let transformEventId;
|
||||
|
||||
|
@ -133,9 +132,26 @@ class Bundler {
|
|||
Activity.endEvent(findEventId);
|
||||
transformEventId = Activity.startEvent('transform');
|
||||
|
||||
let bar;
|
||||
if (process.stdout.isTTY) {
|
||||
bar = new ProgressBar('transforming [:bar] :percent :current/:total', {
|
||||
complete: '=',
|
||||
incomplete: ' ',
|
||||
width: 40,
|
||||
total: result.dependencies.length,
|
||||
});
|
||||
}
|
||||
|
||||
bundle.setMainModuleId(result.mainModuleId);
|
||||
return Promise.all(
|
||||
result.dependencies.map(transformModule)
|
||||
result.dependencies.map(
|
||||
module => this._transformModule(bundle, module).then(transformed => {
|
||||
if (bar) {
|
||||
bar.tick();
|
||||
}
|
||||
return transformed;
|
||||
})
|
||||
)
|
||||
);
|
||||
}).then((transformedModules) => {
|
||||
Activity.endEvent(transformEventId);
|
||||
|
|
Loading…
Reference in New Issue