fix: use module name in logs for plugins loaded with plugins option
				
					
				
			This commit is contained in:
		
							parent
							
								
									3e8216ab35
								
							
						
					
					
						commit
						ff275a5cd4
					
				| @ -19,6 +19,7 @@ module.exports = (context, pluginsPath) => { | |||||||
|           if (isPlainObject(plugin)) { |           if (isPlainObject(plugin)) { | ||||||
|             Object.entries(plugin).forEach(([type, func]) => { |             Object.entries(plugin).forEach(([type, func]) => { | ||||||
|               if (PLUGINS_DEFINITIONS[type]) { |               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]]; |                 plugins[type] = [...(PLUGINS_DEFINITIONS[type].multiple ? plugins[type] || [] : []), [func, config]]; | ||||||
|               } |               } | ||||||
|             }); |             }); | ||||||
|  | |||||||
| @ -10,9 +10,9 @@ module.exports = (context, type, pluginOpt, pluginsPath) => { | |||||||
|     return noop; |     return noop; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   const [path, config] = parseConfig(pluginOpt); |   const [name, config] = parseConfig(pluginOpt); | ||||||
|   const pluginName = isFunction(path) ? `[Function: ${path.name}]` : path; |   const pluginName = name.pluginName ? name.pluginName : isFunction(name) ? `[Function: ${name.name}]` : name; | ||||||
|   const plugin = loadPlugin(context, path, pluginsPath); |   const plugin = loadPlugin(context, name, pluginsPath); | ||||||
| 
 | 
 | ||||||
|   let func; |   let func; | ||||||
|   if (isFunction(plugin)) { |   if (isFunction(plugin)) { | ||||||
| @ -48,10 +48,10 @@ module.exports = (context, type, pluginOpt, pluginsPath) => { | |||||||
|   Reflect.defineProperty(validator, 'pluginName', {value: pluginName, writable: false, enumerable: true}); |   Reflect.defineProperty(validator, 'pluginName', {value: pluginName, writable: false, enumerable: true}); | ||||||
| 
 | 
 | ||||||
|   if (!isFunction(pluginOpt)) { |   if (!isFunction(pluginOpt)) { | ||||||
|     if (pluginsPath[path]) { |     if (pluginsPath[name]) { | ||||||
|       logger.success(`Loaded plugin "${type}" from "${path}" in shareable config "${pluginsPath[path]}"`); |       logger.success(`Loaded plugin "${type}" from "${pluginName}" in shareable config "${pluginsPath[name]}"`); | ||||||
|     } else { |     } else { | ||||||
|       logger.success(`Loaded plugin "${type}" from "${path}"`); |       logger.success(`Loaded plugin "${type}" from "${pluginName}"`); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -18,8 +18,8 @@ const validateSingleStep = conf => { | |||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   const [path, config] = parseConfig(conf[0]); |   const [name, config] = parseConfig(conf[0]); | ||||||
|   return (isString(path) || isFunction(path)) && isPlainObject(config); |   return (isString(name) || isFunction(name)) && isPlainObject(config); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| const validateMultipleStep = conf => { | const validateMultipleStep = conf => { | ||||||
| @ -45,11 +45,11 @@ function validateStep({multiple, required}, conf) { | |||||||
|   return conf.length === 0 || (multiple ? validateMultipleStep : validateSingleStep)(conf); |   return conf.length === 0 || (multiple ? validateMultipleStep : validateSingleStep)(conf); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function loadPlugin({cwd}, path, pluginsPath) { | function loadPlugin({cwd}, name, pluginsPath) { | ||||||
|   const basePath = pluginsPath[path] |   const basePath = pluginsPath[name] | ||||||
|     ? dirname(resolveFrom.silent(__dirname, pluginsPath[path]) || resolveFrom(cwd, pluginsPath[path])) |     ? dirname(resolveFrom.silent(__dirname, pluginsPath[name]) || resolveFrom(cwd, pluginsPath[name])) | ||||||
|     : __dirname; |     : __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) { | function parseConfig(plugin) { | ||||||
|  | |||||||
| @ -59,7 +59,7 @@ test('Export plugins based on "plugins" config (array)', async t => { | |||||||
|   const plugin1 = {verifyConditions: stub(), publish: stub()}; |   const plugin1 = {verifyConditions: stub(), publish: stub()}; | ||||||
|   const plugin2 = {verifyConditions: stub(), verifyRelease: stub()}; |   const plugin2 = {verifyConditions: stub(), verifyRelease: stub()}; | ||||||
|   const plugins = getPlugins( |   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'); |   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 plugin1 = [{verifyConditions: stub(), publish: stub()}, {pluginOpt1: 'plugin1'}]; | ||||||
|   const plugin2 = [{verifyConditions: stub()}, {pluginOpt2: 'plugin2'}]; |   const plugin2 = [{verifyConditions: stub()}, {pluginOpt2: 'plugin2'}]; | ||||||
|   const plugin3 = [stub(), {pluginOpt3: 'plugin3'}]; |   const plugin3 = [stub(), {pluginOpt3: 'plugin3'}]; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user