Skip to content

Commit 1c7552e

Browse files
committed
feat: convert all internal functions to async/await
BREAKING CHANGE: All internal functions have been coverted to return promises and no longer accept callbacks. This is not a breaking change for users but may be breaking to consumers of `node-gyp` if you are requiring internal functions directly.
1 parent 1b3bd34 commit 1c7552e

23 files changed

Lines changed: 1245 additions & 1061 deletions

bin/node-gyp.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ if (dir) {
6868
}
6969
}
7070

71-
function run () {
71+
async function run () {
7272
const command = prog.todo.shift()
7373
if (!command) {
7474
// done!
@@ -77,30 +77,28 @@ function run () {
7777
return
7878
}
7979

80-
prog.commands[command.name](command.args, function (err) {
81-
if (err) {
82-
log.error(command.name + ' error')
83-
log.error('stack', err.stack)
84-
errorMessage()
85-
log.error('not ok')
86-
return process.exit(1)
87-
}
80+
try {
81+
const args = await prog.commands[command.name](command.args) ?? []
82+
8883
if (command.name === 'list') {
89-
const versions = arguments[1]
90-
if (versions.length > 0) {
91-
versions.forEach(function (version) {
92-
console.log(version)
93-
})
84+
if (args.length) {
85+
args.forEach((version) => console.log(version))
9486
} else {
9587
console.log('No node development files installed. Use `node-gyp install` to install a version.')
9688
}
97-
} else if (arguments.length >= 2) {
98-
console.log.apply(console, [].slice.call(arguments, 1))
89+
} else if (args.length >= 1) {
90+
console.log(...args.slice(1))
9991
}
10092

10193
// now run the next command in the queue
102-
process.nextTick(run)
103-
})
94+
return run()
95+
} catch (err) {
96+
log.error(command.name + ' error')
97+
log.error('stack', err.stack)
98+
errorMessage()
99+
log.error('not ok')
100+
return process.exit(1)
101+
}
104102
}
105103

106104
process.on('exit', function (code) {

0 commit comments

Comments
 (0)