Repository navigation
Expand file tree
/
Copy pathnode-manager.ts
More file actions
40 lines (35 loc) · 1.97 KB
/
Copy pathnode-manager.ts
File metadata and controls
40 lines (35 loc) · 1.97 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
import { parseInstalledVpVersion } from "./version.js";
const VERSION_PARTS_RE = /^(\d+)\.(\d+)\.(\d+)/;
// True and unset leave the installer default unchanged (enabled on CI).
// False switches to system Node.js after installation via vp env off node
// (vp env off before 0.3.1), without disabling package-manager management.
// Accept the YAML 1.2 boolean forms (same set as @actions/core
// getBooleanInput); Azure serializes booleans passed to string parameters as
// "True"/"False".
const TRUE_VALUES = new Set(["true", "True", "TRUE"]);
const FALSE_VALUES = new Set(["false", "False", "FALSE"]);
export function parseNodeManager(input: string | undefined): boolean | undefined {
if (!input) return undefined;
if (TRUE_VALUES.has(input)) return true;
if (FALSE_VALUES.has(input)) return false;
throw new Error(`Invalid node-manager input: "${input}". Expected "true", "false", or unset.`);
}
// Scoped env modes were introduced in 0.3.1. Probe the installed version so
// dist-tags and project auto-detection use the same compatibility rule.
export function supportsScopedEnv(versionOutput: string): boolean {
const version = parseInstalledVpVersion(versionOutput);
if (version.startsWith("0.0.0-commit.")) return true;
const match = version.match(VERSION_PARTS_RE);
if (!match)
throw new Error("Could not determine the installed Vite+ version for env configuration.");
const [, major, minor, patch] = match.map(Number);
return major > 0 || minor > 3 || (minor === 3 && patch >= 1);
}
export function nodeManagerOffArgs(versionOutput: string): string[] {
if (parseInstalledVpVersion(versionOutput).startsWith("0.0.0-commit.")) {
console.info(
"setup-vp: node-manager: false requires a preview build that supports `vp env off node`. If this command is unsupported, use a newer preview or a stable release. setup-vp will not fall back to disabling package-manager management.",
);
}
return supportsScopedEnv(versionOutput) ? ["env", "off", "node"] : ["env", "off"];
}