From 1ff4e914f8fbb9edabaf97c8513cdab68163d92a Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Mon, 24 Aug 2015 16:23:46 -0700 Subject: [PATCH] [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} --- .../src/Bundler/__tests__/Bundler-test.js | 5 +++++ react-packager/src/Bundler/index.js | 22 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/react-packager/src/Bundler/__tests__/Bundler-test.js b/react-packager/src/Bundler/__tests__/Bundler-test.js index 20bb1d4a..f79292c0 100644 --- a/react-packager/src/Bundler/__tests__/Bundler-test.js +++ b/react-packager/src/Bundler/__tests__/Bundler-test.js @@ -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); }); }); diff --git a/react-packager/src/Bundler/index.js b/react-packager/src/Bundler/index.js index c9842b72..c1d811d4 100644 --- a/react-packager/src/Bundler/index.js +++ b/react-packager/src/Bundler/index.js @@ -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);