Skip to content

Commit 516123c

Browse files
committed
Public Library function for the Github Action
1 parent f26e4d1 commit 516123c

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"dist/**/*.js",
66
"src/**/*.ts"
77
],
8-
"main": "src/lib.ts",
8+
"main": "src/library.ts",
99
"type": "module",
1010
"scripts": {
1111
"build": "tsup src/main.ts --format esm",

src/lib/configuration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe("parseConfig", () => {
5353
});
5454

5555
it.only("a path must be set", () => {
56-
fs.writeFileSync( "aa.yaml", "version: 1.0.0\n");
56+
fs.writeFileSync("aa.yaml", "version: 1.0.0\n");
5757
expect(() => config({ pathToConfig: "aa.yaml", pathsToScan: [] })).toThrow(OErrorNoPaths);
5858
});
5959
});

src/lib/scanner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ export function isCommonIgnoredFile(file: string): boolean {
179179
return COMMON_IGNORED_FILES.has(basename);
180180
}
181181

182-
export function findOwner(regexps: Rules, baseline: Baseline, file: string): string | null | typeof MATCH_BASELINE {
182+
export type OwnerResult = string | null | typeof MATCH_BASELINE;
183+
export function findOwner(regexps: Rules, baseline: Baseline, file: string): OwnerResult {
183184
if (baseline.check(file)) {
184185
return MATCH_BASELINE;
185186
}

src/library.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { findOwner as fo, type OwnerResult } from "./lib/scanner.ts";
2+
import { config, type ConfigurationOptions } from "./lib/configuration.js";
3+
import { initialize as initializeBaseline } from "./lib/baseline.js";
4+
import { Rules } from "./lib/rules.js";
5+
6+
export type { OwnerResult, ConfigurationOptions };
7+
8+
export function findOwners(
9+
pathToScan: string[],
10+
options: ConfigurationOptions & Omit<ConfigurationOptions, "pathsToScan">,
11+
): Record<string, OwnerResult> {
12+
const c = config(options);
13+
const baseline = initializeBaseline(c);
14+
const rules = new Rules(c.features);
15+
16+
const results: Record<string, OwnerResult> = {};
17+
for (const p of pathToScan) {
18+
results[p] = fo(rules, baseline, p);
19+
}
20+
21+
return results;
22+
}

src/main.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)