-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: npm#246 Credit: @kemitchell Close: npm#246 Reviewed-by: @ruyadorno Thanks @kemitchell for providing the initial work that served as a base for `npm fund`, its original commits messages are preserved as such: - support: add support subcommand - support: fix request caching - support: further sanitize contributor data - doc: Fix typo - support: simplify to just collecting and showing URLs - install: improve `npm support` test - install: drop "the" before "projects you depend on" - doc: Reword mention of `npm support` in `package.json` spec
- Loading branch information
1 parent
cd14d47
commit 266d076
Showing
8 changed files
with
259 additions
and
10 deletions.
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() | ||
}) |