stylelint-webpack-plugin 2.3.2 → 3.1.1

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/dist/index.js CHANGED
@@ -7,8 +7,6 @@ exports.default = void 0;
7
7
 
8
8
  var _path = require("path");
9
9
 
10
- var _arrify = _interopRequireDefault(require("arrify"));
11
-
12
10
  var _globby = _interopRequireDefault(require("globby"));
13
11
 
14
12
  var _micromatch = require("micromatch");
@@ -21,7 +19,6 @@ var _utils = require("./utils");
21
19
 
22
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
21
 
24
- // @ts-ignore
25
22
  // @ts-ignore
26
23
 
27
24
  /** @typedef {import('webpack').Compiler} Compiler */
@@ -35,21 +32,19 @@ const STYLELINT_PLUGIN = 'StylelintWebpackPlugin';
35
32
  let counter = 0;
36
33
 
37
34
  class StylelintWebpackPlugin {
38
- /**
39
- * @param {Options} options
35
+ /**
36
+ * @param {Options} options
40
37
  */
41
38
  constructor(options = {}) {
42
39
  this.key = STYLELINT_PLUGIN;
43
40
  this.options = (0, _options.getOptions)(options);
44
41
  this.run = this.run.bind(this);
45
42
  this.startTime = Date.now();
46
- /** @type {ReadonlyMap<string, null | FileSystemInfoEntry | "ignore" | undefined>} */
47
-
48
43
  this.prevTimestamps = new Map();
49
44
  }
50
- /**
51
- * @param {Compiler} compiler
52
- * @returns {void}
45
+ /**
46
+ * @param {Compiler} compiler
47
+ * @returns {void}
53
48
  */
54
49
 
55
50
 
@@ -73,8 +68,8 @@ class StylelintWebpackPlugin {
73
68
  return this.run(c);
74
69
  });
75
70
  }
76
- /**
77
- * @param {Compiler} compiler
71
+ /**
72
+ * @param {Compiler} compiler
78
73
  */
79
74
 
80
75
 
@@ -90,9 +85,10 @@ class StylelintWebpackPlugin {
90
85
  }
91
86
 
92
87
  const context = this.getContext(compiler);
88
+ const excludeDefault = ['**/node_modules/**', String(compiler.options.output.path)];
93
89
  const options = { ...this.options,
94
- exclude: (0, _utils.parseFiles)(this.options.exclude || ['**/node_modules/**', compiler.options.output.path], context),
95
- extensions: (0, _arrify.default)(this.options.extensions),
90
+ exclude: (0, _utils.parseFiles)(this.options.exclude || excludeDefault, context),
91
+ extensions: (0, _utils.arrify)(this.options.extensions),
96
92
  files: (0, _utils.parseFiles)(this.options.files || '', context)
97
93
  };
98
94
  const wanted = (0, _utils.parseFoldersToGlobs)(options.files, options.extensions);
@@ -119,7 +115,14 @@ class StylelintWebpackPlugin {
119
115
  }
120
116
 
