Skip to content
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