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

Support the use of Node.js as an npm dependency #8

Merged
merged 8 commits into from
Feb 22, 2020

Conversation

mearns
Copy link
Contributor

@mearns mearns commented Nov 16, 2019

A common pattern in npm projects is to specify node as a dependency or devDependency in order to make sure that npm scripts are run with the desired node version. Changes in this pull request will prioritize looking for the presence of an installed ./node_modules/node dependency and use that version if found. I propose that this is the preferred behavior for users, but it is technically breaking backward compatibility because existing uses that happen to have node installed as a dependency will now behave differently.

Two other changes are also rolled into this PR, though they could be separated if they aren't desired. One is that if RUN_NODE_CACHE_PATH is defined and the specified path cache file exists, then it is sourced immediately, instead of waiting to see if node is already found on the existing path. This allows a user to use the env var to override the system path with a custom path cache, which is helpful if their PATH already contains a node executable, but not the one they want to us.

The other change is to allow for a local .node_path file which can also be used to override the system path to use a specific node version: if this file is present (and RUN_NODE_CACHE_PATH is not defined), it will likewise be sourced immediately before checking for the presence of a node command.

This will help allow users to force a particular node version to be used, even if there is already one on the path.
Common pattern is to use node as a devDependency in an npm package so that everything uses that version
of node; if it's present, run-node should probably use that as well.

Unless told not to. Which can be done by specifying the RUN_NODE_CACHE_PATH, in which case that file
will be sourced to update the PATH.

Or, you can do so by having a local .node_path file, which will be sourced if present (and RUN_NODE_CACHE_PATH
is not defined).
run-node Outdated Show resolved Hide resolved
@sindresorhus
Copy link
Owner

sindresorhus commented Nov 16, 2019

I'm ok with the first two changes, but I don't really want the .node_path thing. The behavior of the first two changes should be documented in the readme, so it's clear to the user how it works.

Copy link
Contributor Author

@mearns mearns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it; I'll remove the local node_path, fix the tabs, and update the README.

@mearns
Copy link
Contributor Author

mearns commented Nov 17, 2019

I believe I made the changes as requested, please let me know if there are any other changes you'd like me to make =)

@sindresorhus sindresorhus changed the title Support the use of node as an npm dependency Support the use of Node.js as an npm dependency Feb 22, 2020
@sindresorhus sindresorhus merged commit 9a69ce7 into sindresorhus:master Feb 22, 2020
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

Successfully merging this pull request may close these issues.

2 participants