Azure / Azure/azure-rest-api-specs
[.github/shared] Add helper for "find file in parent folders"
- Dominant language
- TypeSpec
- Stars
- 3.1k
- Forks
- 6k
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 444
Description
We have similar code in at least two places, computing the algorithm "find a file (or regex) in the parent folders of a given folder".
spec-gen-sdk-runner:
https://github.com/Azure/azure-rest-api-specs/pull/40236/changes#r2855964668
suppressions:
https://github.com/Azure/azure-rest-api-specs/blob/d6e4facb4609b342308d8dbfa9cd50c8328e41ff/eng/tools/suppressions/src/suppressions.ts#L198
To reduce duplication, we should create a single helper method with a superset of the functionality needed by all consumers, in .github/shared. Probably a file named `fs.js` rather than existing `path.js`, since we need to use both path and fs APIs.
The API can be like this:
```js
export async function findFilesInParents(
folder: string,
filename: string,
options?: {
maxResults?: number,
stopFolder?: string,
}
): Promise {
```
One decision is whether filename should be a `string` or `Regex`. I prefer `string`, since it lets us check for existence directly, without needing a dir listing. And prevents ambiguous matches, etc.
But spec-gen-sdk-runner currently relies on regex matching, so we may need to support it. Let's check all the consumers and see what we can do.
While extracting this helper, also check this file for other possible helpers to extract:
https://github.com/Azure/azure-rest-api-specs/blob/main/eng/tools/spec-gen-sdk-runner/src/utils.ts
Contributor guide
Assessment
This issue has not been assessed yet.