Creating a new local package

Note: this documentation is for a beta release of Caplin Trader 5. Features may change before the final release.

This page provides instructions on how to create a new local package to share code between applications in a Caplin Trader workspace.



Packages for Caplin Trader 5 applications are created within the context of a Caplin Trader development workspace. For more information on creating a development workspace, see Creating a new workspace.

Creating a new local package

You create a local package by using Caplin CLI's create-package command:

caplin-cli create-package <package-name>

To create a new local package called my-package, for example, follow the steps below:

  1. From the root directory of your CT5 development workspace, run the command below to create a local package called my-package:

    caplin-cli create-package my-package

    Your new local package has the following structure:

    ├── my-package.js
    ├── package.json
    └── _test-ut
        └── my-package-test.js
  2. Change directory to <workspace>/packages/my-package, and run the command below to download the new package's dependencies:

    npm install

Installing a local package in an application

You install local packages to an application by passing a local path to the npm install command.

To install the package my-package created in the previous section, follow the steps below:

  1. Run the command below from the root directory of your Caplin Trader application:

    npm install --save ../../packages/my-package

    This command installs the my-package package and its dependencies to the node_modules directory. The --save option adds my-package as a project dependency in your application's package.json file. From npm v5, the --save option is the default behaviour and is not required.

  2. [npm v4] Edit the package.json file in your Caplin Trader application and change the location of the my-package package from an absolute path to a relative path:

    "dependencies": {
        "my-package": "file:../../packages/my-package"

    From npm v5, a relative path is added to the packages.json file by default and this step is not required.

  3. If your local package includes an aliasProviders module, then edit your application's src/config/aliases.js file and merge the object exported by your package's aliasProviders module with the object exported from the aliases.js file:

    // require aliasProvider here, add to the Object.assign list.
    const myPackageAliasProviders = require('my-package/aliasProviders');
    module.exports = Object.assign({}, myPackageAliasProviders);