From 3eed1933e12b1316e6b1d63c90ca76c119b9e7f4 Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Thu, 27 Jul 2017 21:59:57 +1000 Subject: [PATCH] Don't pass config path through to cosmiconfig (#2547) --- bin/prettier.js | 8 ++++++-- package.json | 2 +- src/resolve-config.js | 22 ++++++---------------- yarn.lock | 6 +++--- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/bin/prettier.js b/bin/prettier.js index 2d932e8f1..4e51517af 100755 --- a/bin/prettier.js +++ b/bin/prettier.js @@ -108,8 +108,12 @@ if (argv["find-config-path"] && filepatterns.length) { } function getOptionsForFile(filePath) { - return resolver - .resolveConfig(filePath, { configFile: argv["config"] }) + const optionsPromise = + argv["config"] === false + ? Promise.resolve(null) + : resolver.resolveConfig(filePath); + + return optionsPromise .then(options => { const parsedArgs = minimist(args, { boolean: booleanOptionNames, diff --git a/package.json b/package.json index 639ee8444..8d045ab4f 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "babel-code-frame": "7.0.0-alpha.12", "babylon": "7.0.0-beta.17", "chalk": "2.0.1", - "cosmiconfig": "2.1.3", + "cosmiconfig": "2.2.2", "dashify": "0.2.2", "diff": "3.2.0", "esutils": "2.0.2", diff --git a/src/resolve-config.js b/src/resolve-config.js index a84507fed..9acbdd734 100644 --- a/src/resolve-config.js +++ b/src/resolve-config.js @@ -8,26 +8,16 @@ const withCache = cosmiconfig("prettier"); const noCache = cosmiconfig("prettier", { cache: false }); function resolveConfig(filePath, opts) { - if (opts && opts.configFile === false) { - // do not look for a config file - return Promise.resolve(null); - } - const useCache = !(opts && opts.useCache === false); const fileDir = filePath ? path.dirname(filePath) : undefined; - return ( - (useCache ? withCache : noCache) - // https://github.com/davidtheclark/cosmiconfig/pull/68 - .load(fileDir, opts && opts.configFile) - .then(result => { - if (!result) { - return null; - } + return (useCache ? withCache : noCache).load(fileDir).then(result => { + if (!result) { + return null; + } - return mergeOverrides(result.config, filePath); - }) - ); + return mergeOverrides(result.config, filePath); + }); } function clearCache() { diff --git a/yarn.lock b/yarn.lock index cd49c02e3..091dd1639 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1020,9 +1020,9 @@ core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" -cosmiconfig@2.1.3: - version "2.1.3" - resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-2.1.3.tgz#952771eb0dddc1cb3fa2f6fbe51a522e93b3ee0a" +cosmiconfig@2.2.2: + version "2.2.2" + resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-2.2.2.tgz#6173cebd56fac042c1f4390edf7af6c07c7cb892" dependencies: is-directory "^0.3.1" js-yaml "^3.4.3"