Skip to content

Commit

Permalink
refactor: code
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito authored Sep 2, 2020
1 parent 8d60fc9 commit 9c9be36
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 149 deletions.
24 changes: 16 additions & 8 deletions src/Webpack4Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default class Webpack4Cache {
);
}

async get(task, sources) {
const weakOutput = this.weakCache.get(task.assetSource);
async get(cacheData, sources) {
const weakOutput = this.weakCache.get(cacheData.assetSource);

if (weakOutput) {
return weakOutput;
Expand All @@ -32,12 +32,13 @@ export default class Webpack4Cache {
}

// eslint-disable-next-line no-param-reassign
task.cacheIdent = task.cacheIdent || serialize(task.cacheKeys);
cacheData.cacheIdent =
cacheData.cacheIdent || serialize(cacheData.cacheKeys);

let cachedResult;

try {
cachedResult = await cacache.get(this.cache, task.cacheIdent);
cachedResult = await cacache.get(this.cache, cacheData.cacheIdent);
} catch (ignoreError) {
// eslint-disable-next-line no-undefined
return undefined;
Expand All @@ -63,17 +64,24 @@ export default class Webpack4Cache {
return cachedResult;
}

async store(task) {
if (!this.weakCache.has(task.assetSource)) {
this.weakCache.set(task.assetSource, task);
async store(cacheData) {
if (!this.weakCache.has(cacheData.assetSource)) {
this.weakCache.set(cacheData.assetSource, cacheData);
}

if (!this.cache) {
// eslint-disable-next-line no-undefined
return undefined;
}

const { cacheIdent, css, assetName, map, input, inputSourceMap } = task;
const {
cacheIdent,
css,
assetName,
map,
input,
inputSourceMap,
} = cacheData;

return cacache.put(
this.cache,
Expand Down
13 changes: 7 additions & 6 deletions src/Webpack5Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ export default class Cache {
this.cache = compilation.getCache('CssMinimizerWebpackPlugin');
}

async get(task) {
async get(cacheData) {
// eslint-disable-next-line no-param-reassign
task.eTag = task.eTag || this.cache.getLazyHashedEtag(task.assetSource);
cacheData.eTag =
cacheData.eTag || this.cache.getLazyHashedEtag(cacheData.assetSource);

return this.cache.getPromise(task.assetName, task.eTag);
return this.cache.getPromise(cacheData.assetName, cacheData.eTag);
}

async store(task) {
const { source, warnings } = task;
async store(cacheData) {
const { source, warnings } = cacheData;

return this.cache.storePromise(task.assetName, task.eTag, {
return this.cache.storePromise(cacheData.assetName, cacheData.eTag, {
source,
warnings,
});
Expand Down
Loading

0 comments on commit 9c9be36

Please sign in to comment.