Skip to content

Commit 54aa025

Browse files
committed
Merge branch 'shuvcode-dev' into integration
Remove .deps-installed.json marker file to match upstream behavior. Simplifies installDependencies() by removing caching mechanism that was dropping files in user project directories. Closes #253
2 parents bb47706 + 31efdbc commit 54aa025

File tree

2 files changed

+18
-104
lines changed

2 files changed

+18
-104
lines changed

packages/opencode/src/config/config.ts

Lines changed: 17 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -165,85 +165,30 @@ export namespace Config {
165165
}
166166
}
167167

168-
// Per-directory install locks to serialize concurrent installs
169-
const installLocks = new Map<string, Promise<void>>()
170-
171-
// Marker file schema for tracking installed dependencies
172-
const DepsInstalledMarker = z.object({
173-
version: z.string(),
174-
timestamp: z.number(),
175-
})
176-
177168
async function installDependencies(dir: string) {
178-
// Wait for any ongoing install in this directory to complete
179-
const existingLock = installLocks.get(dir)
180-
if (existingLock) {
181-
await existingLock
182-
return
183-
}
169+
if (Installation.isLocal()) return
184170

185-
// Create a new lock for this directory
186-
let resolveLock: () => void
187-
const lockPromise = new Promise<void>((resolve) => {
188-
resolveLock = resolve
189-
})
190-
installLocks.set(dir, lockPromise)
191-
192-
try {
193-
const markerPath = path.join(dir, ".deps-installed.json")
194-
const targetVersion = Installation.isLocal() ? "latest" : Installation.BASE_VERSION
195-
196-
// Check if dependencies are already installed with correct version
197-
try {
198-
const markerContent = await Bun.file(markerPath).text()
199-
const marker = DepsInstalledMarker.parse(JSON.parse(markerContent))
200-
if (marker.version === targetVersion) {
201-
log.debug("dependencies already installed", { dir, version: marker.version })
202-
return
203-
}
204-
} catch {
205-
// Marker doesn't exist or is invalid, proceed with install
206-
}
171+
const pkg = path.join(dir, "package.json")
207172

208-
const pkg = path.join(dir, "package.json")
209-
210-
if (!(await Bun.file(pkg).exists())) {
211-
await Bun.write(pkg, "{}")
212-
}
173+
if (!(await Bun.file(pkg).exists())) {
174+
await Bun.write(pkg, "{}")
175+
}
213176

214-
const gitignore = path.join(dir, ".gitignore")
215-
const hasGitIgnore = await Bun.file(gitignore).exists()
216-
if (!hasGitIgnore) {
217-
await Bun.write(
218-
gitignore,
219-
["node_modules", "package.json", "bun.lock", ".gitignore", ".deps-installed.json"].join("\n"),
220-
)
221-
}
177+
const gitignore = path.join(dir, ".gitignore")
178+
const hasGitIgnore = await Bun.file(gitignore).exists()
179+
if (!hasGitIgnore) await Bun.write(gitignore, ["node_modules", "package.json", "bun.lock", ".gitignore"].join("\n"))
222180

223-
// Use BASE_VERSION for @opencode-ai/plugin since it's published by upstream without our -N suffix
224-
await BunProc.run(["add", "@opencode-ai/plugin@" + targetVersion, "--exact"], {
181+
// Use BASE_VERSION for @opencode-ai/plugin since it's published by upstream without our -N suffix
182+
await BunProc.run(
183+
["add", "@opencode-ai/plugin@" + Installation.BASE_VERSION, "--exact"],
184+
{
225185
cwd: dir,
226-
})
227-
228-
// Install any additional dependencies defined in the package.json
229-
// This allows local plugins and custom tools to use external packages
230-
await BunProc.run(["install"], { cwd: dir }).catch(() => {})
186+
},
187+
).catch(() => {})
231188

232-
// Write marker file after successful install
233-
await Bun.write(
234-
markerPath,
235-
JSON.stringify({
236-
version: targetVersion,
237-
timestamp: Date.now(),
238-
}),
239-
)
240-
log.info("dependencies installed", { dir, version: targetVersion })
241-
} catch (err) {
242-
log.error("failed to install dependencies", { dir, error: err })
243-
} finally {
244-
installLocks.delete(dir)
245-
resolveLock!()
246-
}
189+
// Install any additional dependencies defined in the package.json
190+
// This allows local plugins and custom tools to use external packages
191+
await BunProc.run(["install"], { cwd: dir }).catch(() => {})
247192
}
248193

249194
const COMMAND_GLOB = new Bun.Glob("{command,commands}/**/*.md")

packages/opencode/test/config/config.test.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -724,35 +724,4 @@ test("processes .opencode directory without errors in local dev mode", async ()
724724
})
725725
})
726726

727-
test(".opencode directory gets package.json and gitignore created", async () => {
728-
await using tmp = await tmpdir({
729-
init: async (dir) => {
730-
const opencodeDir = path.join(dir, ".opencode")
731-
await fs.mkdir(opencodeDir, { recursive: true })
732-
},
733-
})
734-
await Instance.provide({
735-
directory: tmp.path,
736-
fn: async () => {
737-
await Config.get()
738-
739-
const opencodeDir = path.join(tmp.path, ".opencode")
740-
741-
// Verify package.json was created
742-
const pkgPath = path.join(opencodeDir, "package.json")
743-
const pkgExists = await Bun.file(pkgPath).exists()
744-
expect(pkgExists).toBe(true)
745-
746-
// Verify .gitignore was created
747-
const gitignorePath = path.join(opencodeDir, ".gitignore")
748-
const gitignoreExists = await Bun.file(gitignorePath).exists()
749-
expect(gitignoreExists).toBe(true)
750-
751-
// Verify .gitignore contains necessary entries
752-
const gitignoreContent = await Bun.file(gitignorePath).text()
753-
expect(gitignoreContent).toContain("node_modules")
754-
expect(gitignoreContent).toContain("package.json")
755-
expect(gitignoreContent).toContain("bun.lock")
756-
},
757-
})
758-
})
727+

0 commit comments

Comments
 (0)