Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Commit eab6184

Browse files
iarnaothiym23
authored andcommitted
github: fix the ssh fallback for private github modules
This only impacts github modules installed via github shortcuts, eg npm install project/module When the module is marked as private.
1 parent 94df809 commit eab6184

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

lib/cache/maybe-github.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ module.exports = function maybeGithub (p, cb) {
1313
return addRemoteGit(parsed.git(), true, function (er, data) {
1414
if (er) {
1515
log.info("maybeGithub", "Couldn't clone %s", parsed.git())
16-
log.info("maybeGithub", "Now attempting %s from %s", p, parsed.ssh())
16+
log.info("maybeGithub", "Now attempting %s from %s", p, parsed.sshurl())
1717

18-
return addRemoteGit(parsed.ssh(), false, function (er, data) {
18+
return addRemoteGit(parsed.sshurl(), false, function (er, data) {
1919
if (er) return cb(er)
2020

21-
success(parsed.ssh(), data)
21+
success(parsed.sshurl(), data)
2222
})
2323
}
2424

test/tap/github-shortcut.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict'
2+
var requireInject = require('require-inject')
3+
var test = require('tap').test
4+
5+
test('github-shortcut', function (t) {
6+
var cloneUrls = [
7+
['git://github.com/foo/private.git', 'github shortcuts try git:// first'],
8+
['ssh://[email protected]/foo/private.git', 'github shortcuts try ssh:// urls second']
9+
]
10+
var npm = requireInject.installGlobally('../../lib/npm.js', {
11+
'child_process': {
12+
'execFile': function (cmd, args, options, cb) {
13+
process.nextTick(function () {
14+
if (args[0] !== 'clone') return cb(null, '', '')
15+
var cloneUrl = cloneUrls.shift()
16+
if (cloneUrl) {
17+
t.is(args[3], cloneUrl[0], cloneUrl[1])
18+
} else {
19+
t.fail('too many attempts to clone')
20+
}
21+
cb(new Error())
22+
})
23+
}
24+
}
25+
})
26+
27+
npm.load({loglevel: 'silent'}, function () {
28+
npm.commands.install(['foo/private'], function (er, result) {
29+
t.end()
30+
})
31+
})
32+
})

0 commit comments

Comments
 (0)