nodeenv icon indicating copy to clipboard operation
nodeenv copied to clipboard

Request: Allow version ranges

Open xi opened this issue 9 years ago • 2 comments

It would be great if I could define version ranges instead of exact versions, e.g. 4.x or ^4.3.1. It is probably best to use npm syntax for these ranges.

xi avatar Mar 06 '16 20:03 xi

specifically, it would be awesome if nodeenv could take a version range and only install a full nodeenv if the system-provided one doesn't satisfy the version requirement...

dev-zero avatar Jan 11 '21 17:01 dev-zero

It would be nice for scripting the installation if requirement specifiers were supported (like for pip packages) for specifying nodejs/npm versions:

nodeenv --node ">=20.0.0"
nodeenv --node "~=22.0.0"
nodeenv --node "<21.0.0"

Furthermore, it would also be nice to be able to just specify the major (and optionally minor) version (to install the latest one that matches):

nodeenv --node 22
nodeenv --node 21.7

You can easily hack something together to script this, e.g.

import re
import subprocess
from packaging.version import parse
from shlex import split


def set_up_node(nodejs_version: str = "22"):
    subprocess.run(split("nodeenv --list"), capture_output=True, text=True)
    available_versions = [
        parse(v) for v in re.split(r"[\n\t ]", proc.stderr)
        if v and v.startswith(nodejs_version)
    ]
    subprocess.run(split(f"nodeenv env --node={max(available_versions)} --prebuilt"))
    subprocess.run(f". env/bin/activate && npm install --no-fund .", shell=True)

but it would be nice if nodeenv could do this for you

jstucke avatar May 02 '24 07:05 jstucke