1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/lib/promisify.js
Tim Neutkens f2c2519159
Move build directory outside of server folder (#4565)
The prepares for next-server.

I also took this as an opportunity to get all build directory paths from a single location, as they were previously scattered across webpack/babel plugins and loaders.
2018-06-14 19:30:14 +02:00

27 lines
870 B
JavaScript

const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs')
module.exports = function promisify (original) {
// Names to create an object from in case the callback receives multiple
// arguments, e.g. ['stdout', 'stderr'] for child_process.exec.
const argumentNames = original[kCustomPromisifyArgsSymbol]
return function fn (...args) {
return new Promise((resolve, reject) => {
try {
original.call(this, ...args, (err, ...values) => {
if (err) {
reject(err)
} else if (argumentNames !== undefined && values.length > 1) {
const obj = {}
for (var i = 0; i < argumentNames.length; i++) { obj[argumentNames[i]] = values[i] }
resolve(obj)
} else {
resolve(values[0])
}
})
} catch (err) {
reject(err)
}
})
}
}