diff options
Diffstat (limited to 'pre_commit/languages/node.py')
-rw-r--r-- | pre_commit/languages/node.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/pre_commit/languages/node.py b/pre_commit/languages/node.py index 79ff807..9b636d3 100644 --- a/pre_commit/languages/node.py +++ b/pre_commit/languages/node.py @@ -1,4 +1,5 @@ import contextlib +import functools import os import sys from typing import Generator @@ -6,6 +7,7 @@ from typing import Sequence from typing import Tuple import pre_commit.constants as C +from pre_commit import parse_shebang from pre_commit.envcontext import envcontext from pre_commit.envcontext import PatchesT from pre_commit.envcontext import Var @@ -18,10 +20,22 @@ from pre_commit.util import cmd_output from pre_commit.util import cmd_output_b ENVIRONMENT_DIR = 'node_env' -get_default_version = helpers.basic_get_default_version healthy = helpers.basic_healthy +@functools.lru_cache(maxsize=1) +def get_default_version() -> str: + # nodeenv does not yet support `-n system` on windows + if sys.platform == 'win32': + return C.DEFAULT + # if node is already installed, we can save a bunch of setup time by + # using the installed version + elif all(parse_shebang.find_executable(exe) for exe in ('node', 'npm')): + return 'system' + else: + return C.DEFAULT + + def _envdir(prefix: Prefix, version: str) -> str: directory = helpers.environment_dir(ENVIRONMENT_DIR, version) return prefix.path(directory) |