MCPcopy Create free account
hub / github.com/github/awesome-copilot / removePluginFromExternalJson

Function removePluginFromExternalJson

eng/external-plugin-rereview.mjs:197–225  ·  view source on GitHub ↗
({ pluginName, sourceRepo, filePath = EXTERNAL_PLUGINS_FILE } = {})

Source from the content-addressed store, hash-verified

195}
196
197export function removePluginFromExternalJson({ pluginName, sourceRepo, filePath = EXTERNAL_PLUGINS_FILE } = {}) {
198 const { plugins, errors } = readExternalPlugins({ filePath, policy: "marketplace" });
199 if (errors.length > 0) {
200 throw new Error(errors.join("\n"));
201 }
202
203 const normalizedPluginName = normalizeValue(pluginName);
204 const normalizedSourceRepo = normalizeValue(sourceRepo);
205 const matchIndex = plugins.findIndex((plugin) => {
206 const nameMatches = normalizedPluginName && normalizeValue(plugin?.name) === normalizedPluginName;
207 const repoMatches = normalizedSourceRepo && normalizeValue(plugin?.source?.repo) === normalizedSourceRepo;
208
209 if (normalizedPluginName && normalizedSourceRepo) {
210 return nameMatches && repoMatches;
211 }
212
213 return Boolean(nameMatches || repoMatches);
214 });
215
216 if (matchIndex === -1) {
217 throw new Error(`Could not find external plugin "${pluginName || sourceRepo}" in ${path.relative(process.cwd(), filePath)}`);
218 }
219
220 const updatedPlugins = [...plugins];
221 const [removedPlugin] = updatedPlugins.splice(matchIndex, 1);
222 fs.writeFileSync(filePath, `${JSON.stringify(updatedPlugins, null, 2)}\n`);
223
224 return removedPlugin;
225}
226
227function readCliArgs(argv) {
228 const args = {};

Callers 1

Calls 2

readExternalPluginsFunction · 0.90
normalizeValueFunction · 0.70

Tested by

no test coverage detected