-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow specifying instrumented files
- Loading branch information
1 parent
762fcd0
commit fad5ae5
Showing
7 changed files
with
137 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { resolve } from "node:path"; | ||
|
||
export default class PackageMatcher extends Array<Package> { | ||
constructor( | ||
private root: string, | ||
packages: Package[], | ||
) { | ||
super(...packages); | ||
this.resolved = new Map(packages.map(({ path }) => [path, resolve(root, path)])); | ||
} | ||
|
||
private resolved: Map<string, string>; | ||
|
||
private resolve(path: string) { | ||
return this.resolved.get(path) ?? resolve(this.root, path); | ||
} | ||
|
||
match(path: string): Package | undefined { | ||
const pkg = this.find((pkg) => path.startsWith(this.resolve(pkg.path))); | ||
return pkg?.exclude?.find((ex) => path.includes(ex)) ? undefined : pkg; | ||
} | ||
} | ||
|
||
export interface Package { | ||
path: string; | ||
exclude?: string[]; | ||
} | ||
|
||
export function parsePackages(packages: unknown): Package[] | undefined { | ||
if (!packages || !Array.isArray(packages)) return; | ||
|
||
const result: Package[] = []; | ||
|
||
for (const pkg of packages as unknown[]) { | ||
if (typeof pkg === "string") result.push({ path: pkg }); | ||
else if (typeof pkg === "object" && pkg !== null && "path" in pkg) { | ||
const entry: Package = { path: String(pkg.path) }; | ||
if ("exclude" in pkg) entry.exclude = Array.isArray(pkg.exclude) ? pkg.exclude : []; | ||
result.push(entry); | ||
} | ||
} | ||
|
||
if (result.length > 0) return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters