async function resolveToOnlineTarget (spec = {}) {
    const targetList = await exports.list();
    if (targetList.length === 0) return null;

    // Sort by type: devices first, then emulators.
    targetList.sort(compareBy(t => t.type));

    // Find first matching target for spec. {} matches any target.
    return targetList.find(target =>
        Object.keys(spec).every(k => spec[k] === target[k])
    ) || null;
}
@param {TargetSpec?} spec
@return {Promise<Target>}