Skip to content

Commit

Permalink
cli,outdated: Adds 'Homepage' to outdated --long output. (#81)
Browse files Browse the repository at this point in the history
* feat(cli, outdated): Adds 'Homepage' to outdated --long output.

- `package.json`'s `homepage` property is displayed when using the `--long` option for `npm outdated`

* test: npm outdated --long

- Adds `homepage` to `--parseable` output.
- Updates `npm outdated --long` test to include `homepage` in expected output.
- Adds `homepage` to `npm-outdated` documentation.

* fix: javascript standard style updates

PR-URL: #81
Credit: @jbottigliero
Reviewed-By: @zkat
  • Loading branch information
Joe Bottigliero authored and zkat committed Dec 10, 2018
1 parent 6c4ce6e commit 05f3fe2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/cli/npm-outdated.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ In the output:
* `package type` (when using `--long` / `-l`) tells you whether this package is
a `dependency` or a `devDependency`. Packages not included in `package.json`
are always marked `dependencies`.
* `homepage` (when using `--long` / `-l`) is the `homepage` value contained in the package's `package.json`
* Red means there's a newer version matching your semver requirements, so you should update now.
* Yellow indicates that there's a newer version above your semver requirements (usually new major, or new 0.x minor) so proceed with caution.

Expand Down
15 changes: 11 additions & 4 deletions lib/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function outdated (args, silent, cb) {
'Latest',
'Location'
]
if (long) outHead.push('Package Type')
if (long) outHead.push('Package Type', 'Homepage')
var outTable = [outHead].concat(outList)

if (npm.color) {
Expand Down Expand Up @@ -123,14 +123,18 @@ function makePretty (p) {
var latest = p[4]
var type = p[6]
var deppath = p[7]
var homepage = p[0].package.homepage

var columns = [ depname,
has || 'MISSING',
want,
latest,
deppath
]
if (long) columns[5] = type
if (long) {
columns[5] = type
columns[6] = homepage
}

if (npm.color) {
columns[0] = color[has === want || want === 'linked' ? 'yellow' : 'red'](columns[0]) // dep
Expand All @@ -157,7 +161,7 @@ function makeParseable (list) {
(has ? (depname + '@' + has) : 'MISSING'),
depname + '@' + latest
]
if (long) out.push(type)
if (long) out.push(type, dep.package.homepage)

return out.join(':')
}).join(os.EOL)
Expand All @@ -181,7 +185,10 @@ function makeJSON (list) {
latest: latest,
location: dir
}
if (long) out[depname].type = type
if (long) {
out[depname].type = type
out[depname].homepage = dep.package.homepage
}
})
return JSON.stringify(out, null, 2)
}
Expand Down
4 changes: 4 additions & 0 deletions test/tap/outdated-long.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ test('it should not throw', function (t) {
npm.install('.', function (err) {
t.ifError(err, 'install success')
npm.config.set('long', true)
// since it's possible for the homepage of a package to change, after the
// install we read the value from the package.json directly to specify our
// expected output.
expOut[1] = expOut[1] + ':' + JSON.parse(fs.readFileSync(path.resolve(pkg, 'node_modules', 'underscore', 'package.json'))).homepage
npm.outdated(function (er, d) {
t.ifError(err, 'npm outdated ran without error')
t.is(process.exitCode, 1, 'exit code set to 1')
Expand Down

0 comments on commit 05f3fe2

Please sign in to comment.