resolveConfig.cjs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // NOTICE: This file is generated by Rollup. To modify it,
  2. // please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
  3. 'use strict';
  4. const path = require('node:path');
  5. const process = require('node:process');
  6. const createStylelint = require('./createStylelint.cjs');
  7. const getConfigForFile = require('./getConfigForFile.cjs');
  8. /**
  9. * @type {import('stylelint').PublicApi['resolveConfig']}
  10. */
  11. async function resolveConfig(
  12. filePath,
  13. {
  14. cwd = process.cwd(),
  15. config = undefined,
  16. configBasedir = undefined,
  17. configFile = undefined,
  18. } = {},
  19. ) {
  20. if (!filePath) {
  21. return undefined;
  22. }
  23. const stylelint = createStylelint({
  24. config,
  25. configFile,
  26. configBasedir,
  27. cwd,
  28. });
  29. const absoluteFilePath = !path.isAbsolute(filePath) ? path.join(cwd, filePath) : path.normalize(filePath);
  30. const resolved = await getConfigForFile({
  31. stylelint,
  32. searchPath: absoluteFilePath,
  33. filePath: absoluteFilePath,
  34. });
  35. if (!resolved) {
  36. return undefined;
  37. }
  38. return resolved.config;
  39. }
  40. module.exports = resolveConfig;