Skip to content

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

Merged
southpolesteve merged 1 commit into
mainfrom
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 into
mainfrom
fix/glob-exclude-compat

Conversation

@southpolesteve

Copy link
Copy Markdown
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

pkg-pr-new Bot commented Mar 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 799ce57

@github-actions

github-actions Bot commented Mar 1, 2026

Copy link
Copy Markdown
Contributor
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
Copy Markdown
Collaborator Author

/bonk review please

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown
Contributor

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

ask-bonk Bot commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants