1 |
|
2 | 'use strict';
|
3 |
|
4 | const _ = require('lodash');
|
5 | const augmentConfig = require('./augmentConfig');
|
6 | const createStylelintResult = require('./createStylelintResult');
|
7 | const getConfigForFile = require('./getConfigForFile');
|
8 | const getPostcssResult = require('./getPostcssResult');
|
9 | const isPathIgnored = require('./isPathIgnored');
|
10 | const lintSource = require('./lintSource');
|
11 | const path = require('path');
|
12 | const { cosmiconfig } = require('cosmiconfig');
|
13 |
|
14 | const IS_TEST = process.env.NODE_ENV === 'test';
|
15 | const STOP_DIR = IS_TEST ? path.resolve(__dirname, '..') : undefined;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | module.exports = function(options /*: stylelint$options*/) /*: stylelint$internalApi*/ {
|
27 | options = options || {};
|
28 |
|
29 | const stylelint = { _options: options };
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | stylelint._fullExplorer = cosmiconfig('stylelint', {
|
35 | transform: _.partial(
|
36 | augmentConfig.augmentConfigFull,
|
37 | (stylelint),
|
38 | ),
|
39 | stopDir: STOP_DIR,
|
40 | });
|
41 |
|
42 | stylelint._extendExplorer = cosmiconfig(null, {
|
43 | transform: _.partial(
|
44 | augmentConfig.augmentConfigExtended,
|
45 | (stylelint),
|
46 | ),
|
47 | stopDir: STOP_DIR,
|
48 | });
|
49 |
|
50 | stylelint._specifiedConfigCache = new Map();
|
51 | stylelint._postcssResultCache = new Map();
|
52 | stylelint._createStylelintResult = _.partial(
|
53 | createStylelintResult,
|
54 | (stylelint),
|
55 | );
|
56 | stylelint._getPostcssResult = _.partial(
|
57 | getPostcssResult,
|
58 | (stylelint),
|
59 | );
|
60 | stylelint._lintSource = _.partial(lintSource, (stylelint));
|
61 |
|
62 | stylelint.getConfigForFile = _.partial(
|
63 | getConfigForFile,
|
64 | (stylelint),
|
65 | );
|
66 | stylelint.isPathIgnored = _.partial(
|
67 | isPathIgnored,
|
68 | (stylelint),
|
69 | );
|
70 |
|
71 | return (stylelint);
|
72 | };
|