stylelint-webpack-plugin 3.0.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -26
- package/dist/StylelintError.js +1 -7
- package/dist/getStylelint.js +31 -24
- package/dist/index.js +48 -34
- package/dist/linter.js +32 -23
- package/dist/options.js +14 -16
- package/dist/utils.js +19 -19
- package/package.json +31 -31
- package/types/StylelintError.d.ts +8 -0
- package/types/getStylelint.d.ts +91 -0
- package/{declarations → types}/index.d.ts +13 -10
- package/types/linter.d.ts +109 -0
- package/{declarations → types}/options.d.ts +79 -24
- package/{declarations → types}/utils.d.ts +5 -0
- package/types/worker.d.ts +58 -0
- package/declarations/StylelintError.d.ts +0 -2
- package/declarations/cjs.d.ts +0 -3
- package/declarations/getStylelint.d.ts +0 -24
- package/declarations/linter.d.ts +0 -34
- package/declarations/worker.d.ts +0 -3
- package/dist/cjs.js +0 -5
package/README.md
CHANGED
|
@@ -13,22 +13,50 @@
|
|
|
13
13
|
|
|
14
14
|
# stylelint-webpack-plugin
|
|
15
15
|
|
|
16
|
+
> This is stylelint-webpack-plugin 3.0 which works only with webpack 5. For the webpack 4, see the [2.x branch](https://github.com/webpack-contrib/stylelint-webpack-plugin/tree/2.x).
|
|
17
|
+
|
|
16
18
|
This plugin uses [`stylelint`](https://stylelint.io/) that helps you avoid errors and enforce conventions in your styles.
|
|
17
19
|
|
|
18
20
|
## Getting Started
|
|
19
21
|
|
|
20
22
|
To begin, you'll need to install `stylelint-webpack-plugin`:
|
|
21
23
|
|
|
22
|
-
```
|
|
24
|
+
```console
|
|
23
25
|
npm install stylelint-webpack-plugin --save-dev
|
|
24
26
|
```
|
|
25
27
|
|
|
28
|
+
or
|
|
29
|
+
|
|
30
|
+
```console
|
|
31
|
+
yarn add -D install stylelint-webpack-plugin
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
or
|
|
35
|
+
|
|
36
|
+
```console
|
|
37
|
+
pnpm add -D stylelint-webpack-plugin
|
|
38
|
+
```
|
|
39
|
+
|
|
26
40
|
**Note**: You also need to install `stylelint >= 13` from npm, if you haven't already:
|
|
27
41
|
|
|
28
|
-
```
|
|
42
|
+
```console
|
|
29
43
|
npm install stylelint --save-dev
|
|
30
44
|
```
|
|
31
45
|
|
|
46
|
+
or
|
|
47
|
+
|
|
48
|
+
```console
|
|
49
|
+
yarn add -D stylelint
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
or
|
|
53
|
+
|
|
54
|
+
```console
|
|
55
|
+
pnpm add -D stylelint
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Note**: If you are using Stylelint 13 rather than 14+, you might also need to install `@types/stylelint` as a dev dependency if getting stylelint related type errors.
|
|
59
|
+
|
|
32
60
|
Then add the plugin to your webpack config. For example:
|
|
33
61
|
|
|
34
62
|
```js
|
|
@@ -43,76 +71,128 @@ module.exports = {
|
|
|
43
71
|
|
|
44
72
|
## Options
|
|
45
73
|
|
|
46
|
-
See [stylelint's options](
|
|
74
|
+
See [stylelint's options](https://stylelint.io/user-guide/usage/node-api#options) for the complete list of options available. These options are passed through to the `stylelint` directly.
|
|
47
75
|
|
|
48
76
|
### `configFile`
|
|
49
77
|
|
|
50
|
-
- Type:
|
|
78
|
+
- Type:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
type context = string;
|
|
82
|
+
```
|
|
83
|
+
|
|
51
84
|
- Default: `undefined`
|
|
52
85
|
|
|
53
86
|
Specify the config file location to be used by `stylelint`.
|
|
54
87
|
|
|
55
|
-
**Note:** By default this is [handled by `stylelint`](
|
|
88
|
+
**Note:** By default this is [handled by `stylelint`](https://stylelint.io/user-guide/configure).
|
|
56
89
|
|
|
57
90
|
### `context`
|
|
58
91
|
|
|
59
|
-
- Type:
|
|
92
|
+
- Type:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
type context = string;
|
|
96
|
+
```
|
|
97
|
+
|
|
60
98
|
- Default: `compiler.context`
|
|
61
99
|
|
|
62
100
|
A string indicating the root of your files.
|
|
63
101
|
|
|
64
102
|
### `exclude`
|
|
65
103
|
|
|
66
|
-
- Type:
|
|
104
|
+
- Type:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
type exclude = string | Array<string>;
|
|
108
|
+
```
|
|
109
|
+
|
|
67
110
|
- Default: `['node_modules', compiler.options.output.path]`
|
|
68
111
|
|
|
69
112
|
Specify the files and/or directories to exclude. Must be relative to `options.context`.
|
|
70
113
|
|
|
71
114
|
### `extensions`
|
|
72
115
|
|
|
73
|
-
- Type:
|
|
116
|
+
- Type:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
type extensions = string | Array<string>;
|
|
120
|
+
```
|
|
121
|
+
|
|
74
122
|
- Default: `['css', 'scss', 'sass']`
|
|
75
123
|
|
|
76
124
|
Specify extensions that should be checked.
|
|
77
125
|
|
|
78
126
|
### `files`
|
|
79
127
|
|
|
80
|
-
- Type:
|
|
128
|
+
- Type:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
type files = string | Array<string>;
|
|
132
|
+
```
|
|
133
|
+
|
|
81
134
|
- Default: `null`
|
|
82
135
|
|
|
83
|
-
Specify directories, files, or globs. Must be relative to `options.context`. Directories are
|
|
136
|
+
Specify directories, files, or globs. Must be relative to `options.context`. Directories are traversed recursively looking for files matching `options.extensions`. File and glob patterns ignore `options.extensions`.
|
|
84
137
|
|
|
85
138
|
### `fix`
|
|
86
139
|
|
|
87
|
-
- Type:
|
|
140
|
+
- Type:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
type fix = boolean;
|
|
144
|
+
```
|
|
145
|
+
|
|
88
146
|
- Default: `false`
|
|
89
147
|
|
|
90
|
-
If `true`, `stylelint` will fix as many errors as possible. The fixes are made to the actual source files. All unfixed errors will be reported. See [Autofixing errors](https://stylelint.io/user-guide/
|
|
148
|
+
If `true`, `stylelint` will fix as many errors as possible. The fixes are made to the actual source files. All unfixed errors will be reported. See [Autofixing errors](https://stylelint.io/user-guide/usage/options#fix) docs.
|
|
91
149
|
|
|
92
150
|
### `formatter`
|
|
93
151
|
|
|
94
|
-
- Type:
|
|
152
|
+
- Type:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
type formatter = string | (
|
|
156
|
+
results: Array<import('stylelint').LintResult>
|
|
157
|
+
) => string
|
|
158
|
+
```
|
|
159
|
+
|
|
95
160
|
- Default: `'string'`
|
|
96
161
|
|
|
97
|
-
Specify the formatter that you would like to use to format your results. See [formatter option](https://stylelint.io/user-guide/
|
|
162
|
+
Specify the formatter that you would like to use to format your results. See [formatter option](https://stylelint.io/user-guide/usage/options#formatter).
|
|
98
163
|
|
|
99
164
|
### `lintDirtyModulesOnly`
|
|
100
165
|
|
|
101
|
-
- Type:
|
|
166
|
+
- Type:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
type lintDirtyModulesOnly = boolean;
|
|
170
|
+
```
|
|
171
|
+
|
|
102
172
|
- Default: `false`
|
|
103
173
|
|
|
104
174
|
Lint only changed files, skip lint on start.
|
|
105
175
|
|
|
106
176
|
### `stylelintPath`
|
|
107
177
|
|
|
108
|
-
- Type:
|
|
178
|
+
- Type:
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
type stylelintPath = string;
|
|
182
|
+
```
|
|
183
|
+
|
|
109
184
|
- Default: `stylelint`
|
|
110
185
|
|
|
111
186
|
Path to `stylelint` instance that will be used for linting.
|
|
112
187
|
|
|
113
188
|
### `threads`
|
|
114
189
|
|
|
115
|
-
- Type:
|
|
190
|
+
- Type:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
type threads = boolean | number;
|
|
194
|
+
```
|
|
195
|
+
|
|
116
196
|
- Default: `false`
|
|
117
197
|
|
|
118
198
|
Set to true for an auto-selected pool size based on number of cpus. Set to a number greater than 1 to set an explicit pool size. Set to false, 1, or less to disable and only run in main process.
|
|
@@ -124,42 +204,82 @@ You can still force this behavior by using `emitError` **or** `emitWarning` opti
|
|
|
124
204
|
|
|
125
205
|
#### `emitError`
|
|
126
206
|
|
|
127
|
-
- Type:
|
|
128
|
-
|
|
207
|
+
- Type:
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
type emitError = boolean;
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
- Default: `true`
|
|
129
214
|
|
|
130
215
|
The errors found will always be emitted, to disable set to `false`.
|
|
131
216
|
|
|
132
217
|
#### `emitWarning`
|
|
133
218
|
|
|
134
|
-
- Type:
|
|
135
|
-
|
|
219
|
+
- Type:
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
type emitWarning = boolean;
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
- Default: `true`
|
|
136
226
|
|
|
137
227
|
The warnings found will always be emitted, to disable set to `false`.
|
|
138
228
|
|
|
139
229
|
#### `failOnError`
|
|
140
230
|
|
|
141
|
-
- Type:
|
|
142
|
-
|
|
231
|
+
- Type:
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
type failOnError = boolean;
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
- Default: `true`
|
|
143
238
|
|
|
144
239
|
Will cause the module build to fail if there are any errors, to disable set to `false`.
|
|
145
240
|
|
|
146
241
|
#### `failOnWarning`
|
|
147
242
|
|
|
148
|
-
- Type:
|
|
243
|
+
- Type:
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
type failOnWarning = boolean;
|
|
247
|
+
```
|
|
248
|
+
|
|
149
249
|
- Default: `false`
|
|
150
250
|
|
|
151
251
|
Will cause the module build to fail if there are any warnings, if set to `true`.
|
|
152
252
|
|
|
153
253
|
#### `quiet`
|
|
154
254
|
|
|
155
|
-
- Type:
|
|
255
|
+
- Type:
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
type quiet = boolean;
|
|
259
|
+
```
|
|
260
|
+
|
|
156
261
|
- Default: `false`
|
|
157
262
|
|
|
158
263
|
Will process and report errors only and ignore warnings, if set to `true`.
|
|
159
264
|
|
|
160
265
|
#### `outputReport`
|
|
161
266
|
|
|
162
|
-
- Type:
|
|
267
|
+
- Type:
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
type outputReport =
|
|
271
|
+
| boolean
|
|
272
|
+
| {
|
|
273
|
+
filePath?: string | undefined;
|
|
274
|
+
formatter?:
|
|
275
|
+
| (
|
|
276
|
+
| string
|
|
277
|
+
| ((results: Array<import('stylelint').LintResult>) => string)
|
|
278
|
+
)
|
|
279
|
+
| undefined;
|
|
280
|
+
};
|
|
281
|
+
```
|
|
282
|
+
|
|
163
283
|
- Default: `false`
|
|
164
284
|
|
|
165
285
|
Write the output of the errors to a file, for example a `json` file for use for reporting.
|
package/dist/StylelintError.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
3
|
class StylelintError extends Error {
|
|
9
4
|
/**
|
|
10
5
|
* @param {string=} messages
|
|
@@ -17,5 +12,4 @@ class StylelintError extends Error {
|
|
|
17
12
|
|
|
18
13
|
}
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
exports.default = _default;
|
|
15
|
+
module.exports = StylelintError;
|
package/dist/getStylelint.js
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.default = getStylelint;
|
|
3
|
+
const {
|
|
4
|
+
cpus
|
|
5
|
+
} = require('os');
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
const {
|
|
8
|
+
Worker: JestWorker
|
|
9
|
+
} = require('jest-worker'); // @ts-ignore
|
|
9
10
|
|
|
10
|
-
var _jestWorker = require("jest-worker");
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const {
|
|
13
|
+
setup,
|
|
14
|
+
lintFiles
|
|
15
|
+
} = require('./worker');
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
const {
|
|
18
|
+
jsonStringifyReplacerSortKeys
|
|
19
|
+
} = require('./utils');
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
const {
|
|
22
|
+
getStylelintOptions
|
|
23
|
+
} = require('./options');
|
|
24
|
+
/** @type {{[key: string]: any}} */
|
|
17
25
|
|
|
18
|
-
// @ts-ignore
|
|
19
26
|
|
|
20
|
-
/** @type {{[key: string]: any}} */
|
|
21
27
|
const cache = {};
|
|
22
28
|
/** @typedef {import('stylelint')} Stylelint */
|
|
23
29
|
|
|
@@ -29,9 +35,9 @@ const cache = {};
|
|
|
29
35
|
|
|
30
36
|
/** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */
|
|
31
37
|
|
|
32
|
-
/** @typedef {
|
|
38
|
+
/** @typedef {{api: import('stylelint').InternalApi, stylelint: Stylelint, lintFiles: LintTask, cleanup: AsyncTask, threads: number, }} Linter */
|
|
33
39
|
|
|
34
|
-
/** @typedef {
|
|
40
|
+
/** @typedef {import('jest-worker').Worker & {lintFiles: LintTask}} Worker */
|
|
35
41
|
|
|
36
42
|
/**
|
|
37
43
|
* @param {Options} options
|
|
@@ -39,10 +45,12 @@ const cache = {};
|
|
|
39
45
|
*/
|
|
40
46
|
|
|
41
47
|
function loadStylelint(options) {
|
|
42
|
-
const
|
|
48
|
+
const stylelintOptions = getStylelintOptions(options);
|
|
49
|
+
const stylelint = setup(options, stylelintOptions);
|
|
43
50
|
return {
|
|
44
51
|
stylelint,
|
|
45
|
-
|
|
52
|
+
api: stylelint.createLinter(stylelintOptions),
|
|
53
|
+
lintFiles,
|
|
46
54
|
cleanup: async () => {},
|
|
47
55
|
threads: 1
|
|
48
56
|
};
|
|
@@ -63,15 +71,12 @@ function loadStylelintThreaded(key, poolSize, options) {
|
|
|
63
71
|
const workerOptions = {
|
|
64
72
|
enableWorkerThreads: true,
|
|
65
73
|
numWorkers: poolSize,
|
|
66
|
-
setupArgs: [options,
|
|
74
|
+
setupArgs: [options, getStylelintOptions(options)]
|
|
67
75
|
};
|
|
68
76
|
const local = loadStylelint(options);
|
|
69
|
-
/** @type {Worker?} */
|
|
70
|
-
// prettier-ignore
|
|
71
|
-
|
|
72
77
|
let worker =
|
|
73
|
-
/** @type {Worker} */
|
|
74
|
-
new
|
|
78
|
+
/** @type {Worker?} */
|
|
79
|
+
new JestWorker(source, workerOptions);
|
|
75
80
|
/** @type {Linter} */
|
|
76
81
|
|
|
77
82
|
const context = { ...local,
|
|
@@ -105,7 +110,7 @@ function getStylelint(key, {
|
|
|
105
110
|
threads,
|
|
106
111
|
...options
|
|
107
112
|
}) {
|
|
108
|
-
const max = typeof threads !== 'number' ? threads ?
|
|
113
|
+
const max = typeof threads !== 'number' ? threads ? cpus().length - 1 : 1 : threads;
|
|
109
114
|
const cacheKey = getCacheKey(key, {
|
|
110
115
|
threads,
|
|
111
116
|
...options
|
|
@@ -128,5 +133,7 @@ function getCacheKey(key, options) {
|
|
|
128
133
|
return JSON.stringify({
|
|
129
134
|
key,
|
|
130
135
|
options
|
|
131
|
-
},
|
|
132
|
-
}
|
|
136
|
+
}, jsonStringifyReplacerSortKeys);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
module.exports = getStylelint;
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const {
|
|
4
|
+
isAbsolute,
|
|
5
|
+
join
|
|
6
|
+
} = require('path');
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const globby = require('globby');
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const {
|
|
11
|
+
isMatch
|
|
12
|
+
} = require('micromatch');
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
const {
|
|
15
|
+
getOptions
|
|
16
|
+
} = require('./options');
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var _linter = _interopRequireDefault(require("./linter"));
|
|
17
|
-
|
|
18
|
-
var _utils = require("./utils");
|
|
19
|
-
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
// @ts-ignore
|
|
18
|
+
const linter = require('./linter');
|
|
23
19
|
|
|
20
|
+
const {
|
|
21
|
+
arrify,
|
|
22
|
+
parseFiles,
|
|
23
|
+
parseFoldersToGlobs
|
|
24
|
+
} = require('./utils');
|
|
24
25
|
/** @typedef {import('webpack').Compiler} Compiler */
|
|
25
26
|
|
|
26
27
|
/** @typedef {import('webpack').Module} Module */
|
|
@@ -28,6 +29,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
28
29
|
/** @typedef {import('./options').Options} Options */
|
|
29
30
|
|
|
30
31
|
/** @typedef {Partial<{timestamp:number} | number>} FileSystemInfoEntry */
|
|
32
|
+
|
|
33
|
+
|
|
31
34
|
const STYLELINT_PLUGIN = 'StylelintWebpackPlugin';
|
|
32
35
|
let counter = 0;
|
|
33
36
|
|
|
@@ -37,7 +40,7 @@ class StylelintWebpackPlugin {
|
|
|
37
40
|
*/
|
|
38
41
|
constructor(options = {}) {
|
|
39
42
|
this.key = STYLELINT_PLUGIN;
|
|
40
|
-
this.options =
|
|
43
|
+
this.options = getOptions(options);
|
|
41
44
|
this.run = this.run.bind(this);
|
|
42
45
|
this.startTime = Date.now();
|
|
43
46
|
this.prevTimestamps = new Map();
|
|
@@ -87,15 +90,18 @@ class StylelintWebpackPlugin {
|
|
|
87
90
|
const context = this.getContext(compiler);
|
|
88
91
|
const excludeDefault = ['**/node_modules/**', String(compiler.options.output.path)];
|
|
89
92
|
const options = { ...this.options,
|
|
90
|
-
exclude:
|
|
91
|
-
extensions:
|
|
92
|
-
files:
|
|
93
|
+
exclude: parseFiles(this.options.exclude || excludeDefault, context),
|
|
94
|
+
extensions: arrify(this.options.extensions),
|
|
95
|
+
files: parseFiles(this.options.files || '', context)
|
|
93
96
|
};
|
|
94
|
-
const wanted =
|
|
95
|
-
const exclude =
|
|
97
|
+
const wanted = parseFoldersToGlobs(options.files, options.extensions);
|
|
98
|
+
const exclude = parseFoldersToGlobs(options.exclude);
|
|
96
99
|
compiler.hooks.thisCompilation.tap(this.key, compilation => {
|
|
97
100
|
/** @type {import('./linter').Linter} */
|
|
98
101
|
let lint;
|
|
102
|
+
/** @type {import('stylelint').InternalApi} */
|
|
103
|
+
|
|
104
|
+
let api;
|
|
99
105
|
/** @type {import('./linter').Reporter} */
|
|
100
106
|
|
|
101
107
|
let report;
|
|
@@ -106,30 +112,39 @@ class StylelintWebpackPlugin {
|
|
|
106
112
|
try {
|
|
107
113
|
({
|
|
108
114
|
lint,
|
|
115
|
+
api,
|
|
109
116
|
report,
|
|
110
117
|
threads
|
|
111
|
-
} = (
|
|
118
|
+
} = linter(this.key, options, compilation));
|
|
112
119
|
} catch (e) {
|
|
113
120
|
compilation.errors.push(e);
|
|
114
121
|
return;
|
|
115
122
|
}
|
|
116
123
|
|
|
117
|
-
compilation.hooks.finishModules.
|
|
118
|
-
|
|
124
|
+
compilation.hooks.finishModules.tapPromise(this.key, async () => {
|
|
125
|
+
/** @type {string[]} */
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
const files = (await Promise.all((compiler.modifiedFiles ? Array.from(compiler.modifiedFiles).filter(file => isMatch(file, wanted, {
|
|
119
128
|
dot: true
|
|
120
|
-
}) && !
|
|
129
|
+
}) && !isMatch(file, exclude, {
|
|
121
130
|
dot: true
|
|
122
|
-
})) :
|
|
131
|
+
})) : globby.sync(wanted, {
|
|
123
132
|
dot: true,
|
|
124
133
|
ignore: exclude
|
|
125
|
-
})
|
|
134
|
+
})).map(async file => {
|
|
135
|
+
try {
|
|
136
|
+
return (await api.isPathIgnored(file)) ? false : file;
|
|
137
|
+
} catch (e) {
|
|
138
|
+
return file;
|
|
139
|
+
}
|
|
140
|
+
}))).filter(file => file !== false);
|
|
126
141
|
|
|
127
142
|
if (threads > 1) {
|
|
128
143
|
for (const file of files) {
|
|
129
|
-
lint(
|
|
144
|
+
lint(parseFiles(file, context));
|
|
130
145
|
}
|
|
131
146
|
} else if (files.length > 0) {
|
|
132
|
-
lint(
|
|
147
|
+
lint(parseFiles(files, context));
|
|
133
148
|
}
|
|
134
149
|
}); // await and interpret results
|
|
135
150
|
|
|
@@ -176,8 +191,8 @@ class StylelintWebpackPlugin {
|
|
|
176
191
|
return String(compiler.options.context);
|
|
177
192
|
}
|
|
178
193
|
|
|
179
|
-
if (!
|
|
180
|
-
return
|
|
194
|
+
if (!isAbsolute(this.options.context)) {
|
|
195
|
+
return join(String(compiler.options.context), this.options.context);
|
|
181
196
|
}
|
|
182
197
|
|
|
183
198
|
return this.options.context;
|
|
@@ -185,5 +200,4 @@ class StylelintWebpackPlugin {
|
|
|
185
200
|
|
|
186
201
|
}
|
|
187
202
|
|
|
188
|
-
|
|
189
|
-
exports.default = _default;
|
|
203
|
+
module.exports = StylelintWebpackPlugin;
|
package/dist/linter.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const {
|
|
4
|
+
dirname,
|
|
5
|
+
isAbsolute,
|
|
6
|
+
join
|
|
7
|
+
} = require('path');
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
const StylelintError = require('./StylelintError');
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _getStylelint = _interopRequireDefault(require("./getStylelint"));
|
|
13
|
-
|
|
14
|
-
var _utils = require("./utils");
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
const getStylelint = require('./getStylelint');
|
|
17
12
|
|
|
13
|
+
const {
|
|
14
|
+
arrify
|
|
15
|
+
} = require('./utils');
|
|
18
16
|
/** @typedef {import('stylelint')} Stylelint */
|
|
19
17
|
|
|
20
18
|
/** @typedef {import('stylelint').LintResult} LintResult */
|
|
21
19
|
|
|
20
|
+
/** @typedef {import('stylelint').InternalApi} InternalApi */
|
|
21
|
+
|
|
22
22
|
/** @typedef {import('webpack').Compiler} Compiler */
|
|
23
23
|
|
|
24
24
|
/** @typedef {import('webpack').Compilation} Compilation */
|
|
@@ -40,17 +40,22 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
40
40
|
/** @typedef {{[files: string]: LintResult}} LintResultMap */
|
|
41
41
|
|
|
42
42
|
/** @type {WeakMap<Compiler, LintResultMap>} */
|
|
43
|
+
|
|
44
|
+
|
|
43
45
|
const resultStorage = new WeakMap();
|
|
44
46
|
/**
|
|
45
47
|
* @param {string|undefined} key
|
|
46
48
|
* @param {Options} options
|
|
47
49
|
* @param {Compilation} compilation
|
|
48
|
-
* @returns {{lint: Linter, report: Reporter, threads: number}}
|
|
50
|
+
* @returns {{api: InternalApi, lint: Linter, report: Reporter, threads: number}}
|
|
49
51
|
*/
|
|
50
52
|
|
|
51
53
|
function linter(key, options, compilation) {
|
|
52
54
|
/** @type {Stylelint} */
|
|
53
55
|
let stylelint;
|
|
56
|
+
/** @type {InternalApi} */
|
|
57
|
+
|
|
58
|
+
let api;
|
|
54
59
|
/** @type {(files: string|string[]) => Promise<LintResult[]>} */
|
|
55
60
|
|
|
56
61
|
let lintFiles;
|
|
@@ -68,16 +73,18 @@ function linter(key, options, compilation) {
|
|
|
68
73
|
try {
|
|
69
74
|
({
|
|
70
75
|
stylelint,
|
|
76
|
+
api,
|
|
71
77
|
lintFiles,
|
|
72
78
|
cleanup,
|
|
73
79
|
threads
|
|
74
|
-
} = (
|
|
80
|
+
} = getStylelint(key, options));
|
|
75
81
|
} catch (e) {
|
|
76
|
-
throw new
|
|
82
|
+
throw new StylelintError(e.message);
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
return {
|
|
80
86
|
lint,
|
|
87
|
+
api,
|
|
81
88
|
report,
|
|
82
89
|
threads
|
|
83
90
|
};
|
|
@@ -86,7 +93,7 @@ function linter(key, options, compilation) {
|
|
|
86
93
|
*/
|
|
87
94
|
|
|
88
95
|
function lint(files) {
|
|
89
|
-
for (const file of
|
|
96
|
+
for (const file of arrify(files)) {
|
|
90
97
|
delete crossRunResultStorage[file];
|
|
91
98
|
}
|
|
92
99
|
|
|
@@ -103,7 +110,7 @@ function linter(key, options, compilation) {
|
|
|
103
110
|
await cleanup();
|
|
104
111
|
|
|
105
112
|
for (const result of results) {
|
|
106
|
-
crossRunResultStorage[result.source] = result;
|
|
113
|
+
crossRunResultStorage[String(result.source)] = result;
|
|
107
114
|
}
|
|
108
115
|
|
|
109
116
|
results = Object.values(crossRunResultStorage); // do not analyze if there are no results or stylelint config
|
|
@@ -147,7 +154,7 @@ function linter(key, options, compilation) {
|
|
|
147
154
|
} = compiler.outputFileSystem; // ensure directory exists
|
|
148
155
|
// @ts-ignore - the types for `outputFileSystem` are missing the 3 arg overload
|
|
149
156
|
|
|
150
|
-
mkdir(
|
|
157
|
+
mkdir(dirname(name), {
|
|
151
158
|
recursive: true
|
|
152
159
|
}, err => {
|
|
153
160
|
/* istanbul ignore if */
|
|
@@ -167,8 +174,8 @@ function linter(key, options, compilation) {
|
|
|
167
174
|
filePath
|
|
168
175
|
} = outputReport;
|
|
169
176
|
|
|
170
|
-
if (!
|
|
171
|
-
filePath =
|
|
177
|
+
if (!isAbsolute(filePath)) {
|
|
178
|
+
filePath = join(compiler.outputPath, filePath);
|
|
172
179
|
}
|
|
173
180
|
|
|
174
181
|
await save(filePath, content);
|
|
@@ -187,11 +194,11 @@ function formatResults(formatter, results) {
|
|
|
187
194
|
let warnings;
|
|
188
195
|
|
|
189
196
|
if (results.warnings.length > 0) {
|
|
190
|
-
warnings = new
|
|
197
|
+
warnings = new StylelintError(formatter(results.warnings));
|
|
191
198
|
}
|
|
192
199
|
|
|
193
200
|
if (results.errors.length > 0) {
|
|
194
|
-
errors = new
|
|
201
|
+
errors = new StylelintError(formatter(results.errors));
|
|
195
202
|
}
|
|
196
203
|
|
|
197
204
|
return {
|
|
@@ -295,4 +302,6 @@ function getResultStorage({
|
|
|
295
302
|
}
|
|
296
303
|
|
|
297
304
|
return storage;
|
|
298
|
-
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
module.exports = linter;
|