pacote 11.2.2 → 11.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/git.js +31 -13
  2. package/package.json +1 -1
package/lib/git.js CHANGED
@@ -24,13 +24,16 @@ const _cloneRepo = Symbol('_cloneRepo')
24
24
  const _setResolvedWithSha = Symbol('_setResolvedWithSha')
25
25
  const _prepareDir = Symbol('_prepareDir')
26
26
 
27
- // get the repository url. prefer ssh, fall back to git://
27
+ // get the repository url.
28
+ // prefer https if there's auth, since ssh will drop that.
29
+ // otherwise, prefer ssh if available (more secure).
28
30
  // We have to add the git+ back because npa suppresses it.
29
- const repoUrl = (hosted, opts) =>
30
- hosted.sshurl && addGitPlus(hosted.sshurl(opts)) ||
31
- hosted.https && addGitPlus(hosted.https(opts))
31
+ const repoUrl = (h, opts) =>
32
+ h.sshurl && !(h.https && h.auth) && addGitPlus(h.sshurl(opts)) ||
33
+ h.https && addGitPlus(h.https(opts))
32
34
 
33
- const addGitPlus = url => url && `git+${url}`
35
+ // add git+ to the url, but only one time.
36
+ const addGitPlus = url => url && `git+${url}`.replace(/^(git\+)+/, 'git+')
34
37
 
35
38
  class GitFetcher extends Fetcher {
36
39
  constructor (spec, opts) {
@@ -51,6 +54,11 @@ class GitFetcher extends Fetcher {
51
54
  this.resolvedSha = ''
52
55
  }
53
56
 
57
+ // just exposed to make it easier to test all the combinations
58
+ static repoUrl (hosted, opts) {
59
+ return repoUrl(hosted, opts)
60
+ }
61
+
54
62
  get types () {
55
63
  return ['git']
56
64
  }
@@ -69,13 +77,16 @@ class GitFetcher extends Fetcher {
69
77
  }
70
78
 
71
79
  // first try https, since that's faster and passphrase-less for
72
- // public repos. Fall back to SSH to support private repos.
73
- // NB: we always store the SSH url in the 'resolved' field.
80
+ // public repos, and supports private repos when auth is provided.
81
+ // Fall back to SSH to support private repos
82
+ // NB: we always store the https url in resolved field if auth
83
+ // is present, otherwise ssh if the hosted type provides it
74
84
  [_resolvedFromHosted] (hosted) {
75
85
  return this[_resolvedFromRepo](hosted.https && hosted.https())
76
86
  .catch(er => {
77
87
  const ssh = hosted.sshurl && hosted.sshurl()
78
- if (!ssh)
88
+ // no fallthrough if we can't fall through or have https auth
89
+ if (!ssh || hosted.auth)
79
90
  throw er
80
91
  return this[_resolvedFromRepo](ssh)
81
92
  })
@@ -121,9 +132,11 @@ class GitFetcher extends Fetcher {
121
132
  // either a git url with a hash, or a tarball download URL
122
133
  [_addGitSha] (sha) {
123
134
  if (this.spec.hosted) {
124
- this[_setResolvedWithSha](
125
- this.spec.hosted.shortcut({ noCommittish: true }) + '#' + sha
126
- )
135
+ const h = this.spec.hosted
136
+ const opt = { noCommittish: true }
137
+ const base = h.https && h.auth ? h.https(opt) : h.shortcut(opt)
138
+
139
+ this[_setResolvedWithSha](`${base}#${sha}`)
127
140
  } else {
128
141
  const u = url.format(new url.URL(`#${sha}`, this.spec.rawSpec))
129
142
  this[_setResolvedWithSha](url.format(u))
@@ -232,14 +245,19 @@ class GitFetcher extends Fetcher {
232
245
  })
233
246
  }
234
247
 
248
+ // first try https, since that's faster and passphrase-less for
249
+ // public repos, and supports private repos when auth is provided.
250
+ // Fall back to SSH to support private repos
251
+ // NB: we always store the https url in resolved field if auth
252
+ // is present, otherwise ssh if the hosted type provides it
235
253
  [_cloneHosted] (ref, tmp) {
236
254
  const hosted = this.spec.hosted
237
255
  const https = hosted.https()
238
256
  return this[_cloneRepo](hosted.https({ noCommittish: true }), ref, tmp)
239
257
  .catch(er => {
240
258
  const ssh = hosted.sshurl && hosted.sshurl({ noCommittish: true })
241
- /* istanbul ignore if - should be covered by the resolve() call */
242
- if (!ssh)
259
+ // no fallthrough if we can't fall through or have https auth
260
+ if (!ssh || hosted.auth)
243
261
  throw er
244
262
  return this[_cloneRepo](ssh, ref, tmp)
245
263
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacote",
3
- "version": "11.2.2",
3
+ "version": "11.2.3",
4
4
  "description": "JavaScript package downloader",
5
5
  "author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)",
6
6
  "bin": {