summaryrefslogtreecommitdiffstats
path: root/pre_commit/languages/node.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2020-04-28 05:31:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2020-04-28 05:31:37 +0000
commitd48befde4a798ba4da4f30010e9d0105b1f23d8b (patch)
treeec2b561add30ebe20d451f863de6b5319d8fc099 /pre_commit/languages/node.py
parentAdding upstream version 2.2.0. (diff)
downloadpre-commit-d48befde4a798ba4da4f30010e9d0105b1f23d8b.tar.xz
pre-commit-d48befde4a798ba4da4f30010e9d0105b1f23d8b.zip
Adding upstream version 2.3.0.upstream/2.3.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/languages/node.py')
-rw-r--r--pre_commit/languages/node.py16
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)