import-local
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
pkg-dir | 4.2.0 | 2.07 kB | MIT | prod | |
resolve-cwd | 3.0.0 | 1.91 kB | MIT | prod |
The "import-local" is a utility package that allows a globally installed package to utilize a locally installed version of itself when available. This is particularly useful for CLI tools that want to defer to the user's locally installed version when it's available, but still function if it's not installed locally. AVA and XO are such examples that make use of this method.
To use import-local, first ensure that it is installed in your project by running the command: npm install import-local
. Once done, you can include and use it in your JavaScript code as shown in the example below:
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…
}
In a CommonJS context, you can also pass in __filename
.
The official documentation of import-local can be found in its readme on the GitHub package site at: git+https://github.com/sindresorhus/import-local.git. The readme provides a detailed explanation of how to install and utilize import-local in a detailed and concise manner. There are no additional specific "import-local" docs aside from the readme on the GitHub page.