121
117
  compilation.hooks.finishModules.tap(this.key, () => {
122
- const files = this.getFiles(compiler, wanted, exclude);
118
+ const files = compiler.modifiedFiles ? Array.from(compiler.modifiedFiles).filter(file => (0, _micromatch.isMatch)(file, wanted, {
119
+ dot: true
120
+ }) && !(0, _micromatch.isMatch)(file, exclude, {
121
+ dot: true
122
+ })) : _globby.default.sync(wanted, {
123
+ dot: true,
124
+ ignore: exclude
125
+ });
123
126
 
124
127
  if (threads > 1) {
125
128
  for (const file of files) {
@@ -161,10 +164,10 @@ class StylelintWebpackPlugin {
161
164
  }
162
165
  });
163
166
  }
164
- /**
165
- *
166
- * @param {Compiler} compiler
167
- * @returns {string}
167
+ /**
168
+ *
169
+ * @param {Compiler} compiler
170
+ * @returns {string}
168
171
  */
169
172
 
170
173
 
@@ -179,88 +182,6 @@ class StylelintWebpackPlugin {
179
182
 
180
183
  return this.options.context;
181
184
  }
182
- /**
183
- * @param {Compiler} compiler
184
- * @param {string[]} wanted
185
- * @param {string[]} exclude
186
- * @returns {string[]}
187
- */
188
- // eslint-disable-next-line no-unused-vars
189
-
190
-
191
- getFiles(compiler, wanted, exclude) {
192
- // webpack 5
193
- if (compiler.modifiedFiles) {
194
- return Array.from(compiler.modifiedFiles).filter(file => (0, _micromatch.isMatch)(file, wanted, {
195
- dot: true
196
- }) && !(0, _micromatch.isMatch)(file, exclude, {
197
- dot: true
198
- }));
199
- } // webpack 4
200
-
201
- /* istanbul ignore next */
202
-
203
-
204
- if (compiler.fileTimestamps && compiler.fileTimestamps.size > 0) {
205
- return this.getChangedFiles(compiler.fileTimestamps).filter(file => (0, _micromatch.isMatch)(file, wanted, {
206
- dot: true
207
- }) && !(0, _micromatch.isMatch)(file, exclude, {
208
- dot: true
209
- }));
210
- }
211
-
212
- return _globby.default.sync(wanted, {
213
- dot: true,
214
- ignore: exclude
215
- });
216
- }
217
- /**
218
- * @param {ReadonlyMap<string, null | FileSystemInfoEntry | "ignore" | undefined>} fileTimestamps
219
- * @returns {string[]}
220
- */
221
-
222
- /* istanbul ignore next */
223
-
224
-
225
- getChangedFiles(fileTimestamps) {
226
- /**
227
- * @param {null | FileSystemInfoEntry | "ignore" | undefined} fileSystemInfoEntry
228
- * @returns {Partial<number>}
229
- */
230
- const getTimestamps = fileSystemInfoEntry => {
231
- // @ts-ignore
232
- if (fileSystemInfoEntry && fileSystemInfoEntry.timestamp) {
233
- // @ts-ignore
234
- return fileSystemInfoEntry.timestamp;
235
- } // @ts-ignore
236
-
237
-
238
- return fileSystemInfoEntry;
239
- };
240
- /**
241
- * @param {string} filename
242
- * @param {null | FileSystemInfoEntry | "ignore" | undefined} fileSystemInfoEntry
243
- * @returns {boolean}
244
- */
245
-
246
-
247
- const hasFileChanged = (filename, fileSystemInfoEntry) => {
248
- const prevTimestamp = getTimestamps(this.prevTimestamps.get(filename));
249
- const timestamp = getTimestamps(fileSystemInfoEntry);
250
- return (prevTimestamp || this.startTime) < (timestamp || Infinity);
251
- };
252
-
253
- const changedFiles = [];
254
-
255
- for (const [filename, timestamp] of fileTimestamps.entries()) {
256
- if (hasFileChanged(filename, timestamp)) {
257
- changedFiles.push(filename);
258
- }
259
- }
260
-
261
- this.prevTimestamps = fileTimestamps;
262
- return changedFiles;
263
- }
264
185
 
265
186
  }
266
187
 
package/dist/linter.js CHANGED
@@ -7,15 +7,13 @@ exports.default = linter;
7
7
 
8
8
  var _path = require("path");
9
9
 
10
- var _arrify = _interopRequireDefault(require("arrify"));
11
-
12
10
  var _StylelintError = _interopRequireDefault(require("./StylelintError"));
13
11
 
14
12
  var _getStylelint = _interopRequireDefault(require("./getStylelint"));
15
13
 
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ var _utils = require("./utils");
17
15
 
18
- // @ts-ignore
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
17
 
20
18
  /** @typedef {import('stylelint')} Stylelint */
21
19
 
@@ -43,11 +41,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
43
41
 
44
42
  /** @type {WeakMap<Compiler, LintResultMap>} */
45
43
  const resultStorage = new WeakMap();
46
- /**
47
- * @param {string|undefined} key
48
- * @param {Options} options
49
- * @param {Compilation} compilation
50
- * @returns {{lint: Linter, report: Reporter, threads: number}}
44
+ /**
45
+ * @param {string|undefined} key
46
+ * @param {Options} options
47
+ * @param {Compilation} compilation
48
+ * @returns {{lint: Linter, report: Reporter, threads: number}}
51
49
  */
52
50
 
