Skip to content

Add option to only consider prod dependencies #11

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 1 commit 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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ import npmOutdated from "danger-plugin-npm-outdated";
schedule(npmOutdated());
```

## Options

|Name|Default|Function|
|-|-|-|
|prodOnly|false|Only consider production dependencies|

Pass options to the `npmOutdated` function

```ts
scheduled(npmOutdated({ prodOnly: true }))
```

## Sample message

![sample message](https://raw.githubusercontent.com/revathskumar/danger-plugin-npm-outdated/master/images/message.png)
Expand Down
25 changes: 16 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use strict";
const exec = require("child_process").exec;

const formatOutdatedPackages = (outdatedPackages = {}, packageNames = []) => {
const formatOutdatedPackages = (outdatedPackages = {}, packageNames = [], options = {}) => {
const headers = [
"| Package | Current | Wanted | latest |",
"|---------|---------|--------|--------|"
`| Package | Current | Wanted | latest |${options.prodOnly ? '' : ' kind |'}`,
`|---------|---------|--------|--------|${options.prodOnly ? '' : '------|'}`
];
const content = packageNames.map(packageName => {
const { current, wanted, latest } = outdatedPackages[packageName];
return `| ${packageName} | ${current} | ${wanted} | ${latest} |`;
const { current, wanted, latest, type } = outdatedPackages[packageName];
return `| ${packageName} | ${current} | ${wanted} | ${latest} |${options.prodOnly ? '' : `${type} |`}`;
});
return headers.concat(content).join("\n");
};
Expand All @@ -27,19 +27,26 @@ const execP = outdatedCommand => {
});
};

export default async function npmOutdated(options = {}) {
let outdatedCommand = "npm outdated --json";
export default async function npmOutdated(options = {
prodOnly: false,
}) {
let outdatedCommand = "npm outdated --json --long";

if (options.prodOnly){
outdatedCommand += ' --production'
}

try {
const outdatedPackages = await execP(outdatedCommand);
const packageNames = Object.keys(outdatedPackages);
if (packageNames.length) {
const packagesTable = formatOutdatedPackages(
outdatedPackages,
packageNames
packageNames,
options
);

warn(`You have ${packageNames.length} outdated packages`);
warn(`You have ${packageNames.length} outdated ${options.prodOnly ? 'production' : ''} packages`);
markdown(`

<details>
Expand Down