Skip to content

fix: use function form of glob exclude for Node < 22.14 compat#212

Merged
southpolesteve merged 1 commit intomainfrom
fix/glob-exclude-compat
Mar 1, 2026
Merged

fix: use function form of glob exclude for Node < 22.14 compat#212
southpolesteve merged 1 commit intomainfrom
fix/glob-exclude-compat

Conversation

@southpolesteve
Copy link
Collaborator

Summary

  • Switches exclude option on node:fs/promises glob from string arrays to function form in both app-router.ts and pages-router.ts
  • String arrays for exclude require Node >= 22.14.0, but engines allows >= 22. Users on 22.0.0-22.13.x get ERR_INVALID_ARG_TYPE at runtime.
  • The function form works on all Node >= 22.0.0

Extracted from #134 by @erayack.

The string array form of the exclude option on node:fs/promises glob was only added in Node 22.14.0. Users on Node 22.0.0-22.13.x get ERR_INVALID_ARG_TYPE at runtime. Switch to the function form which works on all Node >= 22.
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 1, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@212 

commit: 799ce57

@github-actions
Copy link

github-actions bot commented Mar 1, 2026

Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original
@southpolesteve
Copy link
Collaborator Author

/bonk review please

Copy link
Contributor

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

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

LGTM. Clean compat fix.

Verification:

  • The exclude option as a string[] was indeed added in Node 22.14.0 (nodejs/node#56489), while exclude as a Function has been available since 22.0.0 (the original fs.glob API). Users on 22.0–22.13 would hit ERR_INVALID_ARG_TYPE at runtime with the old code.
  • The function form receives the entry name (basename) during directory traversal, so name.startsWith("@") and name === "api" || name.startsWith("_") are correct equivalents of the old ["**/@*"] and ["api", "**/_*"] patterns respectively.
  • All CI checks pass (Lint, Typecheck, Vitest, E2E, deploy previews, smoke tests).

One minor behavioral difference worth noting (not blocking): the old string pattern "**/_*" would match _-prefixed entries at any depth, while the function name.startsWith("_") also matches at any depth (since the function is called per-entry during traversal). So the behavior is equivalent here. Similarly "**/@*"name.startsWith("@") is equivalent.

@ask-bonk
Copy link
Contributor

ask-bonk bot commented Mar 1, 2026

PR approved. The fix is correct -- switches from string[] exclude (requires Node >= 22.14.0) to the function form (available since Node 22.0.0), matching the engines: ">=22" constraint in package.json. The function receives basenames during traversal, so the startsWith("@") and === "api" || startsWith("_") checks are behaviorally equivalent to the old glob patterns.

github run

@southpolesteve southpolesteve merged commit 1d38849 into main Mar 1, 2026
23 checks passed
@southpolesteve southpolesteve deleted the fix/glob-exclude-compat branch March 1, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants