mirror of
https://github.com/morluto/rea.git
synced 2026-11-30 18:39:24 +00:00
refactor(vsix): share manifest extension list parsing (#14876)
This commit is contained in:
1 parent
e70ca8d02b
commit
16af28c09e
1 file changed
+13
-27
@@ -174,25 +174,12 @@ const readMemberBytes = async (
|
||||
}
|
||||
};
|
||||
|
||||
const splitCsv = (value: string | null): string[] => {
|
||||
if (value === null) return [];
|
||||
const seen = new Set<string>();
|
||||
const ids: string[] = [];
|
||||
for (const part of value.split(",")) {
|
||||
const id = part.trim();
|
||||
if (id === "" || seen.has(id)) continue;
|
||||
seen.add(id);
|
||||
ids.push(id);
|
||||
}
|
||||
return ids;
|
||||
};
|
||||
|
||||
const asStringArray = (value: unknown): string[] => {
|
||||
if (typeof value === "string") return splitCsv(value);
|
||||
if (!Array.isArray(value)) return [];
|
||||
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>();
|
||||
for (const item of value) {
|
||||
for (const item of items) {
|
||||
if (typeof item !== "string") continue;
|
||||
const id = item.trim();
|
||||
if (id === "" || seen.has(id)) continue;
|
||||
@@ -606,15 +593,14 @@ const parseVsixManifestDocument = (
|
||||
description: metadataText("Description"),
|
||||
},
|
||||
engine: propertyById.get("Microsoft.VisualStudio.Code.Engine") ?? null,
|
||||
extensionDependencies: splitCsv(
|
||||
propertyById.get("Microsoft.VisualStudio.Code.ExtensionDependencies") ??
|
||||
null,
|
||||
extensionDependencies: parseExtensionList(
|
||||
propertyById.get("Microsoft.VisualStudio.Code.ExtensionDependencies"),
|
||||
),
|
||||
extensionPack: splitCsv(
|
||||
propertyById.get("Microsoft.VisualStudio.Code.ExtensionPack") ?? null,
|
||||
extensionPack: parseExtensionList(
|
||||
propertyById.get("Microsoft.VisualStudio.Code.ExtensionPack"),
|
||||
),
|
||||
extensionKind: splitCsv(
|
||||
propertyById.get("Microsoft.VisualStudio.Code.ExtensionKind") ?? null,
|
||||
extensionKind: parseExtensionList(
|
||||
propertyById.get("Microsoft.VisualStudio.Code.ExtensionKind"),
|
||||
),
|
||||
assets,
|
||||
};
|
||||
@@ -744,9 +730,9 @@ const parsePackageJsonDocument = (
|
||||
commands_total: commandRows.length,
|
||||
commands_omitted: listedCommands.omitted,
|
||||
},
|
||||
extensionDependencies: asStringArray(record.extensionDependencies),
|
||||
extensionPack: asStringArray(record.extensionPack),
|
||||
extensionKind: asStringArray(record.extensionKind),
|
||||
extensionDependencies: parseExtensionList(record.extensionDependencies),
|
||||
extensionPack: parseExtensionList(record.extensionPack),
|
||||
extensionKind: parseExtensionList(record.extensionKind),
|
||||
capabilities: {
|
||||
untrusted_workspaces: capabilityValue(
|
||||
record.capabilities !== null &&
|
||||
|
||||
Reference in new issue
Block a user