Skip to main content

Glob patterns

Wherever rev-dep takes a file path or pattern - entry points, files, denyFiles, ignoreMatches, ignoreFiles, graphExclude, and so on - the value is matched as a glob pattern.

Different tools implement slightly different glob "flavors". rev-dep aims to mimic .gitignore matching behavior, so patterns you already use in .gitignore should behave the same way here.

The usual wildcards apply:

  • * - matches any characters
  • ** - matches across directory boundaries
  • ? - matches a single character
  • [...] - a character class (matches one character from the set)
  • {a,b} - alternation (matches a or b)

Troubleshooting: paths with [ ] or { } (e.g. Next.js routes)​

Because [, ], {, and } are glob special characters, a literal path that contains them is not matched as-is. A Next.js dynamic route like pages/admin/clients/[clientId]/edit.tsx is read as a character class ([clientId] = "one of c, l, i, …"), so it never matches the real file - and the entry point silently does nothing.

To match such a path literally, escape the special characters with a backslash. Because the config file is JSON, the backslash itself must be escaped, so you write \\[ and \\] (and \\{, \\}):

{
"rules": [
{
"path": ".",
"restrictedImportersDetection": {
"enabled": true,
"files": ["app/legacy/**"],
"allowedEntryPoints": [
"pages/admin/clients/\\[clientId\\]/edit.tsx"
]
}
}
]
}

Here the config string "\\[clientId\\]" is read as the glob pattern \[clientId\], which matches the literal [clientId] segment.

Tip: you only strictly need to escape the opening bracket - "\\[clientId]" also works, since once [ is escaped there is no character class for ] to close. Escaping both reads more clearly.

You can still combine escaped segments with wildcards, e.g. "pages/admin/clients/\\[clientId\\]/**" to match everything under a dynamic-route directory.