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

feat(cli, outdated): Adds 'Homepage' to outdated --long output. #81

Merged
merged 3 commits into from Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/cli/npm-outdated.md
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
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
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