@@ -156,7 +156,15 @@ function getNodeOs(platform: string) {
156
156
157
157
/** Get the node arch based on target arch */
158
158
function getNodeArch ( arch : string ) {
159
- const allowedArchs = [ 'x64' , 'arm64' , 'armv7l' , 'ppc64' , 's390x' ] ;
159
+ const allowedArchs = [
160
+ 'x64' ,
161
+ 'arm64' ,
162
+ 'armv7l' ,
163
+ 'ppc64' ,
164
+ 's390x' ,
165
+ 'riscv64' ,
166
+ 'loong64' ,
167
+ ] ;
160
168
161
169
if ( ! allowedArchs . includes ( arch ) ) {
162
170
throw new Error ( `Unsupported architecture: ${ arch } ` ) ;
@@ -166,7 +174,7 @@ function getNodeArch(arch: string) {
166
174
}
167
175
168
176
/** Get latest node version based on the provided partial version */
169
- async function getNodeVersion ( nodeVersion : string ) {
177
+ async function getNodeVersion ( os : string , arch : string , nodeVersion : string ) {
170
178
// validate nodeVersion using regex. Allowed formats: 16, 16.0, 16.0.0
171
179
const regex = / ^ \d { 1 , 2 } ( \. \d { 1 , 2 } ) { 0 , 2 } $ / ;
172
180
if ( ! regex . test ( nodeVersion ) ) {
@@ -183,23 +191,39 @@ async function getNodeVersion(nodeVersion: string) {
183
191
return nodeVersion ;
184
192
}
185
193
186
- const response = await fetch ( 'https://nodejs.org/dist/index.json' ) ;
194
+ let url ;
195
+ switch ( arch ) {
196
+ case 'riscv64' :
197
+ case 'loong64' :
198
+ url = 'https://unofficial-builds.nodejs.org/download/release/index.json' ;
199
+ break ;
200
+ default :
201
+ url = 'https://nodejs.org/dist/index.json' ;
202
+ break ;
203
+ }
204
+
205
+ const response = await fetch ( url ) ;
187
206
188
207
if ( ! response . ok ) {
189
208
throw new Error ( 'Failed to fetch node versions' ) ;
190
209
}
191
210
192
211
const versions = await response . json ( ) ;
193
212
194
- const latestVersion = versions
195
- . map ( ( v : { version : string } ) => v . version )
196
- . find ( ( v : string ) => v . startsWith ( `v${ nodeVersion } ` ) ) ;
213
+ const nodeOS = os === 'darwin' ? 'osx' : os ;
214
+ const latestVersionAndFiles = versions
215
+ . map ( ( v : { version : string ; files : string [ ] } ) => [ v . version , v . files ] )
216
+ . find (
217
+ ( [ v , files ] : [ string , string [ ] ] ) =>
218
+ v . startsWith ( `v${ nodeVersion } ` ) &&
219
+ files . find ( ( f : string ) => f . startsWith ( `${ nodeOS } -${ arch } ` ) ) ,
220
+ ) ;
197
221
198
- if ( ! latestVersion ) {
222
+ if ( ! latestVersionAndFiles ) {
199
223
throw new Error ( `Node version ${ nodeVersion } not found` ) ;
200
224
}
201
225
202
- return latestVersion ;
226
+ return latestVersionAndFiles [ 0 ] ;
203
227
}
204
228
205
229
/** Fetch, validate and extract nodejs binary. Returns a path to it */
@@ -222,16 +246,31 @@ async function getNodejsExecutable(
222
246
return process . execPath ;
223
247
}
224
248
249
+ const os = getNodeOs ( target . platform ) ;
250
+ const arch = getNodeArch ( target . arch ) ;
251
+
225
252
const nodeVersion = await getNodeVersion (
253
+ os ,
254
+ arch ,
226
255
target . nodeRange . replace ( 'node' , '' ) ,
227
256
) ;
228
257
229
- const os = getNodeOs ( target . platform ) ;
230
- const arch = getNodeArch ( target . arch ) ;
231
-
232
258
const fileName = `node-${ nodeVersion } -${ os } -${ arch } .${ os === 'win' ? 'zip' : 'tar.gz' } ` ;
233
- const url = `https://nodejs.org/dist/${ nodeVersion } /${ fileName } ` ;
234
- const checksumUrl = `https://nodejs.org/dist/${ nodeVersion } /SHASUMS256.txt` ;
259
+
260
+ let url ;
261
+ let checksumUrl ;
262
+ switch ( arch ) {
263
+ case 'riscv64' :
264
+ case 'loong64' :
265
+ url = `https://unofficial-builds.nodejs.org/download/release/${ nodeVersion } /${ fileName } ` ;
266
+ checksumUrl = `https://unofficial-builds.nodejs.org/download/release/${ nodeVersion } /SHASUMS256.txt` ;
267
+ break ;
268
+ default :
269
+ url = `https://nodejs.org/dist/${ nodeVersion } /${ fileName } ` ;
270
+ checksumUrl = `https://nodejs.org/dist/${ nodeVersion } /SHASUMS256.txt` ;
271
+ break ;
272
+ }
273
+
235
274
const downloadDir = join ( homedir ( ) , '.pkg-cache' , 'sea' ) ;
236
275
237
276
// Ensure the download directory exists
0 commit comments