Skip to content

Commit 14dc89d

Browse files
authored
Remove node10 build paths (#21139)
1 parent abcf535 commit 14dc89d

File tree

2 files changed

+51
-46
lines changed

2 files changed

+51
-46
lines changed

make-util.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -344,23 +344,21 @@ var ensureTool = function (name, versionArgs, validate) {
344344
}
345345
exports.ensureTool = ensureTool;
346346

347+
const node20Version = '20.17.0';
348+
exports.node20Version = node20Version;
349+
347350
var installNodeAsync = async function (nodeVersion) {
348351
const versions = {
349-
20: 'v20.17.0',
350-
16: 'v16.20.2',
351-
14: 'v14.10.1',
352-
10: 'v10.24.1',
353-
6: 'v6.10.3',
354-
5: 'v5.10.1',
352+
20: node20Version
355353
};
356354

357355
if (!nodeVersion) {
358-
nodeVersion = versions[20];
356+
nodeVersion = 'v' + versions[20];
359357
} else {
360358
if (!versions[nodeVersion]) {
361359
fail(`Unexpected node version '${nodeVersion}'. Supported versions: ${Object.keys(versions).join(', ')}`);
362360
};
363-
nodeVersion = versions[nodeVersion];
361+
nodeVersion = 'v' + versions[nodeVersion];
364362
}
365363

366364
if (nodeVersion === run('node -v')) {
@@ -1684,11 +1682,12 @@ var storeNonAggregatedZip = function (zipPath, release, commit) {
16841682
exports.storeNonAggregatedZip = storeNonAggregatedZip;
16851683

16861684
const getTaskNodeVersion = function(buildPath, taskName) {
1685+
const fallbackNode = 20;
16871686
const nodes = new Set();
16881687
const taskJsonPath = path.join(buildPath, taskName, "task.json");
16891688
if (!fs.existsSync(taskJsonPath)) {
1690-
console.warn('Unable to find task.json, defaulting to use Node 10');
1691-
nodes.add(10);
1689+
console.warn(`Unable to find task.json, defaulting to use Node ${fallbackNode}`);
1690+
nodes.add(fallbackNode);
16921691
return Array.from(nodes);
16931692
}
16941693

@@ -1703,16 +1702,16 @@ const getTaskNodeVersion = function(buildPath, taskName) {
17031702
const currExecutor = key.toLocaleLowerCase();
17041703
if (!currExecutor.startsWith('node')) continue;
17051704
const version = currExecutor.replace('node', '');
1706-
nodes.add(parseInt(version) || 20);
1705+
nodes.add(parseInt(version) || fallbackNode);
17071706
}
17081707
}
17091708

17101709
if (nodes.size) {
17111710
return Array.from(nodes);
17121711
}
17131712

1714-
console.warn('Unable to determine execution type from task.json, defaulting to use Node 10 taskName=' + taskName);
1715-
nodes.add(10);
1713+
console.warn(`Unable to determine execution type from task.json, defaulting to use Node ${fallbackNode} taskName=${taskName}`);
1714+
nodes.add(fallbackNode);
17161715
return Array.from(nodes);
17171716
}
17181717
exports.getTaskNodeVersion = getTaskNodeVersion;

make.js

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,17 @@ var tasksCommonPath = path.join(__dirname, 'tasks-common');
6969
var CLI = {};
7070

7171
// node min version
72-
var minNodeVer = '10.24.1';
72+
var minNodeVer = util.node20Version;
7373
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+
);
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...
8384
if (!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

340352
function 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

Comments
 (0)