diff --git a/tools/tool-env/install-promise.js b/tools/tool-env/install-promise.js index dc78ea6661..10dee1cf07 100644 --- a/tools/tool-env/install-promise.js +++ b/tools/tool-env/install-promise.js @@ -1,10 +1,24 @@ // Install a global ES2015-compliant Promise constructor that knows how to // run all its callbacks in Fibers. -var Promise = global.Promise = global.Promise || +var Promise = global.Promise || require("promise/lib/es6-extensions"); -require("meteor-promise").makeCompatible( - Promise, - require("fibers") -); +function makeCompatible(newPromise) { + require("meteor-promise").makeCompatible( + newPromise, + require("fibers") + ); +} + +makeCompatible(Promise); + +Object.defineProperty(global, "Promise", { + get: function () { + return Promise; + }, + + // Make the new Promise compatible with Fibers, but do not allow further + // modifications to global.Promise, e.g. by misbehaving polyfills. + set: makeCompatible +}); diff --git a/tools/tool-testing/selftest.js b/tools/tool-testing/selftest.js index 49d5e7445a..c2ae7feb44 100644 --- a/tools/tool-testing/selftest.js +++ b/tools/tool-testing/selftest.js @@ -27,8 +27,10 @@ var release = require('../packaging/release.js'); var projectContextModule = require('../project-context.js'); var upgraders = require('../upgraders.js'); +require("../tool-env/install-runtime.js"); + try { - var phantomjs = require('phantomjs-prebuilt'); + var phantomPath = require.resolve('phantomjs-prebuilt'); } catch (e) { throw new Error([ "Please install PhantomJS by running the following command:", @@ -40,6 +42,8 @@ try { ].join("\n")); } +var phantomjs = require(phantomPath); + // To allow long stack traces that cross async boundaries require('longjohn');