stylelint-webpack-plugin 1.2.2 → 2.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/CHANGELOG.md +38 -0
- package/README.md +2 -2
- package/declarations/LintDirtyModulesPlugin.d.ts +64 -0
- package/declarations/StylelintError.d.ts +30 -0
- package/declarations/cjs.d.ts +2 -0
- package/declarations/getOptions.d.ts +32 -0
- package/declarations/index.d.ts +18 -0
- package/declarations/linter.d.ts +47 -0
- package/declarations/utils.d.ts +14 -0
- package/dist/LintDirtyModulesPlugin.js +54 -7
- package/dist/StylelintError.js +14 -1
- package/dist/getOptions.js +34 -5
- package/dist/index.js +30 -14
- package/dist/linter.js +56 -8
- package/dist/utils.js +31 -0
- package/package.json +53 -40
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,44 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [2.1.1](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.2.3...v2.1.1) (2020-10-14)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* support typescript ([#213](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/213)) ([b7dfa19](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/b7dfa195b7836bad7ac94a64a0c0a6163021a3e7))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* avoiding https://github.com/mrmlnc/fast-glob/issues/158 ([#209](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/209)) ([14ae30d](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/14ae30df8a6d6b629c4e1fa647b4c6989377aec8))
|
|
16
|
+
* use better micromatch extglobs ([#216](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/216)) ([a70ed3d](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/a70ed3d6b6d8da90bf4dc371057cbe1433b4558d))
|
|
17
|
+
|
|
18
|
+
## [2.1.0](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.2.3...v2.1.0) (2020-06-17)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* support typescript ([#213](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/213)) ([b7dfa19](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/b7dfa195b7836bad7ac94a64a0c0a6163021a3e7))
|
|
24
|
+
|
|
25
|
+
## [2.0.0](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.2.3...v2.0.0) (2020-05-04)
|
|
26
|
+
|
|
27
|
+
### ⚠ BREAKING CHANGES
|
|
28
|
+
|
|
29
|
+
* minimum supported Node.js version is `10.13`
|
|
30
|
+
* minimum supported stylelint version is `13.0.0`
|
|
31
|
+
|
|
32
|
+
### Bug Fixes
|
|
33
|
+
|
|
34
|
+
* avoiding https://github.com/mrmlnc/fast-glob/issues/158 ([#209](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/209)) ([14ae30d](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/14ae30df8a6d6b629c4e1fa647b4c6989377aec8))
|
|
35
|
+
|
|
36
|
+
### [1.2.3](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.2.2...v1.2.3) (2020-02-08)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Performance
|
|
40
|
+
|
|
41
|
+
* require lint of stylelint only one time ([#207](https://github.com/webpack-contrib/stylelint-webpack-plugin/issues/207)) ([7e2495e](https://github.com/webpack-contrib/stylelint-webpack-plugin/commit/7e2495e6ba4d8cebb7f07cc9418020ea494670f8))
|
|
42
|
+
|
|
5
43
|
### [1.2.2](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.2.1...v1.2.2) (2020-02-08)
|
|
6
44
|
|
|
7
45
|
|
package/README.md
CHANGED
|
@@ -150,8 +150,8 @@ Will process and report errors only and ignore warnings, if set to `true`.
|
|
|
150
150
|
[node-url]: https://nodejs.org
|
|
151
151
|
[deps]: https://david-dm.org/webpack-contrib/stylelint-webpack-plugin.svg
|
|
152
152
|
[deps-url]: https://david-dm.org/webpack-contrib/stylelint-webpack-plugin
|
|
153
|
-
[tests]: https://
|
|
154
|
-
[tests-url]: https://
|
|
153
|
+
[tests]: https://github.com/webpack-contrib/stylelint-webpack-plugin/workflows/stylelint-webpack-plugin/badge.svg
|
|
154
|
+
[tests-url]: https://github.com/webpack-contrib/stylelint-webpack-plugin/actions
|
|
155
155
|
[cover]: https://codecov.io/gh/webpack-contrib/stylelint-webpack-plugin/branch/master/graph/badge.svg
|
|
156
156
|
[cover-url]: https://codecov.io/gh/webpack-contrib/stylelint-webpack-plugin
|
|
157
157
|
[chat]: https://badges.gitter.im/webpack/webpack.svg
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** @typedef {import('webpack').Compiler} Compiler */
|
|
2
|
+
/** @typedef {import('./getOptions').Options} Options */
|
|
3
|
+
/** @typedef {import('./linter').Lint} Lint */
|
|
4
|
+
/** @typedef {import('./linter').LinterCallback} LinterCallback */
|
|
5
|
+
/** @typedef {Partial<{timestamp:number} | number>} FileSystemInfoEntry */
|
|
6
|
+
export default class LintDirtyModulesPlugin {
|
|
7
|
+
/**
|
|
8
|
+
* @param {Lint} lint
|
|
9
|
+
* @param {Compiler} compiler
|
|
10
|
+
* @param {Options} options
|
|
11
|
+
*/
|
|
12
|
+
constructor(lint: Lint, compiler: Compiler, options: Options);
|
|
13
|
+
lint: import('./linter').Lint;
|
|
14
|
+
compiler: import('webpack').Compiler;
|
|
15
|
+
options: import('./getOptions').Options;
|
|
16
|
+
startTime: number;
|
|
17
|
+
prevTimestamps: Map<any, any>;
|
|
18
|
+
isFirstRun: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* @param {Compiler} compilation
|
|
21
|
+
* @param {LinterCallback} callback
|
|
22
|
+
* @returns {void}
|
|
23
|
+
*/
|
|
24
|
+
apply(compilation: Compiler, callback: LinterCallback): void;
|
|
25
|
+
/**
|
|
26
|
+
* @param {Map<string, number|FileSystemInfoEntry>} fileTimestamps
|
|
27
|
+
* @param {string | ReadonlyArray<string>} glob
|
|
28
|
+
* @returns {Array<string>}
|
|
29
|
+
*/
|
|
30
|
+
getChangedFiles(
|
|
31
|
+
fileTimestamps: Map<
|
|
32
|
+
string,
|
|
33
|
+
| number
|
|
34
|
+
| Partial<{
|
|
35
|
+
timestamp: number;
|
|
36
|
+
}>
|
|
37
|
+
>,
|
|
38
|
+
glob: string | ReadonlyArray<string>
|
|
39
|
+
): Array<string>;
|
|
40
|
+
}
|
|
41
|
+
export type Compiler = import('webpack').Compiler;
|
|
42
|
+
export type Options = {
|
|
43
|
+
context?: string | undefined;
|
|
44
|
+
emitError?: boolean | undefined;
|
|
45
|
+
emitWarning?: boolean | undefined;
|
|
46
|
+
failOnError?: boolean | undefined;
|
|
47
|
+
failOnWarning?: boolean | undefined;
|
|
48
|
+
files: string | string[];
|
|
49
|
+
formatter: TimerHandler;
|
|
50
|
+
lintDirtyModulesOnly?: boolean | undefined;
|
|
51
|
+
quiet?: boolean | undefined;
|
|
52
|
+
stylelintPath: string;
|
|
53
|
+
};
|
|
54
|
+
export type Lint = (
|
|
55
|
+
options: import('./getOptions').Options
|
|
56
|
+
) => Promise<import('stylelint').LinterResult>;
|
|
57
|
+
export type LinterCallback = (
|
|
58
|
+
error?: import('./StylelintError').default | null | undefined
|
|
59
|
+
) => void;
|
|
60
|
+
export type FileSystemInfoEntry =
|
|
61
|
+
| number
|
|
62
|
+
| Partial<{
|
|
63
|
+
timestamp: number;
|
|
64
|
+
}>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** @typedef {import('stylelint').LintResult} LintResult */
|
|
2
|
+
/** @typedef {import('./getOptions').Options} Options */
|
|
3
|
+
export default class StylelintError extends Error {
|
|
4
|
+
/**
|
|
5
|
+
* @param {Options} options
|
|
6
|
+
* @param {Array<LintResult>} messages
|
|
7
|
+
* @returns {StylelintError}
|
|
8
|
+
*/
|
|
9
|
+
static format(
|
|
10
|
+
{ formatter }: Options,
|
|
11
|
+
messages: Array<LintResult>
|
|
12
|
+
): StylelintError;
|
|
13
|
+
/**
|
|
14
|
+
* @param {Partial<string>} messages
|
|
15
|
+
*/
|
|
16
|
+
constructor(messages: Partial<string>);
|
|
17
|
+
}
|
|
18
|
+
export type LintResult = import('stylelint').LintResult;
|
|
19
|
+
export type Options = {
|
|
20
|
+
context?: string | undefined;
|
|
21
|
+
emitError?: boolean | undefined;
|
|
22
|
+
emitWarning?: boolean | undefined;
|
|
23
|
+
failOnError?: boolean | undefined;
|
|
24
|
+
failOnWarning?: boolean | undefined;
|
|
25
|
+
files: string | string[];
|
|
26
|
+
formatter: TimerHandler;
|
|
27
|
+
lintDirtyModulesOnly?: boolean | undefined;
|
|
28
|
+
quiet?: boolean | undefined;
|
|
29
|
+
stylelintPath: string;
|
|
30
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** @typedef {import("stylelint")} stylelint */
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {Object} Options
|
|
4
|
+
* @property {string=} context
|
|
5
|
+
* @property {boolean=} emitError
|
|
6
|
+
* @property {boolean=} emitWarning
|
|
7
|
+
* @property {boolean=} failOnError
|
|
8
|
+
* @property {boolean=} failOnWarning
|
|
9
|
+
* @property {Array<string> | string} files
|
|
10
|
+
* @property {Function | string} formatter
|
|
11
|
+
* @property {boolean=} lintDirtyModulesOnly
|
|
12
|
+
* @property {boolean=} quiet
|
|
13
|
+
* @property {string} stylelintPath
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @param {Partial<Options>} pluginOptions
|
|
17
|
+
* @returns {Options}
|
|
18
|
+
*/
|
|
19
|
+
export default function getOptions(pluginOptions: Partial<Options>): Options;
|
|
20
|
+
export type stylelint = typeof import('stylelint');
|
|
21
|
+
export type Options = {
|
|
22
|
+
context?: string | undefined;
|
|
23
|
+
emitError?: boolean | undefined;
|
|
24
|
+
emitWarning?: boolean | undefined;
|
|
25
|
+
failOnError?: boolean | undefined;
|
|
26
|
+
failOnWarning?: boolean | undefined;
|
|
27
|
+
files: Array<string> | string;
|
|
28
|
+
formatter: Function | string;
|
|
29
|
+
lintDirtyModulesOnly?: boolean | undefined;
|
|
30
|
+
quiet?: boolean | undefined;
|
|
31
|
+
stylelintPath: string;
|
|
32
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default StylelintWebpackPlugin;
|
|
2
|
+
export type Compiler = import('webpack').Compiler;
|
|
3
|
+
/** @typedef {import('webpack').Compiler} Compiler */
|
|
4
|
+
declare class StylelintWebpackPlugin {
|
|
5
|
+
constructor(options?: {});
|
|
6
|
+
options: import('./getOptions').Options;
|
|
7
|
+
/**
|
|
8
|
+
* @param {Compiler} compiler
|
|
9
|
+
* @returns {void}
|
|
10
|
+
*/
|
|
11
|
+
apply(compiler: Compiler): void;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {Compiler} compiler
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
getContext(compiler: Compiler): string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** @typedef {import('stylelint').LinterResult} LinterResult */
|
|
2
|
+
/** @typedef {import('stylelint').LintResult} LintResult */
|
|
3
|
+
/** @typedef {import('webpack').Compiler} Compiler */
|
|
4
|
+
/** @typedef {import('./getOptions').Options} Options */
|
|
5
|
+
/**
|
|
6
|
+
* @callback Lint
|
|
7
|
+
* @param {Options} options
|
|
8
|
+
* @returns {Promise<LinterResult>}
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @callback LinterCallback
|
|
12
|
+
* @param {StylelintError | null=} error
|
|
13
|
+
* @returns {void}
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @param {Lint} lint
|
|
17
|
+
* @param {Options} options
|
|
18
|
+
* @param {Compiler} compiler
|
|
19
|
+
* @param {LinterCallback} callback
|
|
20
|
+
* @returns {void}
|
|
21
|
+
*/
|
|
22
|
+
export default function linter(
|
|
23
|
+
lint: Lint,
|
|
24
|
+
options: Options,
|
|
25
|
+
compiler: Compiler,
|
|
26
|
+
callback: LinterCallback
|
|
27
|
+
): void;
|
|
28
|
+
export type LinterResult = import('stylelint').LinterResult;
|
|
29
|
+
export type LintResult = import('stylelint').LintResult;
|
|
30
|
+
export type Compiler = import('webpack').Compiler;
|
|
31
|
+
export type Options = {
|
|
32
|
+
context?: string | undefined;
|
|
33
|
+
emitError?: boolean | undefined;
|
|
34
|
+
emitWarning?: boolean | undefined;
|
|
35
|
+
failOnError?: boolean | undefined;
|
|
36
|
+
failOnWarning?: boolean | undefined;
|
|
37
|
+
files: string | string[];
|
|
38
|
+
formatter: TimerHandler;
|
|
39
|
+
lintDirtyModulesOnly?: boolean | undefined;
|
|
40
|
+
quiet?: boolean | undefined;
|
|
41
|
+
stylelintPath: string;
|
|
42
|
+
};
|
|
43
|
+
export type Lint = (options: Options) => Promise<LinterResult>;
|
|
44
|
+
export type LinterCallback = (
|
|
45
|
+
error?: (StylelintError | null) | undefined
|
|
46
|
+
) => void;
|
|
47
|
+
import StylelintError from './StylelintError';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Array<string> | string} files
|
|
3
|
+
* @param {string} context
|
|
4
|
+
* @returns {Array<string>}
|
|
5
|
+
*/
|
|
6
|
+
export function parseFiles(
|
|
7
|
+
files: Array<string> | string,
|
|
8
|
+
context: string
|
|
9
|
+
): Array<string>;
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} str
|
|
12
|
+
* @returns {string}
|
|
13
|
+
*/
|
|
14
|
+
export function replaceBackslashes(str: string): string;
|
|
@@ -9,16 +9,39 @@ var _micromatch = require("micromatch");
|
|
|
9
9
|
|
|
10
10
|
var _linter = _interopRequireDefault(require("./linter"));
|
|
11
11
|
|
|
12
|
+
var _utils = require("./utils");
|
|
13
|
+
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
15
|
|
|
16
|
+
/** @typedef {import('webpack').Compiler} Compiler */
|
|
17
|
+
|
|
18
|
+
/** @typedef {import('./getOptions').Options} Options */
|
|
19
|
+
|
|
20
|
+
/** @typedef {import('./linter').Lint} Lint */
|
|
21
|
+
|
|
22
|
+
/** @typedef {import('./linter').LinterCallback} LinterCallback */
|
|
23
|
+
|
|
24
|
+
/** @typedef {Partial<{timestamp:number} | number>} FileSystemInfoEntry */
|
|
14
25
|
class LintDirtyModulesPlugin {
|
|
15
|
-
|
|
26
|
+
/**
|
|
27
|
+
* @param {Lint} lint
|
|
28
|
+
* @param {Compiler} compiler
|
|
29
|
+
* @param {Options} options
|
|
30
|
+
*/
|
|
31
|
+
constructor(lint, compiler, options) {
|
|
32
|
+
this.lint = lint;
|
|
16
33
|
this.compiler = compiler;
|
|
17
34
|
this.options = options;
|
|
18
35
|
this.startTime = Date.now();
|
|
19
|
-
this.prevTimestamps =
|
|
36
|
+
this.prevTimestamps = new Map();
|
|
20
37
|
this.isFirstRun = true;
|
|
21
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* @param {Compiler} compilation
|
|
41
|
+
* @param {LinterCallback} callback
|
|
42
|
+
* @returns {void}
|
|
43
|
+
*/
|
|
44
|
+
|
|
22
45
|
|
|
23
46
|
apply(compilation, callback) {
|
|
24
47
|
const fileTimestamps = compilation.fileTimestamps || new Map();
|
|
@@ -31,23 +54,47 @@ class LintDirtyModulesPlugin {
|
|
|
31
54
|
}
|
|
32
55
|
|
|
33
56
|
const dirtyOptions = { ...this.options
|
|
34
|
-
};
|
|
35
|
-
|
|
57
|
+
}; // @ts-ignore
|
|
58
|
+
|
|
59
|
+
const glob = (0, _utils.replaceBackslashes)(dirtyOptions.files.join('|'));
|
|
36
60
|
const changedFiles = this.getChangedFiles(fileTimestamps, glob);
|
|
37
61
|
this.prevTimestamps = fileTimestamps;
|
|
38
62
|
|
|
39
63
|
if (changedFiles.length) {
|
|
40
64
|
dirtyOptions.files = changedFiles;
|
|
41
|
-
(0, _linter.default)(dirtyOptions, this.compiler, callback);
|
|
65
|
+
(0, _linter.default)(this.lint, dirtyOptions, this.compiler, callback);
|
|
42
66
|
} else {
|
|
43
67
|
callback();
|
|
44
68
|
}
|
|
45
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* @param {Map<string, number|FileSystemInfoEntry>} fileTimestamps
|
|
72
|
+
* @param {string | ReadonlyArray<string>} glob
|
|
73
|
+
* @returns {Array<string>}
|
|
74
|
+
*/
|
|
75
|
+
|
|
46
76
|
|
|
47
77
|
getChangedFiles(fileTimestamps, glob) {
|
|
78
|
+
/**
|
|
79
|
+
* @param {FileSystemInfoEntry} fileSystemInfoEntry
|
|
80
|
+
* @returns {Partial<number>}
|
|
81
|
+
*/
|
|
48
82
|
const getTimestamps = fileSystemInfoEntry => {
|
|
49
|
-
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
if (fileSystemInfoEntry && fileSystemInfoEntry.timestamp) {
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
return fileSystemInfoEntry.timestamp;
|
|
87
|
+
} // @ts-ignore
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
return fileSystemInfoEntry;
|
|
50
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* @param {string} filename
|
|
94
|
+
* @param {FileSystemInfoEntry} fileSystemInfoEntry
|
|
95
|
+
* @returns {boolean}
|
|
96
|
+
*/
|
|
97
|
+
|
|
51
98
|
|
|
52
99
|
const hasFileChanged = (filename, fileSystemInfoEntry) => {
|
|
53
100
|
const prevTimestamp = getTimestamps(this.prevTimestamps.get(filename));
|
|
@@ -59,7 +106,7 @@ class LintDirtyModulesPlugin {
|
|
|
59
106
|
|
|
60
107
|
for (const [filename, timestamp] of fileTimestamps.entries()) {
|
|
61
108
|
if (hasFileChanged(filename, timestamp) && (0, _micromatch.isMatch)(filename, glob)) {
|
|
62
|
-
changedFiles.push(
|
|
109
|
+
changedFiles.push((0, _utils.replaceBackslashes)(filename));
|
|
63
110
|
}
|
|
64
111
|
}
|
|
65
112
|
|
package/dist/StylelintError.js
CHANGED
|
@@ -5,16 +5,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
/** @typedef {import('stylelint').LintResult} LintResult */
|
|
9
|
+
|
|
10
|
+
/** @typedef {import('./getOptions').Options} Options */
|
|
8
11
|
class StylelintError extends Error {
|
|
12
|
+
/**
|
|
13
|
+
* @param {Partial<string>} messages
|
|
14
|
+
*/
|
|
9
15
|
constructor(messages) {
|
|
10
16
|
super(messages);
|
|
11
17
|
this.name = 'StylelintError';
|
|
12
|
-
this.stack =
|
|
18
|
+
this.stack = '';
|
|
13
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* @param {Options} options
|
|
22
|
+
* @param {Array<LintResult>} messages
|
|
23
|
+
* @returns {StylelintError}
|
|
24
|
+
*/
|
|
25
|
+
|
|
14
26
|
|
|
15
27
|
static format({
|
|
16
28
|
formatter
|
|
17
29
|
}, messages) {
|
|
30
|
+
// @ts-ignore
|
|
18
31
|
return new StylelintError(formatter(messages));
|
|
19
32
|
}
|
|
20
33
|
|
package/dist/getOptions.js
CHANGED
|
@@ -5,20 +5,41 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = getOptions;
|
|
7
7
|
|
|
8
|
-
var _schemaUtils =
|
|
8
|
+
var _schemaUtils = require("schema-utils");
|
|
9
9
|
|
|
10
10
|
var _options = _interopRequireDefault(require("./options.json"));
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
+
/** @typedef {import("stylelint")} stylelint */
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {Object} Options
|
|
18
|
+
* @property {string=} context
|
|
19
|
+
* @property {boolean=} emitError
|
|
20
|
+
* @property {boolean=} emitWarning
|
|
21
|
+
* @property {boolean=} failOnError
|
|
22
|
+
* @property {boolean=} failOnWarning
|
|
23
|
+
* @property {Array<string> | string} files
|
|
24
|
+
* @property {Function | string} formatter
|
|
25
|
+
* @property {boolean=} lintDirtyModulesOnly
|
|
26
|
+
* @property {boolean=} quiet
|
|
27
|
+
* @property {string} stylelintPath
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {Partial<Options>} pluginOptions
|
|
32
|
+
* @returns {Options}
|
|
33
|
+
*/
|
|
14
34
|
function getOptions(pluginOptions) {
|
|
15
35
|
const options = {
|
|
16
|
-
files: '**/*.s
|
|
36
|
+
files: '**/*.(s(c|a)ss|css)',
|
|
17
37
|
formatter: 'string',
|
|
18
38
|
stylelintPath: 'stylelint',
|
|
19
39
|
...pluginOptions
|
|
20
|
-
};
|
|
21
|
-
|
|
40
|
+
}; // @ts-ignore
|
|
41
|
+
|
|
42
|
+
(0, _schemaUtils.validate)(_options.default, options, {
|
|
22
43
|
name: 'Stylelint Webpack Plugin',
|
|
23
44
|
baseDataPath: 'options'
|
|
24
45
|
}); // eslint-disable-next-line
|
|
@@ -28,6 +49,12 @@ function getOptions(pluginOptions) {
|
|
|
28
49
|
options.formatter = getFormatter(stylelint, options.formatter);
|
|
29
50
|
return options;
|
|
30
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* @param {stylelint} stylelint
|
|
54
|
+
* @param {Function | string} formatter
|
|
55
|
+
* @returns {Function}
|
|
56
|
+
*/
|
|
57
|
+
|
|
31
58
|
|
|
32
59
|
function getFormatter({
|
|
33
60
|
formatters
|
|
@@ -37,7 +64,9 @@ function getFormatter({
|
|
|
37
64
|
} // Try to get oficial formatter
|
|
38
65
|
|
|
39
66
|
|
|
40
|
-
if (typeof formatter === 'string' &&
|
|
67
|
+
if (typeof formatter === 'string' && // @ts-ignore
|
|
68
|
+
typeof formatters[formatter] === 'function') {
|
|
69
|
+
// @ts-ignore
|
|
41
70
|
return formatters[formatter];
|
|
42
71
|
}
|
|
43
72
|
|
package/dist/index.js
CHANGED
|
@@ -7,32 +7,42 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _path = require("path");
|
|
9
9
|
|
|
10
|
-
var _arrify = _interopRequireDefault(require("arrify"));
|
|
11
|
-
|
|
12
10
|
var _getOptions = _interopRequireDefault(require("./getOptions"));
|
|
13
11
|
|
|
14
12
|
var _LintDirtyModulesPlugin = _interopRequireDefault(require("./LintDirtyModulesPlugin"));
|
|
15
13
|
|
|
16
14
|
var _linter = _interopRequireDefault(require("./linter"));
|
|
17
15
|
|
|
16
|
+
var _utils = require("./utils");
|
|
17
|
+
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
|
|
20
|
+
/** @typedef {import('webpack').Compiler} Compiler */
|
|
20
21
|
class StylelintWebpackPlugin {
|
|
21
22
|
constructor(options = {}) {
|
|
22
23
|
this.options = (0, _getOptions.default)(options);
|
|
23
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* @param {Compiler} compiler
|
|
27
|
+
* @returns {void}
|
|
28
|
+
*/
|
|
29
|
+
|
|
24
30
|
|
|
25
31
|
apply(compiler) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
};
|
|
32
|
+
const options = { ...this.options,
|
|
33
|
+
files: (0, _utils.parseFiles)(this.options.files, this.getContext(compiler))
|
|
34
|
+
}; // eslint-disable-next-line
|
|
35
|
+
|
|
36
|
+
const {
|
|
37
|
+
lint
|
|
38
|
+
} = require(options.stylelintPath);
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
name: plugin
|
|
42
|
+
} = this.constructor;
|
|
33
43
|
|
|
34
44
|
if (options.lintDirtyModulesOnly) {
|
|
35
|
-
const lintDirty = new _LintDirtyModulesPlugin.default(compiler, options);
|
|
45
|
+
const lintDirty = new _LintDirtyModulesPlugin.default(lint, compiler, options);
|
|
36
46
|
/* istanbul ignore next */
|
|
37
47
|
|
|
38
48
|
compiler.hooks.watchRun.tapAsync(plugin, (compilation, callback) => {
|
|
@@ -40,23 +50,29 @@ class StylelintWebpackPlugin {
|
|
|
40
50
|
});
|
|
41
51
|
} else {
|
|
42
52
|
compiler.hooks.run.tapAsync(plugin, (compilation, callback) => {
|
|
43
|
-
(0, _linter.default)(options, compilation, callback);
|
|
53
|
+
(0, _linter.default)(lint, options, compilation, callback);
|
|
44
54
|
});
|
|
45
55
|
/* istanbul ignore next */
|
|
46
56
|
|
|
47
57
|
compiler.hooks.watchRun.tapAsync(plugin, (compilation, callback) => {
|
|
48
|
-
(0, _linter.default)(options, compilation, callback);
|
|
58
|
+
(0, _linter.default)(lint, options, compilation, callback);
|
|
49
59
|
});
|
|
50
60
|
}
|
|
51
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @param {Compiler} compiler
|
|
65
|
+
* @returns {string}
|
|
66
|
+
*/
|
|
67
|
+
|
|
52
68
|
|
|
53
69
|
getContext(compiler) {
|
|
54
70
|
if (!this.options.context) {
|
|
55
|
-
return compiler.options.context;
|
|
71
|
+
return String(compiler.options.context);
|
|
56
72
|
}
|
|
57
73
|
|
|
58
74
|
if (!(0, _path.isAbsolute)(this.options.context)) {
|
|
59
|
-
return (0, _path.join)(compiler.options.context, this.options.context);
|
|
75
|
+
return (0, _path.join)(String(compiler.options.context), this.options.context);
|
|
60
76
|
}
|
|
61
77
|
|
|
62
78
|
return this.options.context;
|
package/dist/linter.js
CHANGED
|
@@ -9,14 +9,39 @@ var _StylelintError = _interopRequireDefault(require("./StylelintError"));
|
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
/** @typedef {import('stylelint').LinterResult} LinterResult */
|
|
13
|
+
|
|
14
|
+
/** @typedef {import('stylelint').LintResult} LintResult */
|
|
15
|
+
|
|
16
|
+
/** @typedef {import('webpack').Compiler} Compiler */
|
|
17
|
+
|
|
18
|
+
/** @typedef {import('./getOptions').Options} Options */
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @callback Lint
|
|
22
|
+
* @param {Options} options
|
|
23
|
+
* @returns {Promise<LinterResult>}
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @callback LinterCallback
|
|
28
|
+
* @param {StylelintError | null=} error
|
|
29
|
+
* @returns {void}
|
|
30
|
+
*/
|
|
15
31
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
32
|
+
/**
|
|
33
|
+
* @param {Lint} lint
|
|
34
|
+
* @param {Options} options
|
|
35
|
+
* @param {Compiler} compiler
|
|
36
|
+
* @param {LinterCallback} callback
|
|
37
|
+
* @returns {void}
|
|
38
|
+
*/
|
|
39
|
+
function linter(lint, options, compiler, callback) {
|
|
40
|
+
/** @type {Array<LintResult>} */
|
|
41
|
+
let errors = [];
|
|
42
|
+
/** @type {Array<LintResult>} */
|
|
19
43
|
|
|
44
|
+
let warnings = [];
|
|
20
45
|
lint(options).then(({
|
|
21
46
|
results
|
|
22
47
|
}) => {
|
|
@@ -26,11 +51,13 @@ function linter(options, compiler, callback) {
|
|
|
26
51
|
} = parseResults(options, results));
|
|
27
52
|
compiler.hooks.afterEmit.tapAsync('StylelintWebpackPlugin', (compilation, next) => {
|
|
28
53
|
if (warnings.length) {
|
|
54
|
+
// @ts-ignore
|
|
29
55
|
compilation.warnings.push(_StylelintError.default.format(options, warnings));
|
|
30
56
|
warnings = [];
|
|
31
57
|
}
|
|
32
58
|
|
|
33
59
|
if (errors.length) {
|
|
60
|
+
// @ts-ignore
|
|
34
61
|
compilation.errors.push(_StylelintError.default.format(options, errors));
|
|
35
62
|
errors = [];
|
|
36
63
|
}
|
|
@@ -47,15 +74,26 @@ function linter(options, compiler, callback) {
|
|
|
47
74
|
}
|
|
48
75
|
}).catch(e => {
|
|
49
76
|
compiler.hooks.afterEmit.tapAsync('StylelintWebpackPlugin', (compilation, next) => {
|
|
77
|
+
// @ts-ignore
|
|
50
78
|
compilation.errors.push(new _StylelintError.default(e.message));
|
|
51
79
|
next();
|
|
52
80
|
});
|
|
53
81
|
callback();
|
|
54
82
|
});
|
|
55
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* @param {Options} options
|
|
87
|
+
* @param {Array<LintResult>} results
|
|
88
|
+
* @returns {{errors: Array<LintResult>, warnings: Array<LintResult>}}
|
|
89
|
+
*/
|
|
90
|
+
|
|
56
91
|
|
|
57
92
|
function parseResults(options, results) {
|
|
93
|
+
/** @type {Array<LintResult>} */
|
|
58
94
|
let errors = [];
|
|
95
|
+
/** @type {Array<LintResult>} */
|
|
96
|
+
|
|
59
97
|
let warnings = [];
|
|
60
98
|
|
|
61
99
|
if (options.emitError) {
|
|
@@ -76,11 +114,21 @@ function parseResults(options, results) {
|
|
|
76
114
|
warnings
|
|
77
115
|
};
|
|
78
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* @param {LintResult} file
|
|
119
|
+
* @returns {boolean}
|
|
120
|
+
*/
|
|
121
|
+
|
|
79
122
|
|
|
80
123
|
function fileHasErrors(file) {
|
|
81
|
-
return file.errored;
|
|
124
|
+
return !!file.errored;
|
|
82
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* @param {LintResult} file
|
|
128
|
+
* @returns {boolean}
|
|
129
|
+
*/
|
|
130
|
+
|
|
83
131
|
|
|
84
132
|
function fileHasWarnings(file) {
|
|
85
|
-
return file.warnings && file.warnings.length;
|
|
133
|
+
return file.warnings && file.warnings.length > 0;
|
|
86
134
|
}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseFiles = parseFiles;
|
|
7
|
+
exports.replaceBackslashes = replaceBackslashes;
|
|
8
|
+
|
|
9
|
+
var _arrify = _interopRequireDefault(require("arrify"));
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;
|
|
14
|
+
/**
|
|
15
|
+
* @param {Array<string> | string} files
|
|
16
|
+
* @param {string} context
|
|
17
|
+
* @returns {Array<string>}
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function parseFiles(files, context) {
|
|
21
|
+
return (0, _arrify.default)(files).map(file => `${replaceBackslashes(context).replace(UNESCAPED_GLOB_SYMBOLS_RE, '\\$2')}/${replaceBackslashes(file)}`);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} str
|
|
25
|
+
* @returns {string}
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
function replaceBackslashes(str) {
|
|
30
|
+
return str.replace(/\\/g, '/');
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,76 +1,89 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stylelint-webpack-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "A Stylelint plugin for webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/stylelint-webpack-plugin",
|
|
7
7
|
"author": "Javier Sánchez-Marín <javiersanchezmarin@gmail.com>",
|
|
8
|
+
"contributors": [
|
|
9
|
+
"Ricardo Gobbo de Souza <ricardogobbosouza@yahoo.com.br>"
|
|
10
|
+
],
|
|
8
11
|
"homepage": "https://github.com/webpack-contrib/stylelint-webpack-plugin",
|
|
9
12
|
"bugs": "https://github.com/webpack-contrib/stylelint-webpack-plugin/issues",
|
|
13
|
+
"funding": {
|
|
14
|
+
"type": "opencollective",
|
|
15
|
+
"url": "https://opencollective.com/webpack"
|
|
16
|
+
},
|
|
10
17
|
"main": "dist/cjs.js",
|
|
18
|
+
"types": "declarations/index.d.ts",
|
|
11
19
|
"engines": {
|
|
12
|
-
"node": ">=
|
|
20
|
+
"node": ">= 10.13.0"
|
|
13
21
|
},
|
|
14
22
|
"scripts": {
|
|
15
23
|
"start": "npm run build -- -w",
|
|
24
|
+
"clean": "del-cli dist declarations",
|
|
16
25
|
"prebuild": "npm run clean",
|
|
17
|
-
"build": "
|
|
18
|
-
"
|
|
26
|
+
"build:types": "tsc --declaration --emitDeclarationOnly --outDir declarations && prettier \"declarations/**/*.ts\" --write",
|
|
27
|
+
"build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files",
|
|
28
|
+
"build": "npm-run-all -p \"build:**\"",
|
|
19
29
|
"commitlint": "commitlint --from=master",
|
|
20
|
-
"lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css}\" --list-different",
|
|
21
|
-
"lint:js": "eslint --cache src test",
|
|
22
|
-
"lint": "npm-run-all -l -p \"lint:**\"",
|
|
23
|
-
"prepare": "npm run build",
|
|
24
|
-
"release": "standard-version",
|
|
25
30
|
"security": "npm audit",
|
|
31
|
+
"lint:prettier": "prettier --list-different .",
|
|
32
|
+
"lint:js": "eslint --cache .",
|
|
33
|
+
"lint:types": "tsc --pretty --noEmit",
|
|
34
|
+
"lint": "npm-run-all -l -p \"lint:**\"",
|
|
26
35
|
"test:only": "cross-env NODE_ENV=test jest",
|
|
27
|
-
"test:watch": "
|
|
28
|
-
"test:coverage": "
|
|
36
|
+
"test:watch": "npm run test:only -- --watch",
|
|
37
|
+
"test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
|
|
29
38
|
"pretest": "npm run lint",
|
|
30
|
-
"test": "
|
|
39
|
+
"test": "npm run test:coverage",
|
|
40
|
+
"prepare": "npm run build",
|
|
41
|
+
"release": "standard-version",
|
|
31
42
|
"defaults": "webpack-defaults"
|
|
32
43
|
},
|
|
33
44
|
"files": [
|
|
34
|
-
"dist"
|
|
45
|
+
"dist",
|
|
46
|
+
"declarations"
|
|
35
47
|
],
|
|
36
48
|
"peerDependencies": {
|
|
37
|
-
"stylelint": "^
|
|
49
|
+
"stylelint": "^13.0.0",
|
|
38
50
|
"webpack": "^4.0.0 || ^5.0.0"
|
|
39
51
|
},
|
|
40
52
|
"dependencies": {
|
|
41
53
|
"arrify": "^2.0.1",
|
|
42
54
|
"micromatch": "^4.0.2",
|
|
43
|
-
"schema-utils": "^
|
|
55
|
+
"schema-utils": "^3.0.0"
|
|
44
56
|
},
|
|
45
57
|
"devDependencies": {
|
|
46
|
-
"@babel/cli": "^7.
|
|
47
|
-
"@babel/core": "^7.
|
|
48
|
-
"@babel/preset-env": "^7.
|
|
49
|
-
"@commitlint/cli": "^
|
|
50
|
-
"@commitlint/config-conventional": "^
|
|
51
|
-
"@
|
|
58
|
+
"@babel/cli": "^7.12.0",
|
|
59
|
+
"@babel/core": "^7.12.0",
|
|
60
|
+
"@babel/preset-env": "^7.12.0",
|
|
61
|
+
"@commitlint/cli": "^11.0.0",
|
|
62
|
+
"@commitlint/config-conventional": "^11.0.0",
|
|
63
|
+
"@types/micromatch": "^4.0.1",
|
|
64
|
+
"@types/stylelint": "^9.10.1",
|
|
65
|
+
"@types/webpack": "^4.41.20",
|
|
66
|
+
"@webpack-contrib/defaults": "^6.3.0",
|
|
52
67
|
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
|
|
53
|
-
"babel-eslint": "^10.0
|
|
54
|
-
"babel-jest": "^
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"del": "^
|
|
58
|
-
"
|
|
59
|
-
"eslint": "^6.
|
|
60
|
-
"eslint-config-prettier": "^6.7.0",
|
|
68
|
+
"babel-eslint": "^10.1.0",
|
|
69
|
+
"babel-jest": "^26.5.2",
|
|
70
|
+
"cross-env": "^7.0.2",
|
|
71
|
+
"del": "^6.0.0",
|
|
72
|
+
"del-cli": "^3.0.1",
|
|
73
|
+
"eslint": "^7.11.0",
|
|
74
|
+
"eslint-config-prettier": "^6.12.0",
|
|
61
75
|
"eslint-friendly-formatter": "^4.0.1",
|
|
62
|
-
"eslint-plugin-import": "^2.
|
|
63
|
-
"file-loader": "^
|
|
64
|
-
"husky": "^3.
|
|
65
|
-
"jest": "^
|
|
66
|
-
"
|
|
67
|
-
"lint-staged": "^9.5.0",
|
|
68
|
-
"mkdirp": "^0.5.1",
|
|
76
|
+
"eslint-plugin-import": "^2.22.1",
|
|
77
|
+
"file-loader": "^6.1.1",
|
|
78
|
+
"husky": "^4.3.0",
|
|
79
|
+
"jest": "^26.5.3",
|
|
80
|
+
"lint-staged": "^10.4.0",
|
|
69
81
|
"npm-run-all": "^4.1.5",
|
|
70
|
-
"prettier": "^1.
|
|
71
|
-
"standard-version": "^
|
|
72
|
-
"stylelint": "^
|
|
73
|
-
"
|
|
82
|
+
"prettier": "^2.1.2",
|
|
83
|
+
"standard-version": "^9.0.0",
|
|
84
|
+
"stylelint": "^13.7.2",
|
|
85
|
+
"typescript": "^4.0.3",
|
|
86
|
+
"webpack": "^5.1.0"
|
|
74
87
|
},
|
|
75
88
|
"keywords": [
|
|
76
89
|
"stylelint",
|