1
0
Fork 0
mirror of https://github.com/actions/setup-node synced 2024-11-10 07:32:40 +00:00
setup-node/node_modules/before-after-hook/lib/register.js

29 lines
691 B
JavaScript
Raw Normal View History

module.exports = register
function register (state, name, method, options) {
if (typeof method !== 'function') {
throw new Error('method for before hook must be a function')
}
if (!options) {
options = {}
}
if (Array.isArray(name)) {
return name.reverse().reduce(function (callback, name) {
return register.bind(null, state, name, callback, options)
}, method)()
}
return Promise.resolve()
.then(function () {
if (!state.registry[name]) {
return method(options)
}
return (state.registry[name]).reduce(function (method, registered) {
return registered.hook.bind(null, method, options)
}, method)()
})
}