GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: Add centralized filesystem module for Bun.file migration (#14117) · lytedev/opencode@6b29896

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • bun.lock
  • package.json
  • packages/opencode
    • package.json
    • src/util
      • filesystem.ts
    • test
      • file
        • index.test.ts
        • time.test.ts
      • tool
        • edit.test.ts
        • write.test.ts
      • util
        • filesystem.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bun.lock‎

Copy file name to clipboardExpand all lines: bun.lock
+5Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎package.json‎

Copy file name to clipboardExpand all lines: package.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"devDependencies": {
7070
"@actions/artifact": "5.0.1",
7171
"@tsconfig/bun": "catalog:",
72+
"@types/mime-types": "3.0.1",
7273
"husky": "9.1.7",
7374
"prettier": "3.6.2",
7475
"semver": "^7.6.0",
Collapse file

‎packages/opencode/package.json‎

Copy file name to clipboardExpand all lines: packages/opencode/package.json
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@tsconfig/bun": "catalog:",
4141
"@types/babel__core": "7.20.5",
4242
"@types/bun": "catalog:",
43+
"@types/mime-types": "3.0.1",
4344
"@types/turndown": "5.0.5",
4445
"@types/yargs": "17.0.33",
4546
"@typescript/native-preview": "catalog:",
@@ -110,6 +111,7 @@
110111
"hono-openapi": "catalog:",
111112
"ignore": "7.0.5",
112113
"jsonc-parser": "3.3.1",
114+
"mime-types": "3.0.2",
113115
"minimatch": "10.0.3",
114116
"open": "10.1.2",
115117
"opentui-spinner": "0.0.6",
Collapse file

‎packages/opencode/src/util/filesystem.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/util/filesystem.ts
+70-11Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,76 @@
1+
import { mkdir, readFile, writeFile } from "fs/promises"
2+
import { existsSync, statSync } from "fs"
3+
import { lookup } from "mime-types"
14
import { realpathSync } from "fs"
25
import { dirname, join, relative } from "path"
36

47
export namespace Filesystem {
5-
export const exists = (p: string) =>
6-
Bun.file(p)
7-
.stat()
8-
.then(() => true)
9-
.catch(() => false)
10-
11-
export const isDir = (p: string) =>
12-
Bun.file(p)
13-
.stat()
14-
.then((s) => s.isDirectory())
15-
.catch(() => false)
8+
// Fast sync version for metadata checks
9+
export async function exists(p: string): Promise<boolean> {
10+
return existsSync(p)
11+
}
12+
13+
export async function isDir(p: string): Promise<boolean> {
14+
try {
15+
return statSync(p).isDirectory()
16+
} catch {
17+
return false
18+
}
19+
}
20+
21+
export async function size(p: string): Promise<number> {
22+
try {
23+
return statSync(p).size
24+
} catch {
25+
return 0
26+
}
27+
}
28+
29+
export async function readText(p: string): Promise<string> {
30+
return readFile(p, "utf-8")
31+
}
32+
33+
export async function readJson<T>(p: string): Promise<T> {
34+
return JSON.parse(await readFile(p, "utf-8"))
35+
}
36+
37+
export async function readBytes(p: string): Promise<Buffer> {
38+
return readFile(p)
39+
}
40+
41+
function isEnoent(e: unknown): e is { code: "ENOENT" } {
42+
return typeof e === "object" && e !== null && "code" in e && (e as { code: string }).code === "ENOENT"
43+
}
44+
45+
export async function write(p: string, content: string | Buffer, mode?: number): Promise<void> {
46+
try {
47+
if (mode) {
48+
await writeFile(p, content, { mode })
49+
} else {
50+
await writeFile(p, content)
51+
}
52+
} catch (e) {
53+
if (isEnoent(e)) {
54+
await mkdir(dirname(p), { recursive: true })
55+
if (mode) {
56+
await writeFile(p, content, { mode })
57+
} else {
58+
await writeFile(p, content)
59+
}
60+
return
61+
}
62+
throw e
63+
}
64+
}
65+
66+
export async function writeJson(p: string, data: unknown, mode?: number): Promise<void> {
67+
return write(p, JSON.stringify(data, null, 2), mode)
68+
}
69+
70+
export function mimeType(p: string): string {
71+
return lookup(p) || "application/octet-stream"
72+
}
73+
1674
/**
1775
* On Windows, normalize a path to its canonical casing using the filesystem.
1876
* This is needed because Windows paths are case-insensitive but LSP servers
@@ -26,6 +84,7 @@ export namespace Filesystem {
2684
return p
2785
}
2886
}
87+
2988
export function overlaps(a: string, b: string) {
3089
const relA = relative(a, b)
3190
const relB = relative(b, a)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.