1 |
|
2 | "use strict";
|
3 |
|
4 | const augmentConfigFull = require("./augmentConfig").augmentConfigFull;
|
5 | const configurationError = require("./utils/configurationError");
|
6 | const path = require("path");
|
7 |
|
8 |
|
9 |
|
10 | module.exports = function(
|
11 | stylelint /*: stylelint$internalApi*/,
|
12 | searchPath /*:: ?: string*/
|
13 | ) /*: configPromise*/ {
|
14 | searchPath = searchPath || process.cwd();
|
15 |
|
16 | const optionsConfig = stylelint._options.config;
|
17 |
|
18 | if (optionsConfig !== undefined) {
|
19 | const cached = stylelint._specifiedConfigCache.get(
|
20 | optionsConfig
|
21 | );
|
22 |
|
23 | if (cached) return cached;
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | const augmentedResult = augmentConfigFull(stylelint, {
|
29 | config: optionsConfig,
|
30 |
|
31 |
|
32 | filepath: path.join(process.cwd(), "argument-config")
|
33 | });
|
34 |
|
35 | stylelint._specifiedConfigCache.set(optionsConfig, augmentedResult);
|
36 |
|
37 | return augmentedResult;
|
38 | }
|
39 |
|
40 | const searchForConfig = stylelint._options.configFile
|
41 | ? stylelint._fullExplorer.load(stylelint._options.configFile)
|
42 | : stylelint._fullExplorer.search(searchPath);
|
43 |
|
44 | return searchForConfig
|
45 | .then(config => {
|
46 |
|
47 | if (!config) return stylelint._fullExplorer.search(process.cwd());
|
48 |
|
49 | return config;
|
50 | })
|
51 | .then(config => {
|
52 | if (!config) {
|
53 | const ending = searchPath ? ` for ${searchPath}` : "";
|
54 |
|
55 | throw configurationError(`No configuration provided${ending}`);
|
56 | }
|
57 |
|
58 | return config;
|
59 | });
|
60 | };
|