stylelint-webpack-plugin 1.2.3 → 2.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 CHANGED
@@ -61,12 +61,26 @@ Specify the config file location to be used by `stylelint`.
61
61
 
62
62
  A string indicating the root of your files.
63
63
 
64
+ ### `exclude`
65
+
66
+ - Type: `String|Array[String]`
67
+ - Default: `'node_modules'`
68
+
69
+ Specify the files and/or directories to exclude. Must be relative to `options.context`.
70
+
71
+ ### `extensions`
72
+
73
+ - Type: `String|Array[String]`
74
+ - Default: `['css', 'scss', 'sass']`
75
+
76
+ Specify extensions that should be checked.
77
+
64
78
  ### `files`
65
79
 
66
80
  - Type: `String|Array[String]`
67
- - Default: `'**/*.s?(a|c)ss'`
81
+ - Default: `null`
68
82
 
69
- Specify the glob pattern for finding files. Must be relative to `options.context`.
83
+ 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`.
70
84
 
71
85
  ### `fix`
72
86
 
@@ -96,6 +110,13 @@ Lint only changed files, skip lint on start.
96
110
 
97
111
  Path to `stylelint` instance that will be used for linting.
98
112
 
113
+ ### `threads`
114
+
115
+ - Type: `Boolean | Number`
116
+ - Default: `false`
117
+
118
+ 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.
119
+
99
120
  ### Errors and Warning
100
121
 
101
122
  **By default the plugin will auto adjust error reporting depending on stylelint errors/warnings counts.**
@@ -106,21 +127,21 @@ You can still force this behavior by using `emitError` **or** `emitWarning` opti
106
127
  - Type: `Boolean`
107
128
  - Default: `false`
108
129
 
109
- Will always return errors, if set to `true`.
130
+ The errors found will always be emitted, to disable set to `false`.
110
131
 
111
132
  #### `emitWarning`
112
133
 
113
134
  - Type: `Boolean`
114
135
  - Default: `false`
115
136
 
116
- Will always return warnings, if set to `true`.
137
+ The warnings found will always be emitted, to disable set to `false`.
117
138
 
118
139
  #### `failOnError`
119
140
 
120
141
  - Type: `Boolean`
121
142
  - Default: `false`
122
143
 
123
- Will cause the module build to fail if there are any errors, if set to `true`.
144
+ Will cause the module build to fail if there are any errors, to disable set to `false`.
124
145
 
125
146
  #### `failOnWarning`
126
147
 
@@ -136,6 +157,22 @@ Will cause the module build to fail if there are any warnings, if set to `true`.
136
157
 
137
158
  Will process and report errors only and ignore warnings, if set to `true`.
138
159
 
160
+ #### `outputReport`
161
+
162
+ - Type: `Boolean|Object`
163
+ - Default: `false`
164
+
165
+ Write the output of the errors to a file, for example a `json` file for use for reporting.
166
+ The `filePath` is relative to the webpack config: `output.path`.
167
+ You can pass in a different formatter for the output file, if none is passed in the default/configured formatter will be used.
168
+
169
+ ```js
170
+ {
171
+ filePath: 'path/to/file';
172
+ formatter: 'json';
173
+ }
174
+ ```
175
+
139
176
  ## Changelog
140
177
 
141
178
  [Changelog](CHANGELOG.md)
@@ -150,8 +187,8 @@ Will process and report errors only and ignore warnings, if set to `true`.
150
187
  [node-url]: https://nodejs.org
151
188
  [deps]: https://david-dm.org/webpack-contrib/stylelint-webpack-plugin.svg
152
189
  [deps-url]: https://david-dm.org/webpack-contrib/stylelint-webpack-plugin
153
- [tests]: https://dev.azure.com/webpack-contrib/stylelint-webpack-plugin/_apis/build/status/webpack-contrib.stylelint-webpack-plugin?branchName=master
154
- [tests-url]: https://dev.azure.com/webpack-contrib/stylelint-webpack-plugin/_build/latest?definitionId=4&branchName=master
190
+ [tests]: https://github.com/webpack-contrib/stylelint-webpack-plugin/workflows/stylelint-webpack-plugin/badge.svg
191
+ [tests-url]: https://github.com/webpack-contrib/stylelint-webpack-plugin/actions
155
192
  [cover]: https://codecov.io/gh/webpack-contrib/stylelint-webpack-plugin/branch/master/graph/badge.svg
156
193
  [cover-url]: https://codecov.io/gh/webpack-contrib/stylelint-webpack-plugin
157
194
  [chat]: https://badges.gitter.im/webpack/webpack.svg
@@ -0,0 +1,2 @@
1
+ export default StylelintError;
2
+ declare class StylelintError extends Error {}
@@ -0,0 +1,3 @@
1
+ declare const _exports: typeof plugin.default;
2
+ export = _exports;
3
+ import plugin = require('./index');
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @param {string|undefined} key
3
+ * @param {Options} options
4
+ * @returns {Linter}
5
+ */
6
+ export default function getStylelint(
7
+ key: string | undefined,
8
+ { threads, ...options }: Options
9
+ ): Linter;
10
+ export type Stylelint = typeof import('stylelint');
11
+ export type LintResult = import('stylelint').LintResult;
12
+ export type Options = import('./options').Options;
13
+ export type AsyncTask = () => Promise<void>;
14
+ export type LintTask = (files: string | string[]) => Promise<LintResult[]>;
15
+ export type Worker = JestWorker & {
16
+ lintFiles: LintTask;
17
+ };
18
+ export type Linter = {
19
+ stylelint: Stylelint;
20
+ lintFiles: LintTask;
21
+ cleanup: AsyncTask;
22
+ threads: number;
23
+ };
24
+ import { Worker as JestWorker } from 'jest-worker';
@@ -0,0 +1,49 @@
1
+ export default StylelintWebpackPlugin;
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
+ >;
11
+ declare class StylelintWebpackPlugin {
12
+ /**
13
+ * @param {Options} options
14
+ */
15
+ constructor(options?: Options);
16
+ key: string;
17
+ options: Partial<import('./options').PluginOptions>;
18
+ /**
19
+ * @param {Compiler} compiler
20
+ */
21
+ run(compiler: Compiler): Promise<void>;
22
+ startTime: number;
23
+ prevTimestamps: Map<any, any>;
24
+ /**
25
+ * @param {Compiler} compiler
26
+ * @returns {void}
27
+ */
28
+ apply(compiler: Compiler): void;
29
+ /**
30
+ *
31
+ * @param {Compiler} compiler
32
+ * @returns {string}
33
+ */
34
+ getContext(compiler: Compiler): string;
35
+ /**
36
+ * @param {string[]} glob
37
+ * @param {Compiler} compiler
38
+ * @param {Module} module
39
+ * @returns {string[]}
40
+ */
41
+ getFiles(glob: string[], compiler: Compiler, module: Module): string[];
42
+ /**
43
+ * @param {Map<string, null | FileSystemInfoEntry | "ignore">} fileTimestamps
44
+ * @returns {string[]}
45
+ */
46
+ getChangedFiles(
47
+ fileTimestamps: Map<string, 'ignore' | FileSystemInfoEntry | null>
48
+ ): string[];
49
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @param {string|undefined} key
3
+ * @param {Options} options
4
+ * @param {Compilation} compilation
5
+ * @returns {{lint: Linter, report: Reporter, threads: number}}
6
+ */
7
+ export default function linter(
8
+ key: string | undefined,
9
+ options: Options,
10
+ compilation: Compilation
11
+ ): {
12
+ lint: Linter;
13
+ report: Reporter;
14
+ threads: number;
15
+ };
16
+ export type Stylelint = typeof import('stylelint');
17
+ export type LintResult = import('stylelint').LintResult;
18
+ export type Compiler = import('webpack').Compiler;
19
+ export type Compilation = import('webpack').Compilation;
20
+ export type Options = import('./options').Options;
21
+ export type FormatterType = import('./options').FormatterType;
22
+ export type FormatterFunction = (results: LintResult[]) => string;
23
+ export type GenerateReport = (compilation: Compilation) => Promise<void>;
24
+ export type Report = {
25
+ errors?: StylelintError;
26
+ warnings?: StylelintError;
27
+ generateReportAsset?: GenerateReport;
28
+ };
29
+ export type Reporter = () => Promise<Report>;
30
+ export type Linter = (files: string | string[]) => void;
31
+ export type LintResultMap = {
32
+ [files: string]: import('stylelint').LintResult;
33
+ };
34
+ import StylelintError from './StylelintError';
@@ -0,0 +1,62 @@
1
+ /** @typedef {import("stylelint")} stylelint */
2
+ /** @typedef {import("stylelint").LinterOptions} StylelintOptions */
3
+ /** @typedef {import("stylelint").FormatterType} FormatterType */
4
+ /**
5
+ * @typedef {Object} OutputReport
6
+ * @property {string=} filePath
7
+ * @property {FormatterType=} formatter
8
+ */
9
+ /**
10
+ * @typedef {Object} PluginOptions
11
+ * @property {string} context
12
+ * @property {boolean} emitError
13
+ * @property {boolean} emitWarning
14
+ * @property {string|string[]=} exclude
15
+ * @property {string|string[]} extensions
16
+ * @property {boolean} failOnError
17
+ * @property {boolean} failOnWarning
18
+ * @property {string|string[]} files
19
+ * @property {FormatterType} formatter
20
+ * @property {boolean} lintDirtyModulesOnly
21
+ * @property {boolean} quiet
22
+ * @property {string} stylelintPath
23
+ * @property {OutputReport} outputReport
24
+ * @property {number|boolean=} threads
25
+ */
26
+ /** @typedef {Partial<PluginOptions & StylelintOptions>} Options */
27
+ /**
28
+ * @param {Options} pluginOptions
29
+ * @returns {Partial<PluginOptions>}
30
+ */
31
+ export function getOptions(pluginOptions: Options): Partial<PluginOptions>;
32
+ /**
33
+ * @param {Options} pluginOptions
34
+ * @returns {Partial<StylelintOptions>}
35
+ */
36
+ export function getStylelintOptions(
37
+ pluginOptions: Options
38
+ ): Partial<StylelintOptions>;
39
+ export type stylelint = typeof import('stylelint');
40
+ export type StylelintOptions = import('stylelint').LinterOptions;
41
+ export type FormatterType = import('stylelint').FormatterType;
42
+ export type OutputReport = {
43
+ filePath?: string | undefined;
44
+ formatter?: FormatterType | undefined;
45
+ };
46
+ export type PluginOptions = {
47
+ context: string;
48
+ emitError: boolean;
49
+ emitWarning: boolean;
50
+ exclude?: (string | string[]) | undefined;
51
+ extensions: string | string[];
52
+ failOnError: boolean;
53
+ failOnWarning: boolean;
54
+ files: string | string[];
55
+ formatter: FormatterType;
56
+ lintDirtyModulesOnly: boolean;
57
+ quiet: boolean;
58
+ stylelintPath: string;
59
+ outputReport: OutputReport;
60
+ threads?: (number | boolean) | undefined;
61
+ };
62
+ export type Options = Partial<PluginOptions & StylelintOptions>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @param {string|string[]} files
3
+ * @param {string} context
4
+ * @returns {string[]}
5
+ */
6
+ export function parseFiles(files: string | string[], context: string): string[];
7
+ /**
8
+ * @param {string|string[]} patterns
9
+ * @param {string|string[]} extensions
10
+ * @returns {string[]}
11
+ */
12
+ export function parseFoldersToGlobs(
13
+ patterns: string | string[],
14
+ extensions?: string | string[]
15
+ ): string[];
16
+ export function jsonStringifyReplacerSortKeys(_: string, value: any): any;
@@ -0,0 +1,3 @@
1
+ export type Stylelint = typeof import('stylelint');
2
+ export type StylelintOptions = import('stylelint').LinterOptions;
3
+ export type Options = import('./options').Options;
@@ -6,18 +6,16 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
 
8
8
  class StylelintError extends Error {
9
+ /**
10
+ * @param {string=} messages
11
+ */
9
12
  constructor(messages) {
10
13
  super(messages);
11
14
  this.name = 'StylelintError';
12
- this.stack = false;
13
- }
14
-
15
- static format({
16
- formatter
17
- }, messages) {
18
- return new StylelintError(formatter(messages));
15
+ this.stack = '';
19
16
  }
20
17
 
21
18
  }
22
19
 
23
- exports.default = StylelintError;
20
+ var _default = StylelintError;
21
+ exports.default = _default;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = getStylelint;
7
+
8
+ var _os = require("os");
9
+
10
+ var _jestWorker = require("jest-worker");
11
+
12
+ var _worker = require("./worker");
13
+
14
+ var _utils = require("./utils");
15
+
16
+ var _options = require("./options");
17
+
18
+ // @ts-ignore
19
+
20
+ /** @type {{[key: string]: any}} */
21
+ const cache = {};
22
+ /** @typedef {import('stylelint')} Stylelint */
23
+
24
+ /** @typedef {import('stylelint').LintResult} LintResult */
25
+
26
+ /** @typedef {import('./options').Options} Options */
27
+
28
+ /** @typedef {() => Promise<void>} AsyncTask */
29
+
30
+ /** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */
31
+
32
+ /** @typedef {JestWorker & {lintFiles: LintTask}} Worker */
33
+
34
+ /** @typedef {{stylelint: Stylelint, lintFiles: LintTask, cleanup: AsyncTask, threads: number, }} Linter */
35
+
36
+ /**
37
+ * @param {Options} options
38
+ * @returns {Linter}
39
+ */
40
+
41
+ function loadStylelint(options) {
42
+ const stylelint = (0, _worker.setup)(options, (0, _options.getStylelintOptions)(options));
43
+ return {
44
+ stylelint,
45
+ lintFiles: _worker.lintFiles,
46
+ cleanup: async () => {},
47
+ threads: 1
48
+ };
49
+ }
50
+ /**
51
+ * @param {string|undefined} key
52
+ * @param {number} poolSize
53
+ * @param {Options} options
54
+ * @returns {Linter}
55
+ */
56
+
57
+
58
+ function loadStylelintThreaded(key, poolSize, options) {
59
+ const cacheKey = getCacheKey(key, options);
60
+
61
+ const source = require.resolve('./worker');
62
+
63
+ const workerOptions = {
64
+ enableWorkerThreads: true,
65
+ numWorkers: poolSize,
66
+ setupArgs: [options, (0, _options.getStylelintOptions)(options)]
67
+ };
68
+ const local = loadStylelint(options);
69
+ /** @type {Worker?} */
70
+ // prettier-ignore
71
+
72
+ let worker =
73
+ /** @type {Worker} */
74
+ new _jestWorker.Worker(source, workerOptions);
75
+ /** @type {Linter} */
76
+
77
+ const context = { ...local,
78
+ threads: poolSize,
79
+ lintFiles: async files =>
80
+ /* istanbul ignore next */
81
+ worker ? worker.lintFiles(files) : local.lintFiles(files),
82
+ cleanup: async () => {
83
+ cache[cacheKey] = local;
84
+
85
+ context.lintFiles = files => local.lintFiles(files);
86
+ /* istanbul ignore next */
87
+
88
+
89
+ if (worker) {
90
+ worker.end();
91
+ worker = null;
92
+ }
93
+ }
94
+ };
95
+ return context;
96
+ }
97
+ /**
98
+ * @param {string|undefined} key
99
+ * @param {Options} options
100
+ * @returns {Linter}
101
+ */
102
+
103
+
104
+ function getStylelint(key, {
105
+ threads,
106
+ ...options
107
+ }) {
108
+ const max = typeof threads !== 'number' ? threads ? (0, _os.cpus)().length - 1 : 1 : threads;
109
+ const cacheKey = getCacheKey(key, {
110
+ threads,
111
+ ...options
112
+ });
113
+
114
+ if (!cache[cacheKey]) {
115
+ cache[cacheKey] = max > 1 ? loadStylelintThreaded(key, max, options) : loadStylelint(options);
116
+ }
117
+
118
+ return cache[cacheKey];
119
+ }
120
+ /**
121
+ * @param {string|undefined} key
122
+ * @param {Options} options
123
+ * @returns {string}
124
+ */
125
+
126
+
127
+ function getCacheKey(key, options) {
128
+ return JSON.stringify({
129
+ key,
130
+ options
131
+ }, _utils.jsonStringifyReplacerSortKeys);
132
+ }