pacote 11.2.7 → 11.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/README.md CHANGED
@@ -168,6 +168,18 @@ resolved, and other properties, as they are determined.
168
168
  times (even just to validate the cache) for a given packument, since it
169
169
  is unlikely to change in the span of a single command.
170
170
 
171
+
172
+ ### Advanced API
173
+
174
+ Each different type of fetcher is exposed for more advanced usage such as
175
+ using helper methods from this classes:
176
+
177
+ * `DirFetcher`
178
+ * `FileFetcher`
179
+ * `GitFetcher`
180
+ * `RegistryFetcher`
181
+ * `RemoteFetcher`
182
+
171
183
  ## Extracted File Modes
172
184
 
173
185
  Files are extracted with a mode matching the following formula:
package/lib/dir.js CHANGED
@@ -4,11 +4,10 @@ const cacache = require('cacache')
4
4
  const Minipass = require('minipass')
5
5
  const { promisify } = require('util')
6
6
  const readPackageJson = require('read-package-json-fast')
7
- const isPackageBin = require('./util/is-package-bin.js')
7
+ const tarCreateOptions = require('./util/tar-create-options.js')
8
8
  const packlist = require('npm-packlist')
9
9
  const tar = require('tar')
10
10
  const _prepareDir = Symbol('_prepareDir')
11
- const _tarcOpts = Symbol('_tarcOpts')
12
11
  const { resolve } = require('path')
13
12
 
14
13
  const runScript = require('@npmcli/run-script')
@@ -21,6 +20,11 @@ class DirFetcher extends Fetcher {
21
20
  this.resolved = this.spec.fetchSpec
22
21
  }
23
22
 
23
+ // exposes tarCreateOptions as public API
24
+ static tarCreateOptions (manifest) {
25
+ return tarCreateOptions(manifest)
26
+ }
27
+
24
28
  get types () {
25
29
  return ['directory']
26
30
  }
