-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Add support subcommand #246
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a8a2001
support: add support subcommand
kemitchell 9415ba0
support: fix request caching
kemitchell 6f944dd
support: further sanitize contributor data
kemitchell b892bf8
doc: Fix typo
kemitchell 1901d25
support: simplify to just collecting and showing URLs
kemitchell 1e8fe84
install: improve `npm support` test
kemitchell 6e6c732
install: drop "the" before "projects you depend on"
kemitchell e2c042a
doc: Reword mention of `npm support` in `package.json` spec
kemitchell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,7 @@ var cmdList = [ | |
'token', | ||
'profile', | ||
'audit', | ||
'support', | ||
'org', | ||
|
||
'help', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
'use strict' | ||
|
||
const npm = require('./npm.js') | ||
const output = require('./utils/output.js') | ||
const path = require('path') | ||
const readPackageTree = require('read-package-tree') | ||
const semver = require('semver') | ||
const validSupportURL = require('./utils/valid-support-url') | ||
|
||
module.exports = support | ||
|
||
const usage = require('./utils/usage') | ||
support.usage = usage( | ||
'support', | ||
'\nnpm support [--json]' | ||
) | ||
|
||
support.completion = function (opts, cb) { | ||
const argv = opts.conf.argv.remain | ||
switch (argv[2]) { | ||
case 'support': | ||
return cb(null, []) | ||
default: | ||
return cb(new Error(argv[2] + ' not recognized')) | ||
} | ||
} | ||
|
||
// Compare lib/ls.js. | ||
function support (args, silent, cb) { | ||
if (typeof cb !== 'function') { | ||
cb = silent | ||
silent = false | ||
} | ||
const dir = path.resolve(npm.dir, '..') | ||
readPackageTree(dir, function (err, tree) { | ||
if (err) { | ||
process.exitCode = 1 | ||
return cb(err) | ||
} | ||
const data = findPackages(tree) | ||
if (silent) return cb(null, data) | ||
var out | ||
if (npm.config.get('json')) { | ||
out = JSON.stringify(data, null, 2) | ||
} else { | ||
out = data.map(displayPackage).join('\n\n') | ||
} | ||
output(out) | ||
cb(err, data) | ||
}) | ||
} | ||
|
||
function findPackages (root) { | ||
const set = new Set() | ||
iterate(root) | ||
return Array.from(set).sort(function (a, b) { | ||
const comparison = a.name | ||
.toLowerCase() | ||
.localeCompare(b.name.toLowerCase()) | ||
return comparison === 0 | ||
? semver.compare(a.version, b.version) | ||
: comparison | ||
}) | ||
|
||
function iterate (node) { | ||
node.children.forEach(recurse) | ||
} | ||
|
||
function recurse (node) { | ||
const metadata = node.package | ||
const support = metadata.support | ||
if (support && validSupportURL(support)) { | ||
set.add({ | ||
name: metadata.name, | ||
version: metadata.version, | ||
path: node.path, | ||
homepage: metadata.homepage, | ||
repository: metadata.repository, | ||
support: metadata.support | ||
}) | ||
} | ||
if (node.children) iterate(node) | ||
} | ||
} | ||
|
||
function displayPackage (entry) { | ||
return entry.name + '@' + entry.version + ': ' + entry.support | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const URL = require('url').URL | ||
|
||
// Is the value of a `support` property of a `package.json` object | ||
// a valid URL for `npm support` to display? | ||
module.exports = function (argument) { | ||
if (typeof argument !== 'string' || argument.length === 0) { | ||
return false | ||
} | ||
try { | ||
var parsed = new URL(argument) | ||
} catch (error) { | ||
return false | ||
} | ||
if ( | ||
parsed.protocol !== 'https:' && | ||
parsed.protocol !== 'http:' | ||
) return false | ||
return parsed.host | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict' | ||
var test = require('tap').test | ||
var Tacks = require('tacks') | ||
var Dir = Tacks.Dir | ||
var File = Tacks.File | ||
var common = require('../common-tap.js') | ||
|
||
var fixturepath = common.pkg | ||
var fixture = new Tacks(Dir({ | ||
'package.json': File({}), | ||
'hassupport': Dir({ | ||
'package.json': File({ | ||
name: 'hassupport', | ||
version: '7.7.7', | ||
support: 'http://example.com/project/support' | ||
}) | ||
}) | ||
})) | ||
|
||
test('setup', function (t) { | ||
fixture.remove(fixturepath) | ||
fixture.create(fixturepath) | ||
t.end() | ||
}) | ||
|
||
test('install-report', function (t) { | ||
common.npm(['install', '--no-save', './hassupport'], {cwd: fixturepath}, function (err, code, stdout, stderr) { | ||
if (err) throw err | ||
t.is(code, 0, 'installed successfully') | ||
t.is(stderr, '', 'no warnings') | ||
t.includes(stdout, '`npm support`', 'mentions `npm support`') | ||
t.end() | ||
}) | ||
}) | ||
|
||
test('cleanup', function (t) { | ||
fixture.remove(fixturepath) | ||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict' | ||
var test = require('tap').test | ||
var Tacks = require('tacks') | ||
var path = require('path') | ||
var Dir = Tacks.Dir | ||
var File = Tacks.File | ||
var common = require('../common-tap.js') | ||
|
||
var fixturepath = common.pkg | ||
var fixture = new Tacks(Dir({ | ||
'package.json': File({ | ||
name: 'a', | ||
version: '0.0.0', | ||
dependencies: { 'hassupport': '7.7.7' } | ||
}), | ||
'node_modules': Dir({ | ||
hassupport: Dir({ | ||
'package.json': File({ | ||
name: 'hassupport', | ||
version: '7.7.7', | ||
homepage: 'http://example.com/project', | ||
support: 'http://example.com/project/donate' | ||
}) | ||
}) | ||
}) | ||
})) | ||
|
||
test('setup', function (t) { | ||
fixture.remove(fixturepath) | ||
fixture.create(fixturepath) | ||
t.end() | ||
}) | ||
|
||
test('support --json', function (t) { | ||
common.npm(['support', '--json'], {cwd: fixturepath}, function (err, code, stdout, stderr) { | ||
if (err) throw err | ||
t.is(code, 0, 'exited 0') | ||
t.is(stderr, '', 'no warnings') | ||
var parsed | ||
t.doesNotThrow(function () { | ||
parsed = JSON.parse(stdout) | ||
}, 'valid JSON') | ||
t.deepEqual( | ||
parsed, | ||
[ | ||
{ | ||
name: 'hassupport', | ||
version: '7.7.7', | ||
homepage: 'http://example.com/project', | ||
support: 'http://example.com/project/donate', | ||
path: path.resolve(fixturepath, 'node_modules', 'hassupport') | ||
} | ||
], | ||
'output data' | ||
) | ||
t.end() | ||
}) | ||
}) | ||
|
||
test('support', function (t) { | ||
common.npm(['support'], {cwd: fixturepath}, function (err, code, stdout, stderr) { | ||
if (err) throw err | ||
t.is(code, 0, 'exited 0') | ||
t.is(stderr, '', 'no warnings') | ||
t.includes(stdout, 'hassupport', 'outputs project name') | ||
t.includes(stdout, '7.7.7', 'outputs project version') | ||
t.includes(stdout, 'http://example.com/project', 'outputs contributor homepage') | ||
t.includes(stdout, 'http://example.com/project/donate', 'outputs support link') | ||
t.end() | ||
}) | ||
}) | ||
|
||
test('cleanup', function (t) { | ||
t.pass(fixturepath) | ||
fixture.remove(fixturepath) | ||
t.end() | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth versioning this attribute so we can make changes to it in the future? It would allow us to add complexity over time as we see the need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's a string URL, it's a string URL. We don't get to version that standard. :-P
If it's not a string URL, it could be an object with a version property ... if/when we go there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh. The latter is what I was thinking.
But also it might be too weird to version individual attributes rather than the
package.json
schema as a whole.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does collide with what we are defining in https://github.com/nodejs/package-maintenance/blob/master/docs/drafts/PACKAGE-SUPPORT.md.
It would be good to avoid a conflict with that in that we'll be suggesting package maintainers add the larger structure.
Would what is suggested in maintenance/blob/master/docs/drafts/PACKAGE-SUPPORT.md be possible if qualified through a later version? And if so how would we have to update what is in there if we wanted to suggest the larger structure start to be used today? Alternatively, we could change "support" to something else but then it would potentially duplicate info.