Skip to content

Commit 7a8c05a

Browse files
committed
Don’t throw if the scss cache index can’t be read
1 parent 36ad00d commit 7a8c05a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/core/sass.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { dartCompile } from "./dart-sass.ts";
1717
import * as ld from "./lodash.ts";
1818
import { lines } from "./text.ts";
1919
import { md5Hash } from "./hash.ts";
20+
import { debug } from "../vendor/deno.land/[email protected]/log/mod.ts";
2021

2122
export interface SassVariable {
2223
name: string;
@@ -314,9 +315,13 @@ export async function compileWithCache(
314315
let cacheIndex: { [key: string]: { key: string; hash: string } } = {};
315316
let writeCache = true;
316317
if (existsSync(outputFilePath)) {
317-
cacheIndex = JSON.parse(Deno.readTextFileSync(cacheIdxPath));
318-
const existingEntry = cacheIndex[identifierHash];
319-
writeCache = !existingEntry || (existingEntry.hash !== inputHash);
318+
try {
319+
cacheIndex = JSON.parse(Deno.readTextFileSync(cacheIdxPath));
320+
const existingEntry = cacheIndex[identifierHash];
321+
writeCache = !existingEntry || (existingEntry.hash !== inputHash);
322+
} catch {
323+
debug(`The scss cache index file ${cacheIdxPath} can't be read.`);
324+
}
320325
}
321326

322327
// We need to refresh the cache

0 commit comments

Comments
 (0)