Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/import-local
Let a globally installed package use a locally installed version of itself if available
https://github.com/sindresorhus/import-local
Last synced: about 1 month ago
JSON representation
Let a globally installed package use a locally installed version of itself if available
- Host: GitHub
- URL: https://github.com/sindresorhus/import-local
- Owner: sindresorhus
- License: mit
- Created: 2017-05-04T17:49:22.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2022-01-06T08:17:24.000Z (almost 3 years ago)
- Last Synced: 2024-04-14T09:52:45.836Z (7 months ago)
- Language: JavaScript
- Size: 89.8 KB
- Stars: 151
- Watchers: 7
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- awesome-nodejs - import-local - 允许全局安装的 CLI工具 使用自身的本地安装版本 (Uncategorized / Uncategorized)
- awesome-javascript - import-local
- awesome-javascript - import-local
README
# import-local
> Let a globally installed package use a locally installed version of itself if available
Useful 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.
## Install
```sh
npm install import-local
```## Usage
```js
import importLocal from 'import-local';if (importLocal(import.meta.url)) {
console.log('Using local version of this package');
} else {
// Code for both global and local version here…
}
```You can also pass in `__filename` when used in a CommonJS context.