@@ -85,48 +85,33 @@ jobs:
85
85
node-version : 20.x
86
86
check-latest : contains('20.x', '.x')
87
87
88
- # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
89
- - name : Update Windows npm
90
- if : |
91
- matrix.platform.os == 'windows-latest' && (
92
- startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.')
93
- )
94
- run : |
95
- curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
96
- tar xf npm-7.5.4.tgz
97
- cd package
98
- node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
99
- cd ..
100
- rmdir /s /q package
101
-
102
- # Start on Node 10 because we dont test on anything lower
103
- - name : Install npm@7 on Node 10
88
+ - name : Install Latest npm
104
89
shell : bash
105
- if : startsWith(steps.node.outputs.node-version, 'v10.')
106
- id : npm-7
90
+ env :
91
+ NODE_VERSION : ${{ steps.node.outputs.node-version }}
107
92
run : |
108
- npm i --prefer-online --no-fund --no-audit -g npm@7
109
- echo "updated=true" >> "$GITHUB_OUTPUT"
93
+ MATCH=""
94
+ SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6")
110
95
111
- - name : Install npm@8 on Node 12
112
- shell : bash
113
- if : startsWith(steps.node.outputs.node-version, 'v12.')
114
- id : npm-8
115
- run : |
116
- npm i --prefer-online --no-fund --no-audit -g npm@8
117
- echo "updated=true" >> "$GITHUB_OUTPUT"
96
+ echo "node@$NODE_VERSION"
118
97
119
- - name : Install npm@9 on Node 14/16/18.0
120
- shell : bash
121
- if : startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.')
122
- id : npm-9
123
- run : |
124
- npm i --prefer-online --no-fund --no-audit -g npm@9
125
- echo "updated=true" >> "$GITHUB_OUTPUT"
98
+ for SPEC in ${SPECS[@]}; do
99
+ ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node')
100
+ echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)"
126
101
127
- - name : Install npm@latest on Node
128
- if : ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }}
129
- run : npm i --prefer-online --no-fund --no-audit -g npm@latest
102
+ if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then
103
+ MATCH=$SPEC
104
+ echo "Found compatible version: npm@$MATCH"
105
+ break
106
+ fi
107
+ done
108
+
109
+ if [ -z $MATCH ]; then
110
+ echo "Could not find a compatible version of npm for node@$NODE_VERSION"
111
+ exit 1
112
+ fi
113
+
114
+ npm i --prefer-online --no-fund --no-audit -g npm@$MATCH
130
115
131
116
- name : npm Version
132
117
run : npm -v
@@ -232,7 +217,9 @@ jobs:
232
217
- name : Update Windows npm
233
218
if : |
234
219
matrix.platform.os == 'windows-latest' && (
235
- startsWith(steps.node.outputs.node-version, 'v10.') || startsWith(steps.node.outputs.node-version, 'v12.') || startsWith(steps.node.outputs.node-version, 'v14.')
220
+ startsWith(steps.node.outputs.node-version, 'v10.') ||
221
+ startsWith(steps.node.outputs.node-version, 'v12.') ||
222
+ startsWith(steps.node.outputs.node-version, 'v14.')
236
223
)
237
224
run : |
238
225
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
@@ -242,34 +229,33 @@ jobs:
242
229
cd ..
243
230
rmdir /s /q package
244
231
245
- # Start on Node 10 because we dont test on anything lower
246
- - name : Install npm@7 on Node 10
232
+ - name : Install Latest npm
247
233
shell : bash
248
- if : startsWith(steps.node.outputs.node-version, 'v10.')
249
- id : npm-7
234
+ env :
235
+ NODE_VERSION : ${{ steps.node.outputs.node-version }}
250
236
run : |
251
- npm i --prefer-online --no-fund --no-audit -g npm@7
252
- echo "updated=true" >> "$GITHUB_OUTPUT"
237
+ MATCH=""
238
+ SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6")
253
239
254
- - name : Install npm@8 on Node 12
255
- shell : bash
256
- if : startsWith(steps.node.outputs.node-version, 'v12.')
257
- id : npm-8
258
- run : |
259
- npm i --prefer-online --no-fund --no-audit -g npm@8
260
- echo "updated=true" >> "$GITHUB_OUTPUT"
240
+ echo "node@$NODE_VERSION"
261
241
262
- - name : Install npm@9 on Node 14/16/18.0
263
- shell : bash
264
- if : startsWith(steps.node.outputs.node-version, 'v14.') || startsWith(steps.node.outputs.node-version, 'v16.') || startsWith(steps.node.outputs.node-version, 'v18.0.')
265
- id : npm-9
266
- run : |
267
- npm i --prefer-online --no-fund --no-audit -g npm@9
268
- echo "updated=true" >> "$GITHUB_OUTPUT"
242
+ for SPEC in ${SPECS[@]}; do
243
+ ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node')
244
+ echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)"
245
+
246
+ if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then
247
+ MATCH=$SPEC
248
+ echo "Found compatible version: npm@$MATCH"
249
+ break
250
+ fi
251
+ done
252
+
253
+ if [ -z $MATCH ]; then
254
+ echo "Could not find a compatible version of npm for node@$NODE_VERSION"
255
+ exit 1
256
+ fi
269
257
270
- - name : Install npm@latest on Node
271
- if : ${{ !(steps.npm-7.outputs.updated || steps.npm-8.outputs.updated || steps.npm-9.outputs.updated) }}
272
- run : npm i --prefer-online --no-fund --no-audit -g npm@latest
258
+ npm i --prefer-online --no-fund --no-audit -g npm@$MATCH
273
259
274
260
- name : npm Version
275
261
run : npm -v
0 commit comments