The npm object provides access to all npm packages.
To use a package, simply get it by name from npm's properties.
const friendNames = await cli.ask('What are your friends called?', Array);
const uniqueFriendNames = npm.dedupe(friendNames);
cli.tell('Total count of unique friend names: ' + uniqueFriendNames.length);
You do not need to import or install the packages you use in any way; Tasklemon will automatically install and inject any package you use.
To access a package with special characters in its name, use bracket notation.
const uuid = npm['uuid/v4'];
cli.tell('New unique identifier: ' + uuid());
If your script needs a specific version of a package, you can add a package version directive at the top of your script.
Add the directive below the shebang, if any, and above the script's code.
#require username@5.0.0
cli.tell('Hello, ' + await npm.username() + '!');
To have Tasklemon automatically add #require statements for all the packages used by your script, setting them to their latest available version, you can use the --pin-packages command-line action.
It's a good idea to do this, to ensure your script keeps the same behavior over time, even after new versions of the packages are released.
$ lemon --pin-packages script.js
In order to ensure a script can execute offline, and without any download delays, you can ask Tasklemon to preload all of the script's required packages. These include packages you implicitely require, not just the packages pinned by version directives.
This has no purpose for a script that's been run at least once, since Tasklemon will already have downloaded its packages.
$ lemon --preload-pkg script.js
Tasklemon's package cache is generally very resilient, and can recover from most download and installation issues. If something seems broken, however, you can try emptying the package cache.
$ lemon --clear-pkg-cache