refactor(nuget): represent the selected nuspec once (#16712)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-04 20:03:52 +08:00
1 parent 012febae5c
commit af8aefe0a1
1 file changed
+8 -14
+8 -14
View File
@@ -393,12 +393,7 @@ const findNuspec = (
files: readonly { readonly entry: FileEntry; readonly name: string }[],
targets: readonly OpcManifestTarget[] | undefined,
limitations: string[],
): {
readonly member:
| { readonly entry: FileEntry; readonly name: string }
| undefined;
readonly source: "opc-relationship" | "root-nuspec" | undefined;
} => {
) => {
if (targets?.length) {
const targetKeys = new Set(
targets.map(({ lookup }) => opcPartNameKey(lookup)),
@@ -412,7 +407,7 @@ const findNuspec = (
limitations.push(
"OPC manifest relationships resolve to more than one .nuspec ZIP member; identity was not decoded.",
);
return { member: undefined, source: undefined };
return undefined;
}
member = file;
}
@@ -422,7 +417,7 @@ const findNuspec = (
limitations.push(
"The OPC manifest relationship matched a .nuspec member by case-insensitive ZIP name.",
);
return { member, source: "opc-relationship" };
return { member, source: "opc-relationship" } as const;
}
if (targets.length === 1)
limitations.push(
@@ -435,12 +430,12 @@ const findNuspec = (
);
if (rootNuspecs.length > 1) {
limitations.push(NUPKG_LIMITATIONS.ambiguousRootNuspec);
return { member: undefined, source: undefined };
return undefined;
}
if (rootNuspecs.length === 1)
return { member: rootNuspecs[0], source: "root-nuspec" };
const member = rootNuspecs[0];
if (member !== undefined) return { member, source: "root-nuspec" } as const;
limitations.push(NUPKG_LIMITATIONS.noNuspec);
return { member: undefined, source: undefined };
return undefined;
};
class RandomAccessZipReader extends Reader<undefined> {
@@ -618,8 +613,7 @@ export const parseNugetNupkg = async (
limitations,
});
const selected = findNuspec(files, relsTargets, limitations);
if (selected.member === undefined || selected.source === undefined)
return report(null);
if (selected === undefined) return report(null);
if (selected.member.entry.encrypted) {
limitations.push(
`Selected .nuspec ${JSON.stringify(selected.member.name)} is encrypted and was not extracted.`,