Skip to content

Commit af72010

Browse files
committed
Revert "refactor: migrate from Bun.Glob to npm glob package"
This reverts commit 3c21735.
1 parent 50883cc commit af72010

File tree

17 files changed

+122
-226
lines changed

17 files changed

+122
-226
lines changed

bun.lock

Lines changed: 8 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
"@actions/artifact": "5.0.1",
7171
"@tsconfig/bun": "catalog:",
7272
"@types/mime-types": "3.0.1",
73-
"glob": "13.0.5",
7473
"husky": "9.1.7",
7574
"prettier": "3.6.2",
7675
"semver": "^7.6.0",

packages/opencode/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
"diff": "catalog:",
108108
"drizzle-orm": "1.0.0-beta.12-a5629fb",
109109
"fuzzysort": "3.1.0",
110-
"glob": "13.0.5",
111110
"google-auth-library": "10.5.0",
112111
"gray-matter": "4.0.3",
113112
"hono": "catalog:",

packages/opencode/src/cli/cmd/tui/context/theme.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import path from "path"
33
import { createEffect, createMemo, onMount } from "solid-js"
44
import { useSync } from "@tui/context/sync"
55
import { createSimpleContext } from "./helper"
6-
import { Glob } from "../../../../util/glob"
76
import aura from "./theme/aura.json" with { type: "json" }
87
import ayu from "./theme/ayu.json" with { type: "json" }
98
import catppuccin from "./theme/catppuccin.json" with { type: "json" }
@@ -392,6 +391,7 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
392391
},
393392
})
394393

