diff --git a/src/coffee-script.js b/src/coffee-script.js index efdcbb72b..b40a3d9d6 100644 --- a/src/coffee-script.js +++ b/src/coffee-script.js @@ -2,12 +2,7 @@ var crypto = require('crypto') var path = require('path') - -// The coffee-script compiler is required eagerly because: -// 1. It is always used. -// 2. It reassigns Error.prepareStackTrace, so we need to make sure that -// the 'source-map-support' module is installed *after* it is loaded. -var CoffeeScript = require('coffee-script') +var CoffeeScript = null exports.shouldCompile = function() { return true @@ -24,6 +19,10 @@ exports.getCachePath = function(sourceCode) { } exports.compile = function(sourceCode, filePath) { + if (!CoffeeScript) { + CoffeeScript = require('coffee-script') + } + var output = CoffeeScript.compile(sourceCode, { filename: filePath, sourceFiles: [filePath], diff --git a/src/compile-cache.js b/src/compile-cache.js index 366c58800..63ba008ae 100644 --- a/src/compile-cache.js +++ b/src/compile-cache.js @@ -130,3 +130,12 @@ require('source-map-support').install({ } } }) + +// This prevents coffee-script from reassigning `Error.prepareStackTrace` when +// it is loaded. +Object.defineProperty(Error, 'prepareStackTrace', { + value: Error.prepareStackTrace, + configurable: false, + enumerable: true, + writable: false +})