From 3afdc0de9e375aed686ae7461d5bc2b830d6717f Mon Sep 17 00:00:00 2001 From: David Montero Crespo Date: Mon, 9 Mar 2026 13:32:04 -0300 Subject: [PATCH] feat: add library list parser to handle libraries.txt content --- frontend/src/utils/wokwiZip.ts | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/frontend/src/utils/wokwiZip.ts b/frontend/src/utils/wokwiZip.ts index 59efc48..78f70c5 100644 --- a/frontend/src/utils/wokwiZip.ts +++ b/frontend/src/utils/wokwiZip.ts @@ -132,6 +132,24 @@ function metadataIdToWokwiType(metadataId: string): string { return `wokwi-${metadataId}`; } +// ── Library list parser ─────────────────────────────────────────────────────── + +/** + * Parse the contents of a Wokwi libraries.txt file. + * - Strips blank lines and # comments + * - Excludes Wokwi-hosted entries in the form name@wokwi:hash + * (they have no arduino-cli installable equivalent) + */ +export function parseLibrariesTxt(content: string): string[] { + const libs: string[] = []; + for (const raw of content.split('\n')) { + const line = raw.trim(); + if (!line || line.startsWith('#') || line.includes('@wokwi:')) continue; + libs.push(line); + } + return libs; +} + // ── Export ──────────────────────────────────────────────────────────────────── export async function exportToWokwiZip( @@ -305,16 +323,11 @@ export async function importFromWokwiZip(file: File): Promise { return a.name.localeCompare(b.name); }); - // Parse libraries.txt — skip blank lines, comments (#), and Wokwi-only entries (name@wokwi:hash) + // Parse libraries.txt const libraries: string[] = []; const libEntry = zip.file('libraries.txt'); if (libEntry) { - const libText = await libEntry.async('string'); - for (const raw of libText.split('\n')) { - const line = raw.trim(); - if (!line || line.startsWith('#') || line.includes('@wokwi:')) continue; - libraries.push(line); - } + libraries.push(...parseLibrariesTxt(await libEntry.async('string'))); } return { boardType, boardPosition, components, wires, files, libraries };