cacache 15.3.0 → 16.0.2

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.
@@ -20,15 +20,18 @@ function read (cache, integrity, opts = {}) {
20
20
  // get size
21
21
  return lstat(cpath).then(stat => ({ stat, cpath, sri }))
22
22
  }).then(({ stat, cpath, sri }) => {
23
- if (typeof size === 'number' && stat.size !== size)
23
+ if (typeof size === 'number' && stat.size !== size) {
24
24
  throw sizeError(size, stat.size)
25
+ }
25
26
 
26
- if (stat.size > MAX_SINGLE_READ_SIZE)
27
+ if (stat.size > MAX_SINGLE_READ_SIZE) {
27
28
  return readPipeline(cpath, stat.size, sri, new Pipeline()).concat()
29
+ }
28
30
 
29
31
  return readFile(cpath, null).then((data) => {
30
- if (!ssri.checkData(data, sri))
32
+ if (!ssri.checkData(data, sri)) {
31
33
  throw integrityError(sri, cpath)
34
+ }
32
35
 
33
36
  return data
34
37
  })
@@ -55,11 +58,13 @@ function readSync (cache, integrity, opts = {}) {
55
58
  const { size } = opts
56
59
  return withContentSriSync(cache, integrity, (cpath, sri) => {
57
60
  const data = fs.readFileSync(cpath)
58
- if (typeof size === 'number' && size !== data.length)
61
+ if (typeof size === 'number' && size !== data.length) {
59
62
  throw sizeError(size, data.length)
63
+ }
60
64
 
61
- if (ssri.checkData(data, sri))
65
+ if (ssri.checkData(data, sri)) {
62
66
  return data
67
+ }
63
68
 
64
69
  throw integrityError(sri, cpath)
65
70
  })
@@ -75,8 +80,9 @@ function readStream (cache, integrity, opts = {}) {
75
80
  // just lstat to ensure it exists
76
81
  return lstat(cpath).then((stat) => ({ stat, cpath, sri }))
77
82
  }).then(({ stat, cpath, sri }) => {
78
- if (typeof size === 'number' && size !== stat.size)
83
+ if (typeof size === 'number' && size !== stat.size) {
79
84
  return stream.emit('error', sizeError(size, stat.size))
85
+ }
80
86
 
81
87
  readPipeline(cpath, stat.size, sri, stream)
82
88
  }, er => stream.emit('error', er))
@@ -106,21 +112,24 @@ function copySync (cache, integrity, dest) {
106
112
  module.exports.hasContent = hasContent
107
113
 
108
114
  function hasContent (cache, integrity) {
109
- if (!integrity)
115
+ if (!integrity) {
110
116
  return Promise.resolve(false)
117
+ }
111
118
 
112
119
  return withContentSri(cache, integrity, (cpath, sri) => {
113
120
  return lstat(cpath).then((stat) => ({ size: stat.size, sri, stat }))
114
121
  }).catch((err) => {
115
- if (err.code === 'ENOENT')
122
+ if (err.code === 'ENOENT') {
116
123
  return false
124
+ }
117
125
 
118
126
  if (err.code === 'EPERM') {
119
127
  /* istanbul ignore else */
120
- if (process.platform !== 'win32')
128
+ if (process.platform !== 'win32') {
121
129
  throw err
122
- else
130
+ } else {
123
131
  return false
132
+ }
124
133
  }
125
134
  })
126
135
  }
@@ -128,23 +137,26 @@ function hasContent (cache, integrity) {
128
137
  module.exports.hasContent.sync = hasContentSync
129
138
 
130
139
  function hasContentSync (cache, integrity) {
131
- if (!integrity)
140
+ if (!integrity) {
132
141
  return false
142
+ }
133
143
 
134
144
  return withContentSriSync(cache, integrity, (cpath, sri) => {
135
145
  try {
136
146
  const stat = fs.lstatSync(cpath)
137
147
  return { size: stat.size, sri, stat }
138
148
  } catch (err) {
139
- if (err.code === 'ENOENT')
149
+ if (err.code === 'ENOENT') {
140
150
  return false
151
+ }
141
152
 
142
153
  if (err.code === 'EPERM') {
143
154
  /* istanbul ignore else */
144
- if (process.platform !== 'win32')
155
+ if (process.platform !== 'win32') {
145
156
  throw err
146
- else
157
+ } else {
147
158
  return false
159
+ }
148
160
  }
149
161
  }
150
162
  })
@@ -180,13 +192,15 @@ function withContentSri (cache, integrity, fn) {
180
192
  .then((results) => {
181
193
  // Return the first non error if it is found
182
194
  const result = results.find((r) => !(r instanceof Error))
183
- if (result)
195
+ if (result) {
184
196
  return result
197
+ }
185
198
 
186
199
  // Throw the No matching content found error
187
200
  const enoentError = results.find((r) => r.code === 'ENOENT')
188
- if (enoentError)
201
+ if (enoentError) {
189
202
  throw enoentError
203
+ }
190
204
 
191
205
  // Throw generic error
192
206
  throw results.find((r) => r instanceof Error)
@@ -228,6 +242,7 @@ function withContentSriSync (cache, integrity, fn) {
228
242
  }
229
243
 
230
244
  function sizeError (expected, found) {
245
+ /* eslint-disable-next-line max-len */
231
246
  const err = new Error(`Bad data size: expected inserted data to be ${expected} bytes, but got ${found} instead`)
232
247
  err.expected = expected
233
248
  err.found = found
package/lib/content/rm.js CHANGED
@@ -11,9 +11,10 @@ module.exports = rm
11
11
  function rm (cache, integrity) {
12
12
  return hasContent(cache, integrity).then((content) => {
13
13
  // ~pretty~ sure we can't end up with a content lacking sri, but be safe
14
- if (content && content.sri)
14
+ if (content && content.sri) {
15
15
  return rimraf(contentPath(cache, content.sri)).then(() => true)
16
- else
16
+ } else {
17
17
  return false
18
+ }
18
19
  })
19
20
  }
@@ -22,15 +22,18 @@ module.exports = write
22
22
 
23
23
  function write (cache, data, opts = {}) {
24
24
  const { algorithms, size, integrity } = opts
25
- if (algorithms && algorithms.length > 1)
25
+ if (algorithms && algorithms.length > 1) {
26
26
  throw new Error('opts.algorithms only supports a single algorithm for now')
27
+ }
27
28
 
28
- if (typeof size === 'number' && data.length !== size)
29
+ if (typeof size === 'number' && data.length !== size) {
29
30
  return Promise.reject(sizeError(size, data.length))
31
+ }
30
32
 
31
33
  const sri = ssri.fromData(data, algorithms ? { algorithms } : {})
32
- if (integrity && !ssri.checkData(data, integrity, opts))
34
+ if (integrity && !ssri.checkData(data, integrity, opts)) {
33
35
  return Promise.reject(checksumError(integrity, sri))
36
+ }
34
37
 
35
38
  return disposer(makeTmp(cache, opts), makeTmpDisposer,
36
39
  (tmp) => {
@@ -149,8 +152,9 @@ function makeTmp (cache, opts) {
149
152
  }
150
153
 
151
154
  function makeTmpDisposer (tmp) {
152
- if (tmp.moved)
155
+ if (tmp.moved) {
153
156
  return Promise.resolve()
157
+ }
154
158
 
155
159
  return rimraf(tmp.target)
156
160
  }
@@ -171,6 +175,7 @@ function moveToDestination (tmp, cache, sri, opts) {
171
175
  }
172
176
 
173
177
  function sizeError (expected, found) {
178
+ /* eslint-disable-next-line max-len */
174
179
  const err = new Error(`Bad data size: expected inserted data to be ${expected} bytes, but got ${found} instead`)
175
180
  err.expected = expected
176
181
  err.found = found
@@ -49,8 +49,9 @@ async function compact (cache, key, matchFn, opts = {}) {
49
49
  // if the integrity is null and no validateEntry is provided, we break
50
50
  // as we consider the null integrity to be a deletion of everything
51
51
  // that came before it.
52
- if (entry.integrity === null && !opts.validateEntry)
52
+ if (entry.integrity === null && !opts.validateEntry) {
53
53
  break
54
+ }
54
55
 
55
56
  // if this entry is valid, and it is either the first entry or
56
57
  // the newEntries array doesn't already include an entry that
@@ -58,8 +59,9 @@ async function compact (cache, key, matchFn, opts = {}) {
58
59
  // it to the beginning of our list
59
60
  if ((!opts.validateEntry || opts.validateEntry(entry) === true) &&
60
61
  (newEntries.length === 0 ||
61
- !newEntries.find((oldEntry) => matchFn(oldEntry, entry))))
62
+ !newEntries.find((oldEntry) => matchFn(oldEntry, entry)))) {
62
63
  newEntries.unshift(entry)
64
+ }
63
65
  }
64
66
 
65
67
  const newIndex = '\n' + newEntries.map((entry) => {
@@ -78,8 +80,9 @@ async function compact (cache, key, matchFn, opts = {}) {
78
80
  }
79
81
 
80
82
  const teardown = async (tmp) => {
81
- if (!tmp.moved)
83
+ if (!tmp.moved) {
82
84
  return rimraf(tmp.target)
85
+ }
83
86
  }
84
87
 
85
88
  const write = async (tmp) => {
@@ -92,8 +95,9 @@ async function compact (cache, key, matchFn, opts = {}) {
92
95
  try {
93
96
  await fixOwner.chownr(cache, bucket)
94
97
  } catch (err) {
95
- if (err.code !== 'ENOENT')
98
+ if (err.code !== 'ENOENT') {
96
99
  throw err
100
+ }
97
101
  }
98
102
  }
99
103
 
@@ -136,8 +140,9 @@ function insert (cache, key, integrity, opts = {}) {
136
140
  })
137
141
  .then(() => fixOwner.chownr(cache, bucket))
138
142
  .catch((err) => {
139
- if (err.code === 'ENOENT')
143
+ if (err.code === 'ENOENT') {
140
144
  return undefined
145
+ }
141
146
 
142
147
  throw err
143
148
  // There's a class of race conditions that happen when things get deleted
@@ -169,8 +174,9 @@ function insertSync (cache, key, integrity, opts = {}) {
169
174
  try {
170
175
  fixOwner.chownr.sync(cache, bucket)
171
176
  } catch (err) {
172
- if (err.code !== 'ENOENT')
177
+ if (err.code !== 'ENOENT') {
173
178
  throw err
179
+ }
174
180
  }
175
181
  return formatEntry(cache, entry)
176
182
  }
@@ -182,17 +188,19 @@ function find (cache, key) {
182
188
  return bucketEntries(bucket)
183
189
  .then((entries) => {
184
190
  return entries.reduce((latest, next) => {
185
- if (next && next.key === key)
191
+ if (next && next.key === key) {
186
192
  return formatEntry(cache, next)
187
- else
193
+ } else {
188
194
  return latest
195
+ }
189
196
  }, null)
190
197
  })
191
198
  .catch((err) => {
192
- if (err.code === 'ENOENT')
199
+ if (err.code === 'ENOENT') {
193
200
  return null
194
- else
201
+ } else {
195
202
  throw err
203
+ }
196
204
  })
197
205
  }
198
206
 
@@ -202,24 +210,27 @@ function findSync (cache, key) {
202
210
  const bucket = bucketPath(cache, key)
203
211
  try {
204
212
  return bucketEntriesSync(bucket).reduce((latest, next) => {
205
- if (next && next.key === key)
213
+ if (next && next.key === key) {
206
214
  return formatEntry(cache, next)
207
- else
215
+ } else {
208
216
  return latest
217
+ }
209
218
  }, null)
210
219
  } catch (err) {
211
- if (err.code === 'ENOENT')
220
+ if (err.code === 'ENOENT') {
212
221
  return null
213
- else
222
+ } else {
214
223
  throw err
224
+ }
215
225
  }
216
226
  }
217
227
 
218
228
  module.exports.delete = del
219
229
 
220
230
  function del (cache, key, opts = {}) {
221
- if (!opts.removeFully)
231
+ if (!opts.removeFully) {
222
232
  return insert(cache, key, null, opts)
233
+ }
223
234
 
224
235
  const bucket = bucketPath(cache, key)
225
236
  return rimraf(bucket)
@@ -228,8 +239,9 @@ function del (cache, key, opts = {}) {
228
239
  module.exports.delete.sync = delSync
229
240
 
230
241
  function delSync (cache, key, opts = {}) {
231
- if (!opts.removeFully)
242
+ if (!opts.removeFully) {
232
243
  return insertSync(cache, key, null, opts)
244
+ }
233
245
 
234
246
  const bucket = bucketPath(cache, key)
235
247
  return rimraf.sync(bucket)
@@ -263,12 +275,14 @@ function lsStream (cache) {
263
275
  // reduced is a map of key => entry
264
276
  for (const entry of reduced.values()) {
265
277
  const formatted = formatEntry(cache, entry)
266
- if (formatted)
278
+ if (formatted) {
267
279
  stream.write(formatted)
280
+ }
268
281
  }
269
282
  }).catch(err => {
270
- if (err.code === 'ENOENT')
283
+ if (err.code === 'ENOENT') {
271
284
  return undefined
285
+ }
272
286
  throw err
273
287
  })
274
288
  })
@@ -312,8 +326,9 @@ function bucketEntriesSync (bucket, filter) {
312
326
  function _bucketEntries (data, filter) {
313
327
  const entries = []
314
328
  data.split('\n').forEach((entry) => {
315
- if (!entry)
329
+ if (!entry) {
316
330
  return
331
+ }
317
332
 
318
333
  const pieces = entry.split('\t')
319
334
  if (!pieces[1] || hashEntry(pieces[1]) !== pieces[0]) {
@@ -328,8 +343,9 @@ function _bucketEntries (data, filter) {
328
343
  // Entry is corrupted!
329
344
  return
330
345
  }
331
- if (obj)
346
+ if (obj) {
332
347
  entries.push(obj)
348
+ }
333
349
  })
334
350
  return entries
335
351
  }
@@ -371,8 +387,9 @@ function hash (str, digest) {
371
387
 
372
388
  function formatEntry (cache, entry, keepAll) {
373
389
  // Treat null digests as deletions. They'll shadow any previous entries.
374
- if (!entry.integrity && !keepAll)
390
+ if (!entry.integrity && !keepAll) {
375
391
  return null
392
+ }
376
393
 
377
394
  return {
378
395
  key: entry.key,
@@ -386,8 +403,9 @@ function formatEntry (cache, entry, keepAll) {
386
403
 
387
404
  function readdirOrEmpty (dir) {
388
405
  return readdir(dir).catch((err) => {
389
- if (err.code === 'ENOENT' || err.code === 'ENOTDIR')
406
+ if (err.code === 'ENOENT' || err.code === 'ENOTDIR') {
390
407
  return []
408
+ }
391
409
 
392
410
  throw err
393
411
  })
@@ -6,9 +6,9 @@ const Pipeline = require('minipass-pipeline')
6
6
  const fs = require('fs')
7
7
  const util = require('util')
8
8
 
9
- const index = require('./lib/entry-index')
10
- const memo = require('./lib/memoization')
11
- const read = require('./lib/content/read')
9
+ const index = require('./entry-index')
10
+ const memo = require('./memoization')
11
+ const read = require('./content/read')
12
12
 
13
13
  const writeFile = util.promisify(fs.writeFile)
14
14
 
@@ -25,12 +25,14 @@ function getData (cache, key, opts = {}) {
25
25
  }
26
26
 
27
27
  return index.find(cache, key, opts).then((entry) => {
28
- if (!entry)
28
+ if (!entry) {
29
29
  throw new index.NotFoundError(cache, key)
30
+ }
30
31
 
31
32
  return read(cache, entry.integrity, { integrity, size }).then((data) => {
32
- if (memoize)
33
+ if (memoize) {
33
34
  memo.put(cache, entry, data, opts)
35
+ }
34
36
 
35
37
  return {
36
38
  data,
@@ -46,12 +48,14 @@ module.exports = getData
46
48
  function getDataByDigest (cache, key, opts = {}) {
47
49
  const { integrity, memoize, size } = opts
48
50
  const memoized = memo.get.byDigest(cache, key, opts)
49
- if (memoized && memoize !== false)
51
+ if (memoized && memoize !== false) {
50
52
  return Promise.resolve(memoized)
53
+ }
51
54
 
52
55
  return read(cache, key, { integrity, size }).then((res) => {
53
- if (memoize)
56
+ if (memoize) {
54
57
  memo.put.byDigest(cache, key, res, opts)
58
+ }
55
59
  return res
56
60
  })
57
61
  }
@@ -70,8 +74,9 @@ function getDataSync (cache, key, opts = {}) {
70
74
  }
71
75
  }
72
76
  const entry = index.find.sync(cache, key, opts)
73
- if (!entry)
77
+ if (!entry) {
74
78
  throw new index.NotFoundError(cache, key)
79
+ }
75
80
  const data = read.sync(cache, entry.integrity, {
76
81
  integrity: integrity,
77
82
  size: size,
@@ -82,8 +87,9 @@ function getDataSync (cache, key, opts = {}) {
82
87
  size: entry.size,
83
88
  integrity: entry.integrity,
84
89
  }
85
- if (memoize)
90
+ if (memoize) {
86
91
  memo.put(cache, entry, res.data, opts)
92
+ }
87
93
 
88
94
  return res
89
95
  }
@@ -94,15 +100,17 @@ function getDataByDigestSync (cache, digest, opts = {}) {
94
100
  const { integrity, memoize, size } = opts
95
101
  const memoized = memo.get.byDigest(cache, digest, opts)
96
102
 
97
- if (memoized && memoize !== false)
103
+ if (memoized && memoize !== false) {
98
104
  return memoized
105
+ }
99
106
 
100
107
  const res = read.sync(cache, digest, {
101
108
  integrity: integrity,
102
109
  size: size,
103
110
  })
104
- if (memoize)
111
+ if (memoize) {
105
112
  memo.put.byDigest(cache, digest, res, opts)
113
+ }
106
114
 
107
115
  return res
108
116
  }
@@ -122,15 +130,17 @@ const getMemoizedStream = (memoized) => {
122
130
  function getStream (cache, key, opts = {}) {
123
131
  const { memoize, size } = opts
124
132
  const memoized = memo.get(cache, key, opts)
125
- if (memoized && memoize !== false)
133
+ if (memoized && memoize !== false) {
126
134
  return getMemoizedStream(memoized)
135
+ }
127
136
 
128
137
  const stream = new Pipeline()
129
138
  index
130
139
  .find(cache, key)
131
140
  .then((entry) => {
132
- if (!entry)
141
+ if (!entry) {
133
142
  throw new index.NotFoundError(cache, key)
143
+ }
134
144
 
135
145
  stream.emit('metadata', entry.metadata)
136
146
  stream.emit('integrity', entry.integrity)
@@ -170,8 +180,9 @@ function getStreamDigest (cache, integrity, opts = {}) {
170
180
  return stream
171
181
  } else {
172
182
  const stream = read.readStream(cache, integrity, opts)
173
- if (!memoize)
183
+ if (!memoize) {
174
184
  return stream
185
+ }
175
186
 
176
187
  const memoStream = new Collect.PassThrough()
177
188
  memoStream.on('collect', data => memo.put.byDigest(
@@ -189,18 +200,20 @@ module.exports.stream.byDigest = getStreamDigest
189
200
  function info (cache, key, opts = {}) {
190
201
  const { memoize } = opts
191
202
  const memoized = memo.get(cache, key, opts)
192
- if (memoized && memoize !== false)
203
+ if (memoized && memoize !== false) {
193
204
  return Promise.resolve(memoized.entry)
194
- else
205
+ } else {
195
206
  return index.find(cache, key)
207
+ }
196
208
  }
197
209
  module.exports.info = info
198
210
 
199
211
  function copy (cache, key, dest, opts = {}) {
200
212
  if (read.copy) {
201
213
  return index.find(cache, key, opts).then((entry) => {
202
- if (!entry)
214
+ if (!entry) {
203
215
  throw new index.NotFoundError(cache, key)
216
+ }
204
217
  return read.copy(cache, entry.integrity, dest, opts)
205
218
  .then(() => {
206
219
  return {
@@ -225,8 +238,9 @@ function copy (cache, key, dest, opts = {}) {
225
238
  module.exports.copy = copy
226
239
 
227
240
  function copyByDigest (cache, key, dest, opts = {}) {
228
- if (read.copy)
241
+ if (read.copy) {
229
242
  return read.copy(cache, key, dest, opts).then(() => key)
243
+ }
230
244
 
231
245
  return getDataByDigest(cache, key, opts).then((res) => {
232
246
  return writeFile(dest, res).then(() => key)
@@ -1,20 +1,19 @@
1
1
  'use strict'
2
2
 
3
- const ls = require('./ls.js')
4
3
  const get = require('./get.js')
5
4
  const put = require('./put.js')
6
5
  const rm = require('./rm.js')
7
6
  const verify = require('./verify.js')
8
- const { clearMemoized } = require('./lib/memoization.js')
9
- const tmp = require('./lib/util/tmp.js')
10
- const index = require('./lib/entry-index.js')
7
+ const { clearMemoized } = require('./memoization.js')
8
+ const tmp = require('./util/tmp.js')
9
+ const index = require('./entry-index.js')
11
10
 
12
11
  module.exports.index = {}
13
12
  module.exports.index.compact = index.compact
14
13
  module.exports.index.insert = index.insert
15
14
 
16
- module.exports.ls = ls
17
- module.exports.ls.stream = ls.stream
15
+ module.exports.ls = index.ls
16
+ module.exports.ls.stream = index.lsStream
18
17
 
19
18
  module.exports.get = get
20
19
  module.exports.get.byDigest = get.byDigest
@@ -2,13 +2,11 @@
2
2
 
3
3
  const LRU = require('lru-cache')
4
4
 
5
- const MAX_SIZE = 50 * 1024 * 1024 // 50MB
6
- const MAX_AGE = 3 * 60 * 1000
7
-
8
5
  const MEMOIZED = new LRU({
9
- max: MAX_SIZE,
10
- maxAge: MAX_AGE,
11
- length: (entry, key) => key.startsWith('key:') ? entry.data.length : entry.length,
6
+ max: 500,
7
+ maxSize: 50 * 1024 * 1024, // 50MB
8
+ ttl: 3 * 60 * 1000, // 3 minutes
9
+ sizeCalculation: (entry, key) => key.startsWith('key:') ? entry.data.length : entry.length,
12
10
  })
13
11
 
14
12
  module.exports.clearMemoized = clearMemoized
@@ -18,7 +16,7 @@ function clearMemoized () {
18
16
  MEMOIZED.forEach((v, k) => {
19
17
  old[k] = v
20
18
  })
21
- MEMOIZED.reset()
19
+ MEMOIZED.clear()
22
20
  return old
23
21
  }
24
22
 
@@ -62,12 +60,13 @@ class ObjProxy {
62
60
  }
63
61
 
64
62
  function pickMem (opts) {
65
- if (!opts || !opts.memoize)
63
+ if (!opts || !opts.memoize) {
66
64
  return MEMOIZED
67
- else if (opts.memoize.get && opts.memoize.set)
65
+ } else if (opts.memoize.get && opts.memoize.set) {
68
66
  return opts.memoize
69
- else if (typeof opts.memoize === 'object')
67
+ } else if (typeof opts.memoize === 'object') {
70
68
  return new ObjProxy(opts.memoize)
71
- else
69
+ } else {
72
70
  return MEMOIZED
71
+ }
73
72
  }
@@ -1,8 +1,8 @@
1
1
  'use strict'
2
2
 
3
- const index = require('./lib/entry-index')
4
- const memo = require('./lib/memoization')
5
- const write = require('./lib/content/write')
3
+ const index = require('./entry-index')
4
+ const memo = require('./memoization')
5
+ const write = require('./content/write')
6
6
  const Flush = require('minipass-flush')
7
7
  const { PassThrough } = require('minipass-collect')
8
8
  const Pipeline = require('minipass-pipeline')
@@ -21,8 +21,9 @@ function putData (cache, key, data, opts = {}) {
21
21
  return index
22
22
  .insert(cache, key, res.integrity, { ...opts, size: res.size })
23
23
  .then((entry) => {
24
- if (memoize)
24
+ if (memoize) {
25
25
  memo.put(cache, entry, data, opts)
26
+ }
26
27
 
27
28
  return res.integrity
28
29
  })
@@ -67,14 +68,17 @@ function putStream (cache, key, opts = {}) {
67
68
  return index
68
69
  .insert(cache, key, integrity, { ...opts, size })
69
70
  .then((entry) => {
70
- if (memoize && memoData)
71
+ if (memoize && memoData) {
71
72
  memo.put(cache, entry, memoData, opts)
73
+ }
72
74
 
73
- if (integrity)
75
+ if (integrity) {
74
76
  pipeline.emit('integrity', integrity)
77
+ }
75
78
 
76
- if (size)
79
+ if (size) {
77
80
  pipeline.emit('size', size)
81
+ }
78
82
  })
79
83
  },
80
84
  }))
@@ -2,11 +2,11 @@
2
2
 
3
3
  const util = require('util')
4
4
 
5
- const index = require('./lib/entry-index')
6
- const memo = require('./lib/memoization')
5
+ const index = require('./entry-index')
6
+ const memo = require('./memoization')
7
7
  const path = require('path')
8
8
  const rimraf = util.promisify(require('rimraf'))
9
- const rmContent = require('./lib/content/rm')
9
+ const rmContent = require('./content/rm')
10
10
 
11
11
  module.exports = entry
12
12
  module.exports.entry = entry
@@ -8,8 +8,9 @@ function disposer (creatorFn, disposerFn, fn) {
8
8
  .then(
9
9
  // disposer resolved, do something with original fn's promise
10
10
  () => {
11
- if (shouldThrow)
11
+ if (shouldThrow) {
12
12
  throw result
13
+ }
13
14
 
14
15
  return result
15
16
  },
@@ -49,8 +49,9 @@ function fixOwner (cache, filepath) {
49
49
  const { uid, gid } = owner
50
50
 
51
51
  // No need to override if it's already what we used.
52
- if (self.uid === uid && self.gid === gid)
52
+ if (self.uid === uid && self.gid === gid) {
53
53
  return
54
+ }
54
55
 
55
56
  return inflight('fixOwner: fixing ownership on ' + filepath, () =>
56
57
  chownr(
@@ -58,8 +59,9 @@ function fixOwner (cache, filepath) {
58
59
  typeof uid === 'number' ? uid : self.uid,
59
60
  typeof gid === 'number' ? gid : self.gid
60
61
  ).catch((err) => {
61
- if (err.code === 'ENOENT')
62
+ if (err.code === 'ENOENT') {
62
63
  return null
64
+ }
63
65
 
64
66
  throw err
65
67
  })
@@ -93,8 +95,9 @@ function fixOwnerSync (cache, filepath) {
93
95
  )
94
96
  } catch (err) {
95
97
  // only catch ENOENT, any other error is a problem.
96
- if (err.code === 'ENOENT')
98
+ if (err.code === 'ENOENT') {
97
99
  return null
100
+ }
98
101
 
99
102
  throw err
100
103
  }
@@ -110,12 +113,14 @@ function mkdirfix (cache, p, cb) {
110
113
  return Promise.resolve(inferOwner(cache)).then(() => {
111
114
  return mkdirp(p)
112
115
  .then((made) => {
113
- if (made)
116
+ if (made) {
114
117
  return fixOwner(cache, made).then(() => made)
118
+ }
115
119
  })
116
120
  .catch((err) => {
117
- if (err.code === 'EEXIST')
121
+ if (err.code === 'EEXIST') {
118
122
  return fixOwner(cache, p).then(() => null)
123
+ }
119
124
 
120
125
  throw err
121
126
  })
@@ -136,7 +141,8 @@ function mkdirfixSync (cache, p) {
136
141
  if (err.code === 'EEXIST') {
137
142
  fixOwnerSync(cache, p)
138
143
  return null
139
- } else
144
+ } else {
140
145
  throw err
146
+ }
141
147
  }
142
148
  }
@@ -38,10 +38,12 @@ function moveFile (src, dest) {
38
38
  } else if (err.code === 'EEXIST' || err.code === 'EBUSY') {
39
39
  // file already exists, so whatever
40
40
  return resolve()
41
- } else
41
+ } else {
42
42
  return reject(err)
43
- } else
43
+ }
44
+ } else {
44
45
  return resolve()
46
+ }
45
47
  })
46
48
  })
47
49
  .then(() => {
package/lib/verify.js CHANGED
@@ -54,8 +54,9 @@ function verify (cache, opts) {
54
54
  stats[k] = s[k]
55
55
  })
56
56
  const end = new Date()
57
- if (!stats.runTime)
57
+ if (!stats.runTime) {
58
58
  stats.runTime = {}
59
+ }
59
60
 
60
61
  stats.runTime[label] = end - start
61
62
  return Promise.resolve(stats)
@@ -108,8 +109,9 @@ function garbageCollect (cache, opts) {
108
109
  const indexStream = index.lsStream(cache)
109
110
  const liveContent = new Set()
110
111
  indexStream.on('data', (entry) => {
111
- if (opts.filter && !opts.filter(entry))
112
+ if (opts.filter && !opts.filter(entry)) {
112
113
  return
114
+ }
113
115
 
114
116
  liveContent.add(entry.integrity.toString())
115
117
  })
@@ -176,8 +178,9 @@ function verifyContent (filepath, sri) {
176
178
  return ssri
177
179
  .checkStream(new fsm.ReadStream(filepath), sri)
178
180
  .catch((err) => {
179
- if (err.code !== 'EINTEGRITY')
181
+ if (err.code !== 'EINTEGRITY') {
180
182
  throw err
183
+ }
181
184
 
182
185
  return rimraf(filepath).then(() => {
183
186
  contentInfo.valid = false
@@ -186,8 +189,9 @@ function verifyContent (filepath, sri) {
186
189
  .then(() => contentInfo)
187
190
  })
188
191
  .catch((err) => {
189
- if (err.code === 'ENOENT')
192
+ if (err.code === 'ENOENT') {
190
193
  return { size: 0, valid: false }
194
+ }
191
195
 
192
196
  throw err
193
197
  })
@@ -209,9 +213,9 @@ function rebuildIndex (cache, opts) {
209
213
  const entry = entries[k]
210
214
  const excluded = opts.filter && !opts.filter(entry)
211
215
  excluded && stats.rejectedEntries++
212
- if (buckets[hashed] && !excluded)
216
+ if (buckets[hashed] && !excluded) {
213
217
  buckets[hashed].push(entry)
214
- else if (buckets[hashed] && excluded) {
218
+ } else if (buckets[hashed] && excluded) {
215
219
  // skip
216
220
  } else if (excluded) {
217
221
  buckets[hashed] = []
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "cacache",
3
- "version": "15.3.0",
3
+ "version": "16.0.2",
4
4
  "cache-version": {
5
5
  "content": "2",
6
6
  "index": "5"
7
7
  },
8
8
  "description": "Fast, fault-tolerant, cross-platform, disk-based, data-agnostic, content-addressable cache.",
9
- "main": "index.js",
9
+ "main": "lib/index.js",
10
10
  "files": [
11
- "*.js",
11
+ "bin",
12
12
  "lib"
13
13
  ],
14
14
  "scripts": {
@@ -20,10 +20,13 @@
20
20
  "snap": "tap",
21
21
  "coverage": "tap",
22
22
  "test-docker": "docker run -it --rm --name pacotest -v \"$PWD\":/tmp -w /tmp node:latest npm test",
23
- "lint": "npm run npmclilint -- \"*.*js\" \"lib/**/*.*js\" \"test/**/*.*js\"",
23
+ "lint": "eslint '**/*.js'",
24
24
  "npmclilint": "npmcli-lint",
25
25
  "lintfix": "npm run lint -- --fix",
26
- "postsnap": "npm run lintfix --"
26
+ "postsnap": "npm run lintfix --",
27
+ "postlint": "npm-template-check",
28
+ "template-copy": "npm-template-copy --force",
29
+ "posttest": "npm run lint"
27
30
  },
28
31
  "repository": "https://github.com/npm/cacache",
29
32
  "keywords": [
@@ -44,28 +47,28 @@
44
47
  "license": "ISC",
45
48
  "dependencies": {
46
49
  "@npmcli/fs": "^1.0.0",
47
- "@npmcli/move-file": "^1.0.1",
50
+ "@npmcli/move-file": "^1.1.2",
48
51
  "chownr": "^2.0.0",
49
- "fs-minipass": "^2.0.0",
50
- "glob": "^7.1.4",
52
+ "fs-minipass": "^2.1.0",
53
+ "glob": "^7.2.0",
51
54
  "infer-owner": "^1.0.4",
52
- "lru-cache": "^6.0.0",
53
- "minipass": "^3.1.1",
55
+ "lru-cache": "^7.5.1",
56
+ "minipass": "^3.1.6",
54
57
  "minipass-collect": "^1.0.2",
55
58
  "minipass-flush": "^1.0.5",
56
- "minipass-pipeline": "^1.2.2",
57
- "mkdirp": "^1.0.3",
59
+ "minipass-pipeline": "^1.2.4",
60
+ "mkdirp": "^1.0.4",
58
61
  "p-map": "^4.0.0",
59
62
  "promise-inflight": "^1.0.1",
60
63
  "rimraf": "^3.0.2",
61
64
  "ssri": "^8.0.1",
62
- "tar": "^6.0.2",
65
+ "tar": "^6.1.11",
63
66
  "unique-filename": "^1.1.1"
64
67
  },
65
68
  "devDependencies": {
66
- "@npmcli/lint": "^1.0.1",
69
+ "@npmcli/template-oss": "^2.9.2",
67
70
  "benchmark": "^2.1.4",
68
- "chalk": "^4.0.0",
71
+ "chalk": "^4.1.2",
69
72
  "require-inject": "^1.4.4",
70
73
  "tacks": "^1.3.0",
71
74
  "tap": "^15.0.9"
@@ -75,6 +78,11 @@
75
78
  "test-regex": "test/[^/]*.js"
76
79
  },
77
80
  "engines": {
78
- "node": ">= 10"
79
- }
81
+ "node": "^12.13.0 || ^14.15.0 || >=16"
82
+ },
83
+ "templateOSS": {
84
+ "windowsCI": false,
85
+ "version": "2.9.2"
86
+ },
87
+ "author": "GitHub Inc."
80
88
  }
package/ls.js DELETED
@@ -1,6 +0,0 @@
1
- 'use strict'
2
-
3
- const index = require('./lib/entry-index')
4
-
5
- module.exports = index.ls
6
- module.exports.stream = index.lsStream
package/verify.js DELETED
@@ -1,3 +0,0 @@
1
- 'use strict'
2
-
3
- module.exports = require('./lib/verify')