Skip to content

Conversation

@WarningImHack3r
Copy link
Owner

@WarningImHack3r WarningImHack3r commented Sep 6, 2024

Fixes #5.

Context

The plugin replaces imports via a mechanism of regular expressions and string manipulation. It does not do any syntax analysis. As such, it cannot detect incorrect imports.
Extensive testing is done to ensure that the replacements work by constantly testing against the latest versions of lucide-svelte in the CI, independently from the other dependencies upgrades workflow.

However, aliases were not tested. I initially thought it wasn’t possible to do it in a way as extensive as for the regular imports, but I was wrong. *Icon-suffixed icons were correctly handled, though.

Solution

Immediate fix

The immediate solution is to first add tests against aliases imports to make sure they’re working properly. But how to actually make the tests pass?

Well, the only idea that came to my mind is to hardcode a map of alias names and their corresponding icon paths in the source code itself. It's dirty, but it does fix the issue. The main question remains how to maintain this mapping over time?

Long-term solution

As I was thinking through possible solutions, I realized I could make the maintenance process 100% automated. I know when a new breaking release happens (Renovate PR's CI), and I know what to do (get the new map of bindings, update it, and release a new version). What's left is just to fill in the gap.

The idea is the following:

  1. Start from the Renovate PR. It's dedicated to testing against the package, so if it fails, I know it's because the tests broke because of a new deprecation/renaming.
  2. On failure, start the machinery:
    • Export the list of tests in a parseable format
    • Run a dedicated script outside the src directory (so that it's not affecting the real source code, it isn't anyway) that reads this test report file and spits out an updated map of renamed packages
    • Replace the source file with this new map
    • Push these changes directly on master with an updated version in package.json and the updated version of lucide-svelte, after running Prettier, of course. This commit will indirectly close the Renovate PR as Lucide will now be up-to-date.
  3. From this commit on master, run a special CI that detects this kind of commit and creates a GitHub Release from it
  4. The Release pipeline kicks in and automatically uploads the updated package to NPM, as it already does

This CI game should do the trick just fine and publish fixes entirely automatically and very quickly, thanks to Renovate scanning for updates frequently.

TODO

  • Update the test suite to cover aliases
    • I discovered that Lucide*-prefixed icons were a thing, they're now supported and covered
  • Implement an initial mapping
  • Create the script that turns a Vitest output into a map of bindings
  • Update the main.yml CI to update the mapping and push it on the master branch on test failure
  • Create the CI running on master to create a GH release from these special commits
  • Bump version, update README and merge
  • Enjoy?

@WarningImHack3r WarningImHack3r self-assigned this Sep 6, 2024
@WarningImHack3r WarningImHack3r marked this pull request as ready for review September 15, 2024 18:04
Copilot still defaults to the deprecated version lol
@WarningImHack3r WarningImHack3r merged commit 55efd5a into main Sep 15, 2024
4 checks passed
@WarningImHack3r WarningImHack3r deleted the auto-update-renamed branch September 15, 2024 18:16
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.

Plugin does not work with deprecated / renamed icons

2 participants