Skip to content

Commit

Permalink
Use version specified in .node-version if exists
Browse files Browse the repository at this point in the history
It's pretty common to have a file `.node-version` in a repo to specify
the version of node to use.

This will pick up the version specified in this file and use that as
the default when `Config` is initialised.
  • Loading branch information
whi-tw committed Oct 12, 2021
1 parent 21d6a78 commit f01c7d6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nodeenv.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def _load(cls, configfiles, verbose=False):
"""
Load configuration from the given files in reverse order,
if they exist and have a [nodeenv] section.
Additionally, load version from .node-version if file exists.
"""
for configfile in reversed(configfiles):
configfile = os.path.expanduser(configfile)
Expand Down Expand Up @@ -133,6 +134,10 @@ def _load(cls, configfiles, verbose=False):
os.path.basename(configfile), attr, val))
setattr(cls, attr, val)

if os.path.exists(".node-version"):
with open(".node-version", "r") as v_file:
setattr(cls, "node", v_file.readlines(1)[0].strip())

@classmethod
def _dump(cls):
"""
Expand Down

0 comments on commit f01c7d6

Please sign in to comment.