Skip to content
Permalink
Browse files

[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}
  • Loading branch information...
amasad committed Aug 24, 2015
1 parent 8c5626c commit eb248e0b5855c4d4b3d7cd6dff886264787652ee
@@ -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,18 +125,33 @@ 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;

return this.getDependencies(main, isDev, platform).then((result) => {
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);

0 comments on commit eb248e0

Please sign in to comment.
You can’t perform that action at this time.