Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/opencode/src/util/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export namespace Glob {
}

export async function scan(pattern: string, options: Options = {}): Promise<string[]> {
return glob(pattern, toGlobOptions(options)) as Promise<string[]>
const results = (await glob(pattern, toGlobOptions(options))) as string[]
return results.sort()
}

export function scanSync(pattern: string, options: Options = {}): string[] {
return globSync(pattern, toGlobOptions(options)) as string[]
const results = globSync(pattern, toGlobOptions(options)) as string[]
return results.sort()
}

export function match(pattern: string, filepath: string): boolean {
Expand Down
12 changes: 6 additions & 6 deletions packages/opencode/test/util/glob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("Glob", () => {

const results = await Glob.scan("*.txt", { cwd: tmp.path })

expect(results.sort()).toEqual(["a.txt", "b.txt"])
expect(results).toEqual(["a.txt", "b.txt"])
})

test("returns absolute paths when absolute option is true", async () => {
Expand Down Expand Up @@ -53,7 +53,7 @@ describe("Glob", () => {

const results = await Glob.scan("*", { cwd: tmp.path, include: "all" })

expect(results.sort()).toEqual(["file.txt", "subdir"])
expect(results).toEqual(["file.txt", "subdir"])
})

test("handles nested patterns", async () => {
Expand Down Expand Up @@ -93,7 +93,7 @@ describe("Glob", () => {

const results = await Glob.scan("**/*.txt", { cwd: tmp.path, symlink: true })

expect(results.sort()).toEqual(["linkdir/file.txt", "realdir/file.txt"])
expect(results).toEqual(["linkdir/file.txt", "realdir/file.txt"])
})

test("includes dotfiles when dot option is true", async () => {
Expand All @@ -103,7 +103,7 @@ describe("Glob", () => {

const results = await Glob.scan("*", { cwd: tmp.path, dot: true })

expect(results.sort()).toEqual([".hidden", "visible"])
expect(results).toEqual([".hidden", "visible"])
})

test("excludes dotfiles when dot option is false", async () => {
Expand All @@ -125,7 +125,7 @@ describe("Glob", () => {

const results = Glob.scanSync("*.txt", { cwd: tmp.path })

expect(results.sort()).toEqual(["a.txt", "b.txt"])
expect(results).toEqual(["a.txt", "b.txt"])
})

test("respects options", async () => {
Expand All @@ -135,7 +135,7 @@ describe("Glob", () => {

const results = Glob.scanSync("*", { cwd: tmp.path, include: "all" })

expect(results.sort()).toEqual(["file.txt", "subdir"])
expect(results).toEqual(["file.txt", "subdir"])
})
})

Expand Down
Loading