async function getTfx()

in BuildTasks/TfxInstaller/TfxInstaller.ts [24:64]


async function getTfx(versionSpec: string, checkLatest: boolean) {
    if (toolLib.isExplicitVersion(versionSpec)) {
        checkLatest = false; // check latest doesn't make sense when explicit version
    }

    let toolPath: string;
    if (!checkLatest) {
        toolPath = toolLib.findLocalTool('tfx', versionSpec);
    }

    if (!toolPath) {
        let version: string;
        if (toolLib.isExplicitVersion(versionSpec)) {
            version = versionSpec;
        }
        else {
            version = queryLatestMatch(versionSpec);
            if (!version) {
                throw new Error(`Unable to find Tfx version '${versionSpec}'`);
            }

            toolPath = toolLib.findLocalTool('tfx', version);
        }

        if (!toolPath) {
            toolPath = await acquireTfx(version);
        }
    }

    if (os.platform() !== "win32")
    {
        // Depending on target platform npm behaves slightly different. This seems to differ between distros and npm versions too.
        const probePaths = [toolPath, path.join(toolPath, "/bin"), path.join(toolPath, "/node_modules/.bin/")];
        toolPath = probePaths.find((probePath) => {
            return taskLib.exist(path.join(probePath, "/tfx"));
        });
    }
    
    taskLib.setVariable("__tfxpath", toolPath, false);
    toolLib.prependPath(toolPath);
}