|
1 | 1 | import { isAbsolute, join } from 'path'; |
2 | 2 |
|
3 | | -import arrify from 'arrify'; |
4 | | - |
5 | 3 | import getOptions from './getOptions'; |
6 | 4 | import LintDirtyModulesPlugin from './LintDirtyModulesPlugin'; |
7 | 5 | import linter from './linter'; |
| 6 | +import { parseFiles } from './utils'; |
8 | 7 |
|
9 | 8 | class StylelintWebpackPlugin { |
10 | 9 | constructor(options = {}) { |
11 | 10 | this.options = getOptions(options); |
12 | 11 | } |
13 | 12 |
|
14 | 13 | apply(compiler) { |
15 | | - const context = this.getContext(compiler); |
16 | | - const options = { ...this.options }; |
| 14 | + const options = { |
| 15 | + ...this.options, |
| 16 | + files: parseFiles(this.options.files, this.getContext(compiler)), |
| 17 | + }; |
17 | 18 |
|
18 | | - options.files = arrify(options.files).map((file) => |
19 | | - join(context, '/', file).replace(/\\/g, '/') |
20 | | - ); |
| 19 | + // eslint-disable-next-line |
| 20 | + const { lint } = require(options.stylelintPath); |
21 | 21 |
|
22 | 22 | const plugin = { name: this.constructor.name }; |
23 | 23 |
|
24 | 24 | if (options.lintDirtyModulesOnly) { |
25 | | - const lintDirty = new LintDirtyModulesPlugin(compiler, options); |
| 25 | + const lintDirty = new LintDirtyModulesPlugin(lint, compiler, options); |
26 | 26 |
|
27 | 27 | /* istanbul ignore next */ |
28 | 28 | compiler.hooks.watchRun.tapAsync(plugin, (compilation, callback) => { |
29 | 29 | lintDirty.apply(compilation, callback); |
30 | 30 | }); |
31 | 31 | } else { |
32 | 32 | compiler.hooks.run.tapAsync(plugin, (compilation, callback) => { |
33 | | - linter(options, compilation, callback); |
| 33 | + linter(lint, options, compilation, callback); |
34 | 34 | }); |
35 | 35 |
|
36 | 36 | /* istanbul ignore next */ |
37 | 37 | compiler.hooks.watchRun.tapAsync(plugin, (compilation, callback) => { |
38 | | - linter(options, compilation, callback); |
| 38 | + linter(lint, options, compilation, callback); |
39 | 39 | }); |
40 | 40 | } |
41 | 41 | } |
|
0 commit comments