MCPcopy Index your code
hub / github.com/anomalyco/opencode / patchPluginList

Function patchPluginList

packages/opencode/src/plugin/install.ts:181–257  ·  view source on GitHub ↗
(
  text: string,
  list: unknown[] | undefined,
  spec: string,
  next: unknown,
  force = false,
)

Source from the content-addressed store, hash-verified

179}
180
181function patchPluginList(
182 text: string,
183 list: unknown[] | undefined,
184 spec: string,
185 next: unknown,
186 force = false,
187): { mode: Mode; text: string } {
188 const pkg = parsePluginSpecifier(spec).pkg
189 const rows = (list ?? []).map((item, i) => ({
190 item,
191 i,
192 spec: pluginSpec(item),
193 }))
194 const dup = rows.filter((item) => {
195 if (!item.spec) return false
196 if (item.spec === spec) return true
197 if (item.spec.startsWith("file://")) return false
198 return parsePluginSpecifier(item.spec).pkg === pkg
199 })
200
201 if (!dup.length) {
202 if (!list) {
203 return {
204 mode: "add",
205 text: patch(text, ["plugin"], [next]),
206 }
207 }
208 return {
209 mode: "add",
210 text: patch(text, ["plugin", list.length], next, true),
211 }
212 }
213
214 if (!force) {
215 return {
216 mode: "noop",
217 text,
218 }
219 }
220
221 const keep = dup[0]
222 if (!keep) {
223 return {
224 mode: "noop",
225 text,
226 }
227 }
228
229 if (dup.length === 1 && keep.spec === spec) {
230 return {
231 mode: "noop",
232 text,
233 }
234 }
235
236 let out = text
237 if (typeof keep.item === "string") {
238 out = patch(out, ["plugin", keep.i], next)

Callers 1

patchOneFunction · 0.85

Calls 3

parsePluginSpecifierFunction · 0.90
pluginSpecFunction · 0.85
patchFunction · 0.70

Tested by

no test coverage detected