394+
const CUSTOM_THEME_GLOB = new Bun.Glob("themes/*.json")
395395
async function getCustomThemes() {
396396
const directories = [
397397
Global.Path.config,
@@ -405,10 +405,11 @@ async function getCustomThemes() {
405405

406406
const result: Record<string, ThemeJson> = {}
407407
for (const dir of directories) {
408-
for (const item of await Glob.scan("themes/*.json", {
409-
cwd: dir,
408+
for await (const item of CUSTOM_THEME_GLOB.scan({
410409
absolute: true,
410+
followSymlinks: true,
411411
dot: true,
412+
cwd: dir,
412413
})) {
413414
const name = path.basename(item, ".json")
414415
result[name] = await Filesystem.readJson(item)

packages/opencode/src/config/config.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { constants, existsSync } from "fs"
2828
import { Bus } from "@/bus"
2929
import { GlobalBus } from "@/bus/global"
3030
import { Event } from "../server/event"
31-
import { Glob } from "../util/glob"
3231
import { PackageRegistry } from "@/bun/registry"
3332
import { proxied } from "@/util/proxied"
3433
import { iife } from "@/util/iife"
@@ -352,12 +351,14 @@ export namespace Config {
352351
return ext.length ? file.slice(0, -ext.length) : file
353352
}
354353

354+
const COMMAND_GLOB = new Bun.Glob("{command,commands}/**/*.md")
355355
async function loadCommand(dir: string) {
356356
const result: Record<string, Command> = {}
357-
for (const item of await Glob.scan("{command,commands}/**/*.md", {
358-
cwd: dir,
357+
for await (const item of COMMAND_GLOB.scan({
359358
absolute: true,
359+
followSymlinks: true,
360360
dot: true,
361+
cwd: dir,
361362
})) {
362363
const md = await ConfigMarkdown.parse(item).catch(async (err) => {
363364
const message = ConfigMarkdown.FrontmatterError.isInstance(err)
@@ -389,13 +390,15 @@ export namespace Config {
389390
return result
390391
}
391392

393+
const AGENT_GLOB = new Bun.Glob("{agent,agents}/**/*.md")
392394
async function loadAgent(dir: string) {
393395
const result: Record<string, Agent> = {}
394396

395-
for (const item of await Glob.scan("{agent,agents}/**/*.md", {
396-
cwd: dir,
397+
for await (const item of AGENT_GLOB.scan({
397398
absolute: true,
399+
followSymlinks: true,
398400
dot: true,
401+
cwd: dir,
399402
})) {
400403
const md = await ConfigMarkdown.parse(item).catch(async (err) => {
401404
const message = ConfigMarkdown.FrontmatterError.isInstance(err)
@@ -427,12 +430,14 @@ export namespace Config {
427430
return result
428431
}
429432

433+
const MODE_GLOB = new Bun.Glob("{mode,modes}/*.md")
430434
async function loadMode(dir: string) {
431435
const result: Record<string, Agent> = {}
432-
for (const item of await Glob.scan("{mode,modes}/*.md", {
433-
cwd: dir,
436+
for await (const item of MODE_GLOB.scan({
434437
absolute: true,
438+
followSymlinks: true,
435439
dot: true,
440+
cwd: dir,
436441
})) {
437442
const md = await ConfigMarkdown.parse(item).catch(async (err) => {
438443
const message = ConfigMarkdown.FrontmatterError.isInstance(err)
@@ -462,13 +467,15 @@ export namespace Config {
462467
return result
463468
}
464469

470+
const PLUGIN_GLOB = new Bun.Glob("{plugin,plugins}/*.{ts,js}")
465471
async function loadPlugin(dir: string) {
466472
const plugins: string[] = []
467473

468-
for (const item of await Glob.scan("{plugin,plugins}/*.{ts,js}", {
469-
cwd: dir,
474+
for await (const item of PLUGIN_GLOB.scan({
470475
absolute: true,
476+
followSymlinks: true,
471477
dot: true,
478+
cwd: dir,
472479
})) {
473480
plugins.push(pathToFileURL(item).href)
474481
}

packages/opencode/src/file/ignore.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { sep } from "node:path"
2-
import { Glob } from "../util/glob"
32

43
export namespace FileIgnore {
54
const FOLDERS = new Set([
@@ -54,17 +53,19 @@ export namespace FileIgnore {
5453
"**/.nyc_output/**",
5554
]
5655

56+
const FILE_GLOBS = FILES.map((p) => new Bun.Glob(p))
57+
5758
export const PATTERNS = [...FILES, ...FOLDERS]
5859

5960
export function match(
6061
filepath: string,
6162
opts?: {
62-
extra?: string[]
63-
whitelist?: string[]
63+
extra?: Bun.Glob[]
64+
whitelist?: Bun.Glob[]
6465
},
6566
) {
66-
for (const pattern of opts?.whitelist || []) {
67-
if (Glob.match(pattern, filepath)) return false
67+
for (const glob of opts?.whitelist || []) {
68+
if (glob.match(filepath)) return false
6869
}
6970

7071
const parts = filepath.split(sep)
@@ -73,8 +74,8 @@ export namespace FileIgnore {
7374
}
7475

7576
const extra = opts?.extra || []
76-
for (const pattern of [...FILES, ...extra]) {
77-
if (Glob.match(pattern, filepath)) return true
77+
for (const glob of [...FILE_GLOBS, ...extra]) {
78+
if (glob.match(filepath)) return true
7879
}
7980

8081
return false

packages/opencode/src/project/project.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { iife } from "@/util/iife"
1313
import { GlobalBus } from "@/bus/global"
1414
import { existsSync } from "fs"
1515
import { git } from "../util/git"
16-
import { Glob } from "../util/glob"
1716

1817
export namespace Project {
1918
const log = Log.create({ service: "project" })
@@ -263,11 +262,16 @@ export namespace Project {
263262
if (input.vcs !== "git") return
264263
if (input.icon?.override) return
265264
if (input.icon?.url) return
266-
const matches = await Glob.scan("**/{favicon}.{ico,png,svg,jpg,jpeg,webp}", {
267-
cwd: input.worktree,
268-
absolute: true,
269-
include: "file",
270-
})
265+
const glob = new Bun.Glob("**/{favicon}.{ico,png,svg,jpg,jpeg,webp}")
266+
const matches = await Array.fromAsync(
267+
glob.scan({
268+
cwd: input.worktree,
269+
absolute: true,
270+
onlyFiles: true,
271+
followSymlinks: false,
272+
dot: false,
273+
}),
274+
)
271275
const shortest = matches.sort((a, b) => a.length - b.length)[0]
272276
if (!shortest) return
273277
const buffer = await Filesystem.readBytes(shortest)

packages/opencode/src/session/instruction.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Config } from "../config/config"
66
import { Instance } from "../project/instance"
77
import { Flag } from "@/flag/flag"
88
import { Log } from "../util/log"
9-
import { Glob } from "../util/glob"
109
import type { MessageV2 } from "./message-v2"
1110

1211
const log = Log.create({ service: "instruction" })
@@ -99,11 +98,13 @@ export namespace InstructionPrompt {
9998
instruction = path.join(os.homedir(), instruction.slice(2))
10099
}
101100
const matches = path.isAbsolute(instruction)
102-
? await Glob.scan(path.basename(instruction), {
103-
cwd: path.dirname(instruction),
104-
absolute: true,
105-
include: "file",
106-
}).catch(() => [])
101+
? await Array.fromAsync(
102+
new Bun.Glob(path.basename(instruction)).scan({
103+
cwd: path.dirname(instruction),
104+
absolute: true,
105+
onlyFiles: true,
106+
}),
107+
).catch(() => [])
107108
: await resolveRelative(instruction)
108109
matches.forEach((p) => {
109110
paths.add(path.resolve(p))

packages/opencode/src/skill/skill.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { Flag } from "@/flag/flag"
1212
import { Bus } from "@/bus"
1313
import { Session } from "@/session"
1414
import { Discovery } from "./discovery"
15-
import { Glob } from "../util/glob"
1615

1716
export namespace Skill {
1817
const log = Log.create({ service: "skill" })
@@ -45,9 +44,10 @@ export namespace Skill {
4544
// External skill directories to search for (project-level and global)
4645
// These follow the directory layout used by Claude Code and other agents.
4746
const EXTERNAL_DIRS = [".claude", ".agents"]
48-
const EXTERNAL_SKILL_PATTERN = "skills/**/SKILL.md"
49-
const OPENCODE_SKILL_PATTERN = "{skill,skills}/**/SKILL.md"
50-
const SKILL_PATTERN = "**/SKILL.md"
47+
const EXTERNAL_SKILL_GLOB = new Bun.Glob("skills/**/SKILL.md")
48+
49+
const OPENCODE_SKILL_GLOB = new Bun.Glob("{skill,skills}/**/SKILL.md")
50+
const SKILL_GLOB = new Bun.Glob("**/SKILL.md")
5151

5252
export const state = Instance.state(async () => {
5353
const skills: Record<string, Info> = {}
@@ -88,12 +88,15 @@ export namespace Skill {
8888
}
8989

9090
const scanExternal = async (root: string, scope: "global" | "project") => {
91-
return Glob.scan(EXTERNAL_SKILL_PATTERN, {
92-
cwd: root,
93-
absolute: true,
94-
include: "file",
95-
dot: true,
96-
})
91+
return Array.fromAsync(
92+
EXTERNAL_SKILL_GLOB.scan({
93+
cwd: root,
94+
absolute: true,
95+
onlyFiles: true,
96+
followSymlinks: true,
97+
dot: true,
98+
}),
99+
)
97100
.then((matches) => Promise.all(matches.map(addSkill)))
98101
.catch((error) => {
99102
log.error(`failed to scan ${scope} skills`, { dir: root, error })
@@ -120,12 +123,12 @@ export namespace Skill {
120123

121124
// Scan .opencode/skill/ directories
122125
for (const dir of await Config.directories()) {
123-
const matches = await Glob.scan(OPENCODE_SKILL_PATTERN, {
126+
for await (const match of OPENCODE_SKILL_GLOB.scan({
124127
cwd: dir,
125128
absolute: true,
126-
include: "file",
127-
})
128-
for (const match of matches) {
129+
onlyFiles: true,
130+
followSymlinks: true,
131+
})) {
129132
await addSkill(match)
130133
}
131134
}
@@ -139,12 +142,12 @@ export namespace Skill {
139142
log.warn("skill path not found", { path: resolved })
140143
continue
141144
}
142-
const matches = await Glob.scan(SKILL_PATTERN, {
145+
for await (const match of SKILL_GLOB.scan({
143146
cwd: resolved,
144147
absolute: true,
145-
include: "file",
146-
})
147-
for (const match of matches) {
148+
onlyFiles: true,
149+
followSymlinks: true,
150+
})) {
148151
await addSkill(match)
149152
}
150153
}
@@ -154,12 +157,12 @@ export namespace Skill {
154157
const list = await Discovery.pull(url)
155158
for (const dir of list) {
156159
dirs.add(dir)
157-
const matches = await Glob.scan(SKILL_PATTERN, {
160+
for await (const match of SKILL_GLOB.scan({
158161
cwd: dir,
159162
absolute: true,
160-
include: "file",
161-
})
162-
for (const match of matches) {
163+
onlyFiles: true,
164+
followSymlinks: true,
165+
})) {
163166
await addSkill(match)
164167
}
165168
}

0 commit comments

Comments
 (0)