UNPKG

1.05 kBMarkdownView Raw
1# import-local
2
3> Let a globally installed package use a locally installed version of itself if available
4
5Useful for CLI tools that want to defer to the user's locally installed version when available, but still work if it's not installed locally. For example, [AVA](https://avajs.dev) and [XO](https://github.com/xojs/xo) uses this method.
6
7
8## Install
9
10```
11$ npm install import-local
12```
13
14
15## Usage
16
17```js
18const importLocal = require('import-local');
19
20if (importLocal(__filename)) {
21 console.log('Using local version of this package');
22} else {
23 // Code for both global and local version here…
24}
25```
26
27
28---
29
30<div align="center">
31 <b>
32 <a href="https://tidelift.com/subscription/pkg/npm-import-local?utm_source=npm-import-local&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
33 </b>
34 <br>
35 <sub>
36 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
37 </sub>
38</div>