@@ -6,6 +6,12 @@ NAME="${PARAM_STR_REF}"
6
6
VERSION=" "
7
7
SUDO=" "
8
8
9
+ if [[ ${EUID} -ne 0 ]]; then
10
+ echo " Using sudo privileges to finish the process"
11
+
12
+ SUDO=" sudo"
13
+ fi
14
+
9
15
check_installation () {
10
16
local installed_version
11
17
local required_version
@@ -31,6 +37,25 @@ check_installation () {
31
37
fi
32
38
}
33
39
40
+ change_pnpm_store_dir_and_exit () {
41
+ local current_store_dir
42
+ local target_store_dir
43
+
44
+ current_store_dir=$( pnpm store path)
45
+ target_store_dir=" ${HOME} /.pnpm_store"
46
+
47
+ if [[ " ${current_store_dir} " != " ${target_store_dir} " ]]; then
48
+ echo " Changing the pnpm store directory"
49
+
50
+ set -x
51
+ pnpm config set store-dir " ${target_store_dir} "
52
+ ${SUDO} rm -rf " ${current_store_dir} "
53
+ set +x
54
+ fi
55
+
56
+ exit 0
57
+ }
58
+
34
59
if [[ " ${PARAM_STR_REF} " =~ ${PKG_MANAGER_WITH_VERSION_REGEX} ]]; then
35
60
NAME=" ${BASH_REMATCH[1]} "
36
61
VERSION=" ${BASH_REMATCH[2]} "
39
64
echo " export CURRENT_PKG_MANAGER='${NAME} '" >> " ${BASH_ENV} "
40
65
echo " Starting to ensure ${NAME} is set for usage"
41
66
42
- if [[ ${EUID} -ne 0 ]]; then
43
- echo " Using sudo privileges to finish the process"
44
-
45
- SUDO=" sudo"
46
- fi
47
-
67
+ cd ~ || echo " Cannot navigate to home, possible version mismatch"
68
+
48
69
if [[ " ${NAME} " == " npm" ]]; then
70
+ echo " Detected npm $( npm --version) "
71
+
49
72
if [[ -n " ${VERSION} " ]]; then
50
- ${SUDO} npm i -g npm@" ${VERSION} "
51
- check_installation " ${NAME} " " ${VERSION} "
52
- else
53
- echo " Detected npm version: $( npm --version) "
73
+ if npm --version | grep " ${VERSION} " > /dev/null 2>&1 ; then
74
+ echo " Requested version of npm is already installed"
75
+ else
76
+ echo " Requested version of npm not found, updating detected version"
77
+
78
+ ${SUDO} npm i -g npm@" ${VERSION} "
79
+ check_installation " ${NAME} " " ${VERSION} "
80
+ fi
81
+
82
+ exit 0
54
83
fi
55
84
85
+ echo " Using detected version of npm"
86
+
56
87
exit 0
57
88
fi
58
89
59
90
if [[ " ${NAME} " == " pnpm" ]]; then
60
91
if command -v pnpm > /dev/null 2>&1 ; then
61
- echo " Found pnpm installation, removing it"
92
+ echo " Detected pnpm $( pnpm --version) "
93
+
94
+ if [[ -z " ${VERSION} " ]]; then
95
+ echo " Using detected version of pnpm"
96
+
97
+ change_pnpm_store_dir_and_exit
98
+ elif pnpm --version | grep " ${VERSION} " > /dev/null 2>&1 ; then
99
+ echo " Requested vesion of pnpm is already installed"
100
+
101
+ change_pnpm_store_dir_and_exit
102
+ fi
103
+
104
+ echo " Requested version of pnpm not found, removing detected version"
62
105
63
106
${SUDO} rm -rf " $( pnpm store path) " > /dev/null 2>&1
64
107
${SUDO} rm -rf " ${PNPM_HOME} " > /dev/null 2>&1
65
108
${SUDO} npm rm -g pnpm > /dev/null 2>&1
109
+ else
110
+ echo " Did not detect pnpm, proceeding with installation"
66
111
fi
67
112
68
113
if [[ -z " ${VERSION} " ]]; then
69
114
VERSION=$( npm view pnpm version)
115
+
116
+ echo " Version not explicitly requested, opting for ${VERSION} "
70
117
fi
71
118
72
119
${SUDO} npm i -g pnpm@" ${VERSION} "
0 commit comments