fix: skip removed packages during upstream merge

This commit is contained in:
Mark IJbema
2026-04-29 11:50:14 +02:00
parent 828755fea4
commit bb06f4d2ac
7 changed files with 108 additions and 30 deletions
+34
View File
@@ -0,0 +1,34 @@
/**
* Match repository paths against exact, regex, or simple glob patterns.
*/
function esc(text: string): string {
return text.replace(/[|\\{}()[\]^$+?.]/g, "\\$&")
}
function glob(pattern: string): RegExp {
const source = pattern
.split("**")
.map((part) => part.split("*").map(esc).join("[^/]*"))
.join(".*")
return new RegExp(`^${source}$`)
}
export function match(path: string, pattern: string): boolean {
if (path === pattern) return true
if (pattern.startsWith("^") || pattern.includes("\\")) {
return new RegExp(pattern).test(path)
}
if (pattern.includes("*")) {
return glob(pattern).test(path)
}
return false
}
export function matches(path: string, patterns: string[]): boolean {
return patterns.some((pattern) => match(path, pattern))
}
+17
View File
@@ -0,0 +1,17 @@
import { expect, test } from "bun:test"
import { getRecommendation } from "./report"
test("recommends skip for hosted package globs", () => {
expect(getRecommendation("packages/web/src/content/docs/ja/zen.mdx", [], ["packages/web/**"]).recommendation).toBe(
"skip",
)
expect(getRecommendation("packages/console/app/package.json", [], ["packages/console/**"]).recommendation).toBe(
"skip",
)
})
test("does not recommend skip for unrelated packages", () => {
expect(getRecommendation("packages/app/package.json", [], ["packages/web/**"]).recommendation).toBe(
"package-transform",
)
})
+2 -1
View File
@@ -4,6 +4,7 @@
*/
import { $ } from "bun"
import { matches } from "./match"
export interface ConflictReport {
timestamp: string
@@ -119,7 +120,7 @@ export function classifyFile(path: string): ConflictFile["type"] {
* Check if a file should be skipped (not added from upstream)
*/
function shouldSkipFile(path: string, skipPatterns: string[]): boolean {
return skipPatterns.some((pattern) => path === pattern || path.includes(pattern))
return matches(path, skipPatterns)
}
/**