@@ -6,11 +6,12 @@ var fs = require("fs")
6
6
var findCacheDir = require ( "find-cache-dir" )
7
7
var objectHash = require ( "object-hash" )
8
8
var os = require ( "os" )
9
+ var path = require ( "path" )
10
+ var mkdirp = require ( "mkdirp" )
9
11
10
12
var engines = { }
11
13
var rules = { }
12
14
var cache = null
13
- var cachePath = null
14
15
15
16
/**
16
17
* linter
@@ -65,7 +66,9 @@ function lint(input, config, webpack) {
65
66
rules : rulesHash ,
66
67
res : res ,
67
68
}
68
- fs . writeFileSync ( cachePath , JSON . stringify ( cache ) )
69
+ var cacheJson = JSON . stringify ( cache )
70
+ var cachePath = getCachePath ( )
71
+ writeCache ( cachePath , cacheJson )
69
72
}
70
73
}
71
74
@@ -176,18 +179,7 @@ module.exports = function(input, map) {
176
179
// Read the cached information only once and if enable
177
180
if ( cache === null ) {
178
181
if ( config . cache ) {
179
- var thunk = findCacheDir ( {
180
- name : "eslint-loader" ,
181
- thunk : true ,
182
- create : true ,
183
- } )
184
- cachePath = thunk ( "data.json" ) || os . tmpdir ( ) + "/data.json"
185
- try {
186
- cache = require ( cachePath )
187
- }
188
- catch ( e ) {
189
- cache = { }
190
- }
182
+ cache = readCache ( getCachePath ( ) )
191
183
}
192
184
else {
193
185
cache = false
@@ -197,3 +189,33 @@ module.exports = function(input, map) {
197
189
lint ( input , config , this )
198
190
this . callback ( null , input , map )
199
191
}
192
+
193
+ function writeCache ( cachePath , cacheJson ) {
194
+ mkdirp . sync ( path . dirname ( cachePath ) )
195
+ fs . writeFileSync ( cachePath , cacheJson )
196
+ }
197
+
198
+ function readCache ( cachePath ) {
199
+ try {
200
+ return require ( cachePath )
201
+ }
202
+ catch ( e ) {
203
+ return { }
204
+ }
205
+ }
206
+
207
+ function getCachePath ( ) {
208
+ var cachePath
209
+ try {
210
+ var thunk = findCacheDir ( {
211
+ name : "eslint-loader" ,
212
+ thunk : true ,
213
+ create : true ,
214
+ } )
215
+ cachePath = thunk ( "data.json" )
216
+ }
217
+ catch ( e ) {
218
+ cachePath = path . join ( os . tmpdir ( ) , "eslint-loader" , "cache.json" )
219
+ }
220
+ return cachePath
221
+ }
0 commit comments