Skip to content

Commit

Permalink
Add SHA-1 based CoffeeScript compile cache
Browse files Browse the repository at this point in the history
This restores the require cache that was used pre-node integration
  • Loading branch information
kevinsawicki committed Sep 9, 2013
1 parent e10f06e commit bc76b70
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"atomShellVersion": "0.4.5",
"dependencies": {
"async": "0.2.6",
"coffee-cache": "0.1.0",
"coffee-script": "1.6.2",
"coffeestack": "0.4.0",
"first-mate": "0.1.0",
Expand Down
1 change: 0 additions & 1 deletion script/cibuild
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set -e
cd "$(dirname "$0")/.."

rm -rf ~/.atom
rm -rf /tmp/atom-coffee-cache
git clean -dff

./script/bootstrap
Expand Down
24 changes: 24 additions & 0 deletions src/coffee-cache.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
crypto = require 'crypto'
fs = require 'fs'
path = require 'path'

CoffeeScript = require 'coffee-script'
mkdir = require('mkdirp').sync

getCachePath = (coffeeContents)->
digest = crypto.createHash('sha1').update(coffeeContents, 'utf8').digest('hex')
path.join('/tmp/atom-compile-cache/coffee', "#{digest}.coffee")

require.extensions['.coffee'] = (module, filePath) ->
coffeeContents = fs.readFileSync(filePath, 'utf8')
cachePath = getCachePath(coffeeContents)
try
jsContents = fs.readFileSync(cachePath, 'utf8') if fs.statSync(cachePath).isFile()

unless jsContents?
jsContents = CoffeeScript.compile(coffeeContents, filename: filePath)
try
mkdir(path.dirname(cachePath))
fs.writeFileSync(cachePath, jsContents)

module._compile(jsContents, filePath)
4 changes: 2 additions & 2 deletions src/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ delegate.browserMainParts.preMainMessageLoopRun = ->

if args.devMode
require('coffee-script')
require('coffee-cache').setCacheDir('/tmp/atom-coffee-cache')
require('module').globalPaths.push(args.resourcePath + "/src")
require(path.join(args.resourcePath, 'src', 'coffee-cache'))
require('module').globalPaths.push(path.join(args.resourcePath, 'src'))
else
appSrcPath = path.resolve(process.argv[0], "../../Resources/app/src")
require('module').globalPaths.push(appSrcPath)
Expand Down
2 changes: 1 addition & 1 deletion src/task.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Task
constructor: (taskPath) ->
bootstrap = """
require('coffee-script');
require('coffee-cache').setCacheDir('/tmp/atom-coffee-cache');
require('coffee-cache');
Object.defineProperty(require.extensions, '.coffee', {
writable: false,
value: require.extensions['.coffee']
Expand Down
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var currentWindow = require('remote').getCurrentWindow();
try {
require('coffee-script');
require('coffee-cache').setCacheDir('/tmp/atom-coffee-cache');
require('coffee-cache');
Object.defineProperty(require.extensions, '.coffee', {
writable: false,
value: require.extensions['.coffee']
Expand Down
2 changes: 1 addition & 1 deletion tasks/clean-task.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = (grunt) ->

grunt.registerTask 'partial-clean', 'Delete some of the build files', ->
rm grunt.config.get('atom.buildDir')
rm '/tmp/atom-coffee-cache'
rm '/tmp/atom-compile-cache'
rm '/tmp/atom-cached-atom-shells'
rm 'atom-shell'

Expand Down

0 comments on commit bc76b70

Please sign in to comment.