@@ -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,38 @@ 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 latestVersionAndFiles = versions
214
+ . map ( ( v : { version : string ; files : string [ ] } ) => [ v . version , v . files ] )
215
+ . find (
216
+ ( [ v , files ] : [ string , string [ ] ] ) =>
217
+ v . startsWith ( `v${ nodeVersion } ` ) &&
218
+ files . find ( ( f : string ) => f . startsWith ( `${ os } -${ arch } ` ) ) ,
219
+ ) ;
197
220
198
- if ( ! latestVersion ) {
221
+ if ( ! latestVersionAndFiles ) {
199
222
throw new Error ( `Node version ${ nodeVersion } not found` ) ;
200
223
}
201
224
202
- return latestVersion ;
225
+ return latestVersionAndFiles [ 0 ] ;
203
226
}
204
227
205
228
/** Fetch, validate and extract nodejs binary. Returns a path to it */
@@ -222,16 +245,31 @@ async function getNodejsExecutable(
222
245
return process . execPath ;
223
246
}
224
247
248
+ const os = getNodeOs ( target . platform ) ;
249
+ const arch = getNodeArch ( target . arch ) ;
250
+
225
251
const nodeVersion = await getNodeVersion (
252
+ os ,
253
+ arch ,
226
254
target . nodeRange . replace ( 'node' , '' ) ,
227
255
) ;
228
256
229
- const os = getNodeOs ( target . platform ) ;
230
- const arch = getNodeArch ( target . arch ) ;
231
-
232
257
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` ;
258
+
259
+ let url ;
260
+ let checksumUrl ;
261
+ switch ( arch ) {
262
+ case 'riscv64' :
263
+ case 'loong64' :
264
+ url = `https://unofficial-builds.nodejs.org/download/release/${ nodeVersion } /${ fileName } ` ;
265
+ checksumUrl = `https://unofficial-builds.nodejs.org/download/release/${ nodeVersion } /SHASUMS256.txt` ;
266
+ break ;
267
+ default :
268
+ url = `https://nodejs.org/dist/${ nodeVersion } /${ fileName } ` ;
269
+ checksumUrl = `https://nodejs.org/dist/${ nodeVersion } /SHASUMS256.txt` ;
270
+ break ;
271
+ }
272
+
235
273
const downloadDir = join ( homedir ( ) , '.pkg-cache' , 'sea' ) ;
236
274
237
275
// Ensure the download directory exists
0 commit comments