createStylelint.js 982 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. const { cosmiconfig } = require('cosmiconfig');
  3. const augmentConfig = require('./augmentConfig');
  4. const FileCache = require('./utils/FileCache');
  5. const IS_TEST = process.env.NODE_ENV === 'test';
  6. const STOP_DIR = IS_TEST ? process.cwd() : undefined;
  7. /** @typedef {import('stylelint').InternalApi} StylelintInternalApi */
  8. /**
  9. * The stylelint "internal API" is passed among functions
  10. * so that methods on a stylelint instance can invoke
  11. * each other while sharing options and caches.
  12. *
  13. * @type {import('stylelint')['createLinter']}
  14. */
  15. module.exports = function createStylelint(options = {}) {
  16. const cwd = options.cwd || process.cwd();
  17. return {
  18. _options: { ...options, cwd },
  19. _extendExplorer: cosmiconfig('', {
  20. transform: augmentConfig.augmentConfigExtended(cwd),
  21. stopDir: STOP_DIR,
  22. }),
  23. _specifiedConfigCache: new Map(),
  24. _postcssResultCache: new Map(),
  25. _fileCache: new FileCache(options.cacheLocation, options.cacheStrategy, cwd),
  26. };
  27. };