Support plugins field in config (#3584)
* Actually support plugins field in config * Resolve plugin parsers * Fix default from CLI for "plugins"master
parent
15a68394dd
commit
b63c669ed9
|
@ -443,10 +443,19 @@ const detailedOptionMap = detailedOptions.reduce(
|
|||
{}
|
||||
);
|
||||
|
||||
const apiDetailedOptionMap = detailedOptions.reduce(
|
||||
(current, option) =>
|
||||
option.forwardToApi && option.forwardToApi !== option.name
|
||||
? Object.assign(current, { [option.forwardToApi]: option })
|
||||
: current,
|
||||
{}
|
||||
);
|
||||
|
||||
module.exports = {
|
||||
categoryOrder,
|
||||
minimistOptions,
|
||||
detailedOptions,
|
||||
detailedOptionMap,
|
||||
apiDetailedOptionMap,
|
||||
usageSummary
|
||||
};
|
||||
|
|
|
@ -37,9 +37,12 @@ function getOptions(argv) {
|
|||
);
|
||||
}
|
||||
|
||||
function dashifyObject(object) {
|
||||
function cliifyOptions(object) {
|
||||
return Object.keys(object || {}).reduce((output, key) => {
|
||||
output[dashify(key)] = object[key];
|
||||
const apiOption = constant.apiDetailedOptionMap[key];
|
||||
const cliKey = apiOption ? apiOption.name : key;
|
||||
|
||||
output[dashify(cliKey)] = object[key];
|
||||
return output;
|
||||
}, {});
|
||||
}
|
||||
|
@ -202,8 +205,8 @@ function parseArgsToOptions(argv, overrideDefaults) {
|
|||
boolean: constant.minimistOptions.boolean,
|
||||
default: Object.assign(
|
||||
{},
|
||||
dashifyObject(apiDefaultOptions),
|
||||
dashifyObject(overrideDefaults)
|
||||
cliifyOptions(apiDefaultOptions),
|
||||
cliifyOptions(overrideDefaults)
|
||||
)
|
||||
})
|
||||
),
|
||||
|
@ -619,7 +622,10 @@ function normalizeConfig(type, rawConfig, options) {
|
|||
return;
|
||||
}
|
||||
|
||||
const option = constant.detailedOptionMap[key];
|
||||
let option = constant.detailedOptionMap[key];
|
||||
if (type === "api" && option === undefined) {
|
||||
option = constant.apiDetailedOptionMap[key];
|
||||
}
|
||||
|
||||
// unknown option
|
||||
if (option === undefined) {
|
||||
|
|
|
@ -44,6 +44,8 @@ function normalize(options) {
|
|||
const normalized = Object.assign({}, options || {});
|
||||
const filepath = normalized.filepath;
|
||||
|
||||
normalized.plugins = loadPlugins(normalized);
|
||||
|
||||
if (
|
||||
filepath &&
|
||||
!normalized.parentParser &&
|
||||
|
@ -52,7 +54,7 @@ function normalize(options) {
|
|||
const extension = path.extname(filepath);
|
||||
const filename = path.basename(filepath).toLowerCase();
|
||||
|
||||
const language = getSupportInfo().languages.find(
|
||||
const language = getSupportInfo(null, normalized).languages.find(
|
||||
language =>
|
||||
typeof language.since === "string" &&
|
||||
(language.extensions.indexOf(extension) > -1 ||
|
||||
|
@ -122,7 +124,6 @@ function normalize(options) {
|
|||
delete normalized.useFlowParser;
|
||||
}
|
||||
|
||||
normalized.plugins = loadPlugins(normalized);
|
||||
normalized.astFormat = resolveParser(normalized).astFormat;
|
||||
normalized.printer = getPrinter(normalized);
|
||||
|
||||
|
|
Loading…
Reference in New Issue