Ckeditor5: Include CKEditor version number somewhere

Created on 26 Apr 2018  路  11Comments  路  Source: ckeditor/ckeditor5

Currently when I have a js bundle it's hard to determine what version I'm running actually.

feature

Most helpful comment

This is how you can get the version of CKEditor 5 from the console:

console.log( CKEDITOR_VERSION ); // -> '11.0.0'

All 11 comments

In the license header? Or somewhere as a static property in the editor class (could be done by requiring it from package.json in the Editor class)?

The former will be easier to extract with regexp from the source. The latter will be available programmatically in JS. So, we could also have both.

Note: requiring a version from package.json will result in bundling whole package.json. As I remember, webpack@4 solves it.

There is one more place where the version number would be really useful: in the DOM as a data attribute of the ck-editor__editable. This way we could easily understand the version number of the editor when trying to investigate something in users applications.

In users applications CKEditor JS source files are many times merged with other JS files and sometimes obfuscated, which makes getting the version number from source code really cumbersome.

Alternatively, we could expose it as a global variable. Not very clean and I'm not 100% sure that it'd be accessible in all cases, but polluting the editable element with it isn't cool too.

The clean solution would be to have editor.version property which exposes the version from the package.json. As far as I remember the talk with @ma2ciek as soon as Webpack will support JSON tree shaking we will be able to do it as simple as:

import { version as ckeditor5PackageVersion } from '@ckeditor/ckeditor5/package.json';
// ...
this.version = ckeditor5PackageVersion;

However, to make it useful editor need to be exposed.

However, to make it useful editor need to be exposed.

Exactly. That's why we need a global. No one exposes editor except us. But it can look like this:

import { version as ckeditor5PackageVersion } from '@ckeditor/ckeditor5/package.json';
// ...
window.CKEDITOR_VERSION = ckeditor5PackageVersion;

BTW, we can add a check. If window.CKEDITOR_VERSION is defined when this module will be executed, we can log a warning that either someone loaded two builds on one page. Or that packages got duplicated while installation (which might be caused by mismatched dependency versions).

Also, this is exactly the code which we can put in the ckeditor5 package :) We didn't know what to put there and I think that we have an answer :)

I was thinking if we should have window.CKEDITOR_VERSION or window.CKEDITOR.VERSION. We will soon have window.CKEDITOR_DEBUG (or window.CKEDITOR.DEBUG). But I think that window.CKEDITOR.* gives us nothing and brings problem who should initialize it, so window.CKEDITOR_VERSION (and window.CKEDITOR_DEBUG in the future) looks better.

BTW, one of the problems here is accessing the global object. It's not always window (see https://github.com/ckeditor/ckeditor5/issues/879) so we need to be careful.

This is how you can get the version of CKEditor 5 from the console:

console.log( CKEDITOR_VERSION ); // -> '11.0.0'
Was this page helpful?
0 / 5 - 0 ratings