New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(plugins): switched from require
to await import()
when loading plugins
#2558
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fbc528b
refactor(plugins): switched from `require` to `await import()` when l…
travi 476e0bb
fix(plugins): referenced the default of the imported plugin
travi 4fb3cd2
refactor(plugins): improved variable names within reduce loops
travi 47ca65c
refactor(plugins): removed console.logs and resolved lint issues
travi 97fdd48
Merge branch 'master' of github.com:semantic-release/semantic-release…
travi eeae4d3
test(lint): disabled the check for `node/no-unsupported-features/es-s…
travi File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,36 +6,41 @@ const {validatePlugin, validateStep, loadPlugin, parseConfig} = require('./utils | |
const pipeline = require('./pipeline'); | ||
const normalize = require('./normalize'); | ||
|
||
module.exports = (context, pluginsPath) => { | ||
module.exports = async (context, pluginsPath) => { | ||
let {options, logger} = context; | ||
const errors = []; | ||
|
||
const plugins = options.plugins | ||
? castArray(options.plugins).reduce((plugins, plugin) => { | ||
if (validatePlugin(plugin)) { | ||
const [name, config] = parseConfig(plugin); | ||
plugin = isString(name) ? loadPlugin(context, name, pluginsPath) : name; | ||
? await castArray(options.plugins).reduce(async (plugins, plugin) => { | ||
const plugins2 = await plugins; | ||
if (validatePlugin(plugin)) { | ||
const [name, config] = parseConfig(plugin); | ||
plugin = isString(name) ? await loadPlugin(context, name, pluginsPath) : name; | ||
|
||
if (isPlainObject(plugin)) { | ||
Object.entries(plugin).forEach(([type, func]) => { | ||
if (PLUGINS_DEFINITIONS[type]) { | ||
Reflect.defineProperty(func, 'pluginName', { | ||
value: isPlainObject(name) ? 'Inline plugin' : name, | ||
writable: false, | ||
enumerable: true, | ||
}); | ||
plugins[type] = [...(plugins[type] || []), [func, config]]; | ||
} | ||
}); | ||
} else { | ||
errors.push(getError('EPLUGINSCONF', {plugin})); | ||
} | ||
console.log({plugins: options.plugins}) | ||
console.dir(plugin, {depth: null}) | ||
console.log(isPlainObject(plugin)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a reminder to remove the debug logs when the PR is ready :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep 👍🏼 |
||
if (isPlainObject(plugin)) { | ||
Object.entries(plugin).forEach(([type, func]) => { | ||
console.log({type, name}) | ||
if (PLUGINS_DEFINITIONS[type]) { | ||
Reflect.defineProperty(func, 'pluginName', { | ||
value: isPlainObject(name) ? 'Inline plugin' : name, | ||
writable: false, | ||
enumerable: true, | ||
}); | ||
plugins2[type] = [...(plugins2[type] || []), [func, config]]; | ||
} | ||
}); | ||
} else { | ||
errors.push(getError('EPLUGINSCONF', {plugin})); | ||
} | ||
} else { | ||
errors.push(getError('EPLUGINSCONF', {plugin})); | ||
} | ||
|
||
return plugins; | ||
}, {}) | ||
return plugins2; | ||
}, {}) | ||
: []; | ||
|
||
if (errors.length > 0) { | ||
|
@@ -44,9 +49,16 @@ module.exports = (context, pluginsPath) => { | |
|
||
options = {...plugins, ...options}; | ||
|
||
const pluginsConf = Object.entries(PLUGINS_DEFINITIONS).reduce( | ||
(pluginsConf, [type, {required, default: def, pipelineConfig, postprocess = identity, preprocess = identity}]) => { | ||
const pluginsConf = await Object.entries(PLUGINS_DEFINITIONS).reduce( | ||
async (pluginsConf, [type, { | ||
required, | ||
default: def, | ||
pipelineConfig, | ||
postprocess = identity, | ||
preprocess = identity | ||
}]) => { | ||
let pluginOptions; | ||
const pluginsConf2 = await pluginsConf; | ||
|
||
if (isNil(options[type]) && def) { | ||
pluginOptions = def; | ||
|
@@ -60,28 +72,28 @@ module.exports = (context, pluginsPath) => { | |
|
||
if (!validateStep({required}, options[type])) { | ||
errors.push(getError('EPLUGINCONF', {type, required, pluginConf: options[type]})); | ||
return pluginsConf; | ||
return pluginsConf2; | ||
} | ||
|
||
pluginOptions = options[type]; | ||
} | ||
|
||
const steps = castArray(pluginOptions).map((pluginOpt) => | ||
normalize( | ||
const steps = await Promise.all(castArray(pluginOptions).map(async (pluginOpt) => | ||
await normalize( | ||
{...context, options: omit(options, Object.keys(PLUGINS_DEFINITIONS), 'plugins')}, | ||
type, | ||
pluginOpt, | ||
pluginsPath | ||
) | ||
); | ||
)); | ||
|
||
pluginsConf[type] = async (input) => | ||
pluginsConf2[type] = async (input) => | ||
postprocess( | ||
await pipeline(steps, pipelineConfig && pipelineConfig(pluginsConf, logger))(await preprocess(input)), | ||
await pipeline(steps, pipelineConfig && pipelineConfig(pluginsConf2, logger))(await preprocess(input)), | ||
input | ||
); | ||
|
||
return pluginsConf; | ||
return pluginsConf2; | ||
}, | ||
plugins | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there is a better name for
plugins2
? MaybenormalizedPlugins
orawaitedPlugins
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, this is definitely part of the clean up that is necessary once this is working :)