Defer coffee-script require, prevent it from reassigning prepareStackTrace

This commit is contained in:
Max Brunsfeld
2015-08-21 13:45:02 -07:00
parent b533aff8f4
commit f8397661d1
2 changed files with 14 additions and 6 deletions

View File

@@ -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],

View File

@@ -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
})