Skip to content

Commit 5a24f5b

Browse files
fix: path ignored
1 parent 7d634cf commit 5a24f5b

File tree

16 files changed

+1784
-11708
lines changed

16 files changed

+1784
-11708
lines changed

package-lock.json

Lines changed: 1689 additions & 11658 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,45 +48,45 @@
4848
},
4949
"dependencies": {
5050
"globby": "^11.1.0",
51-
"jest-worker": "^29.2.1",
51+
"jest-worker": "^29.3.1",
5252
"micromatch": "^4.0.5",
5353
"normalize-path": "^3.0.0",
5454
"schema-utils": "^4.0.0"
5555
},
5656
"devDependencies": {
57-
"@babel/cli": "^7.19.3",
58-
"@babel/core": "^7.19.6",
59-
"@babel/preset-env": "^7.19.4",
60-
"@commitlint/cli": "^17.2.0",
61-
"@commitlint/config-conventional": "^17.2.0",
57+
"@babel/cli": "^7.20.7",
58+
"@babel/core": "^7.20.7",
59+
"@babel/preset-env": "^7.20.2",
60+
"@commitlint/cli": "^17.3.0",
61+
"@commitlint/config-conventional": "^17.3.0",
6262
"@types/file-entry-cache": "^5.0.2",
6363
"@types/fs-extra": "^9.0.13",
6464
"@types/micromatch": "^4.0.2",
6565
"@types/normalize-path": "^3.0.0",
6666
"@types/webpack": "^5.28.0",
6767
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
6868
"babel-eslint": "^10.1.0",
69-
"babel-jest": "^29.2.2",
69+
"babel-jest": "^29.3.1",
7070
"chokidar": "^3.5.3",
7171
"cross-env": "^7.0.3",
72-
"cspell": "^6.14.3",
72+
"cspell": "^6.18.1",
7373
"del": "^6.1.1",
7474
"del-cli": "^4.0.1",
75-
"eslint": "^8.26.0",
75+
"eslint": "^8.30.0",
7676
"eslint-config-prettier": "^8.5.0",
7777
"eslint-plugin-import": "^2.26.0",
7878
"file-loader": "^6.2.0",
7979
"fs-extra": "^10.1.0",
80-
"husky": "^8.0.1",
81-
"jest": "^29.2.2",
82-
"lint-staged": "^13.0.3",
80+
"husky": "^8.0.2",
81+
"jest": "^29.3.1",
82+
"lint-staged": "^13.1.0",
8383
"npm-run-all": "^4.1.5",
84-
"postcss-scss": "^4.0.5",
85-
"prettier": "^2.7.1",
84+
"postcss-scss": "^4.0.6",
85+
"prettier": "^2.8.1",
8686
"standard-version": "^9.5.0",
87-
"stylelint": "^14.14.0",
88-
"typescript": "^4.8.4",
89-
"webpack": "^5.74.0"
87+
"stylelint": "^14.16.1",
88+
"typescript": "^4.9.4",
89+
"webpack": "^5.75.0"
9090
},
9191
"keywords": [
9292
"stylelint",

src/getStylelint.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ const cache = {};
1313
/** @typedef {import('stylelint')} Stylelint */
1414
/** @typedef {import('stylelint').LintResult} LintResult */
1515
/** @typedef {import('./options').Options} Options */
16+
/** @typedef {(stylelint: Stylelint, filePath: string) => Promise<boolean>} isPathIgnored */
1617
/** @typedef {() => Promise<void>} AsyncTask */
1718
/** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */
18-
/** @typedef {{api: import('stylelint').InternalApi, stylelint: Stylelint, lintFiles: LintTask, cleanup: AsyncTask, threads: number, }} Linter */
19+
/** @typedef {{stylelint: Stylelint, isPathIgnored: isPathIgnored, lintFiles: LintTask, cleanup: AsyncTask, threads: number }} Linter */
1920
/** @typedef {JestWorker & {lintFiles: LintTask}} Worker */
2021

2122
/**
@@ -26,9 +27,23 @@ function loadStylelint(options) {
2627
const stylelintOptions = getStylelintOptions(options);
2728
const stylelint = setup(options, stylelintOptions);
2829

30+
/** @type {isPathIgnored} */
31+
let isPathIgnored;
32+
33+
try {
34+
isPathIgnored = require(`${options.stylelintPath}/lib/isPathIgnored`);
35+
} catch (e) {
36+
try {
37+
// @ts-ignore
38+
isPathIgnored = require('stylelint/lib/isPathIgnored');
39+
} catch (_) {
40+
isPathIgnored = () => Promise.resolve(false);
41+
}
42+
}
43+
2944
return {
3045
stylelint,
31-
api: stylelint.createLinter(stylelintOptions),
46+
isPathIgnored,
3247
lintFiles,
3348
cleanup: async () => {},
3449
threads: 1,

src/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,14 @@ class StylelintWebpackPlugin {
9090
}
9191

9292
compiler.hooks.thisCompilation.tap(this.key, (compilation) => {
93+
/** @type {import('stylelint')} */
94+
let stylelint;
95+
9396
/** @type {import('./linter').Linter} */
9497
let lint;
9598

96-
/** @type {import('stylelint').InternalApi} */
97-
let api;
99+
/** @type {import('./linter').isPathIgnored} */
100+
let isPathIgnored;
98101

99102
/** @type {import('./linter').Reporter} */
100103
let report;
@@ -103,7 +106,7 @@ class StylelintWebpackPlugin {
103106
let threads;
104107

105108
try {
106-
({ lint, api, report, threads } = linter(
109+
({ stylelint, lint, isPathIgnored, report, threads } = linter(
107110
this.key,
108111
options,
109112
compilation
@@ -127,7 +130,7 @@ class StylelintWebpackPlugin {
127130
: globby.sync(wanted, { dot: true, ignore: exclude })
128131
).map(async (file) => {
129132
try {
130-
return (await api.isPathIgnored(file)) ? false : file;
133+
return (await isPathIgnored(stylelint, file)) ? false : file;
131134
} catch (e) {
132135
return file;
133136
}

src/linter.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const { arrify } = require('./utils');
77
/** @typedef {import('stylelint')} Stylelint */
88
/** @typedef {import('stylelint').LintResult} LintResult */
99
/** @typedef {import('stylelint').LinterResult} LinterResult */
10-
/** @typedef {import('stylelint').InternalApi} InternalApi */
1110
/** @typedef {import('stylelint').Formatter} Formatter */
1211
/** @typedef {import('stylelint').FormatterType} FormatterType */
1312
/** @typedef {import('webpack').Compiler} Compiler */
1413
/** @typedef {import('webpack').Compilation} Compilation */
1514
/** @typedef {import('./options').Options} Options */
15+
/** @typedef {import('./getStylelint').isPathIgnored} isPathIgnored */
1616
/** @typedef {(compilation: Compilation) => Promise<void>} GenerateReport */
1717
/** @typedef {{errors?: StylelintError, warnings?: StylelintError, generateReportAsset?: GenerateReport}} Report */
1818
/** @typedef {() => Promise<Report>} Reporter */
@@ -26,14 +26,14 @@ const resultStorage = new WeakMap();
2626
* @param {string|undefined} key
2727
* @param {Options} options
2828
* @param {Compilation} compilation
29-
* @returns {{api: InternalApi, lint: Linter, report: Reporter, threads: number}}
29+
* @returns {{stylelint: Stylelint, isPathIgnored: isPathIgnored, lint: Linter, report: Reporter, threads: number}}
3030
*/
3131
function linter(key, options, compilation) {
3232
/** @type {Stylelint} */
3333
let stylelint;
3434

35-
/** @type {InternalApi} */
36-
let api;
35+
/** @type {isPathIgnored} */
36+
let isPathIgnored;
3737

3838
/** @type {(files: string|string[]) => Promise<LintResult[]>} */
3939
let lintFiles;
@@ -50,7 +50,7 @@ function linter(key, options, compilation) {
5050
const crossRunResultStorage = getResultStorage(compilation);
5151

5252
try {
53-
({ stylelint, api, lintFiles, cleanup, threads } = getStylelint(
53+
({ stylelint, isPathIgnored, lintFiles, cleanup, threads } = getStylelint(
5454
key,
5555
options
5656
));
@@ -59,8 +59,9 @@ function linter(key, options, compilation) {
5959
}
6060

6161
return {
62+
stylelint,
6263
lint,
63-
api,
64+
isPathIgnored,
6465
report,
6566
threads,
6667
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
display: block;
3+
}

test/fixtures/stylelint-path/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require('file-loader!./test.scss');
2+
require('file-loader!./ignore.scss');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
display: block;
3+
}

test/mock/stylelint/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,4 @@ module.exports = {
2424
],
2525
};
2626
},
27-
28-
createLinter() {
29-
return {
30-
isPathIgnored() {
31-
return false;
32-
},
33-
};
34-
},
3527
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param {import('stylelint')} stylelint
3+
* @param {string} filePath
4+
* @returns {Promise<boolean>}
5+
*/
6+
function isPathIgnored(stylelint, filePath) {
7+
return new Promise((resolve) => {
8+
resolve(filePath.endsWith('ignore.scss'));
9+
});
10+
}
11+
12+
module.exports = isPathIgnored;

0 commit comments

Comments
 (0)