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