1 | 'use strict';
|
2 |
|
3 | const createStylelint = require('./createStylelint');
|
4 | const path = require('path');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | module.exports = async function resolveConfig(
|
20 | filePath,
|
21 | { cwd = process.cwd(), config, configBasedir, configFile } = {},
|
22 | ) {
|
23 | if (!filePath) {
|
24 | return undefined;
|
25 | }
|
26 |
|
27 | const stylelint = createStylelint({
|
28 | config,
|
29 | configFile,
|
30 | configBasedir,
|
31 | cwd,
|
32 | });
|
33 |
|
34 | const absoluteFilePath = !path.isAbsolute(filePath)
|
35 | ? path.join(cwd, filePath)
|
36 | : path.normalize(filePath);
|
37 |
|
38 | const configSearchPath = stylelint._options.configFile || absoluteFilePath;
|
39 |
|
40 | const resolved = await stylelint.getConfigForFile(configSearchPath, absoluteFilePath);
|
41 |
|
42 | if (!resolved) {
|
43 | return undefined;
|
44 | }
|
45 |
|
46 | return resolved.config;
|
47 | };
|