@@ -69,16 +69,17 @@ var tasksCommonPath = path.join(__dirname, 'tasks-common');
6969var CLI = { } ;
7070
7171// node min version
72- var minNodeVer = '10.24.1' ;
72+ var minNodeVer = util . node20Version ;
7373if ( 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+ ) ;
7581}
7682
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-
8283// add node modules .bin to the path so we can dictate version of tsc etc...
8384if ( ! test ( '-d' , binPath ) ) {
8485 fail ( 'node modules bin not found. ensure npm install has been run.' ) ;
@@ -309,19 +310,15 @@ CLI.serverBuild = async function(/** @type {{ task: string }} */ argv) {
309310 return res ;
310311 } , { allTasksNode20 : [ ] , allTasksDefault : [ ] } )
311312
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
312317 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 ) ;
318319 }
319320 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 ) ;
325322 }
326323
327324 // Remove Commons from _generated folder as it is not required
@@ -335,6 +332,21 @@ CLI.serverBuild = async function(/** @type {{ task: string }} */ argv) {
335332 }
336333
337334 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+ }
338350}
339351
340352function getNodeVersion ( taskName , includeLocalPackagesBuildConfig ) {
@@ -358,10 +370,9 @@ function getNodeVersion (taskName, includeLocalPackagesBuildConfig) {
358370 return 10 ;
359371}
360372
361- async function buildTaskAsync ( taskName , taskListLength , nodeVersion , isServerBuild = false ) {
373+ async function buildTaskAsync ( taskName , nodeVersion , isServerBuild = false ) {
362374 let isGeneratedTask = false ;
363375 banner ( `Building task ${ taskName } using Node.js ${ nodeVersion } ` ) ;
364- const removeNodeModules = taskListLength > 1 ;
365376
366377 // If we have the task in generated folder, prefer to build from there and add all generated tasks which starts with task name
367378 var taskPath = path . join ( genTaskPath , taskName ) ;
@@ -404,9 +415,6 @@ async function buildTaskAsync(taskName, taskListLength, nodeVersion, isServerBui
404415 // create loc files
405416 createTaskLocJson ( taskPath ) ;
406417 createResjson ( taskDef , taskPath ) ;
407-
408- // determine the type of task
409- shouldBuildNode = shouldBuildNode || supportedNodeTargets . some ( node => taskDef . execution . hasOwnProperty ( node ) ) ;
410418 } else {
411419 outDir = path . join ( buildTasksPath , path . basename ( taskPath ) ) ;
412420 }
@@ -547,20 +555,18 @@ async function buildTaskAsync(taskName, taskListLength, nodeVersion, isServerBui
547555 console . log ( '> copying task resources' ) ;
548556 copyTaskResources ( taskMake , taskPath , outDir ) ;
549557
550- if ( removeNodeModules ) {
551- const taskNodeModulesPath = path . join ( taskPath , 'node_modules' ) ;
558+ const taskNodeModulesPath = path . join ( taskPath , 'node_modules' ) ;
552559
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+ }
557564
558- const taskTestsNodeModulesPath = path . join ( taskPath , 'Tests' , 'node_modules' ) ;
565+ const taskTestsNodeModulesPath = path . join ( taskPath , 'Tests' , 'node_modules' ) ;
559566
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 ) ;
564570 }
565571
566572 // remove duplicated task libs node modules from build tasks.
0 commit comments