Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function getRemotePackageVersion(pkgInfo: i.PackageInfo): Promise {
if (pkgInfo.private) return pkgInfo.version;
const registryUrl: string|undefined = get(pkgInfo, 'publishConfig.registry');
const tag = getPublishTag(pkgInfo.version);
try {
const { version } = await packageJson(pkgInfo.name, {
version: tag,
registryUrl
});
return version as string;
} catch (err) {
if (err instanceof packageJson.VersionNotFoundError) {
return pkgInfo.version;
}
if (err instanceof packageJson.PackageNotFoundError) {
return '0.1.0';
}
throw err;
}
}