stylelint-webpack-plugin 2.0.0 → 2.1.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/CHANGELOG.md +7 -0
- package/declarations/LintDirtyModulesPlugin.d.ts +58 -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 +47 -3
- package/dist/StylelintError.js +14 -1
- package/dist/getOptions.js +31 -2
- package/dist/index.js +17 -5
- package/dist/linter.js +52 -2
- package/dist/utils.js +10 -1
- package/package.json +25 -16
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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.0](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.2.3...v2.1.0) (2020-06-17)
|
|
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
|
+
|
|
5
12
|
## [2.0.0](https://github.com/webpack-contrib/stylelint-webpack-plugin/compare/v1.2.3...v2.0.0) (2020-05-04)
|
|
6
13
|
|
|
7
14
|
### ⚠ BREAKING CHANGES
|
|
@@ -0,0 +1,58 @@
|
|
|
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>} fileTimestamps
|
|
27
|
+
* @param {string | ReadonlyArray<string>} glob
|
|
28
|
+
* @returns {Array<string>}
|
|
29
|
+
*/
|
|
30
|
+
getChangedFiles(
|
|
31
|
+
fileTimestamps: Map<string, number>,
|
|
32
|
+
glob: string | ReadonlyArray<string>
|
|
33
|
+
): Array<string>;
|
|
34
|
+
}
|
|
35
|
+
export type Compiler = import('webpack').Compiler;
|
|
36
|
+
export type Options = {
|
|
37
|
+
context?: string | undefined;
|
|
38
|
+
emitError?: boolean | undefined;
|
|
39
|
+
emitWarning?: boolean | undefined;
|
|
40
|
+
failOnError?: boolean | undefined;
|
|
41
|
+
failOnWarning?: boolean | undefined;
|
|
42
|
+
files: string | string[];
|
|
43
|
+
formatter: TimerHandler;
|
|
44
|
+
lintDirtyModulesOnly?: boolean | undefined;
|
|
45
|
+
quiet?: boolean | undefined;
|
|
46
|
+
stylelintPath: string;
|
|
47
|
+
};
|
|
48
|
+
export type Lint = (
|
|
49
|
+
options: import('./getOptions').Options
|
|
50
|
+
) => Promise<import('stylelint').LinterResult>;
|
|
51
|
+
export type LinterCallback = (
|
|
52
|
+
error?: import('./StylelintError').default | null | undefined
|
|
53
|
+
) => void;
|
|
54
|
+
export type FileSystemInfoEntry =
|
|
55
|
+
| number
|
|
56
|
+
| Partial<{
|
|
57
|
+
timestamp: number;
|
|
58
|
+
}>;
|
|
@@ -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;
|
|
@@ -13,15 +13,35 @@ var _utils = require("./utils");
|
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
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 */
|
|
16
25
|
class LintDirtyModulesPlugin {
|
|
26
|
+
/**
|
|
27
|
+
* @param {Lint} lint
|
|
28
|
+
* @param {Compiler} compiler
|
|
29
|
+
* @param {Options} options
|
|
30
|
+
*/
|
|
17
31
|
constructor(lint, compiler, options) {
|
|
18
32
|
this.lint = lint;
|
|
19
33
|
this.compiler = compiler;
|
|
20
34
|
this.options = options;
|
|
21
35
|
this.startTime = Date.now();
|
|
22
|
-
this.prevTimestamps =
|
|
36
|
+
this.prevTimestamps = new Map();
|
|
23
37
|
this.isFirstRun = true;
|
|
24
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* @param {Compiler} compilation
|
|
41
|
+
* @param {LinterCallback} callback
|
|
42
|
+
* @returns {void}
|
|
43
|
+
*/
|
|
44
|
+
|
|
25
45
|
|
|
26
46
|
apply(compilation, callback) {
|
|
27
47
|
const fileTimestamps = compilation.fileTimestamps || new Map();
|
|
@@ -34,7 +54,8 @@ class LintDirtyModulesPlugin {
|
|
|
34
54
|
}
|
|
35
55
|
|
|
36
56
|
const dirtyOptions = { ...this.options
|
|
37
|
-
};
|
|
57
|
+
}; // @ts-ignore
|
|
58
|
+
|
|
38
59
|
const glob = (0, _utils.replaceBackslashes)(dirtyOptions.files.join('|'));
|
|
39
60
|
const changedFiles = this.getChangedFiles(fileTimestamps, glob);
|
|
40
61
|
this.prevTimestamps = fileTimestamps;
|
|
@@ -46,11 +67,34 @@ class LintDirtyModulesPlugin {
|
|
|
46
67
|
callback();
|
|
47
68
|
}
|
|
48
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* @param {Map<string, number>} fileTimestamps
|
|
72
|
+
* @param {string | ReadonlyArray<string>} glob
|
|
73
|
+
* @returns {Array<string>}
|
|
74
|
+
*/
|
|
75
|
+
|
|
49
76
|
|
|
50
77
|
getChangedFiles(fileTimestamps, glob) {
|
|
78
|
+
/**
|
|
79
|
+
* @param {FileSystemInfoEntry} fileSystemInfoEntry
|
|
80
|
+
* @returns {Partial<number>}
|
|
81
|
+
*/
|
|
51
82
|
const getTimestamps = fileSystemInfoEntry => {
|
|
52
|
-
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
if (fileSystemInfoEntry && fileSystemInfoEntry.timestamp) {
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
return fileSystemInfoEntry.timestamp;
|
|
87
|
+
} // @ts-ignore
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
return fileSystemInfoEntry;
|
|
53
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* @param {string} filename
|
|
94
|
+
* @param {FileSystemInfoEntry} fileSystemInfoEntry
|
|
95
|
+
* @returns {boolean}
|
|
96
|
+
*/
|
|
97
|
+
|
|
54
98
|
|
|
55
99
|
const hasFileChanged = (filename, fileSystemInfoEntry) => {
|
|
56
100
|
const prevTimestamp = getTimestamps(this.prevTimestamps.get(filename));
|
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
|
@@ -11,13 +11,34 @@ 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
36
|
files: '**/*.s?(c|a)ss',
|
|
17
37
|
formatter: 'string',
|
|
18
38
|
stylelintPath: 'stylelint',
|
|
19
39
|
...pluginOptions
|
|
20
|
-
};
|
|
40
|
+
}; // @ts-ignore
|
|
41
|
+
|
|
21
42
|
(0, _schemaUtils.default)(_options.default, options, {
|
|
22
43
|
name: 'Stylelint Webpack Plugin',
|
|
23
44
|
baseDataPath: 'options'
|
|
@@ -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
|
@@ -17,10 +17,16 @@ var _utils = require("./utils");
|
|
|
17
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
32
|
const options = { ...this.options,
|
|
@@ -31,9 +37,9 @@ class StylelintWebpackPlugin {
|
|
|
31
37
|
lint
|
|
32
38
|
} = require(options.stylelintPath);
|
|
33
39
|
|
|
34
|
-
const
|
|
35
|
-
name:
|
|
36
|
-
};
|
|
40
|
+
const {
|
|
41
|
+
name: plugin
|
|
42
|
+
} = this.constructor;
|
|
37
43
|
|
|
38
44
|
if (options.lintDirtyModulesOnly) {
|
|
39
45
|
const lintDirty = new _LintDirtyModulesPlugin.default(lint, compiler, options);
|
|
@@ -53,14 +59,20 @@ class StylelintWebpackPlugin {
|
|
|
53
59
|
});
|
|
54
60
|
}
|
|
55
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @param {Compiler} compiler
|
|
65
|
+
* @returns {string}
|
|
66
|
+
*/
|
|
67
|
+
|
|
56
68
|
|
|
57
69
|
getContext(compiler) {
|
|
58
70
|
if (!this.options.context) {
|
|
59
|
-
return compiler.options.context;
|
|
71
|
+
return String(compiler.options.context);
|
|
60
72
|
}
|
|
61
73
|
|
|
62
74
|
if (!(0, _path.isAbsolute)(this.options.context)) {
|
|
63
|
-
return (0, _path.join)(compiler.options.context, this.options.context);
|
|
75
|
+
return (0, _path.join)(String(compiler.options.context), this.options.context);
|
|
64
76
|
}
|
|
65
77
|
|
|
66
78
|
return this.options.context;
|
package/dist/linter.js
CHANGED
|
@@ -9,8 +9,38 @@ var _StylelintError = _interopRequireDefault(require("./StylelintError"));
|
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
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
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {Lint} lint
|
|
34
|
+
* @param {Options} options
|
|
35
|
+
* @param {Compiler} compiler
|
|
36
|
+
* @param {LinterCallback} callback
|
|
37
|
+
* @returns {void}
|
|
38
|
+
*/
|
|
12
39
|
function linter(lint, options, compiler, callback) {
|
|
40
|
+
/** @type {Array<LintResult>} */
|
|
13
41
|
let errors = [];
|
|
42
|
+
/** @type {Array<LintResult>} */
|
|
43
|
+
|
|
14
44
|
let warnings = [];
|
|
15
45
|
lint(options).then(({
|
|
16
46
|
results
|
|
@@ -48,9 +78,19 @@ function linter(lint, options, compiler, callback) {
|
|
|
48
78
|
callback();
|
|
49
79
|
});
|
|
50
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
*
|
|
83
|
+
* @param {Options} options
|
|
84
|
+
* @param {Array<LintResult>} results
|
|
85
|
+
* @returns {{errors: Array<LintResult>, warnings: Array<LintResult>}}
|
|
86
|
+
*/
|
|
87
|
+
|
|
51
88
|
|
|
52
89
|
function parseResults(options, results) {
|
|
90
|
+
/** @type {Array<LintResult>} */
|
|
53
91
|
let errors = [];
|
|
92
|
+
/** @type {Array<LintResult>} */
|
|
93
|
+
|
|
54
94
|
let warnings = [];
|
|
55
95
|
|
|
56
96
|
if (options.emitError) {
|
|
@@ -71,11 +111,21 @@ function parseResults(options, results) {
|
|
|
71
111
|
warnings
|
|
72
112
|
};
|
|
73
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* @param {LintResult} file
|
|
116
|
+
* @returns {boolean}
|
|
117
|
+
*/
|
|
118
|
+
|
|
74
119
|
|
|
75
120
|
function fileHasErrors(file) {
|
|
76
|
-
return file.errored;
|
|
121
|
+
return !!file.errored;
|
|
77
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* @param {LintResult} file
|
|
125
|
+
* @returns {boolean}
|
|
126
|
+
*/
|
|
127
|
+
|
|
78
128
|
|
|
79
129
|
function fileHasWarnings(file) {
|
|
80
|
-
return file.warnings && file.warnings.length;
|
|
130
|
+
return file.warnings && file.warnings.length > 0;
|
|
81
131
|
}
|
package/dist/utils.js
CHANGED
|
@@ -10,12 +10,21 @@ var _arrify = _interopRequireDefault(require("arrify"));
|
|
|
10
10
|
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
12
|
|
|
13
|
-
// import { join } from 'path';
|
|
14
13
|
const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;
|
|
14
|
+
/**
|
|
15
|
+
* @param {Array<string> | string} files
|
|
16
|
+
* @param {string} context
|
|
17
|
+
* @returns {Array<string>}
|
|
18
|
+
*/
|
|
15
19
|
|
|
16
20
|
function parseFiles(files, context) {
|
|
17
21
|
return (0, _arrify.default)(files).map(file => `${replaceBackslashes(context).replace(UNESCAPED_GLOB_SYMBOLS_RE, '\\$2')}/${replaceBackslashes(file)}`);
|
|
18
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} str
|
|
25
|
+
* @returns {string}
|
|
26
|
+
*/
|
|
27
|
+
|
|
19
28
|
|
|
20
29
|
function replaceBackslashes(str) {
|
|
21
30
|
return str.replace(/\\/g, '/');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stylelint-webpack-plugin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A Stylelint plugin for webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/stylelint-webpack-plugin",
|
|
@@ -15,18 +15,22 @@
|
|
|
15
15
|
"url": "https://opencollective.com/webpack"
|
|
16
16
|
},
|
|
17
17
|
"main": "dist/cjs.js",
|
|
18
|
+
"types": "declarations/index.d.ts",
|
|
18
19
|
"engines": {
|
|
19
20
|
"node": ">= 10.13.0"
|
|
20
21
|
},
|
|
21
22
|
"scripts": {
|
|
22
23
|
"start": "npm run build -- -w",
|
|
23
|
-
"clean": "del-cli dist",
|
|
24
|
+
"clean": "del-cli dist declarations",
|
|
24
25
|
"prebuild": "npm run clean",
|
|
25
|
-
"build": "
|
|
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:**\"",
|
|
26
29
|
"commitlint": "commitlint --from=master",
|
|
27
30
|
"security": "npm audit",
|
|
28
31
|
"lint:prettier": "prettier --list-different .",
|
|
29
32
|
"lint:js": "eslint --cache .",
|
|
33
|
+
"lint:types": "tsc --pretty --noEmit",
|
|
30
34
|
"lint": "npm-run-all -l -p \"lint:**\"",
|
|
31
35
|
"test:only": "cross-env NODE_ENV=test jest",
|
|
32
36
|
"test:watch": "npm run test:only -- --watch",
|
|
@@ -38,7 +42,8 @@
|
|
|
38
42
|
"defaults": "webpack-defaults"
|
|
39
43
|
},
|
|
40
44
|
"files": [
|
|
41
|
-
"dist"
|
|
45
|
+
"dist",
|
|
46
|
+
"declarations"
|
|
42
47
|
],
|
|
43
48
|
"peerDependencies": {
|
|
44
49
|
"stylelint": "^13.0.0",
|
|
@@ -47,33 +52,37 @@
|
|
|
47
52
|
"dependencies": {
|
|
48
53
|
"arrify": "^2.0.1",
|
|
49
54
|
"micromatch": "^4.0.2",
|
|
50
|
-
"schema-utils": "^2.
|
|
55
|
+
"schema-utils": "^2.7.0"
|
|
51
56
|
},
|
|
52
57
|
"devDependencies": {
|
|
53
|
-
"@babel/cli": "^7.
|
|
54
|
-
"@babel/core": "^7.
|
|
55
|
-
"@babel/preset-env": "^7.
|
|
58
|
+
"@babel/cli": "^7.10.1",
|
|
59
|
+
"@babel/core": "^7.10.2",
|
|
60
|
+
"@babel/preset-env": "^7.10.2",
|
|
56
61
|
"@commitlint/cli": "^8.3.5",
|
|
57
62
|
"@commitlint/config-conventional": "^8.3.4",
|
|
63
|
+
"@types/micromatch": "^4.0.1",
|
|
64
|
+
"@types/stylelint": "^9.10.1",
|
|
65
|
+
"@types/webpack": "^4.41.17",
|
|
58
66
|
"@webpack-contrib/defaults": "^6.3.0",
|
|
59
67
|
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
|
|
60
68
|
"babel-eslint": "^10.1.0",
|
|
61
|
-
"babel-jest": "^
|
|
69
|
+
"babel-jest": "^26.0.1",
|
|
62
70
|
"cross-env": "^7.0.2",
|
|
63
71
|
"del": "^5.1.0",
|
|
64
|
-
"del-cli": "^3.0.
|
|
65
|
-
"eslint": "^
|
|
72
|
+
"del-cli": "^3.0.1",
|
|
73
|
+
"eslint": "^7.2.0",
|
|
66
74
|
"eslint-config-prettier": "^6.11.0",
|
|
67
75
|
"eslint-friendly-formatter": "^4.0.1",
|
|
68
|
-
"eslint-plugin-import": "^2.
|
|
76
|
+
"eslint-plugin-import": "^2.21.2",
|
|
69
77
|
"file-loader": "^6.0.0",
|
|
70
78
|
"husky": "^4.2.5",
|
|
71
|
-
"jest": "^
|
|
72
|
-
"lint-staged": "^10.2.
|
|
79
|
+
"jest": "^26.0.1",
|
|
80
|
+
"lint-staged": "^10.2.10",
|
|
73
81
|
"npm-run-all": "^4.1.5",
|
|
74
82
|
"prettier": "^2.0.5",
|
|
75
|
-
"standard-version": "^
|
|
76
|
-
"stylelint": "^13.
|
|
83
|
+
"standard-version": "^8.0.0",
|
|
84
|
+
"stylelint": "^13.6.0",
|
|
85
|
+
"typescript": "^3.9.5",
|
|
77
86
|
"webpack": "^4.43.0"
|
|
78
87
|
},
|
|
79
88
|
"keywords": [
|