createStylelint.mjs 871 B

12345678910111213141516171819202122232425262728293031
  1. import process from 'node:process';
  2. import { cosmiconfig } from 'cosmiconfig';
  3. import FileCache from './utils/FileCache.mjs';
  4. import { augmentConfigExtended } from './augmentConfig.mjs';
  5. const IS_TEST = process.env.NODE_ENV === 'test';
  6. const STOP_DIR = IS_TEST ? process.cwd() : undefined;
  7. /**
  8. * @type {import('stylelint').PublicApi['_createLinter']}
  9. */
  10. export default function createStylelint(options = {}) {
  11. // [INSERT HERE] CommonJS deprecation code
  12. const cwd = options.cwd || process.cwd();
  13. return {
  14. _options: { ...options, cwd },
  15. _extendExplorer: cosmiconfig('', {
  16. transform: augmentConfigExtended(cwd),
  17. stopDir: STOP_DIR,
  18. searchStrategy: 'global', // for backward compatibility
  19. }),
  20. _specifiedConfigCache: new Map(),
  21. _postcssResultCache: new Map(),
  22. _fileCache: new FileCache(options.cacheLocation, options.cacheStrategy, cwd),
  23. };
  24. }