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

Remove outdated files on CLI update

Open WarningImHack3r opened this issue 1 year ago • 2 comments

Describe the feature

With #776, some Form component files have been deleted in favor of others. Using the CLI update adds the new files and updates the modified ones, but does not remove the no-longer-existing ones.

As I’m implementing this feature in my JetBrains plugin, can I also push the change to the CLI update command?

WarningImHack3r avatar Feb 26 '24 18:02 WarningImHack3r

Hmm, I'm not sure we should go deleting all files in a folder that we don't own (and we aren't going to keep a running record of all past files). I'll defer to @AdrianGonz97 to get his thoughts on this!

huntabyte avatar Feb 26 '24 23:02 huntabyte

Yeah, I don't think deleting would be the best idea, especially when we're not keeping track of the history of files that we've created/own.

Perhaps printing a list of files that are potentially no longer needed would suffice instead?

AdrianGonz97 avatar Feb 26 '24 23:02 AdrianGonz97

we aren't going to keep a running record of all past files

No need for that! Just removing all files that are not currently listed remotely

WarningImHack3r avatar Feb 27 '24 06:02 WarningImHack3r

Perhaps printing a list of files that are potentially no longer needed would suffice instead?

IMO that's not that an issue, but I get your fear. What about deleting them only if a git repository is initiated, else list the files? We could even check if the file starts with the name of the component (or == index.ts) as a triple check safety net.

But I'm pretty sure we should do something about it instead of leaving useless files in users' projects

WarningImHack3r avatar Feb 27 '24 06:02 WarningImHack3r

We could even check if the file starts with the name of the component (or == index.ts) as a triple check safety net.

Still don't like this idea, if I create a custom form-input.svelte, I don't expect it to be obliterated by updating the form. At the moment, listing the files that exist that are "no longer necessary" is the only approach I feel comfortable with.

You also have to remember the whole idea behind this project. You own the code. You are responsible for keeping the components up to date and cleaning up any leftovers during an update.

huntabyte avatar Feb 27 '24 19:02 huntabyte

Get it. You're right. Will do that!

WarningImHack3r avatar Feb 27 '24 20:02 WarningImHack3r

this has been brought up in the past: https://github.com/huntabyte/shadcn-svelte/issues/530 and I also ran into this again today.

@huntabyte I understand:

Still don't like this idea, if I create a custom form-input.svelte, I don't expect it to be obliterated by updating the form.

but at the same time, say that I customize form-legend.svelte, then those changes are in fact obliterated by updating the form.

I personally believe that the warning that you should commit your changes before updating is enough, regardless if they are custom changes to existing files added by shadcn-svelte or custom changes to new files added by the user.

another example: the file names used by shadcn-svelte are not reserved in any way. if I have previously created a custom form-field.svelte component and then I update shadcn-svelte - it would now have been obliterated after https://github.com/huntabyte/shadcn-svelte/commit/3e858d268c17619c0e3a0e294a08841072dc5eb8#diff-5049016897f5c47ecf4cec09f654ac3cc993a3362db36a9b883bb7d18119d1e2 right?

therefore, I don't feel like this argument is super solid 🤔

at the very least, could this be a CLI option? so user who wants to remove unused files can do so with for example pnpx shadcn-svelte@latest update --all --clean or whatever that option could be called. that option would nuke the contents of each component directory before installing them again (which is what I have done now manually after detecting loads of false positives in linting errors stemming from old files)

ollema avatar Feb 28 '24 22:02 ollema