Skip to content

Fix export prototype in the multiple files case#337

Merged
NhanLuongBGSV merged 3 commits intoeclipse-autowrx:mainfrom
trantienloi2404:fix/import_export_prototype
Mar 6, 2026
Merged

Fix export prototype in the multiple files case#337
NhanLuongBGSV merged 3 commits intoeclipse-autowrx:mainfrom
trantienloi2404:fix/import_export_prototype

Conversation

@trantienloi2404
Copy link
Contributor

  • Add logic to handle export/import prototype in the multiple files case

@NhanLuongBGSV
Copy link
Contributor

NhanLuongBGSV commented Mar 4, 2026

PR #337 Review — Fix export prototype in the multiple files case

What it does

This PR adds multi-file project support to prototype export (downloadPrototypeZip). Previously, export only wrote a single code.py file. Now:

  1. isProjectCode() — Detects if prototype.code is a JSON array of FileSystemItem (multi-file project format)
  2. addProjectFilesToZip() — Recursively walks the FileSystemItem tree and adds files/folders under a code/ prefix, handling base64-encoded binary files
  3. downloadPrototypeZip — If the code is a multi-file project, extracts it into code/ folder in the zip. Still writes code.py with the raw JSON for backward compatibility
  4. Dead code removal — Removed unused widget_config plugin list extraction block (was a no-op — collected plugins but never used them)

Issues found

1. Import doesn't handle the new code/ folder (Major gap)

zipToPrototype (line 335) only reads code.py:

let code = (await zipFile.file('code.py')?.async('string')) || ''
  • Export writes multi-file projects as actual files under code/ + raw JSON in code.py
  • Import reads code.py and gets the raw JSON string, which technically works because the JSON is the code representation

So it's not brokencode.py contains the full FileSystemItem JSON, and import reads that and stores it as prototype.code. However, this is fragile and confusing. If someone manually edits files in the code/ folder and re-zips, those changes are ignored on import.

2. code.py is misleading for multi-file projects

When isProjectCode returns true, code.py contains a JSON array, not Python code. The .py extension is misleading. Acceptable for backward compatibility but worth documenting with a comment.

3. Unused import (pre-existing)

DaWidgetSetup at line 22 is imported but never used. Not introduced by this PR, but the dead code removal block deleted was the last place it could have been relevant. Consider removing.

4. addProjectFilesToZip only handles single root folder

Lines 86-90 only process fsData[0] and only if it's a folder:

const root = fsData[0]
if (root && root.type === 'folder') {
    addItems(root.items, 'code/')
}

If the project has root-level files (not inside a folder), or multiple root items, they're silently skipped. This matches how the project editor structures data (single root folder), so it's fine for current usage — but the silent skip could hide issues.

Verdict

Acceptable to merge with minor concerns. The export works correctly for multi-file projects, and the backward compatibility approach (keeping code.py) ensures import still works. The dead code removal is clean.

The main risk is the asymmetry between export (writes code/ folder) and import (ignores code/ folder), which could cause confusion but isn't functionally broken since code.py carries the full data.

@NhanLuongBGSV
Copy link
Contributor

@trantienloi2404 Hi Loi, please make small improvements as suggested above

…ove error handling. Ensure all project files are placed under the "code/" folder, with warnings for unknown item types and missing code.py files. Update comments for clarity on backward compatibility and future enhancements.
@NhanLuongBGSV NhanLuongBGSV merged commit 2fcc3f1 into eclipse-autowrx:main Mar 6, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants