3 const augmentConfigFull = require("./augmentConfig").augmentConfigFull;
4 const configurationError = require("./utils/configurationError");
5 const path = require("path");
7 /*:: type configPromise = Promise<?{ config: stylelint$config, filepath: string }>*/
9 module.exports = function(
10 stylelint /*: stylelint$internalApi*/,
11 searchPath /*:: ?: string*/
12 ) /*: configPromise*/ {
13 searchPath = searchPath || process.cwd();
15 const optionsConfig = stylelint._options.config;
17 if (optionsConfig !== undefined) {
18 const cached /*: configPromise*/ = stylelint._specifiedConfigCache.get(
21 if (cached) return cached;
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
30 filepath: path.join(process.cwd(), "argument-config")
32 stylelint._specifiedConfigCache.set(optionsConfig, augmentedResult);
33 return augmentedResult;
36 return stylelint._fullExplorer
37 .load(searchPath, stylelint._options.configFile)
39 // If no config was found, try looking from process.cwd
40 if (!config) return stylelint._fullExplorer.load(process.cwd());
45 const ending = searchPath ? ` for ${searchPath}` : "";
46 throw configurationError(`No configuration provided${ending}`);