-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e15620
commit 62de5c8
Showing
6 changed files
with
309 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import core = require('@tsslint/core'); | ||
import path = require('path'); | ||
import fs = require('fs'); | ||
|
||
export type CacheData = Record<string /* fileName */, core.FileLintCache>; | ||
|
||
export function loadCache( | ||
configFilePath: string, | ||
createHash: (path: string) => string = btoa | ||
): CacheData { | ||
const outDir = core.getDotTsslintPath(configFilePath); | ||
const cacheFileName = createHash(path.relative(outDir, configFilePath)) + '.cache.json'; | ||
const cacheFilePath = path.join(outDir, cacheFileName); | ||
const cacheFileStat = fs.statSync(cacheFilePath, { throwIfNoEntry: false }); | ||
const configFileStat = fs.statSync(configFilePath, { throwIfNoEntry: false }); | ||
if (cacheFileStat?.isFile() && cacheFileStat.mtimeMs > (configFileStat?.mtimeMs ?? 0)) { | ||
try { | ||
return require(cacheFilePath); | ||
} catch { | ||
return {}; | ||
} | ||
} | ||
return {}; | ||
} | ||
|
||
export function saveCache( | ||
configFilePath: string, | ||
cache: CacheData, | ||
createHash: (path: string) => string = btoa | ||
): void { | ||
const outDir = core.getDotTsslintPath(configFilePath); | ||
const cacheFileName = createHash(path.relative(outDir, configFilePath)) + '.cache.json'; | ||
const cacheFilePath = path.join(outDir, cacheFileName); | ||
fs.writeFileSync(cacheFilePath, JSON.stringify(cache)); | ||
} |
Oops, something went wrong.