fix(converters): fix converter discovery and array sharing bugs

This commit is contained in:
Jörg Krzeslak
2026-10-22 16:55:41 +02:00
parent cc1689a2ef
commit 5cdce6b4b4
+10 -14
View File
@@ -259,6 +259,7 @@ async function mainConverter(
converterObj?.properties?.to[key]?.includes(convertTo) converterObj?.properties?.to[key]?.includes(convertTo)
) { ) {
converterFunc = converterObj.converter; converterFunc = converterObj.converter;
converterName = name;
break; break;
} }
} }
@@ -299,6 +300,7 @@ const possibleTargets: Record<string, Record<string, string[]>> = {};
for (const converterName in properties) { for (const converterName in properties) {
const converterProperties = properties[converterName]?.properties; const converterProperties = properties[converterName]?.properties;
if (!converterProperties) continue; if (!converterProperties) continue;
for (const key in converterProperties.from) { for (const key in converterProperties.from) {
@@ -310,7 +312,7 @@ for (const converterName in properties) {
for (const ext of fromList) { for (const ext of fromList) {
if (!possibleTargets[ext]) possibleTargets[ext] = {}; if (!possibleTargets[ext]) possibleTargets[ext] = {};
possibleTargets[ext][converterName] = toList; possibleTargets[ext][converterName] = [...toList];
} }
} }
} }
@@ -319,15 +321,13 @@ export const getPossibleTargets = (from: string): Record<string, string[]> => {
const fromClean = normalizeFiletype(from); const fromClean = normalizeFiletype(from);
return possibleTargets[fromClean] || {}; return possibleTargets[fromClean] || {};
}; }
const possibleInputs: string[] = []; const possibleInputs: string[] = [];
for (const converterName in properties) { for (const converterName in properties) {
const converterProperties = properties[converterName]?.properties; const converterProperties = properties[converterName]?.properties;
if (!converterProperties) { if (!converterProperties) continue;
continue;
}
for (const key in converterProperties.from) { for (const key in converterProperties.from) {
for (const extension of converterProperties.from[key] ?? []) { for (const extension of converterProperties.from[key] ?? []) {
@@ -344,13 +344,11 @@ const allTargets: Record<string, string[]> = {};
for (const converterName in properties) { for (const converterName in properties) {
const converterProperties = properties[converterName]?.properties; const converterProperties = properties[converterName]?.properties;
if (!converterProperties) { if (!converterProperties) continue;
continue;
}
for (const key in converterProperties.to) { for (const key in converterProperties.to) {
if (allTargets[converterName]) { if (allTargets[converterName]) {
allTargets[converterName].push(...(converterProperties.to[key] || [])); allTargets[converterName] = [...allTargets[converterName], ...(converterProperties.to[key] || [])];
} else { } else {
allTargets[converterName] = [...(converterProperties.to[key] || [])]; allTargets[converterName] = [...(converterProperties.to[key] || [])];
} }
@@ -365,13 +363,11 @@ const allInputs: Record<string, string[]> = {};
for (const converterName in properties) { for (const converterName in properties) {
const converterProperties = properties[converterName]?.properties; const converterProperties = properties[converterName]?.properties;
if (!converterProperties) { if (!converterProperties) continue;
continue;
}
for (const key in converterProperties.from) { for (const key in converterProperties.from) {
if (allInputs[converterName]) { if (allInputs[converterName]) {
allInputs[converterName].push(...(converterProperties.from[key] || [])); allInputs[converterName] = [...allInputs[converterName], ...(converterProperties.from[key] || [])];
} else { } else {
allInputs[converterName] = converterProperties.from[key] || []; allInputs[converterName] = converterProperties.from[key] || [];
} }
@@ -386,4 +382,4 @@ export const getAllInputs = (converter: string) => {
* @internal For testing only. Do not use in production. * @internal For testing only. Do not use in production.
* Tests need direct access to cover all branches of converter discovery and chunking logic. * Tests need direct access to cover all branches of converter discovery and chunking logic.
*/ */
export { chunks, mainConverter }; export { chunks, mainConverter };