Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tuaris opened this issue Sep 10, 2024 · 3 comments
Open

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

tuaris opened this issue Sep 10, 2024 · 3 comments

Comments

@tuaris
Copy link

tuaris commented Sep 10, 2024

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
....
@ljharb
Copy link
Member

ljharb commented Sep 10, 2024

I'm not sure what you're asking.

nvm is a sourced shell function, so for a user to have it available, they have to have installed it on their machine. A Makefile can't set that up for them (short of running the install script)

@tuaris
Copy link
Author

tuaris commented Sep 10, 2024

I'm not sure what you're asking.

nvm is a sourced shell function, so for a user to have it available, they have to have installed it on their machine. A Makefile can't set that up for them (short of running the install script)

I'd like my example Makefile to work with and without NVM. If the user wants to or has a version of node/npm setup by NVM, the Makefile should respect it.

@ljharb
Copy link
Member

ljharb commented Sep 10, 2024

Certainly the makefile can which node, and if it's found, just use that - and if not, set up its own nvm and use that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@ljharb @tuaris and others