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

feat(path): single file exports #3510

Merged
merged 11 commits into from
Aug 7, 2023

Conversation

lino-levan
Copy link
Contributor

@lino-levan lino-levan commented Jul 31, 2023

Related #687.

Future PRs:

  • BREAKING: Add "os" argument
  • BREAKING: Rename some methods to make them more intuitive (by @nayeemrmn on discord)
    • basename() -> fileName()
    • dirname() -> parent()
    • extname() -> extension()

@github-actions github-actions bot added the path label Jul 31, 2023
path/dirname.ts Outdated Show resolved Hide resolved
@kt3k
Copy link
Member

kt3k commented Aug 1, 2023

Move to single export file structure looks good to me, and it's probably less controversial to other points if it doesn't have breaking changes. Can we only do the move to single-file export without API design changes in this PR?

Add "os" argument
Make some breaking changes to APIs to allow for more options in the future

These points seem needing more discussion, also these 2 changes don't seem necessarily in the same PR. Maybe try them later PRs?

@lino-levan lino-levan marked this pull request as ready for review August 1, 2023 15:16
@lino-levan lino-levan requested a review from kt3k as a code owner August 1, 2023 15:16
@lino-levan
Copy link
Contributor Author

I guess you're right, but I just wanted to bundle breaking changes together. I'm not sure what the best way to move forward with single-file exports is. Should we expose posixX() and windowsX() to the user? Does that naming make any sense?

@kt3k
Copy link
Member

kt3k commented Aug 2, 2023

I think we can also update mod.ts to use new implementations and that should make the rendering of this page better.

Should we expose posixX() and windowsX() to the user?

I don't think so. The names sound strange to me.

I don't think we should deprecate win32.ts and posix.ts in this PR. I think that should be discussed together with Add "os" argument issue

@kt3k
Copy link
Member

kt3k commented Aug 2, 2023

Also can you add the license headers // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. to the new files?

@lino-levan
Copy link
Contributor Author

Alright, un-deprecating posix.ts and win32.ts (and not updating their implementations) in this PR. I'll change mod.ts to re-export the single-file exports.

@lino-levan
Copy link
Contributor Author

I guess this module will have quite the turbulent future. This should no longer be a breaking change (even if I personally think it should be). We now have duplicated implementations between posix.ts + win32.ts and the single-file exports. If we add an OS argument (or export the internal functions), we should be able to consolidate them.

@lino-levan lino-levan changed the title BREAKING(path): single file exports chore(path): single file exports Aug 2, 2023
@lino-levan
Copy link
Contributor Author

Updated the original comment for future os argument PR. This should be reviewable now.

Copy link
Collaborator

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

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

Sidenote: each function in this sub-module should have JSDocs. I guess this can be done in a follow-up PR.

path/basename.ts Outdated Show resolved Hide resolved
@lino-levan
Copy link
Contributor Author

lino-levan commented Aug 3, 2023

With #3515, is there any value in keeping posix.ts and win32.ts? To clarify, not suggesting to remove it in this PR. I think this PR accomplishes the goal in the title just fine.

@kt3k
Copy link
Member

kt3k commented Aug 4, 2023

It looks like in most test cases, the APIs are called via path.posix or path.win32. So with this change, new implementations are note tested in CI.

Can you also replace the APIs under path.posix and path.win32 with the new ones?

I think each platform specific function (like windowsBasename) should work independently, and we should re-export it as platform specific version.

@lino-levan
Copy link
Contributor Author

I would need to export windowsX and posixX to do this. Are we committed to doing that?

@lino-levan
Copy link
Contributor Author

Alternatively, which is what I initially pushed for, we could implement an os argument, and keep those implementations internal while still being able to test them. Additionally, we would be able to "re-export" the new implementations in posix.ts and win32.ts.

I don't think we should make our API surface larger over this, especially with the naming as it is.

@kt3k
Copy link
Member

kt3k commented Aug 5, 2023

I don't think we should make our API surface larger over this, especially with the naming as it is.

I agree.

How about moving platform specific implementations of, for example, basename (windowsBasename and posixBasename) to _basename.ts? We can use them from basename.ts, posix.ts, and win32.ts, but they are still private from the users

@lino-levan
Copy link
Contributor Author

That seems reasonable. I'll go ahead with that.

@lino-levan
Copy link
Contributor Author

I was skeptical at first, but I'm now convinced that this was the way to do it. Thanks for the suggestion @kt3k! This should now really be ready for review.

Copy link
Collaborator

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

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

Few nits. Otherwise, LGTM! Nice.

path/mod.ts Outdated Show resolved Hide resolved
path/mod.ts Outdated Show resolved Hide resolved
path/mod.ts Outdated Show resolved Hide resolved
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM. Nice work! @lino-levan

I'd tag this change as feat as newly available paths can be considered as new features.

@kt3k kt3k changed the title chore(path): single file exports feat(path): single file exports Aug 7, 2023
@kt3k kt3k merged commit 66b2fb8 into denoland:main Aug 7, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants