multi-tool | Install and require multiple simultaneous versions of any NPM package
Install multiple versions of NPM packages at runtime. Use any semver ranges which are also a valid (Li|U)nix directory
names as your version and require
them intuitively (e.g. require('ramda@0.23.x')
, require('ramda@~0.22.1')
,
require('ramda@latest')
). Leverage custom invalidators to automatically keep installed packages up-to-date.
Install
$ npm install --save multi-tool$ # OR $ yarn add multi-tool
Usage
Require:
An options object is required to configure before using, only path
is required.
const options = // Path to install against path: 'node_modules' // Function used to determine if package should be invalidated and reinstalled when already installed age >= NumberMAX_SAFE_INTEGER // Milliseconds to delay when an install is already occurring before reattempting delay: 2500 // Milliseconds maximum to delay before an install is considered failed if an install is already occurring timeout: 60000;const install = options;
Install and use latest version:
const installed = await ;const R = ; R;
Install and use exact version:
const installed = await ;const R = ; R;
Install and use x-based version:
const installed = await ;const R = ; R;
Install and use tilde-based version:
const installed = await ;const R = ; R;
Install and use caret-based version:
const installed = await ;const R = ; R;
Install invalid package:
const installed = await ;
Install invalid version:
const installed = await ;
Custom invalidators:
It is possible to use custom invalidators to customize when multi-tool
should assume an already successfully
installed package should be reinstalled. This is accomplished via a higher-order function passed as an argument upon
require
. The invalidator function is executed upon each install
. The invalidator function is provided the package
name
, the package version
, and how many milliseconds ago the package at hand was last successfully installed.
The invalidator function should return a Boolean
value which when true will invalidate the previously successfully
installed package and reinstall. The default invalidator behavior is to always invalidate.
Invalidate always:
const invalidate = age >= 0;const install = path: 'node_modules' invalidate;
Invalidate never:
const invalidate = age >= NumberMAX_SAFE_INTEGER;const install = path: 'node_modules' invalidate;
Invalidate only latest versions and only after 10 minutes:
const invalidate = version === 'latest' && age >= 600000;const install = path: 'node_modules' invalidate;
Maintainers
- Rocky Madden (@rockymadden)