mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add helper to warm caches on apm install
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
26
src/compile-cache.coffee
Normal file
26
src/compile-cache.coffee
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user