-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add time
and input
#80
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,11 @@ module.exports = { | |
'error', | ||
'buffer', | ||
], | ||
KEYS: { | ||
standard: 'standard', | ||
error: 'error', | ||
buffer: 'buffer', | ||
}, | ||
standard: function (...args) { | ||
return process.emit('output', 'standard', ...args) | ||
}, | ||
|
@@ -28,6 +33,18 @@ module.exports = { | |
'pause', | ||
'resume', | ||
], | ||
KEYS: { | ||
notice: 'notice', | ||
error: 'error', | ||
warn: 'warn', | ||
info: 'info', | ||
verbose: 'verbose', | ||
http: 'http', | ||
silly: 'silly', | ||
timing: 'timing', | ||
pause: 'pause', | ||
resume: 'resume', | ||
}, | ||
error: function (...args) { | ||
return process.emit('log', 'error', ...args) | ||
}, | ||
|
@@ -52,11 +69,78 @@ module.exports = { | |
timing: function (...args) { | ||
return process.emit('log', 'timing', ...args) | ||
}, | ||
pause: function (...args) { | ||
return process.emit('log', 'pause', ...args) | ||
pause: function () { | ||
return process.emit('log', 'pause') | ||
}, | ||
resume: function () { | ||
return process.emit('log', 'resume') | ||
}, | ||
}, | ||
time: { | ||
LEVELS: [ | ||
'start', | ||
'end', | ||
], | ||
KEYS: { | ||
start: 'start', | ||
end: 'end', | ||
}, | ||
start: function (name, fn) { | ||
process.emit('time', 'start', name) | ||
wraithgar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
function end () { | ||
return process.emit('time', 'end', name) | ||
} | ||
if (typeof fn === 'function') { | ||
const res = fn() | ||
if (res && res.finally) { | ||
return res.finally(end) | ||
} | ||
end() | ||
return res | ||
} | ||
return end | ||
}, | ||
end: function (name) { | ||
return process.emit('time', 'end', name) | ||
}, | ||
}, | ||
input: { | ||
LEVELS: [ | ||
'start', | ||
'end', | ||
'read', | ||
], | ||
KEYS: { | ||
start: 'start', | ||
end: 'end', | ||
read: 'read', | ||
}, | ||
start: function (fn) { | ||
process.emit('input', 'start') | ||
function end () { | ||
wraithgar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return process.emit('input', 'end') | ||
} | ||
if (typeof fn === 'function') { | ||
const res = fn() | ||
if (res && res.finally) { | ||
return res.finally(end) | ||
} | ||
end() | ||
return res | ||
} | ||
return end | ||
}, | ||
end: function () { | ||
return process.emit('input', 'end') | ||
}, | ||
resume: function (...args) { | ||
return process.emit('log', 'resume', ...args) | ||
read: function (...args) { | ||
let resolve, reject | ||
const promise = new Promise((_resolve, _reject) => { | ||
resolve = _resolve | ||
reject = _reject | ||
}) | ||
process.emit('input', 'read', resolve, reject, ...args) | ||
return promise | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I opted for two different ways to do In more generic consumers we can just wrap the current code in |
||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using
node:readline
in npm itself: https://github.com/npm/cli/blob/latest/lib/utils/open-url-prompt.js