53
51
  function linter(key, options, compilation) {
@@ -83,12 +81,12 @@ function linter(key, options, compilation) {
83
81
  report,
84
82
  threads
85
83
  };
86
- /**
87
- * @param {string | string[]} files
84
+ /**
85
+ * @param {string | string[]} files
88
86
  */
89
87
 
90
88
  function lint(files) {
91
- for (const file of (0, _arrify.default)(files)) {
89
+ for (const file of (0, _utils.arrify)(files)) {
92
90
  delete crossRunResultStorage[file];
93
91
  }
94
92
 
@@ -124,9 +122,9 @@ function linter(key, options, compilation) {
124
122
  warnings,
125
123
  generateReportAsset
126
124
  };
127
- /**
128
- * @param {Compilation} compilation
129
- * @returns {Promise<void>}
125
+ /**
126
+ * @param {Compilation} compilation
127
+ * @returns {Promise<void>}
130
128
  */
131
129
 
132
130
  async function generateReportAsset({
@@ -135,9 +133,9 @@ function linter(key, options, compilation) {
135
133
  const {
136
134
  outputReport
137
135
  } = options;
138
- /**
139
- * @param {string} name
140
- * @param {string | Buffer} content
136
+ /**
137
+ * @param {string} name
138
+ * @param {string | Buffer} content
141
139
  */
142
140
 
143
141
  const save = (name, content) =>
@@ -177,10 +175,10 @@ function linter(key, options, compilation) {
177
175
  }
178
176
  }
179
177
  }
180
- /**
181
- * @param {FormatterFunction} formatter
182
- * @param {{ errors: LintResult[]; warnings: LintResult[]; }} results
183
- * @returns {{errors?: StylelintError, warnings?: StylelintError}}
178
+ /**
179
+ * @param {FormatterFunction} formatter
180
+ * @param {{ errors: LintResult[]; warnings: LintResult[]; }} results
181
+ * @returns {{errors?: StylelintError, warnings?: StylelintError}}
184
182
  */
185
183
 
186
184
 
@@ -201,10 +199,10 @@ function formatResults(formatter, results) {
201
199
  warnings
202
200
  };
203
201
  }
204
- /**
205
- * @param {Options} options
206
- * @param {LintResult[]} results
207
- * @returns {{errors: LintResult[], warnings: LintResult[]}}
202
+ /**
203
+ * @param {Options} options
204
+ * @param {LintResult[]} results
205
+ * @returns {{errors: LintResult[], warnings: LintResult[]}}
208
206
  */
209
207
 
210
208
 
@@ -236,10 +234,10 @@ function parseResults(options, results) {
236
234
  warnings
237
235
  };
238
236
  }
239
- /**
240
- * @param {Stylelint} stylelint
241
- * @param {FormatterType=} formatter
242
- * @returns {FormatterFunction}
237
+ /**
238
+ * @param {Stylelint} stylelint
239
+ * @param {FormatterType=} formatter
240
+ * @returns {FormatterFunction}
243
241
  */
244
242
 
245
243
 
@@ -257,33 +255,33 @@ function loadFormatter(stylelint, formatter) {
257
255
 
258
256
  return stylelint.formatters.string;
259
257
  }
260
- /**
261
- * @param {LintResult[]} results
262
- * @returns {LintResult[]}
258
+ /**
259
+ * @param {LintResult[]} results
260
+ * @returns {LintResult[]}
263
261
  */
264
262
 
265
263
 
266
264
  function removeIgnoredWarnings(results) {
267
265
  return results.filter(result => !result.ignored);
268
266
  }
269
- /**
270
- * @param {Promise<LintResult[]>[]} results
271
- * @returns {Promise<LintResult[]>}
267
+ /**
268
+ * @param {Promise<LintResult[]>[]} results
269
+ * @returns {Promise<LintResult[]>}
272
270
  */
273
271
 
274
272
 
275
273
  async function flatten(results) {
276
- /**
277
- * @param {LintResult[]} acc
278
- * @param {LintResult[]} list
274
+ /**
275
+ * @param {LintResult[]} acc
276
+ * @param {LintResult[]} list
279
277
  */
280
278
  const flat = (acc, list) => [...acc, ...list];
281
279
 
282
280
  return (await Promise.all(results)).reduce(flat, []);
283
281
  }
284
- /**
285
- * @param {Compilation} compilation
286
- * @returns {LintResultMap}
282
+ /**
283
+ * @param {Compilation} compilation
284
+ * @returns {LintResultMap}
287
285
  */
288
286
 
289
287
 
package/dist/options.js CHANGED
@@ -20,35 +20,35 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
20
20
 
21
21
  /** @typedef {import("stylelint").FormatterType} FormatterType */
22
22
 
23
- /**
24
- * @typedef {Object} OutputReport
25
- * @property {string=} filePath
26
- * @property {FormatterType=} formatter
23
+ /**
24
+ * @typedef {Object} OutputReport
25
+ * @property {string=} filePath
26
+ * @property {FormatterType=} formatter
27
27
  */
28
28
 
29
- /**
30
- * @typedef {Object} PluginOptions
31
- * @property {string} context
32
- * @property {boolean} emitError
33
- * @property {boolean} emitWarning
34
- * @property {string|string[]=} exclude
35
- * @property {string|string[]} extensions
36
- * @property {boolean} failOnError
37
- * @property {boolean} failOnWarning
38
- * @property {string|string[]} files
39
- * @property {FormatterType} formatter
40
- * @property {boolean} lintDirtyModulesOnly
41
- * @property {boolean} quiet
42
- * @property {string} stylelintPath
43
- * @property {OutputReport} outputReport
44
- * @property {number|boolean=} threads
29
+ /**
30
+ * @typedef {Object} PluginOptions
31
+ * @property {string} context
32
+ * @property {boolean} emitError
33
+ * @property {boolean} emitWarning
34
+ * @property {string|string[]=} exclude
35
+ * @property {string|string[]} extensions
36
+ * @property {boolean} failOnError
37
+ * @property {boolean} failOnWarning
38
+ * @property {string|string[]} files
39
+ * @property {FormatterType} formatter
40
+ * @property {boolean} lintDirtyModulesOnly
41
+ * @property {boolean} quiet
42
+ * @property {string} stylelintPath
43
+ * @property {OutputReport} outputReport
44
+ * @property {number|boolean=} threads
45
45
  */
46
46
 
47
47
  /** @typedef {Partial<PluginOptions & StylelintOptions>} Options */
48
48
 
49
- /**
50
- * @param {Options} pluginOptions
51
- * @returns {Partial<PluginOptions>}
49
+ /**
50
+ * @param {Options} pluginOptions
51
+ * @returns {Partial<PluginOptions>}
52
52
  */
53
53
  function getOptions(pluginOptions) {
54
54
  const options = {
@@ -69,9 +69,9 @@ function getOptions(pluginOptions) {
69
69
  });
70
70
  return options;
71
71
  }
72
- /**
73
- * @param {Options} pluginOptions
74
- * @returns {Partial<StylelintOptions>}
72
+ /**
73
+ * @param {Options} pluginOptions
74
+ * @returns {Partial<StylelintOptions>}
75
75
  */
76
76
 
77
77
 
package/dist/options.json CHANGED
@@ -1,80 +1,80 @@
1
- {
2
- "type": "object",
3
- "additionalProperties": true,
4
- "properties": {
5
- "context": {
6
- "description": "A string indicating the root of your files.",
7
- "type": "string"
8
- },
9
- "emitError": {
10
- "description": "The errors found will always be emitted, to disable set to `false`.",
11
- "type": "boolean"
12
- },
13
- "emitWarning": {
14
- "description": "The warnings found will always be emitted, to disable set to `false`.",
15
- "type": "boolean"
16
- },
17
- "exclude": {
18
- "description": "Specify the files and/or directories to exclude. Must be relative to `options.context`.",
19
- "anyOf": [{ "type": "string" }, { "type": "array" }]
20
- },
21
- "extensions": {
22
- "description": "Specify extensions that should be checked.",
23
- "anyOf": [{ "type": "string" }, { "type": "array" }]
24
- },
25
- "failOnError": {
26
- "description": "Will cause the module build to fail if there are any errors, to disable set to `false`.",
27
- "type": "boolean"
28
- },
29
- "failOnWarning": {
30
- "description": "Will cause the module build to fail if there are any warnings, if set to `true`.",
31
- "type": "boolean"
32
- },
33
- "files": {
34
- "description": "Specify directories, files, or globs. Must be relative to `options.context`. Directories are traveresed recursively looking for files matching `options.extensions`. File and glob patterns ignore `options.extensions`.",
35
- "anyOf": [{ "type": "string" }, { "type": "array" }]
36
- },
37
- "formatter": {
38
- "description": "Specify the formatter that you would like to use to format your results.",
39
- "anyOf": [{ "type": "string" }, { "instanceof": "Function" }]
40
- },
41
- "lintDirtyModulesOnly": {
42
- "description": "Lint only changed files, skip lint on start.",
43
- "type": "boolean"
44
- },
45
- "quiet": {
46
- "description": "Will process and report errors only and ignore warnings, if set to `true`.",
47
- "type": "boolean"
48
- },
49
- "stylelintPath": {
50
- "description": "Path to `stylelint` instance that will be used for linting.",
51
- "type": "string"
52
- },
53
- "outputReport": {
54
- "description": "Write the output of the errors to a file, for example a `json` file for use for reporting.",
55
- "anyOf": [
56
- {
57
- "type": "boolean"
58
- },
59
- {
60
- "type": "object",
61
- "additionalProperties": false,
62
- "properties": {
63
- "filePath": {
64
- "description": "The `filePath` is relative to the webpack config: `output.path`.",
65
- "anyOf": [{ "type": "string" }]
66
- },
67
- "formatter": {
68
- "description": "You can pass in a different formatter for the output file, if none is passed in the default/configured formatter will be used.",
69
- "anyOf": [{ "type": "string" }, { "instanceof": "Function" }]
70
- }
71
- }
72
- }
73
- ]
74
- },
75
- "threads": {
76
- "description": "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.",
77
- "anyOf": [{ "type": "number" }, { "type": "boolean" }]
78
- }
79
- }
80
- }
1
+ {
2
+ "type": "object",
3
+ "additionalProperties": true,
4
+ "properties": {
5
+ "context": {
6
+ "description": "A string indicating the root of your files.",
7
+ "type": "string"
8
+ },
9
+ "emitError": {
10
+ "description": "The errors found will always be emitted, to disable set to `false`.",
11
+ "type": "boolean"
12
+ },
13
+ "emitWarning": {
14
+ "description": "The warnings found will always be emitted, to disable set to `false`.",
15
+ "type": "boolean"
16
+ },
17
+ "exclude": {
18
+ "description": "Specify the files and/or directories to exclude. Must be relative to `options.context`.",
19
+ "anyOf": [{ "type": "string" }, { "type": "array" }]
20
+ },
21
+ "extensions": {
22
+ "description": "Specify extensions that should be checked.",
23
+ "anyOf": [{ "type": "string" }, { "type": "array" }]
24
+ },
25
+ "failOnError": {
26
+ "description": "Will cause the module build to fail if there are any errors, to disable set to `false`.",
27
+ "type": "boolean"
28
+ },
29
+ "failOnWarning": {
30
+ "description": "Will cause the module build to fail if there are any warnings, if set to `true`.",
31
+ "type": "boolean"
32
+ },
33
+ "files": {
34
+ "description": "Specify directories, files, or globs. Must be relative to `options.context`. Directories are traveresed recursively looking for files matching `options.extensions`. File and glob patterns ignore `options.extensions`.",
35
+ "anyOf": [{ "type": "string" }, { "type": "array" }]
36
+ },
37
+ "formatter": {
38
+ "description": "Specify the formatter that you would like to use to format your results.",
39
+ "anyOf": [{ "type": "string" }, { "instanceof": "Function" }]
40
+ },
41
+ "lintDirtyModulesOnly": {
42
+ "description": "Lint only changed files, skip lint on start.",
43
+ "type": "boolean"
44
+ },
45
+ "quiet": {
46
+ "description": "Will process and report errors only and ignore warnings, if set to `true`.",
47
+ "type": "boolean"
48
+ },
49
+ "stylelintPath": {
50
+ "description": "Path to `stylelint` instance that will be used for linting.",
51
+ "type": "string"
52
+ },
53
+ "outputReport": {
54
+ "description": "Write the output of the errors to a file, for example a `json` file for use for reporting.",
55
+ "anyOf": [
56
+ {
57
+ "type": "boolean"
58
+ },
59
+ {
60
+ "type": "object",
61
+ "additionalProperties": false,
62
+ "properties": {
63
+ "filePath": {
64
+ "description": "The `filePath` is relative to the webpack config: `output.path`.",
65
+ "anyOf": [{ "type": "string" }]
66
+ },
67
+ "formatter": {
68
+ "description": "You can pass in a different formatter for the output file, if none is passed in the default/configured formatter will be used.",
69
+ "anyOf": [{ "type": "string" }, { "instanceof": "Function" }]
70
+ }
71
+ }
72
+ }
73
+ ]
74
+ },
75
+ "threads": {
76
+ "description": "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.",
77
+ "anyOf": [{ "type": "number" }, { "type": "boolean" }]
78
+ }
79
+ }
80
+ }