Skip to content

Commit f27eb8f

Browse files
committed
fix plugins reinstalling too often
1 parent ad05453 commit f27eb8f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/opencode/src/npm/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * as Npm from "."
22

33
import path from "path"
4+
import npa from "npm-package-arg"
45
import semver from "semver"
56
import { Effect, Schema, Context, Layer, Option, FileSystem } from "effect"
67
import { NodeFileSystem } from "@effect/platform-node"
@@ -135,6 +136,17 @@ export const layer = Layer.effect(
135136

136137
const add = Effect.fn("Npm.add")(function* (pkg: string) {
137138
const dir = directory(pkg)
139+
const name = (() => {
140+
try {
141+
return npa(pkg).name ?? pkg
142+
} catch {
143+
return pkg
144+
}
145+
})()
146+
147+
if (yield* afs.existsSafe(dir)) {
148+
return resolveEntryPoint(name, path.join(dir, "node_modules", name))
149+
}
138150

139151
const tree = yield* reify({ dir, add: [pkg] })
140152
const first = tree.edgesOut.values().next().value?.to

0 commit comments

Comments
 (0)