CommonJS Module Loading
CommonJS-like functionality has now been integrated with Barista.
-
Node.js follows the CommonJS module system, and the builtin require function is the easiest way to include modules that exist in separate files. The basic functionality of require is that it reads a javascript file, executes the file, and then proceeds to return the exports object. (See http://nodemanual.org/latest/nodejs_ref_guide/)
- Barista now has CommonJS like functionality, there are two global functions available: require(
) and listBundles(); - Require follows the CommonJS concepts, except that instead of reading/executing javascript file, it imports functionality from the Barista library.
- Require may perform multiple operations, such as adding additional ‘types’ to the current runtime.
- E.g. to use SharePoint functionality in Barista, one will need to write:
var sp = require(“SharePoint”);
The inclusion of require and it’s functionality lets script developers specify the name of the variable that holds the export object, and minimizes the amount of global variables that would otherwise be included by default.
-
Require also allows for extensibility: an interface, IBundle, can be implemented by types. If a fully-qualified type name is passed as the string parameter, the type will be loaded and the export object returned. This lets additional bundles be deployed separately from Barista.
- listBundles lists all bundles that are available:
This is a breaking change, existing scripts will need to add the require statements at the top of the script