-
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
Conversation
}) | ||
process.emit('input', 'read', resolve, reject, ...args) | ||
return promise | ||
}, |
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.
The reason I opted for two different ways to do input
is in some specialized producers (eg libnpmexec
) we will want to use input.read
which will give us more control and also be a breaking change.
In more generic consumers we can just wrap the current code in input.start()
and input.end()
. Our consumer will be able to listen and respond to these events, but all others can ignore these events so it won't be a breaking change.
t.match(args.slice(0, 2), [Function, Function], 'input gets resolvers') | ||
t.same(args.slice(2), [1, 'two', [3], { 4: 4 }], 'got expected args') | ||
break | ||
default: |
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.
What about log.pause and log.resume? We've only ever documented that those take no args themselves. Should we make that a reality?
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.
Yeah that seems like a good idea now that we have separate functions for each method.
|
||
**consumer.js** | ||
```js | ||
const { read } = require('read') |
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
Maybe I'll see it when I review again tomorrow but I don't understand the function of |
This question applies to log.pause/unpause and input.start/end. Whose concern should it be if multiple starts/pauses are called and then multiple unpause/ends? How is a consumer to know when ALL interested parties have indicated that logs should unpause or input has truly ended? Obviously if two asynchronous operations are trying to do input they'll inevitably collide with each other so perhaps that's not a concern to solve. This is thinking out loud at this point. |
It is only there to avoid having to manually type strings in consumers. Here's a diff of what you would replace if + const { output } = require('proc-log')
process.on('output', (level, ...args) => {
switch (level) {
- case 'standard':
+ case output.KEYS.standard:
console.log(args)
break
- case 'error'
+ case output.KEYS.error:
console.error(args)
break
}
}) |
You still have to know and type the indices to |
This is why I opted for
|
No, you thought about this more than I did already. This is find as-is. |
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.
If you want to tweak log.pause and log.resume you still can, but I didn't want to block on that.
My remaining 3 comments (readline, log.pause, KEYS) are just those: comments. None of them are blockers but you can act on them if you choose. |
ee6bc93
to
2669f5a
Compare
@wraithgar Pushed a commit removing args from |
🤖 I have created a release *beep* *boop* --- ## [4.1.0](v4.0.0...v4.1.0) (2024-04-15) ### Features * [`e00086e`](e00086e) [#80](#80) add timers and read (@lukekarrys) ### Bug Fixes * [`4832b21`](4832b21) [#80](#80) remove args from log pause/resume (@lukekarrys) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This adds top-level
time
andinput
namespaces.time
is used to facilitate starting/ending timers including the ability to pass in a sync or async callback which will be timed. This is a pattern we already used innpm/cli
and can be replaced with this code fromproc-log
instead.input
is used to send events indicating user input is being read. There are two ways to do this:start
andend
functions or aread
function which will return a promise and emit the promise's resolvers to the consumer.This also adds a
KEYS
to each namespace which is an enum for getting the levels by name. Innpm/cli
our consumer creates these withlog.LEVELS.reduce((a, k) => (a[k] = k, a), {})
so that we don't need to type any string names in our handelrs.