cacache 21.0.0 → 21.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.
@@ -10,6 +10,7 @@ const Pipeline = require('minipass-pipeline')
10
10
  const Flush = require('minipass-flush')
11
11
  const path = require('path')
12
12
  const ssri = require('ssri')
13
+ const cacheDir = require('../util/cache-dir')
13
14
  const { tmpName } = require('../util/tmp')
14
15
  const fsm = require('fs-minipass')
15
16
 
@@ -153,6 +154,7 @@ async function pipeToTmp (inputStream, cache, tmpTarget, opts) {
153
154
 
154
155
  async function makeTmp (cache, opts) {
155
156
  const tmpTarget = tmpName(cache, opts.tmpPrefix)
157
+ await cacheDir.mkdir(cache)
156
158
  await fs.mkdir(path.dirname(tmpTarget), { recursive: true })
157
159
  return {
158
160
  target: tmpTarget,
@@ -13,6 +13,7 @@ const { Minipass } = require('minipass')
13
13
  const path = require('path')
14
14
  const ssri = require('ssri')
15
15
  const { tmpName } = require('./util/tmp')
16
+ const cacheDir = require('./util/cache-dir')
16
17
 
17
18
  const contentPath = require('./content/path')
18
19
  const hashToSegments = require('./util/hash-to-segments')
@@ -70,6 +71,7 @@ async function compact (cache, key, matchFn, opts = {}) {
70
71
 
71
72
  const setup = async () => {
72
73
  const target = tmpName(cache, opts.tmpPrefix)
74
+ await cacheDir.mkdir(cache)
73
75
  await mkdir(path.dirname(target), { recursive: true })
74
76
  return {
75
77
  target,
@@ -121,6 +123,7 @@ async function insert (cache, key, integrity, opts = {}) {
121
123
  metadata,
122
124
  }
123
125
  try {
126
+ await cacheDir.mkdir(cache)
124
127
  await mkdir(path.dirname(bucket), { recursive: true })
125
128
  const stringified = JSON.stringify(entry)
126
129
  // NOTE - Cleverness ahoy!
package/lib/rm.js CHANGED
@@ -27,5 +27,6 @@ module.exports.all = all
27
27
  async function all (cache) {
28
28
  memo.clearMemoized()
29
29
  const paths = await glob(path.join(cache, '*(content-*|index-*)'), { silent: true, nosort: true })
30
+ paths.push(path.join(cache, 'CACHEDIR.TAG'))
30
31
  return Promise.all(paths.map((p) => rm(p, { recursive: true, force: true })))
31
32
  }
@@ -0,0 +1,29 @@
1
+ 'use strict'
2
+
3
+ const fs = require('fs/promises')
4
+ const path = require('path')
5
+
6
+ const tagContent = `Signature: 8a477f597d28d172789f06886806bc55
7
+ # This file is a cache directory tag created by cacache.
8
+ # For information about cache directory tags, see https://bford.info/cachedir/
9
+ `
10
+
11
+ async function mkdir (cache) {
12
+ await fs.mkdir(cache, { recursive: true, owner: 'inherit' })
13
+ await writeTag(cache)
14
+ }
15
+
16
+ async function writeTag (cache) {
17
+ try {
18
+ await fs.writeFile(path.join(cache, 'CACHEDIR.TAG'), tagContent, { flag: 'wx' })
19
+ } catch (err) {
20
+ if (err.code !== 'EEXIST') {
21
+ throw err
22
+ }
23
+ }
24
+ }
25
+
26
+ module.exports = {
27
+ mkdir,
28
+ tagContent,
29
+ }
package/lib/util/tmp.js CHANGED
@@ -4,6 +4,7 @@ const crypto = require('crypto')
4
4
  const { withTempDir } = require('@npmcli/fs')
5
5
  const fs = require('fs/promises')
6
6
  const path = require('path')
7
+ const cacheDir = require('./cache-dir')
7
8
 
8
9
  module.exports.mkdir = mktmpdir
9
10
 
@@ -15,6 +16,7 @@ module.exports.tmpName = function tmpName (cache, tmpPrefix) {
15
16
  async function mktmpdir (cache, opts = {}) {
16
17
  const { tmpPrefix } = opts
17
18
  const tmpDir = path.join(cache, 'tmp')
19
+ await cacheDir.mkdir(cache)
18
20
  await fs.mkdir(tmpDir, { recursive: true, owner: 'inherit' })
19
21
  // do not use path.join(), it drops the trailing / if tmpPrefix is unset
20
22
  const target = `${tmpDir}${path.sep}${tmpPrefix || ''}`
@@ -28,5 +30,7 @@ function withTmp (cache, opts, cb) {
28
30
  cb = opts
29
31
  opts = {}
30
32
  }
31
- return withTempDir(path.join(cache, 'tmp'), cb, opts)
33
+ return cacheDir.mkdir(cache).then(() =>
34
+ withTempDir(path.join(cache, 'tmp'), cb, opts)
35
+ )
32
36
  }
package/lib/verify.js CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict'
2
2
 
3
3
  const {
4
- mkdir,
5
4
  readFile,
6
5
  rm,
7
6
  stat,
@@ -12,6 +11,7 @@ const contentPath = require('./content/path')
12
11
  const fsm = require('fs-minipass')
13
12
  const glob = require('./util/glob.js')
14
13
  const index = require('./entry-index')
14
+ const cacheDir = require('./util/cache-dir')
15
15
  const path = require('path')
16
16
  const ssri = require('ssri')
17
17
 
@@ -77,7 +77,7 @@ async function markEndTime () {
77
77
 
78
78
  async function fixPerms (cache, opts) {
79
79
  opts.log.silly('verify', 'fixing cache permissions')
80
- await mkdir(cache, { recursive: true })
80
+ await cacheDir.mkdir(cache)
81
81
  return null
82
82
  }
83
83
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cacache",
3
- "version": "21.0.0",
3
+ "version": "21.0.2",
4
4
  "cache-version": {
5
5
  "content": "2",
6
6
  "index": "5"
@@ -48,7 +48,7 @@
48
48
  "dependencies": {
49
49
  "@npmcli/fs": "^6.0.0",
50
50
  "fs-minipass": "^3.0.0",
51
- "glob": "^13.0.0",
51
+ "glob": "^14.0.3",
52
52
  "lru-cache": "^11.1.0",
53
53
  "minipass": "^7.0.3",
54
54
  "minipass-collect": "^2.0.1",
@@ -58,8 +58,8 @@
58
58
  "ssri": "^14.0.0"
59
59
  },
60
60
  "devDependencies": {
61
- "@npmcli/eslint-config": "^6.0.1",
62
- "@npmcli/template-oss": "5.1.0",
61
+ "@npmcli/eslint-config": "^7.0.0",
62
+ "@npmcli/template-oss": "5.1.1",
63
63
  "tap": "^16.0.0"
64
64
  },
65
65
  "engines": {
@@ -68,7 +68,7 @@
68
68
  "templateOSS": {
69
69
  "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
70
70
  "windowsCI": false,
71
- "version": "5.1.0",
71
+ "version": "5.1.1",
72
72
  "publish": "true"
73
73
  },
74
74
  "author": "GitHub Inc.",