From 4be51a9cc65635bb26fa4ce62233f26e0104bc20 Mon Sep 17 00:00:00 2001 From: Joe Bottigliero Date: Mon, 26 Nov 2018 10:13:52 -0600 Subject: [PATCH] cli,outdated: Adds 'Homepage' to outdated --long output. (#81) * 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: https://github.com/npm/cli/pull/81 Credit: @jbottigliero Reviewed-By: @zkat --- doc/cli/npm-outdated.md | 1 + lib/outdated.js | 15 +++++++++++---- test/tap/outdated-long.js | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/doc/cli/npm-outdated.md b/doc/cli/npm-outdated.md index ad0d003ceef4..045586a40a72 100644 --- a/doc/cli/npm-outdated.md +++ b/doc/cli/npm-outdated.md @@ -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. diff --git a/lib/outdated.js b/lib/outdated.js index 8b0a43d6ba33..024e076c4f9a 100644 --- a/lib/outdated.js +++ b/lib/outdated.js @@ -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) { @@ -123,6 +123,7 @@ 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', @@ -130,7 +131,10 @@ function makePretty (p) { 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 @@ -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) @@ -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) } diff --git a/test/tap/outdated-long.js b/test/tap/outdated-long.js index 6ea5e6e2c420..976d416a13bb 100644 --- a/test/tap/outdated-long.js +++ b/test/tap/outdated-long.js @@ -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')