pkl
(pronounced pickle) is a package linker for
lerna monorepos. Use it to install packages from your
monorepo into your application. This can be useful for trying a package which is
in development before you publish it.
pkl
can be installed from the npm registry and, as it works across projects,
should be installed globally.
npm install -g pkl
yarn global add pkl
There's a simple example below of adding a monorepo, listing all added monorepos, using it to install a package from, and then removing the monorepo.
# Add a monorepo (so you can use it during install)
$ pkl add components ./path/to/my/component-library
success: added components
- Name mapped to /Users/username/projects/path/to/my/component-library
# Show the monorepos you've added
$ pkl ls
success: showing 1 monorepo
- components → /Users/username/projects/path/to/my/component-library
# Install package "button" into your project from the monorepo
cd ./my-project
$ pkl install components button
✔ button - installed
success: installation complete
- button (components) → [email protected]
# Remove a monorepo (you don't be able to install from it any more)
$ pkl rm components
success: removed components
- Removed mapping to /Users/username/projects/path/to/my/component-library
To get help on the supported commands, use the --help
flag (or run without any
flags or commands).
pkl --help
To see which version you have installed, use the --version
flag.
pkl --version
Some command use npm
as part of their implementation. To use yarn
instead,
add the --yarn
flag. This is only for supported commands; currently install
.
pkl install components button --yarn
pkl
has four sub-commands; add
, rm
, ls
, install
pkl add <monorepo-name>
pkl add <monorepo-name> <folder-path>
This command adds a monorepo name and location, so it shows in the monorepo list
(ls
) and can be used when running install
. If a path to the monorepo folder
is not provided, the current working directory (the one the command is run from)
will be used instead.
The monorepo name and location are added to the monorepo mapping JSON file,
which is stored at ~/.pkl/monorepo-mapping.json
and consists of each monorepo
name mapping to the corresponding absolute path.
pkl rm <monorepo-name>
This command removes a monorepo by name, so it no longer shows in the monorepo
list (ls
) and cannot be used when running install
.
The monorepo name entry is removed from the monorepo mapping JSON file, which is
stored at ~/.pkl/monorepo-mapping.json
.
pkl ls
This command lists all the added monorepo names and locations, which can be used
when using the install
command.
The monorepo mapping JSON file, stored at ~/.pkl/monorepo-mapping.json
, is
pretty printed to the console.
pkl install <monorepo-name> <package-name>
pkl install <monorepo-name> <package-folder-name>
pkl install <monorepo-name> <package-folder-name> [...<package>]
This command installs the named packages from the named monorepo, into the
project where the command is run. Packages can be referenced by their name (as
listed in the name
field of their corresponding package.json
file) or by
their folder name. Multiple packages can be listed to install more than one in a
single command.
Note: For packages without a version, these can only be referenced by their folder name.
Packages to be installed are packed into tar files and moved into a .pkl/
folder within your project. These are then installed -- you may notice your
project package.json
file referencing file:.pkl/my-package.tgz
instead of a
version. To prevent committing these files, you should add the .pkl/
directory
to your .gitignore
.
By default, install
will use npm
to find lerna
, pack packages and install
them. If you want to use yarn
instead, add the --yarn
flag to the end of
your command.
This cli tool is written using
commander, with each command
implemented in its own file under the ./commands
folder.
Linting is enforced using eslint, configured with airbnb-base and prettier.
npm run lint
# Run and apply automatic fixes for any issues
npm run lint -- --fix
Unit testing is written and run using jest, and relies heavily on mocking.
npm test
# Run specific test file
npm test -- ./path/to/file.test.js
# Run in watch mode
npm test -- --watch
# Generate coverage report
npm test -- --coverage