Creating a new local package

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.

Caplin Trader 5 requires the latest version of npm 4 or the latest version of yarn. See Installing Node.js.

Note: Caplin Trader 5 does not yet support npm 5 due to a known issue in npm 5.

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.

Note: the instructions below are known to work with npm 4.6.1. If you are running an earlier version of npm 4, or if you are running npm 5, run the command npm install -g npm@4 to install the latest version of npm 4.

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.

  2. 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);

Updating a local package in an application

Each time you update the source code for your local package under your workspace's packages directory, you will need to update your application's copy of the local package.

Run the command below from your application's root directory to update its copy of the local package:

npm update <package-name>

If your local package is in active development, running npm update each time you change your package's code can quickly become tedious. To save time, you can use the npm package linklocal to replace your application's copy of the package in the npm_modules directory with a symbolic link to the package under your workspace's packages directory.

Follow the steps below:

  1. Install linklocal globally, if you have not already done so:

    npm install -g linklocal
  2. Run the command below from the root directory of your application:

    linklocal --named <package-name> ../../packages/
Important: Do not run the command linklocal link. This command automatically replaces all local packages in your application with symbolic links. This command is not compatible with CT5 and will break your application.