-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathinstall.ps1
More file actions
78 lines (70 loc) · 2.71 KB
/
Copy pathinstall.ps1
File metadata and controls
78 lines (70 loc) · 2.71 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# caveman — installer shim (Windows / PowerShell).
#
# Thin wrapper around bin/install.js (the unified Node installer). Every flag
# you'd pass to bin/install.js can be passed here; we just forward them.
#
# One-line install:
# irm https://raw.githubusercontent.com/JuliusBrussee/caveman/main/install.ps1 | iex
#
# Local clone:
# pwsh install.ps1 [flags]
#
# Why a Node installer? install.sh + install.ps1 used to be parallel sources of
# truth and constantly drifted (issue #249 was a `node -e "..."` quoting bug
# that silently dropped the JSON merge step on every Windows install). One
# Node script works everywhere without quoting bugs.
#
# Why no top-level param() and everything inside a function? `irm | iex`
# executes this file as a string: script-path variables ($PSCommandPath,
# $MyInvocation.MyCommand.Path) are $null and a top-level param block cannot
# receive arguments through a pipe anyway (issue #565). Wrapping the logic in
# a function and forwarding $args keeps one script working for both the pipe
# path (no args, no script path) and the local-clone path.
function Install-Caveman {
param(
[string[]]$InstallerArgs = @()
)
$ErrorActionPreference = "Stop"
$Repo = "JuliusBrussee/caveman"
# Require Node ≥18.
$node = Get-Command node -ErrorAction SilentlyContinue
if (-not $node) {
Write-Error @"
caveman: Node.js (>=18) required. Install:
- winget install OpenJS.NodeJS.LTS
- or download from https://nodejs.org
"@
exit 1
}
$nodeMajor = [int](& node -p "process.versions.node.split('.')[0]")
if ($nodeMajor -lt 18) {
Write-Error "caveman: Node $nodeMajor too old. Need Node >=18. Upgrade: https://nodejs.org"
exit 1
}
# If we're inside the repo clone, run the local installer directly.
# $PSCommandPath is $null when piped to iex (#565) — the old unguarded
# Split-Path on it was the "Cannot bind argument to parameter 'Path'
# because it is null" crash.
if ($PSCommandPath) {
$here = Split-Path -Parent $PSCommandPath
$local = Join-Path $here "bin/install.js"
if (Test-Path $local) {
& node $local @InstallerArgs
exit $LASTEXITCODE
}
}
# Curl-pipe path: delegate to npx.
$npx = Get-Command npx -ErrorAction SilentlyContinue
if (-not $npx) {
Write-Error "caveman: npx required (ships with Node >=18). Reinstall Node.js."
exit 1
}
# Do NOT pass `--` here — npm 7+ npx already forwards trailing args to the
# package, and a literal `--` was tripping bin/install.js's parseArgs as an
# unknown flag.
& npx -y "github:$Repo" @InstallerArgs
exit $LASTEXITCODE
}
# $args is the automatic variable: populated when run as a file
# (`pwsh install.ps1 --force`), empty under `irm | iex`.
Install-Caveman -InstallerArgs $args