package-manager-manager
Advanced tools
Comparing version 0.0.0 to 0.1.0
@@ -1,2 +0,3 @@ | ||
export * from './utils'; | ||
export { getPackageManager } from './packageManager'; | ||
export type { PackageManager, PackageManagerName } from './packageManager'; | ||
//# sourceMappingURL=index.d.ts.map |
20
index.js
@@ -1,5 +0,21 @@ | ||
import { isWindows as r } from "./utils/os.js"; | ||
import { getPackageManager as h } from "./packageManager.js"; | ||
import "shellac"; | ||
import "./commands/getRunScript.js"; | ||
import "./commands/getRunExec.js"; | ||
import "node:fs/promises"; | ||
import "node:path"; | ||
import "node:process"; | ||
import "./utils/locks.js"; | ||
import "./utils/yarn.js"; | ||
import "./package/index.js"; | ||
import "./package/bun.js"; | ||
import "./package/npm.js"; | ||
import "./package/shared.js"; | ||
import "./package/pnpm.js"; | ||
import "./package/yarn.js"; | ||
import "./utils/workspace.js"; | ||
import "./utils/cliCommands.js"; | ||
export { | ||
r as isWindows | ||
h as getPackageManager | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "package-manager-manager", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"description": "Utilities for managing package managers.", | ||
@@ -11,9 +11,17 @@ "license": "MIT", | ||
"import": "./index.js", | ||
"require": "./index.cjs", | ||
"types": "./index.d.ts" | ||
"require": "./index.cjs" | ||
} | ||
}, | ||
"typesVersions": { | ||
"*": { | ||
"types": [ | ||
"./index.d.ts" | ||
] | ||
} | ||
}, | ||
"publishConfig": { | ||
"directory": "dist" | ||
}, | ||
"main": "./index.js", | ||
"types": "./index.d.ts", | ||
"repository": { | ||
@@ -30,6 +38,9 @@ "type": "git", | ||
"@tsconfig/strictest": "^2.0.1", | ||
"@types/mock-fs": "^4.13.1", | ||
"@types/node": "^20.3.3", | ||
"eslint": "^8.41.0", | ||
"eslint": "^8.44.0", | ||
"eslint-config-ixn": "^1.4.2", | ||
"prettier": "^2.8.8", | ||
"eslint-plugin-unicorn": "^48.0.1", | ||
"mock-fs": "^5.2.0", | ||
"prettier": "^3.0.0", | ||
"typescript": "^5.0.4", | ||
@@ -42,13 +53,15 @@ "vite": "^4.3.5", | ||
"dependencies": { | ||
"js-yaml": "^4.1.0" | ||
"js-yaml": "^4.1.0", | ||
"shellac": "^0.8.0" | ||
}, | ||
"scripts": { | ||
"build": "vite build && node ./scripts/build.js", | ||
"build": "vite build", | ||
"build:watch": "pnpm run build --watch", | ||
"lint": "eslint \"./**/*.{cjs,js,jsx,ts,tsx}\"", | ||
"prettier": "prettier --ignore-unknown --ignore-path=.gitignore --check .", | ||
"prettier:format": "prettier --ignore-unknown --ignore-path=.gitignore --write .", | ||
"prettier": "prettier --ignore-unknown --ignore-path .gitignore --ignore-path .prettierignore --check .", | ||
"prettier:fix": "prettier --ignore-unknown --ignore-path .gitignore --ignore-path .prettierignore --write .", | ||
"tsc": "tsc --noEmit", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"test": "vitest run --dir=tests", | ||
"test:watch": "vitest --dir=tests", | ||
"test:e2e": "vitest run --dir=e2e --no-threads", | ||
"test:coverage": "vitest run --coverage", | ||
@@ -55,0 +68,0 @@ "alter-version": "node ./scripts/alter-version.js", |
103
README.md
@@ -20,8 +20,107 @@ <p align="center"> | ||
**package-manager-manager** is a library aimed at providing information regarding the package manager currently being used in a given project. | ||
It can be used in CLIs or similar projects which may at some point need to know and adapt their behavior based on the package manager currently used by the developer (e.g. A project scaffolding tool, a bundling tool, etc...). | ||
## Usage | ||
Add the library to your project. | ||
To use the library first install it in your project, via: | ||
```sh | ||
npm add package-manager-manager | ||
npm i package-manager-manager | ||
``` | ||
(or your package manager's equivalent) | ||
Then simply import and use the `getPackageManager()` function to get an object containing all the information you need regarding the package manager currently being used: | ||
```js | ||
const packageManager = await getPackageManager(); | ||
console.log(packageManager.name); | ||
// logs 'npm', 'yarn', 'pnpm' or 'bun' | ||
console.log(packageManager.version); | ||
// logs the version of the package manager e.g. '8.11.0' | ||
``` | ||
> **Note** | ||
> This library comes with properly defined and documented typescript types, meaning that once you obtain the `PackageManager` object you will be able to easily see what's available on it and get all necessary details directly in your IDE | ||
### API | ||
### getPackageInfo | ||
`packageManager.getPackageInfo` allows you to get the information regarding a locally installed package that your client application is using, it can for example be used to make sure your user's application has a certain dependency or to gather and display the package version of such dependency. | ||
For example: | ||
```js | ||
const zodPackage = await packageManager.getPackageInfo('zod'); | ||
if (zodPackage) { | ||
console.log(`starting validation using zod (version: ${zodPackage.version}`); | ||
} else { | ||
throw new Error('Error: zod is not installed'); | ||
} | ||
``` | ||
> **Note** | ||
> This method only returns the information of a **locally installed package**, or _null_ in case the package is not installed, it does not return information of packages not locally installed (the API could be extended in the future to also include such use case) | ||
### getRunScript | ||
`packageManager.getRunScript` let's you create a command that can be used to run a script defined in the package.json file. | ||
For example: | ||
```js | ||
const buildStr = packageManager.getRunScript('build', { | ||
args: ['./dist', '--verbose'], | ||
}); | ||
console.log(`To build your application run: ${buildStr}`); | ||
``` | ||
If you need more fine grained control over the command you can use its `packageManager.getRunScriptStruct` alternative to obtain an object representing the command. | ||
For example: | ||
```js | ||
import { spawn } from 'child_process'; | ||
const buildCmd = packageManager.getRunScriptStruct('build', { | ||
args: ['./dist', '--verbose'], | ||
}); | ||
// run the command for the user | ||
spawn(buildCmd.cmd, buildCmd.cmdArgs); | ||
``` | ||
### getRunExec | ||
`packageManager.getRunExec` let's you create a command that can be used to execute a command from a target package (which may or may not be locally installed). | ||
For example: | ||
```js | ||
const eslintStr = packageManager.getRunExec('eslint', { | ||
args: ['./src', '--quiet'], | ||
}); | ||
console.log(`To run eslint on your application run: ${eslintStr}`); | ||
``` | ||
If you need more fine grained control over the command you can use its `packageManager.getRunExecStruct` alternative to obtain an object representing the command. | ||
For example: | ||
```js | ||
import { spawn } from 'child_process'; | ||
const eslintCmd = packageManager.getRunExec('eslint', { | ||
args: ['./src', '--quiet'], | ||
}); | ||
// run the command for the user | ||
spawn(eslintCmd.cmd, eslintCmd.cmdArgs); | ||
``` |
export * from './os'; | ||
export * from './workspace'; | ||
export * from './locks'; | ||
export * from './yarn'; | ||
export * from './cliCommands'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,5 +0,17 @@ | ||
import { isWindows as r } from "./os.js"; | ||
import { isWindows as m } from "./os.js"; | ||
import { getProjectRootDir as s } from "./workspace.js"; | ||
import { isLockFile as l, lockFiles as x } from "./locks.js"; | ||
import { isYarnClassic as a } from "./yarn.js"; | ||
import { getPmCliCommandKeywords as n } from "./cliCommands.js"; | ||
import "node:fs/promises"; | ||
import "node:path"; | ||
import "node:process"; | ||
export { | ||
r as isWindows | ||
n as getPmCliCommandKeywords, | ||
s as getProjectRootDir, | ||
l as isLockFile, | ||
m as isWindows, | ||
a as isYarnClassic, | ||
x as lockFiles | ||
}; | ||
//# sourceMappingURL=index.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 6 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
124560
111
918
126
2
14
11
1
+ Addedshellac@^0.8.0
+ Addedreghex@1.0.2(transitive)
+ Addedshellac@0.8.0(transitive)