feature: vor und nachteile

This commit is contained in:
Hikyu
2026-05-31 13:54:31 +02:00
parent 552a947a1c
commit e3dad17446
23270 changed files with 3024794 additions and 200 deletions
+35
View File
@@ -0,0 +1,35 @@
/**
Resolve the path of a globally installed module.
@param moduleName - What you would use in [`import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import).
@returns The resolved path. Throws if the module cannot be found.
@example
```
// $ npm install --global cat-names
import {resolveGlobal} from 'resolve-global';
console.log(resolveGlobal('cat-names'));
//=> '/usr/local/lib/node_modules/cat-names'
```
*/
export function resolveGlobal(moduleName: string): string;
/**
Resolve the path of a globally installed module.
@param moduleName - What you would use in [`import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import).
@returns The resolved path. Returns `undefined` instead of throwing if the module cannot be found.
@example
```
// $ npm install --global cat-names
import {resolveGlobalSilent} from 'resolve-global';
console.log(resolveGlobalSilent('cat-names'));
//=> '/usr/local/lib/node_modules/cat-names'
```
*/
export function resolveGlobalSilent(moduleName: string): string | undefined;
+20
View File
@@ -0,0 +1,20 @@
import {createRequire} from 'node:module';
import globalDirectory from 'global-directory';
// TODO: Use `import.meta.resolve` when targeting Node.js 22.
const {resolve} = createRequire(import.meta.url);
export function resolveGlobal(moduleName) {
return resolve(moduleName, {
paths: [
globalDirectory.yarn.packages,
globalDirectory.npm.packages,
],
});
}
export function resolveGlobalSilent(moduleName) {
try {
return resolveGlobal(moduleName);
} catch {}
}
+9
View File
@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+53
View File
@@ -0,0 +1,53 @@
{
"name": "resolve-global",
"version": "2.0.0",
"description": "Resolve the path of a globally installed module",
"license": "MIT",
"repository": "sindresorhus/resolve-global",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {
"node": ">=18"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"resolve",
"global",
"package",
"module",
"globally",
"path",
"npm",
"yarn",
"packages",
"require"
],
"dependencies": {
"global-directory": "^4.0.1"
},
"devDependencies": {
"ava": "^5.3.1",
"execa": "^8.0.1",
"tsd": "^0.29.0",
"xo": "^0.56.0"
},
"ava": {
"timeout": "10m"
}
}
+46
View File
@@ -0,0 +1,46 @@
# resolve-global
> Resolve the path of a globally installed module
## Install
```sh
npm install resolve-global
```
## Usage
```sh
npm install --global cat-names
```
```js
import {resolveGlobal} from 'resolve-global';
console.log(resolveGlobal('cat-names'));
//=> '/usr/local/lib/node_modules/cat-names'
```
## API
### resolveGlobal(moduleName)
Throws if the module cannot be found.
### resolveGlobalSilent(moduleName)
Returns `undefined` instead of throwing if the module cannot be found.
#### moduleName
Type: `string`
What you would use in [`import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import).
## Related
- [import-global](https://github.com/sindresorhus/import-global) - Import a globally installed module
- [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module from a given path
- [import-from](https://github.com/sindresorhus/import-from) - Import a module from a given path
- [is-installed-globally](https://github.com/sindresorhus/is-installed-globally) - Check if your package was installed globally
- [global-directory](https://github.com/sindresorhus/global-directory) - Get the directory of globally installed packages and binaries