Skip to content

Commit 500d191

Browse files
authored
style: use prettier defaults (#109)
1 parent be8c305 commit 500d191

35 files changed

+689
-690
lines changed

.eslintrc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
root: true,
3-
extends: ['@webpack-contrib/eslint-config-webpack', 'prettier'],
3+
extends: ["@webpack-contrib/eslint-config-webpack", "prettier"],
44
rules: {
5-
'import/no-namespace': 'off',
5+
"import/no-namespace": "off",
66
},
77
};

.github/workflows/nodejs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
uses: actions/setup-node@v2
3434
with:
3535
node-version: ${{ matrix.node-version }}
36-
cache: 'npm'
36+
cache: "npm"
3737

3838
- name: Use latest NPM
3939
run: sudo npm i -g npm
@@ -72,7 +72,7 @@ jobs:
7272
uses: actions/setup-node@v2
7373
with:
7474
node-version: ${{ matrix.node-version }}
75-
cache: 'npm'
75+
cache: "npm"
7676

7777
- name: Use latest NPM on ubuntu/macos
7878
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'

.prettierrc.js

-1
This file was deleted.

README.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ Then add the plugin to your `webpack` configuration. For example:
3131
**webpack.config.js**
3232

3333
```js
34-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
35-
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
34+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
35+
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
3636

3737
module.exports = {
3838
module: {
3939
rules: [
4040
{
4141
test: /.s?css$/,
42-
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
42+
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
4343
},
4444
],
4545
},
@@ -229,7 +229,7 @@ module.exports = {
229229
minimizerOptions: {
230230
level: {
231231
1: {
232-
roundingPrecision: 'all=3,px=5',
232+
roundingPrecision: "all=3,px=5",
233233
},
234234
},
235235
},
@@ -293,7 +293,7 @@ module.exports = {
293293
new CssMinimizerPlugin({
294294
minimizerOptions: {
295295
preset: [
296-
'default',
296+
"default",
297297
{
298298
discardComments: { removeAll: true },
299299
},
@@ -319,7 +319,7 @@ module.exports = {
319319
minimizer: [
320320
new CssMinimizerPlugin({
321321
minimizerOptions: {
322-
preset: require.resolve('cssnano-preset-simple'),
322+
preset: require.resolve("cssnano-preset-simple"),
323323
},
324324
}),
325325
],
@@ -338,7 +338,7 @@ The `parser`,` stringifier` and `syntax` can be either a function or a string in
338338
> ⚠️ **If a function is passed, the `parallel` option must be disabled.**.
339339
340340
```js
341-
import sugarss from 'sugarss';
341+
import sugarss from "sugarss";
342342

