mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 23:09:34 +00:00
refactor(vsix): share manifest text normalization (#16803)
This commit is contained in:
1 parent
33b2763423
commit
596f9424dd
1 file changed
+13
-28
@@ -123,7 +123,8 @@ const emptyKindCounts = (): VsixPackage["member_kind_counts"] => ({
|
||||
unknown: 0,
|
||||
});
|
||||
|
||||
const nonempty = (value: string): string | null => value.trim() || null;
|
||||
const nonempty = (value: unknown): string | null =>
|
||||
typeof value === "string" ? value.trim() || null : null;
|
||||
|
||||
const wrapZipFailure = (
|
||||
cause: unknown,
|
||||
@@ -169,16 +170,12 @@ const readMemberBytes = async (
|
||||
const parseExtensionList = (value: unknown): string[] => {
|
||||
const items = typeof value === "string" ? value.split(",") : value;
|
||||
if (!Array.isArray(items)) return [];
|
||||
const ids: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
const ids = new Set<string>();
|
||||
for (const item of items) {
|
||||
if (typeof item !== "string") continue;
|
||||
const id = item.trim();
|
||||
if (id === "" || seen.has(id)) continue;
|
||||
seen.add(id);
|
||||
ids.push(id);
|
||||
const id = nonempty(item);
|
||||
if (id !== null) ids.add(id);
|
||||
}
|
||||
return ids;
|
||||
return [...ids];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -216,13 +213,8 @@ const capabilityValue = (
|
||||
? record.supported
|
||||
? "true"
|
||||
: "false"
|
||||
: typeof record.supported === "string"
|
||||
? nonempty(record.supported)
|
||||
: null;
|
||||
const description =
|
||||
typeof record.description === "string"
|
||||
? nonempty(record.description)
|
||||
: null;
|
||||
: nonempty(record.supported);
|
||||
const description = nonempty(record.description);
|
||||
if (supported === null && description === null) return null;
|
||||
return { supported, description };
|
||||
};
|
||||
@@ -656,10 +648,7 @@ const parsePackageJsonDocument = (
|
||||
return empty;
|
||||
}
|
||||
const engines = isRecord(record.engines) ? record.engines : undefined;
|
||||
const engine =
|
||||
engines !== undefined && typeof engines.vscode === "string"
|
||||
? nonempty(engines.vscode)
|
||||
: null;
|
||||
const engine = nonempty(engines?.vscode);
|
||||
const contributesRaw = isRecord(record.contributes)
|
||||
? record.contributes
|
||||
: undefined;
|
||||
@@ -691,7 +680,7 @@ const parsePackageJsonDocument = (
|
||||
typeof command.command === "string" && command.command !== ""
|
||||
? command.command
|
||||
: null,
|
||||
title: typeof command.title === "string" ? nonempty(command.title) : null,
|
||||
title: nonempty(command.title),
|
||||
};
|
||||
});
|
||||
const capabilities = isRecord(record.capabilities)
|
||||
@@ -699,13 +688,9 @@ const parsePackageJsonDocument = (
|
||||
: undefined;
|
||||
return {
|
||||
identity: {
|
||||
name: typeof record.name === "string" ? nonempty(record.name) : null,
|
||||
publisher:
|
||||
typeof record.publisher === "string"
|
||||
? nonempty(record.publisher)
|
||||
: null,
|
||||
version:
|
||||
typeof record.version === "string" ? nonempty(record.version) : null,
|
||||
name: nonempty(record.name),
|
||||
publisher: nonempty(record.publisher),
|
||||
version: nonempty(record.version),
|
||||
},
|
||||
engine,
|
||||
main: packageJsonEntryPath(record.main),
|
||||
|
||||
Reference in new issue
Block a user