[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:
Amjad Masad 2015-08-24 16:23:46 -07:00
parent c675840fd9
commit 1ff4e914f8
2 changed files with 24 additions and 3 deletions

View File

@ -26,6 +26,7 @@ describe('Bundler', function() {
var bundler; var bundler;
var assetServer; var assetServer;
var modules; var modules;
var ProgressBar;
beforeEach(function() { beforeEach(function() {
getDependencies = jest.genMockFn(); getDependencies = jest.genMockFn();
@ -49,6 +50,8 @@ describe('Bundler', function() {
callback(null, '{"json":true}'); callback(null, '{"json":true}');
}); });
ProgressBar = require('progress');
assetServer = { assetServer = {
getAssetData: jest.genMockFn(), getAssetData: jest.genMockFn(),
}; };
@ -221,6 +224,8 @@ describe('Bundler', function() {
expect(p.addAsset.mock.calls[1]).toEqual([ expect(p.addAsset.mock.calls[1]).toEqual([
imgModule imgModule
]); ]);
expect(ProgressBar.prototype.tick.mock.calls.length).toEqual(modules.length);
}); });
}); });

View File

@ -12,6 +12,7 @@ const assert = require('assert');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const Promise = require('promise'); const Promise = require('promise');
const ProgressBar = require('progress');
const Cache = require('../Cache'); const Cache = require('../Cache');
const Transformer = require('../JSTransformer'); const Transformer = require('../JSTransformer');
const DependencyResolver = require('../DependencyResolver'); const DependencyResolver = require('../DependencyResolver');
@ -124,8 +125,6 @@ class Bundler {
bundle(main, runModule, sourceMapUrl, isDev, platform) { bundle(main, runModule, sourceMapUrl, isDev, platform) {
const bundle = new Bundle(sourceMapUrl); const bundle = new Bundle(sourceMapUrl);
const transformModule = this._transformModule.bind(this, bundle);
const findEventId = Activity.startEvent('find dependencies'); const findEventId = Activity.startEvent('find dependencies');
let transformEventId; let transformEventId;
@ -133,9 +132,26 @@ class Bundler {
Activity.endEvent(findEventId); Activity.endEvent(findEventId);
transformEventId = Activity.startEvent('transform'); 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); bundle.setMainModuleId(result.mainModuleId);
return Promise.all( 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) => { }).then((transformedModules) => {
Activity.endEvent(transformEventId); Activity.endEvent(transformEventId);