-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
os: refactor structure of the os module #12654
Conversation
What is the reason for the |
// No parens at the end
`${os.endianess}` instead of `${os.endianness()}` Likewise with the other functions that always return primitives. It's extremely minor and quite cheap for us to support. Another, example... `${os.platform}-${os.release}-${os.arch}-${os.hostname}` Instead of `${os.platform()}-${os.release()}-${os.arch()}-${os.hostname()}` |
test/parallel/test-os.js
Outdated
/* eslint-disable no-restricted-properties */ | ||
[ | ||
|
||
[assert.equal, `${os.freemem}`, os.freemem()], |
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.
Nit: Maybe better as
assert.strictEqual, `${os.freemem}`, `${os.freemem()}`]
Matter of style preference, I suppose.
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.
This was intentional, recognizing that the differences in the values should still be equal.
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.
This was intentional, recognizing that the differences in the values should still be equal.
You might be misunderstanding my suggestion. I know it's intentional. Explicitly converting the number to a string and using strictEqual()
makes it more clear that it's intentional, at least in my opinion. OK by me, though, if you prefer the way it 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.
Sorry, I know what you meant, just wasn't being very clear. I'm using assert.equal()
intentionally because the return value of the methods themselves are numbers and I want to ensure that the conversion to string after the Symbol.toPrimitive
call returns an equal (but not strict equal) result. Either way I think gets the job done but to answer the question: yes, I prefer it this way :-)
Oops, I rebased while the CI was checking things out and goofed it up. |
Once more with gusto: https://ci.nodejs.org/job/node-test-pull-request/7718/ |
CI is green |
ping @nodejs/collaborators |
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.
Looks similar to #12717. LGTM.
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.
LGTM
Is it really semver-minor? Even though I don't think someone really used these functions in template literals as values themselves (as it doesn't make much sense), strictly speaking, the behavior has changed. Before: > `${os.endianness}`
'function () { return \'LE\'; }' After: > `${os.endianness}`
'LE' It might be better to make this a major change just to be safe and strictly adhering to semver, especially given the fact that v8.0 is coming soon. It might be also worth to split this into two commits (just refactoring and However, a huge +1 to the change itself, about a week ago I really wished these functions were getters when I used them in template literals, while this PR solves it even more elegantly :) |
CITGM for this PR: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/751/ |
I'm good with defensively labeling this as semver-major. |
test/parallel/test-os.js
Outdated
[assert.strictEqual, `${os.type}`, os.type()], | ||
[assert.strictEqual, `${os.endianness}`, os.endianness()] | ||
].forEach((set) => { | ||
set[0](set[1], set[2], `${set[1]}, ${set[2]}`); |
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’m not actually sure whether the extra error message argument here is helpful, and maybe I would just inline assert.strictEqual
here instead of passing it as part of set
. (Just a suggestion, feel free to ignore me if you disagree)
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.
Now that they're all strictEquals.. +1 :-)
Refactor the structure of the os module to use more efficient module.exports = {} pattern. Add Symbol.toPrimitive support to os methods that return simple primitives. This is a minor tweak that makes using these slightly more friendly when doing things like: ```js var m = `${os.tmpdir}/foo` ```
Refactor the structure of the os module to use more efficient module.exports = {} pattern. Add Symbol.toPrimitive support to os methods that return simple primitives. This is a minor tweak that makes using these slightly more friendly when doing things like: ```js var m = `${os.tmpdir}/foo` ``` PR-URL: #12654 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
PR-URL: #12654 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Landed in 473572e and 23fc082 |
Refactor the structure of the os module to use more efficient module.exports = {} pattern. Add Symbol.toPrimitive support to os methods that return simple primitives. This is a minor tweak that makes using these slightly more friendly when doing things like: ```js var m = `${os.tmpdir}/foo` ``` PR-URL: nodejs#12654 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
PR-URL: nodejs#12654 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
As far as I can tell, adding I'm bringing this up because I don't know how to possibly word this as a breaking change for the 8.0.0 breaking changes doc. Reading function bodies in any real, dependant way is already not supported. (Obviously. This is like Adding the symbol does not alter any existing behavior of the actual documented functions, in any way (including The behavior before, for coercion to "primitive", is effectively a common "misuse" error that under normal circumstances would be akin to any of our This either: adds behavior that was "missing", or "fixes" previously "broken" behavior. @jasnell, @addaleax, @aqrln Thoughts? Would I be ok to remove the label? (We can add |
I think so, yes. I don’t think this kind of change makes sense for LTS, so I’m adding the dont-land labels. |
@Fishrock123 yes, I'm fine with it. Thanks for bringing this up. |
In this particular case, dropping down to |
Refactoring the structure of the os module to use the more efficient
module.exports = {}
pattern.Also adds simple
Symbol.toPrimitive
support for each of the os methods that return simple primitives.Lastly, removes extraneous console output from the test-os.js
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
os