Skip to content

Commit 45c79c2

Browse files
terraboopsclaude
andauthored
fix: preserve existing plugin order, append new plugins at bottom (#14)
Read existing marketplace.json to get current plugin order. Existing plugins keep their position, new plugins are appended at the end (sorted alphabetically among themselves). Produces clean additive diffs instead of noisy reordering. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 150b7bc commit 45c79c2

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

scripts/dist/discover-components.cjs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7984,12 +7984,31 @@ function generateMarketplace(plugins, config) {
79847984
category: plugin.category === "code" || plugin.category === "analysis" ? "development" : "productivity"
79857985
});
79867986
}
7987+
const marketplacePath = path.join(".claude-plugin", "marketplace.json");
7988+
let existingOrder = [];
7989+
try {
7990+
const existing = JSON.parse(fs.readFileSync(marketplacePath, "utf8"));
7991+
existingOrder = (existing.plugins || []).map((p) => p.source);
7992+
} catch {
7993+
}
7994+
const existingSet = new Set(existingOrder);
7995+
const pluginsBySource = new Map(marketplacePlugins.map((p) => [p.source, p]));
7996+
const ordered = [];
7997+
for (const source of existingOrder) {
7998+
if (pluginsBySource.has(source)) {
7999+
ordered.push(pluginsBySource.get(source));
8000+
pluginsBySource.delete(source);
8001+
}
8002+
}
8003+
const newPlugins = Array.from(pluginsBySource.values());
8004+
newPlugins.sort((a, b) => a.source.localeCompare(b.source));
8005+
ordered.push(...newPlugins);
79878006
return {
79888007
"$schema": "https://anthropic.com/claude-code/marketplace.schema.json",
79898008
name,
79908009
description,
79918010
owner,
7992-
plugins: marketplacePlugins
8011+
plugins: ordered
79938012
};
79948013
}
79958014
function writePluginJsonFiles(plugins, config) {

scripts/src/discover-components.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,12 +1296,40 @@ function generateMarketplace(plugins, config) {
12961296
});
12971297
}
12981298

1299+
// Stable ordering: preserve existing order, append new plugins at the end.
1300+
// This keeps diffs clean — only additions/removals, never reordering.
1301+
const marketplacePath = path.join('.claude-plugin', 'marketplace.json');
1302+
let existingOrder = [];
1303+
try {
1304+
const existing = JSON.parse(fs.readFileSync(marketplacePath, 'utf8'));
1305+
existingOrder = (existing.plugins || []).map(p => p.source);
1306+
} catch {
1307+
// No existing file or invalid JSON — all plugins are new
1308+
}
1309+
1310+
const existingSet = new Set(existingOrder);
1311+
const pluginsBySource = new Map(marketplacePlugins.map(p => [p.source, p]));
1312+
1313+
// Existing plugins in their original order (skip any that were removed)
1314+
const ordered = [];
1315+
for (const source of existingOrder) {
1316+
if (pluginsBySource.has(source)) {
1317+
ordered.push(pluginsBySource.get(source));
1318+
pluginsBySource.delete(source);
1319+
}
1320+
}
1321+
1322+
// New plugins appended at the end, sorted alphabetically among themselves
1323+
const newPlugins = Array.from(pluginsBySource.values());
1324+
newPlugins.sort((a, b) => a.source.localeCompare(b.source));
1325+
ordered.push(...newPlugins);
1326+
12991327
return {
13001328
"$schema": "https://anthropic.com/claude-code/marketplace.schema.json",
13011329
name,
13021330
description,
13031331
owner,
1304-
plugins: marketplacePlugins
1332+
plugins: ordered
13051333
};
13061334
}
13071335

0 commit comments

Comments
 (0)