Skip to content

Commit

Permalink
chore: update readme with automd
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 6, 2024
1 parent a7dfce7 commit d523b47
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 31 deletions.
87 changes: 58 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
+------------------------------------------------+
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -56,4 +57,4 @@
"engines": {
"node": "^14.16.0 || >=16.10.0"
}
}
}
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d523b47

Please sign in to comment.