Repository navigation
feat: add stop option to detect - #39
Conversation
|
What is the motivation for this? |
I needed this feature for testing package manager detection in my codebase that uses pnpm. Specifically, I have tests that should return null when no package manager is found, but without the stop option, the traversal continues upward and finds the pnpm configuration at the repository root, causing the test to fail. The stop option allows me to properly test these scenarios by limiting how far up the directory tree the search goes. |
|
I personally would like to use this too for similar reasons, and plays in hand to JoshuaKGoldberg/formatly#54 (where it'd soon use |
Currently we can't break the traversing up directories, which we now can.
6676f55 to
189ac6c
Compare
| /** | ||
| * The path to stop traversing up the directory. | ||
| */ | ||
| stop?: string |
There was a problem hiding this comment.
Perhaps a discussion point for others if we should consider stopDir instead (used by lilconfig)
There was a problem hiding this comment.
Would this be better as a function that takes each dir and call it shouldStop(dir: string)? A static path can have many edge cases of path normalization, tailing slash, etc.
There was a problem hiding this comment.
I believe it should be safe since path.resolve(stop) was called so it normalizes it. We could reference how lilconfig handles it though, but I think a string is easier to understand and configure.
bluwy
left a comment
There was a problem hiding this comment.
LGTM 👍 I'm not a maintainer here, so will leave to them for the final review
|
Seems like a reasonable idea. If we also exported a method to find the monorepo root so that users could provide that as the |
This will make made-in-common#39 a replacement for made-in-common#23.
stop option to detectstop option to detect & export getWorkspaceRoot
|
I'm wondering if there are any remaining concerns about this PR that I could address to help move it forward? |
|
Looking back, I think I have a slight preference to renaming as I personally don't find the need to do this now, but it would've made reviewing easier I imagine if the new workspace api is done in a separate PR. |
I will create a new separate issue, so we can decide whether or not to also detect lerna workspaces and other workspace tools.
stop option to detect & export getWorkspaceRootstop option to detect
Description
This PR adds a new stop option to
detect. This will allow us to stop traversing directories when a certain directory is hit.Linked Issues
N/A
Additional context
N/A