Upgrade cosmiconfig to v3, remove hardcoded combinatoric problem (#2843)

* Upgrade cosmiconfig to v3, remove hardcoded combinatoric problem

* Fix indendation change from 1.7

* Ensure default value for useCache is true

* Pin mem version
master
Lucas Azzola 2017-09-16 20:24:08 +10:00 committed by GitHub
parent 2c59fb2f07
commit 48899289da
5 changed files with 35 additions and 34 deletions

View File

@ -14,7 +14,7 @@
"babel-code-frame": "7.0.0-alpha.12",
"babylon": "7.0.0-beta.23",
"chalk": "2.1.0",
"cosmiconfig": "git://github.com/davidtheclark/cosmiconfig.git#6eb3cc85d3a435e6b9e252b341e601960312f410",
"cosmiconfig": "3.0.0",
"dashify": "0.2.2",
"diff": "3.2.0",
"esutils": "2.0.2",
@ -25,6 +25,7 @@
"ignore": "^3.3.3",
"jest-docblock": "21.1.0",
"jest-validate": "21.1.0",
"mem": "1.1.0",
"minimatch": "3.0.4",
"minimist": "1.2.0",
"parse5": "3.0.2",

View File

@ -138,7 +138,7 @@ function getOptionsOrDie(argv, filePath) {
try {
return argv["config"] === false
? null
: resolver.resolveConfig.sync(filePath);
: resolver.resolveConfig.sync(filePath, { config: argv["config"] });
} catch (error) {
console.error("Error: Invalid configuration file.");
console.error(error.message);

View File

@ -493,9 +493,9 @@ function printNumber(rawNumber) {
function maybeToLowerCase(value) {
return value.includes("$") ||
value.includes("@") ||
value.includes("#") ||
value.startsWith("--")
value.includes("@") ||
value.includes("#") ||
value.startsWith("--")
? value
: value.toLowerCase();
}

View File

@ -2,40 +2,48 @@
const cosmiconfig = require("cosmiconfig");
const minimatch = require("minimatch");
const mem = require("mem");
const asyncWithCache = cosmiconfig("prettier");
const asyncNoCache = cosmiconfig("prettier", { cache: false });
const syncWithCache = cosmiconfig("prettier", { sync: true });
const syncNoCache = cosmiconfig("prettier", { cache: false, sync: true });
const getExplorerMemoized = mem(opts =>
cosmiconfig("prettier", { sync: opts.sync, cache: opts.cache })
);
/** @param {{ cache: boolean, sync: boolean }} opts */
function getLoadFunction(opts) {
// Normalize opts before passing to a memoized function
opts = Object.assign({ sync: false, cache: false }, opts);
return getExplorerMemoized(opts).load;
}
function resolveConfig(filePath, opts) {
const useCache = !(opts && opts.useCache === false);
return (useCache ? asyncWithCache : asyncNoCache)
.load(filePath)
.then(result => {
return !result ? null : mergeOverrides(result.config, filePath);
});
opts = Object.assign({ useCache: true }, opts);
const load = getLoadFunction({ cache: !!opts.useCache, sync: false });
return load(filePath, opts.config).then(result => {
return !result ? null : mergeOverrides(result.config, filePath);
});
}
resolveConfig.sync = (filePath, opts) => {
const useCache = !(opts && opts.useCache === false);
const result = (useCache ? syncWithCache : syncNoCache).load(filePath);
opts = Object.assign({ useCache: true }, opts);
const load = getLoadFunction({ cache: !!opts.useCache, sync: true });
const result = load(filePath, opts.config);
return !result ? null : mergeOverrides(result.config, filePath);
};
function clearCache() {
syncWithCache.clearCaches();
asyncWithCache.clearCaches();
mem.clear(getExplorerMemoized);
}
function resolveConfigFile(filePath) {
return asyncNoCache.load(filePath).then(result => {
const load = getLoadFunction({ sync: false });
return load(filePath).then(result => {
return result ? result.filepath : null;
});
}
resolveConfigFile.sync = filePath => {
const result = syncNoCache.load(filePath);
const load = getLoadFunction({ sync: true });
const result = load(filePath);
return result ? result.filepath : null;
};

View File

@ -1056,17 +1056,13 @@ 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@git://github.com/davidtheclark/cosmiconfig.git#6eb3cc85d3a435e6b9e252b341e601960312f410":
version "2.2.2"
resolved "git://github.com/davidtheclark/cosmiconfig.git#6eb3cc85d3a435e6b9e252b341e601960312f410"
cosmiconfig@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-3.0.0.tgz#9c465e02f5a7cc6e8f7e5975fce4a1b712d7d936"
dependencies:
is-directory "^0.3.1"
is-promise "^2.1.0"
js-yaml "^3.9.0"
minimist "^1.2.0"
os-homedir "^1.0.1"
parse-json "^2.2.0"
please-upgrade-node "^3.0.1"
require-from-string "^1.1.0"
create-ecdh@^4.0.0:
@ -2718,7 +2714,7 @@ markdown-toc@1.1.0:
repeat-string "^1.6.1"
strip-color "^0.1.0"
mem@^1.1.0:
mem@1.1.0, mem@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/mem/-/mem-1.1.0.tgz#5edd52b485ca1d900fe64895505399a0dfa45f76"
dependencies:
@ -2980,7 +2976,7 @@ os-browserify@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/os-browserify/-/os-browserify-0.2.1.tgz#63fc4ccee5d2d7763d26bbf8601078e6c2e0044f"
os-homedir@^1.0.0, os-homedir@^1.0.1:
os-homedir@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3"
@ -3162,10 +3158,6 @@ pkg-dir@^1.0.0:
dependencies:
find-up "^1.0.0"
please-upgrade-node@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.0.1.tgz#0a681f2c18915e5433a5ca2cd94e0b8206a782db"
pluralize@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-4.0.0.tgz#59b708c1c0190a2f692f1c7618c446b052fd1762"