Skip to content

Commit 2284b0c

Browse files
fix: cache invalidation
1 parent e5036ca commit 2284b0c

27 files changed

+818
-391
lines changed

package-lock.json

+57-57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@
6666
"file-loader": "^6.1.0",
6767
"husky": "^4.3.0",
6868
"jest": "^26.4.2",
69-
"lint-staged": "^10.3.0",
69+
"lint-staged": "^10.4.0",
7070
"memfs": "^3.2.0",
7171
"npm-run-all": "^4.1.5",
7272
"prettier": "^2.1.2",
7373
"standard-version": "^9.0.0",
74-
"webpack": "^4.44.1"
74+
"webpack": "^4.44.2"
7575
},
7676
"keywords": [
7777
"webpack"

src/index.js

+23-17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import webpack, {
1111
version as webpackVersion,
1212
} from 'webpack';
1313
import validateOptions from 'schema-utils';
14+
import serialize from 'serialize-javascript';
1415

1516
import schema from './options.json';
1617

@@ -52,7 +53,6 @@ class CompressionPlugin {
5253
};
5354

5455
this.algorithm = this.options.algorithm;
55-
this.compressionOptions = this.options.compressionOptions;
5656

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

69-
this.compressionOptions = {
69+
this.options.compressionOptions = {
7070
...{ level: 9 },
71-
...this.compressionOptions,
71+
...this.options.compressionOptions,
7272
};
7373
}
7474
}
@@ -117,20 +117,22 @@ class CompressionPlugin {
117117

118118
runCompressionAlgorithm(input) {
119119
return new Promise((resolve, reject) => {
120-
const { algorithm, compressionOptions } = this;
120+
this.algorithm(
121+
input,
122+
this.options.compressionOptions,
123+
(error, result) => {
124+
if (error) {
125+
return reject(error);
126+
}
121127

122-
algorithm(input, compressionOptions, (error, result) => {
123-
if (error) {
124-
return reject(error);
125-
}
128+
if (!Buffer.isBuffer(result)) {
129+
// eslint-disable-next-line no-param-reassign
130+
result = Buffer.from(result);
131+
}
126132

127-
if (!Buffer.isBuffer(result)) {
128-
// eslint-disable-next-line no-param-reassign
129-
result = Buffer.from(result);
133+
return resolve(result);
130134
}
131-
132-
return resolve(result);
133-
});
135+
);
134136
});
135137
}
136138

@@ -204,12 +206,16 @@ class CompressionPlugin {
204206
'compression-webpack-plugin': require('../package.json').version,
205207
algorithm: this.algorithm,
206208
originalAlgorithm: this.options.algorithm,
207-
compressionOptions: this.compressionOptions,
209+
compressionOptions: this.options.compressionOptions,
208210
name,
209211
contentHash: crypto.createHash('md4').update(input).digest('hex'),
210212
};
211213
} else {
212-
cacheData.name = name;
214+
cacheData.name = serialize({
215+
name,
216+
algorithm: this.options.algorithm,
217+
compressionOptions: this.options.compressionOptions,
218+
});
213219
}
214220

215221
let output = await cache.get(cacheData, { RawSource });
@@ -282,7 +288,7 @@ class CompressionPlugin {
282288
// TODO `...` required only for webpack@4
283289
const newOriginalInfo = {
284290
...info,
285-
related: { [relatedName]: newName },
291+
related: { [relatedName]: newName, ...info.related },
286292
};
287293

288294
CompressionPlugin.updateAsset(

0 commit comments

Comments
 (0)