@anvil-works/anvil-cli 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -1
- package/dist/cli.js +64 -44
- package/dist/program.d.ts.map +1 -1
- package/dist/services/node-runtime.d.ts +9 -0
- package/dist/services/node-runtime.d.ts.map +1 -0
- package/package.json +1 -1
- package/scripts/install/install.cmd +11 -1
- package/scripts/install/install.ps1 +59 -43
- package/scripts/install/install.sh +108 -33
package/README.md
CHANGED
|
@@ -29,12 +29,40 @@ irm https://anvil.works/install-cli.ps1 | iex
|
|
|
29
29
|
curl -fsSL https://anvil.works/install-cli.cmd -o install.cmd && install.cmd && del install.cmd
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
### npm
|
|
32
|
+
### Manual npm installation
|
|
33
|
+
|
|
34
|
+
This requires your own supported Node.js installation (22, 24 or 26 LTS).
|
|
33
35
|
|
|
34
36
|
```bash
|
|
35
37
|
npm install -g @anvil-works/anvil-cli@latest
|
|
36
38
|
```
|
|
37
39
|
|
|
40
|
+
The installers use an independently installed Node.js 22, 24 or 26 LTS when available. If Node is missing or unsupported, installation stops with setup instructions. There are no interactive prompts.
|
|
41
|
+
|
|
42
|
+
To allow the installer to provide a private Node.js 24 copy when needed, use the appropriate command below.
|
|
43
|
+
|
|
44
|
+
macOS/Linux:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
curl -fsSL https://anvil.works/install-cli.sh | sh -s -- --install-node
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
PowerShell:
|
|
51
|
+
|
|
52
|
+
```powershell
|
|
53
|
+
& ([scriptblock]::Create((irm https://anvil.works/install-cli.ps1))) -InstallNode
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
CMD:
|
|
57
|
+
|
|
58
|
+
```cmd
|
|
59
|
+
curl -fsSL https://anvil.works/install-cli.cmd -o install.cmd && install.cmd --install-node && del install.cmd
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The private copy is stored under `~/.anvil-cli` and added to PATH, so other Node tools may use it too. Rerunning the installer updates that copy to the latest Node 24 release and migrates older bundled Node 20 installations.
|
|
63
|
+
|
|
64
|
+
Run `anvil update` to check for CLI and bundled Node updates. If bundled Node needs updating, it shows the installer command to rerun.
|
|
65
|
+
|
|
38
66
|
## Quickstart
|
|
39
67
|
|
|
40
68
|
This is the main happy path:
|
package/dist/cli.js
CHANGED
|
@@ -17015,25 +17015,55 @@ Examples:
|
|
|
17015
17015
|
await runTestCommand(targets, options);
|
|
17016
17016
|
});
|
|
17017
17017
|
}
|
|
17018
|
+
var external_os_ = __webpack_require__("os");
|
|
17019
|
+
async function getManagedNodeUpdate() {
|
|
17020
|
+
const anvilHome = process.env.ANVIL_HOME || (0, external_path_.join)((0, external_os_.homedir)(), ".anvil-cli");
|
|
17021
|
+
let executable;
|
|
17022
|
+
try {
|
|
17023
|
+
executable = (0, external_path_.relative)((0, external_fs_.realpathSync)(anvilHome), (0, external_fs_.realpathSync)(process.execPath)).split(external_path_.sep).join("/");
|
|
17024
|
+
} catch {
|
|
17025
|
+
return null;
|
|
17026
|
+
}
|
|
17027
|
+
if (!/^node-v(?:20|24)\/(?:bin\/node|node\.exe)$/i.test(executable)) return null;
|
|
17028
|
+
let latestVersion = null;
|
|
17029
|
+
try {
|
|
17030
|
+
const response = await fetch("https://nodejs.org/dist/latest-v24.x/SHASUMS256.txt", {
|
|
17031
|
+
signal: AbortSignal.timeout(5000)
|
|
17032
|
+
});
|
|
17033
|
+
if (response.ok) latestVersion = (await response.text()).match(/\bnode-(v24\.\d+\.\d+)-/)?.[1] ?? null;
|
|
17034
|
+
} catch {}
|
|
17035
|
+
const outdated = external_semver_default().major(process.version) < 24 || null !== latestVersion && external_semver_default().lt(process.version, latestVersion);
|
|
17036
|
+
return {
|
|
17037
|
+
currentVersion: process.version,
|
|
17038
|
+
latestVersion,
|
|
17039
|
+
status: outdated ? "update-available" : latestVersion ? "up-to-date" : "check-failed"
|
|
17040
|
+
};
|
|
17041
|
+
}
|
|
17018
17042
|
var validate = __webpack_require__("./src/commands/validate.ts");
|
|
17019
17043
|
var programBase = __webpack_require__("./src/programBase.ts");
|
|
17020
17044
|
function getUpdateInstructions(platform) {
|
|
17021
|
-
|
|
17022
|
-
|
|
17023
|
-
"curl -fsSL https://anvil.works/install-cli.cmd -o install.cmd && install.cmd && del install.cmd || npm install -g @anvil-works/anvil-cli@latest",
|
|
17045
|
+
return [
|
|
17046
|
+
...getInstallerInstructions(platform),
|
|
17024
17047
|
"npm install -g @anvil-works/anvil-cli@latest",
|
|
17025
17048
|
"pnpm add -g @anvil-works/anvil-cli@latest"
|
|
17026
17049
|
];
|
|
17050
|
+
}
|
|
17051
|
+
function getInstallerInstructions(platform) {
|
|
17052
|
+
if ("win32" === platform) return [
|
|
17053
|
+
"irm https://anvil.works/install-cli.ps1 | iex",
|
|
17054
|
+
"curl -fsSL https://anvil.works/install-cli.cmd -o install.cmd && install.cmd && del install.cmd"
|
|
17055
|
+
];
|
|
17027
17056
|
return [
|
|
17028
|
-
"curl -fsSL https://anvil.works/install-cli.sh | sh
|
|
17029
|
-
"npm install -g @anvil-works/anvil-cli@latest",
|
|
17030
|
-
"pnpm add -g @anvil-works/anvil-cli@latest"
|
|
17057
|
+
"curl -fsSL https://anvil.works/install-cli.sh | sh"
|
|
17031
17058
|
];
|
|
17032
17059
|
}
|
|
17033
17060
|
async function handleUpdateCommand() {
|
|
17034
17061
|
try {
|
|
17035
17062
|
src_logger.vF.progress("update", "Checking for updates...");
|
|
17036
|
-
const latestVersion = await
|
|
17063
|
+
const [latestVersion, nodeRuntime] = await Promise.all([
|
|
17064
|
+
(0, anvil_api.getLatestVersion)(),
|
|
17065
|
+
getManagedNodeUpdate()
|
|
17066
|
+
]);
|
|
17037
17067
|
src_logger.vF.progressEnd("update");
|
|
17038
17068
|
if (!latestVersion) {
|
|
17039
17069
|
src_logger.vF.warn("Could not check for updates. Please check your internet connection.");
|
|
@@ -17043,55 +17073,45 @@ Examples:
|
|
|
17043
17073
|
src_logger.vF.warn("Could not compare versions. Version format may be invalid.");
|
|
17044
17074
|
process.exit(1);
|
|
17045
17075
|
}
|
|
17046
|
-
|
|
17047
|
-
|
|
17048
|
-
|
|
17049
|
-
|
|
17050
|
-
latestVersion,
|
|
17051
|
-
status: "up-to-date"
|
|
17052
|
-
}
|
|
17053
|
-
});
|
|
17054
|
-
else {
|
|
17055
|
-
src_logger.vF.success(`You're already using the latest version: ${programBase.xv}`);
|
|
17056
|
-
console.log();
|
|
17057
|
-
}
|
|
17058
|
-
return;
|
|
17059
|
-
}
|
|
17060
|
-
if (external_semver_default().gt(programBase.xv, latestVersion)) {
|
|
17061
|
-
if ((0, globalConfig.JP)().jsonMode) (0, src_logger.SP)(true, {
|
|
17062
|
-
data: {
|
|
17063
|
-
currentVersion: programBase.xv,
|
|
17064
|
-
latestVersion,
|
|
17065
|
-
status: "ahead",
|
|
17066
|
-
note: "This might be a development build."
|
|
17067
|
-
}
|
|
17068
|
-
});
|
|
17069
|
-
else {
|
|
17070
|
-
src_logger.vF.warn(`You're using version ${programBase.xv}, which is newer than the latest published version ${latestVersion}.`);
|
|
17071
|
-
console.log(external_chalk_default().gray(" This might be a development build."));
|
|
17072
|
-
console.log();
|
|
17073
|
-
}
|
|
17074
|
-
return;
|
|
17075
|
-
}
|
|
17076
|
-
const instructions = getUpdateInstructions(process.platform);
|
|
17076
|
+
const cliStatus = external_semver_default().eq(programBase.xv, latestVersion) ? "up-to-date" : external_semver_default().gt(programBase.xv, latestVersion) ? "ahead" : "update-available";
|
|
17077
|
+
const runtimeUpdateAvailable = nodeRuntime?.status === "update-available";
|
|
17078
|
+
const updateAvailable = "update-available" === cliStatus || runtimeUpdateAvailable;
|
|
17079
|
+
const instructions = runtimeUpdateAvailable ? getInstallerInstructions(process.platform) : getUpdateInstructions(process.platform);
|
|
17077
17080
|
if ((0, globalConfig.JP)().jsonMode) return void (0, src_logger.SP)(true, {
|
|
17078
17081
|
data: {
|
|
17079
17082
|
currentVersion: programBase.xv,
|
|
17080
17083
|
latestVersion,
|
|
17081
|
-
status: "update-available",
|
|
17082
|
-
|
|
17084
|
+
status: runtimeUpdateAvailable ? "update-available" : cliStatus,
|
|
17085
|
+
..."ahead" === cliStatus ? {
|
|
17086
|
+
note: "This might be a development build."
|
|
17087
|
+
} : {},
|
|
17088
|
+
...nodeRuntime ? {
|
|
17089
|
+
nodeRuntime
|
|
17090
|
+
} : {},
|
|
17091
|
+
...updateAvailable ? {
|
|
17092
|
+
instructions
|
|
17093
|
+
} : {}
|
|
17083
17094
|
}
|
|
17084
17095
|
});
|
|
17085
|
-
src_logger.vF.
|
|
17096
|
+
if ("up-to-date" === cliStatus) src_logger.vF.success(`You're already using the latest CLI version: ${programBase.xv}`);
|
|
17097
|
+
else if ("ahead" === cliStatus) {
|
|
17098
|
+
src_logger.vF.warn(`You're using version ${programBase.xv}, which is newer than the latest published version ${latestVersion}.`);
|
|
17099
|
+
console.log(external_chalk_default().gray(" This might be a development build."));
|
|
17100
|
+
} else src_logger.vF.warn(`↑ Update available: ${programBase.xv} → ${latestVersion}`);
|
|
17101
|
+
if (runtimeUpdateAvailable) src_logger.vF.warn(`Bundled Node.js update available: ${nodeRuntime.currentVersion} → ${nodeRuntime.latestVersion ?? "Node.js 24 LTS"}`);
|
|
17102
|
+
else if (nodeRuntime?.status === "check-failed") src_logger.vF.warn("Could not check bundled Node.js for updates. Please check your internet connection.");
|
|
17086
17103
|
console.log();
|
|
17087
|
-
|
|
17104
|
+
if (!updateAvailable) return;
|
|
17105
|
+
console.log(external_chalk_default().cyan(runtimeUpdateAvailable ? "To update bundled Node.js and the CLI, rerun the installer:" : "To update, run one of the following commands:"));
|
|
17088
17106
|
console.log();
|
|
17089
17107
|
if ("win32" === process.platform) {
|
|
17090
17108
|
console.log(external_chalk_default().gray(" PowerShell: ") + external_chalk_default().white(instructions[0]));
|
|
17091
17109
|
console.log(external_chalk_default().gray(" CMD: ") + external_chalk_default().white(instructions[1]));
|
|
17092
17110
|
} else console.log(external_chalk_default().gray(" macOS/Linux: ") + external_chalk_default().white(instructions[0]));
|
|
17093
|
-
|
|
17094
|
-
|
|
17111
|
+
if (!runtimeUpdateAvailable) {
|
|
17112
|
+
console.log(external_chalk_default().gray(" npm: ") + external_chalk_default().white(instructions[instructions.length - 2]));
|
|
17113
|
+
console.log(external_chalk_default().gray(" pnpm: ") + external_chalk_default().white(instructions[instructions.length - 1]));
|
|
17114
|
+
}
|
|
17095
17115
|
console.log();
|
|
17096
17116
|
} catch (e) {
|
|
17097
17117
|
src_logger.vF.error("Error: " + e.message);
|
package/dist/program.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA2BzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,GAAG,MAAM,EAAE,CAMzE;AAYD,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CA8EzD;AAED,wBAAgB,YAAY,IAAI,OAAO,CAyDtC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface ManagedNodeUpdate {
|
|
2
|
+
currentVersion: string;
|
|
3
|
+
latestVersion: string | null;
|
|
4
|
+
status: "up-to-date" | "update-available" | "check-failed";
|
|
5
|
+
}
|
|
6
|
+
/** Check only the runtime installed by our installers; other Node installations belong to the user. */
|
|
7
|
+
export declare function getManagedNodeUpdate(): Promise<ManagedNodeUpdate | null>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=node-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-runtime.d.ts","sourceRoot":"","sources":["../../src/services/node-runtime.ts"],"names":[],"mappings":"AAKA,UAAU,iBAAiB;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,MAAM,EAAE,YAAY,GAAG,kBAAkB,GAAG,cAAc,CAAC;CAC9D;AAED,uGAAuG;AACvG,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CA+B9E"}
|
package/package.json
CHANGED
|
@@ -3,6 +3,16 @@ REM Source of truth: @anvil-works/anvil-cli (scripts/install/install.cmd).
|
|
|
3
3
|
REM This script is synced into anvil website static install endpoints; do not edit the synced copy directly.
|
|
4
4
|
setlocal
|
|
5
5
|
|
|
6
|
+
set "NODE_OPTION="
|
|
7
|
+
if "%~1"=="--install-node" (
|
|
8
|
+
set "NODE_OPTION=-InstallNode"
|
|
9
|
+
shift
|
|
10
|
+
)
|
|
11
|
+
if not "%~1"=="" (
|
|
12
|
+
echo Error: supported option is --install-node.
|
|
13
|
+
exit /b 1
|
|
14
|
+
)
|
|
15
|
+
|
|
6
16
|
set "SCRIPT_URL=%ANVIL_INSTALL_URL%"
|
|
7
17
|
if not defined SCRIPT_URL set "SCRIPT_URL=https://anvil.works/install-cli.ps1"
|
|
8
18
|
set "SCRIPT_PATH=%TEMP%\anvil-install-%RANDOM%%RANDOM%.ps1"
|
|
@@ -26,7 +36,7 @@ if errorlevel 1 (
|
|
|
26
36
|
exit /b 1
|
|
27
37
|
)
|
|
28
38
|
|
|
29
|
-
powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_PATH%"
|
|
39
|
+
powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_PATH%" %NODE_OPTION%
|
|
30
40
|
set "EXIT_CODE=%ERRORLEVEL%"
|
|
31
41
|
|
|
32
42
|
del /q "%SCRIPT_PATH%" >nul 2>&1
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
# Source of truth: @anvil-works/anvil-cli (scripts/install/install.ps1).
|
|
2
2
|
# This script is synced into anvil website static install endpoints; do not edit the synced copy directly.
|
|
3
|
+
param([switch]$InstallNode)
|
|
4
|
+
|
|
3
5
|
$ErrorActionPreference = 'Stop'
|
|
4
6
|
Set-StrictMode -Version Latest
|
|
5
7
|
|
|
6
8
|
$AnvilHome = if ($env:ANVIL_HOME) { $env:ANVIL_HOME } else { Join-Path $env:USERPROFILE '.anvil-cli' }
|
|
7
|
-
$
|
|
9
|
+
$AnvilHome = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($AnvilHome)
|
|
10
|
+
$NodeDir = Join-Path $AnvilHome 'node-v24'
|
|
11
|
+
$LegacyNodeDir = Join-Path $AnvilHome 'node-v20'
|
|
8
12
|
$NpmPrefix = Join-Path $AnvilHome 'npm-global'
|
|
9
|
-
$MinTargetMajor = 20
|
|
10
13
|
|
|
11
14
|
function Write-Info([string] $Message) {
|
|
12
15
|
Write-Host $Message
|
|
@@ -29,41 +32,34 @@ function Get-PlatformArch {
|
|
|
29
32
|
return 'x64'
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
function Get-
|
|
33
|
-
|
|
34
|
-
return $null
|
|
35
|
+
function Get-NodeVersion([string] $Command) {
|
|
36
|
+
try {
|
|
37
|
+
return ([string](& $Command -v 2>$null)).Trim()
|
|
35
38
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if ($version -match '^v(\d+)') {
|
|
39
|
-
return [int]$Matches[1]
|
|
39
|
+
catch {
|
|
40
|
+
return ''
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
return $null
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
function Update-CurrentPath {
|
|
46
|
-
$
|
|
45
|
+
if ($UseManagedNode) {
|
|
46
|
+
$env:Path = "$NodeDir;$env:Path"
|
|
47
|
+
}
|
|
48
|
+
$env:Path = "$NpmPrefix;$env:Path"
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
function
|
|
51
|
+
function Update-UserPath {
|
|
50
52
|
$currentUserPath = [Environment]::GetEnvironmentVariable('Path', 'User')
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
$parts = $currentUserPath -split ';' | Where-Object { $_ -ne '' }
|
|
57
|
-
if ($parts -contains $Segment) {
|
|
58
|
-
return
|
|
53
|
+
$parts = @($currentUserPath -split ';' | Where-Object { $_ -and $_ -notin @($LegacyNodeDir, $NodeDir, $NpmPrefix) })
|
|
54
|
+
if ($UseManagedNode) {
|
|
55
|
+
$parts = @($NodeDir) + $parts
|
|
59
56
|
}
|
|
60
|
-
|
|
61
|
-
[Environment]::SetEnvironmentVariable('Path', "$Segment;$currentUserPath", 'User')
|
|
57
|
+
[Environment]::SetEnvironmentVariable('Path', ((@($NpmPrefix) + $parts) -join ';'), 'User')
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
function Install-
|
|
60
|
+
function Install-NodeV24 {
|
|
65
61
|
$arch = Get-PlatformArch
|
|
66
|
-
$baseUrl = 'https://nodejs.org/dist/latest-
|
|
62
|
+
$baseUrl = 'https://nodejs.org/dist/latest-v24.x'
|
|
67
63
|
$sumsUrl = "$baseUrl/SHASUMS256.txt"
|
|
68
64
|
|
|
69
65
|
$tmpRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("anvil-install-" + [System.Guid]::NewGuid().ToString('N'))
|
|
@@ -73,7 +69,7 @@ function Install-NodeV20 {
|
|
|
73
69
|
$sumsPath = Join-Path $tmpRoot 'SHASUMS256.txt'
|
|
74
70
|
Invoke-WebRequest -UseBasicParsing -Uri $sumsUrl -OutFile $sumsPath
|
|
75
71
|
|
|
76
|
-
$pattern = "node-
|
|
72
|
+
$pattern = "node-v24\.[0-9]+\.[0-9]+-win-$arch\.zip$"
|
|
77
73
|
$archiveLine = Get-Content -LiteralPath $sumsPath | Where-Object { $_ -match $pattern } | Select-Object -First 1
|
|
78
74
|
if (-not $archiveLine) {
|
|
79
75
|
Fail "Could not resolve Node.js archive for win-$arch"
|
|
@@ -81,10 +77,16 @@ function Install-NodeV20 {
|
|
|
81
77
|
|
|
82
78
|
$tokens = $archiveLine -split '\s+'
|
|
83
79
|
$archiveName = $tokens[-1]
|
|
80
|
+
$latestVersion = ($archiveName -split '-')[1]
|
|
81
|
+
$nodeExe = Join-Path $NodeDir 'node.exe'
|
|
82
|
+
if ((Test-Path -LiteralPath $nodeExe) -and (Get-NodeVersion $nodeExe) -eq $latestVersion) {
|
|
83
|
+
Write-Info "Using current bundled Node.js $latestVersion"
|
|
84
|
+
return
|
|
85
|
+
}
|
|
84
86
|
$archivePath = Join-Path $tmpRoot $archiveName
|
|
85
87
|
$archiveUrl = "$baseUrl/$archiveName"
|
|
86
88
|
|
|
87
|
-
Write-Info "Installing Node.js
|
|
89
|
+
Write-Info "Installing Node.js $latestVersion for win-$arch..."
|
|
88
90
|
Invoke-WebRequest -UseBasicParsing -Uri $archiveUrl -OutFile $archivePath
|
|
89
91
|
|
|
90
92
|
$expectedHash = ($tokens | Where-Object { $_ -match '^[A-Fa-f0-9]{64}$' } | Select-Object -First 1)
|
|
@@ -95,16 +97,15 @@ function Install-NodeV20 {
|
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
if (Test-Path -LiteralPath $NodeDir) {
|
|
99
|
-
Remove-Item -LiteralPath $NodeDir -Recurse -Force
|
|
100
|
-
}
|
|
101
|
-
|
|
102
100
|
Expand-Archive -LiteralPath $archivePath -DestinationPath $tmpRoot -Force
|
|
103
|
-
$expandedRoot = Get-ChildItem -LiteralPath $tmpRoot -Directory | Where-Object { $_.Name -like 'node-
|
|
101
|
+
$expandedRoot = Get-ChildItem -LiteralPath $tmpRoot -Directory | Where-Object { $_.Name -like 'node-v24.*-win-*' } | Select-Object -First 1
|
|
104
102
|
if (-not $expandedRoot) {
|
|
105
103
|
Fail 'Failed to locate extracted Node.js directory'
|
|
106
104
|
}
|
|
107
105
|
|
|
106
|
+
if (Test-Path -LiteralPath $NodeDir) {
|
|
107
|
+
Remove-Item -LiteralPath $NodeDir -Recurse -Force
|
|
108
|
+
}
|
|
108
109
|
Move-Item -LiteralPath $expandedRoot.FullName -Destination $NodeDir
|
|
109
110
|
}
|
|
110
111
|
finally {
|
|
@@ -115,24 +116,36 @@ function Install-NodeV20 {
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
function Ensure-Node {
|
|
118
|
-
$
|
|
119
|
-
if ($
|
|
120
|
-
|
|
119
|
+
$nodeCommand = Get-Command node -ErrorAction SilentlyContinue
|
|
120
|
+
if ($nodeCommand -and $nodeCommand.CommandType -eq 'Application' -and (Split-Path -Parent $nodeCommand.Source) -in @($LegacyNodeDir, $NodeDir)) {
|
|
121
|
+
Install-NodeV24
|
|
122
|
+
return $true
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
$version = if ($nodeCommand) { Get-NodeVersion 'node' } else { '' }
|
|
126
|
+
$major = if ($version -match '^v(\d+)') { [int]$Matches[1] } else { $null }
|
|
127
|
+
if ($major -in @(22, 24, 26)) {
|
|
121
128
|
Write-Info "Using existing Node.js $version"
|
|
122
|
-
return
|
|
129
|
+
return $false
|
|
123
130
|
}
|
|
124
131
|
|
|
125
|
-
if ($
|
|
126
|
-
|
|
132
|
+
if (-not $InstallNode) {
|
|
133
|
+
$found = if ($version) { "found Node.js $version" } elseif ($nodeCommand) { 'Node.js could not report its version' } else { 'Node.js was not found' }
|
|
134
|
+
Fail "Anvil CLI requires Node.js 22, 24 or 26 LTS; $found.
|
|
135
|
+
Install/update Node.js yourself: https://nodejs.org/en/download
|
|
136
|
+
Or install a private Node.js 24 copy and add it to PATH:
|
|
137
|
+
PowerShell: & ([scriptblock]::Create((irm https://anvil.works/install-cli.ps1))) -InstallNode
|
|
138
|
+
CMD: curl -fsSL https://anvil.works/install-cli.cmd -o install.cmd && install.cmd --install-node && del install.cmd"
|
|
127
139
|
}
|
|
128
140
|
|
|
129
141
|
Ensure-Directory -Path $AnvilHome
|
|
130
|
-
Install-
|
|
142
|
+
Install-NodeV24
|
|
143
|
+
return $true
|
|
131
144
|
}
|
|
132
145
|
|
|
133
146
|
function Ensure-Npm {
|
|
134
147
|
$npmCmd = Join-Path $NodeDir 'npm.cmd'
|
|
135
|
-
if (Test-Path -LiteralPath $npmCmd) {
|
|
148
|
+
if ($UseManagedNode -and (Test-Path -LiteralPath $npmCmd)) {
|
|
136
149
|
return $npmCmd
|
|
137
150
|
}
|
|
138
151
|
|
|
@@ -191,11 +204,10 @@ function Main {
|
|
|
191
204
|
Ensure-Directory -Path $AnvilHome
|
|
192
205
|
Ensure-Directory -Path $NpmPrefix
|
|
193
206
|
|
|
194
|
-
Ensure-Node
|
|
207
|
+
$UseManagedNode = Ensure-Node
|
|
195
208
|
|
|
196
209
|
Update-CurrentPath
|
|
197
|
-
|
|
198
|
-
Add-UserPathSegment -Segment $NpmPrefix
|
|
210
|
+
Update-UserPath
|
|
199
211
|
|
|
200
212
|
Warn-IfMissingGit
|
|
201
213
|
|
|
@@ -217,6 +229,10 @@ function Main {
|
|
|
217
229
|
Fail "anvil installed but command verification failed: $($_.Exception.Message)"
|
|
218
230
|
}
|
|
219
231
|
|
|
232
|
+
if (Test-Path -LiteralPath $LegacyNodeDir) {
|
|
233
|
+
Remove-Item -LiteralPath $LegacyNodeDir -Recurse -Force
|
|
234
|
+
}
|
|
235
|
+
|
|
220
236
|
Write-Info ''
|
|
221
237
|
Write-Info "anvil-cli installed successfully (v$version)"
|
|
222
238
|
Write-Info "Next steps: run 'anvil configure' or 'anvil checkout'"
|
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
set -eu
|
|
5
5
|
|
|
6
6
|
ANVIL_HOME="${ANVIL_HOME:-$HOME/.anvil-cli}"
|
|
7
|
-
|
|
7
|
+
mkdir -p "$ANVIL_HOME"
|
|
8
|
+
ANVIL_HOME="$(cd "$ANVIL_HOME" && pwd -P)"
|
|
9
|
+
NODE_DIR="$ANVIL_HOME/node-v24"
|
|
8
10
|
NPM_PREFIX="$ANVIL_HOME/npm-global"
|
|
9
|
-
|
|
11
|
+
USE_MANAGED_NODE=1
|
|
12
|
+
INSTALL_NODE=0
|
|
10
13
|
|
|
11
14
|
log() {
|
|
12
15
|
printf '%s\n' "$*"
|
|
@@ -29,7 +32,10 @@ is_windows_posix() {
|
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
windows_posix_node_error() {
|
|
32
|
-
fail "Windows Git Bash
|
|
35
|
+
fail "Windows Git Bash requires Node.js 22, 24 or 26 LTS and npm.
|
|
36
|
+
Install/update Node.js yourself: https://nodejs.org/en/download
|
|
37
|
+
Or use PowerShell to install a private Node.js 24 copy and add it to PATH:
|
|
38
|
+
& ([scriptblock]::Create((irm https://anvil.works/install-cli.ps1))) -InstallNode"
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
normalize_npm_prefix() {
|
|
@@ -66,15 +72,49 @@ cleanup_legacy_npm_prefix() {
|
|
|
66
72
|
append_path_export() {
|
|
67
73
|
profile_file="$1"
|
|
68
74
|
if is_windows_posix; then
|
|
69
|
-
line='export PATH="$HOME/.anvil-cli/npm-global:$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-
|
|
75
|
+
line='export PATH="$HOME/.anvil-cli/npm-global:$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v24/bin:$PATH"'
|
|
76
|
+
if [ "${USE_MANAGED_NODE:-1}" -eq 0 ]; then
|
|
77
|
+
line='export PATH="$HOME/.anvil-cli/npm-global:$HOME/.anvil-cli/npm-global/bin:$PATH"'
|
|
78
|
+
fi
|
|
70
79
|
else
|
|
71
|
-
line='export PATH="$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-
|
|
80
|
+
line='export PATH="$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v24/bin:$PATH"'
|
|
81
|
+
if [ "${USE_MANAGED_NODE:-1}" -eq 0 ]; then
|
|
82
|
+
line='export PATH="$HOME/.anvil-cli/npm-global/bin:$PATH"'
|
|
83
|
+
fi
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
system_node_line="$line"
|
|
87
|
+
managed_node_line="$line"
|
|
88
|
+
if [ "$ANVIL_HOME" != "$(cd "$HOME" && pwd -P)/.anvil-cli" ]; then
|
|
89
|
+
saved_path="$NPM_PREFIX/bin"
|
|
90
|
+
if is_windows_posix; then
|
|
91
|
+
saved_path="$NPM_PREFIX:$saved_path"
|
|
92
|
+
fi
|
|
93
|
+
# Single-quote the actual custom location when saving it as shell code.
|
|
94
|
+
saved_path="$(printf '%s' "$saved_path" | sed "s/'/'\\\\''/g")"
|
|
95
|
+
saved_node_path="$(printf '%s' "$NODE_DIR/bin" | sed "s/'/'\\\\''/g")"
|
|
96
|
+
system_node_line="export PATH='$saved_path':\$PATH"
|
|
97
|
+
managed_node_line="export PATH='$saved_path:$saved_node_path':\$PATH"
|
|
98
|
+
line="$system_node_line"
|
|
99
|
+
if [ "${USE_MANAGED_NODE:-1}" -eq 1 ]; then
|
|
100
|
+
line="$managed_node_line"
|
|
101
|
+
fi
|
|
72
102
|
fi
|
|
73
103
|
|
|
74
104
|
[ -f "$profile_file" ] || touch "$profile_file"
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
105
|
+
profile_tmp="$(mktemp)"
|
|
106
|
+
# Replace only the exact PATH exports written by these installers.
|
|
107
|
+
grep -Fvx \
|
|
108
|
+
-e 'export PATH="$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v20/bin:$PATH"' \
|
|
109
|
+
-e 'export PATH="$HOME/.anvil-cli/npm-global:$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v20/bin:$PATH"' \
|
|
110
|
+
-e 'export PATH="$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v24/bin:$PATH"' \
|
|
111
|
+
-e 'export PATH="$HOME/.anvil-cli/npm-global:$HOME/.anvil-cli/npm-global/bin:$HOME/.anvil-cli/node-v24/bin:$PATH"' \
|
|
112
|
+
-e 'export PATH="$HOME/.anvil-cli/npm-global/bin:$PATH"' \
|
|
113
|
+
-e 'export PATH="$HOME/.anvil-cli/npm-global:$HOME/.anvil-cli/npm-global/bin:$PATH"' \
|
|
114
|
+
-e "$system_node_line" -e "$managed_node_line" "$profile_file" > "$profile_tmp" || [ "$?" -eq 1 ]
|
|
115
|
+
printf '%s\n' "$line" >> "$profile_tmp"
|
|
116
|
+
cat "$profile_tmp" > "$profile_file"
|
|
117
|
+
rm -f "$profile_tmp"
|
|
78
118
|
}
|
|
79
119
|
|
|
80
120
|
persist_path_hint() {
|
|
@@ -109,26 +149,29 @@ detect_platform() {
|
|
|
109
149
|
esac
|
|
110
150
|
}
|
|
111
151
|
|
|
112
|
-
|
|
113
|
-
node -v 2>/dev/null | sed -E 's/^v([0-9]+).*/\1/'
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
install_node_v20() {
|
|
152
|
+
install_node_v24() {
|
|
117
153
|
detect_platform
|
|
118
154
|
need_cmd curl
|
|
119
155
|
need_cmd tar
|
|
120
156
|
|
|
121
|
-
base_url="https://nodejs.org/dist/latest-
|
|
157
|
+
base_url="https://nodejs.org/dist/latest-v24.x"
|
|
122
158
|
sums_url="$base_url/SHASUMS256.txt"
|
|
123
159
|
tmp_dir="$(mktemp -d)"
|
|
124
160
|
trap 'rm -rf "$tmp_dir"' EXIT INT TERM
|
|
125
161
|
|
|
126
|
-
log "Installing Node.js v20 for $platform_os-$platform_arch..."
|
|
127
162
|
curl -fsSL "$sums_url" -o "$tmp_dir/SHASUMS256.txt"
|
|
128
163
|
|
|
129
|
-
archive_name="$(grep -E "node-
|
|
164
|
+
archive_name="$(grep -E "node-v24\\.[0-9]+\\.[0-9]+-$platform_os-$platform_arch\\.tar\\.xz$" "$tmp_dir/SHASUMS256.txt" | awk '{print $2}' | head -n1)"
|
|
130
165
|
[ -n "$archive_name" ] || fail "Could not resolve Node.js archive for $platform_os-$platform_arch"
|
|
131
166
|
|
|
167
|
+
latest_version="${archive_name#node-}"
|
|
168
|
+
latest_version="${latest_version%-$platform_os-$platform_arch.tar.xz}"
|
|
169
|
+
if [ -x "$NODE_DIR/bin/node" ] && [ "$("$NODE_DIR/bin/node" -v)" = "$latest_version" ]; then
|
|
170
|
+
log "Using current bundled Node.js $latest_version"
|
|
171
|
+
return
|
|
172
|
+
fi
|
|
173
|
+
|
|
174
|
+
log "Installing Node.js $latest_version for $platform_os-$platform_arch..."
|
|
132
175
|
archive_url="$base_url/$archive_name"
|
|
133
176
|
archive_path="$tmp_dir/$archive_name"
|
|
134
177
|
|
|
@@ -146,37 +189,61 @@ install_node_v20() {
|
|
|
146
189
|
log "Warning: no sha256 tool found; skipping checksum verification"
|
|
147
190
|
fi
|
|
148
191
|
|
|
192
|
+
mkdir -p "$tmp_dir/node"
|
|
193
|
+
tar -xJf "$archive_path" -C "$tmp_dir/node" --strip-components=1
|
|
149
194
|
rm -rf "$NODE_DIR"
|
|
150
|
-
|
|
151
|
-
tar -xJf "$archive_path" -C "$NODE_DIR" --strip-components=1
|
|
195
|
+
mv "$tmp_dir/node" "$NODE_DIR"
|
|
152
196
|
}
|
|
153
197
|
|
|
154
198
|
ensure_node() {
|
|
199
|
+
found_version="Node.js was not found"
|
|
155
200
|
if command -v node >/dev/null 2>&1; then
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
201
|
+
node_path="$(command -v node)"
|
|
202
|
+
case "$node_path" in
|
|
203
|
+
*/*) node_path="$(cd "${node_path%/*}" && pwd -P)/${node_path##*/}" ;;
|
|
204
|
+
esac
|
|
205
|
+
case "$node_path" in
|
|
206
|
+
"$NODE_DIR/bin/node"|"$ANVIL_HOME/node-v20/bin/node"|"$NODE_DIR/node"|"$NODE_DIR/node.exe"|"$ANVIL_HOME/node-v20/node"|"$ANVIL_HOME/node-v20/node.exe")
|
|
207
|
+
if is_windows_posix; then
|
|
208
|
+
fail "Updating bundled Node.js on Windows requires PowerShell: irm https://anvil.works/install-cli.ps1 | iex"
|
|
209
|
+
fi
|
|
210
|
+
install_node_v24
|
|
211
|
+
return
|
|
212
|
+
;;
|
|
213
|
+
esac
|
|
214
|
+
node_version="$(node -v 2>/dev/null)" || node_version=""
|
|
215
|
+
major="$(printf '%s\n' "$node_version" | sed -E 's/^v([0-9]+).*/\1/')"
|
|
216
|
+
case "$major" in
|
|
217
|
+
22|24|26)
|
|
218
|
+
USE_MANAGED_NODE=0
|
|
219
|
+
log "Using existing Node.js $node_version"
|
|
220
|
+
return
|
|
221
|
+
;;
|
|
222
|
+
esac
|
|
223
|
+
found_version="detected Node.js ${node_version:-(version unavailable)}"
|
|
167
224
|
fi
|
|
168
225
|
|
|
169
226
|
if is_windows_posix; then
|
|
170
227
|
windows_posix_node_error
|
|
171
228
|
fi
|
|
172
|
-
|
|
229
|
+
if [ "$INSTALL_NODE" -eq 1 ]; then
|
|
230
|
+
install_node_v24
|
|
231
|
+
return
|
|
232
|
+
fi
|
|
233
|
+
fail "Anvil CLI requires Node.js 22, 24 or 26 LTS; $found_version.
|
|
234
|
+
Install/update Node.js yourself: https://nodejs.org/en/download
|
|
235
|
+
Or install a private Node.js 24 copy and add it to PATH:
|
|
236
|
+
curl -fsSL https://anvil.works/install-cli.sh | sh -s -- --install-node"
|
|
173
237
|
}
|
|
174
238
|
|
|
175
239
|
configure_current_path() {
|
|
240
|
+
if [ "$USE_MANAGED_NODE" -eq 1 ]; then
|
|
241
|
+
PATH="$NODE_DIR/bin:$PATH"
|
|
242
|
+
fi
|
|
176
243
|
if is_windows_posix; then
|
|
177
|
-
export PATH="$NPM_PREFIX:$NPM_PREFIX/bin:$
|
|
244
|
+
export PATH="$NPM_PREFIX:$NPM_PREFIX/bin:$PATH"
|
|
178
245
|
else
|
|
179
|
-
export PATH="$NPM_PREFIX/bin:$
|
|
246
|
+
export PATH="$NPM_PREFIX/bin:$PATH"
|
|
180
247
|
fi
|
|
181
248
|
}
|
|
182
249
|
|
|
@@ -201,7 +268,13 @@ anvil_version() {
|
|
|
201
268
|
}
|
|
202
269
|
|
|
203
270
|
main() {
|
|
204
|
-
|
|
271
|
+
for arg in "$@"; do
|
|
272
|
+
case "$arg" in
|
|
273
|
+
--install-node) INSTALL_NODE=1 ;;
|
|
274
|
+
*) fail "Unknown option: $arg" ;;
|
|
275
|
+
esac
|
|
276
|
+
done
|
|
277
|
+
mkdir -p "$NPM_PREFIX"
|
|
205
278
|
|
|
206
279
|
ensure_node
|
|
207
280
|
|
|
@@ -219,6 +292,8 @@ main() {
|
|
|
219
292
|
fail "anvil installed but command not found on PATH"
|
|
220
293
|
fi
|
|
221
294
|
|
|
295
|
+
rm -rf "$ANVIL_HOME/node-v20"
|
|
296
|
+
|
|
222
297
|
log ""
|
|
223
298
|
log "anvil-cli installed successfully${version:+ (v$version)}"
|
|
224
299
|
log "Next steps: run 'anvil configure' or 'anvil checkout'"
|