in sample.ts [58:124]
async function getNode(versionSpec: string, checkLatest: boolean) {
console.log('');
console.log('--------------------------');
console.log('SAMPLE: ' + versionSpec);
console.log('--------------------------');
if (toolLib.isExplicitVersion(versionSpec)) {
checkLatest = false; // check latest doesn't make sense when explicit version
}
let toolPath: string;
if (!checkLatest) {
//
// Let's try and resolve the version spec locally first
//
toolPath = toolLib.findLocalTool('node', versionSpec);
}
if (!toolPath) {
let version: string;
if (toolLib.isExplicitVersion(versionSpec)) {
//
// Explicit version was specified. No need to query for list of versions.
//
version = versionSpec;
}
else {
//
// Let's query and resolve the latest version for the versionSpec.
// If the version is an explicit version (1.1.1 or v1.1.1) then no need to query.
// If your tool doesn't offer a mechanism to query,
// then it can only support exact version inputs.
//
version = await queryLatestMatch(versionSpec);
if (!version) {
throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
}
//
// Check the cache for the resolved version.
//
toolPath = toolLib.findLocalTool('node', version)
}
if (!toolPath) {
//
// Download, extract, cache
//
toolPath = await acquireNode(version);
}
}
//
// A tool installer initimately knows details about the layout of that tool
// for example, node binary is in the bin folder after the extract on Mac/Linux.
// layouts could change by version, by platform etc... but that's the tool installers job
//
if (osPlat != 'win32') {
toolPath = path.join(toolPath, 'bin');
}
//
// Prepend the tools path. This prepends the PATH for the current process and
// instructs the agent to prepend for each task that follows.
//
toolLib.prependPath(toolPath);
}