343343
module.exports = {
344344
optimization: {
@@ -365,7 +365,7 @@ module.exports = {
365365
new CssMinimizerPlugin({
366366
minimizerOptions: {
367367
processorOptions: {
368-
parser: 'sugarss',
368+
parser: "sugarss",
369369
},
370370
},
371371
}),
@@ -420,18 +420,18 @@ module.exports = {
420420
Don't forget to enable `sourceMap` options for all loaders.
421421

422422
```js
423-
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
423+
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
424424

425425
module.exports = {
426-
devtool: 'source-map',
426+
devtool: "source-map",
427427
module: {
428428
loaders: [
429429
{
430430
test: /.s?css$/,
431431
use: [
432432
MiniCssExtractPlugin.loader,
433-
{ loader: 'css-loader', options: { sourceMap: true } },
434-
{ loader: 'sass-loader', options: { sourceMap: true } },
433+
{ loader: "css-loader", options: { sourceMap: true } },
434+
{ loader: "sass-loader", options: { sourceMap: true } },
435435
],
436436
},
437437
],
@@ -453,7 +453,7 @@ module.exports = {
453453
new CssMinimizerPlugin({
454454
minimizerOptions: {
455455
preset: [
456-
'default',
456+
"default",
457457
{
458458
discardComments: { removeAll: true },
459459
},
@@ -476,14 +476,14 @@ It is possible to use another minify function.
476476

477477
```js
478478
module.exports = {
479-
devtool: 'source-map',
479+
devtool: "source-map",
480480
optimization: {
481481
minimize: true,
482482
minimizer: [
483483
new CssMinimizerPlugin({
484484
minify: async (data, inputMap) => {
485-
const csso = require('csso');
486-
const sourcemap = require('source-map');
485+
const csso = require("csso");
486+
const sourcemap = require("source-map");
487487

488488
const [[filename, input]] = Object.entries(data);
489489
const minifiedCss = csso.minify(input, {
@@ -515,7 +515,7 @@ module.exports = {
515515

516516
```js
517517
module.exports = {
518-
devtool: 'source-map',
518+
devtool: "source-map",
519519
optimization: {
520520
minimize: true,
521521
minimizer: [
@@ -535,7 +535,7 @@ module.exports = {
535535

536536
```js
537537
module.exports = {
538-
devtool: 'source-map',
538+
devtool: "source-map",
539539
optimization: {
540540
minimize: true,
541541
minimizer: [

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: '12.13.0',
13+
node: "12.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
};

jest.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
testEnvironment: 'node',
3-
setupFilesAfterEnv: ['<rootDir>/setupTest.js'],
2+
testEnvironment: "node",
3+
setupFilesAfterEnv: ["<rootDir>/setupTest.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': ['eslint --fix', 'prettier --write'],
3-
'*.{json,md,yml,css,ts}': ['prettier --write'],
2+
"*.js": ["eslint --fix", "prettier --write"],
3+
"*.{json,md,yml,css,ts}": ["prettier --write"],
44
};

src/cjs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const plugin = require('./index');
1+
const plugin = require("./index");
22

33
module.exports = plugin.default;

src/index.js

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import * as os from 'os';
1+
import * as os from "os";
22

3-
import { SourceMapConsumer } from 'source-map';
4-
import { validate } from 'schema-utils';
5-
import serialize from 'serialize-javascript';
6-
import pLimit from 'p-limit';
7-
import { Worker } from 'jest-worker';
3+
import { SourceMapConsumer } from "source-map";
4+
import { validate } from "schema-utils";
5+
import serialize from "serialize-javascript";
6+
import pLimit from "p-limit";
7+
import { Worker } from "jest-worker";
88

9-
import { cssnanoMinify, cssoMinify, cleanCssMinify } from './utils';
9+
import { cssnanoMinify, cssoMinify, cleanCssMinify } from "./utils";
1010

11-
import * as schema from './options.json';
12-
import { minify as minifyFn } from './minify';
11+
import * as schema from "./options.json";
12+
import { minify as minifyFn } from "./minify";
1313

1414
const warningRegex = /\s.+:+([0-9]+):+([0-9]+)/;
1515

1616
class CssMinimizerPlugin {
1717
constructor(options = {}) {
1818
validate(schema, options, {
19-
name: 'Css Minimizer Plugin',
20-
baseDataPath: 'options',
19+
name: "Css Minimizer Plugin",
20+
baseDataPath: "options",
2121
});
2222

2323
const {
@@ -49,7 +49,7 @@ class CssMinimizerPlugin {
4949
input.version &&
5050
input.sources &&
5151
Array.isArray(input.sources) &&
52-
typeof input.mappings === 'string'
52+
typeof input.mappings === "string"
5353
);
5454
}
5555

@@ -72,8 +72,8 @@ class CssMinimizerPlugin {
7272
original.column
7373
}][${name}:${error.line},${error.column}]${
7474
error.stack
75-
? `\n${error.stack.split('\n').slice(1).join('\n')}`
76-
: ''
75+
? `\n${error.stack.split("\n").slice(1).join("\n")}`
76+
: ""
7777
}`
7878
);
7979
builtError.file = name;
@@ -85,7 +85,7 @@ class CssMinimizerPlugin {
8585
`${name} from Css Minimizer \n${error.message} [${name}:${error.line},${
8686
error.column
8787
}]${
88-
error.stack ? `\n${error.stack.split('\n').slice(1).join('\n')}` : ''
88+
error.stack ? `\n${error.stack.split("\n").slice(1).join("\n")}` : ""
8989
}`
9090
);
9191
builtError.file = name;
@@ -114,7 +114,7 @@ class CssMinimizerPlugin {
114114
warningsFilter
115115
) {
116116
let warningMessage = warning;
117-
let locationMessage = '';
117+
let locationMessage = "";
118118
let source;
119119

120120
if (sourceMap) {
@@ -136,7 +136,7 @@ class CssMinimizerPlugin {
136136
) {
137137
({ source } = original);
138138

139-
warningMessage = `${warningMessage.replace(warningRegex, '')}`;
139+
warningMessage = `${warningMessage.replace(warningRegex, "")}`;
140140
locationMessage = `${requestShortener.shorten(original.source)}:${
141141
original.line
142142
}:${original.column}`;
@@ -162,10 +162,10 @@ class CssMinimizerPlugin {
162162
}
163163

164164
async optimize(compiler, compilation, assets, optimizeOptions) {
165-
const cache = compilation.getCache('CssMinimizerWebpackPlugin');
165+
const cache = compilation.getCache("CssMinimizerWebpackPlugin");
166166
let numberOfAssetsForMinify = 0;
167167
const assetsForMinify = await Promise.all(
168-
Object.keys(typeof assets === 'undefined' ? compilation.assets : assets)
168+
Object.keys(typeof assets === "undefined" ? compilation.assets : assets)
169169
.filter((name) => {
170170
const { info } = compilation.getAsset(name);
171171

@@ -219,7 +219,7 @@ class CssMinimizerPlugin {
219219
return initializedWorker;
220220
}
221221

222-
initializedWorker = new Worker(require.resolve('./minify'), {
222+
initializedWorker = new Worker(require.resolve("./minify"), {
223223
numWorkers: numberOfWorkers,
224224
enableWorkerThreads: true,
225225
});
@@ -228,13 +228,13 @@ class CssMinimizerPlugin {
228228
const workerStdout = initializedWorker.getStdout();
229229

230230
if (workerStdout) {
231-
workerStdout.on('data', (chunk) => process.stdout.write(chunk));
231+
workerStdout.on("data", (chunk) => process.stdout.write(chunk));
232232
}
233233

234234
const workerStderr = initializedWorker.getStderr();
235235

236236
if (workerStderr) {
237-
workerStderr.on('data', (chunk) => process.stderr.write(chunk));
237+
workerStderr.on("data", (chunk) => process.stderr.write(chunk));
238238
}
239239

240240
return initializedWorker;
@@ -348,7 +348,7 @@ class CssMinimizerPlugin {
348348
constructor(message) {
349349
super(message);
350350

351-
this.name = 'Warning';
351+
this.name = "Warning";
352352
this.hideStack = true;
353353
this.file = name;
354354
}
@@ -397,12 +397,12 @@ class CssMinimizerPlugin {
397397

398398
compilation.hooks.statsPrinter.tap(pluginName, (stats) => {
399399
stats.hooks.print
400-
.for('asset.info.minimized')
400+
.for("asset.info.minimized")
401401
.tap(
402-
'css-minimizer-webpack-plugin',
402+
"css-minimizer-webpack-plugin",
403403
(minimized, { green, formatFlag }) =>
404404
// eslint-disable-next-line no-undefined
405-
minimized ? green(formatFlag('minimized')) : ''
405+
minimized ? green(formatFlag("minimized")) : ""
406406
);
407407
});
408408
});

src/minify.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const minify = async (options) => {
22
const minifyFns =
3-
typeof options.minify === 'function' ? [options.minify] : options.minify;
3+
typeof options.minify === "function" ? [options.minify] : options.minify;
44

55
const result = {
66
code: options.input,
@@ -37,11 +37,11 @@ async function transform(options) {
3737
// Safer for possible security issues, albeit not critical at all here
3838
// eslint-disable-next-line no-new-func, no-param-reassign
3939
const evaluatedOptions = new Function(
40-
'exports',
41-
'require',
42-
'module',
43-
'__filename',
44-
'__dirname',
40+
"exports",
41+
"require",
42+
"module",
43+
"__filename",
44+
"__dirname",
4545
`'use strict'\nreturn ${options}`
4646
)(exports, require, module, __filename, __dirname);
4747

0 commit comments

Comments
 (0)