


























@@ -140,14 +140,6 @@ function splitRef(value: string): { base: string; ref?: string } {
140140};
141141}
142142143-function toOptionalString(value: unknown): string | undefined {
144-if (typeof value !== "string") {
145-return undefined;
146-}
147-const trimmed = value.trim();
148-return trimmed.length > 0 ? trimmed : undefined;
149-}
150-151143function normalizeEntrySource(
152144raw: unknown,
153145): { ok: true; source: MarketplaceEntrySource } | { ok: false; error: string } {
@@ -167,21 +159,21 @@ function normalizeEntrySource(
167159}
168160169161const rec = raw as Record<string, unknown>;
170-const kind = toOptionalString(rec.type) ?? toOptionalString(rec.source);
162+const kind = normalizeOptionalString(rec.type) ?? normalizeOptionalString(rec.source);
171163if (!kind) {
172164return { ok: false, error: 'plugin source object missing "type" or "source"' };
173165}
174166175167if (kind === "path") {
176-const sourcePath = toOptionalString(rec.path);
168+const sourcePath = normalizeOptionalString(rec.path);
177169if (!sourcePath) {
178170return { ok: false, error: 'path source missing "path"' };
179171}
180172return { ok: true, source: { kind: "path", path: sourcePath } };
181173}
182174183175if (kind === "github") {
184-const repo = toOptionalString(rec.repo) ?? toOptionalString(rec.url);
176+const repo = normalizeOptionalString(rec.repo) ?? normalizeOptionalString(rec.url);
185177if (!repo) {
186178return { ok: false, error: 'github source missing "repo"' };
187179}
@@ -190,14 +182,17 @@ function normalizeEntrySource(
190182source: {
191183kind: "github",
192184 repo,
193-path: toOptionalString(rec.path),
194-ref: toOptionalString(rec.ref) ?? toOptionalString(rec.branch) ?? toOptionalString(rec.tag),
185+path: normalizeOptionalString(rec.path),
186+ref:
187+normalizeOptionalString(rec.ref) ??
188+normalizeOptionalString(rec.branch) ??
189+normalizeOptionalString(rec.tag),
195190},
196191};
197192}
198193199194if (kind === "git") {
200-const url = toOptionalString(rec.url) ?? toOptionalString(rec.repo);
195+const url = normalizeOptionalString(rec.url) ?? normalizeOptionalString(rec.repo);
201196if (!url) {
202197return { ok: false, error: 'git source missing "url"' };
203198}
@@ -206,15 +201,18 @@ function normalizeEntrySource(
206201source: {
207202kind: "git",
208203 url,
209-path: toOptionalString(rec.path),
210-ref: toOptionalString(rec.ref) ?? toOptionalString(rec.branch) ?? toOptionalString(rec.tag),
204+path: normalizeOptionalString(rec.path),
205+ref:
206+normalizeOptionalString(rec.ref) ??
207+normalizeOptionalString(rec.branch) ??
208+normalizeOptionalString(rec.tag),
211209},
212210};
213211}
214212215213if (kind === "git-subdir") {
216-const url = toOptionalString(rec.url) ?? toOptionalString(rec.repo);
217-const sourcePath = toOptionalString(rec.path) ?? toOptionalString(rec.subdir);
214+const url = normalizeOptionalString(rec.url) ?? normalizeOptionalString(rec.repo);
215+const sourcePath = normalizeOptionalString(rec.path) ?? normalizeOptionalString(rec.subdir);
218216if (!url) {
219217return { ok: false, error: 'git-subdir source missing "url"' };
220218}
@@ -227,13 +225,16 @@ function normalizeEntrySource(
227225kind: "git-subdir",
228226 url,
229227path: sourcePath,
230-ref: toOptionalString(rec.ref) ?? toOptionalString(rec.branch) ?? toOptionalString(rec.tag),
228+ref:
229+normalizeOptionalString(rec.ref) ??
230+normalizeOptionalString(rec.branch) ??
231+normalizeOptionalString(rec.tag),
231232},
232233};
233234}
234235235236if (kind === "url") {
236-const url = toOptionalString(rec.url);
237+const url = normalizeOptionalString(rec.url);
237238if (!url) {
238239return { ok: false, error: 'url source missing "url"' };
239240}
@@ -381,7 +382,7 @@ function parseMarketplaceManifest(
381382return { ok: false, error: `invalid marketplace entry in ${sourceLabel}: expected object` };
382383}
383384const plugin = entry as Record<string, unknown>;
384-const name = toOptionalString(plugin.name);
385+const name = normalizeOptionalString(plugin.name);
385386if (!name) {
386387return { ok: false, error: `invalid marketplace entry in ${sourceLabel}: missing name` };
387388}
@@ -394,17 +395,17 @@ function parseMarketplaceManifest(
394395}
395396plugins.push({
396397 name,
397-version: toOptionalString(plugin.version),
398-description: toOptionalString(plugin.description),
398+version: normalizeOptionalString(plugin.version),
399+description: normalizeOptionalString(plugin.description),
399400source: normalizedSource.source,
400401});
401402}
402403403404return {
404405ok: true,
405406manifest: {
406-name: toOptionalString(rec.name),
407-version: toOptionalString(rec.version),
407+name: normalizeOptionalString(rec.name),
408+version: normalizeOptionalString(rec.version),
408409 plugins,
409410},
410411};
@@ -430,7 +431,7 @@ async function readClaudeKnownMarketplaces(): Promise<Record<string, KnownMarket
430431}
431432const record = value as Record<string, unknown>;
432433result[name] = {
433-installLocation: toOptionalString(record.installLocation),
434+installLocation: normalizeOptionalString(record.installLocation),
434435source: record.source,
435436};
436437}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。