Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/opencode/src/project/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ const disposal = {

export const Instance = {
async provide<R>(input: { directory: string; init?: () => Promise<any>; fn: () => R }): Promise<R> {
let existing = cache.get(input.directory)
const directory = Filesystem.canonical(input.directory)
let existing = cache.get(directory)
if (!existing) {
Log.Default.info("creating instance", { directory: input.directory })
Log.Default.info("creating instance", { directory })
existing = iife(async () => {
const { project, sandbox } = await Project.fromDirectory(input.directory)
const { project, sandbox } = await Project.fromDirectory(directory)
const ctx = {
directory: input.directory,
directory,
worktree: sandbox,
project,
}
Expand All @@ -35,7 +36,7 @@ export const Instance = {
})
return ctx
})
cache.set(input.directory, existing)
cache.set(directory, existing)
}
const ctx = await existing
return context.provide(ctx, async () => {
Expand Down
15 changes: 14 additions & 1 deletion packages/opencode/src/util/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { chmod, mkdir, readFile, writeFile } from "fs/promises"
import { createWriteStream, existsSync, statSync } from "fs"
import { lookup } from "mime-types"
import { realpathSync } from "fs"
import { dirname, join, relative } from "path"
import { dirname, join, normalize, relative, resolve } from "path"
import { Readable } from "stream"
import { pipeline } from "stream/promises"
import { Glob } from "./glob"
Expand Down Expand Up @@ -113,6 +113,19 @@ export namespace Filesystem {
}
}

export function canonical(p: string): string {
const abs = normalize(resolve(p))
const real = (() => {
try {
return normalize(realpathSync.native(abs))
} catch {
return abs
}
})()
if (process.platform === "win32") return real.toLowerCase()
return real
}

export function windowsPath(p: string): string {
if (process.platform !== "win32") return p
return (
Expand Down
Loading