MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / removeIntegrationFromConfig

Function removeIntegrationFromConfig

packages/core/config/src/write.ts:91–121  ·  view source on GitHub ↗
(
  path: string,
  namespace: string,
)

Source from the content-addressed store, hash-verified

89 * Remove an integration from the config file by namespace.
90 */
91export const removeIntegrationFromConfig = (
92 path: string,
93 namespace: string,
94): Effect.Effect<void, PlatformError, FileSystem.FileSystem> =>
95 Effect.gen(function* () {
96 const fs = yield* FileSystem.FileSystem;
97
98 const exists = yield* fs.exists(path);
99 if (!exists) return;
100
101 let text = yield* fs.readFileString(path);
102 const tree = jsonc.parseTree(text);
103 if (!tree) return;
104
105 const integrationsNode = jsonc.findNodeAtLocation(tree, ["integrations"]);
106 if (!integrationsNode?.children) return;
107
108 // Walk backwards so indices stay valid after each removal
109 for (let i = integrationsNode.children.length - 1; i >= 0; i--) {
110 const child = integrationsNode.children[i]!;
111 const nsNode = jsonc.findNodeAtLocation(child, ["namespace"]);
112 if (nsNode && jsonc.getNodeValue(nsNode) === namespace) {
113 const edits = jsonc.modify(text, ["integrations", i], undefined, {
114 formattingOptions: FORMATTING,
115 });
116 text = jsonc.applyEdits(text, edits);
117 }
118 }
119
120 yield* fs.writeFileString(path, text);
121 });
122
123/**
124 * Write a full config object to a file.

Callers 2

makeFileConfigSinkFunction · 0.90
config.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected