Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/rstack/src/fmt/cacheStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ const createEmptyCache = (namespace: string): ParsedFmtCacheFile => ({
optionsUseCounts: [],
});

const parseCacheFile = (content: string): ParsedFmtCacheFile | undefined => {
const parseCacheFile = (
content: string,
expectedNamespace: string,
): ParsedFmtCacheFile | undefined => {
let value: unknown;
try {
value = JSON.parse(content);
Expand All @@ -73,7 +76,7 @@ const parseCacheFile = (content: string): ParsedFmtCacheFile | undefined => {
const { version, namespace, options, files } = cache;
if (
version !== fmtCacheVersion ||
typeof namespace !== 'string' ||
namespace !== expectedNamespace ||
!Array.isArray(options) ||
!Array.isArray(files) ||
files.length % fileEntryWidth !== 0
Expand Down Expand Up @@ -262,14 +265,12 @@ const loadFmtCacheStore = async (filePath: string, namespace: string): Promise<F

try {
const content = await readFile(filePath, 'utf8');
const parsed = parseCacheFile(content);
const parsed = parseCacheFile(content, namespace);
if (!parsed) {
return new FmtCacheStoreImpl(filePath, emptyCache, undefined, true);
}

return parsed.cache.namespace === namespace
? new FmtCacheStoreImpl(filePath, parsed, content, false)
: new FmtCacheStoreImpl(filePath, emptyCache, undefined, true);
return new FmtCacheStoreImpl(filePath, parsed, content, false);
} catch (error) {
const missing = isFileNotFoundError(error);
return new FmtCacheStoreImpl(filePath, emptyCache, undefined, !missing);
Expand Down