diff options
Diffstat (limited to 'deps/npm/node_modules/pacote/lib/fetchers/git.js')
-rw-r--r-- | deps/npm/node_modules/pacote/lib/fetchers/git.js | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/deps/npm/node_modules/pacote/lib/fetchers/git.js b/deps/npm/node_modules/pacote/lib/fetchers/git.js index d8af769364..9da6a6438a 100644 --- a/deps/npm/node_modules/pacote/lib/fetchers/git.js +++ b/deps/npm/node_modules/pacote/lib/fetchers/git.js @@ -15,7 +15,6 @@ const PassThrough = require('stream').PassThrough const path = require('path') const pipe = BB.promisify(require('mississippi').pipe) const rimraf = BB.promisify(require('rimraf')) -const semver = require('semver') const uniqueFilename = require('unique-filename') // `git` dependencies are fetched from git repositories and packed up. @@ -50,7 +49,7 @@ Fetcher.impl(fetchGit, { opts = optCheck(opts) let streamError const stream = new PassThrough().on('error', e => { streamError = e }) - const cacheName = manifest._resolved || spec.saveSpec || spec.fetchSpec + const cacheName = manifest._uniqueResolved || manifest._resolved || '' const cacheStream = ( opts.cache && cacache.get.stream( @@ -69,11 +68,9 @@ Fetcher.impl(fetchGit, { manifest._repo, manifest._ref, manifest._rawRef, tmp, opts ).then(HEAD => { if (streamError) { throw streamError } - if (!manifest._resolved) { - manifest._resolved = spec.saveSpec.replace(/#.*/, `#${HEAD}`) - manifest._uniqueResolved = manifest._resolved - } - return packDir(manifest, cacheName, tmp, stream, opts) + manifest._resolved = spec.saveSpec.replace(/(:?#.*)?$/, `#${HEAD}`) + manifest._uniqueResolved = manifest._resolved + return packDir(manifest, manifest._uniqueResolved, tmp, stream, opts) }) }).catch(err => stream.emit('error', err)) } @@ -102,9 +99,9 @@ function hostedManifest (spec, opts) { } function plainManifest (repo, spec, opts) { - const rawRef = spec.gitCommittish + const rawRef = spec.gitCommittish || spec.gitRange return resolve( - repo, rawRef, spec.name, opts + repo, spec, spec.name, opts ).then(ref => { if (ref) { const resolved = spec.saveSpec.replace(/(?:#.*)?$/, `#${ref.sha}`) @@ -113,7 +110,7 @@ function plainManifest (repo, spec, opts) { _resolved: resolved, _spec: spec, _ref: ref, - _rawRef: rawRef, + _rawRef: spec.gitCommittish || spec.gitRange, _uniqueResolved: resolved } } else { @@ -132,19 +129,18 @@ function plainManifest (repo, spec, opts) { }) } -function resolve (url, rawRef, name, opts) { - const semverMatch = rawRef.match(/^semver:v?(.*)/) - const isSemver = semverMatch && semver.validRange(semverMatch[1]) +function resolve (url, spec, name, opts) { + const isSemver = !!spec.gitRange return git.revs(url, opts).then(remoteRefs => { return isSemver ? pickManifest({ versions: remoteRefs.versions, 'dist-tags': remoteRefs['dist-tags'], name: name - }, semverMatch[1], opts) + }, spec.gitRange, opts) : remoteRefs ? BB.resolve( - remoteRefs.refs[rawRef] || remoteRefs.refs[remoteRefs.shas[rawRef]] + remoteRefs.refs[spec.gitCommittish] || remoteRefs.refs[remoteRefs.shas[spec.gitCommittish]] ) : null }) |