diff --git a/README.md b/README.md index 094d1d3..4108b6c 100644 --- a/README.md +++ b/README.md @@ -5,34 +5,32 @@ [![Github Actions][github-actions-src]][github-actions-href] [![Codecov][codecov-src]][codecov-href] -> Unified Package Manager for Node.js - -🚧 This project is under development. Please follow [issues](https://github.com/unjs/nypm/issues) for the roadmap. 🚧 +> Unified Package Manager for Node.js and Bun ## What does **nypm** do? -✅ Supports **npm, yarn, pnpm and bun** out of the box with a unified API +✅ Supports [npm](https://docs.npmjs.com/cli/v10/commands/npm), [Yarn](https://yarnpkg.com/), [pnpm](https://pnpm.io/) and [bun](https://bun.sh/package-manager) out of the box with a unified API. -✅ Provides an **API interface** to interact with package managers +✅ Provides an **API interface** to interact with package managers. -✅ **Autodetects** project's package manager using package.json and known lockfiles +✅ **Autodetects** project's package manager using `package.json` and known lockfiles. -✅ **Auto-installs and use exactly expected version** of supported package managers using [nodejs/corepack](https://github.com/nodejs/corepack) +✅ **Auto-installs and use exactly expected version** of supported package managers using [nodejs/corepack](https://github.com/nodejs/corepack) when available. -✅ **Minimal** implementation +✅ **Minimal** implementation. -nypm, detects package manager type and version and converts command into package manager CLI arguments. It then uses corepack to execute package manager's command (and download it if necessary). +nypm, detects package manager type and version and converts command into package manager CLI arguments. It then uses corepack or proper command to execute package manager's command and download it if necessary. ``` +------------------------------------------------+ | nypm | +------------------------------------------------+ - +-----------------------------------+ - | Corepack | - +-----------------------------------+ - +---------+ +---------+ +---------+ +---------+ - | npm | | yarn | | pnpm | | bun | - +---------+ +---------+ +---------+ +---------+ + +-----------------------------------+ +---------+ + | Corepack | | bun | + +-----------------------------------+ +---------+ + +---------+ +---------+ +---------+ + | npm | | yarn | | pnpm | + +---------+ +---------+ +---------+ +------------------------------------------------+ | Node.js project | +------------------------------------------------+ @@ -43,61 +41,92 @@ nypm, detects package manager type and version and converts command into package **Install dependencies:** ```sh -npx nypm@latest i +npx nypm i ``` **Add a dependency:** ```sh -npx nypm@latest add defu +npx nypm add defu ``` **Remove a dependency:** ```sh -npx nypm@latest remove defu +npx nypm remove defu ``` ## API Usage Install package: +<!-- AUTOMD_START generator="pm-install" name="nypm" --> + ```sh +# ✨ Auto-detect +npx nypm i nypm + # npm npm install nypm -# pnpm -pnpm install nypm - # yarn yarn add nypm +# pnpm +pnpm install nypm + # bun bun install nypm ``` +<!-- AUTOMD_END --> + Import: ```js // ESM import { - detectPackageManager, - installDependencies, addDependency, - addDevDependency, - removeDependency, } from "nypm"; // CommonJS const { - detectPackageManager, - installDependencies, addDependency, - addDevDependency, - removeDependency, } = require("nypm"); ``` +<!-- AUTOMD_START generator="jsdocs" --> + +### `addDependency(name, options)` + +Adds dependency to the project. + +### `addDevDependency(name, options)` + +Adds dev dependency to the project. + +### `detectPackageManager(cwd, options)` + +Detect the package manager used in a directory (and up) by checking various sources: + +1. Use `packageManager` field from package.json +2. Known lock files and other files + +### `ensureDependencyInstalled(name, options)` + +Ensures dependency is installed. + +### `installDependencies(options)` + +Installs project dependencies. + +### `removeDependency(name, options)` + +Removes dependency from the project. + + +<!-- AUTOMD_END --> + ## 💻 Development - Clone this repository diff --git a/package.json b/package.json index dc2aa23..20109a9 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "dist" ], "scripts": { - "build": "unbuild", + "build": "automd && unbuild", "dev": "vitest dev", "lint": "eslint --ext .ts,.js,.mjs,.cjs . && prettier -c src test", "lint:fix": "eslint --ext .ts,.js,.mjs,.cjs . --fix && prettier -w src test", @@ -42,6 +42,7 @@ "devDependencies": { "@types/node": "^20.11.16", "@vitest/coverage-v8": "^1.2.2", + "automd": "^0.1.4", "changelogen": "^0.5.5", "eslint": "^8.56.0", "eslint-config-unjs": "^0.2.1", @@ -56,4 +57,4 @@ "engines": { "node": "^14.16.0 || >=16.10.0" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fed3ebd..031be14 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -25,6 +25,9 @@ devDependencies: '@vitest/coverage-v8': specifier: ^1.2.2 version: 1.2.2(vitest@1.2.2) + automd: + specifier: ^0.1.4 + version: 0.1.4 changelogen: specifier: ^0.5.5 version: 0.5.5 @@ -1179,6 +1182,20 @@ packages: resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==} dev: true + /automd@0.1.4: + resolution: {integrity: sha512-zRo8YtH2SI1fa4gJn/ykVuunfO/SAE5+I4XTEu6dQkUFOV6ydYhMI1F818LgX5K2CoBQJNNWKiF67CNz3ixTfg==} + hasBin: true + dependencies: + citty: 0.1.5 + consola: 3.2.3 + destr: 2.0.2 + magic-string: 0.30.7 + scule: 1.3.0 + untyped: 1.4.2 + transitivePeerDependencies: + - supports-color + dev: true + /autoprefixer@10.4.17(postcss@8.4.34): resolution: {integrity: sha512-/cpVNRLSfhOtcGflT13P2794gVSgmPgTR+erw5ifnMLZb0UnSlkK4tquLmkd3BhA+nLo5tX8Cu0upUsGKvKbmg==} engines: {node: ^10 || ^12 || >=14}