GeezerVison is showing github.com — refactor: migrate from Bun.Glob to npm glob package · lytedev/opencode@3c21735
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: bun.lock +10-8Lines changed: 10 additions & 8 deletions Collapse file Copy file name to clipboardExpand all lines: package.json +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 70 | 70 | "@actions/artifact": "5.0.1", | 71 | 71 | "@tsconfig/bun": "catalog:", | 72 | 72 | "@types/mime-types": "3.0.1", | | 73 | + "glob": "13.0.5", | 73 | 74 | "husky": "9.1.7", | 74 | 75 | "prettier": "3.6.2", | 75 | 76 | "semver": "^7.6.0", | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/package.json +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 107 | 107 | "diff": "catalog:", | 108 | 108 | "drizzle-orm": "1.0.0-beta.12-a5629fb", | 109 | 109 | "fuzzysort": "3.1.0", | | 110 | + "glob": "13.0.5", | 110 | 111 | "google-auth-library": "10.5.0", | 111 | 112 | "gray-matter": "4.0.3", | 112 | 113 | "hono": "catalog:", | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/context/theme.tsx +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import path from "path" | 3 | 3 | import { createEffect, createMemo, onMount } from "solid-js" | 4 | 4 | import { useSync } from "@tui/context/sync" | 5 | 5 | import { createSimpleContext } from "./helper" | | 6 | +import { Glob } from "../../../../util/glob" | 6 | 7 | import aura from "./theme/aura.json" with { type: "json" } | 7 | 8 | import ayu from "./theme/ayu.json" with { type: "json" } | 8 | 9 | import catppuccin from "./theme/catppuccin.json" with { type: "json" } | @@ -391,7 +392,6 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({ | 391 | 392 | }, | 392 | 393 | }) | 393 | 394 |
| 394 | | -const CUSTOM_THEME_GLOB = new Bun.Glob("themes/*.json") | 395 | 395 | async function getCustomThemes() { | 396 | 396 | const directories = [ | 397 | 397 | Global.Path.config, | @@ -405,11 +405,10 @@ async function getCustomThemes() { | 405 | 405 |
| 406 | 406 | const result: Record<string, ThemeJson> = {} | 407 | 407 | for (const dir of directories) { | 408 | | - for await (const item of CUSTOM_THEME_GLOB.scan({ | | 408 | + for (const item of await Glob.scan("themes/*.json", { | | 409 | + cwd: dir, | 409 | 410 | absolute: true, | 410 | | - followSymlinks: true, | 411 | 411 | dot: true, | 412 | | - cwd: dir, | 413 | 412 | })) { | 414 | 413 | const name = path.basename(item, ".json") | 415 | 414 | result[name] = await Filesystem.readJson(item) | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/config/config.ts +9-16Lines changed: 9 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,6 +28,7 @@ import { constants, existsSync } from "fs" | 28 | 28 | import { Bus } from "@/bus" | 29 | 29 | import { GlobalBus } from "@/bus/global" | 30 | 30 | import { Event } from "../server/event" | | 31 | +import { Glob } from "../util/glob" | 31 | 32 | import { PackageRegistry } from "@/bun/registry" | 32 | 33 | import { proxied } from "@/util/proxied" | 33 | 34 | import { iife } from "@/util/iife" | @@ -351,14 +352,12 @@ export namespace Config { | 351 | 352 | return ext.length ? file.slice(0, -ext.length) : file | 352 | 353 | } | 353 | 354 |
| 354 | | - const COMMAND_GLOB = new Bun.Glob("{command,commands}/**/*.md") | 355 | 355 | async function loadCommand(dir: string) { | 356 | 356 | const result: Record<string, Command> = {} | 357 | | - for await (const item of COMMAND_GLOB.scan({ | | 357 | + for (const item of await Glob.scan("{command,commands}/**/*.md", { | | 358 | + cwd: dir, | 358 | 359 | absolute: true, | 359 | | - followSymlinks: true, | 360 | 360 | dot: true, | 361 | | - cwd: dir, | 362 | 361 | })) { | 363 | 362 | const md = await ConfigMarkdown.parse(item).catch(async (err) => { | 364 | 363 | const message = ConfigMarkdown.FrontmatterError.isInstance(err) | @@ -390,15 +389,13 @@ export namespace Config { | 390 | 389 | return result | 391 | 390 | } | 392 | 391 |
| 393 | | - const AGENT_GLOB = new Bun.Glob("{agent,agents}/**/*.md") | 394 | 392 | async function loadAgent(dir: string) { | 395 | 393 | const result: Record<string, Agent> = {} | 396 | 394 |
| 397 | | - for await (const item of AGENT_GLOB.scan({ | | 395 | + for (const item of await Glob.scan("{agent,agents}/**/*.md", { | | 396 | + cwd: dir, | 398 | 397 | absolute: true, | 399 | | - followSymlinks: true, | 400 | 398 | dot: true, | 401 | | - cwd: dir, | 402 | 399 | })) { | 403 | 400 | const md = await ConfigMarkdown.parse(item).catch(async (err) => { | 404 | 401 | const message = ConfigMarkdown.FrontmatterError.isInstance(err) | @@ -430,14 +427,12 @@ export namespace Config { | 430 | 427 | return result | 431 | 428 | } | 432 | 429 |
| 433 | | - const MODE_GLOB = new Bun.Glob("{mode,modes}/*.md") | 434 | 430 | async function loadMode(dir: string) { | 435 | 431 | const result: Record<string, Agent> = {} | 436 | | - for await (const item of MODE_GLOB.scan({ | | 432 | + for (const item of await Glob.scan("{mode,modes}/*.md", { | | 433 | + cwd: dir, | 437 | 434 | absolute: true, | 438 | | - followSymlinks: true, | 439 | 435 | dot: true, | 440 | | - cwd: dir, | 441 | 436 | })) { | 442 | 437 | const md = await ConfigMarkdown.parse(item).catch(async (err) => { | 443 | 438 | const message = ConfigMarkdown.FrontmatterError.isInstance(err) | @@ -467,15 +462,13 @@ export namespace Config { | 467 | 462 | return result | 468 | 463 | } | 469 | 464 |
| 470 | | - const PLUGIN_GLOB = new Bun.Glob("{plugin,plugins}/*.{ts,js}") | 471 | 465 | async function loadPlugin(dir: string) { | 472 | 466 | const plugins: string[] = [] | 473 | 467 |
| 474 | | - for await (const item of PLUGIN_GLOB.scan({ | | 468 | + for (const item of await Glob.scan("{plugin,plugins}/*.{ts,js}", { | | 469 | + cwd: dir, | 475 | 470 | absolute: true, | 476 | | - followSymlinks: true, | 477 | 471 | dot: true, | 478 | | - cwd: dir, | 479 | 472 | })) { | 480 | 473 | plugins.push(pathToFileURL(item).href) | 481 | 474 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/file/ignore.ts +7-8Lines changed: 7 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { sep } from "node:path" | | 2 | +import { Glob } from "../util/glob" | 2 | 3 |
| 3 | 4 | export namespace FileIgnore { | 4 | 5 | const FOLDERS = new Set([ | @@ -53,19 +54,17 @@ export namespace FileIgnore { | 53 | 54 | "**/.nyc_output/**", | 54 | 55 | ] | 55 | 56 |
| 56 | | - const FILE_GLOBS = FILES.map((p) => new Bun.Glob(p)) | 57 | | - | 58 | 57 | export const PATTERNS = [...FILES, ...FOLDERS] | 59 | 58 |
| 60 | 59 | export function match( | 61 | 60 | filepath: string, | 62 | 61 | opts?: { | 63 | | - extra?: Bun.Glob[] | 64 | | - whitelist?: Bun.Glob[] | | 62 | + extra?: string[] | | 63 | + whitelist?: string[] | 65 | 64 | }, | 66 | 65 | ) { | 67 | | - for (const glob of opts?.whitelist || []) { | 68 | | - if (glob.match(filepath)) return false | | 66 | + for (const pattern of opts?.whitelist || []) { | | 67 | + if (Glob.match(pattern, filepath)) return false | 69 | 68 | } | 70 | 69 |
| 71 | 70 | const parts = filepath.split(sep) | @@ -74,8 +73,8 @@ export namespace FileIgnore { | 74 | 73 | } | 75 | 74 |
| 76 | 75 | const extra = opts?.extra || [] | 77 | | - for (const glob of [...FILE_GLOBS, ...extra]) { | 78 | | - if (glob.match(filepath)) return true | | 76 | + for (const pattern of [...FILES, ...extra]) { | | 77 | + if (Glob.match(pattern, filepath)) return true | 79 | 78 | } | 80 | 79 |
| 81 | 80 | return false | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/project/project.ts +6-10Lines changed: 6 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,7 @@ import { iife } from "@/util/iife" | 13 | 13 | import { GlobalBus } from "@/bus/global" | 14 | 14 | import { existsSync } from "fs" | 15 | 15 | import { git } from "../util/git" | | 16 | +import { Glob } from "../util/glob" | 16 | 17 |
| 17 | 18 | export namespace Project { | 18 | 19 | const log = Log.create({ service: "project" }) | @@ -262,16 +263,11 @@ export namespace Project { | 262 | 263 | if (input.vcs !== "git") return | 263 | 264 | if (input.icon?.override) return | 264 | 265 | if (input.icon?.url) return | 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 | | - ) | | 266 | + const matches = await Glob.scan("**/{favicon}.{ico,png,svg,jpg,jpeg,webp}", { | | 267 | + cwd: input.worktree, | | 268 | + absolute: true, | | 269 | + include: "file", | | 270 | + }) | 275 | 271 | const shortest = matches.sort((a, b) => a.length - b.length)[0] | 276 | 272 | if (!shortest) return | 277 | 273 | const buffer = await Filesystem.readBytes(shortest) | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/session/instruction.ts +6-7Lines changed: 6 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@ import { Config } from "../config/config" | 6 | 6 | import { Instance } from "../project/instance" | 7 | 7 | import { Flag } from "@/flag/flag" | 8 | 8 | import { Log } from "../util/log" | | 9 | +import { Glob } from "../util/glob" | 9 | 10 | import type { MessageV2 } from "./message-v2" | 10 | 11 |
| 11 | 12 | const log = Log.create({ service: "instruction" }) | @@ -98,13 +99,11 @@ export namespace InstructionPrompt { | 98 | 99 | instruction = path.join(os.homedir(), instruction.slice(2)) | 99 | 100 | } | 100 | 101 | const matches = path.isAbsolute(instruction) | 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(() => []) | | 102 | + ? await Glob.scan(path.basename(instruction), { | | 103 | + cwd: path.dirname(instruction), | | 104 | + absolute: true, | | 105 | + include: "file", | | 106 | + }).catch(() => []) | 108 | 107 | : await resolveRelative(instruction) | 109 | 108 | matches.forEach((p) => { | 110 | 109 | paths.add(path.resolve(p)) | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/skill/skill.ts +22-25Lines changed: 22 additions & 25 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,7 @@ import { Flag } from "@/flag/flag" | 12 | 12 | import { Bus } from "@/bus" | 13 | 13 | import { Session } from "@/session" | 14 | 14 | import { Discovery } from "./discovery" | | 15 | +import { Glob } from "../util/glob" | 15 | 16 |
| 16 | 17 | export namespace Skill { | 17 | 18 | const log = Log.create({ service: "skill" }) | @@ -44,10 +45,9 @@ export namespace Skill { | 44 | 45 | // External skill directories to search for (project-level and global) | 45 | 46 | // These follow the directory layout used by Claude Code and other agents. | 46 | 47 | const EXTERNAL_DIRS = [".claude", ".agents"] | 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") | | 48 | + const EXTERNAL_SKILL_PATTERN = "skills/**/SKILL.md" | | 49 | + const OPENCODE_SKILL_PATTERN = "{skill,skills}/**/SKILL.md" | | 50 | + const SKILL_PATTERN = "**/SKILL.md" | 51 | 51 |
| 52 | 52 | export const state = Instance.state(async () => { | 53 | 53 | const skills: Record<string, Info> = {} | @@ -88,15 +88,12 @@ export namespace Skill { | 88 | 88 | } | 89 | 89 |
| 90 | 90 | const scanExternal = async (root: string, scope: "global" | "project") => { | 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 | | - ) | | 91 | + return Glob.scan(EXTERNAL_SKILL_PATTERN, { | | 92 | + cwd: root, | | 93 | + absolute: true, | | 94 | + include: "file", | | 95 | + dot: true, | | 96 | + }) | 100 | 97 | .then((matches) => Promise.all(matches.map(addSkill))) | 101 | 98 | .catch((error) => { | 102 | 99 | log.error(`failed to scan ${scope} skills`, { dir: root, error }) | @@ -123,12 +120,12 @@ export namespace Skill { | 123 | 120 |
| 124 | 121 | // Scan .opencode/skill/ directories | 125 | 122 | for (const dir of await Config.directories()) { | 126 | | - for await (const match of OPENCODE_SKILL_GLOB.scan({ | | 123 | + const matches = await Glob.scan(OPENCODE_SKILL_PATTERN, { | 127 | 124 | cwd: dir, | 128 | 125 | absolute: true, | 129 | | - onlyFiles: true, | 130 | | - followSymlinks: true, | 131 | | - })) { | | 126 | + include: "file", | | 127 | + }) | | 128 | + for (const match of matches) { | 132 | 129 | await addSkill(match) | 133 | 130 | } | 134 | 131 | } | @@ -142,12 +139,12 @@ export namespace Skill { | 142 | 139 | log.warn("skill path not found", { path: resolved }) | 143 | 140 | continue | 144 | 141 | } | 145 | | - for await (const match of SKILL_GLOB.scan({ | | 142 | + const matches = await Glob.scan(SKILL_PATTERN, { | 146 | 143 | cwd: resolved, | 147 | 144 | absolute: true, | 148 | | - onlyFiles: true, | 149 | | - followSymlinks: true, | 150 | | - })) { | | 145 | + include: "file", | | 146 | + }) | | 147 | + for (const match of matches) { | 151 | 148 | await addSkill(match) | 152 | 149 | } | 153 | 150 | } | @@ -157,12 +154,12 @@ export namespace Skill { | 157 | 154 | const list = await Discovery.pull(url) | 158 | 155 | for (const dir of list) { | 159 | 156 | dirs.add(dir) | 160 | | - for await (const match of SKILL_GLOB.scan({ | | 157 | + const matches = await Glob.scan(SKILL_PATTERN, { | 161 | 158 | cwd: dir, | 162 | 159 | absolute: true, | 163 | | - onlyFiles: true, | 164 | | - followSymlinks: true, | 165 | | - })) { | | 160 | + include: "file", | | 161 | + }) | | 162 | + for (const match of matches) { | 166 | 163 | await addSkill(match) | 167 | 164 | } | 168 | 165 | } | |
|