-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[RFC] Plugins v2.0 #919
[RFC] Plugins v2.0 #919
Conversation
While powerful, my biggest hesitation to continue with this is with how fragile plugin implementations would be. They'd be relying on implementation details... not ideal. We'd have to be extra careful with our semantic versioning to allow plugin developers to properly lock their peerDependency. This may be more gimmicky than realistic. |
Cool, thanks for starting to think about this! I think we should follow two principles:
I think these two principles can guide us in the right direction. I know @jamiebuilds has been doing some thinking in this area as well. Would be good to hear from him as well (perhaps in a separate RFC?). |
Some more guiding principles:
Ideally the shape of a plugin should fit within this: type JSONValue =
| null
| boolean
| number
| string
| Array<JSONValue>
| JSONObject;
type JSONObject = {
[key: string]: JSONValue,
};
type Plugin = {
[key: string]: (input: JSONObject) => JSONObject,
};
declare module.exports: Plugin;
Additionally:
module.exports = {
methodOne(input) {
return { ..., extra: { foo: true } };
},
methodTwo(input) {
console.log(input.extra.foo); // true
}
}; Non-requirements
|
Note: This is in the very early stages of development still. I'm opening this to begin a discussion on the direction & approach before proceeding any further. There is still a ton of work to be done if we want to peruse this. We need to consider any maintenance overhead this could introduce.
Details
What: This is a complete plugin system overhaul. The proposed implementation gives the plugin developer full-reign to hook into any part of parcel that they see fit. Existing plugins remain compatible via a shim in the new system, but the exported API of parcel would change for programmatic consumers. We could likely maintain the existing exported API - but without plugin support for a few versions to ease transition.
Highlights:
So Far: The code within demonstrates an approach to plugins that allows plugin developers to "mixin" their functionality. For now, the approach has been added to the
Bundler
,Logger
, andHTMLPackager
strictly for demonstration purposes. You can extrapolate the pattern to see how it would be applied across the code base - a minor addition to each file we'd want to support.Examples
Unicorn Logger
Plugin Implementation:
Demo:
HTML Comment Header
You could imagine that this plugin would ship configurable, so the user could configure their header. The following demonstrates a hard-coded comment header though.
Plugin Implementation:
Demo:
Next Steps
Plugin.init
and would control the order that mixins are appliesmixwith
into a utility - it contains more than we need#918 CC: @davidnagli @devongovett @DeMoorJasper