Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

refack
Copy link
Contributor

@refack refack commented Apr 19, 2017

make path.parse return an object where base is a computed property

Ref: #1999

TODO:

  • Add test
  • Update doc with new capabilities
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

path

@nodejs-github-bot nodejs-github-bot added the path Issues and PRs related to the path subsystem. label Apr 19, 2017
@refack
Copy link
Contributor Author

refack commented Apr 19, 2017

multi-platform test: https://ci.nodejs.org/job/node-test-pull-request/7515/

@refack refack added the wip Issues and PRs that are still a work in progress. label Apr 19, 2017
@benjamingr
Copy link
Member

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.

@benjamingr benjamingr added semver-major PRs that contain breaking changes and should be released in the next major version. dont-land-on-v4.x labels Apr 19, 2017
@refack refack force-pushed the improve-path-parse-1999 branch from 4dcae43 to e2cc4e7 Compare April 19, 2017 13:35
@refack
Copy link
Contributor Author

refack commented Apr 19, 2017

I want to ask is it semver-major? the api change is that base moved from being a value property into a computed property?
(I lean semver-minor, if all tests pass, but no strong opinion)

on Second tought, it changes (probably undocumented) behaviour, so semver-major indeed.
As for the don't land that could be debated.

@refack
Copy link
Contributor Author

refack commented Apr 19, 2017

multi-platform test: https://ci.nodejs.org/job/node-test-pull-request/7517/

@jasnell
Copy link
Member

jasnell commented Apr 19, 2017

Well, semver-major automatically implies don't land on any of the current or LTS releases so there's no much to debate ;-)

@benjamingr
Copy link
Member

@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 semver-major.

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 Stability: 2 - Stable.

@refack
Copy link
Contributor Author

refack commented Apr 19, 2017

Well, semver-major automatically implies don't land on any of the current or LTS releases so there's no much to debate ;-)

Yeah, Obv. I just had a convoluted thought...

@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 semver-major.

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 Stability: 2 - Stable.

I don't feel strongly, just a little clarifying discussion to help me understand the common assumptions:

  1. I totally agree that changing stable API is semver-major (to the point of being ridiculous assert.fail() accept a single argument or two arguments  #12293 (comment))
  2. Question: only thing changed is the "mechanics" of a property in the returned value in https://nodejs.org/api/path.html#path_path_parse_path. Is that even considered a change?
  3. If all tests pass with no tests changes made by me, (like the proverbial tree in the woods) did anything change 🕴️ ?
    image

@refack refack requested a review from joyeecheung April 19, 2017 15:25
@refack
Copy link
Contributor Author

refack commented Apr 19, 2017

P.S. If we're talking breaking changes, how about me adding a .format() method to the returned type?
Also finding a way to make it compatible with url.format() so we get a file://.... output?

lib/path.js Outdated
configurable: false,
get() { return this.name + this.ext; },
set(value) {
if (value.startsWith('.') || !value.includes('.')) {
Copy link
Contributor

@mscdex mscdex Apr 19, 2017

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) {
  // ...

Copy link
Contributor Author

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('.')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@mscdex
Copy link
Contributor

mscdex commented Apr 19, 2017

Also, be sure that the const or other changes do not cause any permanent deopts. You can use either #12456 or do it manually (e.g. after compiling: ./node --trace-opt --always-opt --trace-file-names test/parallel/test-path-parse-format.js | grep -i 'aborted\|disabled').

@refack refack force-pushed the improve-path-parse-1999 branch from e2cc4e7 to f760d1b Compare April 19, 2017 17:46
@refack
Copy link
Contributor Author

refack commented Apr 19, 2017

Ohh, found the real API change (it was in path.format 🤦)

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
...

@refack
Copy link
Contributor Author

refack commented Apr 19, 2017

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);

@refack
Copy link
Contributor Author

refack commented Apr 19, 2017

Also, be sure that the const or other changes do not cause any permanent deopts.

No new deopts.

@nwoltman
Copy link
Contributor

There should also be a similar getter/setter for dir (since root forms the first part of dir and changing dir should update root).

lib/path.js Outdated
const li = value.lastIndexOf('.');
if (li > 0) {
this.ext = value.slice(li);
this.name = value.split(0, li);
Copy link
Member

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?

Copy link
Contributor Author

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.

@refack refack force-pushed the improve-path-parse-1999 branch from f760d1b to 3e5c7d0 Compare April 21, 2017 14:55
@@ -1136,6 +1129,22 @@ const win32 = {
else if (isAbsolute)
ret.dir = path.slice(0, rootEnd);

Object.defineProperty(ret, 'base', {
Copy link
Contributor

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?

Copy link
Contributor Author

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 😵

@refack refack force-pushed the improve-path-parse-1999 branch 2 times, most recently from 4754c8b to 57272db Compare April 25, 2017 11:53
make `parse` return an object where `base` is a computed property

Ref: nodejs#1999
@refack refack force-pushed the improve-path-parse-1999 branch from 57272db to f5d22a2 Compare July 23, 2017 17:45
@BridgeAR BridgeAR added the stalled Issues and PRs that are stalled. label Sep 12, 2017
@BridgeAR
Copy link
Member

Ping @refack

@BridgeAR
Copy link
Member

Closing due to long inactivity and no response. @refack please feel free to reopen if you would like to pursue this further.

@BridgeAR BridgeAR closed this Sep 23, 2017
@refack refack self-assigned this Nov 11, 2018
@refack refack removed their assignment Mar 11, 2019
@refack refack added help wanted Issues that need assistance from volunteers or PRs that need help to proceed. stalled Issues and PRs that are stalled. and removed stalled Issues and PRs that are stalled. labels May 23, 2019
@refack refack changed the title [wip] path: improve parse => format combination [partial work] path: improve parse => format combination May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issues that need assistance from volunteers or PRs that need help to proceed. path Issues and PRs related to the path subsystem. semver-major PRs that contain breaking changes and should be released in the next major version. stalled Issues and PRs that are stalled. wip Issues and PRs that are still a work in progress.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants