https://github.com/cloud-elements/multi-tool
:package: Install and require multiple simultaneous versions of any NPM package
https://github.com/cloud-elements/multi-tool
multiple nodejs npm package require semver simultaneous versioning
Last synced: 7 days ago
JSON representation
:package: Install and require multiple simultaneous versions of any NPM package
- Host: GitHub
- URL: https://github.com/cloud-elements/multi-tool
- Owner: cloud-elements
- Created: 2017-02-03T19:29:45.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-01-25T22:14:36.000Z (about 8 years ago)
- Last Synced: 2025-10-04T14:52:35.936Z (4 months ago)
- Topics: multiple, nodejs, npm, package, require, semver, simultaneous, versioning
- Language: JavaScript
- Homepage:
- Size: 260 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# multi-tool | Install and require multiple simultaneous versions of any NPM package
[](https://www.npmjs.com/package/multi-tool)
[](http://semver.org/)
[](https://guides.github.com/introduction/flow/)
[](https://github.com/sindresorhus/xo)
[](https://en.wikipedia.org/wiki/Functional_programming)
[](https://circleci.com/gh/cloud-elements/multi-tool)
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
```bash
$ 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.
```javascript
const options = {
// Path to install against
path: 'node_modules',
// Function used to determine if package should be invalidated and reinstalled when already installed
invalidate: (name, version, age) => age >= Number.MAX_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 = require('multi-tool')(options);
```
### Install and use latest version:
```javascript
const installed = await install('ramda', 'latest');
const R = require('ramda@latest');
R.identity(0);
```
### Install and use exact version:
```javascript
const installed = await install('ramda', '0.23.0');
const R = require('ramda@0.23.0');
R.identity(0);
```
### Install and use x-based version:
```javascript
const installed = await install('ramda', '0.23.x');
const R = require('ramda@0.23.x');
R.identity(0);
```
### Install and use tilde-based version:
```javascript
const installed = await install('ramda', '~0.22.1');
const R = require('ramda@~0.22.1');
R.identity(0);
```
### Install and use caret-based version:
```javascript
const installed = await install('ramda', '^0.22.1');
const R = require('ramda@^0.22.1');
R.identity(0);
```
### Install invalid package:
```javascript
const installed = await install('package-doesnt-exist', 'latest');
```
### Install invalid version:
```javascript
const installed = await install('ramda', '99.99.99');
```
### 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:
```javascript
const invalidate = (name, version, age) => age >= 0;
const install = require('multi-tool')({path: 'node_modules', invalidate});
```
#### Invalidate never:
```javascript
const invalidate = (name, version, age) => age >= Number.MAX_SAFE_INTEGER;
const install = require('multi-tool')({path: 'node_modules', invalidate});
```
#### Invalidate only latest versions and only after 10 minutes:
```javascript
const invalidate = (name, version, age) => version === 'latest' && age >= 600000;
const install = require('multi-tool')({path: 'node_modules', invalidate});
```
## Maintainers
* Rocky Madden ([@rockymadden](https://github.com/rockymadden))