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 getAvailableHaulPreset(
progress: Ora,
targetHaulPreset: string
): Promise {
// Stop searching on 0.59 - there's no preset below 0.59.
if (targetHaulPreset.includes('0.59')) {
return targetHaulPreset;
}
try {
await npmFetch(targetHaulPreset);
return targetHaulPreset;
} catch (error) {
if (error.statusCode === 404) {
progress.info(
`${targetHaulPreset} not available. Trying older version...`
);
const previousHaulPreset = targetHaulPreset.replace(/-0\.\d+$/, match => {
const [major, minor] = match.slice(1).split('.');
return `-${major}.${parseInt(minor, 10) - 1}`;
});
return await getAvailableHaulPreset(progress, previousHaulPreset);
}
return targetHaulPreset;
}
}