Standardlize plugin/preset result object.
This commit is contained in:
@@ -25,18 +25,18 @@ export function resolvePreset(name: string, dirname: string): string|null {
|
||||
return null;
|
||||
}
|
||||
|
||||
export function loadPlugin(name: string, dirname: string): { filepath: string, plugin: mixed } {
|
||||
export function loadPlugin(name: string, dirname: string): { filepath: string, value: mixed } {
|
||||
throw new Error(`Cannot load plugin ${name} relative to ${dirname} in a browser`);
|
||||
}
|
||||
|
||||
export function loadPreset(name: string, dirname: string): { filepath: string, preset: mixed } {
|
||||
export function loadPreset(name: string, dirname: string): { filepath: string, value: mixed } {
|
||||
throw new Error(`Cannot load preset ${name} relative to ${dirname} in a browser`);
|
||||
}
|
||||
|
||||
export function loadParser(name: string, dirname: string): { filepath: string, parser: Function } {
|
||||
export function loadParser(name: string, dirname: string): { filepath: string, value: Function } {
|
||||
throw new Error(`Cannot load parser ${name} relative to ${dirname} in a browser`);
|
||||
}
|
||||
|
||||
export function loadGenerator(name: string, dirname: string): { filepath: string, generator: Function } {
|
||||
export function loadGenerator(name: string, dirname: string): { filepath: string, value: Function } {
|
||||
throw new Error(`Cannot load generator ${name} relative to ${dirname} in a browser`);
|
||||
}
|
||||
|
||||
@@ -26,27 +26,27 @@ export function resolvePreset(presetName: string, dirname: string): string|null
|
||||
return resolveFromPossibleNames(possibleNames, dirname);
|
||||
}
|
||||
|
||||
export function loadPlugin(name: string, dirname: string): { filepath: string, plugin: mixed } {
|
||||
export function loadPlugin(name: string, dirname: string): { filepath: string, value: mixed } {
|
||||
const filepath = resolvePlugin(name, dirname);
|
||||
if (!filepath) throw new Error(`Plugin ${name} not found relative to ${dirname}`);
|
||||
|
||||
return {
|
||||
filepath,
|
||||
plugin: requireModule(filepath),
|
||||
value: requireModule(filepath),
|
||||
};
|
||||
}
|
||||
|
||||
export function loadPreset(name: string, dirname: string): { filepath: string, preset: mixed } {
|
||||
export function loadPreset(name: string, dirname: string): { filepath: string, value: mixed } {
|
||||
const filepath = resolvePreset(name, dirname);
|
||||
if (!filepath) throw new Error(`Preset ${name} not found relative to ${dirname}`);
|
||||
|
||||
return {
|
||||
filepath,
|
||||
preset: requireModule(filepath),
|
||||
value: requireModule(filepath),
|
||||
};
|
||||
}
|
||||
|
||||
export function loadParser(name: string, dirname: string): { filepath: string, parser: Function } {
|
||||
export function loadParser(name: string, dirname: string): { filepath: string, value: Function } {
|
||||
const filepath = resolveQuiet(name, dirname);
|
||||
if (!filepath) throw new Error(`Parser ${name} not found relative to ${dirname}`);
|
||||
|
||||
@@ -61,11 +61,11 @@ export function loadParser(name: string, dirname: string): { filepath: string, p
|
||||
|
||||
return {
|
||||
filepath,
|
||||
parser: mod.parse,
|
||||
value: mod.parse,
|
||||
};
|
||||
}
|
||||
|
||||
export function loadGenerator(name: string, dirname: string): { filepath: string, generator: Function } {
|
||||
export function loadGenerator(name: string, dirname: string): { filepath: string, value: Function } {
|
||||
const filepath = resolveQuiet(name, dirname);
|
||||
if (!filepath) throw new Error(`Generator ${name} not found relative to ${dirname}`);
|
||||
|
||||
@@ -80,7 +80,7 @@ export function loadGenerator(name: string, dirname: string): { filepath: string
|
||||
|
||||
return {
|
||||
filepath,
|
||||
generator: mod.print,
|
||||
value: mod.print,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -171,13 +171,15 @@ class OptionManager {
|
||||
}
|
||||
|
||||
if (opts.parserOpts && typeof opts.parserOpts.parser === "string") {
|
||||
opts.parserOpts.parser = loadParser(opts.parserOpts.parser, dirname).parser;
|
||||
opts.parserOpts.parser = loadParser(opts.parserOpts.parser, dirname).value;
|
||||
}
|
||||
|
||||
if (opts.generatorOpts && typeof opts.generatorOpts.generator === "string") {
|
||||
opts.generatorOpts.generator = loadGenerator(opts.generatorOpts.generator, dirname).generator;
|
||||
opts.generatorOpts.generator = loadGenerator(opts.generatorOpts.generator, dirname).value;
|
||||
}
|
||||
|
||||
// const plugins =
|
||||
|
||||
// resolve presets
|
||||
if (opts.presets) {
|
||||
if (!Array.isArray(rawOpts.presets)) throw new Error(`${alias}.presets should be an array`);
|
||||
@@ -298,7 +300,7 @@ function resolvePresets(presets: Array<string | Object>, dirname: string) {
|
||||
if (typeof preset === "string") {
|
||||
({
|
||||
filepath: presetLoc,
|
||||
preset,
|
||||
value: preset,
|
||||
} = loadPreset(preset, dirname));
|
||||
}
|
||||
const resolvedPreset = loadPresetObject(preset, options, { dirname });
|
||||
@@ -455,7 +457,7 @@ function normalisePlugins(loc, dirname, plugins) {
|
||||
|
||||
// allow plugins to be specified as strings
|
||||
if (typeof plugin === "string") {
|
||||
plugin = loadPlugin(plugin, dirname).plugin;
|
||||
plugin = loadPlugin(plugin, dirname).value;
|
||||
}
|
||||
|
||||
plugin = normalisePlugin(plugin, loc, i, alias);
|
||||
|
||||
Reference in New Issue
Block a user