-
-
Notifications
You must be signed in to change notification settings - Fork 947
Expand file tree
/
Copy pathnode.py
More file actions
50 lines (35 loc) · 1.17 KB
/
node.py
File metadata and controls
50 lines (35 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from __future__ import annotations
import functools
import json
from pre_commit.prefix import Prefix
from pre_commit.request import fetch
RESOLVABLE = ('latest', 'lts')
@functools.cache
def _node_versions() -> dict[str, str]:
resp = fetch('https://nodejs.org/download/release/index.json')
contents = json.load(resp)
ret = {'latest': contents[0]['version']}
for dct in contents:
if dct['lts']:
ret['lts'] = dct['version']
break
else:
raise AssertionError('unreachable')
return ret
def resolve(version: str) -> str:
return _node_versions()[version]
@functools.cache
def _target_platform() -> str:
# to support:
# linux-arm64, linux-ppc64le, linux-s390x, linux-x64
# osx-arm64-tar, osx-x86-tar
# win-arm64-zip, win-x64-zip
# or fallback to `src` ?
raise NotImplementedError
def install(prefix: Prefix, version: str) -> None:
# TODO: download and extract to prefix
raise NotImplementedError
def health_check(prefix: Prefix, version: str) -> str | None:
# TODO: previously checked `node --version`
# TODO: but maybe just check that the installed os/arch is correct?
return None