mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-17 12:56:41 +02:00
3c21735b35
Replace Bun.Glob usage with a new Glob utility wrapper around the npm 'glob' package. This moves us off Bun-specific APIs toward standard Node.js compatible solutions. Changes: - Add new src/util/glob.ts utility module with scan(), scanSync(), and match() - Default include option is 'file' (only returns files, not directories) - Add symlink option (default: false) to control symlink following - Migrate all 12 files using Bun.Glob to use the new Glob utility - Add comprehensive tests for the glob utility Breaking changes: - Removed support for include: 'dir' option (use include: 'all' and filter manually) - symlink now defaults to false (was true in most Bun.Glob usages) Files migrated: - src/util/log.ts - src/util/filesystem.ts - src/tool/truncation.ts - src/session/instruction.ts - src/storage/json-migration.ts - src/storage/storage.ts - src/project/project.ts - src/cli/cmd/tui/context/theme.tsx - src/config/config.ts - src/tool/registry.ts - src/skill/skill.ts - src/file/ignore.ts
83 lines
1.4 KiB
TypeScript
83 lines
1.4 KiB
TypeScript
import { sep } from "node:path"
|
|
import { Glob } from "../util/glob"
|
|
|
|
export namespace FileIgnore {
|
|
const FOLDERS = new Set([
|
|
"node_modules",
|
|
"bower_components",
|
|
".pnpm-store",
|
|
"vendor",
|
|
".npm",
|
|
"dist",
|
|
"build",
|
|
"out",
|
|
".next",
|
|
"target",
|
|
"bin",
|
|
"obj",
|
|
".git",
|
|
".svn",
|
|
".hg",
|
|
".vscode",
|
|
".idea",
|
|
".turbo",
|
|
".output",
|
|
"desktop",
|
|
".sst",
|
|
".cache",
|
|
".webkit-cache",
|
|
"__pycache__",
|
|
".pytest_cache",
|
|
"mypy_cache",
|
|
".history",
|
|
".gradle",
|
|
])
|
|
|
|
const FILES = [
|
|
"**/*.swp",
|
|
"**/*.swo",
|
|
|
|
"**/*.pyc",
|
|
|
|
// OS
|
|
"**/.DS_Store",
|
|
"**/Thumbs.db",
|
|
|
|
// Logs & temp
|
|
"**/logs/**",
|
|
"**/tmp/**",
|
|
"**/temp/**",
|
|
"**/*.log",
|
|
|
|
// Coverage/test outputs
|
|
"**/coverage/**",
|
|
"**/.nyc_output/**",
|
|
]
|
|
|
|
export const PATTERNS = [...FILES, ...FOLDERS]
|
|
|
|
export function match(
|
|
filepath: string,
|
|
opts?: {
|
|
extra?: string[]
|
|
whitelist?: string[]
|
|
},
|
|
) {
|
|
for (const pattern of opts?.whitelist || []) {
|
|
if (Glob.match(pattern, filepath)) return false
|
|
}
|
|
|
|
const parts = filepath.split(sep)
|
|
for (let i = 0; i < parts.length; i++) {
|
|
if (FOLDERS.has(parts[i])) return true
|
|
}
|
|
|
|
const extra = opts?.extra || []
|
|
for (const pattern of [...FILES, ...extra]) {
|
|
if (Glob.match(pattern, filepath)) return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
}
|