Skip to content

Commit

Permalink
fix: cache invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Sep 19, 2020
1 parent e5036ca commit 2284b0c
Show file tree
Hide file tree
Showing 27 changed files with 818 additions and 391 deletions.
114 changes: 57 additions & 57 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@
"file-loader": "^6.1.0",
"husky": "^4.3.0",
"jest": "^26.4.2",
"lint-staged": "^10.3.0",
"lint-staged": "^10.4.0",
"memfs": "^3.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.2",
"standard-version": "^9.0.0",
"webpack": "^4.44.1"
"webpack": "^4.44.2"
},
"keywords": [
"webpack"
Expand Down
40 changes: 23 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import webpack, {
version as webpackVersion,
} from 'webpack';
import validateOptions from 'schema-utils';
import serialize from 'serialize-javascript';

import schema from './options.json';

Expand Down Expand Up @@ -52,7 +53,6 @@ class CompressionPlugin {
};

this.algorithm = this.options.algorithm;
this.compressionOptions = this.options.compressionOptions;

if (typeof this.algorithm === 'string') {
// eslint-disable-next-line global-require
Expand All @@ -66,9 +66,9 @@ class CompressionPlugin {
);
}

this.compressionOptions = {
this.options.compressionOptions = {
...{ level: 9 },
...this.compressionOptions,
...this.options.compressionOptions,
};
}
}
Expand Down Expand Up @@ -117,20 +117,22 @@ class CompressionPlugin {

runCompressionAlgorithm(input) {
return new Promise((resolve, reject) => {
const { algorithm, compressionOptions } = this;
this.algorithm(
input,
this.options.compressionOptions,
(error, result) => {
if (error) {
return reject(error);
}

algorithm(input, compressionOptions, (error, result) => {
if (error) {
return reject(error);
}
if (!Buffer.isBuffer(result)) {
// eslint-disable-next-line no-param-reassign
result = Buffer.from(result);
}

if (!Buffer.isBuffer(result)) {
// eslint-disable-next-line no-param-reassign
result = Buffer.from(result);
return resolve(result);
}

return resolve(result);
});
);
});
}

Expand Down Expand Up @@ -204,12 +206,16 @@ class CompressionPlugin {
'compression-webpack-plugin': require('../package.json').version,
algorithm: this.algorithm,
originalAlgorithm: this.options.algorithm,
compressionOptions: this.compressionOptions,
compressionOptions: this.options.compressionOptions,
name,
contentHash: crypto.createHash('md4').update(input).digest('hex'),
};
} else {
cacheData.name = name;
cacheData.name = serialize({
name,
algorithm: this.options.algorithm,
compressionOptions: this.options.compressionOptions,
});
}

let output = await cache.get(cacheData, { RawSource });
Expand Down Expand Up @@ -282,7 +288,7 @@ class CompressionPlugin {
// TODO `...` required only for webpack@4
const newOriginalInfo = {
...info,
related: { [relatedName]: newName },
related: { [relatedName]: newName, ...info.related },
};

CompressionPlugin.updateAsset(
Expand Down
Loading

0 comments on commit 2284b0c

Please sign in to comment.