@@ -86,40 +86,18 @@ install_deps() {
86
86
fi
87
87
}
88
88
89
- run_yarn () {
90
- yarn_version=$1
91
- if [ -d $NETLIFY_CACHE_DIR /yarn ]
92
- then
93
- export PATH=$NETLIFY_CACHE_DIR /yarn/bin:$PATH
94
- fi
95
- restore_home_cache " .yarn_cache" " yarn cache"
96
-
97
- if [ $( which yarn) ] && [ " $( yarn --version) " != " $yarn_version " ]
98
- then
99
- echo " Found yarn version ($( yarn --version) ) that doesn't match expected ($yarn_version )"
100
- rm -rf $NETLIFY_CACHE_DIR /yarn $HOME /.yarn
101
- npm uninstall yarn -g
102
- fi
103
-
104
- if ! [ $( which yarn) ]
105
- then
106
- echo " Installing yarn at version $yarn_version "
107
- rm -rf $HOME /.yarn
108
- bash /usr/local/bin/yarn-installer.sh --version $yarn_version
109
- mv $HOME /.yarn $NETLIFY_CACHE_DIR /yarn
110
- export PATH=$NETLIFY_CACHE_DIR /yarn/bin:$PATH
111
- fi
112
-
113
-
89
+ restore_node_modules () {
114
90
local workspace_output
115
91
local workspace_exit_code
92
+ local installer=$1
116
93
# YARN_IGNORE_PATH will ignore the presence of a local yarn executable (i.e. yarn 2) and default
117
94
# to using the global one (which, for now, is always yarn 1.x). See https://yarnpkg.com/configuration/yarnrc#ignorePath
95
+ # we can actually use this command for npm workspaces as well
118
96
workspace_output=" $( YARN_IGNORE_PATH=1 yarn workspaces --json info 2> /dev/null) "
119
97
workspace_exit_code=$?
120
98
if [ $workspace_exit_code -eq 0 ]
121
99
then
122
- echo " Yarn workspaces detected"
100
+ echo " $installer workspaces detected"
123
101
local package_locations
124
102
# Extract all the packages and respective locations. .data will be a JSON object like
125
103
# {
@@ -134,9 +112,36 @@ run_yarn() {
134
112
mapfile -t package_locations <<< " $(echo " $workspace_output " | jq -r '.data | fromjson | to_entries | .[].value.location')"
135
113
restore_js_workspaces_cache " ${package_locations[@]} "
136
114
else
137
- echo " No yarn workspaces detected"
115
+ echo " No $installer workspaces detected"
138
116
restore_cwd_cache node_modules " node modules"
139
117
fi
118
+ }
119
+
120
+ run_yarn () {
121
+ yarn_version=$1
122
+ if [ -d $NETLIFY_CACHE_DIR /yarn ]
123
+ then
124
+ export PATH=$NETLIFY_CACHE_DIR /yarn/bin:$PATH
125
+ fi
126
+ restore_home_cache " .yarn_cache" " yarn cache"
127
+
128
+ if [ $( which yarn) ] && [ " $( yarn --version) " != " $yarn_version " ]
129
+ then
130
+ echo " Found yarn version ($( yarn --version) ) that doesn't match expected ($yarn_version )"
131
+ rm -rf $NETLIFY_CACHE_DIR /yarn $HOME /.yarn
132
+ npm uninstall yarn -g
133
+ fi
134
+
135
+ if ! [ $( which yarn) ]
136
+ then
137
+ echo " Installing yarn at version $yarn_version "
138
+ rm -rf $HOME /.yarn
139
+ bash /usr/local/bin/yarn-installer.sh --version $yarn_version
140
+ mv $HOME /.yarn $NETLIFY_CACHE_DIR /yarn
141
+ export PATH=$NETLIFY_CACHE_DIR /yarn/bin:$PATH
142
+ fi
143
+
144
+ restore_node_modules " yarn"
140
145
141
146
echo " Installing NPM modules using Yarn version $( yarn --version) "
142
147
run_npm_set_temp
@@ -166,7 +171,12 @@ run_npm_set_temp() {
166
171
}
167
172
168
173
run_npm () {
169
- restore_cwd_cache node_modules " node modules"
174
+ if [ -n " $EXPERIMENTAL_NPM_WORKSPACES_CACHING " ]
175
+ then
176
+ restore_node_modules " npm"
177
+ else
178
+ restore_cwd_cache node_modules " node modules"
179
+ fi
170
180
171
181
if [ -n " $NPM_VERSION " ]
172
182
then
0 commit comments