({ pluginName, sourceRepo, filePath = EXTERNAL_PLUGINS_FILE } = {})
| 195 | } |
| 196 | |
| 197 | export 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 | |
| 227 | function readCliArgs(argv) { |
| 228 | const args = {}; |
no test coverage detected