diff --git a/src/coordinator.js b/src/coordinator.js index 13c2fa8..a2370c4 100644 --- a/src/coordinator.js +++ b/src/coordinator.js @@ -2,6 +2,7 @@ import cluster from 'cluster'; import os from 'os'; import './environment'; +import Promise from './promise'; import logger from './utils/logger'; import { raceTo } from './utils/lifecycle'; diff --git a/src/environment.js b/src/environment.js index 80ad23d..6d2605e 100644 --- a/src/environment.js +++ b/src/environment.js @@ -1,26 +1,2 @@ /* eslint func-names:0 no-extra-parens:0 */ import 'airbnb-js-shims'; -import Promise from 'bluebird'; - -const es6methods = ['then', 'catch', 'constructor']; -const es6StaticMethods = ['all', 'race', 'resolve', 'reject', 'cast']; - -function isNotMethod(name) { - return !(es6methods.includes(name) || es6StaticMethods.includes(name) || name.charAt(0) === '_'); -} - -function del(obj) { - /* eslint no-param-reassign: 0 */ - return (key) => { delete obj[key]; }; -} - -function toFastProperties(obj) { - (function () {}).prototype = obj; -} - -Object.keys(Promise.prototype).filter(isNotMethod).forEach(del(Promise.prototype)); -Object.keys(Promise).filter(isNotMethod).forEach(del(Promise)); -toFastProperties(Promise); -toFastProperties(Promise.prototype); - -global.Promise = Promise; diff --git a/src/promise.js b/src/promise.js new file mode 100644 index 0000000..272616c --- /dev/null +++ b/src/promise.js @@ -0,0 +1,25 @@ +/* eslint func-names:0 no-extra-parens:0 */ +import Promise from 'bluebird'; + +const es6methods = ['then', 'catch', 'constructor']; +const es6StaticMethods = ['all', 'race', 'resolve', 'reject', 'cast']; + +function isNotMethod(name) { + return !(es6methods.includes(name) || es6StaticMethods.includes(name) || name.charAt(0) === '_'); +} + +function del(obj) { + /* eslint no-param-reassign: 0 */ + return (key) => { delete obj[key]; }; +} + +function toFastProperties(obj) { + (function () {}).prototype = obj; +} + +Object.keys(Promise.prototype).filter(isNotMethod).forEach(del(Promise.prototype)); +Object.keys(Promise).filter(isNotMethod).forEach(del(Promise)); +toFastProperties(Promise); +toFastProperties(Promise.prototype); + +export default Promise; diff --git a/src/utils/BatchManager.js b/src/utils/BatchManager.js index 304e542..561efa7 100644 --- a/src/utils/BatchManager.js +++ b/src/utils/BatchManager.js @@ -1,3 +1,5 @@ +import Promise from '../promise'; + const noHTMLError = new TypeError( 'HTML was not returned to Hypernova, this is most likely an error within your application. Check your logs for any uncaught errors and/or rejections.', ); diff --git a/src/utils/lifecycle.js b/src/utils/lifecycle.js index 8fb5029..6a947c9 100644 --- a/src/utils/lifecycle.js +++ b/src/utils/lifecycle.js @@ -1,3 +1,4 @@ +import Promise from '../promise'; import logger from './logger'; const MAX_LIFECYCLE_EXECUTION_TIME_IN_MS = 300; diff --git a/src/worker.js b/src/worker.js index 59db4fd..4f9230e 100644 --- a/src/worker.js +++ b/src/worker.js @@ -1,6 +1,7 @@ import bodyParser from 'body-parser'; import './environment'; +import Promise from './promise'; import logger from './utils/logger'; import renderBatch from './utils/renderBatch'; import { runAppLifecycle, errorSync, raceTo } from './utils/lifecycle';