nvm icon indicating copy to clipboard operation
nvm copied to clipboard

What is the portable way of using NVM's node in Makefiles

Open tuaris opened this issue 1 year ago • 3 comments

I know how to call NVM from a Makefile, assuming everyone is using NVM. What if there is someone out there that's not using NVM? What's the correct way to use the environment NVM sets up from within a Makefile without assuming NVM exists and without forcing a default version change on the user's NVM environment?

For example, in the shell I can do:

node -v # Outputs 20
nvm use # Gets version from .nvmrc with '18' in it
node -v # Outputs 18
npm install
npm build
....

Consider the following Makefile

build:
    node -v
    npm install
    npm build

I would like it to function as follows:

node -v # Outputs 20
nvm use # Gets version from .nvmrc with '18' in it
node -v # Outputs 18
make build
node -v # Outputs 18
....

tuaris avatar Sep 10 '24 20:09 tuaris