shadcn-svelte icon indicating copy to clipboard operation
shadcn-svelte copied to clipboard

Updating the components

Open saturnonearth opened this issue 1 year ago • 2 comments

Change Type

Addition

Proposed Changes

Apologies if I missed it in the docs, but is there a section on what to do if components are updated? Since it's a CLI orientated system that essentially just imports components into your project -

  • What would you do if a bug is fixed or features are added to a particular component? Especially if you have made any custom modifications.
    • Is there some way to diff it?

saturnonearth avatar Jun 05 '23 16:06 saturnonearth

At the moment, you have to diff it yourself manually. Since they are your components and there's no predicting what you might do with them, not sure if it's practical.

You could always re-add them and check the git diff locally to update anything that may have changed, or simply look at the updated components code.

Open to ideas if anyone has anything better. Just remember, this isn't 'supposed' to operate like a normal component library, more as a reference.

huntabyte avatar Jun 05 '23 17:06 huntabyte

In the meantime, I will work on adding something to do the docs to explain that as I assume it'll be a common question.

huntabyte avatar Jun 05 '23 17:06 huntabyte

Open to ideas if anyone has anything better. Just remember, this isn't 'supposed' to operate like a normal component library, more as a reference.

I guess for me, I am more concerned with bugs that may be fixed in the individual components, which I would like to push into my components, rather than custom attributes.

Maybe some way to keep track of the individual version of each component so you can at least tell if there are substantial updates or fixes to them?

saturnonearth avatar Jun 05 '23 19:06 saturnonearth

Thinking out loud for a second:

Say that we provide an npx shadcn-svelte update command that will read the contents the components/ui (or whatever the user has specified in shadcn.componentPath) and check if the user's components need to be updated.

How do we differentiate between the currently up-to-date components and the user's current components? We can't diff on the content of the files because of user defined formatting differences, as well as the possibility that the user may have already modified the files, so string diffing won't work.

What if we provide some kind of versioning to each component? My first thought would be to add the versioning to the shadcn object in svelte.config.js, but I think that would quickly devolve into a mess the more components the user installs...

How about versioning on a per component basis where the index.ts of each component dir has an export for the version? That might actually work, but I feel like we may be getting too deep into the weeds here. I'm not a particular fan of this either.

Perhaps the best solution may be the simplest? Have update read the child dirs of the specified componentPath, figure out which ones are shadcn components (I'm oversimplifying a little bit here), and overwrite them with the latest.

We'd have to provide a warning, as well as a [y/n] prompt, before continuing to overwrite the contents of those files, but I think this method would be easiest to implement and maintain.

AdrianGonz97 avatar Jun 05 '23 20:06 AdrianGonz97

We can't diff on the content of the files because of user defined formatting differences, as well as the possibility that the user may have already modified the files, so string diffing won't work.

Are you able to basically flatten or remove all tabs/spaces/formatting of both files so they are equivalent? (if the user hasn't actually added any content to the file)

Perhaps the best solution may be the simplest? Have update read the child dirs of the specified componentPath, figure out which ones are shadcn components (I'm oversimplifying a little bit here), and overwrite them with the latest. We'd have to provide a warning, as well as a [y/n] prompt, before continuing to overwrite the contents of those files, but I think this method would be easiest to implement and maintain.

Honestly I'm fine with this

saturnonearth avatar Jun 05 '23 20:06 saturnonearth