You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
825 B
40 lines
825 B
|
2 years ago
|
'use strict';
|
||
|
|
|
||
|
|
const path = require('path');
|
||
|
|
|
||
|
|
const createStylelint = require('./createStylelint');
|
||
|
|
const getConfigForFile = require('./getConfigForFile');
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @type {import('stylelint')['resolveConfig']}
|
||
|
|
*/
|
||
|
|
module.exports = async function resolveConfig(
|
||
|
|
filePath,
|
||
|
|
{ cwd = process.cwd(), config, configBasedir, configFile } = {},
|
||
|
|
) {
|
||
|
|
if (!filePath) {
|
||
|
|
return undefined;
|
||
|
|
}
|
||
|
|
|
||
|
|
const stylelint = createStylelint({
|
||
|
|
config,
|
||
|
|
configFile,
|
||
|
|
configBasedir,
|
||
|
|
cwd,
|
||
|
|
});
|
||
|
|
|
||
|
|
const absoluteFilePath = !path.isAbsolute(filePath)
|
||
|
|
? path.join(cwd, filePath)
|
||
|
|
: path.normalize(filePath);
|
||
|
|
|
||
|
|
const configSearchPath = stylelint._options.configFile || absoluteFilePath;
|
||
|
|
|
||
|
|
const resolved = await getConfigForFile(stylelint, configSearchPath, absoluteFilePath);
|
||
|
|
|
||
|
|
if (!resolved) {
|
||
|
|
return undefined;
|
||
|
|
}
|
||
|
|
|
||
|
|
return resolved.config;
|
||
|
|
};
|