Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function acquireTfx(version: string): Promise {
try{
version = toolLib.cleanVersion(version);
let extPath: string;
taskLib.assertAgent('2.115.0');
extPath = taskLib.getVariable('Agent.TempDirectory');
if (!extPath) {
throw new Error('Expected Agent.TempDirectory to be set');
}
extPath = path.join(extPath, 'tfx'); // use as short a path as possible due to nested node_modules folders
taskLib.mkdirP(path.join(extPath));
const npmRunner = new tr.ToolRunner("npm");
npmRunner.arg(["install", "tfx-cli@" + version, "--prefix", extPath]);
const result = npmRunner.execSync({ failOnStdErr: false, silent: true, ignoreReturnCode: false} as tr.IExecOptions);
if (result.code === 0)
{
console.log('yuniql/var_downloadUrl: ' + downloadUrl);
const temp: string = await toolLib.downloadTool(downloadUrl);
console.log('yuniql/var_temp: ' + temp);
//extract assemblies
const extractRoot: string = await toolLib.extractZip(temp);
console.log('yuniql/var_extractRoot: ' + extractRoot);
//cache assemblies
if (version != 'latest') {
toolLib.cacheDir(extractRoot, "yuniql", version);
} else {
//use v0.0.0 as placeholder for latest version
//TODO: always replace the current cached version for now
toolLib.cleanVersion('v0.0.0');
toolLib.cacheDir(extractRoot, "yuniql", 'v0.0.0');
}
//append PATH
toolLib.prependPath(extractRoot);
}
}
catch (error) {
console.log('yuniql/error: ' + error.message);
taskLib.setResult(taskLib.TaskResult.Failed, error.message);
}
}
function sanitizeVersionString(inputVersion: string) : string{
const version = toolLib.cleanVersion(inputVersion);
if(!version) {
throw new Error(tl.loc("NotAValidSemverVersion"));
}
return version;
}