@@ -65,35 +69,12 @@ class DirFetcher extends Fetcher {
65
69
  // pipe to the stream, and proxy errors the chain.
66
70
  this[_prepareDir]()
67
71
  .then(() => packlist({ path: this.resolved }))
68
- .then(files => tar.c(this[_tarcOpts](), files)
72
+ .then(files => tar.c(tarCreateOptions(this.package), files)
69
73
  .on('error', er => stream.emit('error', er)).pipe(stream))
70
74
  .catch(er => stream.emit('error', er))
71
75
  return stream
72
76
  }
73
77
 
74
- [_tarcOpts] () {
75
- return {
76
- cwd: this.resolved,
77
- prefix: 'package/',
78
- portable: true,
79
- gzip: true,
80
-
81
- // ensure that package bins are always executable
82
- // Note that npm-packlist is already filtering out
83
- // anything that is not a regular file, ignored by
84
- // .npmignore or package.json "files", etc.
85
- filter: (path, stat) => {
86
- if (isPackageBin(this.package, path))
87
- stat.mode |= 0o111
88
- return true
89
- },
90
-
91
- // Provide a specific date in the 1980s for the benefit of zip,
92
- // which is confounded by files dated at the Unix epoch 0.
93
- mtime: new Date('1985-10-26T08:15:00.000Z'),
94
- }
95
- }
96
-
97
78
  manifest () {
98
79
  if (this.package)
99
80
  return Promise.resolve(this.package)
package/lib/fetcher.js CHANGED
@@ -40,6 +40,7 @@ const _istream = Symbol('_istream')
40
40
  const _assertType = Symbol('_assertType')
41
41
  const _tarballFromCache = Symbol('_tarballFromCache')
42
42
  const _tarballFromResolved = Symbol.for('pacote.Fetcher._tarballFromResolved')
43
+ const _cacheFetches = Symbol.for('pacote.Fetcher._cacheFetches')
43
44
 
44
45
  class FetcherBase {
45
46
  constructor (spec, opts) {
@@ -166,25 +167,19 @@ class FetcherBase {
166
167
  }
167
168
 
168
169
  // private, should be overridden.
169
- // Note that they should *not* calculate or check integrity, but *just*
170
- // return the raw tarball data stream.
170
+ // Note that they should *not* calculate or check integrity or cache,
171
+ // but *just* return the raw tarball data stream.
171
172
  [_tarballFromResolved] () {
172
173
  throw this.notImplementedError
173
174
  }
174
175
 
175
176
  // public, should not be overridden
176
177
  tarball () {
177
- return this.tarballStream(stream => new Promise((res, rej) => {
178
- const buf = []
179
- stream.on('error', er => rej(er))
180
- stream.on('end', () => {
181
- const data = Buffer.concat(buf)
182
- data.integrity = this.integrity && String(this.integrity)
183
- data.resolved = this.resolved
184
- data.from = this.from
185
- return res(data)
186
- })
187
- stream.on('data', d => buf.push(d))
178
+ return this.tarballStream(stream => stream.concat().then(data => {
179
+ data.integrity = this.integrity && String(this.integrity)
180
+ data.resolved = this.resolved
181
+ data.from = this.from
182
+ return data
188
183
  }))
189
184
  }
190
185
 
@@ -194,6 +189,10 @@ class FetcherBase {
194
189
  return cacache.get.stream.byDigest(this.cache, this.integrity, this.opts)
195
190
  }
196
191
 
192
+ get [_cacheFetches] () {
193
+ return true
194
+ }
195
+
197
196
  [_istream] (stream) {
198
197
  // everyone will need one of these, either for verifying or calculating
199
198
  // We always set it, because we have might only have a weak legacy hex
@@ -203,7 +202,31 @@ class FetcherBase {
203
202
  // gets to the point of re-setting the integrity.
204
203
  const istream = ssri.integrityStream(this.opts)
205
204
  istream.on('integrity', i => this.integrity = i)
206
- return stream.on('error', er => istream.emit('error', er)).pipe(istream)
205
+ stream.on('error', er => istream.emit('error', er))
206
+
207
+ // if not caching this, just pipe through to the istream and return it
208
+ if (!this.opts.cache || !this[_cacheFetches])
209
+ return stream.pipe(istream)
210
+
211
+ // we have to return a stream that gets ALL the data, and proxies errors,
212
+ // but then pipe from the original tarball stream into the cache as well.
213
+ // To do this without losing any data, and since the cacache put stream
214
+ // is not a passthrough, we have to pipe from the original stream into
215
+ // the cache AFTER we pipe into the istream. Since the cache stream
216
+ // has an asynchronous flush to write its contents to disk, we need to
217
+ // defer the istream end until the cache stream ends.
218
+ stream.pipe(istream, { end: false })
219
+ const cstream = cacache.put.stream(
220
+ this.opts.cache,
221
+ `pacote:tarball:${this.from}`,
222
+ this.opts
223
+ )
224
+ stream.pipe(cstream)
225
+ // defer istream end until after cstream
226
+ // cache write errors should not crash the fetch, this is best-effort.
227
+ cstream.promise().catch(() => {}).then(() => istream.end())
228
+
229
+ return istream
207
230
  }
208
231
 
209
232
  pickIntegrityAlgorithm () {
@@ -232,7 +255,9 @@ class FetcherBase {
232
255
  // An ENOENT trying to read a tgz file, for example, is Right Out.
233
256
  isRetriableError (er) {
234
257
  // TODO: check error class, once those are rolled out to our deps
235
- return this.isDataCorruptionError(er) || er.code === 'ENOENT'
258
+ return this.isDataCorruptionError(er) ||
259
+ er.code === 'ENOENT' ||
260
+ er.code === 'EISDIR'
236
261
  }
237
262
 
238
263
  // Mostly internal, but has some uses
package/lib/index.js CHANGED
@@ -1,5 +1,16 @@
1
1
  const { get } = require('./fetcher.js')
2
+ const GitFetcher = require('./git.js')
3
+ const RegistryFetcher = require('./registry.js')
4
+ const FileFetcher = require('./file.js')
5
+ const DirFetcher = require('./dir.js')
6
+ const RemoteFetcher = require('./remote.js')
7
+
2
8
  module.exports = {
9
+ GitFetcher,
10
+ RegistryFetcher,
11
+ FileFetcher,
12
+ DirFetcher,
13
+ RemoteFetcher,
3
14
  resolve: (spec, opts) => get(spec, opts).resolve(),
4
15
  extract: (spec, dest, opts) => get(spec, opts).extract(dest),
5
16
  manifest: (spec, opts) => get(spec, opts).manifest(),
package/lib/registry.js CHANGED
@@ -3,6 +3,7 @@ const RemoteFetcher = require('./remote.js')
3
3
  const _tarballFromResolved = Symbol.for('pacote.Fetcher._tarballFromResolved')
4
4
  const pacoteVersion = require('../package.json').version
5
5
  const npa = require('npm-package-arg')
6
+ const rpj = require('read-package-json-fast')
6
7
  const pickManifest = require('npm-pick-manifest')
7
8
  const ssri = require('ssri')
8
9
  const Minipass = require('minipass')
@@ -156,7 +157,8 @@ class RegistryFetcher extends Fetcher {
156
157
  }
157
158
  if (this.integrity)
158
159
  mani._integrity = String(this.integrity)
159
- return this.package = mani
160
+ this.package = rpj.normalize(mani)
161
+ return this.package
160
162
  })
161
163
  }
162
164
 
package/lib/remote.js CHANGED
@@ -8,6 +8,7 @@ const Minipass = require('minipass')
8
8
  // The default registry URL is a string of great magic.
9
9
  const magic = /^https?:\/\/registry\.npmjs\.org\//
10
10
 
11
+ const _cacheFetches = Symbol.for('pacote.Fetcher._cacheFetches')
11
12
  const _headers = Symbol('_headers')
12
13
  class RemoteFetcher extends Fetcher {
13
14
  constructor (spec, opts) {
@@ -21,6 +22,12 @@ class RemoteFetcher extends Fetcher {
21
22
  this.pkgid = opts.pkgid ? opts.pkgid : `remote:${nameat}${this.resolved}`
22
23
  }
23
24
 
25
+ // Don't need to cache tarball fetches in pacote, because make-fetch-happen
26
+ // will write into cacache anyway.
27
+ get [_cacheFetches] () {
28
+ return false
29
+ }
30
+
24
31
  [_tarballFromResolved] () {
25
32
  const stream = new Minipass()
26
33
  const fetchOpts = {
@@ -0,0 +1,30 @@
1
+ const isPackageBin = require('./is-package-bin.js')
2
+
3
+ const tarCreateOptions = manifest => ({
4
+ cwd: manifest._resolved,
5
+ prefix: 'package/',
6
+ portable: true,
7
+ gzip: {
8
+ // forcing the level to 9 seems to avoid some
9
+ // platform specific optimizations that cause
10
+ // integrity mismatch errors due to differing
11
+ // end results after compression
12
+ level: 9
13
+ },
14
+
15
+ // ensure that package bins are always executable
16
+ // Note that npm-packlist is already filtering out
17
+ // anything that is not a regular file, ignored by
18
+ // .npmignore or package.json "files", etc.
19
+ filter: (path, stat) => {
20
+ if (isPackageBin(manifest, path))
21
+ stat.mode |= 0o111
22
+ return true
23
+ },
24
+
25
+ // Provide a specific date in the 1980s for the benefit of zip,
26
+ // which is confounded by files dated at the Unix epoch 0.
27
+ mtime: new Date('1985-10-26T08:15:00.000Z'),
28
+ })
29
+
30
+ module.exports = tarCreateOptions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacote",
3
- "version": "11.2.7",
3
+ "version": "11.3.3",
4
4
  "description": "JavaScript package downloader",
5
5
  "author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)",
6
6
  "bin": {
@@ -17,15 +17,12 @@
17
17
  },
18
18
  "tap": {
19
19
  "timeout": 300,
20
- "check-coverage": true,
21
- "coverage-map": "map.js",
22
- "esm": false
20
+ "coverage-map": "map.js"
23
21
  },
24
22
  "devDependencies": {
25
23
  "mutate-fs": "^2.1.1",
26
24
  "npm-registry-mock": "^1.3.1",
27
- "require-inject": "^1.4.4",
28
- "tap": "^14.11.0"
25
+ "tap": "^15.0.4"
29
26
  },
30
27
  "files": [
31
28
  "lib/**/*.js"
@@ -49,7 +46,7 @@
49
46
  "npm-package-arg": "^8.0.1",
50
47
  "npm-packlist": "^2.1.4",
51
48
  "npm-pick-manifest": "^6.0.0",
52
- "npm-registry-fetch": "^9.0.0",
49
+ "npm-registry-fetch": "^10.0.0",
53
50
  "promise-retry": "^2.0.1",
54
51
  "read-package-json-fast": "^2.0.1",
55
52
  "rimraf": "^3.0.2",