Skip to content

Commit

Permalink
feat: update README with example and motivation
Browse files Browse the repository at this point in the history
  • Loading branch information
jase88 committed Jul 24, 2023
1 parent 2e29d3f commit 33ff270
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
58 changes: 55 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# filter-npm-deps

![npm](https://img.shields.io/npm/v/filter-npm-deps?style=flat-square)

filter-npm-deps is a convenient Node.js CLI script designed to filter a given list of dependencies from your `package.json`.

It supports filtering dependencies from all three commonly used dependency fields: *dependencies*, *devDependencies*, and *optionalDependencies*.
It supports filtering dependencies from all three commonly used dependency fields: _dependencies_, _devDependencies_, and _optionalDependencies_.

## 🎯 Motivation

In many projects, the `package.json` file contains numerous dependencies serving different purposes.
However, certain scenarios, like CI jobs, demand only specific dependencies in particular versions.
Therefore `filter-npm-deps` can reduce or prune your package.json, to only contain the dependencies that you need.

## 🚀 Usage

Expand All @@ -13,12 +20,57 @@ To use filter-npm-deps, you can easily invoke it with npx as follows:
npx filter-npm-deps -d [dependencies]
```

For example, if you want to only keep "lodash" and "axios" with the given version from your package.json, you can run:
## 🧰 Requirements

- node.js 18 or higher

## 📝Example

Given the following package.json:

```json
{
"name": "my-app",
"description": "...",
"dependencies": {
"axios": "1.4.0",
"lodash-es": "4.17.21"
},
"devDependencies": {
"typescript": "5.1.6"
},
"optionalDependencies": {
"playwright": "1.36.1"
}
}
```

If you want to only keep `playwright` and `lodash-es` with the given version from your package.json, you can run:

```bash
npx filter-npm-deps -d "lodash, axios"
npx filter-npm-deps -d "playwright,lodash-es"
```

which would result in:

```json
{
"name": "my-app",
"description": "...",
"dependencies": {
"lodash-es": "4.17.21"
},
"devDependencies": {},
"optionalDependencies": {
"playwright": "1.36.1"
}
}
```

Afterward you can install your dependencies with your package manager of choice.

For example with npm:
`npm ci`

## 💡 Alternatives

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "filter-npm-deps",
"version": "0.1.0",
"description": "",
"version": "0.1.1",
"description": "A convenient Node.js CLI script to filter and only keep a list of dependencies from your package.json",
"engines": {
"node": ">=18"
},
Expand All @@ -10,7 +10,6 @@
},
"repository": "https://github.com/jase88/filter-npm-deps",
"homepage": "https://github.com/jase88/filter-npm-deps#readme",
"author": "",
"license": "MIT",
"keywords": [
"filter",
Expand Down

0 comments on commit 33ff270

Please sign in to comment.