-
Notifications
You must be signed in to change notification settings - Fork 677
feat: node:path polyfill refinements
#7235
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
Conversation
🦋 Changeset detectedLatest commit: 2860d2e The changes in this PR will be included in the next version bump. This PR includes changesets to release 26 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
yeah, maybe we can just use node:path? I don’t remember why we needed a polyfill, but if the build and the tests pass, it’s fine.
|
Hey @hanspagel,
I done a quick search:
Ok, I'll update this PR later to see if Ci complains about the change. |
|
ah yeah, if the relevant code actually ends up in a browser, sure. thanks for looking into this |
420601b to
8345776
Compare
8345776 to
c6dfaef
Compare
This comment was marked as resolved.
This comment was marked as resolved.
|
Adding for completeness: Using |
packages/helpers/src/node/path.ts
Outdated
| export default { | ||
| extname: extname, | ||
| basename: basename, | ||
| dirname: dirname, | ||
| sep: sep, | ||
| delimiter: delimiter, | ||
| relative: relative, | ||
| join: join, | ||
| isAbsolute: isAbsolute, | ||
| normalize: normalize, | ||
| resolve: resolve, | ||
| extname, | ||
| basename, | ||
| dirname, | ||
| sep, | ||
| delimiter, | ||
| relative, | ||
| join, | ||
| isAbsolute, | ||
| normalize, | ||
| resolve, | ||
| } |
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.
| export default { | |
| extname: extname, | |
| basename: basename, | |
| dirname: dirname, | |
| sep: sep, | |
| delimiter: delimiter, | |
| relative: relative, | |
| join: join, | |
| isAbsolute: isAbsolute, | |
| normalize: normalize, | |
| resolve: resolve, | |
| extname, | |
| basename, | |
| dirname, | |
| sep, | |
| delimiter, | |
| relative, | |
| join, | |
| isAbsolute, | |
| normalize, | |
| resolve, | |
| } | |
| export const path = { | |
| extname, | |
| basename, | |
| dirname, | |
| sep, | |
| delimiter, | |
| relative, | |
| join, | |
| isAbsolute, | |
| normalize, | |
| resolve, | |
| } |
hey looks good! Can we just avoid the default export? I would have thought biome would have caught this.
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.
Can we just avoid the default export?
I usually avoid default export, however using it would make the module signature different from node:path.
No problem making the change though.
I would have thought biome would have caught this.
I think that is because noDefaultExport rule is not explicitly enabled in the repo.
Consider that recommended rules are disabled:
Line 100 in 8351cf4
| "recommended": false, |
Here’s a clearer and more polished version of your text, while keeping your original intent and tone:
After finishing the work on enabling knip across the entire repository, I can check which recommended rules can be enabled to improve code consistency and quality of code.
Since you mentioned this, I’d start with enabling noDefaultExport 😅.
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.
hey you are a legend! haha. Lets make the change, no need to follow nodes bad habbits.
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 probably didn't turn on recommended because there would be too many infractions 😓, were getting closer though!
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.
hey you are a legend! haha. Lets make the change, no need to follow nodes bad habbits.
Addressed via 2860d2e
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.
Nice work with the move!
Also @hanspagel there are a few libs that do the same thing if we don't want to maintain this code
https://www.npmjs.com/package/path-browserify
https://www.npmjs.com/package/node-stdlib-browser
https://www.npmjs.com/package/vite-plugin-node-polyfills
|
I would rather us maintain this. Polyfill libraries have been and endless headache in the past. This also encourages a least-usage pattern as you have to roll any polyfills we need. |
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.
Love it.
Problem
#7232 (reply in thread)
Solution
I added a new export on helpers package:
@scalar/helpers/node/path.This exports expose the polyfill that was duplicated in 2 packages.
This polifyll is now used from
@scalar/json-magicpackage.Regarding
@scalar/openapi-parserusage I noticed that was used alongsidenode:fsso I don't think that the polifyll is necessary.I'll add a review comment so we can discuss this easily.
Checklist
I've gone through the following:
pnpm changeset).Note
Introduce a shared
@scalar/helpers/node/pathpolyfill, updatejson-magicto use it, and switchopenapi-parserto nativenode:path, removing duplicated polyfills and adding tests.@scalar/helpers)@scalar/helpers/node/pathwith typed POSIX path utilities insrc/node/path.tsand export viapackage.json("./node/*").pathfunctions (packages/helpers/src/node/path.test.ts).@scalar/json-magic)@scalar/helpers/node/pathinsrc/bundle/bundle.ts.src/polyfills/index.ts).@scalar/openapi-parser)node:path(dirname,join) inplugins/read-files/read-files.ts.src/polyfills/*).read-files.test.ts.Written by Cursor Bugbot for commit 2860d2e. This will update automatically on new commits. Configure here.