.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / getConfigForFile.js
1 /* @flow */
2 "use strict";
3 const augmentConfigFull = require("./augmentConfig").augmentConfigFull;
4 const configurationError = require("./utils/configurationError");
5 const path = require("path");
6
7 /*:: type configPromise = Promise<?{ config: stylelint$config, filepath: string }>*/
8
9 module.exports = function(
10   stylelint /*: stylelint$internalApi*/,
11   searchPath /*:: ?: string*/
12 ) /*: configPromise*/ {
13   searchPath = searchPath || process.cwd();
14
15   const optionsConfig = stylelint._options.config;
16
17   if (optionsConfig !== undefined) {
18     const cached /*: configPromise*/ = stylelint._specifiedConfigCache.get(
19       optionsConfig
20     );
21     if (cached) return cached;
22
23     // stylelint._fullExplorer (cosmiconfig) is already configured to
24     // run augmentConfigFull; but since we're making up the result here,
25     // we need to manually run the transform
26     const augmentedResult = augmentConfigFull(stylelint, {
27       config: optionsConfig,
28       // Add the extra path part so that we can get the directory without being
29       // confused
30       filepath: path.join(process.cwd(), "argument-config")
31     });
32     stylelint._specifiedConfigCache.set(optionsConfig, augmentedResult);
33     return augmentedResult;
34   }
35
36   return stylelint._fullExplorer
37     .load(searchPath, stylelint._options.configFile)
38     .then(config => {
39       // If no config was found, try looking from process.cwd
40       if (!config) return stylelint._fullExplorer.load(process.cwd());
41       return config;
42     })
43     .then(config => {
44       if (!config) {
45         const ending = searchPath ? ` for ${searchPath}` : "";
46         throw configurationError(`No configuration provided${ending}`);
47       }
48       return config;
49     });
50 };