Skip to content

Commit 6b00c65

Browse files
refactor: code (webpack-contrib#22)
1 parent 7bf20dc commit 6b00c65

File tree

5 files changed

+171
-162
lines changed

5 files changed

+171
-162
lines changed

src/Webpack4Cache.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,23 @@ export default class Webpack4Cache {
2626
// eslint-disable-next-line no-param-reassign
2727
task.cacheIdent = task.cacheIdent || serialize(task.cacheKeys);
2828

29-
const { data } = await cacache.get(this.cacheDir, task.cacheIdent);
29+
let cachedResult;
3030

31-
return JSON.parse(data);
31+
try {
32+
cachedResult = await cacache.get(this.cacheDir, task.cacheIdent);
33+
} catch (ignoreError) {
34+
// eslint-disable-next-line no-undefined
35+
return undefined;
36+
}
37+
38+
return JSON.parse(cachedResult.data);
3239
}
3340

34-
async store(task, data) {
35-
return cacache.put(this.cacheDir, task.cacheIdent, JSON.stringify(data));
41+
async store(task) {
42+
return cacache.put(
43+
this.cacheDir,
44+
task.cacheIdent,
45+
JSON.stringify(task.output)
46+
);
3647
}
3748
}

src/Webpack5Cache.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@ export default class Cache {
1111

1212
async get(task) {
1313
// eslint-disable-next-line no-param-reassign
14-
task.cacheIdent = task.cacheIdent || `${task.name}`;
14+
task.eTag = task.eTag || this.cache.getLazyHashedEtag(task.assetSource);
1515

16-
// eslint-disable-next-line no-param-reassign
17-
task.cacheETag =
18-
task.cacheETag || this.cache.getLazyHashedEtag(task.assetSource);
19-
20-
return this.cache.getPromise(task.cacheIdent, task.cacheETag);
16+
return this.cache.getPromise(task.assetName, task.eTag);
2117
}
2218

23-
async store(task, data) {
24-
return this.cache.storePromise(task.cacheIdent, task.cacheETag, data);
19+
async store(task) {
20+
return this.cache.storePromise(task.assetName, task.eTag, task.output);
2521
}
2622
}

0 commit comments

Comments
 (0)