asdf-vm

How to manage .tool-versions for current directory without storing it in current directory


I've come to love what asdf does for my onboarding story in projects that i have control over.

However for projects where there is a strange mandate that it must use nvm and must not migrate to asdf for whatever reason, i'd like a way to utilise .tool-versions for certain directories that are unable to have this commited:

maybe something like:

~/.asdf/projects/
  home_me_projects_clientname_projectname.toolversions
  home_me_projects_someotherclientname_projectname.toolversions

then perhaps some kind of direnv magic in my ~/.tool-versions and ~/.direnv that magically picks the right one above depending on what directory i'm in?

anybody else had a need for such a solution?


Solution

  • There are a couple ways to work around that requirement:

    1. If you want to have a .tool-versions file for your projects, but never commit them to Git, try setting up a global gitignore for your .tool-versions files. Then you can use them anywhere and never worry about committing them to any project. (see https://stackoverflow.com/a/7335487/1245380).

    2. Wrap each project directory in an outer directory containing just a .tool-versions file for the project. For example:

      ~/projects
      |--project_1
      |  |--.tool-versions
      |  |--project_1
      |--project_2
      |  |--.tool-versions
      |  |--project_2
      

      This ensures the version info from the .tool-versions files are used when you are working on the source code in the inner project_1 and project_2 directories

    3. Use the nodejs plugins legacy version file support to read the versions from .nvmrc or .node-version files: https://github.com/asdf-vm/asdf-nodejs#nvmrc-and-node-version-support