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