From 15a06cbdb33b93a32b66cba2991246d3aa2b4caa Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sun, 27 Jan 2013 18:11:07 -0800 Subject: [PATCH] DRY up how cache file path is generated --- src/stdlib/require.coffee | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/stdlib/require.coffee b/src/stdlib/require.coffee index 85e6cac8f..e5718085b 100644 --- a/src/stdlib/require.coffee +++ b/src/stdlib/require.coffee @@ -55,9 +55,7 @@ exts = eval("define(function(require, exports, module) { 'use strict';" + code + "})\n//@ sourceURL=" + file) __defines.pop()?.call() coffee: (file, retry=true) -> - tmpPath = "/tmp/atom-compiled-scripts" - cacheFilePath = [tmpPath, $native.md5ForPath(file)].join("/") - + cacheFilePath = getCacheFilePath(file) if __exists(cacheFilePath) compiled = __read(cacheFilePath) writeToCache = false @@ -85,13 +83,15 @@ getPath = (path) -> parts = path.split '.' return path unless parts[parts.length - 1] is 'coffee' - tmpPath = "/tmp/atom-compiled-scripts" - cachePath = [tmpPath, $native.md5ForPath(path)].join("/") - if not __exists(cachePath) + cacheFilePath = getCacheFilePath(path) + unless __exists(cacheFilePath) {CoffeeScript} = require 'coffee-script' compiled = CoffeeScript.compile(__read(path), filename: path) - $native.write(cachePath, compiled) - cachePath + $native.write(cacheFilePath, compiled) + cacheFilePath + +getCacheFilePath = (path) -> + "/tmp/atom-compiled-scripts/#{$native.md5ForPath(path)}" resolve = (name, {verifyExistence}={}) -> verifyExistence ?= true