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

Commit aa629b4

Browse files
committedFeb 26, 2020
fix: remove figgy-pudding
1 parent a0fdf7e commit aa629b4

File tree

5 files changed

+119
-45
lines changed

5 files changed

+119
-45
lines changed
 

‎index.js

+20-30
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
'use strict'
22

33
const fetch = require('npm-registry-fetch')
4-
const figgyPudding = require('figgy-pudding')
5-
const getStream = require('get-stream')
64
const validate = require('aproba')
75

8-
const HooksConfig = figgyPudding({
9-
package: {},
10-
limit: {},
11-
offset: {},
12-
Promise: {default: () => Promise}
13-
})
14-
156
const eu = encodeURIComponent
167
const cmd = module.exports = {}
17-
cmd.add = (name, endpoint, secret, opts) => {
18-
opts = HooksConfig(opts)
8+
cmd.add = (name, endpoint, secret, opts = {}) => {
199
validate('SSSO', [name, endpoint, secret, opts])
2010
let type = 'package'
2111
if (name.match(/^@[^/]+$/)) {
@@ -25,18 +15,19 @@ cmd.add = (name, endpoint, secret, opts) => {
2515
type = 'owner'
2616
name = name.substr(1)
2717
}
28-
return fetch.json('/-/npm/v1/hooks/hook', opts.concat({
18+
return fetch.json('/-/npm/v1/hooks/hook', {
19+
...opts,
2920
method: 'POST',
3021
body: { type, name, endpoint, secret }
31-
}))
22+
})
3223
}
3324

34-
cmd.rm = (id, opts) => {
35-
opts = HooksConfig(opts)
25+
cmd.rm = (id, opts = {}) => {
3626
validate('SO', [id, opts])
37-
return fetch.json(`/-/npm/v1/hooks/hook/${eu(id)}`, opts.concat({
27+
return fetch.json(`/-/npm/v1/hooks/hook/${eu(id)}`, {
28+
...opts,
3829
method: 'DELETE'
39-
}, opts)).catch(err => {
30+
}).catch(err => {
4031
if (err.code === 'E404') {
4132
return null
4233
} else {
@@ -45,36 +36,35 @@ cmd.rm = (id, opts) => {
4536
})
4637
}
4738

48-
cmd.update = (id, endpoint, secret, opts) => {
49-
opts = HooksConfig(opts)
39+
cmd.update = (id, endpoint, secret, opts = {}) => {
5040
validate('SSSO', [id, endpoint, secret, opts])
51-
return fetch.json(`/-/npm/v1/hooks/hook/${eu(id)}`, opts.concat({
41+
return fetch.json(`/-/npm/v1/hooks/hook/${eu(id)}`, {
42+
...opts,
5243
method: 'PUT',
5344
body: {endpoint, secret}
54-
}, opts))
45+
})
5546
}
5647

57-
cmd.find = (id, opts) => {
58-
opts = HooksConfig(opts)
48+
cmd.find = (id, opts = {}) => {
5949
validate('SO', [id, opts])
6050
return fetch.json(`/-/npm/v1/hooks/hook/${eu(id)}`, opts)
6151
}
6252

63-
cmd.ls = (opts) => {
64-
return getStream.array(cmd.ls.stream(opts))
53+
cmd.ls = (opts = {}) => {
54+
return cmd.ls.stream(opts).collect()
6555
}
6656

67-
cmd.ls.stream = (opts) => {
68-
opts = HooksConfig(opts)
69-
const {package: pkg, limit, offset} = opts
57+
cmd.ls.stream = (opts = {}) => {
58+
const { package: pkg, limit, offset } = opts
7059
validate('S|Z', [pkg])
7160
validate('N|Z', [limit])
7261
validate('N|Z', [offset])
73-
return fetch.json.stream('/-/npm/v1/hooks', 'objects.*', opts.concat({
62+
return fetch.json.stream('/-/npm/v1/hooks', 'objects.*', {
63+
...opts,
7464
query: {
7565
package: pkg,
7666
limit,
7767
offset
7868
}
79-
}))
69+
})
8070
}

‎package-lock.json

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

‎package.json

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"license": "ISC",
2828
"dependencies": {
2929
"aproba": "^2.0.0",
30-
"figgy-pudding": "^3.4.1",
3130
"get-stream": "^4.0.0",
3231
"npm-registry-fetch": "^3.8.0"
3332
},
File renamed without changes.

‎test/index.js

+88-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
'use strict'
22

3-
const figgyPudding = require('figgy-pudding')
3+
// const figgyPudding = require('figgy-pudding')
44
const test = require('tap').test
5-
const tnock = require('./util/tnock.js')
5+
const tnock = require('./fixtures/tnock.js')
66

77
const hooks = require('../index.js')
88

9-
const OPTS = figgyPudding({registry: {}})({
9+
const OPTS = {
1010
registry: 'https://mock.reg/'
11-
})
11+
}
12+
1213
const HOOK_URL = 'https://my.hook.url/'
14+
const REG = 'https://registry.npmjs.org/'
15+
16+
test('add package hook with no options', t => {
17+
const params = {
18+
type: 'package',
19+
name: 'mypkg',
20+
endpoint: HOOK_URL,
21+
secret: 'sekrit'
22+
}
23+
const hook = Object.assign({
24+
id: 'deadbeef',
25+
status: 'active'
26+
}, params)
27+
tnock(t, REG)
28+
.post('/-/npm/v1/hooks/hook', params)
29+
.reply(200, hook)
30+
return hooks.add('mypkg', HOOK_URL, 'sekrit')
31+
.then(json => t.deepEqual(json, hook))
32+
})
1333

1434
test('add package hook', t => {
1535
const params = {
@@ -83,6 +103,14 @@ test('add scope hook', t => {
83103
.then(json => t.deepEqual(json, hook))
84104
})
85105

106+
test('rm with no options', t => {
107+
tnock(t, REG)
108+
.delete('/-/npm/v1/hooks/hook/hithere')
109+
.reply(200, {id: 'hithere'})
110+
return hooks.rm('hithere')
111+
.then(json => t.equal(json.id, 'hithere'))
112+
})
113+
86114
test('rm', t => {
87115
tnock(t, OPTS.registry)
88116
.delete('/-/npm/v1/hooks/hook/hithere')
@@ -109,6 +137,14 @@ test('rm null on other err', t => {
109137
)
110138
})
111139

140+
test('find with no options', t => {
141+
tnock(t, REG)
142+
.get('/-/npm/v1/hooks/hook/hithere')
143+
.reply(200, {id: 'hithere'})
144+
return hooks.find('hithere')
145+
.then(json => t.equal(json.id, 'hithere'))
146+
})
147+
112148
test('find', t => {
113149
tnock(t, OPTS.registry)
114150
.get('/-/npm/v1/hooks/hook/hithere')
@@ -117,6 +153,35 @@ test('find', t => {
117153
.then(json => t.equal(json.id, 'hithere'))
118154
})
119155

156+
test('ls', t => {
157+
const entries = [
158+
{id: 'first'},
159+
{id: 'second'},
160+
{id: 'third'}
161+
]
162+
tnock(t, REG)
163+
.get('/-/npm/v1/hooks')
164+
.reply(200, {objects: entries})
165+
return hooks.ls().then(
166+
json => t.deepEqual(json, entries)
167+
)
168+
})
169+
170+
test('ls.stream', t => {
171+
const entries = [
172+
{id: 'first'},
173+
{id: 'second'},
174+
{id: 'third'}
175+
]
176+
tnock(t, REG)
177+
.get('/-/npm/v1/hooks')
178+
.reply(200, {objects: entries})
179+
180+
return hooks.ls.stream().collect().then(
181+
json => t.deepEqual(json, entries)
182+
)
183+
})
184+
120185
test('ls', t => {
121186
const entries = [
122187
{id: 'first'},
@@ -140,9 +205,10 @@ test('ls package', t => {
140205
tnock(t, OPTS.registry)
141206
.get('/-/npm/v1/hooks?package=%40npm%2Fhooks')
142207
.reply(200, {objects: entries})
143-
return hooks.ls(OPTS.concat({
208+
return hooks.ls({
209+
...OPTS,
144210
package: '@npm/hooks'
145-
})).then(json => t.deepEqual(json, entries))
211+
}).then(json => t.deepEqual(json, entries))
146212
})
147213

148214
test('ls limit+offset', t => {
@@ -154,10 +220,11 @@ test('ls limit+offset', t => {
154220
tnock(t, OPTS.registry)
155221
.get('/-/npm/v1/hooks?limit=10&offset=20')
156222
.reply(200, {objects: entries})
157-
return hooks.ls(OPTS.concat({
223+
return hooks.ls({
224+
...OPTS,
158225
limit: 10,
159226
offset: 20
160-
})).then(json => t.deepEqual(json, entries))
227+
}).then(json => t.deepEqual(json, entries))
161228
})
162229

163230
test('ls package+limit+offset', t => {
@@ -169,11 +236,22 @@ test('ls package+limit+offset', t => {
169236
tnock(t, OPTS.registry)
170237
.get('/-/npm/v1/hooks?package=%40npm%2Fhooks&limit=10&offset=20')
171238
.reply(200, {objects: entries})
172-
return hooks.ls(OPTS.concat({
239+
return hooks.ls({
240+
...OPTS,
173241
limit: 10,
174242
offset: 20,
175243
package: '@npm/hooks'
176-
})).then(json => t.deepEqual(json, entries))
244+
}).then(json => t.deepEqual(json, entries))
245+
})
246+
test('update with no options', t => {
247+
tnock(t, REG)
248+
.put('/-/npm/v1/hooks/hook/hi')
249+
.reply(200, (uri, body) => body)
250+
return hooks.update('hi', HOOK_URL, 'sekrit')
251+
.then(json => t.deepEqual(json, {
252+
endpoint: HOOK_URL,
253+
secret: 'sekrit'
254+
}))
177255
})
178256

179257
test('update', t => {

0 commit comments

Comments
 (0)
This repository has been archived.