@@ -69,16 +69,17 @@ var tasksCommonPath = path.join(__dirname, 'tasks-common');
69
69
var CLI = { } ;
70
70
71
71
// node min version
72
- var minNodeVer = '10.24.1' ;
72
+ var minNodeVer = util . node20Version ;
73
73
if ( semver . lt ( process . versions . node , minNodeVer ) ) {
74
- fail ( 'requires node >= ' + minNodeVer + '. installed: ' + process . versions . node ) ;
74
+ fail (
75
+ `Node.js version ${ process . versions . node } detected. This build requires Node.js >= ${ minNodeVer } .\n` +
76
+ `To remediate:\n` +
77
+ ` 1. Install NVM for Windows: winget install CoreyButler.NVMforWindows\n` +
78
+ ` 2. Install Node.js ${ minNodeVer } : nvm install ${ minNodeVer } \n` +
79
+ ` 3. Use Node.js ${ minNodeVer } : nvm use ${ minNodeVer } \n`
80
+ ) ;
75
81
}
76
82
77
- // Node 14 is supported by the build system, but not currently by the agent. Block it for now
78
- var supportedNodeTargets = [ "Node" , "Node10" /*, "Node14"*/ ] ;
79
- var node10Version = '10.24.1' ;
80
- var node20Version = '20.17.0' ;
81
-
82
83
// add node modules .bin to the path so we can dictate version of tsc etc...
83
84
if ( ! test ( '-d' , binPath ) ) {
84
85
fail ( 'node modules bin not found. ensure npm install has been run.' ) ;
@@ -309,19 +310,15 @@ CLI.serverBuild = async function(/** @type {{ task: string }} */ argv) {
309
310
return res ;
310
311
} , { allTasksNode20 : [ ] , allTasksDefault : [ ] } )
311
312
313
+ const builtTasks = new Set ( ) ;
314
+
315
+ // This code is structured to support installing/building with multiple node versions in the future, including the same task for multiple node versions
316
+ // Currently, we only support Node.js 20
312
317
if ( allTasksNode20 . length > 0 ) {
313
- await util . installNodeAsync ( '20' ) ;
314
- ensureTool ( 'node' , '--version' , `v${ node20Version } ` ) ;
315
- for ( const taskName of allTasksNode20 ) {
316
- await buildTaskWrapped ( taskName , allTasksNode20 . length , 20 , ! writeUpdatedsFromGenTasks ) ;
317
- }
318
+ await installNodeAndBuildTasks ( 20 , util . node20Version , allTasksNode20 , builtTasks ) ;
318
319
}
319
320
if ( allTasksDefault . length > 0 ) {
320
- await util . installNodeAsync ( '10' ) ;
321
- ensureTool ( 'node' , '--version' , `v${ node10Version } ` ) ;
322
- for ( const taskName of allTasksDefault ) {
323
- await buildTaskWrapped ( taskName , allTasksNode20 . length , 10 , ! writeUpdatedsFromGenTasks ) ;
324
- }
321
+ await installNodeAndBuildTasks ( 20 , util . node20Version , allTasksDefault , builtTasks ) ;
325
322
}
326
323
327
324
// Remove Commons from _generated folder as it is not required
@@ -335,6 +332,21 @@ CLI.serverBuild = async function(/** @type {{ task: string }} */ argv) {
335
332
}
336
333
337
334
banner ( 'Build successful' , true ) ;
335
+
336
+ // Track tasks that have been built with specific node versions to avoid duplicates
337
+ async function installNodeAndBuildTasks ( nodeMajorVersion , nodeFullVersion , buildTaskList , builtTasks ) {
338
+ await util . installNodeAsync ( nodeMajorVersion . toString ( ) ) ;
339
+ ensureTool ( 'node' , '--version' , `v${ nodeFullVersion } ` ) ;
340
+ for ( const taskName of buildTaskList ) {
341
+ const taskKey = `${ taskName } -${ nodeMajorVersion } ` ;
342
+ if ( ! builtTasks . has ( taskKey ) ) {
343
+ builtTasks . add ( taskKey ) ;
344
+ await buildTaskWrapped ( taskName , nodeMajorVersion , ! writeUpdatedsFromGenTasks ) ;
345
+ } else {
346
+ console . log ( `Skipping ${ taskName } for Node.js ${ nodeMajorVersion } - already built` ) ;
347
+ }
348
+ }
349
+ }
338
350
}
339
351
340
352
function getNodeVersion ( taskName , includeLocalPackagesBuildConfig ) {
@@ -358,10 +370,9 @@ function getNodeVersion (taskName, includeLocalPackagesBuildConfig) {
358
370
return 10 ;
359
371
}
360
372
361
- async function buildTaskAsync ( taskName , taskListLength , nodeVersion , isServerBuild = false ) {
373
+ async function buildTaskAsync ( taskName , nodeVersion , isServerBuild = false ) {
362
374
let isGeneratedTask = false ;
363
375
banner ( `Building task ${ taskName } using Node.js ${ nodeVersion } ` ) ;
364
- const removeNodeModules = taskListLength > 1 ;
365
376
366
377
// If we have the task in generated folder, prefer to build from there and add all generated tasks which starts with task name
367
378
var taskPath = path . join ( genTaskPath , taskName ) ;
@@ -404,9 +415,6 @@ async function buildTaskAsync(taskName, taskListLength, nodeVersion, isServerBui
404
415
// create loc files
405
416
createTaskLocJson ( taskPath ) ;
406
417
createResjson ( taskDef , taskPath ) ;
407
-
408
- // determine the type of task
409
- shouldBuildNode = shouldBuildNode || supportedNodeTargets . some ( node => taskDef . execution . hasOwnProperty ( node ) ) ;
410
418
} else {
411
419
outDir = path . join ( buildTasksPath , path . basename ( taskPath ) ) ;
412
420
}
@@ -547,20 +555,18 @@ async function buildTaskAsync(taskName, taskListLength, nodeVersion, isServerBui
547
555
console . log ( '> copying task resources' ) ;
548
556
copyTaskResources ( taskMake , taskPath , outDir ) ;
549
557
550
- if ( removeNodeModules ) {
551
- const taskNodeModulesPath = path . join ( taskPath , 'node_modules' ) ;
558
+ const taskNodeModulesPath = path . join ( taskPath , 'node_modules' ) ;
552
559
553
- if ( fs . existsSync ( taskNodeModulesPath ) ) {
554
- console . log ( '\n> removing node modules' ) ;
555
- rm ( '-Rf' , taskNodeModulesPath ) ;
556
- }
560
+ if ( fs . existsSync ( taskNodeModulesPath ) ) {
561
+ console . log ( '\n> removing node modules' ) ;
562
+ rm ( '-Rf' , taskNodeModulesPath ) ;
563
+ }
557
564
558
- const taskTestsNodeModulesPath = path . join ( taskPath , 'Tests' , 'node_modules' ) ;
565
+ const taskTestsNodeModulesPath = path . join ( taskPath , 'Tests' , 'node_modules' ) ;
559
566
560
- if ( fs . existsSync ( taskTestsNodeModulesPath ) ) {
561
- console . log ( '\n> removing task tests node modules' ) ;
562
- rm ( '-Rf' , taskTestsNodeModulesPath ) ;
563
- }
567
+ if ( fs . existsSync ( taskTestsNodeModulesPath ) ) {
568
+ console . log ( '\n> removing task tests node modules' ) ;
569
+ rm ( '-Rf' , taskTestsNodeModulesPath ) ;
564
570
}
565
571
566
572
// remove duplicated task libs node modules from build tasks.
0 commit comments