forked from nylas/nylas-mail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathless-compile-cache.es6
46 lines (40 loc) · 1.48 KB
/
less-compile-cache.es6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import _ from 'underscore';
import path from 'path';
import LessCache from 'less-cache';
// {LessCache} wrapper used by {ThemeManager} to read stylesheets.
export default class LessCompileCache {
constructor({configDirPath, resourcePath, importPaths}) {
this.lessSearchPaths = [
path.join(resourcePath, 'static', 'variables'),
path.join(resourcePath, 'static'),
];
let allImportPaths = importPaths;
if (allImportPaths != null) {
allImportPaths = importPaths.concat(this.lessSearchPaths);
} else {
allImportPaths = this.lessSearchPaths;
}
this.cache = new LessCache({
cacheDir: path.join(configDirPath, 'compile-cache', 'less'),
fallbackDir: path.join(resourcePath, 'less-compile-cache'),
importPaths: allImportPaths,
resourcePath: resourcePath,
});
}
// Setting the import paths is a VERY expensive operation (200ms +)
// because it walks the entire file tree and does a file state for each
// and every importPath. If we already have the imports, then load it
// from our backend FileListCache.
setImportPaths(importPaths = []) {
const fullImportPaths = importPaths.concat(this.lessSearchPaths);
if (!_.isEqual(fullImportPaths, this.cache.importPaths)) {
this.cache.setImportPaths(fullImportPaths);
}
}
read(stylesheetPath) {
return this.cache.readFileSync(stylesheetPath);
}
cssForFile(stylesheetPath, lessContent) {
return this.cache.cssForFile(stylesheetPath, lessContent);
}
}