@@ -3,6 +3,8 @@ import { cpus } from "node:os";
33import fs from "node:fs/promises" ;
44import { spawn } from "node:child_process" ;
55
6+ const nodejsGithubRepo = "https://github.com/nodejs/node" ;
7+
68let OS = process . env . OS ;
79const ARCH = process . env . ARCH == "amd64" ? "x64" : "arm64" ;
810
@@ -20,38 +22,8 @@ switch (process.platform) {
2022 current_os = "linux" ;
2123 break ;
2224}
23-
2425if ( ! OS ) OS = current_os ;
2526
26- const nodejsGithubRepo = "https://github.com/nodejs/node" ;
27- const removeTheVCharacter = ( str ) => str . replace ( "v" , "" ) ;
28-
29- const nodeIndexUrl = "https://nodejs.org/dist/index.json" ;
30- const getLatestNodeVersion = async ( ) => {
31- const res = await fetch ( nodeIndexUrl ) ;
32- const jsonData = await res . json ( ) ;
33-
34- return removeTheVCharacter ( jsonData [ 0 ] [ "version" ] ) ;
35- } ;
36-
37- const getLatestPublishedVersion = async ( ) =>
38- removeTheVCharacter ( await fs . readFile ( "version.txt" , { encoding : "utf8" } ) ) ;
39-
40- const isANewerVersion = ( oldVer , newVer ) => {
41- const oldParts = oldVer . split ( "." ) ;
42- const newParts = newVer . split ( "." ) ;
43-
44- for ( var i = 0 ; i < newParts . length ; i ++ ) {
45- const a = ~ ~ newParts [ i ] ; // parse int
46- const b = ~ ~ oldParts [ i ] ; // parse int
47-
48- if ( a > b ) return true ;
49- if ( a < b ) return false ;
50- }
51-
52- return false ;
53- } ;
54-
5527const spawnAsync = ( program , args ) =>
5628 new Promise ( ( resolve , reject ) => {
5729 console . log ( "Running:" , [ program , ...args ] . join ( " " ) ) ;
@@ -66,22 +38,11 @@ const spawnAsync = (program, args) =>
6638 } ) ;
6739 } ) ;
6840
69- const latestNodeVersion = await getLatestNodeVersion ( ) ;
70- if ( ! isANewerVersion ( await getLatestPublishedVersion ( ) , latestNodeVersion ) ) {
71- console . log ( "Nothing to do!" ) ;
72- process . exit ( 0 ) ;
73- }
74-
41+ const version = await fs . readFile ( "version.txt" , { encoding : "utf8" } ) ;
7542if ( ! syncFs . existsSync ( "node" ) ) {
7643 await spawnAsync (
7744 "git" ,
78- [
79- "clone" ,
80- nodejsGithubRepo ,
81- "--branch" ,
82- `v${ latestNodeVersion } ` ,
83- "--depth=1" ,
84- ] ,
45+ [ "clone" , nodejsGithubRepo , "--branch" , version , "--depth=1" ] ,
8546 undefined ,
8647 { }
8748 ) ;
0 commit comments