fix: use module name in logs for plugins loaded with plugins option

This commit is contained in:
Pierre Vanduynslager 2018-10-09 15:16:41 -04:00
parent 3e8216ab35
commit ff275a5cd4
4 changed files with 15 additions and 14 deletions

View File

@ -19,6 +19,7 @@ module.exports = (context, pluginsPath) => {
if (isPlainObject(plugin)) {
Object.entries(plugin).forEach(([type, func]) => {
if (PLUGINS_DEFINITIONS[type]) {
Reflect.defineProperty(func, 'pluginName', {value: 'Inline plugin', writable: false, enumerable: true});
plugins[type] = [...(PLUGINS_DEFINITIONS[type].multiple ? plugins[type] || [] : []), [func, config]];
}
});

View File

@ -10,9 +10,9 @@ module.exports = (context, type, pluginOpt, pluginsPath) => {
return noop;
}
const [path, config] = parseConfig(pluginOpt);
const pluginName = isFunction(path) ? `[Function: ${path.name}]` : path;
const plugin = loadPlugin(context, path, pluginsPath);
const [name, config] = parseConfig(pluginOpt);
const pluginName = name.pluginName ? name.pluginName : isFunction(name) ? `[Function: ${name.name}]` : name;
const plugin = loadPlugin(context, name, pluginsPath);
let func;
if (isFunction(plugin)) {
@ -48,10 +48,10 @@ module.exports = (context, type, pluginOpt, pluginsPath) => {
Reflect.defineProperty(validator, 'pluginName', {value: pluginName, writable: false, enumerable: true});
if (!isFunction(pluginOpt)) {
if (pluginsPath[path]) {
logger.success(`Loaded plugin "${type}" from "${path}" in shareable config "${pluginsPath[path]}"`);
if (pluginsPath[name]) {
logger.success(`Loaded plugin "${type}" from "${pluginName}" in shareable config "${pluginsPath[name]}"`);
} else {
logger.success(`Loaded plugin "${type}" from "${path}"`);
logger.success(`Loaded plugin "${type}" from "${pluginName}"`);
}
}

View File

@ -18,8 +18,8 @@ const validateSingleStep = conf => {
return false;
}
const [path, config] = parseConfig(conf[0]);
return (isString(path) || isFunction(path)) && isPlainObject(config);
const [name, config] = parseConfig(conf[0]);
return (isString(name) || isFunction(name)) && isPlainObject(config);
};
const validateMultipleStep = conf => {
@ -45,11 +45,11 @@ function validateStep({multiple, required}, conf) {
return conf.length === 0 || (multiple ? validateMultipleStep : validateSingleStep)(conf);
}
function loadPlugin({cwd}, path, pluginsPath) {
const basePath = pluginsPath[path]
? dirname(resolveFrom.silent(__dirname, pluginsPath[path]) || resolveFrom(cwd, pluginsPath[path]))
function loadPlugin({cwd}, name, pluginsPath) {
const basePath = pluginsPath[name]
? dirname(resolveFrom.silent(__dirname, pluginsPath[name]) || resolveFrom(cwd, pluginsPath[name]))
: __dirname;
return isFunction(path) ? path : require(resolveFrom.silent(basePath, path) || resolveFrom(cwd, path));
return isFunction(name) ? name : require(resolveFrom.silent(basePath, name) || resolveFrom(cwd, name));
}
function parseConfig(plugin) {

View File

@ -59,7 +59,7 @@ test('Export plugins based on "plugins" config (array)', async t => {
const plugin1 = {verifyConditions: stub(), publish: stub()};
const plugin2 = {verifyConditions: stub(), verifyRelease: stub()};
const plugins = getPlugins(
{cwd, logger: t.context.logger, options: {plugins: [plugin1, plugin2], verifyRelease: () => {}}},
{cwd, logger: t.context.logger, options: {plugins: [plugin1, [plugin2, {}]], verifyRelease: () => {}}},
{}
);
@ -125,7 +125,7 @@ test('Use only last definition of single plugin steps declared in "plugins" conf
t.is(typeof plugins.fail, 'function');
});
test('Merge global options, "plugins" options and sptep options', async t => {
test('Merge global options, "plugins" options and step options', async t => {
const plugin1 = [{verifyConditions: stub(), publish: stub()}, {pluginOpt1: 'plugin1'}];
const plugin2 = [{verifyConditions: stub()}, {pluginOpt2: 'plugin2'}];
const plugin3 = [stub(), {pluginOpt3: 'plugin3'}];