pacote 7.6.0 → 8.1.1

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,68 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ <a name="8.1.1"></a>
6
+ ## [8.1.1](https://github.com/zkat/pacote/compare/v8.1.0...v8.1.1) (2018-04-24)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **tarball:** Remove promise handler error ([#148](https://github.com/zkat/pacote/issues/148)) ([47da3f6](https://github.com/zkat/pacote/commit/47da3f6)), closes [#145](https://github.com/zkat/pacote/issues/145)
12
+
13
+
14
+
15
+ <a name="8.1.0"></a>
16
+ # [8.1.0](https://github.com/zkat/pacote/compare/v8.0.0...v8.1.0) (2018-04-18)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * **git:** workaround for mississippi.finished intermitent failures ([#144](https://github.com/zkat/pacote/issues/144)) ([788fd13](https://github.com/zkat/pacote/commit/788fd13)), closes [#143](https://github.com/zkat/pacote/issues/143)
22
+
23
+
24
+ ### Features
25
+
26
+ * **tarball:** calculate shasum when missing, not just integrity ([#149](https://github.com/zkat/pacote/issues/149)) ([ccc6e90](https://github.com/zkat/pacote/commit/ccc6e90))
27
+
28
+
29
+
30
+ <a name="8.0.0"></a>
31
+ # [8.0.0](https://github.com/zkat/pacote/compare/v7.6.1...v8.0.0) (2018-04-12)
32
+
33
+
34
+ ### Bug Fixes
35
+
36
+ * **git:** make full clones do a full mirror ([85b269b](https://github.com/zkat/pacote/commit/85b269b))
37
+
38
+
39
+ ### deps
40
+
41
+ * bump deps ([6737bf6](https://github.com/zkat/pacote/commit/6737bf6))
42
+
43
+
44
+ ### meta
45
+
46
+ * drop support for node@4 ([11478ff](https://github.com/zkat/pacote/commit/11478ff))
47
+
48
+
49
+ ### BREAKING CHANGES
50
+
51
+ * some dependencies were upgraded to versions that do not
52
+ support node@4.
53
+ * node@4 is no longer supported
54
+
55
+
56
+
57
+ <a name="7.6.1"></a>
58
+ ## [7.6.1](https://github.com/zkat/pacote/compare/v7.6.0...v7.6.1) (2018-03-08)
59
+
60
+
61
+ ### Bug Fixes
62
+
63
+ * **standard:** update to new standard rules ([bb52d02](https://github.com/zkat/pacote/commit/bb52d02))
64
+
65
+
66
+
5
67
  <a name="7.6.0"></a>
6
68
  # [7.6.0](https://github.com/zkat/pacote/compare/v7.5.3...v7.6.0) (2018-03-08)
7
69
 
package/extract.js CHANGED
@@ -24,27 +24,27 @@ function extract (spec, dest, opts) {
24
24
  return withTarballStream(spec, opts, stream => {
25
25
  return tryExtract(spec, stream, dest, opts)
26
26
  })
27
- .then(() => {
28
- if (!opts.resolved) {
29
- const pjson = path.join(dest, 'package.json')
30
- return readFileAsync(pjson, 'utf8')
31
- .then(str => truncateAsync(pjson)
32
- .then(() => appendFileAsync(pjson, str.replace(
33
- /}\s*$/,
34
- `\n,"_resolved": ${
35
- JSON.stringify(opts.resolved || '')
36
- }\n,"_integrity": ${
37
- JSON.stringify(opts.integrity || '')
38
- }\n,"_from": ${
39
- JSON.stringify(spec.toString())
40
- }\n}`
41
- ))))
42
- }
43
- })
44
- .then(() => opts.log.silly(
45
- 'extract',
46
- `${spec} extracted to ${dest} (${Date.now() - startTime}ms)`
47
- ))
27
+ .then(() => {
28
+ if (!opts.resolved) {
29
+ const pjson = path.join(dest, 'package.json')
30
+ return readFileAsync(pjson, 'utf8')
31
+ .then(str => truncateAsync(pjson)
32
+ .then(() => appendFileAsync(pjson, str.replace(
33
+ /}\s*$/,
34
+ `\n,"_resolved": ${
35
+ JSON.stringify(opts.resolved || '')
36
+ }\n,"_integrity": ${
37
+ JSON.stringify(opts.integrity || '')
38
+ }\n,"_from": ${
39
+ JSON.stringify(spec.toString())
40
+ }\n}`
41
+ ))))
42
+ }
43
+ })
44
+ .then(() => opts.log.silly(
45
+ 'extract',
46
+ `${spec} extracted to ${dest} (${Date.now() - startTime}ms)`
47
+ ))
48
48
  }
49
49
 
50
50
  function tryExtract (spec, tarStream, dest, opts) {
@@ -52,19 +52,19 @@ function tryExtract (spec, tarStream, dest, opts) {
52
52
  tarStream.on('error', reject)
53
53
  setImmediate(resolve)
54
54
  })
55
- .then(() => rimraf(dest))
56
- .then(() => mkdirp(dest))
57
- .then(() => new BB((resolve, reject) => {
58
- const xtractor = extractStream(spec, dest, opts)
59
- tarStream.on('error', reject)
60
- xtractor.on('error', reject)
61
- xtractor.on('close', resolve)
62
- tarStream.pipe(xtractor)
63
- }))
64
- .catch(err => {
65
- if (err.code === 'EINTEGRITY') {
66
- err.message = `Verification failed while extracting ${spec}:\n${err.message}`
67
- }
68
- throw err
69
- })
55
+ .then(() => rimraf(dest))
56
+ .then(() => mkdirp(dest))
57
+ .then(() => new BB((resolve, reject) => {
58
+ const xtractor = extractStream(spec, dest, opts)
59
+ tarStream.on('error', reject)
60
+ xtractor.on('error', reject)
61
+ xtractor.on('close', resolve)
62
+ tarStream.pipe(xtractor)
63
+ }))
64
+ .catch(err => {
65
+ if (err.code === 'EINTEGRITY') {
66
+ err.message = `Verification failed while extracting ${spec}:\n${err.message}`
67
+ }
68
+ throw err
69
+ })
70
70
  }
@@ -29,6 +29,7 @@ Fetcher.impl(fetchDirectory, {
29
29
  pkg._hasShrinkwrap = !!sr
30
30
  pkg._resolved = spec.fetchSpec
31
31
  pkg._integrity = false // Don't auto-calculate integrity
32
+ pkg._shasum = false // Don't auto-calculate shasum either
32
33
  return pkg
33
34
  }
34
35
  ).then(pkg => {
@@ -52,13 +52,13 @@ Fetcher.impl(fetchFile, {
52
52
  } else {
53
53
  let integrity
54
54
  const cacheWriter = !opts.cache
55
- ? BB.resolve(null)
56
- : (pipe(
57
- fs.createReadStream(src),
58
- cacache.put.stream(opts.cache, `pacote:tarball:${src}`, {
59
- integrity: opts.integrity
60
- }).on('integrity', d => { integrity = d })
61
- ))
55
+ ? BB.resolve(null)
56
+ : (pipe(
57
+ fs.createReadStream(src),
58
+ cacache.put.stream(opts.cache, `pacote:tarball:${src}`, {
59
+ integrity: opts.integrity
60
+ }).on('integrity', d => { integrity = d })
61
+ ))
62
62
  return cacheWriter.then(() => {
63
63
  if (integrity) { stream.emit('integrity', integrity) }
64
64
  return pipe(fs.createReadStream(src), stream)
@@ -112,7 +112,8 @@ function plainManifest (repo, spec, opts) {
112
112
  _ref: ref,
113
113
  _rawRef: spec.gitCommittish || spec.gitRange,
114
114
  _uniqueResolved: resolved,
115
- _integrity: false
115
+ _integrity: false,
116
+ _shasum: false
116
117
  }
117
118
  } else {
118
119
  // We're SOL and need a full clone :(
@@ -125,7 +126,8 @@ function plainManifest (repo, spec, opts) {
125
126
  _rawRef: rawRef,
126
127
  _resolved: rawRef && rawRef.match(/^[a-f0-9]{40}$/) && resolved,
127
128
  _uniqueResolved: rawRef && rawRef.match(/^[a-f0-9]{40}$/) && resolved,
128
- _integrity: false
129
+ _integrity: false,
130
+ _shasum: false
129
131
  }
130
132
  }
131
133
  })
@@ -135,16 +137,16 @@ function resolve (url, spec, name, opts) {
135
137
  const isSemver = !!spec.gitRange
136
138
  return git.revs(url, opts).then(remoteRefs => {
137
139
  return isSemver
138
- ? pickManifest({
139
- versions: remoteRefs.versions,
140
- 'dist-tags': remoteRefs['dist-tags'],
141
- name: name
142
- }, spec.gitRange, opts)
143
- : remoteRefs
144
- ? BB.resolve(
145
- remoteRefs.refs[spec.gitCommittish] || remoteRefs.refs[remoteRefs.shas[spec.gitCommittish]]
146
- )
147
- : null
140
+ ? pickManifest({
141
+ versions: remoteRefs.versions,
142
+ 'dist-tags': remoteRefs['dist-tags'],
143
+ name: name
144
+ }, spec.gitRange, opts)
145
+ : remoteRefs
146
+ ? BB.resolve(
147
+ remoteRefs.refs[spec.gitCommittish] || remoteRefs.refs[remoteRefs.shas[spec.gitCommittish]]
148
+ )
149
+ : null
148
150
  })
149
151
  }
150
152
 
@@ -68,12 +68,12 @@ function logRequest (uri, res, startTime, opts) {
68
68
 
69
69
  function getCacheMode (opts) {
70
70
  return opts.offline
71
- ? 'only-if-cached'
72
- : opts.preferOffline
73
- ? 'force-cache'
74
- : opts.preferOnline
75
- ? 'no-cache'
76
- : 'default'
71
+ ? 'only-if-cached'
72
+ : opts.preferOffline
73
+ ? 'force-cache'
74
+ : opts.preferOnline
75
+ ? 'no-cache'
76
+ : 'default'
77
77
  }
78
78
 
79
79
  function getHeaders (uri, registry, opts) {
@@ -28,8 +28,8 @@ function manifest (spec, opts) {
28
28
 
29
29
  function metadataUrl (registry, name) {
30
30
  const normalized = registry.slice(-1) !== '/'
31
- ? registry + '/'
32
- : registry
31
+ ? registry + '/'
32
+ : registry
33
33
  return url.resolve(normalized, name)
34
34
  }
35
35
 
@@ -41,6 +41,7 @@ function tarball (spec, opts) {
41
41
  )
42
42
  fetchStream.on('error', err => stream.emit('error', err))
43
43
  fetchStream.pipe(stream)
44
+ return null
44
45
  }).catch(err => stream.emit('error', err))
45
46
  return stream
46
47
  }
@@ -60,20 +61,21 @@ function fromManifest (manifest, spec, opts) {
60
61
  integrity: manifest._integrity,
61
62
  algorithms: [
62
63
  manifest._integrity
63
- ? ssri.parse(manifest._integrity).pickAlgorithm()
64
- : 'sha1'
64
+ ? ssri.parse(manifest._integrity).pickAlgorithm()
65
+ : 'sha1'
65
66
  ],
66
67
  spec
67
68
  }, opts))
68
- .then(res => {
69
- const hash = res.headers.get('x-local-cache-hash')
70
- if (hash) {
71
- stream.emit('integrity', decodeURIComponent(hash))
72
- }
73
- res.body.on('error', err => stream.emit('error', err))
74
- res.body.pipe(stream)
75
- })
76
- .catch(err => stream.emit('error', err))
69
+ .then(res => {
70
+ const hash = res.headers.get('x-local-cache-hash')
71
+ if (hash) {
72
+ stream.emit('integrity', decodeURIComponent(hash))
73
+ }
74
+ res.body.on('error', err => stream.emit('error', err))
75
+ res.body.pipe(stream)
76
+ return null
77
+ })
78
+ .catch(err => stream.emit('error', err))
77
79
  return stream
78
80
  }
79
81
 
@@ -5,7 +5,7 @@ const BB = require('bluebird')
5
5
  const cacache = require('cacache')
6
6
  const cacheKey = require('./util/cache-key')
7
7
  const fetchFromManifest = require('./fetch').fromManifest
8
- const finished = BB.promisify(require('mississippi').finished)
8
+ const finished = require('./util/finished')
9
9
  const minimatch = require('minimatch')
10
10
  const normalize = require('normalize-package-data')
11
11
  const optCheck = require('./util/opt-check')
@@ -38,8 +38,8 @@ function finalizeManifest (pkg, spec, opts) {
38
38
  opts = optCheck(opts)
39
39
 
40
40
  const cachedManifest = (opts.cache && key && !opts.preferOnline && !opts.fullMetadata)
41
- ? cacache.get.info(opts.cache, key, opts)
42
- : BB.resolve(null)
41
+ ? cacache.get.info(opts.cache, key, opts)
42
+ : BB.resolve(null)
43
43
 
44
44
  return cachedManifest.then(cached => {
45
45
  if (cached && cached.metadata.manifest) {
@@ -47,8 +47,8 @@ function finalizeManifest (pkg, spec, opts) {
47
47
  } else {
48
48
  return tarballedProps(pkg, spec, opts).then(props => {
49
49
  return pkg && pkg.name
50
- ? new Manifest(pkg, props, opts.fullMetadata)
51
- : new Manifest(props, null, opts.fullMetadata)
50
+ ? new Manifest(pkg, props, opts.fullMetadata)
51
+ : new Manifest(props, null, opts.fullMetadata)
52
52
  }).then(manifest => {
53
53
  const cacheKey = key || finalKey(manifest, spec)
54
54
  if (!opts.cache || !cacheKey) {
@@ -98,7 +98,7 @@ function Manifest (pkg, fromTarball, fullMetadata) {
98
98
  // and if they don't, we need to extract and read the tarball ourselves.
99
99
  // These are details required by the installer.
100
100
  this._integrity = pkg._integrity || fromTarball._integrity || null
101
- this._shasum = pkg._shasum || null
101
+ this._shasum = pkg._shasum || fromTarball._shasum || null
102
102
  this._shrinkwrap = pkg._shrinkwrap || fromTarball._shrinkwrap || null
103
103
  this.bin = pkg.bin || fromTarball.bin || null
104
104
 
@@ -140,7 +140,9 @@ function tarballedProps (pkg, spec, opts) {
140
140
  pkg.directories &&
141
141
  pkg.directories.bin
142
142
  ))
143
- const needsHash = !pkg || (!pkg._integrity && pkg._integrity !== false)
143
+ const needsIntegrity = !pkg || (!pkg._integrity && pkg._integrity !== false)
144
+ const needsShasum = !pkg || (!pkg._shasum && pkg._shasum !== false)
145
+ const needsHash = needsIntegrity || needsShasum
144
146
  const needsManifest = !pkg || !pkg.name
145
147
  const needsExtract = needsShrinkwrap || needsBin || needsManifest
146
148
  if (!needsShrinkwrap && !needsBin && !needsHash && !needsManifest) {
@@ -153,7 +155,7 @@ function tarballedProps (pkg, spec, opts) {
153
155
  needsShrinkwrap && jsonFromStream('npm-shrinkwrap.json', extracted),
154
156
  needsManifest && jsonFromStream('package.json', extracted),
155
157
  needsBin && getPaths(extracted),
156
- needsHash && ssri.fromStream(tarStream),
158
+ needsHash && ssri.fromStream(tarStream, {algorithms: ['sha1', 'sha512']}),
157
159
  needsExtract && pipe(tarStream, extracted),
158
160
  (sr, mani, paths, hash) => {
159
161
  if (needsManifest && !mani) {
@@ -169,8 +171,8 @@ function tarballedProps (pkg, spec, opts) {
169
171
  // to add to bin
170
172
  if (paths && paths.length) {
171
173
  const dirBin = mani
172
- ? (mani && mani.directories && mani.directories.bin)
173
- : (pkg && pkg.directories && pkg.directories.bin)
174
+ ? (mani && mani.directories && mani.directories.bin)
175
+ : (pkg && pkg.directories && pkg.directories.bin)
174
176
  if (dirBin) {
175
177
  extraProps.bin = {}
176
178
  paths.forEach(filePath => {
@@ -188,7 +190,8 @@ function tarballedProps (pkg, spec, opts) {
188
190
  _resolved: (mani && mani._resolved) ||
189
191
  (pkg && pkg._resolved) ||
190
192
  spec.fetchSpec,
191
- _integrity: hash && hash.toString()
193
+ _integrity: needsIntegrity && hash && hash.sha512 && hash.sha512[0].toString(),
194
+ _shasum: needsShasum && hash && hash.sha1 && hash.sha1[0].hexDigest()
192
195
  })
193
196
  }
194
197
  )
@@ -0,0 +1,17 @@
1
+ 'use strict'
2
+
3
+ const BB = require('bluebird')
4
+
5
+ module.exports = function (child, hasExitCode = false) {
6
+ return BB.fromNode(function (cb) {
7
+ child.on('error', cb)
8
+ child.on(hasExitCode ? 'close' : 'end', function (exitCode) {
9
+ if (exitCode === undefined || exitCode === 0) {
10
+ cb()
11
+ } else {
12
+ let err = new Error('exited with error code: ' + exitCode)
13
+ cb(err)
14
+ }
15
+ })
16
+ })
17
+ }
package/lib/util/git.js CHANGED
@@ -6,7 +6,7 @@ const cp = require('child_process')
6
6
  const execFileAsync = BB.promisify(cp.execFile, {
7
7
  multiArgs: true
8
8
  })
9
- const finished = BB.promisify(require('mississippi').finished)
9
+ const finished = require('./finished')
10
10
  const LRU = require('lru-cache')
11
11
  const optCheck = require('./opt-check')
12
12
  const osenv = require('osenv')
@@ -70,16 +70,14 @@ try {
70
70
  module.exports.clone = fullClone
71
71
  function fullClone (repo, committish, target, opts) {
72
72
  opts = optCheck(opts)
73
- const gitArgs = ['clone', '-q', repo, target]
73
+ const gitArgs = ['clone', '--mirror', '-q', repo, path.join(target, '.git')]
74
74
  if (process.platform === 'win32') {
75
75
  gitArgs.push('--config', 'core.longpaths=true')
76
76
  }
77
- return execGit(gitArgs, {
78
- cwd: path.dirname(target)
79
- }, opts).then(() => {
80
- return committish && execGit(['checkout', committish], {
81
- cwd: target
82
- })
77
+ return execGit(gitArgs, {cwd: target}).then(() => {
78
+ return execGit(['init'], {cwd: target})
79
+ }).then(() => {
80
+ return execGit(['checkout', committish || 'HEAD'], {cwd: target})
83
81
  }).then(() => {
84
82
  return updateSubmodules(target, opts)
85
83
  }).then(() => headSha(target, opts))
@@ -215,7 +213,7 @@ function spawnGit (gitArgs, gitOpts, opts) {
215
213
  child.stdout.on('data', d => { stdout += d })
216
214
  child.stderr.on('data', d => { stderr += d })
217
215
 
218
- return finished(child).catch(err => {
216
+ return finished(child, true).catch(err => {
219
217
  if (shouldRetry(stderr)) {
220
218
  retry(err)
221
219
  } else {
@@ -258,10 +256,10 @@ const REFS_HEADS = 'refs/heads/'
258
256
  const HEAD = 'HEAD'
259
257
  function refType (ref) {
260
258
  return ref.indexOf(REFS_TAGS) !== -1
261
- ? 'tag'
262
- : ref.indexOf(REFS_HEADS) !== -1
263
- ? 'branch'
264
- : ref.endsWith(HEAD)
265
- ? 'head'
266
- : 'other'
259
+ ? 'tag'
260
+ : ref.indexOf(REFS_HEADS) !== -1
261
+ ? 'branch'
262
+ : ref.endsWith(HEAD)
263
+ ? 'head'
264
+ : 'other'
267
265
  }
@@ -45,8 +45,8 @@ function PacoteOptions (opts) {
45
45
  this.fullMetadata = opts.fullMetadata
46
46
  this.alwaysAuth = opts.alwaysAuth
47
47
  this.includeDeprecated = opts.includeDeprecated == null
48
- ? true
49
- : opts.includeDeprecated
48
+ ? true
49
+ : opts.includeDeprecated
50
50
 
51
51
  this.dirPacker = opts.dirPacker || null
52
52
 
@@ -14,8 +14,8 @@ function packDir (manifest, label, dir, target, opts) {
14
14
  opts = optCheck(opts)
15
15
 
16
16
  const packer = opts.dirPacker
17
- ? BB.resolve(opts.dirPacker(manifest, dir))
18
- : mkPacker(dir)
17
+ ? BB.resolve(opts.dirPacker(manifest, dir))
18
+ : mkPacker(dir)
19
19
 
20
20
  if (!opts.cache) {
21
21
  return packer.then(packer => pipe(packer, target))
@@ -27,107 +27,107 @@ function withTarballStream (spec, opts, streamHandler) {
27
27
  opts.resolved &&
28
28
  opts.resolved.startsWith('file:')
29
29
  )
30
- ? BB.try(() => {
30
+ ? BB.try(() => {
31
31
  // NOTE - this is a special shortcut! Packages installed as files do not
32
32
  // have a `resolved` field -- this specific case only occurs when you have,
33
33
  // say, a git dependency or a registry dependency that you've packaged into
34
34
  // a local file, and put that file: spec in the `resolved` field.
35
- opts.log.silly('pacote', `trying ${spec} by local file: ${opts.resolved}`)
36
- const file = path.resolve(opts.where || '.', opts.resolved.substr(5))
37
- return statAsync(file)
38
- .then(() => {
39
- const verifier = ssri.integrityStream({integrity: opts.integrity})
40
- const stream = fs.createReadStream(file)
41
- .on('error', err => verifier.emit('error', err))
42
- .pipe(verifier)
43
- return streamHandler(stream)
44
- })
45
- .catch(err => {
46
- if (err.code === 'EINTEGRITY') {
47
- opts.log.warn('pacote', `EINTEGRITY while extracting ${spec} from ${file}.You will have to recreate the file.`)
48
- opts.log.verbose('pacote', `EINTEGRITY for ${spec}: ${err.message}`)
49
- }
50
- throw err
35
+ opts.log.silly('pacote', `trying ${spec} by local file: ${opts.resolved}`)
36
+ const file = path.resolve(opts.where || '.', opts.resolved.substr(5))
37
+ return statAsync(file)
38
+ .then(() => {
39
+ const verifier = ssri.integrityStream({integrity: opts.integrity})
40
+ const stream = fs.createReadStream(file)
41
+ .on('error', err => verifier.emit('error', err))
42
+ .pipe(verifier)
43
+ return streamHandler(stream)
44
+ })
45
+ .catch(err => {
46
+ if (err.code === 'EINTEGRITY') {
47
+ opts.log.warn('pacote', `EINTEGRITY while extracting ${spec} from ${file}.You will have to recreate the file.`)
48
+ opts.log.verbose('pacote', `EINTEGRITY for ${spec}: ${err.message}`)
49
+ }
50
+ throw err
51
+ })
51
52
  })
52
- })
53
- : BB.reject(Object.assign(new Error('no file!'), {code: 'ENOENT'}))
53
+ : BB.reject(Object.assign(new Error('no file!'), {code: 'ENOENT'}))
54
54
 
55
55
  const tryDigest = tryFile
56
- .catch(err => {
57
- if (
58
- opts.preferOnline ||
56
+ .catch(err => {
57
+ if (
58
+ opts.preferOnline ||
59
59
  !opts.cache ||
60
60
  !opts.integrity ||
61
61
  !RETRIABLE_ERRORS.has(err.code)
62
- ) {
63
- throw err
64
- } else {
65
- opts.log.silly('tarball', `trying ${spec} by hash: ${opts.integrity}`)
66
- const stream = cacache.get.stream.byDigest(
67
- opts.cache, opts.integrity, opts
68
- )
69
- stream.once('error', err => stream.on('newListener', (ev, l) => {
70
- if (ev === 'error') { l(err) }
71
- }))
72
- return streamHandler(stream)
73
- .catch(err => {
74
- if (err.code === 'EINTEGRITY' || err.code === 'Z_DATA_ERROR') {
75
- opts.log.warn('tarball', `cached data for ${spec} (${opts.integrity}) seems to be corrupted. Refreshing cache.`)
76
- return cleanUpCached(opts.cache, opts.integrity, opts)
77
- .then(() => { throw err })
78
- } else {
79
- throw err
80
- }
81
- })
82
- }
83
- })
62
+ ) {
63
+ throw err
64
+ } else {
65
+ opts.log.silly('tarball', `trying ${spec} by hash: ${opts.integrity}`)
66
+ const stream = cacache.get.stream.byDigest(
67
+ opts.cache, opts.integrity, opts
68
+ )
69
+ stream.once('error', err => stream.on('newListener', (ev, l) => {
70
+ if (ev === 'error') { l(err) }
71
+ }))
72
+ return streamHandler(stream)
73
+ .catch(err => {
74
+ if (err.code === 'EINTEGRITY' || err.code === 'Z_DATA_ERROR') {
75
+ opts.log.warn('tarball', `cached data for ${spec} (${opts.integrity}) seems to be corrupted. Refreshing cache.`)
76
+ return cleanUpCached(opts.cache, opts.integrity, opts)
77
+ .then(() => { throw err })
78
+ } else {
79
+ throw err
80
+ }
81
+ })
82
+ }
83
+ })
84
84
 
85
85
  const trySpec = tryDigest
86
- .catch(err => {
87
- if (!RETRIABLE_ERRORS.has(err.code)) {
86
+ .catch(err => {
87
+ if (!RETRIABLE_ERRORS.has(err.code)) {
88
88
  // If it's not one of our retriable errors, bail out and give up.
89
- throw err
90
- } else {
91
- opts.log.silly(
92
- 'tarball',
93
- `no local data for ${spec}. Extracting by manifest.`
94
- )
95
- return BB.resolve(retry((tryAgain, attemptNum) => {
96
- const tardata = fetch.tarball(spec, opts)
97
- if (!opts.resolved) {
98
- tardata.on('manifest', m => {
99
- opts.resolved = m._resolved
100
- })
101
- tardata.on('integrity', i => {
102
- opts.integrity = i
103
- })
104
- }
105
- return BB.try(() => streamHandler(tardata))
106
- .catch(err => {
107
- // Retry once if we have a cache, to clear up any weird conditions.
108
- // Don't retry network errors, though -- make-fetch-happen has already
109
- // taken care of making sure we're all set on that front.
110
- if (opts.cache && err.code && !err.code.match(/^E\d{3}$/)) {
111
- if (err.code === 'EINTEGRITY' || err.code === 'Z_DATA_ERROR') {
112
- opts.log.warn('tarball', `tarball data for ${spec} (${opts.integrity}) seems to be corrupted. Trying one more time.`)
113
- }
114
- return cleanUpCached(opts.cache, err.sri, opts)
115
- .then(() => tryAgain(err))
116
- } else {
117
- throw err
89
+ throw err
90
+ } else {
91
+ opts.log.silly(
92
+ 'tarball',
93
+ `no local data for ${spec}. Extracting by manifest.`
94
+ )
95
+ return BB.resolve(retry((tryAgain, attemptNum) => {
96
+ const tardata = fetch.tarball(spec, opts)
97
+ if (!opts.resolved) {
98
+ tardata.on('manifest', m => {
99
+ opts.resolved = m._resolved
100
+ })
101
+ tardata.on('integrity', i => {
102
+ opts.integrity = i
103
+ })
118
104
  }
119
- })
120
- }, {retries: 1}))
121
- }
122
- })
105
+ return BB.try(() => streamHandler(tardata))
106
+ .catch(err => {
107
+ // Retry once if we have a cache, to clear up any weird conditions.
108
+ // Don't retry network errors, though -- make-fetch-happen has already
109
+ // taken care of making sure we're all set on that front.
110
+ if (opts.cache && err.code && !err.code.match(/^E\d{3}$/)) {
111
+ if (err.code === 'EINTEGRITY' || err.code === 'Z_DATA_ERROR') {
112
+ opts.log.warn('tarball', `tarball data for ${spec} (${opts.integrity}) seems to be corrupted. Trying one more time.`)
113
+ }
114
+ return cleanUpCached(opts.cache, err.sri, opts)
115
+ .then(() => tryAgain(err))
116
+ } else {
117
+ throw err
118
+ }
119
+ })
120
+ }, {retries: 1}))
121
+ }
122
+ })
123
123
 
124
124
  return trySpec
125
- .catch(err => {
126
- if (err.code === 'EINTEGRITY') {
127
- err.message = `Verification failed while extracting ${spec}:\n${err.message}`
128
- }
129
- throw err
130
- })
125
+ .catch(err => {
126
+ if (err.code === 'EINTEGRITY') {
127
+ err.message = `Verification failed while extracting ${spec}:\n${err.message}`
128
+ }
129
+ throw err
130
+ })
131
131
  }
132
132
 
133
133
  function cleanUpCached (cachePath, integrity, opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacote",
3
- "version": "7.6.0",
3
+ "version": "8.1.1",
4
4
  "description": "JavaScript package downloader",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -42,16 +42,16 @@
42
42
  "license": "MIT",
43
43
  "dependencies": {
44
44
  "bluebird": "^3.5.1",
45
- "cacache": "^10.0.4",
45
+ "cacache": "^11.0.1",
46
46
  "get-stream": "^3.0.0",
47
47
  "glob": "^7.1.2",
48
- "lru-cache": "^4.1.1",
49
- "make-fetch-happen": "^2.6.0",
48
+ "lru-cache": "^4.1.2",
49
+ "make-fetch-happen": "^4.0.1",
50
50
  "minimatch": "^3.0.4",
51
- "mississippi": "^2.0.0",
51
+ "mississippi": "^3.0.0",
52
52
  "mkdirp": "^0.5.1",
53
53
  "normalize-package-data": "^2.4.0",
54
- "npm-package-arg": "^6.0.0",
54
+ "npm-package-arg": "^6.1.0",
55
55
  "npm-packlist": "^1.1.10",
56
56
  "npm-pick-manifest": "^2.1.0",
57
57
  "osenv": "^0.1.5",
@@ -61,20 +61,20 @@
61
61
  "rimraf": "^2.6.2",
62
62
  "safe-buffer": "^5.1.1",
63
63
  "semver": "^5.5.0",
64
- "ssri": "^5.2.4",
65
- "tar": "^4.3.3",
64
+ "ssri": "^6.0.0",
65
+ "tar": "^4.4.1",
66
66
  "unique-filename": "^1.1.0",
67
67
  "which": "^1.3.0"
68
68
  },
69
69
  "devDependencies": {
70
- "nock": "^9.1.6",
70
+ "nock": "^9.2.5",
71
71
  "npmlog": "^4.1.2",
72
- "nyc": "^11.4.1",
72
+ "nyc": "^11.6.0",
73
73
  "require-inject": "^1.4.2",
74
- "standard": "^10.0.3",
74
+ "standard": "^11.0.1",
75
75
  "standard-version": "^4.3.0",
76
76
  "tacks": "^1.2.6",
77
- "tap": "^11.1.0",
77
+ "tap": "^11.1.3",
78
78
  "tar-stream": "^1.5.5",
79
79
  "weallbehave": "^1.2.0",
80
80
  "weallcontribute": "^1.0.7"
package/tarball.js CHANGED
@@ -45,7 +45,7 @@ function tarballStream (spec, opts) {
45
45
  })
46
46
  }
47
47
  })
48
- .catch(err => output.emit('error', err))
48
+ .catch(err => output.emit('error', err))
49
49
  return output
50
50
  }
51
51
 
@@ -54,14 +54,14 @@ function tarballToFile (spec, dest, opts) {
54
54
  opts = optCheck(opts)
55
55
  spec = npa(spec, opts.where)
56
56
  return mkdirp(path.dirname(dest))
57
- .then(() => withTarballStream(spec, opts, stream => {
58
- return rimraf(dest)
59
- .then(() => new BB((resolve, reject) => {
60
- const writer = fs.createWriteStream(dest)
61
- stream.on('error', reject)
62
- writer.on('error', reject)
63
- writer.on('close', resolve)
64
- stream.pipe(writer)
57
+ .then(() => withTarballStream(spec, opts, stream => {
58
+ return rimraf(dest)
59
+ .then(() => new BB((resolve, reject) => {
60
+ const writer = fs.createWriteStream(dest)
61
+ stream.on('error', reject)
62
+ writer.on('error', reject)
63
+ writer.on('close', resolve)
64
+ stream.pipe(writer)
65
+ }))
65
66
  }))
66
- }))
67
67
  }