stylelint-webpack-plugin 3.1.0 → 3.3.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 +143 -23
- package/dist/StylelintError.js +2 -8
- package/dist/getStylelint.js +31 -24
- package/dist/index.js +60 -42
- package/dist/linter.js +33 -23
- package/dist/options.js +14 -16
- package/dist/utils.js +17 -19
- package/package.json +30 -31
- package/types/StylelintError.d.ts +8 -0
- package/{declarations → types}/getStylelint.d.ts +35 -13
- package/{declarations → types}/index.d.ts +22 -11
- package/{declarations → types}/linter.d.ts +44 -15
- package/{declarations → types}/options.d.ts +47 -38
- package/{declarations → types}/utils.d.ts +5 -0
- package/{declarations → types}/worker.d.ts +9 -0
- package/declarations/StylelintError.d.ts +0 -2
- package/declarations/cjs.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 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:
|
|
207
|
+
- Type:
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
type emitError = boolean;
|
|
211
|
+
```
|
|
212
|
+
|
|
128
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:
|
|
219
|
+
- Type:
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
type emitWarning = boolean;
|
|
223
|
+
```
|
|
224
|
+
|
|
135
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:
|
|
231
|
+
- Type:
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
type failOnError = boolean;
|
|
235
|
+
```
|
|
236
|
+
|
|
142
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,21 +1,15 @@
|
|
|
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
|
|
11
6
|
*/
|
|
12
7
|
constructor(messages) {
|
|
13
|
-
super(messages);
|
|
8
|
+
super(`[stylelint] ${messages}`);
|
|
14
9
|
this.name = 'StylelintError';
|
|
15
10
|
this.stack = '';
|
|
16
11
|
}
|
|
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 {JestWorker & {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();
|
|
@@ -51,11 +54,21 @@ class StylelintWebpackPlugin {
|
|
|
51
54
|
apply(compiler) {
|
|
52
55
|
// Generate key for each compilation,
|
|
53
56
|
// this differentiates one from the other when being cached.
|
|
54
|
-
this.key = compiler.name || `${this.key}_${counter += 1}`;
|
|
57
|
+
this.key = compiler.name || `${this.key}_${counter += 1}`;
|
|
58
|
+
const context = this.getContext(compiler);
|
|
59
|
+
const excludeDefault = ['**/node_modules/**', String(compiler.options.output.path)];
|
|
60
|
+
const options = { ...this.options,
|
|
61
|
+
context,
|
|
62
|
+
exclude: parseFiles(this.options.exclude || excludeDefault, context),
|
|
63
|
+
extensions: arrify(this.options.extensions),
|
|
64
|
+
files: parseFiles(this.options.files || '', context)
|
|
65
|
+
};
|
|
66
|
+
const wanted = parseFoldersToGlobs(options.files, options.extensions);
|
|
67
|
+
const exclude = parseFoldersToGlobs(options.exclude); // If `lintDirtyModulesOnly` is disabled,
|
|
55
68
|
// execute the linter on the build
|
|
56
69
|
|
|
57
70
|
if (!this.options.lintDirtyModulesOnly) {
|
|
58
|
-
compiler.hooks.run.tapPromise(this.key, this.run);
|
|
71
|
+
compiler.hooks.run.tapPromise(this.key, c => this.run(c, options, wanted, exclude));
|
|
59
72
|
}
|
|
60
73
|
|
|
61
74
|
let isFirstRun = this.options.lintDirtyModulesOnly;
|
|
@@ -65,15 +78,18 @@ class StylelintWebpackPlugin {
|
|
|
65
78
|
return Promise.resolve();
|
|
66
79
|
}
|
|
67
80
|
|
|
68
|
-
return this.run(c);
|
|
81
|
+
return this.run(c, options, wanted, exclude);
|
|
69
82
|
});
|
|
70
83
|
}
|
|
71
84
|
/**
|
|
72
85
|
* @param {Compiler} compiler
|
|
86
|
+
* @param {Options} options
|
|
87
|
+
* @param {string[]} wanted
|
|
88
|
+
* @param {string[]} exclude
|
|
73
89
|
*/
|
|
74
90
|
|
|
75
91
|
|
|
76
|
-
async run(compiler) {
|
|
92
|
+
async run(compiler, options, wanted, exclude) {
|
|
77
93
|
// Do not re-hook
|
|
78
94
|
|
|
79
95
|
/* istanbul ignore if */
|
|
@@ -84,18 +100,12 @@ class StylelintWebpackPlugin {
|
|
|
84
100
|
return;
|
|
85
101
|
}
|
|
86
102
|
|
|
87
|
-
const context = this.getContext(compiler);
|
|
88
|
-
const excludeDefault = ['**/node_modules/**', String(compiler.options.output.path)];
|
|
89
|
-
const options = { ...this.options,
|
|
90
|
-
exclude: (0, _utils.parseFiles)(this.options.exclude || excludeDefault, context),
|
|
91
|
-
extensions: (0, _utils.arrify)(this.options.extensions),
|
|
92
|
-
files: (0, _utils.parseFiles)(this.options.files || '', context)
|
|
93
|
-
};
|
|
94
|
-
const wanted = (0, _utils.parseFoldersToGlobs)(options.files, options.extensions);
|
|
95
|
-
const exclude = (0, _utils.parseFoldersToGlobs)(options.exclude);
|
|
96
103
|
compiler.hooks.thisCompilation.tap(this.key, compilation => {
|
|
97
104
|
/** @type {import('./linter').Linter} */
|
|
98
105
|
let lint;
|
|
106
|
+
/** @type {import('stylelint').InternalApi} */
|
|
107
|
+
|
|
108
|
+
let api;
|
|
99
109
|
/** @type {import('./linter').Reporter} */
|
|
100
110
|
|
|
101
111
|
let report;
|
|
@@ -106,30 +116,39 @@ class StylelintWebpackPlugin {
|
|
|
106
116
|
try {
|
|
107
117
|
({
|
|
108
118
|
lint,
|
|
119
|
+
api,
|
|
109
120
|
report,
|
|
110
121
|
threads
|
|
111
|
-
} = (
|
|
122
|
+
} = linter(this.key, options, compilation));
|
|
112
123
|
} catch (e) {
|
|
113
124
|
compilation.errors.push(e);
|
|
114
125
|
return;
|
|
115
126
|
}
|
|
116
127
|
|
|
117
|
-
compilation.hooks.finishModules.
|
|
118
|
-
|
|
128
|
+
compilation.hooks.finishModules.tapPromise(this.key, async () => {
|
|
129
|
+
/** @type {string[]} */
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
const files = (await Promise.all((compiler.modifiedFiles ? Array.from(compiler.modifiedFiles).filter(file => isMatch(file, wanted, {
|
|
119
132
|
dot: true
|
|
120
|
-
}) && !
|
|
133
|
+
}) && !isMatch(file, exclude, {
|
|
121
134
|
dot: true
|
|
122
|
-
})) :
|
|
135
|
+
})) : globby.sync(wanted, {
|
|
123
136
|
dot: true,
|
|
124
137
|
ignore: exclude
|
|
125
|
-
})
|
|
138
|
+
})).map(async file => {
|
|
139
|
+
try {
|
|
140
|
+
return (await api.isPathIgnored(file)) ? false : file;
|
|
141
|
+
} catch (e) {
|
|
142
|
+
return file;
|
|
143
|
+
}
|
|
144
|
+
}))).filter(file => file !== false);
|
|
126
145
|
|
|
127
146
|
if (threads > 1) {
|
|
128
147
|
for (const file of files) {
|
|
129
|
-
lint(
|
|
148
|
+
lint(parseFiles(file, options.context || ''));
|
|
130
149
|
}
|
|
131
150
|
} else if (files.length > 0) {
|
|
132
|
-
lint(
|
|
151
|
+
lint(parseFiles(files, options.context || ''));
|
|
133
152
|
}
|
|
134
153
|
}); // await and interpret results
|
|
135
154
|
|
|
@@ -176,8 +195,8 @@ class StylelintWebpackPlugin {
|
|
|
176
195
|
return String(compiler.options.context);
|
|
177
196
|
}
|
|
178
197
|
|
|
179
|
-
if (!
|
|
180
|
-
return
|
|
198
|
+
if (!isAbsolute(this.options.context)) {
|
|
199
|
+
return join(String(compiler.options.context), this.options.context);
|
|
181
200
|
}
|
|
182
201
|
|
|
183
202
|
return this.options.context;
|
|
@@ -185,5 +204,4 @@ class StylelintWebpackPlugin {
|
|
|
185
204
|
|
|
186
205
|
}
|
|
187
206
|
|
|
188
|
-
|
|
189
|
-
exports.default = _default;
|
|
207
|
+
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,12 +93,13 @@ 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
|
|
|
93
100
|
rawResults.push(lintFiles(files).catch(e => {
|
|
94
|
-
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
compilation.errors.push(new StylelintError(e.message));
|
|
95
103
|
return [];
|
|
96
104
|
}));
|
|
97
105
|
}
|
|
@@ -147,7 +155,7 @@ function linter(key, options, compilation) {
|
|
|
147
155
|
} = compiler.outputFileSystem; // ensure directory exists
|
|
148
156
|
// @ts-ignore - the types for `outputFileSystem` are missing the 3 arg overload
|
|
149
157
|
|
|
150
|
-
mkdir(
|
|
158
|
+
mkdir(dirname(name), {
|
|
151
159
|
recursive: true
|
|
152
160
|
}, err => {
|
|
153
161
|
/* istanbul ignore if */
|
|
@@ -167,8 +175,8 @@ function linter(key, options, compilation) {
|
|
|
167
175
|
filePath
|
|
168
176
|
} = outputReport;
|
|
169
177
|
|
|
170
|
-
if (!
|
|
171
|
-
filePath =
|
|
178
|
+
if (!isAbsolute(filePath)) {
|
|
179
|
+
filePath = join(compiler.outputPath, filePath);
|
|
172
180
|
}
|
|
173
181
|
|
|
174
182
|
await save(filePath, content);
|
|
@@ -187,11 +195,11 @@ function formatResults(formatter, results) {
|
|
|
187
195
|
let warnings;
|
|
188
196
|
|
|
189
197
|
if (results.warnings.length > 0) {
|
|
190
|
-
warnings = new
|
|
198
|
+
warnings = new StylelintError(formatter(results.warnings));
|
|
191
199
|
}
|
|
192
200
|
|
|
193
201
|
if (results.errors.length > 0) {
|
|
194
|
-
errors = new
|
|
202
|
+
errors = new StylelintError(formatter(results.errors));
|
|
195
203
|
}
|
|
196
204
|
|
|
197
205
|
return {
|
|
@@ -295,4 +303,6 @@ function getResultStorage({
|
|
|
295
303
|
}
|
|
296
304
|
|
|
297
305
|
return storage;
|
|
298
|
-
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
module.exports = linter;
|
package/dist/options.js
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.getOptions = getOptions;
|
|
7
|
-
exports.getStylelintOptions = getStylelintOptions;
|
|
8
|
-
|
|
9
|
-
var _schemaUtils = require("schema-utils");
|
|
10
|
-
|
|
11
|
-
var _options = _interopRequireDefault(require("./options.json"));
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
// @ts-ignore
|
|
3
|
+
const {
|
|
4
|
+
validate
|
|
5
|
+
} = require('schema-utils');
|
|
16
6
|
|
|
7
|
+
const schema = require('./options.json');
|
|
17
8
|
/** @typedef {import("stylelint")} stylelint */
|
|
18
9
|
|
|
19
10
|
/** @typedef {import("stylelint").LinterOptions} StylelintOptions */
|
|
@@ -50,6 +41,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
50
41
|
* @param {Options} pluginOptions
|
|
51
42
|
* @returns {Partial<PluginOptions>}
|
|
52
43
|
*/
|
|
44
|
+
|
|
45
|
+
|
|
53
46
|
function getOptions(pluginOptions) {
|
|
54
47
|
const options = {
|
|
55
48
|
extensions: ['css', 'scss', 'sass'],
|
|
@@ -63,7 +56,7 @@ function getOptions(pluginOptions) {
|
|
|
63
56
|
} : {})
|
|
64
57
|
}; // @ts-ignore
|
|
65
58
|
|
|
66
|
-
|
|
59
|
+
validate(schema, options, {
|
|
67
60
|
name: 'Stylelint Webpack Plugin',
|
|
68
61
|
baseDataPath: 'options'
|
|
69
62
|
});
|
|
@@ -83,7 +76,7 @@ function getStylelintOptions(pluginOptions) {
|
|
|
83
76
|
files,
|
|
84
77
|
formatter,
|
|
85
78
|
...stylelintOnlyOptions
|
|
86
|
-
} =
|
|
79
|
+
} = schema.properties; // No need to guard the for-in because schema.properties has hardcoded keys.
|
|
87
80
|
// eslint-disable-next-line guard-for-in
|
|
88
81
|
|
|
89
82
|
for (const option in stylelintOnlyOptions) {
|
|
@@ -92,4 +85,9 @@ function getStylelintOptions(pluginOptions) {
|
|
|
92
85
|
}
|
|
93
86
|
|
|
94
87
|
return stylelintOptions;
|
|
95
|
-
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = {
|
|
91
|
+
getOptions,
|
|
92
|
+
getStylelintOptions
|
|
93
|
+
};
|
package/dist/utils.js
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.arrify = arrify;
|
|
7
|
-
exports.jsonStringifyReplacerSortKeys = void 0;
|
|
8
|
-
exports.parseFiles = parseFiles;
|
|
9
|
-
exports.parseFoldersToGlobs = parseFoldersToGlobs;
|
|
3
|
+
const {
|
|
4
|
+
resolve
|
|
5
|
+
} = require('path');
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _normalizePath = _interopRequireDefault(require("normalize-path"));
|
|
16
|
-
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
|
|
19
|
-
// @ts-ignore
|
|
7
|
+
const {
|
|
8
|
+
statSync
|
|
9
|
+
} = require('fs');
|
|
20
10
|
|
|
11
|
+
const normalizePath = require('normalize-path');
|
|
21
12
|
/**
|
|
22
13
|
* @template T
|
|
23
14
|
* @param {T} value
|
|
@@ -35,6 +26,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
35
26
|
*/
|
|
36
27
|
|
|
37
28
|
/* istanbul ignore next */
|
|
29
|
+
|
|
30
|
+
|
|
38
31
|
function arrify(value) {
|
|
39
32
|
// eslint-disable-next-line no-undefined
|
|
40
33
|
if (value === null || value === undefined) {
|
|
@@ -71,7 +64,7 @@ function arrify(value) {
|
|
|
71
64
|
function parseFiles(files, context) {
|
|
72
65
|
return arrify(files).map((
|
|
73
66
|
/** @type {string} */
|
|
74
|
-
file) => (
|
|
67
|
+
file) => normalizePath(resolve(context, file)));
|
|
75
68
|
}
|
|
76
69
|
/**
|
|
77
70
|
* @param {string|string[]} patterns
|
|
@@ -91,7 +84,7 @@ function parseFoldersToGlobs(patterns, extensions = []) {
|
|
|
91
84
|
pattern) => {
|
|
92
85
|
try {
|
|
93
86
|
// The patterns are absolute because they are prepended with the context.
|
|
94
|
-
const stats =
|
|
87
|
+
const stats = statSync(pattern);
|
|
95
88
|
/* istanbul ignore else */
|
|
96
89
|
|
|
97
90
|
if (stats.isDirectory()) {
|
|
@@ -124,4 +117,9 @@ const jsonStringifyReplacerSortKeys = (_, value) => {
|
|
|
124
117
|
return value instanceof Object && !(value instanceof Array) ? Object.keys(value).sort().reduce(insert, {}) : value;
|
|
125
118
|
};
|
|
126
119
|
|
|
127
|
-
exports
|
|
120
|
+
module.exports = {
|
|
121
|
+
arrify,
|
|
122
|
+
parseFiles,
|
|
123
|
+
parseFoldersToGlobs,
|
|
124
|
+
jsonStringifyReplacerSortKeys
|
|
125
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stylelint-webpack-plugin",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "A Stylelint plugin for webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/stylelint-webpack-plugin",
|
|
@@ -11,16 +11,16 @@
|
|
|
11
11
|
"type": "opencollective",
|
|
12
12
|
"url": "https://opencollective.com/webpack"
|
|
13
13
|
},
|
|
14
|
-
"main": "dist/
|
|
15
|
-
"types": "
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"types": "types/index.d.ts",
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">= 12.13.0"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"start": "npm run build -- -w",
|
|
21
|
-
"clean": "del-cli dist
|
|
21
|
+
"clean": "del-cli dist types",
|
|
22
22
|
"prebuild": "npm run clean",
|
|
23
|
-
"build:types": "tsc --declaration --emitDeclarationOnly --outDir
|
|
23
|
+
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write",
|
|
24
24
|
"build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files",
|
|
25
25
|
"build": "npm-run-all -p \"build:**\"",
|
|
26
26
|
"commitlint": "commitlint --from=master",
|
|
@@ -39,52 +39,51 @@
|
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
41
41
|
"dist",
|
|
42
|
-
"
|
|
42
|
+
"types"
|
|
43
43
|
],
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"stylelint": "^13.0.0 || ^14.0.0",
|
|
46
46
|
"webpack": "^5.0.0"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"
|
|
50
|
-
"globby": "^11.0
|
|
51
|
-
"
|
|
52
|
-
"micromatch": "^4.0.4",
|
|
49
|
+
"jest-worker": "^28.1.0",
|
|
50
|
+
"globby": "^11.1.0",
|
|
51
|
+
"micromatch": "^4.0.5",
|
|
53
52
|
"normalize-path": "^3.0.0",
|
|
54
|
-
"schema-utils": "^
|
|
53
|
+
"schema-utils": "^4.0.0"
|
|
55
54
|
},
|
|
56
55
|
"devDependencies": {
|
|
57
|
-
"@babel/cli": "^7.
|
|
58
|
-
"@babel/core": "^7.
|
|
59
|
-
"@babel/preset-env": "^7.
|
|
60
|
-
"@commitlint/cli": "^
|
|
61
|
-
"@commitlint/config-conventional": "^
|
|
56
|
+
"@babel/cli": "^7.17.10",
|
|
57
|
+
"@babel/core": "^7.18.0",
|
|
58
|
+
"@babel/preset-env": "^7.18.0",
|
|
59
|
+
"@commitlint/cli": "^16.2.3",
|
|
60
|
+
"@commitlint/config-conventional": "^16.2.1",
|
|
62
61
|
"@types/fs-extra": "^9.0.13",
|
|
63
62
|
"@types/micromatch": "^4.0.2",
|
|
64
63
|
"@types/normalize-path": "^3.0.0",
|
|
65
64
|
"@types/webpack": "^5.28.0",
|
|
66
65
|
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
|
|
67
66
|
"babel-eslint": "^10.1.0",
|
|
68
|
-
"babel-jest": "^
|
|
69
|
-
"chokidar": "^3.5.
|
|
67
|
+
"babel-jest": "^28.1.0",
|
|
68
|
+
"chokidar": "^3.5.3",
|
|
70
69
|
"cross-env": "^7.0.3",
|
|
71
|
-
"del": "^6.
|
|
70
|
+
"del": "^6.1.0",
|
|
72
71
|
"del-cli": "^4.0.1",
|
|
73
|
-
"eslint": "^8.
|
|
74
|
-
"eslint-config-prettier": "^8.
|
|
75
|
-
"eslint-plugin-import": "^2.
|
|
72
|
+
"eslint": "^8.15.0",
|
|
73
|
+
"eslint-config-prettier": "^8.5.0",
|
|
74
|
+
"eslint-plugin-import": "^2.26.0",
|
|
76
75
|
"file-loader": "^6.2.0",
|
|
77
|
-
"fs-extra": "^10.
|
|
76
|
+
"fs-extra": "^10.1.0",
|
|
78
77
|
"husky": "^7.0.4",
|
|
79
|
-
"jest": "^
|
|
80
|
-
"lint-staged": "^
|
|
78
|
+
"jest": "^28.1.0",
|
|
79
|
+
"lint-staged": "^12.4.1",
|
|
81
80
|
"npm-run-all": "^4.1.5",
|
|
82
|
-
"postcss-scss": "^4.0.
|
|
83
|
-
"prettier": "^2.
|
|
84
|
-
"standard-version": "^9.
|
|
85
|
-
"stylelint": "^14.
|
|
86
|
-
"typescript": "^4.
|
|
87
|
-
"webpack": "^5.
|
|
81
|
+
"postcss-scss": "^4.0.4",
|
|
82
|
+
"prettier": "^2.6.2",
|
|
83
|
+
"standard-version": "^9.5.0",
|
|
84
|
+
"stylelint": "^14.8.2",
|
|
85
|
+
"typescript": "^4.6.2",
|
|
86
|
+
"webpack": "^5.72.1"
|
|
88
87
|
},
|
|
89
88
|
"keywords": [
|
|
90
89
|
"stylelint",
|
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
/// <reference types="stylelint" />
|
|
2
|
+
export = getStylelint;
|
|
2
3
|
/**
|
|
3
4
|
* @param {string|undefined} key
|
|
4
5
|
* @param {Options} options
|
|
5
6
|
* @returns {Linter}
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
declare function getStylelint(
|
|
8
9
|
key: string | undefined,
|
|
9
10
|
{ threads, ...options }: Options
|
|
10
11
|
): Linter;
|
|
11
|
-
|
|
12
|
+
declare namespace getStylelint {
|
|
13
|
+
export {
|
|
14
|
+
Stylelint,
|
|
15
|
+
LintResult,
|
|
16
|
+
Options,
|
|
17
|
+
AsyncTask,
|
|
18
|
+
LintTask,
|
|
19
|
+
Linter,
|
|
20
|
+
Worker,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
type Options = import('./options').Options;
|
|
24
|
+
type Linter = {
|
|
25
|
+
api: import('stylelint').InternalApi;
|
|
26
|
+
stylelint: Stylelint;
|
|
27
|
+
lintFiles: LintTask;
|
|
28
|
+
cleanup: AsyncTask;
|
|
29
|
+
threads: number;
|
|
30
|
+
};
|
|
31
|
+
type Stylelint = import('postcss').PluginCreator<
|
|
12
32
|
import('stylelint').PostcssPluginOptions
|
|
13
33
|
> & {
|
|
14
34
|
lint: (
|
|
@@ -30,6 +50,15 @@ export type Stylelint = import('postcss').PluginCreator<
|
|
|
30
50
|
createLinter: (
|
|
31
51
|
options: import('stylelint').LinterOptions
|
|
32
52
|
) => import('stylelint').InternalApi;
|
|
53
|
+
resolveConfig: (
|
|
54
|
+
filePath: string,
|
|
55
|
+
options?:
|
|
56
|
+
| Pick<
|
|
57
|
+
import('stylelint').LinterOptions,
|
|
58
|
+
'cwd' | 'config' | 'configFile' | 'configBasedir'
|
|
59
|
+
>
|
|
60
|
+
| undefined
|
|
61
|
+
) => Promise<import('stylelint').Config | undefined>;
|
|
33
62
|
utils: {
|
|
34
63
|
report: (problem: import('stylelint').Problem) => void;
|
|
35
64
|
ruleMessages: <
|
|
@@ -54,17 +83,10 @@ export type Stylelint = import('postcss').PluginCreator<
|
|
|
54
83
|
) => void;
|
|
55
84
|
};
|
|
56
85
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
export type Worker = JestWorker & {
|
|
86
|
+
type LintResult = import('stylelint').LintResult;
|
|
87
|
+
type AsyncTask = () => Promise<void>;
|
|
88
|
+
type LintTask = (files: string | string[]) => Promise<LintResult[]>;
|
|
89
|
+
type Worker = JestWorker & {
|
|
62
90
|
lintFiles: LintTask;
|
|
63
91
|
};
|
|
64
|
-
export type Linter = {
|
|
65
|
-
stylelint: Stylelint;
|
|
66
|
-
lintFiles: LintTask;
|
|
67
|
-
cleanup: AsyncTask;
|
|
68
|
-
threads: number;
|
|
69
|
-
};
|
|
70
92
|
import { Worker as JestWorker } from 'jest-worker';
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export type Compiler = import('webpack').Compiler;
|
|
3
|
-
export type Module = import('webpack').Module;
|
|
4
|
-
export type Options = import('./options').Options;
|
|
5
|
-
export type FileSystemInfoEntry = Partial<
|
|
6
|
-
| {
|
|
7
|
-
timestamp: number;
|
|
8
|
-
}
|
|
9
|
-
| number
|
|
10
|
-
>;
|
|
1
|
+
export = StylelintWebpackPlugin;
|
|
11
2
|
declare class StylelintWebpackPlugin {
|
|
12
3
|
/**
|
|
13
4
|
* @param {Options} options
|
|
@@ -17,8 +8,16 @@ declare class StylelintWebpackPlugin {
|
|
|
17
8
|
options: Partial<import('./options').PluginOptions>;
|
|
18
9
|
/**
|
|
19
10
|
* @param {Compiler} compiler
|
|
11
|
+
* @param {Options} options
|
|
12
|
+
* @param {string[]} wanted
|
|
13
|
+
* @param {string[]} exclude
|
|
20
14
|
*/
|
|
21
|
-
run(
|
|
15
|
+
run(
|
|
16
|
+
compiler: Compiler,
|
|
17
|
+
options: Options,
|
|
18
|
+
wanted: string[],
|
|
19
|
+
exclude: string[]
|
|
20
|
+
): Promise<void>;
|
|
22
21
|
startTime: number;
|
|
23
22
|
prevTimestamps: Map<any, any>;
|
|
24
23
|
/**
|
|
@@ -33,3 +32,15 @@ declare class StylelintWebpackPlugin {
|
|
|
33
32
|
*/
|
|
34
33
|
getContext(compiler: Compiler): string;
|
|
35
34
|
}
|
|
35
|
+
declare namespace StylelintWebpackPlugin {
|
|
36
|
+
export { Compiler, Module, Options, FileSystemInfoEntry };
|
|
37
|
+
}
|
|
38
|
+
type Compiler = import('webpack').Compiler;
|
|
39
|
+
type Options = import('./options').Options;
|
|
40
|
+
type Module = import('webpack').Module;
|
|
41
|
+
type FileSystemInfoEntry = Partial<
|
|
42
|
+
| {
|
|
43
|
+
timestamp: number;
|
|
44
|
+
}
|
|
45
|
+
| number
|
|
46
|
+
>;
|
|
@@ -1,20 +1,44 @@
|
|
|
1
1
|
/// <reference types="stylelint" />
|
|
2
|
+
export = linter;
|
|
2
3
|
/**
|
|
3
4
|
* @param {string|undefined} key
|
|
4
5
|
* @param {Options} options
|
|
5
6
|
* @param {Compilation} compilation
|
|
6
|
-
* @returns {{lint: Linter, report: Reporter, threads: number}}
|
|
7
|
+
* @returns {{api: InternalApi, lint: Linter, report: Reporter, threads: number}}
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
declare function linter(
|
|
9
10
|
key: string | undefined,
|
|
10
11
|
options: Options,
|
|
11
12
|
compilation: Compilation
|
|
12
13
|
): {
|
|
14
|
+
api: InternalApi;
|
|
13
15
|
lint: Linter;
|
|
14
16
|
report: Reporter;
|
|
15
17
|
threads: number;
|
|
16
18
|
};
|
|
17
|
-
|
|
19
|
+
declare namespace linter {
|
|
20
|
+
export {
|
|
21
|
+
Stylelint,
|
|
22
|
+
LintResult,
|
|
23
|
+
InternalApi,
|
|
24
|
+
Compiler,
|
|
25
|
+
Compilation,
|
|
26
|
+
Options,
|
|
27
|
+
FormatterType,
|
|
28
|
+
FormatterFunction,
|
|
29
|
+
GenerateReport,
|
|
30
|
+
Report,
|
|
31
|
+
Reporter,
|
|
32
|
+
Linter,
|
|
33
|
+
LintResultMap,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
type Options = import('./options').Options;
|
|
37
|
+
type Compilation = import('webpack').Compilation;
|
|
38
|
+
type InternalApi = import('stylelint').InternalApi;
|
|
39
|
+
type Linter = (files: string | string[]) => void;
|
|
40
|
+
type Reporter = () => Promise<Report>;
|
|
41
|
+
type Stylelint = import('postcss').PluginCreator<
|
|
18
42
|
import('stylelint').PostcssPluginOptions
|
|
19
43
|
> & {
|
|
20
44
|
lint: (
|
|
@@ -36,6 +60,15 @@ export type Stylelint = import('postcss').PluginCreator<
|
|
|
36
60
|
createLinter: (
|
|
37
61
|
options: import('stylelint').LinterOptions
|
|
38
62
|
) => import('stylelint').InternalApi;
|
|
63
|
+
resolveConfig: (
|
|
64
|
+
filePath: string,
|
|
65
|
+
options?:
|
|
66
|
+
| Pick<
|
|
67
|
+
import('stylelint').LinterOptions,
|
|
68
|
+
'cwd' | 'config' | 'configFile' | 'configBasedir'
|
|
69
|
+
>
|
|
70
|
+
| undefined
|
|
71
|
+
) => Promise<import('stylelint').Config | undefined>;
|
|
39
72
|
utils: {
|
|
40
73
|
report: (problem: import('stylelint').Problem) => void;
|
|
41
74
|
ruleMessages: <
|
|
@@ -60,21 +93,17 @@ export type Stylelint = import('postcss').PluginCreator<
|
|
|
60
93
|
) => void;
|
|
61
94
|
};
|
|
62
95
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export type GenerateReport = (compilation: Compilation) => Promise<void>;
|
|
70
|
-
export type Report = {
|
|
96
|
+
type LintResult = import('stylelint').LintResult;
|
|
97
|
+
type Compiler = import('webpack').Compiler;
|
|
98
|
+
type FormatterType = import('./options').FormatterType;
|
|
99
|
+
type FormatterFunction = (results: LintResult[]) => string;
|
|
100
|
+
type GenerateReport = (compilation: Compilation) => Promise<void>;
|
|
101
|
+
type Report = {
|
|
71
102
|
errors?: StylelintError;
|
|
72
103
|
warnings?: StylelintError;
|
|
73
104
|
generateReportAsset?: GenerateReport;
|
|
74
105
|
};
|
|
75
|
-
|
|
76
|
-
export type Linter = (files: string | string[]) => void;
|
|
77
|
-
export type LintResultMap = {
|
|
106
|
+
type LintResultMap = {
|
|
78
107
|
[files: string]: import('stylelint').LintResult;
|
|
79
108
|
};
|
|
80
|
-
import StylelintError
|
|
109
|
+
import StylelintError = require('./StylelintError');
|
|
@@ -1,42 +1,4 @@
|
|
|
1
1
|
/// <reference types="stylelint" />
|
|
2
|
-
/** @typedef {import("stylelint")} stylelint */
|
|
3
|
-
/** @typedef {import("stylelint").LinterOptions} StylelintOptions */
|
|
4
|
-
/** @typedef {import("stylelint").FormatterType} FormatterType */
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {Object} OutputReport
|
|
7
|
-
* @property {string=} filePath
|
|
8
|
-
* @property {FormatterType=} formatter
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* @typedef {Object} PluginOptions
|
|
12
|
-
* @property {string} context
|
|
13
|
-
* @property {boolean} emitError
|
|
14
|
-
* @property {boolean} emitWarning
|
|
15
|
-
* @property {string|string[]=} exclude
|
|
16
|
-
* @property {string|string[]} extensions
|
|
17
|
-
* @property {boolean} failOnError
|
|
18
|
-
* @property {boolean} failOnWarning
|
|
19
|
-
* @property {string|string[]} files
|
|
20
|
-
* @property {FormatterType} formatter
|
|
21
|
-
* @property {boolean} lintDirtyModulesOnly
|
|
22
|
-
* @property {boolean} quiet
|
|
23
|
-
* @property {string} stylelintPath
|
|
24
|
-
* @property {OutputReport} outputReport
|
|
25
|
-
* @property {number|boolean=} threads
|
|
26
|
-
*/
|
|
27
|
-
/** @typedef {Partial<PluginOptions & StylelintOptions>} Options */
|
|
28
|
-
/**
|
|
29
|
-
* @param {Options} pluginOptions
|
|
30
|
-
* @returns {Partial<PluginOptions>}
|
|
31
|
-
*/
|
|
32
|
-
export function getOptions(pluginOptions: Options): Partial<PluginOptions>;
|
|
33
|
-
/**
|
|
34
|
-
* @param {Options} pluginOptions
|
|
35
|
-
* @returns {Partial<StylelintOptions>}
|
|
36
|
-
*/
|
|
37
|
-
export function getStylelintOptions(
|
|
38
|
-
pluginOptions: Options
|
|
39
|
-
): Partial<StylelintOptions>;
|
|
40
2
|
export type stylelint = import('postcss').PluginCreator<
|
|
41
3
|
import('stylelint').PostcssPluginOptions
|
|
42
4
|
> & {
|
|
@@ -59,6 +21,15 @@ export type stylelint = import('postcss').PluginCreator<
|
|
|
59
21
|
createLinter: (
|
|
60
22
|
options: import('stylelint').LinterOptions
|
|
61
23
|
) => import('stylelint').InternalApi;
|
|
24
|
+
resolveConfig: (
|
|
25
|
+
filePath: string,
|
|
26
|
+
options?:
|
|
27
|
+
| Pick<
|
|
28
|
+
import('stylelint').LinterOptions,
|
|
29
|
+
'cwd' | 'config' | 'configFile' | 'configBasedir'
|
|
30
|
+
>
|
|
31
|
+
| undefined
|
|
32
|
+
) => Promise<import('stylelint').Config | undefined>;
|
|
62
33
|
utils: {
|
|
63
34
|
report: (problem: import('stylelint').Problem) => void;
|
|
64
35
|
ruleMessages: <
|
|
@@ -106,3 +77,41 @@ export type PluginOptions = {
|
|
|
106
77
|
threads?: (number | boolean) | undefined;
|
|
107
78
|
};
|
|
108
79
|
export type Options = Partial<PluginOptions & StylelintOptions>;
|
|
80
|
+
/** @typedef {import("stylelint")} stylelint */
|
|
81
|
+
/** @typedef {import("stylelint").LinterOptions} StylelintOptions */
|
|
82
|
+
/** @typedef {import("stylelint").FormatterType} FormatterType */
|
|
83
|
+
/**
|
|
84
|
+
* @typedef {Object} OutputReport
|
|
85
|
+
* @property {string=} filePath
|
|
86
|
+
* @property {FormatterType=} formatter
|
|
87
|
+
*/
|
|
88
|
+
/**
|
|
89
|
+
* @typedef {Object} PluginOptions
|
|
90
|
+
* @property {string} context
|
|
91
|
+
* @property {boolean} emitError
|
|
92
|
+
* @property {boolean} emitWarning
|
|
93
|
+
* @property {string|string[]=} exclude
|
|
94
|
+
* @property {string|string[]} extensions
|
|
95
|
+
* @property {boolean} failOnError
|
|
96
|
+
* @property {boolean} failOnWarning
|
|
97
|
+
* @property {string|string[]} files
|
|
98
|
+
* @property {FormatterType} formatter
|
|
99
|
+
* @property {boolean} lintDirtyModulesOnly
|
|
100
|
+
* @property {boolean} quiet
|
|
101
|
+
* @property {string} stylelintPath
|
|
102
|
+
* @property {OutputReport} outputReport
|
|
103
|
+
* @property {number|boolean=} threads
|
|
104
|
+
*/
|
|
105
|
+
/** @typedef {Partial<PluginOptions & StylelintOptions>} Options */
|
|
106
|
+
/**
|
|
107
|
+
* @param {Options} pluginOptions
|
|
108
|
+
* @returns {Partial<PluginOptions>}
|
|
109
|
+
*/
|
|
110
|
+
export function getOptions(pluginOptions: Options): Partial<PluginOptions>;
|
|
111
|
+
/**
|
|
112
|
+
* @param {Options} pluginOptions
|
|
113
|
+
* @returns {Partial<StylelintOptions>}
|
|
114
|
+
*/
|
|
115
|
+
export function getStylelintOptions(
|
|
116
|
+
pluginOptions: Options
|
|
117
|
+
): Partial<StylelintOptions>;
|
|
@@ -39,4 +39,9 @@ export function parseFoldersToGlobs(
|
|
|
39
39
|
patterns: string | string[],
|
|
40
40
|
extensions?: string | string[]
|
|
41
41
|
): string[];
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param {string} _ key, but unused
|
|
45
|
+
* @param {any} value
|
|
46
|
+
*/
|
|
42
47
|
export function jsonStringifyReplacerSortKeys(_: string, value: any): any;
|
|
@@ -21,6 +21,15 @@ export type Stylelint = import('postcss').PluginCreator<
|
|
|
21
21
|
createLinter: (
|
|
22
22
|
options: import('stylelint').LinterOptions
|
|
23
23
|
) => import('stylelint').InternalApi;
|
|
24
|
+
resolveConfig: (
|
|
25
|
+
filePath: string,
|
|
26
|
+
options?:
|
|
27
|
+
| Pick<
|
|
28
|
+
import('stylelint').LinterOptions,
|
|
29
|
+
'cwd' | 'config' | 'configFile' | 'configBasedir'
|
|
30
|
+
>
|
|
31
|
+
| undefined
|
|
32
|
+
) => Promise<import('stylelint').Config | undefined>;
|
|
24
33
|
utils: {
|
|
25
34
|
report: (problem: import('stylelint').Problem) => void;
|
|
26
35
|
ruleMessages: <
|
package/declarations/cjs.d.ts
DELETED