Skip to content

Conversation

@marcalexiei
Copy link
Contributor

@marcalexiei marcalexiei commented Nov 2, 2025

Problem

#7232 (reply in thread)

Right now the following file pairs have the same content:

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-magic package.
Regarding @scalar/openapi-parser usage I noticed that was used alongside node:fs so 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:

  • I've added an explanation why this change is needed.
  • I've added a changeset (pnpm changeset).
  • I've added tests for the regression or new feature.
  • I've updated the documentation (Not needed).

Note

Introduce a shared @scalar/helpers/node/path polyfill, update json-magic to use it, and switch openapi-parser to native node:path, removing duplicated polyfills and adding tests.

  • Helpers (@scalar/helpers)
    • New polyfill: Add @scalar/helpers/node/path with typed POSIX path utilities in src/node/path.ts and export via package.json ("./node/*").
    • Tests: Add comprehensive unit tests for path functions (packages/helpers/src/node/path.test.ts).
  • JSON Magic (@scalar/json-magic)
    • Refactor: Replace internal path polyfill with @scalar/helpers/node/path in src/bundle/bundle.ts.
    • Cleanup: Remove duplicated polyfill re-exports (src/polyfills/index.ts).
  • OpenAPI Parser (@scalar/openapi-parser)
    • Fix: Use native node:path (dirname, join) in plugins/read-files/read-files.ts.
    • Cleanup: Remove duplicated polyfill files (src/polyfills/*).
    • Tests: Minor typo fix in read-files.test.ts.

Written by Cursor Bugbot for commit 2860d2e. This will update automatically on new commits. Configure here.

@changeset-bot
Copy link

changeset-bot bot commented Nov 2, 2025

🦋 Changeset detected

Latest commit: 2860d2e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
@scalar/json-magic Minor
@scalar/openapi-parser Patch
@scalar/helpers Minor
@scalar/api-client Patch
@scalar/api-reference Patch
@scalar/oas-utils Patch
@scalar/workspace-store Patch
@scalar/fastify-api-reference Patch
@scalar/import Patch
@scalar/mock-server Patch
@scalar/openapi-to-markdown Patch
@scalar/components Patch
@scalar/object-utils Patch
@scalar/postman-to-openapi Patch
@scalar/sidebar Patch
@scalar/void-server Patch
@scalar/nuxt Patch
@scalar/api-client-react Patch
scalar-app Patch
@scalarapi/docker-api-reference Patch
@scalar/aspire Patch
@scalar/aspnetcore Patch
@scalar/webjar Patch
@scalar/api-reference-react Patch
@scalar/pre-post-request-scripts Patch
@scalar/use-codemirror Patch

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

@marcalexiei marcalexiei marked this pull request as ready for review November 2, 2025 05:42
Copy link
Member

@hanspagel hanspagel left a 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.

@marcalexiei
Copy link
Contributor Author

Hey @hanspagel,

yeah, maybe we can just use node:path? I don’t remember why we needed a polyfill,

I done a quick search:
packages/json-magic/src/bundle/bundle.ts ends up bundled in the standalone file,
so I think that the polifyll was included because some of the code was executed in the browser?
All path functions are used inside resolveReferencePath which might get called when in a browser.


I don’t remember why we needed a polyfill, but if the build and the tests pass, it’s fine.

Ok, I'll update this PR later to see if Ci complains about the change.

@marcalexiei marcalexiei closed this Nov 3, 2025
@marcalexiei marcalexiei deleted the dedupe-path-polyfill branch November 3, 2025 10:31
@marcalexiei marcalexiei restored the dedupe-path-polyfill branch November 3, 2025 10:31
@marcalexiei marcalexiei reopened this Nov 3, 2025
@hanspagel
Copy link
Member

hanspagel commented Nov 3, 2025

ah yeah, if the relevant code actually ends up in a browser, sure.
I thought it would just be used for the read files plugin or something

thanks for looking into this

cursor[bot]

This comment was marked as outdated.

@marcalexiei

This comment was marked as resolved.

@marcalexiei marcalexiei requested a review from hanspagel November 3, 2025 10:50
@marcalexiei
Copy link
Contributor Author

Adding for completeness:

Using node:path in json-magic bundle causes CI to fail:
https://github.com/scalar/scalar/actions/runs/19031676179/job/54347195263:

ERROR in node:path
Module build failed: UnhandledSchemeError: Reading from "node:path" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.

@marcalexiei marcalexiei requested a review from hanspagel November 3, 2025 17:24
Comment on lines 220 to 231
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,
}
Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

@marcalexiei marcalexiei Nov 3, 2025

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:

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

Copy link
Member

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.

Copy link
Member

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!

Copy link
Contributor Author

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

Copy link
Member

@amritk amritk left a 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

@geoffgscott
Copy link
Member

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.

Copy link
Member

@geoffgscott geoffgscott left a comment

Choose a reason for hiding this comment

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

Love it.

@hanspagel hanspagel merged commit c1ecd0c into scalar:main Nov 5, 2025
35 checks passed
@hanspagel hanspagel mentioned this pull request Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants