ckeditor / ckeditor5-design

☠ Early discussions about CKEditor 5's architecture. Closed now. Go to https://github.com/ckeditor/ckeditor5 ☠
58 stars 12 forks source link

Why not naming the plugins? #121

Closed Reinmar closed 7 years ago

Reinmar commented 8 years ago

While updating the https://github.com/ckeditor/ckeditor5-design/wiki/Plugins page I wanted to explain why we decided to not give plugins their names.

Explanation:

In order to bundle a CKEditor build (create a single file distribution) the bundler must be able to analyze dependencies between plugins. The developer will only define, for example, that the bundle should contain the 'image/captionedimage', 'link' and 'creator-classic/classic' plugins, so the bundler must find the rest.

In the ES 6 modules system, dependencies between modules (and remember – plugin is simply a module) are resolved by import statements. You can run any bundler on the code shown in the Dependencies chapter and tools like Rollup or r.js (when bundling an AMD build of that code) will easily find out that the CaptionedImage plugin requires also two other modules.

We could name the plugins and define dependencies using those names (actually – paths, because the plugin loader needs paths), but that would mean that you're no longer able to apply the bundler of your choice, because only the official CKEditor bundler would know how to read the dependencies.

The alternative could be to use the names, but resolve them on the build step and automatically transform them into the current format. This would also allow using any bundler and plugins could always be retrieved by their names, but is definitely a much more complicated solution to code. But most importantly, that wouldn't be much of a difference.

The rule is simple – when you initialize the editor, you know which plugins you load so you can access them by the names you used. However, you don't know their dependencies, so you should not try to access them. On the other hand, when you're a plugin developer, you need to import your plugin's dependencies anyway, so then you alway have the keys to the plugin collection.


In case of any doubts or ideas, feel free to comment.

Reinmar commented 7 years ago

We actually decided to allow naming plugins (which is optional). However, this is additional feature, not required by any bundler/builder to work.