MCPcopy Index your code
hub / github.com/CopilotKit/CopilotKit / handleVersionSync

Function handleVersionSync

scripts/sync-plugin-skills.ts:201–256  ·  view source on GitHub ↗
(opts: SyncOptions)

Source from the content-addressed store, hash-verified

199// Returns a drift description string (for check mode), or empty string if in sync.
200// In write mode, mutates the files and always returns empty string.
201async function handleVersionSync(opts: SyncOptions): Promise<string> {
202 const srcPath = join(opts.cwd, VERSION_SOURCE_PACKAGE_JSON);
203 if (!existsSync(srcPath)) return "";
204 const srcVersion: string = JSON.parse(
205 await readFile(srcPath, "utf8"),
206 ).version;
207
208 const pluginPath = join(opts.cwd, PLUGIN_JSON);
209 const marketPath = join(opts.cwd, MARKETPLACE_JSON);
210
211 if (existsSync(pluginPath)) {
212 const plugin = JSON.parse(await readFile(pluginPath, "utf8"));
213 if (plugin.version !== srcVersion) {
214 if (opts.mode === "check") {
215 return `plugin.json version is "${plugin.version}", expected "${srcVersion}" (from ${VERSION_SOURCE_PACKAGE_JSON})`;
216 }
217 plugin.version = srcVersion;
218 await writeFile(pluginPath, JSON.stringify(plugin, null, 2) + "\n");
219 }
220 }
221
222 if (existsSync(marketPath)) {
223 const market = JSON.parse(await readFile(marketPath, "utf8"));
224 const marketVersion = market.plugins?.[0]?.version;
225 const metadataVersion = market.metadata?.version;
226 // Both version fields in marketplace.json track the runtime package. They
227 // are checked together so neither rots independently — metadata.version was
228 // historically unmanaged and drifted behind plugins[0].version.
229 if (marketVersion !== srcVersion) {
230 if (opts.mode === "check") {
231 return `marketplace.json plugins[0].version is "${marketVersion}", expected "${srcVersion}" (from ${VERSION_SOURCE_PACKAGE_JSON})`;
232 }
233 }
234 if (metadataVersion !== undefined && metadataVersion !== srcVersion) {
235 if (opts.mode === "check") {
236 return `marketplace.json metadata.version is "${metadataVersion}", expected "${srcVersion}" (from ${VERSION_SOURCE_PACKAGE_JSON})`;
237 }
238 }
239 if (opts.mode === "write") {
240 let mutated = false;
241 if (market.plugins?.[0] && marketVersion !== srcVersion) {
242 market.plugins[0].version = srcVersion;
243 mutated = true;
244 }
245 if (market.metadata && metadataVersion !== srcVersion) {
246 market.metadata.version = srcVersion;
247 mutated = true;
248 }
249 if (mutated) {
250 await writeFile(marketPath, JSON.stringify(market, null, 2) + "\n");
251 }
252 }
253 }
254
255 return "";
256}
257
258// ─── CLI ─────────────────────────────────────────────────────────────────────

Callers 1

syncPluginSkillsFunction · 0.85

Calls 2

parseMethod · 0.80
writeFileFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…