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

Add matchPattern to load only some specific paths #287

Closed
2 tasks done
hugoattal opened this issue Dec 20, 2022 · 2 comments · Fixed by #289
Closed
2 tasks done

Add matchPattern to load only some specific paths #287

hugoattal opened this issue Dec 20, 2022 · 2 comments · Fixed by #289

Comments

@hugoattal
Copy link
Contributor

hugoattal commented Dec 20, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

I'd like to match only some specific paths, ignoring every other files.

I suggest two things:

  • Add a matchPattern that process the file only if it matches the pattern. If there is also an ignore pattern, I guess the order of priority should be match, ignore (if the route is matching, then check if it's ignored)
  • Add the ability for matchPattern and ignorePattern to provide both Regex OR function that return a boolean OR string contained in the path.

ℹ️ I can do the PR if that's okay.

Motivation

Here's my architecture:

/routes/user/handlers/get.ts (shoud load)
/routes/user/handlers/get.spec.ts (should ignore)
/routes/user/lib.ts (should ignore)

I could use the ignorePattern regex, but I feel like it's not a super intuitive DX.

Example

Here's what my example could look like:

app.register(autoload, {
  dir: path.join(__dirname, "routes"),
  matchPattern: /handlers\/\w.ts$/
})

// or

app.register(autoload, {
  dir: path.join(__dirname, "routes"),
  matchPattern: /handlers/,
  ignorePattern: /spec\.ts$/
})

// or

app.register(autoload, {
  dir: path.join(__dirname, "routes"),
  matchPattern: "/handlers/",
  ignorePattern: (path) => path.endsWith("spec.ts")
})
@mcollina
Copy link
Member

Go ahead with a PR!

@hugoattal
Copy link
Contributor Author

Thanks! Done here: #289

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 a pull request may close this issue.

2 participants