resolveConfig.mjs 861 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { isAbsolute, join, normalize } from 'node:path';
  2. import process from 'node:process';
  3. import createStylelint from './createStylelint.mjs';
  4. import getConfigForFile from './getConfigForFile.mjs';
  5. /**
  6. * @type {import('stylelint').PublicApi['resolveConfig']}
  7. */
  8. export default async function resolveConfig(
  9. filePath,
  10. {
  11. cwd = process.cwd(),
  12. config = undefined,
  13. configBasedir = undefined,
  14. configFile = undefined,
  15. } = {},
  16. ) {
  17. if (!filePath) {
  18. return undefined;
  19. }
  20. const stylelint = createStylelint({
  21. config,
  22. configFile,
  23. configBasedir,
  24. cwd,
  25. });
  26. const absoluteFilePath = !isAbsolute(filePath) ? join(cwd, filePath) : normalize(filePath);
  27. const resolved = await getConfigForFile({
  28. stylelint,
  29. searchPath: absoluteFilePath,
  30. filePath: absoluteFilePath,
  31. });
  32. if (!resolved) {
  33. return undefined;
  34. }
  35. return resolved.config;
  36. }