pulsar-edit / package-backend

Pulsar Server Backend for Packages
https://api.pulsar-edit.dev
MIT License
12 stars 11 forks source link

[BUG] Renamed packages should redirect to the new name #268

Open savetheclocktower opened 1 month ago

savetheclocktower commented 1 month ago

(Couldn't decide between “feature” and “bug,” so I flipped a coin.)

What is the Bug We support the renaming of a package, but this only seems to point the GitHub repo to a new name. It effectively “orphans” the old name and its subscribers.

Instead, the old name should function as an “alias” for the new name. Consider a package renamed from old-name to new-name; when Pulsar checks what the latest version of old-name is, it should get the same result as if it had asked what the newest version of new-name is. The package “card” in Pulsar can show the new name, but otherwise nothing else would have to change about the repo on the user's machine; it could still exist at ~/.pulsar/packages/old-name without any problem.

I'm pretty sure this would be seamless. An edge case would be if the user explicitly searched for new-name; ideally they'd get the new-name result and Pulsar would know that it was already installed.

How to Replicate the Bug Check out these search results. They reflect both the original name of a package and what I renamed it to.

savetheclocktower commented 1 month ago

I didn't even know you could rename packages until I started contributing to Pulsar, so I had no idea whether the feature had been properly implemented back in the Atom days. Since NPM doesn't have the ability to rename packages, I was skeptical that Pulsar and PPM had managed to handle this seamlessly.

So I did some digging. Here's what I found. (Keep in mind that most of this is hypothetical, and can’t actually be tested until we fix how the /packages/:packageName endpoint works.)

This was a rollercoaster — I spent at least half an hour writing this where I was convinced that this flow wouldn’t work, but then I read the code more closely. I think the takeaway is this:

Honestly, though, the first item is the crucial one; once that logic fix is deployed, we can run real-world experiments about this stuff and act accordingly.

confused-Techie commented 1 month ago

Fantastic write up here. So from reading that and seeing how empty our current logic is during a rename, it seems to me the best thing to do and the easiest fix is we add an additional field to the names table of the database. This could simply be migrated_name which contains the new name of a given package. From there this function returns a call to itself for that package's name.

Since we return another call this could follow infinite changes no matter how many times a package's name is changed, and ensures it will always return the most up to date package name, which then can be returned via the API.

While the method outlined above isn't the best for SEO, since like you said that should be a 301 redirect, this could get things working rather quickly, and sometime later we look into a proper redirect. But a redirect could likely be accomplished with an check of the name being returned having matched the name request by the user and redirecting. Which actually sounds incredibly easy, but does require both implementations.

I'll try to take a shot at this one later today if I find the time

savetheclocktower commented 1 month ago

I opened #269 yesterday to improve the testing situation around package renaming and make it better resemble real-world renaming scenarios.

Here's a rough checklist of how to proceed: