From 3f072d22ea46b4794e01c0ee5de4fc04653e9374 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Tue, 8 Mar 2016 10:38:48 -0800 Subject: [PATCH] Don't rebuild bundles automatically on file changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Don’t rebuild bundles automatically after they have been requested once. This helps to not lock developer machines. Reviewed By: martinbigio Differential Revision: D3019751 fb-gh-sync-id: 98367b4fb89c5ae22c00444eabc1194ba6832dba shipit-source-id: 98367b4fb89c5ae22c00444eabc1194ba6832dba --- .../src/Server/__tests__/Server-test.js | 6 ++--- react-packager/src/Server/index.js | 26 +------------------ 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/react-packager/src/Server/__tests__/Server-test.js b/react-packager/src/Server/__tests__/Server-test.js index a2248842..796f281a 100644 --- a/react-packager/src/Server/__tests__/Server-test.js +++ b/react-packager/src/Server/__tests__/Server-test.js @@ -197,7 +197,7 @@ describe('processRequest', () => { }); }); - it('rebuilds the bundles that contain a file when that file is changed', () => { + it('does not rebuild the bundles that contain a file when that file is changed', () => { const bundleFunc = jest.genMockFunction(); bundleFunc .mockReturnValueOnce( @@ -233,7 +233,7 @@ describe('processRequest', () => { jest.runAllTimers(); jest.runAllTicks(); - expect(bundleFunc.mock.calls.length).toBe(2); + expect(bundleFunc.mock.calls.length).toBe(1); makeRequest(requestHandler, 'mybundle.bundle?runModule=true') .done(response => @@ -242,7 +242,7 @@ describe('processRequest', () => { jest.runAllTicks(); }); - it('rebuilds the bundles that contain a file when that file is changed, even when hot loading is enabled', () => { + it('does not rebuild the bundles that contain a file when that file is changed, even when hot loading is enabled', () => { const bundleFunc = jest.genMockFunction(); bundleFunc .mockReturnValueOnce( diff --git a/react-packager/src/Server/index.js b/react-packager/src/Server/index.js index c1f20606..985516be 100644 --- a/react-packager/src/Server/index.js +++ b/react-packager/src/Server/index.js @@ -197,7 +197,7 @@ class Server { this._fileWatcher.on('all', this._onFileChange.bind(this)); this._debouncedFileChangeHandler = _.debounce(filePath => { - this._rebuildBundles(filePath); + this._clearBundles(); this._informChangeWatchers(); }, 50); } @@ -293,30 +293,6 @@ class Server { this._bundles = Object.create(null); } - _rebuildBundles() { - const buildBundle = this.buildBundle.bind(this); - const bundles = this._bundles; - - Object.keys(bundles).forEach(function(optionsJson) { - const options = JSON.parse(optionsJson); - // Wait for a previous build (if exists) to finish. - bundles[optionsJson] = (bundles[optionsJson] || Promise.resolve()).finally(function() { - // With finally promise callback we can't change the state of the promise - // so we need to reassign the promise. - bundles[optionsJson] = buildBundle(options).then(function(p) { - // Make a throwaway call to getSource to cache the source string. - p.getSource({ - inlineSourceMap: options.inlineSourceMap, - minify: options.minify, - dev: options.dev, - }); - return p; - }); - }); - return bundles[optionsJson]; - }); - } - _informChangeWatchers() { const watchers = this._changeWatchers; const headers = {