Skip to content

Adding support for exclude option #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ import npmOutdated from "danger-plugin-npm-outdated";

// Note: You need to use schedule()
schedule(npmOutdated());

// example using options
schedule(npmOutdated({ exclude: ['package-name'] }));
```

## Options
| Option | Type | Default |
| ------ | ---- | ------- |
| `exclude` | `string[]` | `[]` |


## Sample message

![sample message](https://raw.githubusercontent.com/revathskumar/danger-plugin-npm-outdated/master/images/message.png)
Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ const execP = outdatedCommand => {
};

export default async function npmOutdated(options = {}) {
const exclude = (options && options.exclude) || [];
if (exclude && !Array.isArray(exclude)) {
throw new TypeError('exclude option must be of type string[] containing package names to exclude');
}

let outdatedCommand = "npm outdated --json";

try {
const outdatedPackages = await execP(outdatedCommand);
const packageNames = Object.keys(outdatedPackages);
const packageNames = Object.keys(outdatedPackages).filter((packageName) => !exclude.includes(packageName));
if (packageNames.length) {
const packagesTable = formatOutdatedPackages(
outdatedPackages,
Expand Down