Skip to content
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

T/131: Introduce CKEditor 5 builds #132

Merged
merged 30 commits into from
Apr 3, 2017
Merged

T/131: Introduce CKEditor 5 builds #132

merged 30 commits into from
Apr 3, 2017

Conversation

pomek
Copy link
Member

@pomek pomek commented Mar 16, 2017

Feature: Added a util for creating an entry point for Rollup/Webpack. Introduced a new editor bundler - ckeditor5-dev-bundler-webpack. Closes #131.

@pomek pomek requested a review from Reinmar March 17, 2017 12:29
@pomek pomek changed the title [WIP] T/131: Introduce CKEditor 5 builds T/131: Introduce CKEditor 5 builds Mar 17, 2017
export default class ClassicEditor extends ClassicEditorBase {}

ClassicEditor.build = {
plugins: [ ArticlePlugin ],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ArticlePreset.

* @param {Object} config
* @returns {Promise}
*/
module.exports = function runWebpack( config ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this module?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we talked F2F, we don't need this module. I'll remove it.

"babel-core": "^6.24.0",
"babel-loader": "^6.4.0",
"babel-preset-env": "^1.2.2",
"babel-preset-es2015": "^6.24.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use this (see ckeditor/ckeditor5#415).

"dependencies": {
"babel-core": "^6.24.0",
"babel-loader": "^6.4.0",
"babel-preset-env": "^1.2.2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch the code to use this preset.


output: {
path: options.destinationPath,
filename: 'ckeditor.es6.js',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We redefined a bit the two types of builds: ckeditor/ckeditor5#408 (comment)

* @returns {Object}
*/
module.exports = function getWebpackConfig( options ) {
const config = getWebpackES6Config( options );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that one config is an extension of the other one because it's not. See that you're overriding the plugins property, so it's not an inheritance and it shouldn't be implemented here as such.

E.g. what if the ES6 config will require more plugins? You don't know if you need to override just Babili or all of them.

So, let's KISS here and just duplicate the config object twice. After all – "Duplication is easier to fix than broken abstraction"


resolveLoader: {
modules: [
path.join( options.cwd, 'node_modules' )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed. Or at least – it should not be needed.

"babel-loader": "^6.4.0",
"babel-preset-env": "^1.2.2",
"babel-preset-es2015": "^6.24.0",
"babili-webpack-plugin": "0.0.11",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ^.

const plugins = getPlugins( options.plugins );

let content = `/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hardcode 2017.

* @param {Object} config
* @returns {String}
*/
module.exports = function getEditorConfig( config ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this function doing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes string from specified config. I understand you are talking about missing JSDoc.

* @param {Array.<String>} pluginPaths
* @returns {Object}
*/
module.exports = function getPlugins( pluginPaths ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this function doing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing JSDoc, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid it's not only that. But I'll wait for the docs to verify this ;)

@pomek
Copy link
Member Author

pomek commented Mar 22, 2017

No, it isn't ready. I forgot to implement ckeditor/ckeditor5#408 (comment) (and comments below).

@pomek
Copy link
Member Author

pomek commented Mar 22, 2017

Ok, should be fine.

} );

const expectedEntryFile = `/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imagine it's January 1, 2018 ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure :D

Will fix it.

@Reinmar
Copy link
Member

Reinmar commented Mar 24, 2017

🍆

@Reinmar
Copy link
Member

Reinmar commented Mar 24, 2017

I noticed that you've moved Webpack plugin to the new package. I'd keep it in the old one. It'll be used far more often and by far more developers than the utils, so let's expose it better.

@pomek
Copy link
Member Author

pomek commented Mar 27, 2017

@Reinmar, ready to review once again.

Kamil Piechaczek added 2 commits March 27, 2017 10:31
…enamed as "dev-webpack-utils". File: packages/ckeditor5-dev-tests/package.json.

This reverts commit 6747044.
* @param {Object} config
* @returns {String}
*/
module.exports = function getEditorConfig( config ) {
Copy link
Member

@Reinmar Reinmar Mar 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't very safe, unfortunately. E.g. every " character will be replaced with ' which certainly isn't correct.

Therefore, let's do the simplest possible thing now – output a JSON string to the entry file and parse it there. The entry file should look like this:

const config = JSON.parse( '...' );

Or, to keep the config more readable in the entry file:

const config = JSON.parse(
`{
    "foo": "bar"
}`
);

Ooor... we can keep the editor config in a separate file (editor-config.js) – next to ckeditor.js and simply import it. Then, we won't need to stringify anything. You could check this option first.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check it. Thanks for the idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the config will be a separate file, the createEntryPoint() function could get its path as an argument.


pluginPaths.forEach( ( pathToFile ) => {
const basePluginName = capitalize( path.basename( pathToFile, '.js' ) );
let pluginName = basePluginName + 'Plugin';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something's seriously wrong in here. Why isn't this a const? Why there's a loop which uses the same variable name in the loop and then assigns a new value to it?

If this code works, then it needs to be refactored to also have any sense ;) I looked at it for 10s and don't get it which means that it's wrong :P

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code has sense and works - it generates a unique name for a plugin.

If given name is already used, the next one will contain a number at the end.

Why isn't this a const?

Because: pluginName = basePluginName + ( ++i ).toString() + 'Plugin'; in the while loop.

It means, given plugin name is already used. We need to generate new.

OTOH, maybe it is not required because plugins with the same names shouldn't exist.

I looked at it for 10s and don't get it which means that it's wrong :P

Sorry, but does not sound like a metric for me. ;/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but does not sound like a metric for me. ;/

Well, this is the most important metric of a good code. If it's understandable to other developers.

@Reinmar
Copy link
Member

Reinmar commented Apr 3, 2017

I've tried to play a bit with ckeditor5-build-classic and I realised that it's very cumbersome because there are no webpack configs there to play with. So I think that it'll be better to actually keep them in the build repos. This means that they'll be duplicated and a bit harder to maintain but the DX will be better.

PS. And the thing I've been trying to check is removePlugins option... and it doesn't work.

@Reinmar
Copy link
Member

Reinmar commented Apr 3, 2017

Another thing I noticed is that the way how we run Webpack swallows errors... So, I'm gonna remove or simplify bin/build.js and run Webpack directly.

@Reinmar Reinmar merged commit 0aa523b into master Apr 3, 2017
@Reinmar Reinmar deleted the t/131 branch April 3, 2017 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants