-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
add execa.stdout()
shortcut
#14
Conversation
444623c
to
98fc977
Compare
The one advantage to the first, is that |
Sure, I guess I could add that, but the important question is; Do you think this is a valid addition? |
Regardless of the parens, I actually don't think one way is more clearer than the other. The first example is how I would expect it to work, the latter one would just be a nice shortcut. I could live without it. |
I don't think it's that helpful, but I haven't written a lot of tests using it. |
Alternatively change the test(async t => {
t.is(await execa('./cli.js').stdout, 'foo');
}); |
I think Mark's idea is the best so far. |
Note: it needs to be implemented as a getter that defers creation of additional promises so you don't end up with unhandled rejections. |
Why is it better?
What if you want both |
Subjective, I like the trailing
both: const {stdout, stderr} = await execa('./cli'); Just one: const stdout = await execa('./cli').stdout; Or maybe just leave it as is: const {stdout} = await execa('./cli'); |
How can |
It can't - it would always be a promise. |
@jamestalmage But, then your example wouldn't work: const {stdout} = await execa('./cli');
|
Both would work - the await is evaluated before the assignment: const {stdout} = await execa('./cli');
// =>
const {stdout} = await Promise.resolve({stdout:string, stderr: string});
// =>
const {stdout} = {stdout: string, stderr: string};
// =>
const stdout = string and const stdout = await exec('./cli').stdout;
// =>
const stdout = await Promise.resolve(string);
// =>
const stdout = string; |
Implements an alternative to sindresorhus#14.
See jamestalmage@70629c6#diff-1dd241c4cd3fd1dd89c570cee98b79ddR115 It can definitely work both ways. Still, not sure it's the best idea |
98fc977
to
b812baf
Compare
So if we're going with this it would be |
One potential advantage: #18 (comment) Ignoring the stream you don't care about improves memory efficiency. |
Another argument for adding this. When returning the result of return execa('bin').then(result => result.stdout); This would be nicer: return execa.stdout('bin'); |
b812baf
to
1f25008
Compare
@jamestalmage Ready for review. |
@@ -123,6 +123,20 @@ module.exports = function (cmd, args, opts) { | |||
return spawned; | |||
}; | |||
|
|||
module.exports.stdout = function () { | |||
// TODO: set `stderr: 'ignore'` when that option is implemented |
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.
Deferring this until #24 is done.
Thanks for the great feedback :) |
Not sure about this one. The thinking is that stdout is the most common use-case so might be nice to have a shortcut for it. This is not about the amount of characters, as that's mostly the same, but rather clarity.
Example:
You can see how the second one is more readable because of less parens.
@kevva @SamVerschueren @jamestalmage @novemberborn Could use your opion 🙌