Thursday 31st August, 2017

Editor and NPM

npm has become the de facto package manager for Javascript libraries, owing in part to how easy it makes it to install software and dependencies, but also due to the huge amount of software that is available through the npm directory. DataTables and its extensions are available on npm making installation and integration of DataTables very easy with any given tool chain / build process (and there are plenty of them in the Javascript world!).

npm is ideally suited for distribution of open source software such as DataTables, but it doesn't work so well for commercial software such as Editor. The full Editor package is only available to license holders, a license which npm knows nothing about. The source for Editor could be placed on npm for distribution but there would be no way to enforce the license - and the license fees from Editor is what makes continued development and support of DataTables and its other extensions possible!

Holding packages

The approach taken to allow Editor to be used in an npm tool chain is to have an almost empty holding package on npm which will be installed when npm install datatables.net-editor is executed. This has a post-install script which will display an information message detailing how the full Editor package can be installed:

# npm install datatables.net-editor

> node postinstall.js

DataTables Editor installation
To complete the installation of Editor, please download a licensed or trial package from
https://editor.datatables.net/download and then run the install.js script:

  node node_modules/datatables.net-editor/install.js path/to/Editor.zip

This will insert the correct licensed or trial files into your node_modules structure.

To complete the installation download Editor (either the licensed version or the trial) and then execute the node_modules/datatables.net-editor/install.js script, pointing it to the download Editor zip file, as detailed in the post-install message. The script will unzip the package and insert files into their required locations for use with import editor from 'datatables.net-editor'; / require('datatables.net-editor'); just like with any other package.

Styling libraries

Just as with DataTables core and the other extensions, there are also packages for the styling frameworks supported by Editor such as Bootstrap, Foundation and Semantic UI. As with the other software, these styling integration libraries are defined by adding a suffix to the package such as -bs for Bootstrap 3. Please see the npm download page for full details.

There is no additional installation script to run for the styling packages, the main installation script will automatically detect if there are any Editor styling packages installed and move the appropriate files from the Editor zip package into those packages.

Source control

For integration with source control, it is recommended that you commit the zip file into your repository, so the install command can be easily completed whenever npm install is run for future clones of the project. Equally, a custom post install script could be used to execute the install command immediately. In this way you do not need to commit anything from node_modules into source control.

In an ideal world

Ideally this extra step wouldn't be required for installing Editor via npm. However, due to its commercial nature and requiring a license to being able to use it, I'm not aware of any better solutions. If anyone does has any suggestions for how this could be improves, they are very welcome. In the meantime, hopefully this post has described the what, why and how of using Editor with npm / yarn.

Happy coding!