From 4a491f23d43e62c797127164047047fc3b8b1f07 Mon Sep 17 00:00:00 2001 From: apatel369 Date: Mon, 25 Nov 2024 22:54:20 -0600 Subject: [PATCH 1/8] Fix: Use ref passed by user to get version in create astro --- .changeset/selfish-bulldogs-jog.md | 5 +++++ packages/create-astro/src/actions/context.ts | 2 +- packages/create-astro/src/messages.ts | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/selfish-bulldogs-jog.md diff --git a/.changeset/selfish-bulldogs-jog.md b/.changeset/selfish-bulldogs-jog.md new file mode 100644 index 000000000000..474cc7993dc3 --- /dev/null +++ b/.changeset/selfish-bulldogs-jog.md @@ -0,0 +1,5 @@ +--- +'create-astro': patch +--- + +Fixes an issue where the `getVersion` function was incorrectly using the `latest` tag instead of the user-specified `ref` to determine the Astro version. diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index 59f85f88a10e..33d80898fc5f 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -93,7 +93,7 @@ export async function getContext(argv: string[]): Promise { prompt, packageManager, username: getName(), - version: getVersion(packageManager, 'astro', process.env.ASTRO_VERSION), + version: getVersion(packageManager, 'astro', process.env.ASTRO_VERSION, ref), skipHouston, fancy, add, diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index 898c9c728e28..30bd4f231d41 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, fallback = '', ref = 'latest') => new Promise(async (resolve) => { let registry = await getRegistry(packageManager); - const { version } = await fetch(`${registry}/${packageName}/latest`, { + const { version } = await fetch(`${registry}/${packageName}/${ref}`, { redirect: 'follow', }) .then((res) => res.json()) From 421f7680be1d02f127a1d33b8cc428b8ff9075d4 Mon Sep 17 00:00:00 2001 From: apatel369 Date: Tue, 26 Nov 2024 21:09:16 -0600 Subject: [PATCH 2/8] fix tag name --- packages/create-astro/src/actions/context.ts | 5 +++-- packages/create-astro/src/messages.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index 33d80898fc5f..3581444ab09d 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -75,7 +75,8 @@ export async function getContext(argv: string[]): Promise { '--add': add, } = flags; let projectName = cwd; - + const tag = ref === 'next' ? 'beta' : ref; + if (no) { yes = false; if (install == undefined) install = false; @@ -93,7 +94,7 @@ export async function getContext(argv: string[]): Promise { prompt, packageManager, username: getName(), - version: getVersion(packageManager, 'astro', process.env.ASTRO_VERSION, ref), + version: getVersion(packageManager, 'astro', process.env.ASTRO_VERSION, tag), skipHouston, fancy, add, diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index 30bd4f231d41..51b9f2116fdf 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 = '', ref = 'latest') => +export const getVersion = (packageManager: string, packageName: string, fallback = '', tag = 'latest') => new Promise(async (resolve) => { let registry = await getRegistry(packageManager); - const { version } = await fetch(`${registry}/${packageName}/${ref}`, { + const { version } = await fetch(`${registry}/${packageName}/${tag}`, { redirect: 'follow', }) .then((res) => res.json()) From 4bde0d0d47989d78c4aa558c997a11e40b78a73b Mon Sep 17 00:00:00 2001 From: apatel369 Date: Tue, 26 Nov 2024 21:32:34 -0600 Subject: [PATCH 3/8] improve changeset --- .changeset/selfish-bulldogs-jog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/selfish-bulldogs-jog.md b/.changeset/selfish-bulldogs-jog.md index 474cc7993dc3..668d010813f3 100644 --- a/.changeset/selfish-bulldogs-jog.md +++ b/.changeset/selfish-bulldogs-jog.md @@ -2,4 +2,4 @@ 'create-astro': patch --- -Fixes an issue where the `getVersion` function was incorrectly using the `latest` tag instead of the user-specified `ref` to determine the Astro version. +Fixes an issue where installing Astro v5-beta using `create-astro` would display the wrong Astro version in the installation messages. From cfd35f5e8482e7dc0f19146983fa7529aeaa9871 Mon Sep 17 00:00:00 2001 From: apatel369 Date: Sat, 30 Nov 2024 00:21:36 -0600 Subject: [PATCH 4/8] parse tag from command --- packages/create-astro/src/actions/context.ts | 6 ++++-- packages/create-astro/src/messages.ts | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index 3581444ab09d..f6e71a4694e1 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -34,6 +34,8 @@ export interface Context { } export async function getContext(argv: string[]): Promise { + const packageTag = argv.find((argItem) => /^(astro|create-astro)@/.exec(argItem))?.split('@')[1]; + const flags = arg( { '--template': String, @@ -76,7 +78,7 @@ export async function getContext(argv: string[]): Promise { } = flags; let projectName = cwd; const tag = ref === 'next' ? 'beta' : ref; - + if (no) { yes = false; if (install == undefined) install = false; @@ -94,7 +96,7 @@ export async function getContext(argv: string[]): Promise { prompt, packageManager, username: getName(), - version: getVersion(packageManager, 'astro', process.env.ASTRO_VERSION, tag), + 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 51b9f2116fdf..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 = '', tag = 'latest') => +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}/${tag}`, { + const { version } = await fetch(`${registry}/${packageName}/${packageTag}`, { redirect: 'follow', }) .then((res) => res.json()) From 3507123795bb1e5d259e8a959e187e4ac65166ab Mon Sep 17 00:00:00 2001 From: apatel369 Date: Sat, 30 Nov 2024 00:22:51 -0600 Subject: [PATCH 5/8] cleanup --- packages/create-astro/src/actions/context.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index f6e71a4694e1..a8211b8b0e3a 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -77,7 +77,6 @@ export async function getContext(argv: string[]): Promise { '--add': add, } = flags; let projectName = cwd; - const tag = ref === 'next' ? 'beta' : ref; if (no) { yes = false; From 4acb6830b2627bb562f27ac487c93066dc9aef18 Mon Sep 17 00:00:00 2001 From: apatel369 Date: Sat, 30 Nov 2024 00:48:14 -0600 Subject: [PATCH 6/8] improve changeset --- .changeset/selfish-bulldogs-jog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/selfish-bulldogs-jog.md b/.changeset/selfish-bulldogs-jog.md index 668d010813f3..b6693ef59b9b 100644 --- a/.changeset/selfish-bulldogs-jog.md +++ b/.changeset/selfish-bulldogs-jog.md @@ -2,4 +2,4 @@ 'create-astro': patch --- -Fixes an issue where installing Astro v5-beta using `create-astro` would display the wrong Astro version in the installation messages. +Fixes an issue where installing Astro beta using `create-astro` displays the wrong Astro version in the installation messages. From 3f28643066dc449af112c4e1a81e687bd1a9ffd0 Mon Sep 17 00:00:00 2001 From: apatel369 Date: Sun, 8 Dec 2024 14:24:17 -0600 Subject: [PATCH 7/8] fallback to latest --- packages/create-astro/src/actions/context.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index a8211b8b0e3a..3693ad0c50a2 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -34,7 +34,9 @@ export interface Context { } export async function getContext(argv: string[]): Promise { - const packageTag = argv.find((argItem) => /^(astro|create-astro)@/.exec(argItem))?.split('@')[1]; + 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( { From 8a6bcbde23e5c31c5fb1320f07aa02c024e71dae Mon Sep 17 00:00:00 2001 From: apatel369 Date: Sun, 8 Dec 2024 14:26:54 -0600 Subject: [PATCH 8/8] format --- packages/create-astro/src/actions/context.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/create-astro/src/actions/context.ts b/packages/create-astro/src/actions/context.ts index 3693ad0c50a2..fdcbbb7a32bd 100644 --- a/packages/create-astro/src/actions/context.ts +++ b/packages/create-astro/src/actions/context.ts @@ -34,9 +34,12 @@ export interface Context { } export async function getContext(argv: string[]): Promise { - const packageSpecifier = argv.find((argItem) => /^(astro|create-astro)@/.exec(argItem))?.split('@')[1]; + 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 packageTag = + packageSpecifier && /^v?\d[^a-zA-Z]*$/.test(packageSpecifier) ? 'latest' : packageSpecifier; const flags = arg( {