Skip to content

Commit d2aef46

Browse files
committed
Add automatic Node.js version switching via nvm, fnm, or n and use npx pnpm for dependency installation and build
- if default node version is incorrect (require 22.x), try using system-installed node version manager, e.g. fnm, nvm to switch before failing - don't support outdated stuff like volta - force using pnpm through npx at all times
1 parent 9562f44 commit d2aef46

1 file changed

Lines changed: 44 additions & 13 deletions

File tree

‎install.sh‎

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,50 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
# Check required dependencies
5-
for cmd in git node pnpm; do
6-
if ! command -v $cmd &> /dev/null; then
7-
echo "Error: $cmd is required but not installed."
8-
exit 1
4+
# Check git first
5+
if ! command -v git &> /dev/null; then
6+
echo "Error: git is required but not installed."
7+
exit 1
8+
fi
9+
10+
# Validate Node.js version and attempt to switch if necessary
11+
check_node_version() {
12+
if ! command -v node &> /dev/null; then return 1; fi
13+
local version
14+
version=$(node -v | sed 's/^v//' | cut -d. -f1)
15+
[ "$version" -ge 20 ]
16+
}
17+
18+
if ! check_node_version; then
19+
echo "Node.js version 20 or higher is required (Node.js 22.x is recommended)."
20+
echo "Attempting to switch to Node.js 22 using a version manager..."
21+
22+
SWITCHED=false
23+
24+
# Try nvm
25+
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
26+
if [ -s "$NVM_DIR/nvm.sh" ]; then
27+
\. "$NVM_DIR/nvm.sh"
28+
fi
29+
if type nvm >/dev/null 2>&1; then
30+
nvm install 22 && nvm use 22 && SWITCHED=true
931
fi
10-
done
1132

12-
# Validate Node.js version
13-
NODE_MAJOR_VERSION=$(node -v | sed 's/^v//' | cut -d. -f1)
14-
if [ "$NODE_MAJOR_VERSION" -lt 20 ]; then
15-
echo "Error: Node.js version 20 or higher is required (Node.js 22.x is recommended)."
16-
exit 1
33+
# Try fnm
34+
if [ "$SWITCHED" = false ] && command -v fnm &> /dev/null; then
35+
eval "$(fnm env)"
36+
fnm install 22 && fnm use 22 && SWITCHED=true
37+
fi
38+
39+
# Try n
40+
if [ "$SWITCHED" = false ] && command -v n &> /dev/null; then
41+
n 22 && SWITCHED=true
42+
fi
43+
44+
if [ "$SWITCHED" = false ]; then
45+
echo "Error: Failed to find a compatible Node.js version and no supported version manager (nvm, fnm, n) could switch it."
46+
exit 1
47+
fi
1748
fi
1849

1950
# Detect available editors in the system
@@ -72,11 +103,11 @@ cd "$TMP_DIR"
72103
REPO_DIR="$TMP_DIR"
73104

74105
echo "Installing dependencies..."
75-
pnpm install > /dev/null 2>&1
106+
npx --yes pnpm install > /dev/null 2>&1
76107

77108
echo "Building extension..."
78109
cd apps/editor
79-
pnpm run build > /dev/null 2>&1
110+
npx --yes pnpm run build > /dev/null 2>&1
80111

81112
VSIX_FILE=$(ls *.vsix | head -n 1)
82113

0 commit comments

Comments
 (0)