pnpm 7.9.1 → 7.9.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.
- package/README.md +22 -7
- package/bin/pnpm.cjs +3 -0
- package/bin/pnpx.cjs +1 -15
- package/dist/node_modules/.modules.yaml +3 -3
- package/dist/node_modules/.pnpm/lock.yaml +76 -42
- package/dist/node_modules/@npmcli/fs/lib/common/owner-sync.js +96 -0
- package/dist/node_modules/@npmcli/fs/lib/common/owner.js +8 -4
- package/dist/node_modules/@npmcli/fs/lib/copy-file.js +3 -9
- package/dist/node_modules/@npmcli/fs/lib/fs.js +9 -3
- package/dist/node_modules/@npmcli/fs/lib/index.js +3 -1
- package/dist/node_modules/@npmcli/fs/lib/mkdir.js +19 -0
- package/dist/node_modules/@npmcli/fs/lib/mkdtemp.js +3 -8
- package/dist/node_modules/@npmcli/fs/lib/with-owner-sync.js +21 -0
- package/dist/node_modules/@npmcli/fs/lib/with-owner.js +21 -0
- package/dist/node_modules/@npmcli/fs/lib/with-temp-dir.js +4 -2
- package/dist/node_modules/@npmcli/fs/lib/write-file.js +3 -8
- package/dist/node_modules/@npmcli/fs/package.json +21 -9
- package/dist/node_modules/@npmcli/move-file/{index.js → lib/index.js} +50 -27
- package/dist/node_modules/@npmcli/move-file/package.json +20 -7
- package/dist/node_modules/@tootallnate/once/LICENSE +21 -0
- package/dist/node_modules/@tootallnate/once/dist/index.js +21 -36
- package/dist/node_modules/@tootallnate/once/dist/index.js.map +1 -1
- package/dist/node_modules/@tootallnate/once/dist/overloaded-parameters.js +3 -0
- package/dist/node_modules/@tootallnate/once/dist/overloaded-parameters.js.map +1 -0
- package/dist/node_modules/@tootallnate/once/dist/types.js +3 -0
- package/dist/node_modules/@tootallnate/once/dist/types.js.map +1 -0
- package/dist/node_modules/@tootallnate/once/package.json +22 -15
- package/dist/node_modules/cacache/lib/content/read.js +99 -102
- package/dist/node_modules/cacache/lib/content/rm.js +9 -8
- package/dist/node_modules/cacache/lib/content/write.js +67 -67
- package/dist/node_modules/cacache/lib/entry-index.js +128 -118
- package/dist/node_modules/cacache/{get.js → lib/get.js} +88 -100
- package/dist/node_modules/cacache/{index.js → lib/index.js} +5 -6
- package/dist/node_modules/cacache/lib/memoization.js +10 -11
- package/dist/node_modules/cacache/{put.js → lib/put.js} +23 -26
- package/dist/node_modules/cacache/{rm.js → lib/rm.js} +3 -3
- package/dist/node_modules/cacache/lib/util/fix-owner.js +41 -38
- package/dist/node_modules/cacache/lib/util/move-file.js +36 -47
- package/dist/node_modules/cacache/lib/util/tmp.js +5 -7
- package/dist/node_modules/cacache/lib/verify.js +160 -190
- package/dist/node_modules/cacache/node_modules/brace-expansion/.github/FUNDING.yml +2 -0
- package/dist/node_modules/cacache/node_modules/brace-expansion/LICENSE +21 -0
- package/dist/node_modules/cacache/node_modules/brace-expansion/index.js +203 -0
- package/dist/node_modules/cacache/node_modules/brace-expansion/package.json +46 -0
- package/dist/node_modules/cacache/node_modules/glob/LICENSE +15 -0
- package/dist/node_modules/cacache/node_modules/glob/common.js +240 -0
- package/dist/node_modules/cacache/node_modules/glob/glob.js +790 -0
- package/dist/node_modules/cacache/node_modules/glob/package.json +55 -0
- package/dist/node_modules/cacache/node_modules/glob/sync.js +486 -0
- package/dist/node_modules/cacache/node_modules/minimatch/LICENSE +15 -0
- package/dist/node_modules/cacache/node_modules/minimatch/lib/path.js +4 -0
- package/dist/node_modules/cacache/node_modules/minimatch/minimatch.js +906 -0
- package/dist/node_modules/cacache/node_modules/minimatch/package.json +32 -0
- package/dist/node_modules/cacache/package.json +34 -30
- package/dist/node_modules/http-proxy-agent/dist/agent.js +3 -3
- package/dist/node_modules/http-proxy-agent/dist/agent.js.map +1 -1
- package/dist/node_modules/http-proxy-agent/package.json +4 -4
- package/dist/node_modules/lru-cache/LICENSE +1 -1
- package/dist/node_modules/lru-cache/index.js +921 -247
- package/dist/node_modules/lru-cache/package.json +49 -9
- package/dist/node_modules/make-fetch-happen/LICENSE +1 -1
- package/dist/node_modules/make-fetch-happen/lib/agent.js +34 -14
- package/dist/node_modules/make-fetch-happen/lib/cache/entry.js +90 -106
- package/dist/node_modules/make-fetch-happen/lib/cache/errors.js +1 -0
- package/dist/node_modules/make-fetch-happen/lib/cache/index.js +10 -6
- package/dist/node_modules/make-fetch-happen/lib/cache/policy.js +21 -21
- package/dist/node_modules/make-fetch-happen/lib/dns.js +49 -0
- package/dist/node_modules/make-fetch-happen/lib/fetch.js +40 -22
- package/dist/node_modules/make-fetch-happen/lib/index.js +4 -3
- package/dist/node_modules/make-fetch-happen/lib/options.js +17 -9
- package/dist/node_modules/make-fetch-happen/lib/pipeline.js +41 -0
- package/dist/node_modules/make-fetch-happen/lib/remote.js +28 -9
- package/dist/node_modules/make-fetch-happen/package.json +36 -33
- package/dist/node_modules/minipass-fetch/lib/blob.js +4 -4
- package/dist/node_modules/minipass-fetch/lib/body.js +63 -49
- package/dist/node_modules/minipass-fetch/lib/fetch-error.js +2 -1
- package/dist/node_modules/minipass-fetch/lib/headers.js +38 -21
- package/dist/node_modules/minipass-fetch/lib/index.js +130 -106
- package/dist/node_modules/minipass-fetch/lib/request.js +46 -28
- package/dist/node_modules/minipass-fetch/lib/response.js +3 -2
- package/dist/node_modules/minipass-fetch/package.json +27 -14
- package/dist/node_modules/node-gyp/.github/workflows/release-please.yml +1 -1
- package/dist/node_modules/node-gyp/.github/workflows/tests.yml +16 -9
- package/dist/node_modules/node-gyp/.github/workflows/visual-studio.yml +16 -8
- package/dist/node_modules/node-gyp/lib/build.js +7 -0
- package/dist/node_modules/node-gyp/lib/configure.js +26 -1
- package/dist/node_modules/node-gyp/lib/create-config-gypi.js +2 -1
- package/dist/node_modules/node-gyp/lib/find-visualstudio.js +9 -8
- package/dist/node_modules/node-gyp/lib/node-gyp.js +4 -0
- package/dist/node_modules/node-gyp/package.json +4 -4
- package/dist/node_modules/semver/node_modules/lru-cache/LICENSE +15 -0
- package/dist/node_modules/semver/node_modules/lru-cache/index.js +334 -0
- package/dist/node_modules/semver/node_modules/lru-cache/package.json +34 -0
- package/dist/node_modules/socks-proxy-agent/dist/index.js +3 -3
- package/dist/node_modules/socks-proxy-agent/dist/index.js.map +1 -1
- package/dist/node_modules/socks-proxy-agent/package.json +2 -2
- package/dist/node_modules/ssri/{index.js → lib/index.js} +78 -24
- package/dist/node_modules/ssri/package.json +27 -16
- package/dist/pnpm.cjs +67042 -65886
- package/package.json +6 -6
- package/dist/node_modules/@npmcli/fs/lib/common/file-url-to-path/index.js +0 -17
- package/dist/node_modules/@npmcli/fs/lib/common/file-url-to-path/polyfill.js +0 -121
- package/dist/node_modules/@npmcli/fs/lib/mkdir/index.js +0 -32
- package/dist/node_modules/@npmcli/fs/lib/mkdir/polyfill.js +0 -81
- package/dist/node_modules/cacache/lib/util/disposer.js +0 -30
- package/dist/node_modules/cacache/ls.js +0 -6
- package/dist/node_modules/cacache/verify.js +0 -3
- package/dist/node_modules/minipass-fetch/index.js +0 -1
|
@@ -1,38 +1,35 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const fs = require('fs')
|
|
3
|
+
const fs = require('@npmcli/fs')
|
|
6
4
|
const fsm = require('fs-minipass')
|
|
7
5
|
const ssri = require('ssri')
|
|
8
6
|
const contentPath = require('./path')
|
|
9
7
|
const Pipeline = require('minipass-pipeline')
|
|
10
8
|
|
|
11
|
-
const lstat = util.promisify(fs.lstat)
|
|
12
|
-
const readFile = util.promisify(fs.readFile)
|
|
13
|
-
|
|
14
9
|
module.exports = read
|
|
15
10
|
|
|
16
11
|
const MAX_SINGLE_READ_SIZE = 64 * 1024 * 1024
|
|
17
|
-
function read (cache, integrity, opts = {}) {
|
|
12
|
+
async function read (cache, integrity, opts = {}) {
|
|
18
13
|
const { size } = opts
|
|
19
|
-
|
|
14
|
+
const { stat, cpath, sri } = await withContentSri(cache, integrity, async (cpath, sri) => {
|
|
20
15
|
// get size
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
const stat = await fs.stat(cpath)
|
|
17
|
+
return { stat, cpath, sri }
|
|
18
|
+
})
|
|
19
|
+
if (typeof size === 'number' && stat.size !== size) {
|
|
20
|
+
throw sizeError(size, stat.size)
|
|
21
|
+
}
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
if (stat.size > MAX_SINGLE_READ_SIZE) {
|
|
24
|
+
return readPipeline(cpath, stat.size, sri, new Pipeline()).concat()
|
|
25
|
+
}
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
const data = await fs.readFile(cpath, { encoding: null })
|
|
28
|
+
if (!ssri.checkData(data, sri)) {
|
|
29
|
+
throw integrityError(sri, cpath)
|
|
30
|
+
}
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
})
|
|
35
|
-
})
|
|
32
|
+
return data
|
|
36
33
|
}
|
|
37
34
|
|
|
38
35
|
const readPipeline = (cpath, size, sri, stream) => {
|
|
@@ -54,12 +51,14 @@ module.exports.sync = readSync
|
|
|
54
51
|
function readSync (cache, integrity, opts = {}) {
|
|
55
52
|
const { size } = opts
|
|
56
53
|
return withContentSriSync(cache, integrity, (cpath, sri) => {
|
|
57
|
-
const data = fs.readFileSync(cpath)
|
|
58
|
-
if (typeof size === 'number' && size !== data.length)
|
|
54
|
+
const data = fs.readFileSync(cpath, { encoding: null })
|
|
55
|
+
if (typeof size === 'number' && size !== data.length) {
|
|
59
56
|
throw sizeError(size, data.length)
|
|
57
|
+
}
|
|
60
58
|
|
|
61
|
-
if (ssri.checkData(data, sri))
|
|
59
|
+
if (ssri.checkData(data, sri)) {
|
|
62
60
|
return data
|
|
61
|
+
}
|
|
63
62
|
|
|
64
63
|
throw integrityError(sri, cpath)
|
|
65
64
|
})
|
|
@@ -71,29 +70,29 @@ module.exports.readStream = readStream
|
|
|
71
70
|
function readStream (cache, integrity, opts = {}) {
|
|
72
71
|
const { size } = opts
|
|
73
72
|
const stream = new Pipeline()
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
// Set all this up to run on the stream and then just return the stream
|
|
74
|
+
Promise.resolve().then(async () => {
|
|
75
|
+
const { stat, cpath, sri } = await withContentSri(cache, integrity, async (cpath, sri) => {
|
|
76
|
+
// just stat to ensure it exists
|
|
77
|
+
const stat = await fs.stat(cpath)
|
|
78
|
+
return { stat, cpath, sri }
|
|
79
|
+
})
|
|
80
|
+
if (typeof size === 'number' && size !== stat.size) {
|
|
79
81
|
return stream.emit('error', sizeError(size, stat.size))
|
|
82
|
+
}
|
|
80
83
|
|
|
81
|
-
readPipeline(cpath, stat.size, sri, stream)
|
|
82
|
-
}
|
|
84
|
+
return readPipeline(cpath, stat.size, sri, stream)
|
|
85
|
+
}).catch(err => stream.emit('error', err))
|
|
83
86
|
|
|
84
87
|
return stream
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
module.exports.copy = copy
|
|
90
|
-
module.exports.copy.sync = copySync
|
|
91
|
-
copyFile = util.promisify(fs.copyFile)
|
|
92
|
-
}
|
|
90
|
+
module.exports.copy = copy
|
|
91
|
+
module.exports.copy.sync = copySync
|
|
93
92
|
|
|
94
93
|
function copy (cache, integrity, dest) {
|
|
95
94
|
return withContentSri(cache, integrity, (cpath, sri) => {
|
|
96
|
-
return copyFile(cpath, dest)
|
|
95
|
+
return fs.copyFile(cpath, dest)
|
|
97
96
|
})
|
|
98
97
|
}
|
|
99
98
|
|
|
@@ -105,104 +104,101 @@ function copySync (cache, integrity, dest) {
|
|
|
105
104
|
|
|
106
105
|
module.exports.hasContent = hasContent
|
|
107
106
|
|
|
108
|
-
function hasContent (cache, integrity) {
|
|
109
|
-
if (!integrity)
|
|
110
|
-
return
|
|
107
|
+
async function hasContent (cache, integrity) {
|
|
108
|
+
if (!integrity) {
|
|
109
|
+
return false
|
|
110
|
+
}
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
return
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
try {
|
|
113
|
+
return await withContentSri(cache, integrity, async (cpath, sri) => {
|
|
114
|
+
const stat = await fs.stat(cpath)
|
|
115
|
+
return { size: stat.size, sri, stat }
|
|
116
|
+
})
|
|
117
|
+
} catch (err) {
|
|
118
|
+
if (err.code === 'ENOENT') {
|
|
116
119
|
return false
|
|
120
|
+
}
|
|
117
121
|
|
|
118
122
|
if (err.code === 'EPERM') {
|
|
119
123
|
/* istanbul ignore else */
|
|
120
|
-
if (process.platform !== 'win32')
|
|
124
|
+
if (process.platform !== 'win32') {
|
|
121
125
|
throw err
|
|
122
|
-
else
|
|
126
|
+
} else {
|
|
123
127
|
return false
|
|
128
|
+
}
|
|
124
129
|
}
|
|
125
|
-
}
|
|
130
|
+
}
|
|
126
131
|
}
|
|
127
132
|
|
|
128
133
|
module.exports.hasContent.sync = hasContentSync
|
|
129
134
|
|
|
130
135
|
function hasContentSync (cache, integrity) {
|
|
131
|
-
if (!integrity)
|
|
136
|
+
if (!integrity) {
|
|
132
137
|
return false
|
|
138
|
+
}
|
|
133
139
|
|
|
134
140
|
return withContentSriSync(cache, integrity, (cpath, sri) => {
|
|
135
141
|
try {
|
|
136
|
-
const stat = fs.
|
|
142
|
+
const stat = fs.statSync(cpath)
|
|
137
143
|
return { size: stat.size, sri, stat }
|
|
138
144
|
} catch (err) {
|
|
139
|
-
if (err.code === 'ENOENT')
|
|
145
|
+
if (err.code === 'ENOENT') {
|
|
140
146
|
return false
|
|
147
|
+
}
|
|
141
148
|
|
|
142
149
|
if (err.code === 'EPERM') {
|
|
143
150
|
/* istanbul ignore else */
|
|
144
|
-
if (process.platform !== 'win32')
|
|
151
|
+
if (process.platform !== 'win32') {
|
|
145
152
|
throw err
|
|
146
|
-
else
|
|
153
|
+
} else {
|
|
147
154
|
return false
|
|
155
|
+
}
|
|
148
156
|
}
|
|
149
157
|
}
|
|
150
158
|
})
|
|
151
159
|
}
|
|
152
160
|
|
|
153
|
-
function withContentSri (cache, integrity, fn) {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (result)
|
|
184
|
-
return result
|
|
185
|
-
|
|
186
|
-
// Throw the No matching content found error
|
|
187
|
-
const enoentError = results.find((r) => r.code === 'ENOENT')
|
|
188
|
-
if (enoentError)
|
|
189
|
-
throw enoentError
|
|
190
|
-
|
|
191
|
-
// Throw generic error
|
|
192
|
-
throw results.find((r) => r instanceof Error)
|
|
193
|
-
})
|
|
161
|
+
async function withContentSri (cache, integrity, fn) {
|
|
162
|
+
const sri = ssri.parse(integrity)
|
|
163
|
+
// If `integrity` has multiple entries, pick the first digest
|
|
164
|
+
// with available local data.
|
|
165
|
+
const algo = sri.pickAlgorithm()
|
|
166
|
+
const digests = sri[algo]
|
|
167
|
+
|
|
168
|
+
if (digests.length <= 1) {
|
|
169
|
+
const cpath = contentPath(cache, digests[0])
|
|
170
|
+
return fn(cpath, digests[0])
|
|
171
|
+
} else {
|
|
172
|
+
// Can't use race here because a generic error can happen before
|
|
173
|
+
// a ENOENT error, and can happen before a valid result
|
|
174
|
+
const results = await Promise.all(digests.map(async (meta) => {
|
|
175
|
+
try {
|
|
176
|
+
return await withContentSri(cache, meta, fn)
|
|
177
|
+
} catch (err) {
|
|
178
|
+
if (err.code === 'ENOENT') {
|
|
179
|
+
return Object.assign(
|
|
180
|
+
new Error('No matching content found for ' + sri.toString()),
|
|
181
|
+
{ code: 'ENOENT' }
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
return err
|
|
185
|
+
}
|
|
186
|
+
}))
|
|
187
|
+
// Return the first non error if it is found
|
|
188
|
+
const result = results.find((r) => !(r instanceof Error))
|
|
189
|
+
if (result) {
|
|
190
|
+
return result
|
|
194
191
|
}
|
|
195
|
-
}
|
|
196
192
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
.catch(reject)
|
|
202
|
-
} catch (err) {
|
|
203
|
-
reject(err)
|
|
193
|
+
// Throw the No matching content found error
|
|
194
|
+
const enoentError = results.find((r) => r.code === 'ENOENT')
|
|
195
|
+
if (enoentError) {
|
|
196
|
+
throw enoentError
|
|
204
197
|
}
|
|
205
|
-
|
|
198
|
+
|
|
199
|
+
// Throw generic error
|
|
200
|
+
throw results.find((r) => r instanceof Error)
|
|
201
|
+
}
|
|
206
202
|
}
|
|
207
203
|
|
|
208
204
|
function withContentSriSync (cache, integrity, fn) {
|
|
@@ -228,6 +224,7 @@ function withContentSriSync (cache, integrity, fn) {
|
|
|
228
224
|
}
|
|
229
225
|
|
|
230
226
|
function sizeError (expected, found) {
|
|
227
|
+
/* eslint-disable-next-line max-len */
|
|
231
228
|
const err = new Error(`Bad data size: expected inserted data to be ${expected} bytes, but got ${found} instead`)
|
|
232
229
|
err.expected = expected
|
|
233
230
|
err.found = found
|
|
@@ -8,12 +8,13 @@ const rimraf = util.promisify(require('rimraf'))
|
|
|
8
8
|
|
|
9
9
|
module.exports = rm
|
|
10
10
|
|
|
11
|
-
function rm (cache, integrity) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
async function rm (cache, integrity) {
|
|
12
|
+
const content = await hasContent(cache, integrity)
|
|
13
|
+
// ~pretty~ sure we can't end up with a content lacking sri, but be safe
|
|
14
|
+
if (content && content.sri) {
|
|
15
|
+
await rimraf(contentPath(cache, content.sri))
|
|
16
|
+
return true
|
|
17
|
+
} else {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
19
20
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const events = require('events')
|
|
3
4
|
const util = require('util')
|
|
4
5
|
|
|
5
6
|
const contentPath = require('./path')
|
|
6
7
|
const fixOwner = require('../util/fix-owner')
|
|
7
|
-
const fs = require('fs')
|
|
8
|
+
const fs = require('@npmcli/fs')
|
|
8
9
|
const moveFile = require('../util/move-file')
|
|
9
10
|
const Minipass = require('minipass')
|
|
10
11
|
const Pipeline = require('minipass-pipeline')
|
|
@@ -13,31 +14,35 @@ const path = require('path')
|
|
|
13
14
|
const rimraf = util.promisify(require('rimraf'))
|
|
14
15
|
const ssri = require('ssri')
|
|
15
16
|
const uniqueFilename = require('unique-filename')
|
|
16
|
-
const { disposer } = require('./../util/disposer')
|
|
17
17
|
const fsm = require('fs-minipass')
|
|
18
18
|
|
|
19
|
-
const writeFile = util.promisify(fs.writeFile)
|
|
20
|
-
|
|
21
19
|
module.exports = write
|
|
22
20
|
|
|
23
|
-
function write (cache, data, opts = {}) {
|
|
21
|
+
async function write (cache, data, opts = {}) {
|
|
24
22
|
const { algorithms, size, integrity } = opts
|
|
25
|
-
if (algorithms && algorithms.length > 1)
|
|
23
|
+
if (algorithms && algorithms.length > 1) {
|
|
26
24
|
throw new Error('opts.algorithms only supports a single algorithm for now')
|
|
25
|
+
}
|
|
27
26
|
|
|
28
|
-
if (typeof size === 'number' && data.length !== size)
|
|
29
|
-
|
|
27
|
+
if (typeof size === 'number' && data.length !== size) {
|
|
28
|
+
throw sizeError(size, data.length)
|
|
29
|
+
}
|
|
30
30
|
|
|
31
31
|
const sri = ssri.fromData(data, algorithms ? { algorithms } : {})
|
|
32
|
-
if (integrity && !ssri.checkData(data, integrity, opts))
|
|
33
|
-
|
|
32
|
+
if (integrity && !ssri.checkData(data, integrity, opts)) {
|
|
33
|
+
throw checksumError(integrity, sri)
|
|
34
|
+
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
36
|
+
const tmp = await makeTmp(cache, opts)
|
|
37
|
+
try {
|
|
38
|
+
await fs.writeFile(tmp.target, data, { flag: 'wx' })
|
|
39
|
+
await moveToDestination(tmp, cache, sri, opts)
|
|
40
|
+
return { integrity: sri, size: data.length }
|
|
41
|
+
} finally {
|
|
42
|
+
if (!tmp.moved) {
|
|
43
|
+
await rimraf(tmp.target)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
module.exports.stream = writeStream
|
|
@@ -75,9 +80,11 @@ class CacacheWriteStream extends Flush {
|
|
|
75
80
|
// defer this one tick by rejecting a promise on it.
|
|
76
81
|
return Promise.reject(e).catch(cb)
|
|
77
82
|
}
|
|
83
|
+
// eslint-disable-next-line promise/catch-or-return
|
|
78
84
|
this.handleContentP.then(
|
|
79
85
|
(res) => {
|
|
80
86
|
res.integrity && this.emit('integrity', res.integrity)
|
|
87
|
+
// eslint-disable-next-line promise/always-return
|
|
81
88
|
res.size !== null && this.emit('size', res.size)
|
|
82
89
|
cb()
|
|
83
90
|
},
|
|
@@ -91,21 +98,39 @@ function writeStream (cache, opts = {}) {
|
|
|
91
98
|
return new CacacheWriteStream(cache, opts)
|
|
92
99
|
}
|
|
93
100
|
|
|
94
|
-
function handleContent (inputStream, cache, opts) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
101
|
+
async function handleContent (inputStream, cache, opts) {
|
|
102
|
+
const tmp = await makeTmp(cache, opts)
|
|
103
|
+
try {
|
|
104
|
+
const res = await pipeToTmp(inputStream, cache, tmp.target, opts)
|
|
105
|
+
await moveToDestination(
|
|
106
|
+
tmp,
|
|
107
|
+
cache,
|
|
108
|
+
res.integrity,
|
|
109
|
+
opts
|
|
110
|
+
)
|
|
111
|
+
return res
|
|
112
|
+
} finally {
|
|
113
|
+
if (!tmp.moved) {
|
|
114
|
+
await rimraf(tmp.target)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
106
117
|
}
|
|
107
118
|
|
|
108
|
-
function pipeToTmp (inputStream, cache, tmpTarget, opts) {
|
|
119
|
+
async function pipeToTmp (inputStream, cache, tmpTarget, opts) {
|
|
120
|
+
const outStream = new fsm.WriteStream(tmpTarget, {
|
|
121
|
+
flags: 'wx',
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
if (opts.integrityEmitter) {
|
|
125
|
+
// we need to create these all simultaneously since they can fire in any order
|
|
126
|
+
const [integrity, size] = await Promise.all([
|
|
127
|
+
events.once(opts.integrityEmitter, 'integrity').then(res => res[0]),
|
|
128
|
+
events.once(opts.integrityEmitter, 'size').then(res => res[0]),
|
|
129
|
+
new Pipeline(inputStream, outStream).promise(),
|
|
130
|
+
])
|
|
131
|
+
return { integrity, size }
|
|
132
|
+
}
|
|
133
|
+
|
|
109
134
|
let integrity
|
|
110
135
|
let size
|
|
111
136
|
const hashStream = ssri.integrityStream({
|
|
@@ -120,57 +145,32 @@ function pipeToTmp (inputStream, cache, tmpTarget, opts) {
|
|
|
120
145
|
size = s
|
|
121
146
|
})
|
|
122
147
|
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// NB: this can throw if the hashStream has a problem with
|
|
128
|
-
// it, and the data is fully written. but pipeToTmp is only
|
|
129
|
-
// called in promisory contexts where that is handled.
|
|
130
|
-
const pipeline = new Pipeline(
|
|
131
|
-
inputStream,
|
|
132
|
-
hashStream,
|
|
133
|
-
outStream
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
return pipeline.promise()
|
|
137
|
-
.then(() => ({ integrity, size }))
|
|
138
|
-
.catch(er => rimraf(tmpTarget).then(() => {
|
|
139
|
-
throw er
|
|
140
|
-
}))
|
|
148
|
+
const pipeline = new Pipeline(inputStream, hashStream, outStream)
|
|
149
|
+
await pipeline.promise()
|
|
150
|
+
return { integrity, size }
|
|
141
151
|
}
|
|
142
152
|
|
|
143
|
-
function makeTmp (cache, opts) {
|
|
153
|
+
async function makeTmp (cache, opts) {
|
|
144
154
|
const tmpTarget = uniqueFilename(path.join(cache, 'tmp'), opts.tmpPrefix)
|
|
145
|
-
|
|
155
|
+
await fixOwner.mkdirfix(cache, path.dirname(tmpTarget))
|
|
156
|
+
return {
|
|
146
157
|
target: tmpTarget,
|
|
147
158
|
moved: false,
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function makeTmpDisposer (tmp) {
|
|
152
|
-
if (tmp.moved)
|
|
153
|
-
return Promise.resolve()
|
|
154
|
-
|
|
155
|
-
return rimraf(tmp.target)
|
|
159
|
+
}
|
|
156
160
|
}
|
|
157
161
|
|
|
158
|
-
function moveToDestination (tmp, cache, sri, opts) {
|
|
162
|
+
async function moveToDestination (tmp, cache, sri, opts) {
|
|
159
163
|
const destination = contentPath(cache, sri)
|
|
160
164
|
const destDir = path.dirname(destination)
|
|
161
165
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
})
|
|
167
|
-
.then(() => {
|
|
168
|
-
tmp.moved = true
|
|
169
|
-
return fixOwner.chownr(cache, destination)
|
|
170
|
-
})
|
|
166
|
+
await fixOwner.mkdirfix(cache, destDir)
|
|
167
|
+
await moveFile(tmp.target, destination)
|
|
168
|
+
tmp.moved = true
|
|
169
|
+
await fixOwner.chownr(cache, destination)
|
|
171
170
|
}
|
|
172
171
|
|
|
173
172
|
function sizeError (expected, found) {
|
|
173
|
+
/* eslint-disable-next-line max-len */
|
|
174
174
|
const err = new Error(`Bad data size: expected inserted data to be ${expected} bytes, but got ${found} instead`)
|
|
175
175
|
err.expected = expected
|
|
176
176
|
err.found = found
|