Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

Commit 6ad0662

Browse files
Michael Perrottemikemimik
Michael Perrotte
authored andcommittedMar 2, 2020
feat: replace get-stream with minipass
1 parent df54f9c commit 6ad0662

File tree

4 files changed

+76
-444
lines changed

4 files changed

+76
-444
lines changed
 

‎index.js

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use strict'
22

3-
const getStream = require('get-stream')
3+
const Minipass = require('minipass')
44
const npa = require('npm-package-arg')
55
const npmFetch = require('npm-registry-fetch')
6-
const { PassThrough } = require('stream')
76
const validate = require('aproba')
87

98
const eu = encodeURIComponent
@@ -81,15 +80,17 @@ cmd.revoke = (spec, entity, opts) => {
8180

8281
cmd.lsPackages = (entity, opts) => {
8382
return pwrap(opts, () => {
84-
return getStream.array(
85-
cmd.lsPackages.stream(entity, opts)
86-
).then(data => data.reduce((acc, [key, val]) => {
87-
if (!acc) {
88-
acc = {}
89-
}
90-
acc[key] = val
91-
return acc
92-
}, null))
83+
return cmd.lsPackages.stream(entity, opts)
84+
.collect()
85+
.then(data => {
86+
return data.reduce((acc, [key, val]) => {
87+
if (!acc) {
88+
acc = {}
89+
}
90+
acc[key] = val
91+
return acc
92+
}, null)
93+
})
9394
})
9495
}
9596

@@ -104,7 +105,7 @@ cmd.lsPackages.stream = (entity, opts) => {
104105
}
105106
opts.query = { format: 'cli' }
106107
opts.mapJSON = mapJSON
107-
const ret = new PassThrough({ objectMode: true })
108+
const ret = new Minipass({ objectMode: true })
108109
npmFetch.json.stream(uri, '*', opts).on('error', err => {
109110
if (err.code === 'E404' && !team) {
110111
uri = `/-/user/${eu(scope)}/package`
@@ -124,15 +125,17 @@ cmd.lsCollaborators = (spec, user, opts) => {
124125
user = undefined
125126
}
126127
return pwrap(opts, () => {
127-
return getStream.array(
128-
cmd.lsCollaborators.stream(spec, user, opts)
129-
).then(data => data.reduce((acc, [key, val]) => {
130-
if (!acc) {
131-
acc = {}
132-
}
133-
acc[key] = val
134-
return acc
135-
}, null))
128+
return cmd.lsCollaborators.stream(spec, user, opts)
129+
.collect()
130+
.then(data => {
131+
return data.reduce((acc, [key, val]) => {
132+
if (!acc) {
133+
acc = {}
134+
}
135+
acc[key] = val
136+
return acc
137+
}, null)
138+
})
136139
})
137140
}
138141

‎package-lock.json

+41-411
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"homepage": "https://npmjs.com/package/libnpmaccess",
2626
"dependencies": {
2727
"aproba": "^2.0.0",
28-
"get-stream": "^4.0.0",
28+
"minipass": "^3.1.1",
2929
"npm-package-arg": "^8.0.0",
3030
"npm-registry-fetch": "^4.0.0"
3131
},

‎test/index.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
const getStream = require('get-stream')
43
const { test } = require('tap')
54
const tnock = require('./util/tnock.js')
65

@@ -227,11 +226,11 @@ test('ls-packages stream', t => {
227226
tnock(t, REG).get(
228227
'/-/team/myorg/myteam/package?format=cli'
229228
).reply(200, serverPackages)
230-
return getStream.array(
231-
access.lsPackages.stream('myorg:myteam', OPTS)
232-
).then(data => {
233-
t.deepEqual(data, clientPackages, 'got streamed client package info')
234-
})
229+
return access.lsPackages.stream('myorg:myteam', OPTS)
230+
.collect()
231+
.then(data => {
232+
t.deepEqual(data, clientPackages, 'got streamed client package info')
233+
})
235234
})
236235

237236
test('ls-collaborators', t => {
@@ -267,11 +266,11 @@ test('ls-collaborators stream', t => {
267266
tnock(t, REG).get(
268267
'/-/package/%40foo%2Fbar/collaborators?format=cli'
269268
).reply(200, serverCollaborators)
270-
return getStream.array(
271-
access.lsCollaborators.stream('@foo/bar', OPTS)
272-
).then(data => {
273-
t.deepEqual(data, clientCollaborators, 'got collaborators')
274-
})
269+
return access.lsCollaborators.stream('@foo/bar', OPTS)
270+
.collect()
271+
.then(data => {
272+
t.deepEqual(data, clientCollaborators, 'got collaborators')
273+
})
275274
})
276275

277276
test('ls-collaborators w/scope', t => {

0 commit comments

Comments
 (0)
This repository has been archived.