Javascript Build and Dojo changes in 5.1

Introduction

5.1 brings some changes to the way our Javascript applications are built. Most of these changes involve the consolidation to RequireJS for loading and building. Other changes integrate RequireJS configuration information into the Karma unit testing framework. We also upgraded to the 1.9 version of Dojo which is now fully AMD compatible.

Dojo Upgrade

Many of our thin-client applications are built using the Dojo framework. Prior to 5.1, the version of Dojo in use was based on 1.6. This presented several changes for us ranging from build-time, unit testing, the runtime production and debug loading in the browser. None of these was the fault of Dojo, but the rather fact that we mixed our Dojo usage with non-Dojo Javascript based on AMD modules, loaded and built by RequireJS.

In 5.1 we've upgraded to Dojo 1.9, which is fully AMD compatible. This allowed us to remove the Dojo build from our projects and consolidate to RequireJS Compressor for all Javascript building. On the browser-side we now have a single loading mechanism, RequireJS, instead of RequireJS and Dojo's loader. This move greatly simplifies the system as a whole.

The full Dojo 1.9 source is distributed as part of the common-ui plugin and made available through common-ui's RequireJS configuration for anyone to use.

Migrating custom Pentaho solutions based on Dojo in 5.1

If you've built Platform Plugins based on the older version of Dojo that we used to ship, you'll have to migrate your code to work with the new AMD loader syntax. The Dojo foundation has a very comprehensive guide on how to migrate from the old Dojo syntax and loader here: Dojo 2.0 Migration.

Note: You do not have to include dojo.js in your page as described in their migration guide. We use the RequireJS loader instead which is available on any page which includes the webcontext.js script. AMD Javascript Modules (RequireJS)#webcontext

RequireJS "pen." Namespace Deprecated

Prior to 5.1 we had to namespace the RequireJS "require" and "define" functions as "pen.require" and "pen.define". This was done to avoid conflict with the older 1.6. Dojo. This conflict has been eliminated in 5.1. You can now use the standard "require" and "define" functions per the AMD spec. The "pen.*" form will continue to function to maintain backwards compatibility with existing scripts.

RequireJS Optimizer Build

More commonly referred to as r.js, RequireJS Compressor is what we use to "build" our AMD-based Javascript applications. Building involves combining all necessary script files into a single file. Further optimizations can be made, condensing down the javascript to a single line with the shortest possible download size by enabling the UglifyJS option.

5.1 sees r.js updated to the latest version which enables more options for tuning the build. Subfloor-js has been enhanced to detect the availability of NodeJS and prefer it over the default Rhino-based build, which provides up to a 5x decrease in build time. Other enhancements to our build profiles have been made to further reduce the build time.

Karma Testing

Our Javascript unit tests going forward are all written as Jasmine tests run through Karmahttp://karma-runner.github.io/0.10/index.html. The full requireJS configuration is made available to any script running as part of the tests, greatly simplifying the task of writing unit tests.

TODO: link to Javascript development guide.
TODO: link to sample Javascript Platform Plugin