-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
[partial work] path: improve parse => format combination #12511
Conversation
|
Adding semver-major since this is a breaking API change. I'm +1 on the actual change. Also pinging @nodejs/collaborators since this is an API change in case anyone has anything to add. |
4dcae43
to
e2cc4e7
Compare
|
multi-platform test: https://ci.nodejs.org/job/node-test-pull-request/7517/ |
Well, |
@refack those don't-land-on are just to indicate that it's a backwards incompatible change so it should not be ported to older versions. It's a given given If you feel strongly about this not being semver-major I'm open to discussion, but I find it hard to justify a minor version breaking existing code - this is not just people relying on undocumented behavior, this is an API change in an API marked as |
Yeah, Obv. I just had a convoluted thought...
I don't feel strongly, just a little clarifying discussion to help me understand the common assumptions:
|
P.S. If we're talking breaking changes, how about me adding a |
lib/path.js
Outdated
configurable: false, | ||
get() { return this.name + this.ext; }, | ||
set(value) { | ||
if (value.startsWith('.') || !value.includes('.')) { |
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.
Why do we need both of these? Can't we combine both using one call to value.indexOf()
?:
var dotIdx = value.indexOf('.');
if (dotIdx <= 0) {
// ...
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.
actually this is wrong, in Windows .test.exe
is considered and exe
file
lib/path.js
Outdated
configurable: false, | ||
get() { return this.name + this.ext; }, | ||
set(value) { | ||
if (value.startsWith('.') || !value.includes('.')) { |
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.
Ditto
Also, be sure that the |
e2cc4e7
to
f760d1b
Compare
Ohh, found the real API change (it was in When providing properties to the `pathObject` remember that there are
combinations where one property has priority over another:
* `pathObject.root` is ignored if `pathObject.dir` is provided
* `pathObject.ext` and `pathObject.name` are ignored if `pathObject.base` exists
... |
No wait, I'm confused 😵 the above described behavior still stands, and this test passes: const output = path.parse(element);
assert.strictEqual(typeof output.root, 'string');
assert.strictEqual(typeof output.dir, 'string');
assert.strictEqual(typeof output.base, 'string');
assert.strictEqual(typeof output.ext, 'string');
assert.strictEqual(typeof output.name, 'string');
assert.strictEqual(path.format(output), element); |
No new deopts. |
There should also be a similar getter/setter for |
lib/path.js
Outdated
const li = value.lastIndexOf('.'); | ||
if (li > 0) { | ||
this.ext = value.slice(li); | ||
this.name = value.split(0, li); |
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.
isn't this supposed to be slice
?
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.
obv. 🤦
Need to writes tests, and finish this PR.
f760d1b
to
3e5c7d0
Compare
@@ -1136,6 +1129,22 @@ const win32 = { | |||
else if (isAbsolute) | |||
ret.dir = path.slice(0, rootEnd); | |||
|
|||
Object.defineProperty(ret, 'base', { |
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.
Same code repeated. Can this be refactored to be a function?
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.
prbly, I look into it, but this file is full of dup code 😵
4754c8b
to
57272db
Compare
make `parse` return an object where `base` is a computed property Ref: nodejs#1999
57272db
to
f5d22a2
Compare
Ping @refack |
Closing due to long inactivity and no response. @refack please feel free to reopen if you would like to pursue this further. |
make
path.parse
return an object wherebase
is a computed propertyRef: #1999
TODO:
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
path