diff options
| author | Adam <[email protected]> | 2025-08-28 10:49:40 -0500 |
|---|---|---|
| committer | Adam <[email protected]> | 2025-08-28 10:49:45 -0500 |
| commit | aa9ab0a30452f8ee0cc7dd0d5d170600bad26f8a (patch) | |
| tree | 776985b1aaa0b7b084a4a71e613d4357719b6ded /packages | |
| parent | 4331d77b9e153fcaa737e02e846759c8e648ad6f (diff) | |
| download | opencode-aa9ab0a30452f8ee0cc7dd0d5d170600bad26f8a.tar.gz opencode-aa9ab0a30452f8ee0cc7dd0d5d170600bad26f8a.zip | |
feat: include ignored files
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/opencode/package.json | 1 | ||||
| -rw-r--r-- | packages/opencode/src/file/index.ts | 19 | ||||
| -rw-r--r-- | packages/sdk/js/src/gen/types.gen.ts | 1 |
3 files changed, 18 insertions, 3 deletions
diff --git a/packages/opencode/package.json b/packages/opencode/package.json index 6f5b6fc57..5e80b480b 100644 --- a/packages/opencode/package.json +++ b/packages/opencode/package.json @@ -41,6 +41,7 @@ "gray-matter": "4.0.3", "hono": "catalog:", "hono-openapi": "0.4.8", + "ignore": "7.0.5", "isomorphic-git": "1.32.1", "jsonc-parser": "3.3.1", "minimatch": "10.0.3", diff --git a/packages/opencode/src/file/index.ts b/packages/opencode/src/file/index.ts index 7613e920d..40e0c2cfc 100644 --- a/packages/opencode/src/file/index.ts +++ b/packages/opencode/src/file/index.ts @@ -6,6 +6,7 @@ import path from "path" import * as git from "isomorphic-git" import { App } from "../app/app" import fs from "fs" +import ignore from "ignore" import { Log } from "../util/log" export namespace File { @@ -29,6 +30,7 @@ export namespace File { name: z.string(), path: z.string(), type: z.enum(["file", "directory"]), + ignored: z.boolean(), }) .openapi({ ref: "FileNode", @@ -133,18 +135,29 @@ export namespace File { } export async function list(dir?: string) { - const ignore = [".git", ".DS_Store"] + const exclude = [".git", ".DS_Store"] const app = App.info() + let ignored = (_: string) => false + if (app.git) { + const gitignore = Bun.file(path.join(app.path.root, ".gitignore")) + if (await gitignore.exists()) { + const ig = ignore().add(await gitignore.text()) + ignored = ig.ignores.bind(ig) + } + } const resolved = dir ? path.join(app.path.cwd, dir) : app.path.cwd const nodes: Node[] = [] for (const entry of await fs.promises.readdir(resolved, { withFileTypes: true })) { - if (ignore.includes(entry.name)) continue + if (exclude.includes(entry.name)) continue const fullPath = path.join(resolved, entry.name) const relativePath = path.relative(app.path.cwd, fullPath) + const relativeToRoot = path.relative(app.path.root, fullPath) + const type = entry.isDirectory() ? "directory" : "file" nodes.push({ name: entry.name, path: relativePath, - type: entry.isDirectory() ? "directory" : "file", + type, + ignored: ignored(type === "directory" ? relativeToRoot + "/" : relativeToRoot), }) } return nodes.sort((a, b) => { diff --git a/packages/sdk/js/src/gen/types.gen.ts b/packages/sdk/js/src/gen/types.gen.ts index 5043f9688..c6e7fedb2 100644 --- a/packages/sdk/js/src/gen/types.gen.ts +++ b/packages/sdk/js/src/gen/types.gen.ts @@ -1142,6 +1142,7 @@ export type FileNode = { name: string path: string type: "file" | "directory" + ignored: boolean } export type File = { |
