-
Notifications
You must be signed in to change notification settings - Fork 995
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
refactor: use process.stdout.columns instead of dep #737
Conversation
8ebaf67
to
d5326d0
Compare
@@ -397,8 +397,11 @@ module.exports = function (yargs, y18n) { | |||
|
|||
// guess the width of the console window, max-width 80. | |||
function windowWidth () { | |||
const wsize = require('window-size') | |||
return wsize.width ? Math.min(80, wsize.width) : null | |||
if (process && process.stdout && process.stdout.columns && Math.min(80, process.stdout.colums)) { |
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 last term in this conjunction seems a bit odd? (Also: typeof process === 'object'
is probably the better first check here, at least if there’s a chance this file will ever switch to strict mode?)
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.
I agree, this should probably look something more like this:
if (typeof process === 'object' && process.stdout && process.stdout.columns) {
return Math.min(80, process.stdout.colums)
} else {
return 80
}
I think it's probably more correct to explicitly return 80
than null, this might be a historical bug.
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.
Huh, not sure what I was thinking there. What I am wondering now though, why is the output's width limited to 80 columns like that? Since Math.min()
always returns the tiniest value of the given parameters, it can only return numbers in the range of <=80
like that.
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'll need to figure out how to test this new logic to keep coverage at 100%
.
You might be able to do something like mock process.stdout.columns
in a test for Travis.
@bcoe Yeah, was just about to push something similar. I approve! |
this is a great example of where packages like edit: @maxrimue can you clarify where the "resource intensiveness" was so we can look into in window-size? Clearly that's not good if something is buggy, I'd like to get it figured out. |
@jonschlinkert I don't right now have the actual data at hand, sorry. However, I can tell you that the resource intensity was relative, The main reason for me to do this PR however is that |
Your code won't work on Windows 10 or newer, and it will fail if not a TTY. Not sure if those count as drawbacks.
Great idea. Reminds me of |
Got any references for that? Is that a Node bug?
Maybe I’m being naïve, but how does the concept of a window size apply to non-TTYs? |
This pr was in fact created on my Windows 10 machine, for me it does work |
jonschlinkert/window-size#6. When this pr was made, I verified that there was a bug. As I recall there was a regression in node 7.1.0 on windows, perhaps that was the culprit. Any thoughts @addaleax? (but shouldn't this question have been asked of @maxrimue)?
No, you're right. I meant "is" Which circles us back around to my initial point. We use yargs and yargs-parser in something like 15-25 libs. I've seen issues and edge cases on window-size and during research I've done per those discussions. Because of that, these changes seem naive to me. But if this is indeed all that's needed in window-size, it would have been awesome to have that discussion so that we could improve window-size for all users. That's all, nothing more. I don't care about the dependency. @maxrimue, @addaleax are you saying there is zero chance of issues/edge cases with these code changes? If so, I'll be a happy camper. |
Yeah, there’s something in the back of my head about that too. Anything related to that should be fixed by now, though.
Huh, I didn’t know that thing existed (also, Node 0.6 was a long time ago…). in any case, yargs’
At the very least one difference to |
@jonschlinkert I'm a big advocate of the tiny module approach to software development. I've been trying to hit a balance with yargs where we outsource appropriate components, while being mindful of complaints I've been seeing over the past few months along performance and dependency count related lines: https://twitter.com/guillaumeQD/status/807917750425440256 When @maxrimue began advocating this change, I was hesitant because I knew that @jonschlinkert I apologize for not looping you into this conversation at the outset, this was an oversight. I'd like to better understand what edge-cases we're dropping on the floor by excluding this dependency; this brings up a couple interesting options:
|
Good grief lol. What's funny is that I wrote the correct thing, @bcoe no need to apologize, I really appreciate the detail. To be clear, I'm much more interested in just having a solution that consistently works (and won't create issues and regressions), I'm not at all concerned with window-size being a dependency. I'm a big fan of just making the right decision for your code base, and I'm sorry that feel you had to apologize to me about that. That's my fault for how I approached the issue. Circling back to my initial concerns, I think this was unusual for me in the sense that I just happened to be working on window-size this past week, and when I saw the changes here, the only thing that went through my mind was, "really? Is that all we need to be doing on window-size now?" and if so I feel like a jackass for overcomplicating the code so much - especially now in light of my "rounding error". still, admittedly I don't have as much time to stay current on changes in node.js these days, and I can't help but think based on window-size issues and past research that there are edge cases lurking. But... that doesn't mean there will be edge cases or issues for yargs that way that it's being used here. I remember it being somewhat of a pain to research when I first created it. But that was a while ago, and a lot has changed. This is basically where my mind was: I'd love to simplify the code for everyone using window-size if we're confident that there won't be edge cases where the other fallbacks are needed (namely |
I was able to remove the dependency
window-size
and instead useprocess.stdout.columns
which effectively does the same thing but seems to be much less resource hungry.