resolveConfig.js 825 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. const path = require('path');
  3. const createStylelint = require('./createStylelint');
  4. const getConfigForFile = require('./getConfigForFile');
  5. /**
  6. * @type {import('stylelint')['resolveConfig']}
  7. */
  8. module.exports = async function resolveConfig(
  9. filePath,
  10. { cwd = process.cwd(), config, configBasedir, configFile } = {},
  11. ) {
  12. if (!filePath) {
  13. return undefined;
  14. }
  15. const stylelint = createStylelint({
  16. config,
  17. configFile,
  18. configBasedir,
  19. cwd,
  20. });
  21. const absoluteFilePath = !path.isAbsolute(filePath)
  22. ? path.join(cwd, filePath)
  23. : path.normalize(filePath);
  24. const configSearchPath = stylelint._options.configFile || absoluteFilePath;
  25. const resolved = await getConfigForFile(stylelint, configSearchPath, absoluteFilePath);
  26. if (!resolved) {
  27. return undefined;
  28. }
  29. return resolved.config;
  30. };