Skip to content

refactor: use utility for cross-platform path regex construction #701

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

Merged

Conversation

james-elicx
Copy link
Contributor

  • Create a new utility for constructing regular expressions with cross-platform paths.
  • Update usage to use the new utility.

Copy link

pkg-pr-new bot commented Jan 16, 2025

Open in Stackblitz

pnpm add https://pkg.pr.new/@opennextjs/aws@701

commit: 8d603ae

Copy link

changeset-bot bot commented Jan 16, 2025

🦋 Changeset detected

Latest commit: 8d603ae

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

This PR includes changesets to release 3 packages
Name Type
@opennextjs/aws Patch
app-pages-router Patch
app-router 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

@james-elicx james-elicx marked this pull request as ready for review January 16, 2025 16:00
@@ -0,0 +1,10 @@
export function getCrossPlatformPathRegex(
regex: string,
opts: { escape: boolean } = { escape: true },
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the escape options ? It's not used anywhere.
My take on this is that we should only escape path related stuff here (i.e. / the starting ./ and file extensions)

Copy link
Contributor

Choose a reason for hiding this comment

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

Why the escape options ?

That's something I asked James.

If you only want to escape a path then you would use the default value (true)

But sometimes (i.e. ESBuild filter), you might want to have more control on the pattern and do not escape special chars.

Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

@james-elicx thanks for the change, LGTM.

Let's have more discussion with @conico974 about the exact behavior this should have

@vicb
Copy link
Contributor

vicb commented Jan 17, 2025

@conico974 replying here as the convo is resolved:

I understand your point but sounds like "only escape path related stuff here (i.e. / the starting ./ and file extensions)" is not without surprises either.

For now I feel like we have those solutions:

  • only handle the separator
  • handle the separator and escape the special chars (do not offer { escape: false } - I will come with a different function for my needs
  • use the impl in this PR.

I need some think to think about it.

Notes:

  • /(\/|\\)edgeFunctionHandler.js/g was wrongly escaped before this PR (only to say there is probably no ideal solution, as you mentioned we can get things wrong after this PR too)
  • I think you replied before I updated my message

@conico974
Copy link
Contributor

@vicb As you said there is probably no ideal solution for this ( unless with some typescript wizardry, but it's not worth the effort ).
Personally i would have just made it escape path related stuff, and if we need more complex stuff we just write our own regex.
But i'm fine with the current implementation as long as we provide enough explanation as to what needs to be done for these special cases.

Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for adding a clear doc and tests.

Copy link
Contributor

@conico974 conico974 left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks

@conico974 conico974 merged commit 00ce837 into opennextjs:main Jan 17, 2025
3 checks passed
@github-actions github-actions bot mentioned this pull request Jan 16, 2025
@james-elicx james-elicx deleted the james/cross-platform-path-utility branch January 17, 2025 11:46
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.

3 participants