@@ -5,6 +5,7 @@ var fs = require('fs');
5
5
var mkdirp = require ( 'mkdirp' ) ;
6
6
var ncp = require ( 'ncp' ) ;
7
7
var path = require ( 'path' ) ;
8
+ var semver = require ( 'semver' ) ;
8
9
var recursiveReaddir = require ( 'recursive-readdir' ) ;
9
10
var request = require ( 'request' ) ;
10
11
var rimraf = require ( 'rimraf' ) ;
@@ -83,6 +84,7 @@ var npm = new (require('../lib/npm'))({nodistDir: stagingDir});
83
84
//default npm version to the latest at the time of writing
84
85
var npmVersion = '6.14.16' ;
85
86
var nodeVersion = '16.15.0' ;
87
+ var maxNodeMainVersion = '^20' ;
86
88
87
89
var versionPathx86 = '' ;
88
90
var versionPathx64 = '' ;
@@ -102,31 +104,14 @@ console.log('Welcome to the Nodist Builder');
102
104
console . log ( ' before going further we need to prep our staging folder' ) ;
103
105
104
106
//defining helper functions
105
- function getLatestNodeVersionFor ( nodeVersions , fileType ) {
107
+ function getLatestUsableNodeVersionFor ( nodeVersions , fileType ) {
106
108
for ( var key in nodeVersions ) {
107
- if ( nodeVersions [ key ] . files . includes ( fileType ) ) {
108
- return nodeVersions [ key ] . version ;
109
+ if ( nodeVersions [ key ] . files . includes ( fileType ) && semver . satisfies ( nodeVersions [ key ] . version , maxNodeMainVersion ) ) {
110
+ return { nodeVersion : nodeVersions [ key ] . version , npmVersion : nodeVersions [ key ] . npm } ;
109
111
}
110
112
}
111
113
}
112
114
113
- async function resolveLinkedWorkspaces ( dirPath ) {
114
- let movedLinks = 0 ;
115
- const files = await fs . readdirAsync ( dirPath , { withFileTypes : true } ) ;
116
- const dirPromises = [ ] ;
117
- for ( const file of files ) {
118
- const filePath = path . join ( dirPath , file . name ) ;
119
- if ( file . isSymbolicLink ( ) ) {
120
- const linkTarget = await fs . readlinkAsync ( filePath ) ;
121
- await fs . renameAsync ( path . join ( dirPath , linkTarget ) , filePath ) ;
122
- movedLinks ++ ;
123
- } else if ( file . isDirectory ( ) ) {
124
- dirPromises . push ( resolveLinkedWorkspaces ( filePath ) ) ;
125
- }
126
- }
127
- return ( await Promise . all ( dirPromises ) ) . reduce ( ( sum , num ) => sum + num , movedLinks ) ;
128
- }
129
-
130
115
//start by clearing the staging and tmp folders
131
116
P . all ( [
132
117
rimraf ( outDir ) ,
@@ -217,7 +202,7 @@ P.all([
217
202
} ) ;
218
203
} )
219
204
. then ( function ( res ) {
220
- nodeVersion = getLatestNodeVersionFor ( res . body , 'win-x86-exe' ) ;
205
+ ( { nodeVersion, npmVersion } = getLatestUsableNodeVersionFor ( res . body , 'win-x86-exe' ) ) ;
221
206
nodeLatestUrlx86 = nodeLatestUrlx86 . replace ( 'VERSION' , nodeVersion ) ;
222
207
nodeLatestUrlx64 = nodeLatestUrlx64 . replace ( 'VERSION' , nodeVersion ) ;
223
208
console . log ( 'Latest version of Node ' + nodeVersion ) ;
@@ -253,14 +238,9 @@ P.all([
253
238
) ;
254
239
} )
255
240
. then ( function ( ) {
256
- console . log ( 'Figure out the latest version of NPM' ) ;
257
- return npm . latestVersion ( ) ;
258
- } )
259
- . then ( function ( version ) {
260
- npmVersion = version ;
261
- var downloadLink = npm . downloadUrl ( version ) ;
262
- console . log ( 'Determined latest NPM as ' + npmVersion ) ;
263
- console . log ( 'Downloading latest NPM from ' + downloadLink ) ;
241
+ var downloadLink = npm . downloadUrl ( npmVersion ) ;
242
+ console . log ( 'Determined matching NPM as ' + npmVersion ) ;
243
+ console . log ( 'Downloading matching NPM from ' + downloadLink ) ;
264
244
return Promise . resolve ( )
265
245
. then ( ( ) => mkdirp ( stagingNpmDir + '/' + npmVersion . replace ( 'v' , '' ) ) )
266
246
. then ( ( ) => {
@@ -291,7 +271,7 @@ P.all([
291
271
} )
292
272
. then ( function ( ) {
293
273
console . log ( 'Installation complete' ) ;
294
- return resolveLinkedWorkspaces ( path . join ( stagingNpmDir , npmVersion . replace ( 'v' , '' ) , 'node_modules' ) ) ;
274
+ return helper . resolveLinkedWorkspaces ( path . join ( stagingNpmDir , npmVersion . replace ( 'v' , '' ) ) , false ) ;
295
275
} )
296
276
. then ( function ( movedLinks ) {
297
277
if ( movedLinks ) {
0 commit comments