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

fix(cloudflare-pages): use predefined wildcards in routes.exclude #2319

Merged
merged 4 commits into from
Apr 2, 2024

Conversation

pgraug
Copy link
Contributor

@pgraug pgraug commented Mar 27, 2024

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

When using Cloudflare Pages with Nitro all static files need to be present in the _routes.json file's exclude array.

Since only 100 entries are allowed in the file, projects can use wildcards to reduce the number entries (eg. excluding "/_nuxt/*" excludes all subpaths).

Nitro handles this well for nitro.options.publicAssets by adding the wildcard path and then not adding the individual files matching it. But if you just add a wildcard to nitro.options.cloudflare.pages.routes.exclude it still includes the individual files like so:

{
  "version": 1,
  "include": ["/*"],
  "exclude": [
    "/cf-pages-exclude/*",
    "/cf-pages-exclude/not-in-routes-json.txt",  <-- This shouldn't be here
    ...
  ]
}

That's what this PR fixes. It handles both cases using routes.exclude (that explicitPublicAssets has already been appended to) for the globby ignore list, replacing the "/*" syntax used on Cloudflare Pages with the "/**" syntax that globby uses.

I added a test that fails without the fix.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@pi0 pi0 changed the title fix(cloudflare-pages): don't exclude paths in _routes.json if a matching wildcard is already excluded fix(cloudflare-pages): use predefined wildcards in routes.exclude Apr 2, 2024
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Thanks!

@pi0 pi0 merged commit 3cb566e into unjs:main Apr 2, 2024
4 checks passed
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.

2 participants