resolveTargetVersion() — astro Function Reference
Architecture documentation for the resolveTargetVersion() function in verify.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD fad12ab0_742a_6814_2126_8d920a4ce06f["resolveTargetVersion()"] bf354028_170b_aac5_1cb8_bcd8677afe9a["verify.ts"] fad12ab0_742a_6814_2126_8d920a4ce06f -->|defined in| bf354028_170b_aac5_1cb8_bcd8677afe9a cbd6d1fc_ab83_8b16_92d7_39f57bf3357b["verifyVersions()"] cbd6d1fc_ab83_8b16_92d7_39f57bf3357b -->|calls| fad12ab0_742a_6814_2126_8d920a4ce06f eff3ad1f_8498_3945_4399_e3510956954c["extractChangelogURLFromRepository()"] fad12ab0_742a_6814_2126_8d920a4ce06f -->|calls| eff3ad1f_8498_3945_4399_e3510956954c style fad12ab0_742a_6814_2126_8d920a4ce06f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/upgrade/src/actions/verify.ts lines 138–188
async function resolveTargetVersion(packageInfo: PackageInfo, registry: string): Promise<void> {
const packageMetadata = await fetch(`${registry}/${packageInfo.name}`, {
headers: { accept: 'application/vnd.npm.install-v1+json' },
});
if (packageMetadata.status >= 400) {
throw new Error(`Unable to resolve "${packageInfo.name}"`);
}
const { 'dist-tags': distTags } = await packageMetadata.json();
let version = distTags[packageInfo.targetVersion];
if (version) {
packageInfo.tag = packageInfo.targetVersion;
packageInfo.targetVersion = version;
} else {
packageInfo.targetVersion = 'latest';
version = distTags.latest;
}
if (packageInfo.currentVersion === version) {
return;
}
const prefix = packageInfo.targetVersion === 'latest' ? '^' : '';
packageInfo.targetVersion = `${prefix}${version}`;
const fromVersion = semverCoerce(packageInfo.currentVersion)!;
const toVersion = semverParse(version)!;
const bump = semverDiff(fromVersion, toVersion);
if ((bump === 'major' && toVersion.prerelease.length === 0) || bump === 'premajor') {
packageInfo.isMajor = true;
if (packageInfo.name === 'astro') {
const upgradeGuide = `https://docs.astro.build/en/guides/upgrade-to/v${toVersion.major}/`;
const docsRes = await fetch(upgradeGuide);
// OK if this request fails, it's probably a prerelease without a public migration guide.
// In that case, we should fallback to the CHANGELOG check below.
if (docsRes.status === 200) {
packageInfo.changelogURL = upgradeGuide;
packageInfo.changelogTitle = `Upgrade to Astro v${toVersion.major}`;
return;
}
}
const latestMetadata = await fetch(`${registry}/${packageInfo.name}/latest`);
if (latestMetadata.status >= 400) {
throw new Error(`Unable to resolve "${packageInfo.name}"`);
}
const { repository } = await latestMetadata.json();
const branch = bump === 'premajor' ? 'next' : 'main';
packageInfo.changelogURL = extractChangelogURLFromRepository(repository, version, branch);
packageInfo.changelogTitle = 'CHANGELOG';
} else {
// Dependency updates should not include the specific dist-tag
// since they are just for compatibility
packageInfo.tag = undefined;
}
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does resolveTargetVersion() do?
resolveTargetVersion() is a function in the astro codebase, defined in packages/upgrade/src/actions/verify.ts.
Where is resolveTargetVersion() defined?
resolveTargetVersion() is defined in packages/upgrade/src/actions/verify.ts at line 138.
What does resolveTargetVersion() call?
resolveTargetVersion() calls 1 function(s): extractChangelogURLFromRepository.
What calls resolveTargetVersion()?
resolveTargetVersion() is called by 1 function(s): verifyVersions.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free