Updating Lifecycle Event Names to `onEvent`
See original GitHub issueThe object returned by plugins represent the config, name, and the handlers that respond to lifecycle events.
These lifecycle events are events that happen during the course of a build. For example preBuild postBuild
, preDeploy
etc
Because these handler functions are responding to events, I think it would improve clarity of the plugin API to make the keys of event handler functions look more like an event handler.
For example, instead of prebuild
using onPrebuild
.
Changes
module.exports = function myPlugin(config) {
return {
- preBuild: () => {
+ onPreBuild: () => {
// run thing on pre-build
},
- build: () => {
+ onBuild: () => {
// run thing on build
},
- postBuild: () => {
+ onPostBuild: () => {
// run thing on post build
}
}
}
I believe this would make it a little more clear that the keys beginning with on
are bits of functionality that response to a particular lifecycle event.
I also think this will make it easier to evolve the plugin API without running into namespace clashes. E.g. (random example) if we wanted to use the build
key in the future for some kind of config
We can achieve this with a breaking change or non-breaking change.
The non-breaking change would require some mapping of existing keys & deprecation notices for plugins using the “older” non onXyz
syntax
Issue Analytics
- State:
- Created 4 years ago
- Comments:20 (20 by maintainers)
Lets go ahead and change this.
Part 2 before merging the code changes will be updating the plugin content we can edit. https://www.notion.so/netlify/Build-Plugins-Reference-Guide-2b5ed75d19254b5389f2713bfc0fef6a
Just to be clear, the expected behavior is migrating the lifecycle events in a backward compatible way.
E.g.
build
would change toonBuild
(etc)build
will still operate as normal but will log outthe build lifecycle has been updated to onBuild, please update your plugins accordingly
onXyz
lifecycle eventsI think this is a good idea. 👍
Tagging @verythorough as this would require some documentation/articles updates.