stylelint-webpack-plugin 4.1.0 → 5.0.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
@@ -7,12 +7,12 @@
7
7
  [![node][node]][node-url]
8
8
  [![tests][tests]][tests-url]
9
9
  [![coverage][cover]][cover-url]
10
- [![chat][chat]][chat-url]
10
+ [![discussion][discussion]][discussion-url]
11
11
  [![size][size]][size-url]
12
12
 
13
13
  # stylelint-webpack-plugin
14
14
 
15
- > This is stylelint-webpack-plugin 3.0 which works only with webpack 5. For the webpack 4, see the [2.x branch](https://github.com/webpack-contrib/stylelint-webpack-plugin/tree/2.x).
15
+ > This version of stylelint-webpack-plugin only works with webpack 5. For the webpack 4, see the [2.x branch](https://github.com/webpack-contrib/stylelint-webpack-plugin/tree/2.x).
16
16
 
17
17
  This plugin uses [`stylelint`](https://stylelint.io/) that helps you avoid errors and enforce conventions in your styles.
18
18
 
@@ -76,6 +76,30 @@ module.exports = {
76
76
 
77
77
  See [stylelint's options](https://stylelint.io/user-guide/usage/node-api#options) for the complete list of options available. These options are passed through to the `stylelint` directly.
78
78
 
79
+ ### `cache`
80
+
81
+ - Type:
82
+
83
+ ```ts
84
+ type cache = boolean;
85
+ ```
86
+
87
+ - Default: `true`
88
+
89
+ The cache is enabled by default to decrease execution time.
90
+
91
+ ### `cacheLocation`
92
+
93
+ - Type:
94
+
95
+ ```ts
96
+ type cacheLocation = string;
97
+ ```
98
+
99
+ - Default: `node_modules/.cache/stylelint-webpack-plugin/.stylelintcache`
100
+
101
+ Specify the path to the cache location. Can be a file or a directory.
102
+
79
103
  ### `configFile`
80
104
 
81
105
  - Type:
@@ -314,7 +338,7 @@ You can pass in a different formatter for the output file, if none is passed in
314
338
  [tests-url]: https://github.com/webpack-contrib/stylelint-webpack-plugin/actions
315
339
  [cover]: https://codecov.io/gh/webpack-contrib/stylelint-webpack-plugin/branch/master/graph/badge.svg
316
340
  [cover-url]: https://codecov.io/gh/webpack-contrib/stylelint-webpack-plugin
317
- [chat]: https://badges.gitter.im/webpack/webpack.svg
318
- [chat-url]: https://gitter.im/webpack/webpack
341
+ [discussion]: https://img.shields.io/github/discussions/webpack/webpack
342
+ [discussion-url]: https://github.com/webpack/webpack/discussions
319
343
  [size]: https://packagephobia.now.sh/badge?p=stylelint-webpack-plugin
320
344
  [size-url]: https://packagephobia.now.sh/result?p=stylelint-webpack-plugin
@@ -29,10 +29,9 @@ const cache = {};
29
29
  /** @typedef {import('stylelint').Formatter} Formatter */
30
30
  /** @typedef {import('stylelint').FormatterType} FormatterType */
31
31
  /** @typedef {import('./options').Options} Options */
32
- /** @typedef {(stylelint: Stylelint, filePath: string) => Promise<boolean>} isPathIgnored */
33
32
  /** @typedef {() => Promise<void>} AsyncTask */
34
33
  /** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */
35
- /** @typedef {{stylelint: Stylelint, isPathIgnored: isPathIgnored, lintFiles: LintTask, cleanup: AsyncTask, threads: number }} Linter */
34
+ /** @typedef {{stylelint: Stylelint, lintFiles: LintTask, cleanup: AsyncTask, threads: number }} Linter */
36
35
  /** @typedef {JestWorker & {lintFiles: LintTask}} Worker */
37
36
 
38
37
  /**
@@ -42,22 +41,8 @@ const cache = {};
42
41
  function loadStylelint(options) {
43
42
  const stylelintOptions = getStylelintOptions(options);
44
43
  const stylelint = setup(options, stylelintOptions);
45
-
46
- /** @type {isPathIgnored} */
47
- let isPathIgnored;
48
- try {
49
- isPathIgnored = require(`${options.stylelintPath}/lib/isPathIgnored`);
50
- } catch (e) {
51
- try {
52
- // @ts-ignore
53
- isPathIgnored = require('stylelint/lib/isPathIgnored');
54
- } catch (_) {
55
- isPathIgnored = () => Promise.resolve(false);
56
- }
57
- }
58
44
  return {
59
45
  stylelint,
60
- isPathIgnored,
61
46
  lintFiles,
62
47
  cleanup: async () => {},
63
48
  threads: 1
package/dist/index.js CHANGED
@@ -89,15 +89,9 @@ class StylelintWebpackPlugin {
89
89
  return;
90
90
  }
91
91
  compiler.hooks.thisCompilation.tap(this.key, compilation => {
92
- /** @type {import('./getStylelint').Stylelint} */
93
- let stylelint;
94
-
95
92
  /** @type {import('./linter').Linter} */
96
93
  let lint;
97
94
 
98
- /** @type {import('./linter').isPathIgnored} */
99
- let isPathIgnored;
100
-
101
95
  /** @type {import('./linter').Reporter} */
102
96
  let report;
103
97
 
@@ -105,9 +99,7 @@ class StylelintWebpackPlugin {
105
99
  let threads;
106
100
  try {
107
101
  ({
108
- stylelint,
109
102
  lint,
110
- isPathIgnored,
111
103
  report,
112
104
  threads
113
105
  } = linter(this.key, options, compilation));
@@ -118,20 +110,14 @@ class StylelintWebpackPlugin {
118
110
  compilation.hooks.finishModules.tapPromise(this.key, async () => {
119
111
  /** @type {string[]} */
120
112
  // @ts-ignore
121
- const files = (await Promise.all((compiler.modifiedFiles ? Array.from(compiler.modifiedFiles).filter(file => isMatch(file, wanted, {
113
+ const files = compiler.modifiedFiles ? Array.from(compiler.modifiedFiles).filter(file => isMatch(file, wanted, {
122
114
  dot: true
123
115
  }) && !isMatch(file, exclude, {
124
116
  dot: true
125
117
  })) : globby.sync(wanted, {
126
118
  dot: true,
127
119
  ignore: exclude
128
- })).map(async file => {
129
- try {
130
- return (await isPathIgnored(stylelint, file)) ? false : file;
131
- } catch (e) {
132
- return file;
133
- }
134
- }))).filter(file => file !== false);
120
+ });
135
121
  if (threads > 1) {
136
122
  for (const file of files) {
137
123
  lint(parseFiles(file, String(options.context)));
package/dist/linter.js CHANGED
@@ -18,7 +18,6 @@ const {
18
18
  /** @typedef {import('./getStylelint').LinterResult} LinterResult */
19
19
  /** @typedef {import('./getStylelint').Formatter} Formatter */
20
20
  /** @typedef {import('./getStylelint').FormatterType} FormatterType */
21
- /** @typedef {import('./getStylelint').isPathIgnored} isPathIgnored */
22
21
  /** @typedef {import('./options').Options} Options */
23
22
  /** @typedef {(compilation: Compilation) => Promise<void>} GenerateReport */
24
23
  /** @typedef {{errors?: StylelintError, warnings?: StylelintError, generateReportAsset?: GenerateReport}} Report */
@@ -33,15 +32,12 @@ const resultStorage = new WeakMap();
33
32
  * @param {string|undefined} key
34
33
  * @param {Options} options
35
34
  * @param {Compilation} compilation
36
- * @returns {{stylelint: Stylelint, isPathIgnored: isPathIgnored, lint: Linter, report: Reporter, threads: number}}
35
+ * @returns {{lint: Linter, report: Reporter, threads: number}}
37
36
  */
38
37
  function linter(key, options, compilation) {
39
38
  /** @type {Stylelint} */
40
39
  let stylelint;
41
40
 
42
- /** @type {isPathIgnored} */
43
- let isPathIgnored;
44
-
45
41
  /** @type {(files: string|string[]) => Promise<LintResult[]>} */
46
42
  let lintFiles;
47
43
 
@@ -57,7 +53,6 @@ function linter(key, options, compilation) {
57
53
  try {
58
54
  ({
59
55
  stylelint,
60
- isPathIgnored,
61
56
  lintFiles,
62
57
  cleanup,
63
58
  threads
@@ -66,9 +61,7 @@ function linter(key, options, compilation) {
66
61
  throw new StylelintError(e.message);
67
62
  }
68
63
  return {
69
- stylelint,
70
64
  lint,
71
- isPathIgnored,
72
65
  report,
73
66
  threads
74
67
  };
@@ -101,7 +94,7 @@ function linter(key, options, compilation) {
101
94
  if (!results || results.length < 1) {
102
95
  return {};
103
96
  }
104
- const formatter = loadFormatter(stylelint, options.formatter);
97
+ const formatter = await loadFormatter(stylelint, options.formatter);
105
98
 
106
99
  /** @type {LinterResult} */
107
100
  const returnValue = {
@@ -137,7 +130,7 @@ function linter(key, options, compilation) {
137
130
  * @param {string} name
138
131
  * @param {string | Buffer} content
139
132
  */
140
- const save = (name, content) => /** @type {Promise<void>} */
133
+ const save = (name, content) => ( /** @type {Promise<void>} */
141
134
  new Promise((finish, bail) => {
142
135
  const {
143
136
  mkdir,
@@ -154,12 +147,12 @@ function linter(key, options, compilation) {
154
147
  if (err2) bail(err2);else finish();
155
148
  });
156
149
  });
157
- });
150
+ }));
158
151
  if (!outputReport || !outputReport.filePath) {
159
152
  return;
160
153
  }
161
154
  const content = outputReport.formatter;
162
- loadFormatter(stylelint, outputReport.formatter)(results, returnValue);
155
+ (await loadFormatter(stylelint, outputReport.formatter))(results, returnValue);
163
156
  formatter(results, returnValue);
164
157
  let {
165
158
  filePath
@@ -229,7 +222,7 @@ function parseResults(options, results) {
229
222
  /**
230
223
  * @param {Stylelint} stylelint
231
224
  * @param {FormatterType=} formatter
232
- * @returns {Formatter}
225
+ * @returns {Promise<Formatter>|Formatter}
233
226
  */
234
227
  function loadFormatter(stylelint, formatter) {
235
228
  if (typeof formatter === 'function') {
package/dist/options.js CHANGED
@@ -40,6 +40,8 @@ const schema = require('./options.json');
40
40
  */
41
41
  function getOptions(pluginOptions) {
42
42
  const options = {
43
+ cache: true,
44
+ cacheLocation: 'node_modules/.cache/stylelint-webpack-plugin/.stylelintcache',
43
45
  extensions: ['css', 'scss', 'sass'],
44
46
  emitError: true,
45
47
  emitWarning: true,
package/dist/options.json CHANGED
@@ -36,7 +36,11 @@
36
36
  },
37
37
  "formatter": {
38
38
  "description": "Specify the formatter that you would like to use to format your results.",
39
- "anyOf": [{ "type": "string" }, { "instanceof": "Function" }]
39
+ "anyOf": [
40
+ { "type": "string" },
41
+ { "instanceof": "Function" },
42
+ { "instanceof": "Promise" }
43
+ ]
40
44
  },
41
45
  "lintDirtyModulesOnly": {
42
46
  "description": "Lint only changed files, skip lint on start.",
package/dist/worker.js CHANGED
@@ -33,7 +33,8 @@ async function lintFiles(files) {
33
33
  results
34
34
  } = await stylelint.lint({
35
35
  ...linterOptions,
36
- files
36
+ files,
37
+ quietDeprecationWarnings: true
37
38
  });
38
39
 
39
40
  // Reset result to work with worker
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stylelint-webpack-plugin",
3
- "version": "4.1.0",
3
+ "version": "5.0.0",
4
4
  "description": "A Stylelint plugin for webpack",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/stylelint-webpack-plugin",
@@ -14,7 +14,7 @@
14
14
  "main": "dist/index.js",
15
15
  "types": "types/index.d.ts",
16
16
  "engines": {
17
- "node": ">= 14.15.0"
17
+ "node": ">= 18.12.0"
18
18
  },
19
19
  "scripts": {
20
20
  "start": "npm run build -- -w",
@@ -30,7 +30,10 @@
30
30
  "lint:spelling": "cspell \"**/*.*\"",
31
31
  "lint:types": "tsc --pretty --noEmit",
32
32
  "lint": "npm-run-all -l -p \"lint:**\"",
33
- "test:only": "cross-env NODE_ENV=test jest --testTimeout=60000",
33
+ "fix:js": "npm run lint:js -- --fix",
34
+ "fix:prettier": "npm run lint:prettier -- --write",
35
+ "fix": "npm-run-all -l fix:js fix:prettier",
36
+ "test:only": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_ENV=test jest --testTimeout=60000",
34
37
  "test:watch": "npm run test:only -- --watch",
35
38
  "test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
36
39
  "pretest": "npm run lint",
@@ -43,51 +46,51 @@
43
46
  "types"
44
47
  ],
45
48
  "peerDependencies": {
46
- "stylelint": "^13.0.0 || ^14.0.0 || ^15.0.0",
49
+ "stylelint": "^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
47
50
  "webpack": "^5.0.0"
48
51
  },
49
52
  "dependencies": {
50
53
  "globby": "^11.1.0",
51
- "jest-worker": "^29.4.2",
54
+ "jest-worker": "^29.7.0",
52
55
  "micromatch": "^4.0.5",
53
56
  "normalize-path": "^3.0.0",
54
- "schema-utils": "^4.0.0"
57
+ "schema-utils": "^4.2.0"
55
58
  },
56
59
  "devDependencies": {
57
- "@babel/cli": "^7.20.7",
58
- "@babel/core": "^7.20.12",
59
- "@babel/preset-env": "^7.20.2",
60
- "@commitlint/cli": "^17.4.2",
61
- "@commitlint/config-conventional": "^17.4.2",
62
- "@types/file-entry-cache": "^5.0.2",
63
- "@types/fs-extra": "^9.0.13",
64
- "@types/micromatch": "^4.0.2",
65
- "@types/node": "^18.13.0",
66
- "@types/normalize-path": "^3.0.0",
67
- "@types/webpack": "^5.28.0",
60
+ "@babel/cli": "^7.23.4",
61
+ "@babel/core": "^7.23.7",
62
+ "@babel/preset-env": "^7.23.8",
63
+ "@commitlint/cli": "^18.6.0",
64
+ "@commitlint/config-conventional": "^18.6.0",
65
+ "@types/file-entry-cache": "^5.0.4",
66
+ "@types/fs-extra": "^11.0.4",
67
+ "@types/micromatch": "^4.0.6",
68
+ "@types/node": "^20.11.6",
69
+ "@types/normalize-path": "^3.0.2",
70
+ "@types/webpack": "^5.28.5",
68
71
  "@webpack-contrib/eslint-config-webpack": "^3.0.0",
69
72
  "babel-eslint": "^10.1.0",
70
- "babel-jest": "^29.4.2",
73
+ "babel-jest": "^29.7.0",
71
74
  "chokidar": "^3.5.3",
72
75
  "cross-env": "^7.0.3",
73
- "cspell": "^6.22.0",
74
- "del": "^6.1.1",
75
- "del-cli": "^4.0.1",
76
- "eslint": "^8.34.0",
77
- "eslint-config-prettier": "^8.6.0",
78
- "eslint-plugin-import": "^2.27.5",
76
+ "cspell": "^8.3.2",
77
+ "del": "^7.1.0",
78
+ "del-cli": "^5.1.0",
79
+ "eslint": "^8.56.0",
80
+ "eslint-config-prettier": "^9.1.0",
81
+ "eslint-plugin-import": "^2.29.1",
79
82
  "file-loader": "^6.2.0",
80
- "fs-extra": "^10.1.0",
83
+ "fs-extra": "^11.2.0",
81
84
  "husky": "^8.0.3",
82
- "jest": "^29.4.2",
83
- "lint-staged": "^13.1.1",
85
+ "jest": "^29.7.0",
86
+ "lint-staged": "^15.2.0",
84
87
  "npm-run-all": "^4.1.5",
85
- "postcss-scss": "^4.0.6",
86
- "prettier": "^2.8.4",
88
+ "postcss-scss": "^4.0.9",
89
+ "prettier": "^3.2.4",
87
90
  "standard-version": "^9.5.0",
88
- "stylelint": "^15.0.0",
89
- "typescript": "^4.9.5",
90
- "webpack": "^5.75.0"
91
+ "stylelint": "^16.2.0",
92
+ "typescript": "^5.3.3",
93
+ "webpack": "^5.90.0"
91
94
  },
92
95
  "keywords": [
93
96
  "stylelint",
@@ -1,4 +1,3 @@
1
- /// <reference types="stylelint" />
2
1
  export = getStylelint;
3
2
  /**
4
3
  * @param {string|undefined} key
@@ -7,7 +6,7 @@ export = getStylelint;
7
6
  */
8
7
  declare function getStylelint(
9
8
  key: string | undefined,
10
- { threads, ...options }: Options
9
+ { threads, ...options }: Options,
11
10
  ): Linter;
12
11
  declare namespace getStylelint {
13
12
  export {
@@ -18,7 +17,6 @@ declare namespace getStylelint {
18
17
  Formatter,
19
18
  FormatterType,
20
19
  Options,
21
- isPathIgnored,
22
20
  AsyncTask,
23
21
  LintTask,
24
22
  Linter,
@@ -28,7 +26,6 @@ declare namespace getStylelint {
28
26
  type Options = import('./options').Options;
29
27
  type Linter = {
30
28
  stylelint: Stylelint;
31
- isPathIgnored: isPathIgnored;
32
29
  lintFiles: LintTask;
33
30
  cleanup: AsyncTask;
34
31
  threads: number;
@@ -44,10 +41,6 @@ type LinterOptions = import('stylelint').LinterOptions;
44
41
  type LinterResult = import('stylelint').LinterResult;
45
42
  type Formatter = import('stylelint').Formatter;
46
43
  type FormatterType = import('stylelint').FormatterType;
47
- type isPathIgnored = (
48
- stylelint: Stylelint,
49
- filePath: string
50
- ) => Promise<boolean>;
51
44
  type AsyncTask = () => Promise<void>;
52
45
  type LintTask = (files: string | string[]) => Promise<LintResult[]>;
53
46
  type Worker = JestWorker & {
package/types/index.d.ts CHANGED
@@ -16,7 +16,7 @@ declare class StylelintWebpackPlugin {
16
16
  compiler: Compiler,
17
17
  options: Options,
18
18
  wanted: string[],
19
- exclude: string[]
19
+ exclude: string[],
20
20
  ): Promise<void>;
21
21
  startTime: number;
22
22
  prevTimestamps: Map<any, any>;
@@ -36,8 +36,8 @@ declare namespace StylelintWebpackPlugin {
36
36
  export { Compiler, Module, Options, FileSystemInfoEntry };
37
37
  }
38
38
  type Compiler = import('webpack').Compiler;
39
- type Options = import('./options').Options;
40
39
  type Module = import('webpack').Module;
40
+ type Options = import('./options').Options;
41
41
  type FileSystemInfoEntry = Partial<
42
42
  | {
43
43
  timestamp: number;
package/types/linter.d.ts CHANGED
@@ -1,18 +1,15 @@
1
- /// <reference types="stylelint" />
2
1
  export = linter;
3
2
  /**
4
3
  * @param {string|undefined} key
5
4
  * @param {Options} options
6
5
  * @param {Compilation} compilation
7
- * @returns {{stylelint: Stylelint, isPathIgnored: isPathIgnored, lint: Linter, report: Reporter, threads: number}}
6
+ * @returns {{lint: Linter, report: Reporter, threads: number}}
8
7
  */
9
8
  declare function linter(
10
9
  key: string | undefined,
11
10
  options: Options,
12
- compilation: Compilation
11
+ compilation: Compilation,
13
12
  ): {
14
- stylelint: Stylelint;
15
- isPathIgnored: getStylelint.isPathIgnored;
16
13
  lint: Linter;
17
14
  report: Reporter;
18
15
  threads: number;
@@ -26,7 +23,6 @@ declare namespace linter {
26
23
  LinterResult,
27
24
  Formatter,
28
25
  FormatterType,
29
- isPathIgnored,
30
26
  Options,
31
27
  GenerateReport,
32
28
  Report,
@@ -37,16 +33,14 @@ declare namespace linter {
37
33
  }
38
34
  type Options = import('./options').Options;
39
35
  type Compilation = import('webpack').Compilation;
40
- type Stylelint = import('./getStylelint').Stylelint;
41
36
  type Linter = (files: string | string[]) => void;
42
37
  type Reporter = () => Promise<Report>;
43
- import getStylelint = require('./getStylelint');
44
38
  type Compiler = import('webpack').Compiler;
39
+ type Stylelint = import('./getStylelint').Stylelint;
45
40
  type LintResult = import('./getStylelint').LintResult;
46
41
  type LinterResult = import('./getStylelint').LinterResult;
47
42
  type Formatter = import('./getStylelint').Formatter;
48
43
  type FormatterType = import('./getStylelint').FormatterType;
49
- type isPathIgnored = import('./getStylelint').isPathIgnored;
50
44
  type GenerateReport = (compilation: Compilation) => Promise<void>;
51
45
  type Report = {
52
46
  errors?: StylelintError;
@@ -56,5 +56,5 @@ export function getOptions(pluginOptions: Options): Partial<PluginOptions>;
56
56
  * @returns {Partial<StylelintOptions>}
57
57
  */
58
58
  export function getStylelintOptions(
59
- pluginOptions: Options
59
+ pluginOptions: Options,
60
60
  ): Partial<StylelintOptions>;
package/types/utils.d.ts CHANGED
@@ -14,16 +14,16 @@
14
14
  }
15
15
  */
16
16
  export function arrify<T>(
17
- value: T
17
+ value: T,
18
18
  ): T extends null | undefined
19
19
  ? []
20
20
  : T extends string
21
- ? [string]
22
- : T extends readonly unknown[]
23
- ? T
24
- : T extends Iterable<infer T_1>
25
- ? T_1[]
26
- : [T];
21
+ ? [string]
22
+ : T extends readonly unknown[]
23
+ ? T
24
+ : T extends Iterable<infer T_1>
25
+ ? T_1[]
26
+ : [T];
27
27
  /**
28
28
  * @param {string|string[]} files
29
29
  * @param {string} context
@@ -37,7 +37,7 @@ export function parseFiles(files: string | string[], context: string): string[];
37
37
  */
38
38
  export function parseFoldersToGlobs(
39
39
  patterns: string | string[],
40
- extensions?: string | string[]
40
+ extensions?: string | string[],
41
41
  ): string[];
42
42
  /**
43
43
  *