diff --git a/src/babel.js b/src/babel.js index e44d78996..8223cb634 100644 --- a/src/babel.js +++ b/src/babel.js @@ -1,6 +1,5 @@ 'use strict' -var _ = require('underscore-plus') var crypto = require('crypto') var path = require('path') var defaultOptions = require('../static/babelrc.json') @@ -45,7 +44,10 @@ exports.compile = function(sourceCode, filePath) { babel = require('babel-core') } - var options = _.defaults({filename: filePath}, defaultOptions) + var options = {filename: filePath} + for (var key in defaultOptions) { + options[key] = defaultOptions[key] + } return babel.transform(sourceCode, options).code } diff --git a/src/compile-cache.js b/src/compile-cache.js index ab9f8b663..366c58800 100644 --- a/src/compile-cache.js +++ b/src/compile-cache.js @@ -1,9 +1,8 @@ 'use strict' var path = require('path') -var CSON = require('season') var fs = require('fs-plus') -var _ = require('underscore-plus') +var CSON = null var COMPILERS = { '.js': require('./babel'), @@ -13,7 +12,9 @@ var COMPILERS = { var cacheDirectory = null -_.each(COMPILERS, function (compiler, extension) { +Object.keys(COMPILERS).forEach(function (extension) { + var compiler = COMPILERS[extension] + Object.defineProperty(require.extensions, extension, { enumerable: true, writable: false, @@ -34,7 +35,6 @@ exports.setAtomHomeDirectory = function (atomHome) { exports.setCacheDirectory = function (directory) { cacheDirectory = directory - CSON.setCacheDir(path.join(cacheDirectory, 'cson')); } exports.getCacheDirectory = function () { @@ -46,6 +46,7 @@ exports.addPathToCache = function (filePath, atomHome) { var extension = path.extname(filePath) if (extension === '.cson') { + CSON = CSON || require('season') CSON.readFileSync(filePath) } else { var compiler = COMPILERS[extension] diff --git a/static/index.js b/static/index.js index 238cb385e..4769837cc 100644 --- a/static/index.js +++ b/static/index.js @@ -78,6 +78,7 @@ var setupWindow = function(loadSettings) { }); setupVmCompatibility(); + setupCsonCache(compileCache.getCacheDirectory()) require(loadSettings.bootstrapScript); require('ipc').sendChannel('window-command', 'window:loaded'); @@ -101,6 +102,10 @@ var setupAtomHome = function() { } } +var setupCsonCache = function(cacheDir) { + require('season').setCacheDir(path.join(cacheDir, 'cson')); +} + var setupVmCompatibility = function() { var vm = require('vm'); if (!vm.Script.createContext) {