fnm icon indicating copy to clipboard operation
fnm copied to clipboard

Support cleaning the cache directory

Open ryanccn opened this issue 2 years ago • 15 comments

It would be great if fnm supported cleaning up the cache directory. Currently, I have 2398 directories in the cache directory, and I think that having a command (which maybe runs periodically when you run any fnm command?)that removes everything in that directory is better than having to do so manually while the folders build up.

ryanccn avatar Mar 12 '22 08:03 ryanccn

@Schniz

ryanccn avatar Aug 12 '22 06:08 ryanccn

hey there. There is no good solution unfortunately.

  1. these are not directories but symlinks. They don't really harm your computer but feel free to remove them: rm $(dirname $FNM_MULTISHELL_PATH)/*
  2. periodic cleanings aren't gonna cut it 100% because we need to know whether the shell is still in use. however this is not really possible because we can't know for sure which shell have evaluated this env. it was possible if we would say to init fnm with fnm env --pid=$$ but we don't.
  3. as I mentioned time does not tell us anything. We might be able to clean on restarts--but I don't know how to hook into that. If you know how to make this magic happen I'd be happy to pair or get your insights so we can bake this into fnm and clean up the symlinks directory.
  4. I have 937 symlinks (shocking, I expected way more). du $(dirname $FNM_MULTISHELL_PATH) return 0 bytes, so I am not concerned about it. should I?

Schniz avatar Aug 16 '22 13:08 Schniz

Maybe this is useful: https://stackoverflow.com/questions/18221348/exit-hook-working-both-on-bash-and-zsh

aesadsklfjsl avatar Oct 28 '22 06:10 aesadsklfjsl

Thanks for this!!!

Schniz avatar Oct 28 '22 15:10 Schniz

Hello~ I don't know why fnm needs to create multishells symlinks. Even if you enter the same path again, it still creates a new and different symlinks. I don't understand why it was designed this way.

fearnliu avatar Jul 20 '23 11:07 fearnliu

Hello~ I don't know why fnm needs to create multishells symlinks. Even if you enter the same path again, it still creates a new and different symlinks. I don't understand why it was designed this way.

@fengyinxu It's because each shell instance can be using its own version of Node.js, so each multishell symlink is specific to one shell instance.

ryanccn avatar Jul 20 '23 11:07 ryanccn

Hello~ I don't know why fnm needs to create multishells symlinks. Even if you enter the same path again, it still creates a new and different symlinks. I don't understand why it was designed this way.

@fengyinxu It's because each shell instance can be using its own version of Node.js, so each multishell symlink is specific to one shell instance.

Typically, what we need is a different version of Nodejs for each project, not each shell instance. I'm not familiar with rust. I'm curious as to why fnm designed it this way (cache, multishells) What is the need for this design. I see there is a PR #865 associated with the issue, but it's a pity that the PR has not been merged now.

fearnliu avatar Jul 20 '23 11:07 fearnliu

@fengyinxu Commands like fnm use change the node version the shell is using; even .node-version and engines.node support set the node version in the shell where you cded into the project.

ryanccn avatar Jul 20 '23 11:07 ryanccn

Is there a reason for not creating these symlinks in $TMPDIR? 🤔

MunifTanjim avatar Aug 17 '23 10:08 MunifTanjim