Skip to content

Commit fbb57b1

Browse files
style: prettier default (#220)
1 parent 5e3bb95 commit fbb57b1

40 files changed

+604
-605
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
root: true,
3-
extends: ['@webpack-contrib/eslint-config-webpack', 'prettier'],
3+
extends: ["@webpack-contrib/eslint-config-webpack", "prettier"],
44
};

.prettierrc.js

-1
This file was deleted.

README.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Then add the plugin to your `webpack` config. For example:
2929
**webpack.config.js**
3030

3131
```js
32-
const CompressionPlugin = require('compression-webpack-plugin');
32+
const CompressionPlugin = require("compression-webpack-plugin");
3333

3434
module.exports = {
3535
plugins: [new CompressionPlugin()],
@@ -129,7 +129,7 @@ The algorithm is taken from [zlib](https://nodejs.org/api/zlib.html).
129129
module.exports = {
130130
plugins: [
131131
new CompressionPlugin({
132-
algorithm: 'gzip',
132+
algorithm: "gzip",
133133
}),
134134
],
135135
};
@@ -259,7 +259,7 @@ For example we have `assets/images/image.png?foo=bar#hash`:
259259
module.exports = {
260260
plugins: [
261261
new CompressionPlugin({
262-
filename: '[path][base].gz',
262+
filename: "[path][base].gz",
263263
}),
264264
],
265265
};
@@ -277,10 +277,10 @@ module.exports = {
277277
// The `pathData` argument contains all placeholders - `path`/`name`/`ext`/etc
278278
// Available properties described above, for the `String` notation
279279
if (/\.svg$/.test(pathData.file)) {
280-
return 'assets/svg/[path][base].gz';
280+
return "assets/svg/[path][base].gz";
281281
}
282282

283-
return 'assets/js/[path][base].gz';
283+
return "assets/js/[path][base].gz";
284284
},
285285
}),
286286
],
@@ -355,7 +355,7 @@ Enable file caching and set path to cache directory.
355355
module.exports = {
356356
plugins: [
357357
new CompressionPlugin({
358-
cache: 'path/to/cache',
358+
cache: "path/to/cache",
359359
}),
360360
],
361361
};
@@ -378,7 +378,7 @@ $ npm install @gfx/zopfli --save-dev
378378
**webpack.config.js**
379379

380380
```js
381-
const zopfli = require('@gfx/zopfli');
381+
const zopfli = require("@gfx/zopfli");
382382

383383
module.exports = {
384384
plugins: [
@@ -405,13 +405,13 @@ We can take advantage of this built-in support for Brotli in Node 10.16.0 and la
405405
**webpack.config.js**
406406

407407
```js
408-
const zlib = require('zlib');
408+
const zlib = require("zlib");
409409

