Skip to content

Commit

Permalink
source map support for stack traces
Browse files Browse the repository at this point in the history
  • Loading branch information
dangreen committed Jan 16, 2016
1 parent 59c6ff0 commit f45c198
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
35 changes: 32 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var path = require('path');
var path = require('path'),
sourceMapSupport = require('source-map-support'),
babelRegisterCache = require('babel-register/lib/cache');

module.exports = function(sails) {

Expand Down Expand Up @@ -36,6 +38,35 @@ module.exports = function(sails) {
sails.log.verbose("Babel hook deactivated.");
} else {

if (sails.config.environment === 'development') {

sourceMapSupport.install({
retrieveSourceMap: function(file) {

var cache = babelRegisterCache.get(),
sourceMap = null;

Object.keys(cache).some(function(hash) {

var fileCache = cache[hash];

if (fileCache.options.filename != file) {
return false;
}

sourceMap = {
url: file,
map: fileCache.map
};

return true;
});

return sourceMap;
}
});
}

if (config.polyfill) {
require("babel-polyfill");
}
Expand All @@ -48,7 +79,5 @@ module.exports = function(sails) {
sails.log.verbose("Babel hook activated. Enjoy ES6/7 power in your Sails app.");
}
},

};

};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"dependencies": {
"babel-register": "^6.3.13",
"babel-preset-es2015": "^6.3.13",
"babel-polyfill": "^6.3.14"
"babel-polyfill": "^6.3.14",
"source-map-support": "^0.4.0"
},
"devDependencies": {
"glob": "^5.0.3",
Expand Down

0 comments on commit f45c198

Please sign in to comment.