run `nvm use` automatically every time there's a .nvmrc file on the directory

前端 未结 10 1810
南笙
南笙 2020-12-23 11:05

How to configure my shell so that nvm use run automatically every time there\'s a .nvmrc file on the directory and use the latest version or a global config whe

10条回答
  •  旧时难觅i
    2020-12-23 11:35

    I tried many solutions for this and nothing worked the way I wanted, so I wrote my own:

    ZSH function to auto-switch to correct Node version

    As far as I know, this is the only one that meets all the following criteria:

    • guarantees you are always on the right version by searching up the directory tree to find the closest .nvmrc (just like nvm use);
    • can handle any valid .nvmrc format;
    • clearly warns you if no installed version satisfies the .nvmrc,
    • assumes you want default if there is no .nvmrc anywhere up the tree;
    • is completely silent and fast if you are already on the correct Node version.

提交回复
热议问题