diff --git a/.changeset/selfish-bulldogs-jog.md b/.changeset/selfish-bulldogs-jog.md new file mode 100644 index 000000000000..b6693ef59b9b --- /dev/null +++ b/.changeset/selfish-bulldogs-jog.md @@ -0,0 +1,5 @@ +--- +'create-astro': patch +--- + +Fixes an issue where installing Astro beta using `create-astro` displays the wrong Astro version in the installation messages. diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index 59f85f88a10e..fdcbbb7a32bd 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -34,6 +34,13 @@ export interface Context { } export async function getContext(argv: string[]): Promise { + const packageSpecifier = argv + .find((argItem) => /^(astro|create-astro)@/.exec(argItem)) + ?.split('@')[1]; + // Fallback to 'latest' if it's a version number + const packageTag = + packageSpecifier && /^v?\d[^a-zA-Z]*$/.test(packageSpecifier) ? 'latest' : packageSpecifier; + const flags = arg( { '--template': String, @@ -93,7 +100,7 @@ export async function getContext(argv: string[]): Promise { prompt, packageManager, username: getName(), - version: getVersion(packageManager, 'astro', process.env.ASTRO_VERSION), + version: getVersion(packageManager, 'astro', packageTag, process.env.ASTRO_VERSION), skipHouston, fancy, add, diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index 898c9c728e28..892dcbb6400a 100644 --- a/packages/create-astro/src/messages.ts +++ b/packages/create-astro/src/messages.ts @@ -60,10 +60,10 @@ export const getName = () => }); }); -export const getVersion = (packageManager: string, packageName: string, fallback = '') => +export const getVersion = (packageManager: string, packageName: string, packageTag = 'latest', fallback = '') => new Promise(async (resolve) => { let registry = await getRegistry(packageManager); - const { version } = await fetch(`${registry}/${packageName}/latest`, { + const { version } = await fetch(`${registry}/${packageName}/${packageTag}`, { redirect: 'follow', }) .then((res) => res.json())