Don't rebuild bundles automatically on file changes

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
This commit is contained in:
David Aurelio 2016-03-08 10:38:48 -08:00 committed by Facebook Github Bot 6
parent accccd8e55
commit e76fb68141
2 changed files with 4 additions and 28 deletions

View File

@ -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(); const bundleFunc = jest.genMockFunction();
bundleFunc bundleFunc
.mockReturnValueOnce( .mockReturnValueOnce(
@ -233,7 +233,7 @@ describe('processRequest', () => {
jest.runAllTimers(); jest.runAllTimers();
jest.runAllTicks(); jest.runAllTicks();
expect(bundleFunc.mock.calls.length).toBe(2); expect(bundleFunc.mock.calls.length).toBe(1);
makeRequest(requestHandler, 'mybundle.bundle?runModule=true') makeRequest(requestHandler, 'mybundle.bundle?runModule=true')
.done(response => .done(response =>
@ -242,7 +242,7 @@ describe('processRequest', () => {
jest.runAllTicks(); 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(); const bundleFunc = jest.genMockFunction();
bundleFunc bundleFunc
.mockReturnValueOnce( .mockReturnValueOnce(

View File

@ -197,7 +197,7 @@ class Server {
this._fileWatcher.on('all', this._onFileChange.bind(this)); this._fileWatcher.on('all', this._onFileChange.bind(this));
this._debouncedFileChangeHandler = _.debounce(filePath => { this._debouncedFileChangeHandler = _.debounce(filePath => {
this._rebuildBundles(filePath); this._clearBundles();
this._informChangeWatchers(); this._informChangeWatchers();
}, 50); }, 50);
} }
@ -293,30 +293,6 @@ class Server {
this._bundles = Object.create(null); 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() { _informChangeWatchers() {
const watchers = this._changeWatchers; const watchers = this._changeWatchers;
const headers = { const headers = {