Skip to content

Commit 9523f0c

Browse files
chore: update plugin (#230)
* chore: update plugin * test: fix output report * test: fix * test: fix * test: fix * test: fix * test: fix * test: skip watch test for now * ci: update node version * ci: update node version * fix: threads * ci: disable temporarly windows * style: formatting * style: formatting * ci: debug on windows * fix: always normalize path * style: formatting * test: normalize path * ci: enable ubuntu-latest and macos-latest * test: watch * style: use `fs-extra` * style: formatting * test: fix watch test * test: fix * test: debug watch * test: fix * fix: get files on watch mode * fix: get files * fix: get files using `fast-glob` * fix: export * test: increase coverage * test: fix context path * fix: changed files * test: skip watch * test: increase coverage
1 parent 0302cd7 commit 9523f0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+23726
-7152
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
module.exports = {
22
root: true,
33
extends: ['@webpack-contrib/eslint-config-webpack', 'prettier'],
4+
rules: {
5+
'global-require': 'off',
6+
'import/no-dynamic-require': 'off',
7+
},
48
};

.github/workflows/nodejs.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
fetch-depth: 0
3131

3232
- name: Use Node.js ${{ env.node-version }}
33-
uses: actions/setup-node@v1
33+
uses: actions/setup-node@v2
3434
with:
3535
node-version: ${{ env.node-version }}
3636

@@ -43,8 +43,8 @@ jobs:
4343
- name: Lint
4444
run: npm run lint
4545

46-
#- name: Security audit
47-
# run: npm run security
46+
- name: Security audit
47+
run: npm run security
4848

4949
- name: Check commit message
5050
uses: wagoid/commitlint-github-action@v1
@@ -68,7 +68,7 @@ jobs:
6868
- uses: actions/checkout@v2
6969

7070
- name: Use Node.js ${{ matrix.node-version }}
71-
uses: actions/setup-node@v1
71+
uses: actions/setup-node@v2
7272
with:
7373
node-version: ${{ matrix.node-version }}
7474

.husky/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

README.md

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,26 @@ Specify the config file location to be used by `stylelint`.
6161

6262
A string indicating the root of your files.
6363

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+
6478
### `files`
6579

6680
- Type: `String|Array[String]`
67-
- Default: `'**/*.(s(c|a)ss|css)'`
81+
- Default: `null`
6882

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`.
7084

7185
### `fix`
7286

@@ -96,6 +110,13 @@ Lint only changed files, skip lint on start.
96110

97111
Path to `stylelint` instance that will be used for linting.
98112

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+
99120
### Errors and Warning
100121

101122
**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
106127
- Type: `Boolean`
107128
- Default: `false`
108129

109-
Will always return errors, if set to `true`.
130+
The errors found will always be emitted, to disable set to `false`.
110131

111132
#### `emitWarning`
112133

113134
- Type: `Boolean`
114135
- Default: `false`
115136

116-
Will always return warnings, if set to `true`.
137+
The warnings found will always be emitted, to disable set to `false`.
117138

118139
#### `failOnError`
119140

120141
- Type: `Boolean`
121142
- Default: `false`
122143

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`.
124145

125146
#### `failOnWarning`
126147

@@ -136,6 +157,22 @@ Will cause the module build to fail if there are any warnings, if set to `true`.
136157

137158
Will process and report errors only and ignore warnings, if set to `true`.
138159

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+
139176
## Changelog
140177

141178
[Changelog](CHANGELOG.md)

declarations/LintDirtyModulesPlugin.d.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

declarations/StylelintError.d.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,2 @@
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-
};
1+
export default StylelintError;
2+
declare class StylelintError extends Error {}

declarations/cjs.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
declare const _exports: typeof import('.').default;
1+
declare const _exports: typeof plugin.default;
22
export = _exports;
3+
import plugin = require('./index');

declarations/getOptions.d.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

declarations/getStylelint.d.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/** @typedef {import('stylelint')} Stylelint */
2+
/** @typedef {import('stylelint').LintResult} LintResult */
3+
/** @typedef {import('./options').Options} Options */
4+
/** @typedef {() => Promise<void>} AsyncTask */
5+
/** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */
6+
/** @typedef {JestWorker & {lintFiles: LintTask}} Worker */
7+
/** @typedef {{stylelint: Stylelint, lintFiles: LintTask, cleanup: AsyncTask, threads: number, }} Linter */
8+
/**
9+
* @param {Options} options
10+
* @returns {Linter}
11+
*/
12+
export function loadStylelint(options: Options): Linter;
13+
/**
14+
* @param {string|undefined} key
15+
* @param {number} poolSize
16+
* @param {Options} options
17+
* @returns {Linter}
18+
*/
19+
export function loadStylelintThreaded(
20+
key: string | undefined,
21+
poolSize: number,
22+
options: Options
23+
): Linter;
24+
/**
25+
* @param {string|undefined} key
26+
* @param {Options} options
27+
* @returns {Linter}
28+
*/
29+
export default function getStylelint(
30+
key: string | undefined,
31+
{ threads, ...options }: Options
32+
): Linter;
33+
export type Stylelint = typeof import('stylelint');
34+
export type LintResult = import('stylelint').LintResult;
35+
export type Options = import('./options').Options;
36+
export type AsyncTask = () => Promise<void>;
37+
export type LintTask = (files: string | string[]) => Promise<LintResult[]>;
38+
export type Worker = JestWorker & {
39+
lintFiles: LintTask;
40+
};
41+
export type Linter = {
42+
stylelint: Stylelint;
43+
lintFiles: LintTask;
44+
cleanup: AsyncTask;
45+
threads: number;
46+
};
47+
import JestWorker from 'jest-worker';

declarations/index.d.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
export default StylelintWebpackPlugin;
22
export type Compiler = import('webpack').Compiler;
3-
/** @typedef {import('webpack').Compiler} 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+
>;
411
declare class StylelintWebpackPlugin {
5-
constructor(options?: {});
6-
options: import('./getOptions').Options;
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>;
724
/**
825
* @param {Compiler} compiler
926
* @returns {void}
@@ -15,4 +32,17 @@ declare class StylelintWebpackPlugin {
1532
* @returns {string}
1633
*/
1734
getContext(compiler: Compiler): string;
35+
/**
36+
* @param {Compiler} compiler
37+
* @param {Module} module
38+
* @returns {string[]}
39+
*/
40+
getFiles({ fileTimestamps }: Compiler, { buildInfo }: Module): string[];
41+
/**
42+
* @param {Map<string, null | FileSystemInfoEntry | "ignore">} fileTimestamps
43+
* @returns {string[]}
44+
*/
45+
getChangedFiles(
46+
fileTimestamps: Map<string, 'ignore' | FileSystemInfoEntry | null>
47+
): string[];
1848
}

0 commit comments

Comments
 (0)