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

Added support for detecting outdated git packages. #8300 #12833

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 20 additions & 1 deletion lib/outdated.js
Expand Up @@ -40,6 +40,7 @@ var mapToRegistry = require('./utils/map-to-registry.js')
var isExtraneous = require('./install/is-extraneous.js')
var recalculateMetadata = require('./install/deps.js').recalculateMetadata
var moduleName = require('./utils/module-name.js')
var git = require('./utils/git')

function uniqName (item) {
return item[0].path + '|' + item[1] + '|' + item[7]
Expand Down Expand Up @@ -337,7 +338,25 @@ function shouldUpdate (args, tree, dep, has, req, depth, pkgpath, cb, type) {
return doIt('linked', 'linked')
}
if (parsed.type === 'git' || parsed.type === 'hosted') {
return doIt('git', 'git')
var gitUrlParts = (parsed.type === 'hosted' ? parsed.hosted.sshUrl : parsed.rawSpec).split('#')
var gitPath = gitUrlParts[0]
var wanted = gitUrlParts[1]

if (!gitPath || !wanted) {
return doIt('git', 'git')
}
if (!/\d+\.\d+\.\d+$/.test(wanted)) {
return doIt('git', 'git')
}

var tags = git.execSync([ 'ls-remote', '--tags', gitPath ]).toString()
var semverTags = tags.match(/\d+\.\d+\.\d+$/gm)
if (!semverTags) {
return doIt(wanted, 'git')
}

var sortedSemverTags = semverTags.sort(semver.rcompare)
return doIt(wanted, sortedSemverTags[0])
}

// search for the latest package
Expand Down
8 changes: 8 additions & 0 deletions lib/utils/git.js
@@ -1,10 +1,12 @@
// handle some git configuration for windows

exports.spawn = spawnGit
exports.execSync = execSyncGit
exports.chainableExec = chainableExec
exports.whichAndExec = whichAndExec

var exec = require('child_process').execFile
var execSync = require('child_process').execFileSync
var spawn = require('./spawn')
var npm = require('../npm.js')
var which = require('which')
Expand All @@ -22,6 +24,12 @@ function execGit (args, options, cb) {
return exec(git, fullArgs, options, cb)
}

function execSyncGit (args, options) {
log.info('git', args)
var fullArgs = prefixGitArgs().concat(args || [])
return execSync(git, fullArgs, options)
}

function spawnGit (args, options) {
log.info('git', args)
return spawn(git, prefixGitArgs().concat(args || []), options)
Expand Down
10 changes: 8 additions & 2 deletions test/tap/outdated-git.js
Expand Up @@ -20,7 +20,9 @@ var json = {
dependencies: {
'foo-github': 'robertkowalski/foo',
'foo-private': 'git://github.com/robertkowalski/foo-private.git',
'foo-private-credentials': 'git://user:pass@github.com/robertkowalski/foo-private.git'
'foo-private-credentials': 'git://user:pass@github.com/robertkowalski/foo-private.git',
'npm-outdated-git-test': 'goloroden/npm-outdated-git-test#0.1.0',
'npm-outdated-git-test-outdated': 'goloroden/npm-outdated-git-test#0.0.1'
}
}

Expand All @@ -31,14 +33,18 @@ test('setup', function (t) {

test('discovers new versions in outdated', function (t) {
process.chdir(pkg)
t.plan(5)
t.plan(9)
npm.load({cache: cache, registry: common.registry, loglevel: 'silent'}, function () {
npm.commands.outdated([], function (er, d) {
t.equal(d[0][3], 'git')
t.equal(d[0][4], 'git')
t.equal(d[0][5], 'github:robertkowalski/foo')
t.equal(d[1][5], 'git://github.com/robertkowalski/foo-private.git')
t.equal(d[2][5], 'git://user:pass@github.com/robertkowalski/foo-private.git')
t.equal(d[3][3], '0.1.0')
t.equal(d[3][4], '0.1.0')
t.equal(d[4][3], '0.0.1')
t.equal(d[4][4], '0.1.0')
})
})
})
Expand Down