From 89d334f0b80fe1fc2c3c9010d9afb459359901f9 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 11 Feb 2015 16:29:11 -0800 Subject: [PATCH 01/23] :arrow_up: season@5.1.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 84ca82304..02a44cd67 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "scandal": "2.0.0", "scoped-property-store": "^0.16.2", "scrollbar-style": "^2.0.0", - "season": "^5.1.2", + "season": "^5.1.4", "semver": "~4.2", "serializable": "^1", "service-hub": "^0.4.0", From 0738d456b54b57687c34d95a3149e8473c17e16d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 10:57:38 -0800 Subject: [PATCH 02/23] Use coffee-cash module --- package.json | 1 + src/6to5.coffee | 7 ++++--- src/browser/main.coffee | 18 +++++++----------- src/task.coffee | 7 +++---- static/index.js | 36 +++++++++++++++++------------------- 5 files changed, 32 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index 02a44cd67..fea47001f 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "atom-keymap": "^3.1.2", "bootstrap": "git+https://github.com/atom/bootstrap.git#6af81906189f1747fd6c93479e3d998ebe041372", "clear-cut": "0.4.0", + "coffee-cash": "0.5.0", "coffee-script": "1.8.0", "coffeestack": "0.8.0", "color": "^0.7.3", diff --git a/src/6to5.coffee b/src/6to5.coffee index 15059ad62..e24c63768 100644 --- a/src/6to5.coffee +++ b/src/6to5.coffee @@ -89,6 +89,7 @@ create6to5VersionAndOptionsDigest = (version, options) -> updateDigestForJsonValue(shasum, options) shasum.digest('hex') +cacheDir = null jsCacheDir = null getCachePath = (sourceCode) -> @@ -96,8 +97,7 @@ getCachePath = (sourceCode) -> unless jsCacheDir? to5Version = require('6to5-core/package.json').version - cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache') - jsCacheDir = path.join(cacheDir, 'js', '6to5', create6to5VersionAndOptionsDigest(to5Version, defaultOptions)) + jsCacheDir = path.join(cacheDir, '6to5', create6to5VersionAndOptionsDigest(to5Version, defaultOptions)) path.join(jsCacheDir, "#{digest}.js") @@ -139,7 +139,8 @@ loadFile = (module, filePath) -> js = getCachedJavaScript(cachePath) ? transpile(sourceCode, filePath, cachePath) module._compile(js, filePath) -register = -> +register = (newCacheDir) -> + cacheDir = newCacheDir Object.defineProperty(require.extensions, '.js', { writable: false value: loadFile diff --git a/src/browser/main.coffee b/src/browser/main.coffee index 22360a076..f1027e7db 100644 --- a/src/browser/main.coffee +++ b/src/browser/main.coffee @@ -15,6 +15,8 @@ process.on 'uncaughtException', (error={}) -> start = -> setupAtomHome() + setupCoffeeCache() + if process.platform is 'win32' SquirrelUpdate = require './squirrel-update' squirrelCommand = process.argv[1] @@ -49,9 +51,7 @@ start = -> else path.resolve(pathToOpen) - setupCoffeeScript() if args.devMode - require(path.join(args.resourcePath, 'src', 'coffee-cache')).register() AtomApplication = require path.join(args.resourcePath, 'src', 'browser', 'atom-application') else AtomApplication = require './atom-application' @@ -66,15 +66,6 @@ global.devResourcePath = path.normalize(global.devResourcePath) if global.devRes setupCrashReporter = -> crashReporter.start(productName: 'Atom', companyName: 'GitHub') -setupCoffeeScript = -> - CoffeeScript = null - - require.extensions['.coffee'] = (module, filePath) -> - CoffeeScript ?= require('coffee-script') - coffee = fs.readFileSync(filePath, 'utf8') - js = CoffeeScript.compile(coffee, filename: filePath) - module._compile(js, filePath) - setupAtomHome = -> return if process.env.ATOM_HOME @@ -83,6 +74,11 @@ setupAtomHome = -> atomHome = fs.realpathSync(atomHome) process.env.ATOM_HOME = atomHome +setupCoffeeCache = -> + CoffeeCache = require 'coffee-cash' + cacheDirectory = path.join(process.env.ATOM_HOME, 'compile-cache', 'coffee') + CoffeeCache.register(cacheDirectory) + parseCommandLine = -> version = app.getVersion() options = optimist(process.argv[1..]) diff --git a/src/task.coffee b/src/task.coffee index 42b744b6d..7ac635642 100644 --- a/src/task.coffee +++ b/src/task.coffee @@ -65,12 +65,11 @@ class Task # * `taskPath` The {String} path to the CoffeeScript/JavaScript file that # exports a single {Function} to execute. constructor: (taskPath) -> - coffeeCacheRequire = "require('#{require.resolve('./coffee-cache')}').register();" - coffeeScriptRequire = "require('#{require.resolve('coffee-script')}').register();" + coffeeCacheRequire = "require('#{require.resolve('coffee-cash')}')" + coffeeCachePath = require('coffee-cash').getCacheDirectory() taskBootstrapRequire = "require('#{require.resolve('./task-bootstrap')}');" bootstrap = """ - #{coffeeScriptRequire} - #{coffeeCacheRequire} + #{coffeeCacheRequire}.register('#{coffeeCachePath}'); #{taskBootstrapRequire} """ bootstrap = bootstrap.replace(/\\/g, "\\\\") diff --git a/static/index.js b/static/index.js index e5f84f794..670da0072 100644 --- a/static/index.js +++ b/static/index.js @@ -1,11 +1,3 @@ -function registerRuntimeTranspilers() { - // This sets require.extensions['.coffee']. - require('coffee-script').register(); - - // This redefines require.extensions['.js']. - require('../src/6to5').register(); -} - window.onload = function() { try { var startTime = Date.now(); @@ -13,6 +5,22 @@ window.onload = function() { var fs = require('fs'); var path = require('path'); + function registerRuntimeTranspilers() { + var cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache'); + // Use separate compile cache when sudo'ing as root to avoid permission issues + if (process.env.USER === 'root' && process.env.SUDO_USER && process.env.SUDO_USER !== process.env.USER) { + cacheDir = path.join(cacheDir, 'root'); + } + + // This sets require.extensions['.coffee']. + require('coffee-cash').register(path.join(cacheDir, 'coffee')); + + require('season').setCacheDir(path.join(cacheDir, 'cson')); + + // This redefines require.extensions['.js']. + require('../src/6to5').register(path.join(cacheDir, 'js')); + } + // Ensure ATOM_HOME is always set before anything else is required if (!process.env.ATOM_HOME) { var home; @@ -45,10 +53,7 @@ window.onload = function() { var devMode = loadSettings.devMode || !loadSettings.resourcePath.startsWith(process.resourcesPath + path.sep); - // Require before the module cache in dev mode - if (devMode) { - registerRuntimeTranspilers(); - } + registerRuntimeTranspilers(); ModuleCache = require('../src/module-cache'); ModuleCache.register(loadSettings); @@ -64,13 +69,6 @@ window.onload = function() { }); require('vm-compatibility-layer'); - - if (!devMode) { - registerRuntimeTranspilers(); - } - - require('../src/coffee-cache').register(); - require(loadSettings.bootstrapScript); require('ipc').sendChannel('window-command', 'window:loaded'); From e9eb3d1d348801bff0518f5faa4e96adab82b5c6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 11:01:04 -0800 Subject: [PATCH 03/23] Remove old coffee cache --- src/coffee-cache.coffee | 76 ----------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 src/coffee-cache.coffee diff --git a/src/coffee-cache.coffee b/src/coffee-cache.coffee deleted file mode 100644 index 1e06fd4d5..000000000 --- a/src/coffee-cache.coffee +++ /dev/null @@ -1,76 +0,0 @@ -crypto = require 'crypto' -path = require 'path' - -CoffeeScript = require 'coffee-script' -CSON = require 'season' -fs = require 'fs-plus' - -cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache') - -stats = - hits: 0 - misses: 0 - -# Use separate compile cache when sudo'ing as root to avoid permission issues -if process.env.USER is 'root' and process.env.SUDO_USER and process.env.SUDO_USER isnt process.env.USER - cacheDir = path.join(cacheDir, 'root') - -coffeeCacheDir = path.join(cacheDir, 'coffee') -CSON.setCacheDir(path.join(cacheDir, 'cson')) - -getCachePath = (coffee) -> - digest = crypto.createHash('sha1').update(coffee, 'utf8').digest('hex') - path.join(coffeeCacheDir, "#{digest}.js") - -getCachedJavaScript = (cachePath) -> - if fs.isFileSync(cachePath) - try - cachedJavaScript = fs.readFileSync(cachePath, 'utf8') - stats.hits++ - return cachedJavaScript - return - -convertFilePath = (filePath) -> - if process.platform is 'win32' - filePath = "/#{path.resolve(filePath).replace(/\\/g, '/')}" - encodeURI(filePath) - -compileCoffeeScript = (coffee, filePath, cachePath) -> - {js, v3SourceMap} = CoffeeScript.compile(coffee, filename: filePath, sourceMap: true) - stats.misses++ - # Include source map in the web page environment. - if btoa? and JSON? and unescape? and encodeURIComponent? - js = "#{js}\n//# sourceMappingURL=data:application/json;base64,#{btoa unescape encodeURIComponent v3SourceMap}\n//# sourceURL=#{convertFilePath(filePath)}" - try - fs.writeFileSync(cachePath, js) - js - -requireCoffeeScript = (module, filePath) -> - coffee = fs.readFileSync(filePath, 'utf8') - cachePath = getCachePath(coffee) - js = getCachedJavaScript(cachePath) ? compileCoffeeScript(coffee, filePath, cachePath) - module._compile(js, filePath) - -module.exports = - cacheDir: cacheDir - - register: -> - Object.defineProperty(require.extensions, '.coffee', { - writable: false - value: requireCoffeeScript - }) - - addPathToCache: (filePath) -> - switch path.extname(filePath) - when '.coffee' - content = fs.readFileSync(filePath, 'utf8') - cachePath = getCachePath(coffee) - compileCoffeeScript(coffee, filePath, cachePath) - when '.cson' - CSON.readFileSync(filePath) - when '.js' - require('./6to5').addPathToCache(filePath) - - getCacheMisses: -> stats.misses - - getCacheHits: -> stats.hits From d7e4099bc43f77d49ad4ede5d94769088d44d34a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 11:02:25 -0800 Subject: [PATCH 04/23] :arrow_up: grim@1.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fea47001f..a0391365d 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "fstream": "0.1.24", "fuzzaldrin": "^2.1", "git-utils": "^3.0.0", - "grim": "1.1.1", + "grim": "1.1.2", "guid": "0.0.10", "jasmine-json": "~0.0", "jasmine-tagged": "^1.1.3", From dea381e83b43a5dd5e90f895d38350d6f33ad871 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 11:03:23 -0800 Subject: [PATCH 05/23] :arrow_up: exception-reporting@0.24 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a0391365d..66bc1542f 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "deprecation-cop": "0.36.0", "dev-live-reload": "0.41.0", "encoding-selector": "0.18.0", - "exception-reporting": "0.23.0", + "exception-reporting": "0.24.0", "find-and-replace": "0.157.0", "fuzzy-finder": "0.66.0", "git-diff": "0.52.0", From 8a4fb47c74ad1b88f01213927e23da3094644472 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 11:07:21 -0800 Subject: [PATCH 06/23] :arrow_up: jasmine-tagged@1.1.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 66bc1542f..88f77b894 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "grim": "1.1.2", "guid": "0.0.10", "jasmine-json": "~0.0", - "jasmine-tagged": "^1.1.3", + "jasmine-tagged": "^1.1.4", "jquery": "^2.1.1", "less-cache": "0.21", "marked": "^0.3", From 2bd782f9e0a2144e7169841344dc53fb042a200a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 11:09:49 -0800 Subject: [PATCH 07/23] :arrow_up: coffeestack@1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 88f77b894..22aa4f331 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "clear-cut": "0.4.0", "coffee-cash": "0.5.0", "coffee-script": "1.8.0", - "coffeestack": "0.8.0", + "coffeestack": "^1", "color": "^0.7.3", "delegato": "^1", "emissary": "^1.3.1", From da3b1a48819b54d0623757f95362b6d3e0a34944 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 11:15:59 -0800 Subject: [PATCH 08/23] Add root cache check in browser process --- src/browser/main.coffee | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/browser/main.coffee b/src/browser/main.coffee index f1027e7db..e4b212cd3 100644 --- a/src/browser/main.coffee +++ b/src/browser/main.coffee @@ -76,7 +76,11 @@ setupAtomHome = -> setupCoffeeCache = -> CoffeeCache = require 'coffee-cash' - cacheDirectory = path.join(process.env.ATOM_HOME, 'compile-cache', 'coffee') + cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache'); + # Use separate compile cache when sudo'ing as root to avoid permission issues + if process.env.USER is 'root' and process.env.SUDO_USER and process.env.SUDO_USER isnt process.env.USER + cacheDir = path.join(cacheDir, 'root') + cacheDirectory = path.join(cacheDir, 'coffee') CoffeeCache.register(cacheDirectory) parseCommandLine = -> From d6212cfc795d3848ff080cd89998ef678e83278b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 11:16:12 -0800 Subject: [PATCH 09/23] Start caching source maps --- static/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/static/index.js b/static/index.js index 670da0072..36f6d4a67 100644 --- a/static/index.js +++ b/static/index.js @@ -15,6 +15,8 @@ window.onload = function() { // This sets require.extensions['.coffee']. require('coffee-cash').register(path.join(cacheDir, 'coffee')); + require('coffeestack').setCacheDirectory(path.join(cacheDir, 'coffee', 'source-maps')); + require('season').setCacheDir(path.join(cacheDir, 'cson')); // This redefines require.extensions['.js']. From 68926d1319486d1a5af0a05ed0d439ec7bfabe0e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 11:18:37 -0800 Subject: [PATCH 10/23] :art: Comment each cache setup --- static/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/static/index.js b/static/index.js index 36f6d4a67..88634ee63 100644 --- a/static/index.js +++ b/static/index.js @@ -12,14 +12,16 @@ window.onload = function() { cacheDir = path.join(cacheDir, 'root'); } - // This sets require.extensions['.coffee']. + // Setup caching of .coffee files require('coffee-cash').register(path.join(cacheDir, 'coffee')); + // Set up caching of source maps for generated stack traces require('coffeestack').setCacheDirectory(path.join(cacheDir, 'coffee', 'source-maps')); + // Setup caching of .cson files require('season').setCacheDir(path.join(cacheDir, 'cson')); - // This redefines require.extensions['.js']. + // Setup caching of .js files that start with "use 6to5" require('../src/6to5').register(path.join(cacheDir, 'js')); } From 57bb4c322c4fde74cdaa7d7a8f92876c60343435 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 11:37:26 -0800 Subject: [PATCH 11/23] Add source map caching to tasks --- package.json | 2 +- src/task.coffee | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 22aa4f331..891376183 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "clear-cut": "0.4.0", "coffee-cash": "0.5.0", "coffee-script": "1.8.0", - "coffeestack": "^1", + "coffeestack": "^1.1", "color": "^0.7.3", "delegato": "^1", "emissary": "^1.3.1", diff --git a/src/task.coffee b/src/task.coffee index 7ac635642..a69eedd01 100644 --- a/src/task.coffee +++ b/src/task.coffee @@ -67,9 +67,12 @@ class Task constructor: (taskPath) -> coffeeCacheRequire = "require('#{require.resolve('coffee-cash')}')" coffeeCachePath = require('coffee-cash').getCacheDirectory() + coffeeStackRequire = "require('#{require.resolve('coffeestack')}')" + stackCachePath = require('coffeestack').getCacheDirectory() taskBootstrapRequire = "require('#{require.resolve('./task-bootstrap')}');" bootstrap = """ #{coffeeCacheRequire}.register('#{coffeeCachePath}'); + #{coffeeStackRequire}.setCacheDirectory('#{stackCachePath}'); #{taskBootstrapRequire} """ bootstrap = bootstrap.replace(/\\/g, "\\\\") From efd8f160da3f3914138e261f99cf987ab544c855 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 12:10:12 -0800 Subject: [PATCH 12/23] Add helper to warm caches on apm install --- package.json | 2 +- src/6to5.coffee | 9 +++++++-- src/compile-cache.coffee | 26 ++++++++++++++++++++++++++ static/index.js | 8 ++++++-- 4 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/compile-cache.coffee diff --git a/package.json b/package.json index 891376183..4c0e8ba97 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "atom-keymap": "^3.1.2", "bootstrap": "git+https://github.com/atom/bootstrap.git#6af81906189f1747fd6c93479e3d998ebe041372", "clear-cut": "0.4.0", - "coffee-cash": "0.5.0", + "coffee-cash": "0.6.0", "coffee-script": "1.8.0", "coffeestack": "^1.1", "color": "^0.7.3", diff --git a/src/6to5.coffee b/src/6to5.coffee index e24c63768..3ceb81480 100644 --- a/src/6to5.coffee +++ b/src/6to5.coffee @@ -139,15 +139,20 @@ loadFile = (module, filePath) -> js = getCachedJavaScript(cachePath) ? transpile(sourceCode, filePath, cachePath) module._compile(js, filePath) -register = (newCacheDir) -> - cacheDir = newCacheDir +register = -> Object.defineProperty(require.extensions, '.js', { writable: false value: loadFile }) +setCacheDirectory = (newCacheDir) -> + if cacheDir isnt newCacheDir + cacheDir = newCacheDir + jsCacheDir = null + module.exports = register: register + setCacheDirectory: setCacheDirectory getCacheMisses: -> stats.misses getCacheHits: -> stats.hits diff --git a/src/compile-cache.coffee b/src/compile-cache.coffee new file mode 100644 index 000000000..d5e9f0ccf --- /dev/null +++ b/src/compile-cache.coffee @@ -0,0 +1,26 @@ +path = require 'path' + +CSON = require 'season' +CoffeeCache = require 'coffee-cash' +to5 = require './6to5' + +cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache') +# Use separate compile cache when sudo'ing as root to avoid permission issues +if process.env.USER is 'root' and process.env.SUDO_USER and process.env.SUDO_USER isnt process.env.USER + cacheDir = path.join(cacheDir, 'root') + +CoffeeCache.setCacheDirectory(path.join(cacheDir, 'coffee')) +CSON.setCacheDir(path.join(cacheDir, 'cson')) +to5.setCacheDirectory(path.join(cacheDir, 'js')) + +# This file is required directly by apm so that files can be cached during +# package install so that the first package load in Atom doesn't have to +# compile anything. +exports.addPathToCache = (filePath) -> + switch path.extname(filePath) + when '.coffee' + CoffeeCache.addPathToCache(filePath) + when '.cson' + CSON.readFileSync(filePath) + when '.js' + to5.addPathToCache(filePath) diff --git a/static/index.js b/static/index.js index 88634ee63..ebb921100 100644 --- a/static/index.js +++ b/static/index.js @@ -13,7 +13,9 @@ window.onload = function() { } // Setup caching of .coffee files - require('coffee-cash').register(path.join(cacheDir, 'coffee')); + var CoffeeCache = require('coffee-cash'); + CoffeeCache.setCacheDirectory(path.join(cacheDir, 'coffee')); + CoffeeCache.register(); // Set up caching of source maps for generated stack traces require('coffeestack').setCacheDirectory(path.join(cacheDir, 'coffee', 'source-maps')); @@ -22,7 +24,9 @@ window.onload = function() { require('season').setCacheDir(path.join(cacheDir, 'cson')); // Setup caching of .js files that start with "use 6to5" - require('../src/6to5').register(path.join(cacheDir, 'js')); + var to5 = require('../src/6to5'); + to5.setCacheDirectory(path.join(cacheDir, 'js')); + to5.register(); } // Ensure ATOM_HOME is always set before anything else is required From a5f40e2e7fec304efc5b1d3929d3ebc5f640c313 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 12:23:44 -0800 Subject: [PATCH 13/23] Call setCacheDirectory on CoffeeCache --- src/browser/main.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/browser/main.coffee b/src/browser/main.coffee index e4b212cd3..e8b9c3cd2 100644 --- a/src/browser/main.coffee +++ b/src/browser/main.coffee @@ -80,8 +80,8 @@ setupCoffeeCache = -> # Use separate compile cache when sudo'ing as root to avoid permission issues if process.env.USER is 'root' and process.env.SUDO_USER and process.env.SUDO_USER isnt process.env.USER cacheDir = path.join(cacheDir, 'root') - cacheDirectory = path.join(cacheDir, 'coffee') - CoffeeCache.register(cacheDirectory) + CoffeeCache.setCacheDirectory(path.join(cacheDir, 'coffee')) + CoffeeCache.register() parseCommandLine = -> version = app.getVersion() From 86cdfaeb9487a29dfb3b0156aa8223fb82085db0 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 12:27:00 -0800 Subject: [PATCH 14/23] Set cache directory in tasks --- src/task.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/task.coffee b/src/task.coffee index a69eedd01..6fe055ca6 100644 --- a/src/task.coffee +++ b/src/task.coffee @@ -71,7 +71,8 @@ class Task stackCachePath = require('coffeestack').getCacheDirectory() taskBootstrapRequire = "require('#{require.resolve('./task-bootstrap')}');" bootstrap = """ - #{coffeeCacheRequire}.register('#{coffeeCachePath}'); + #{coffeeCacheRequire}.setCacheDirectory('#{coffeeCachePath}'); + #{coffeeCacheRequire}.register(); #{coffeeStackRequire}.setCacheDirectory('#{stackCachePath}'); #{taskBootstrapRequire} """ From 01f059d156d35c5d0a1bdf016c1bc5f5d91bb3de Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 13:23:29 -0800 Subject: [PATCH 15/23] Allow atom home to be passed in --- src/compile-cache.coffee | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/compile-cache.coffee b/src/compile-cache.coffee index d5e9f0ccf..3eeac000a 100644 --- a/src/compile-cache.coffee +++ b/src/compile-cache.coffee @@ -1,22 +1,21 @@ path = require 'path' - CSON = require 'season' CoffeeCache = require 'coffee-cash' to5 = require './6to5' -cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache') -# Use separate compile cache when sudo'ing as root to avoid permission issues -if process.env.USER is 'root' and process.env.SUDO_USER and process.env.SUDO_USER isnt process.env.USER - cacheDir = path.join(cacheDir, 'root') - -CoffeeCache.setCacheDirectory(path.join(cacheDir, 'coffee')) -CSON.setCacheDir(path.join(cacheDir, 'cson')) -to5.setCacheDirectory(path.join(cacheDir, 'js')) - # This file is required directly by apm so that files can be cached during # package install so that the first package load in Atom doesn't have to # compile anything. -exports.addPathToCache = (filePath) -> +exports.addPathToCache = (filePath, atomHome) -> + cacheDir = path.join(atomHome, 'compile-cache') + # Use separate compile cache when sudo'ing as root to avoid permission issues + if process.env.USER is 'root' and process.env.SUDO_USER and process.env.SUDO_USER isnt process.env.USER + cacheDir = path.join(cacheDir, 'root') + + CoffeeCache.setCacheDirectory(path.join(cacheDir, 'coffee')) + CSON.setCacheDir(path.join(cacheDir, 'cson')) + to5.setCacheDirectory(path.join(cacheDir, 'js')) + switch path.extname(filePath) when '.coffee' CoffeeCache.addPathToCache(filePath) From fcced492d4908afe584ba80cfacfebe23ead60c9 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 13:31:49 -0800 Subject: [PATCH 16/23] Break out helper methods in index.js --- static/index.js | 95 +++++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 42 deletions(-) diff --git a/static/index.js b/static/index.js index ebb921100..fefb343e6 100644 --- a/static/index.js +++ b/static/index.js @@ -1,49 +1,17 @@ +var fs = require('fs'); +var path = require('path'); + window.onload = function() { try { var startTime = Date.now(); - var fs = require('fs'); - var path = require('path'); - - function registerRuntimeTranspilers() { - var cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache'); - // Use separate compile cache when sudo'ing as root to avoid permission issues - if (process.env.USER === 'root' && process.env.SUDO_USER && process.env.SUDO_USER !== process.env.USER) { - cacheDir = path.join(cacheDir, 'root'); - } - - // Setup caching of .coffee files - var CoffeeCache = require('coffee-cash'); - CoffeeCache.setCacheDirectory(path.join(cacheDir, 'coffee')); - CoffeeCache.register(); - - // Set up caching of source maps for generated stack traces - require('coffeestack').setCacheDirectory(path.join(cacheDir, 'coffee', 'source-maps')); - - // Setup caching of .cson files - require('season').setCacheDir(path.join(cacheDir, 'cson')); - - // Setup caching of .js files that start with "use 6to5" - var to5 = require('../src/6to5'); - to5.setCacheDirectory(path.join(cacheDir, 'js')); - to5.register(); - } - // Ensure ATOM_HOME is always set before anything else is required - if (!process.env.ATOM_HOME) { - var home; - if (process.platform === 'win32') { - home = process.env.USERPROFILE; - } else { - home = process.env.HOME; - } - var atomHome = path.join(home, '.atom'); - try { - atomHome = fs.realpathSync(atomHome); - } catch (error) { - // Ignore since the path might just not exist yet. - } - process.env.ATOM_HOME = atomHome; + setupAtomHome(); + + var cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache'); + // Use separate compile cache when sudo'ing as root to avoid permission issues + if (process.env.USER === 'root' && process.env.SUDO_USER && process.env.SUDO_USER !== process.env.USER) { + cacheDir = path.join(cacheDir, 'root'); } // Skip "?loadSettings=". @@ -61,7 +29,7 @@ window.onload = function() { var devMode = loadSettings.devMode || !loadSettings.resourcePath.startsWith(process.resourcesPath + path.sep); - registerRuntimeTranspilers(); + setupCoffeeCache(cacheDir); ModuleCache = require('../src/module-cache'); ModuleCache.register(loadSettings); @@ -77,6 +45,11 @@ window.onload = function() { }); require('vm-compatibility-layer'); + + setupCsonCache(cacheDir); + setupSourceMapCache(cacheDir); + setup6to5(cacheDir); + require(loadSettings.bootstrapScript); require('ipc').sendChannel('window-command', 'window:loaded'); @@ -94,3 +67,41 @@ window.onload = function() { console.error(error.stack || error); } } + +var setupCoffeeCache = function(cacheDir) { + var CoffeeCache = require('coffee-cash'); + CoffeeCache.setCacheDirectory(path.join(cacheDir, 'coffee')); + CoffeeCache.register(); +} + +var setupAtomHome = function() { + if (!process.env.ATOM_HOME) { + var home; + if (process.platform === 'win32') { + home = process.env.USERPROFILE; + } else { + home = process.env.HOME; + } + var atomHome = path.join(home, '.atom'); + try { + atomHome = fs.realpathSync(atomHome); + } catch (error) { + // Ignore since the path might just not exist yet. + } + process.env.ATOM_HOME = atomHome; + } +} + +var setup6to5 = function(cacheDir) { + var to5 = require('../src/6to5'); + to5.setCacheDirectory(path.join(cacheDir, 'js')); + to5.register(); +} + +var setupCsonCache = function(cacheDir) { + require('season').setCacheDir(path.join(cacheDir, 'cson')); +} + +var setupSourceMapCache = function(cacheDir) { + require('coffeestack').setCacheDirectory(path.join(cacheDir, 'coffee', 'source-maps')); +} From 445eee42dba24f268ac380f0df3d29658f60467b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 13:34:17 -0800 Subject: [PATCH 17/23] :art: --- static/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/static/index.js b/static/index.js index fefb343e6..a58c1170d 100644 --- a/static/index.js +++ b/static/index.js @@ -57,8 +57,7 @@ window.onload = function() { global.atom.loadTime = Date.now() - startTime; console.log('Window load time: ' + global.atom.getWindowLoadTime() + 'ms'); } - } - catch (error) { + } catch (error) { var currentWindow = require('remote').getCurrentWindow(); currentWindow.setSize(800, 600); currentWindow.center(); From 3f246035da829f27e914cd3ae62207f6d110cc1c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 13:36:37 -0800 Subject: [PATCH 18/23] Remove semicolon --- src/browser/main.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser/main.coffee b/src/browser/main.coffee index e8b9c3cd2..3b6018d5b 100644 --- a/src/browser/main.coffee +++ b/src/browser/main.coffee @@ -76,7 +76,7 @@ setupAtomHome = -> setupCoffeeCache = -> CoffeeCache = require 'coffee-cash' - cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache'); + cacheDir = path.join(process.env.ATOM_HOME, 'compile-cache') # Use separate compile cache when sudo'ing as root to avoid permission issues if process.env.USER is 'root' and process.env.SUDO_USER and process.env.SUDO_USER isnt process.env.USER cacheDir = path.join(cacheDir, 'root') From 20b2be51d95bde83ffe2cf0fbe8be274ed822054 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 13:53:43 -0800 Subject: [PATCH 19/23] Add initial compile cache spec --- spec/compile-cache-spec.coffee | 28 ++++++++++++++++++++++++++++ spec/fixtures/cson.cson | 1 + src/compile-cache.coffee | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 spec/compile-cache-spec.coffee create mode 100644 spec/fixtures/cson.cson diff --git a/spec/compile-cache-spec.coffee b/spec/compile-cache-spec.coffee new file mode 100644 index 000000000..0cae70434 --- /dev/null +++ b/spec/compile-cache-spec.coffee @@ -0,0 +1,28 @@ +path = require 'path' +CSON = require 'season' +CoffeeCache = require 'coffee-cash' + +to5 = require '../src/6to5' +CompileCache = require '../src/compile-cache' + +describe "Compile Cache", -> + describe ".addPathToCache(filePath)", -> + it "adds the path to the correct CSON, CoffeeScript, or 6to5 cache", -> + spyOn(CSON, 'readFileSync').andCallThrough() + spyOn(CoffeeCache, 'addPathToCache').andCallThrough() + spyOn(to5, 'addPathToCache').andCallThrough() + + CompileCache.addPathToCache(path.join(__dirname, 'fixtures', 'cson.cson')) + expect(CSON.readFileSync.callCount).toBe 1 + expect(CoffeeCache.addPathToCache.callCount).toBe 0 + expect(to5.addPathToCache.callCount).toBe 0 + + CompileCache.addPathToCache(path.join(__dirname, 'fixtures', 'coffee.coffee')) + expect(CSON.readFileSync.callCount).toBe 1 + expect(CoffeeCache.addPathToCache.callCount).toBe 1 + expect(to5.addPathToCache.callCount).toBe 0 + + CompileCache.addPathToCache(path.join(__dirname, 'fixtures', '6to5', 'double-quotes.js')) + expect(CSON.readFileSync.callCount).toBe 1 + expect(CoffeeCache.addPathToCache.callCount).toBe 1 + expect(to5.addPathToCache.callCount).toBe 1 diff --git a/spec/fixtures/cson.cson b/spec/fixtures/cson.cson new file mode 100644 index 000000000..6fe1e8a01 --- /dev/null +++ b/spec/fixtures/cson.cson @@ -0,0 +1 @@ +a: 4 diff --git a/src/compile-cache.coffee b/src/compile-cache.coffee index 3eeac000a..53b16a437 100644 --- a/src/compile-cache.coffee +++ b/src/compile-cache.coffee @@ -7,6 +7,8 @@ to5 = require './6to5' # package install so that the first package load in Atom doesn't have to # compile anything. exports.addPathToCache = (filePath, atomHome) -> + atomHome ?= process.env.ATOM_HOME + cacheDir = path.join(atomHome, 'compile-cache') # Use separate compile cache when sudo'ing as root to avoid permission issues if process.env.USER is 'root' and process.env.SUDO_USER and process.env.SUDO_USER isnt process.env.USER From 718886a077f58741b57dc443c068da5829fc3986 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 13:55:56 -0800 Subject: [PATCH 20/23] Pass in full path to root cache dir --- src/6to5.coffee | 2 +- static/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/6to5.coffee b/src/6to5.coffee index 3ceb81480..2aa5d6344 100644 --- a/src/6to5.coffee +++ b/src/6to5.coffee @@ -97,7 +97,7 @@ getCachePath = (sourceCode) -> unless jsCacheDir? to5Version = require('6to5-core/package.json').version - jsCacheDir = path.join(cacheDir, '6to5', create6to5VersionAndOptionsDigest(to5Version, defaultOptions)) + jsCacheDir = path.join(cacheDir, create6to5VersionAndOptionsDigest(to5Version, defaultOptions)) path.join(jsCacheDir, "#{digest}.js") diff --git a/static/index.js b/static/index.js index a58c1170d..fb56a84bd 100644 --- a/static/index.js +++ b/static/index.js @@ -93,7 +93,7 @@ var setupAtomHome = function() { var setup6to5 = function(cacheDir) { var to5 = require('../src/6to5'); - to5.setCacheDirectory(path.join(cacheDir, 'js')); + to5.setCacheDirectory(path.join(cacheDir, 'js', '6to5')); to5.register(); } From b2d5a4da4bbcbc32be532cd7b8ac0273fe76498b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 13:58:51 -0800 Subject: [PATCH 21/23] :art: --- src/compile-cache.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compile-cache.coffee b/src/compile-cache.coffee index 53b16a437..ec85ae674 100644 --- a/src/compile-cache.coffee +++ b/src/compile-cache.coffee @@ -8,7 +8,6 @@ to5 = require './6to5' # compile anything. exports.addPathToCache = (filePath, atomHome) -> atomHome ?= process.env.ATOM_HOME - cacheDir = path.join(atomHome, 'compile-cache') # Use separate compile cache when sudo'ing as root to avoid permission issues if process.env.USER is 'root' and process.env.SUDO_USER and process.env.SUDO_USER isnt process.env.USER From 71591a8fd8452b01343e54147fab6e3982c96a3d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 14:12:33 -0800 Subject: [PATCH 22/23] :arrow_up: coffee-cash@0.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4c0e8ba97..a70ee36c1 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "atom-keymap": "^3.1.2", "bootstrap": "git+https://github.com/atom/bootstrap.git#6af81906189f1747fd6c93479e3d998ebe041372", "clear-cut": "0.4.0", - "coffee-cash": "0.6.0", + "coffee-cash": "0.7.0", "coffee-script": "1.8.0", "coffeestack": "^1.1", "color": "^0.7.3", From 375b6edeb4309dee36f920e8fad3839067b09cb7 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Feb 2015 14:13:02 -0800 Subject: [PATCH 23/23] Ensure registered extension is enumerable --- src/6to5.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/6to5.coffee b/src/6to5.coffee index 2aa5d6344..9d67efcf8 100644 --- a/src/6to5.coffee +++ b/src/6to5.coffee @@ -141,6 +141,7 @@ loadFile = (module, filePath) -> register = -> Object.defineProperty(require.extensions, '.js', { + enumerable: true writable: false value: loadFile })