Refactor plugin/config loading, add theme-only plugin package support (#20556)

This commit is contained in:
Sebastian
2026-04-02 01:50:22 +02:00
committed by GitHub
parent 854484babf
commit f6fd43e574
24 changed files with 1246 additions and 539 deletions

View File

@@ -83,6 +83,95 @@ describe("filesystem", () => {
})
})
describe("findUp()", () => {
test("keeps previous nearest-first behavior for single target", async () => {
await using tmp = await tmpdir()
const parent = path.join(tmp.path, "parent")
const child = path.join(parent, "child")
await fs.mkdir(child, { recursive: true })
await fs.writeFile(path.join(tmp.path, "marker"), "root", "utf-8")
await fs.writeFile(path.join(parent, "marker"), "parent", "utf-8")
const result = await Filesystem.findUp("marker", child, tmp.path)
expect(result).toEqual([path.join(parent, "marker"), path.join(tmp.path, "marker")])
})
test("respects stop boundary", async () => {
await using tmp = await tmpdir()
const parent = path.join(tmp.path, "parent")
const child = path.join(parent, "child")
await fs.mkdir(child, { recursive: true })
await fs.writeFile(path.join(tmp.path, "marker"), "root", "utf-8")
await fs.writeFile(path.join(parent, "marker"), "parent", "utf-8")
const result = await Filesystem.findUp("marker", child, parent)
expect(result).toEqual([path.join(parent, "marker")])
})
test("supports multiple targets with nearest-first default ordering", async () => {
await using tmp = await tmpdir()
const parent = path.join(tmp.path, "parent")
const child = path.join(parent, "child")
await fs.mkdir(child, { recursive: true })
await fs.writeFile(path.join(parent, "cfg.jsonc"), "{}", "utf-8")
await fs.writeFile(path.join(tmp.path, "cfg.json"), "{}", "utf-8")
await fs.writeFile(path.join(tmp.path, "cfg.jsonc"), "{}", "utf-8")
const result = await Filesystem.findUp(["cfg.json", "cfg.jsonc"], child, tmp.path)
expect(result).toEqual([
path.join(parent, "cfg.jsonc"),
path.join(tmp.path, "cfg.json"),
path.join(tmp.path, "cfg.jsonc"),
])
})
test("supports rootFirst ordering for multiple targets", async () => {
await using tmp = await tmpdir()
const parent = path.join(tmp.path, "parent")
const child = path.join(parent, "child")
await fs.mkdir(child, { recursive: true })
await fs.writeFile(path.join(parent, "cfg.jsonc"), "{}", "utf-8")
await fs.writeFile(path.join(tmp.path, "cfg.json"), "{}", "utf-8")
await fs.writeFile(path.join(tmp.path, "cfg.jsonc"), "{}", "utf-8")
const result = await Filesystem.findUp(["cfg.json", "cfg.jsonc"], child, tmp.path, { rootFirst: true })
expect(result).toEqual([
path.join(tmp.path, "cfg.json"),
path.join(tmp.path, "cfg.jsonc"),
path.join(parent, "cfg.jsonc"),
])
})
test("rootFirst preserves json then jsonc order per directory", async () => {
await using tmp = await tmpdir()
const project = path.join(tmp.path, "project")
const nested = path.join(project, "nested")
await fs.mkdir(nested, { recursive: true })
await fs.writeFile(path.join(tmp.path, "opencode.json"), "{}", "utf-8")
await fs.writeFile(path.join(tmp.path, "opencode.jsonc"), "{}", "utf-8")
await fs.writeFile(path.join(project, "opencode.json"), "{}", "utf-8")
await fs.writeFile(path.join(project, "opencode.jsonc"), "{}", "utf-8")
const result = await Filesystem.findUp(["opencode.json", "opencode.jsonc"], nested, tmp.path, {
rootFirst: true,
})
expect(result).toEqual([
path.join(tmp.path, "opencode.json"),
path.join(tmp.path, "opencode.jsonc"),
path.join(project, "opencode.json"),
path.join(project, "opencode.jsonc"),
])
})
})
describe("readText()", () => {
test("reads file content", async () => {
await using tmp = await tmpdir()