410410
module.exports = {
411411
plugins: [
412412
new CompressionPlugin({
413-
filename: '[path][base].br',
414-
algorithm: 'brotliCompress',
413+
filename: "[path][base].br",
414+
algorithm: "brotliCompress",
415415
test: /\.(js|css|html|svg)$/,
416416
compressionOptions: {
417417
params: {
@@ -434,20 +434,20 @@ You can find all Brotli’s options in [the relevant part of the zlib module doc
434434
**webpack.config.js**
435435

436436
```js
437-
const zlib = require('zlib');
437+
const zlib = require("zlib");
438438

439439
module.exports = {
440440
plugins: [
441441
new CompressionPlugin({
442-
filename: '[path][base].gz',
443-
algorithm: 'gzip',
442+
filename: "[path][base].gz",
443+
algorithm: "gzip",
444444
test: /\.js$|\.css$|\.html$/,
445445
threshold: 10240,
446446
minRatio: 0.8,
447447
}),
448448
new CompressionPlugin({
449-
filename: '[path][base].br',
450-
algorithm: 'brotliCompress',
449+
filename: "[path][base].br",
450+
algorithm: "brotliCompress",
451451
test: /\.(js|css|html|svg)$/,
452452
compressionOptions: {
453453
params: {

babel.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ module.exports = (api) => {
77
return {
88
presets: [
99
[
10-
'@babel/preset-env',
10+
"@babel/preset-env",
1111
{
1212
targets: {
13-
node: '10.13.0',
13+
node: "10.13.0",
1414
},
1515
},
1616
],

commitlint.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
extends: ['@commitlint/config-conventional'],
2+
extends: ["@commitlint/config-conventional"],
33
};

husky.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
hooks: {
3-
'pre-commit': 'lint-staged',
4-
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
3+
"pre-commit": "lint-staged",
4+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
55
},
66
};

jest.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
testEnvironment: 'node',
3-
snapshotResolver: './test/helpers/snapshotResolver.js',
2+
testEnvironment: "node",
3+
snapshotResolver: "./test/helpers/snapshotResolver.js",
44
};

lint-staged.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
'*.js': ['prettier --write', 'eslint --fix'],
3-
'*.{json,md,yml,css,ts}': ['prettier --write'],
2+
"*.js": ["eslint --fix", "prettier --write"],
3+
"*.{json,md,yml,css,ts}": ["prettier --write"],
44
};

src/Webpack4Cache.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import os from 'os';
1+
import os from "os";
22

3-
import cacache from 'cacache';
4-
import findCacheDir from 'find-cache-dir';
5-
import serialize from 'serialize-javascript';
3+
import cacache from "cacache";
4+
import findCacheDir from "find-cache-dir";
5+
import serialize from "serialize-javascript";
66

77
export default class Webpack4Cache {
88
constructor(compilation, options, weakCache) {
@@ -14,7 +14,7 @@ export default class Webpack4Cache {
1414
}
1515

1616
static getCacheDirectory() {
17-
return findCacheDir({ name: 'compression-webpack-plugin' }) || os.tmpdir();
17+
return findCacheDir({ name: "compression-webpack-plugin" }) || os.tmpdir();
1818
}
1919

2020
async get(cacheData, { RawSource }) {

src/Webpack5Cache.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default class Cache {
22
constructor(compilation) {
3-
this.cache = compilation.getCache('CompressionWebpackPlugin');
3+
this.cache = compilation.getCache("CompressionWebpackPlugin");
44
}
55

66
async get(cacheData) {

src/cjs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./index').default;
1+
module.exports = require("./index").default;

src/index.js

+32-32
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,37 @@
33
Author Tobias Koppers @sokra
44
*/
55

6-
import crypto from 'crypto';
7-
import path from 'path';
6+
import crypto from "crypto";
7+
import path from "path";
88

99
import webpack, {
1010
ModuleFilenameHelpers,
1111
version as webpackVersion,
12-
} from 'webpack';
13-
import { validate } from 'schema-utils';
14-
import serialize from 'serialize-javascript';
12+
} from "webpack";
13+
import { validate } from "schema-utils";
14+
import serialize from "serialize-javascript";
1515

16-
import schema from './options.json';
16+
import schema from "./options.json";
1717

1818
const { RawSource } =
1919
// eslint-disable-next-line global-require
20-
webpack.sources || require('webpack-sources');
20+
webpack.sources || require("webpack-sources");
2121

2222
class CompressionPlugin {
2323
constructor(options = {}) {
2424
validate(schema, options, {
25-
name: 'Compression Plugin',
26-
baseDataPath: 'options',
25+
name: "Compression Plugin",
26+
baseDataPath: "options",
2727
});
2828

2929
const {
3030
test,
3131
include,
3232
exclude,
3333
cache = true,
34-
algorithm = 'gzip',
34+
algorithm = "gzip",
3535
compressionOptions = {},
36-
filename = '[path][base].gz',
36+
filename = "[path][base].gz",
3737
threshold = 0,
3838
minRatio = 0.8,
3939
deleteOriginalAssets = false,
@@ -54,9 +54,9 @@ class CompressionPlugin {
5454

5555
this.algorithm = this.options.algorithm;
5656

57-
if (typeof this.algorithm === 'string') {
57+
if (typeof this.algorithm === "string") {
5858
// eslint-disable-next-line global-require
59-
const zlib = require('zlib');
59+
const zlib = require("zlib");
6060

6161
this.algorithm = zlib[this.algorithm];
6262

@@ -157,7 +157,7 @@ class CompressionPlugin {
157157

158158
async compress(compilation, assets, CacheEngine, weakCache) {
159159
const assetNames = Object.keys(
160-
typeof assets === 'undefined' ? compilation.assets : assets
160+
typeof assets === "undefined" ? compilation.assets : assets
161161
).filter((assetName) =>
162162
// eslint-disable-next-line no-undefined
163163
ModuleFilenameHelpers.matchObject.bind(undefined, this.options)(assetName)
@@ -188,18 +188,18 @@ class CompressionPlugin {
188188

189189
let relatedName;
190190

191-
if (typeof this.options.algorithm === 'function') {
191+
if (typeof this.options.algorithm === "function") {
192192
let filenameForRelatedName = this.options.filename;
193193

194-
const index = filenameForRelatedName.lastIndexOf('?');
194+
const index = filenameForRelatedName.lastIndexOf("?");
195195

196196
if (index >= 0) {
197197
filenameForRelatedName = filenameForRelatedName.substr(0, index);
198198
}
199199

200200
relatedName = `${path.extname(filenameForRelatedName).slice(1)}ed`;
201-
} else if (this.options.algorithm === 'gzip') {
202-
relatedName = 'gzipped';
201+
} else if (this.options.algorithm === "gzip") {
202+
relatedName = "gzipped";
203203
} else {
204204
relatedName = `${this.options.algorithm}ed`;
205205
}
@@ -224,12 +224,12 @@ class CompressionPlugin {
224224
cacheData.cacheKeys = {
225225
nodeVersion: process.version,
226226
// eslint-disable-next-line global-require
227-
'compression-webpack-plugin': require('../package.json').version,
227+
"compression-webpack-plugin": require("../package.json").version,
228228
algorithm: this.algorithm,
229229
originalAlgorithm: this.options.algorithm,
230230
compressionOptions: this.options.compressionOptions,
231231
name,
232-
contentHash: crypto.createHash('md4').update(input).digest('hex'),
232+
contentHash: crypto.createHash("md4").update(input).digest("hex"),
233233
};
234234
} else {
235235
cacheData.name = serialize({
@@ -261,8 +261,8 @@ class CompressionPlugin {
261261

262262
const match = /^([^?#]*)(\?[^#]*)?(#.*)?$/.exec(name);
263263
const [, replacerFile] = match;
264-
const replacerQuery = match[2] || '';
265-
const replacerFragment = match[3] || '';
264+
const replacerQuery = match[2] || "";
265+
const replacerFragment = match[3] || "";
266266
const replacerExt = path.extname(replacerFile);
267267
const replacerBase = path.basename(replacerFile);
268268
const replacerName = replacerBase.slice(
@@ -280,12 +280,12 @@ class CompressionPlugin {
280280
path: replacerPath,
281281
base: replacerBase,
282282
name: replacerName,
283-
ext: replacerExt || '',
283+
ext: replacerExt || "",
284284
};
285285

286286
let newFilename = this.options.filename;
287287

288-
if (typeof newFilename === 'function') {
288+
if (typeof newFilename === "function") {
289289
newFilename = newFilename(pathData);
290290
}
291291

@@ -301,7 +301,7 @@ class CompressionPlugin {
301301
}
302302

303303
if (this.options.deleteOriginalAssets) {
304-
if (this.options.deleteOriginalAssets === 'keep-source-map') {
304+
if (this.options.deleteOriginalAssets === "keep-source-map") {
305305
// TODO `...` required only for webpack@4
306306
const updatedAssetInfo = {
307307
...info,
@@ -341,15 +341,15 @@ class CompressionPlugin {
341341
}
342342

343343
static isWebpack4() {
344-
return webpackVersion[0] === '4';
344+
return webpackVersion[0] === "4";
345345
}
346346

347347
apply(compiler) {
348348
const pluginName = this.constructor.name;
349349

350350
if (CompressionPlugin.isWebpack4()) {
351351
// eslint-disable-next-line global-require
352-
const CacheEngine = require('./Webpack4Cache').default;
352+
const CacheEngine = require("./Webpack4Cache").default;
353353
const weakCache = new WeakMap();
354354

355355
compiler.hooks.emit.tapPromise({ name: pluginName }, (compilation) =>
@@ -358,11 +358,11 @@ class CompressionPlugin {
358358
);
359359
} else {
360360
// eslint-disable-next-line global-require
361-
const CacheEngine = require('./Webpack5Cache').default;
361+
const CacheEngine = require("./Webpack5Cache").default;
362362

363363
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
364364
// eslint-disable-next-line global-require
365-
const Compilation = require('webpack/lib/Compilation');
365+
const Compilation = require("webpack/lib/Compilation");
366366

367367
compilation.hooks.processAssets.tapPromise(
368368
{
@@ -374,12 +374,12 @@ class CompressionPlugin {
374374

375375
compilation.hooks.statsPrinter.tap(pluginName, (stats) => {
376376
stats.hooks.print
377-
.for('asset.info.compressed')
377+
.for("asset.info.compressed")
378378
.tap(
379-
'compression-webpack-plugin',
379+
"compression-webpack-plugin",
380380
(compressed, { green, formatFlag }) =>
381381
// eslint-disable-next-line no-undefined
382-
compressed ? green(formatFlag('compressed')) : undefined
382+
compressed ? green(formatFlag("compressed")) : undefined
383383
);
384384
});
385385
});

0 commit comments

Comments
 (0)