Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(create-astro): use CLI version tag to determine astro version #12529

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions .changeset/selfish-bulldogs-jog.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 8 additions & 1 deletion packages/create-astro/src/actions/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export interface Context {
}

export async function getContext(argv: string[]): Promise<Context> {
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;
Comment on lines +41 to +42
Copy link
Member

@bluwy bluwy Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we play a bit safer here and only allow known tags? e.g.

switch (packageSpecifier) {
  case 'alpha':
  case 'beta':
  case 'rc':
    return packageSpecifier;
  default:
    return 'latest'
}

The code here is inferring the tag between create-astro and astro, and they might not match if we're loosely passing them.


const flags = arg(
{
'--template': String,
Expand Down Expand Up @@ -93,7 +100,7 @@ export async function getContext(argv: string[]): Promise<Context> {
prompt,
packageManager,
username: getName(),
version: getVersion(packageManager, 'astro', process.env.ASTRO_VERSION),
version: getVersion(packageManager, 'astro', packageTag, process.env.ASTRO_VERSION),
skipHouston,
fancy,
add,
Expand Down
4 changes: 2 additions & 2 deletions packages/create-astro/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(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())
Expand Down
Loading