Skip to content

Commit 815dbe7

Browse files
committed
fix: apple silicon compatible
1 parent f0c131e commit 815dbe7

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

nodem.sh

+33-11
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function setup_files() {
6464
#
6565
function setup_file() {
6666
local file=$1
67-
local nodem_config='$PATH:$HOME/.nodem'
67+
local nodem_config="$PATH:$HOME/.nodem"
6868
if [ -f "$file" ]; then
6969
if ! file_contains $file $nodem_config; then
7070
echo 'export PATH=$PATH:$HOME/.nodem' >> $file
@@ -78,41 +78,63 @@ function setup_file() {
7878
function install() {
7979
local version=$1
8080
exit_if_empty "$version" "version"
81-
82-
local targz="node-v${version}-${DISTRIBUTION}-x64.tar.gz"
81+
local targz
82+
targz=$(get_dist_filename "$version")
8383

8484
# Download targz to folder $version
8585
if [ ! -f ~/.nodem/tmp/$targz ]; then
8686
yellow "Downloading node-v${version} files"
87-
download $version
87+
download "$version"
8888
green "Download successfully completed"
8989
fi
9090

9191
echo "Extracting files..."
92-
tar -xf $TMP_DIR/$targz -C $TMP_DIR
93-
rm -f $TMP_DIR/$targz
92+
tar -xf "$TMP_DIR/$targz" -C $TMP_DIR
93+
rm -f "$TMP_DIR/$targz"
9494

9595
# move dir to proper location with version
9696
echo "Installing files..."
9797
local node_dir=$(ls $TMP_DIR)
9898
rm -rf $VERSIONS_DIR/$version
99-
mkdir -p $VERSIONS_DIR/$version
100-
mv -f $TMP_DIR/$node_dir/* $VERSIONS_DIR/$version
99+
mkdir -p "$VERSIONS_DIR/$version"
100+
echo "Moving files to $VERSIONS_DIR/$version"
101+
mv -f $TMP_DIR/"$node_dir"/* "$VERSIONS_DIR/$version"
101102
echo "Node version stored in $VERSIONS_DIR/$version"
102103

103104
# clean tmp dir
104105
rm -rf $TMP_DIR
105106
if ! has_npm; then
106-
use_version $version --npm
107+
use_version "$version" --npm
107108
else
108-
use_version $version
109+
use_version "$version"
109110
fi
110111
green "Node Version $version successfully installed"
111112
}
112113

113114
function download() {
114115
local version=$1
115-
wget $NODE_DIST_URL/v${version}/node-v${version}-${DISTRIBUTION}-x64.tar.gz -P $TMP_DIR
116+
local arch
117+
local filename
118+
arch=$(get_arch)
119+
filename=$(get_dist_filename "$version")
120+
wget "$NODE_DIST_URL/v${version}/${filename}" -P $TMP_DIR
121+
}
122+
123+
function get_dist_filename() {
124+
local version=$1
125+
local arch
126+
arch=$(get_arch)
127+
echo "node-v${version}-${DISTRIBUTION}-${arch}.tar.gz"
128+
}
129+
130+
function get_arch() {
131+
local arch
132+
arch=$(uname -m)
133+
if [[ $arch == "arm64" ]]; then
134+
echo "arm64"
135+
else
136+
echo "x64"
137+
fi
116138
}
117139

118140
function use_version() {

0 commit comments

Comments
 (0)