Skip to content

Commit ef82ddf

Browse files
committed
fix: tweak setGitCommittish
It does more than set one attribute, and shouldn't need to return res if it' mutating in place
1 parent 93c7ef0 commit ef82ddf

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/npa.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,11 @@ Result.prototype.toJSON = function () {
183183
return result
184184
}
185185

186-
function setGitCommittish (res, committish) {
186+
// sets res.gitCommittish, res.gitRange, and res.gitSubdir
187+
function setGitAttrs (res, committish) {
187188
if (!committish) {
188189
res.gitCommittish = null
189-
return res
190+
return
190191
}
191192

192193
// for each :: separated item:
@@ -224,8 +225,6 @@ function setGitCommittish (res, committish) {
224225
}
225226
log.warn('npm-package-arg', `ignoring unknown key "${name}"`)
226227
}
227-
228-
return res
229228
}
230229

231230
function fromFile (res, where) {
@@ -303,7 +302,8 @@ function fromHostedGit (res, hosted) {
303302
res.hosted = hosted
304303
res.saveSpec = hosted.toString({ noGitPlus: false, noCommittish: false })
305304
res.fetchSpec = hosted.getDefaultRepresentation() === 'shortcut' ? null : hosted.toString()
306-
return setGitCommittish(res, hosted.committish)
305+
setGitAttrs(res, hosted.committish)
306+
return res
307307
}
308308

309309
function unsupportedURLType (protocol, spec) {
@@ -326,7 +326,7 @@ function fromURL (res) {
326326
const matched = rawSpec.match(/^git\+ssh:\/\/([^:#]+:[^#]+(?:\.git)?)(?:#(.*))?$/i)
327327
if (matched && !matched[1].match(/:[0-9]+\/?.*$/i)) {
328328
res.type = 'git'
329-
setGitCommittish(res, matched[2])
329+
setGitAttrs(res, matched[2])
330330
res.fetchSpec = matched[1]
331331
return res
332332
}
@@ -345,7 +345,7 @@ function fromURL (res) {
345345
case 'git+file:':
346346
case 'git+ssh:':
347347
res.type = 'git'
348-
setGitCommittish(res, parsedUrl.hash.slice(1))
348+
setGitAttrs(res, parsedUrl.hash.slice(1))
349349
if (parsedUrl.protocol === 'git+file:' && /^git\+file:\/\/[a-z]:/i.test(rawSpec)) {
350350
// URL can't handle drive letters on windows file paths, the host can't contain a :
351351
res.fetchSpec = `git+file://${parsedUrl.host.toLowerCase()}:${parsedUrl.pathname}`

0 commit comments

Comments
 (0)