pacote 7.3.2 → 7.3.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
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="7.3.3"></a>
6
+ ## [7.3.3](https://github.com/zkat/pacote/compare/v7.3.2...v7.3.3) (2018-02-15)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **tarball:** another attempt at fixing opts.resolved ([aff3b6a](https://github.com/zkat/pacote/commit/aff3b6a))
12
+
13
+
14
+
5
15
  <a name="7.3.2"></a>
6
16
  ## [7.3.2](https://github.com/zkat/pacote/compare/v7.3.1...v7.3.2) (2018-02-15)
7
17
 
@@ -13,19 +13,30 @@ const url = require('url')
13
13
  module.exports = tarball
14
14
  function tarball (spec, opts) {
15
15
  opts = optCheck(opts)
16
+ const registry = pickRegistry(spec, opts)
16
17
  const stream = new PassThrough()
17
- const p = (opts.resolved && opts.integrity && spec.type === 'version')
18
- ? BB.resolve({
19
- name: spec.name,
20
- version: spec.fetchSpec,
21
- _integrity: opts.integrity,
22
- _resolved: opts.resolved,
23
- _fakeChild: true
24
- })
25
- : manifest(spec, opts)
26
- p.then(manifest => {
27
- !manifest._fakeChild && stream.emit('manifest', manifest)
28
- const fetchStream = fromManifest(manifest, spec, opts).on(
18
+ let mani
19
+ if (
20
+ opts.resolved &&
21
+ // spec.type === 'version' &&
22
+ opts.resolved.indexOf(registry) === 0
23
+ ) {
24
+ // fakeChild is a shortcut to avoid looking up a manifest!
25
+ mani = BB.resolve({
26
+ name: spec.name,
27
+ version: spec.fetchSpec,
28
+ _integrity: opts.integrity,
29
+ _resolved: opts.resolved,
30
+ _fakeChild: true
31
+ })
32
+ } else {
33
+ // We can't trust opts.resolved if it's going to a separate host.
34
+ mani = manifest(spec, opts)
35
+ }
36
+
37
+ mani.then(mani => {
38
+ !mani._fakeChild && stream.emit('manifest', mani)
39
+ const fetchStream = fromManifest(mani, spec, opts).on(
29
40
  'integrity', i => stream.emit('integrity', i)
30
41
  )
31
42
  fetchStream.on('error', err => stream.emit('error', err))
@@ -40,33 +51,27 @@ function fromManifest (manifest, spec, opts) {
40
51
  opts.scope = spec.scope || opts.scope
41
52
  const stream = new PassThrough()
42
53
  const registry = pickRegistry(spec, opts)
43
- getTarballUrl(spec, registry, manifest, opts)
44
- .then(uri => {
45
- return fetch(uri, registry, Object.assign({
46
- headers: {
47
- 'pacote-req-type': 'tarball',
48
- 'pacote-pkg-id': `registry:${
49
- spec.type === 'remote'
50
- ? spec
51
- : `${manifest.name}@${manifest.version}`
52
- }`
53
- },
54
- integrity: manifest._integrity,
55
- algorithms: [
56
- manifest._integrity
57
- ? ssri.parse(manifest._integrity).pickAlgorithm()
58
- : 'sha1'
59
- ],
60
- spec
61
- }, opts))
62
- .then(res => {
63
- const hash = res.headers.get('x-local-cache-hash')
64
- if (hash) {
65
- stream.emit('integrity', decodeURIComponent(hash))
66
- }
67
- res.body.on('error', err => stream.emit('error', err))
68
- res.body.pipe(stream)
69
- })
54
+ const uri = getTarballUrl(spec, registry, manifest, opts)
55
+ fetch(uri, registry, Object.assign({
56
+ headers: {
57
+ 'pacote-req-type': 'tarball',
58
+ 'pacote-pkg-id': `registry:${manifest.name}@${uri}`
59
+ },
60
+ integrity: manifest._integrity,
61
+ algorithms: [
62
+ manifest._integrity
63
+ ? ssri.parse(manifest._integrity).pickAlgorithm()
64
+ : 'sha1'
65
+ ],
66
+ spec
67
+ }, 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)
70
75
  })
71
76
  .catch(err => stream.emit('error', err))
72
77
  return stream
@@ -74,40 +79,23 @@ function fromManifest (manifest, spec, opts) {
74
79
 
75
80
  function getTarballUrl (spec, registry, mani, opts) {
76
81
  const reg = url.parse(registry)
77
- const tarball = url.parse(opts.resolved || mani._resolved)
78
- return (
79
- // We cannot trust opts.resolved as-is: there can only be one registry per
80
- // "scope" on any individual npm run, so we have to take any previously
81
- // resolved fields and check them against the current registry -- if they
82
- // don't match, we need to do a manifest fetch from the correct registry to
83
- // get the tarball URL we're trying to reference.
84
- (!opts.resolved || reg.hostname === tarball.hostname)
85
- ? Promise.resolve(Object.assign(mani, {
86
- _resolved: opts.resolved || mani._resolved
87
- }))
88
- // This second lookup should ONLY happen when we didn't already do a
89
- // registry lookup earlier.
90
- : manifest(spec, opts)
91
- )
92
- .then(mani => {
93
- const tarball = url.parse(mani._resolved)
94
- // https://github.com/npm/npm/pull/9471
95
- //
96
- // TL;DR: Some alternative registries host tarballs on http and packuments
97
- // on https, and vice-versa. There's also a case where people who can't use
98
- // SSL to access the npm registry, for example, might use
99
- // `--registry=http://registry.npmjs.org/`. In this case, we need to
100
- // rewrite `tarball` to match the protocol.
101
- //
102
- if (reg.hostname === tarball.hostname && reg.protocol !== tarball.protocol) {
103
- tarball.protocol = reg.protocol
104
- // Ports might be same host different protocol!
105
- if (reg.port !== tarball.port) {
106
- delete tarball.host
107
- tarball.port = reg.port
108
- }
109
- delete tarball.href
82
+ const tarball = url.parse(mani._resolved)
83
+ // https://github.com/npm/npm/pull/9471
84
+ //
85
+ // TL;DR: Some alternative registries host tarballs on http and packuments
86
+ // on https, and vice-versa. There's also a case where people who can't use
87
+ // SSL to access the npm registry, for example, might use
88
+ // `--registry=http://registry.npmjs.org/`. In this case, we need to
89
+ // rewrite `tarball` to match the protocol.
90
+ //
91
+ if (reg.hostname === tarball.hostname && reg.protocol !== tarball.protocol) {
92
+ tarball.protocol = reg.protocol
93
+ // Ports might be same host different protocol!
94
+ if (reg.port !== tarball.port) {
95
+ delete tarball.host
96
+ tarball.port = reg.port
110
97
  }
111
- return Promise.resolve(url.format(tarball))
112
- })
98
+ delete tarball.href
99
+ }
100
+ return url.format(tarball)
113
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacote",
3
- "version": "7.3.2",
3
+ "version": "7.3.3",
4
4
  "description": "JavaScript package downloader",
5
5
  "main": "index.js",
6
6
  "files": [