From 9988dd67e2e4647c974979470d2e63d80433b611 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Thu, 10 Oct 2024 21:32:49 +0800 Subject: [PATCH] Improve default template download speed (#12154) --- .changeset/curvy-bikes-sing.md | 5 ++++ .github/workflows/sync-examples.yml | 6 +++-- examples/hackernews/.gitignore | 4 +++- examples/integration/.gitignore | 24 +++++++++++++++++++ examples/middleware/.gitignore | 24 +++++++++++++++++++ examples/server-islands/.gitignore | 24 +++++++++++++++++++ examples/ssr/.gitignore | 24 +++++++++++++++++++ examples/starlog/.gitignore | 24 +++++++++++++++++++ examples/view-transitions/.gitignore | 24 +++++++++++++++++++ packages/create-astro/src/actions/template.ts | 17 ++++++++++--- 10 files changed, 170 insertions(+), 6 deletions(-) create mode 100644 .changeset/curvy-bikes-sing.md create mode 100644 examples/integration/.gitignore create mode 100644 examples/middleware/.gitignore create mode 100644 examples/server-islands/.gitignore create mode 100644 examples/ssr/.gitignore create mode 100644 examples/starlog/.gitignore create mode 100644 examples/view-transitions/.gitignore diff --git a/.changeset/curvy-bikes-sing.md b/.changeset/curvy-bikes-sing.md new file mode 100644 index 0000000000..c41cf1a12b --- /dev/null +++ b/.changeset/curvy-bikes-sing.md @@ -0,0 +1,5 @@ +--- +'create-astro': minor +--- + +Improves default template download speed by downloading from a branch containing the template only diff --git a/.github/workflows/sync-examples.yml b/.github/workflows/sync-examples.yml index 5cafeef2c2..a18d62738e 100644 --- a/.github/workflows/sync-examples.yml +++ b/.github/workflows/sync-examples.yml @@ -40,11 +40,13 @@ jobs: # We only do sync if there are no changesets, so we don't accidentally allow users # to clone examples that may rely on unreleased code - - name: Sync from main branch to latest branch + - name: Sync from main branch to latest and examples/* branches if: steps.detect.outputs.has-changesets == 'false' && github.ref == 'refs/heads/main' uses: bluwy/auto-branch-sync-action@v1 with: - map: / -> latest + map: | + / -> latest + /examples/* -> examples/* skip-unchanged-check: ${{ inputs.skip-unchanged-check == true }} dry-run: ${{ inputs.dry-run == true }} diff --git a/examples/hackernews/.gitignore b/examples/hackernews/.gitignore index cfc68ec190..16d54bb13c 100644 --- a/examples/hackernews/.gitignore +++ b/examples/hackernews/.gitignore @@ -1,6 +1,5 @@ # build output dist/ -.output/ # generated types .astro/ @@ -20,3 +19,6 @@ pnpm-debug.log* # macOS-specific files .DS_Store + +# jetbrains setting folder +.idea/ diff --git a/examples/integration/.gitignore b/examples/integration/.gitignore new file mode 100644 index 0000000000..16d54bb13c --- /dev/null +++ b/examples/integration/.gitignore @@ -0,0 +1,24 @@ +# build output +dist/ +# generated types +.astro/ + +# dependencies +node_modules/ + +# logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + + +# environment variables +.env +.env.production + +# macOS-specific files +.DS_Store + +# jetbrains setting folder +.idea/ diff --git a/examples/middleware/.gitignore b/examples/middleware/.gitignore new file mode 100644 index 0000000000..16d54bb13c --- /dev/null +++ b/examples/middleware/.gitignore @@ -0,0 +1,24 @@ +# build output +dist/ +# generated types +.astro/ + +# dependencies +node_modules/ + +# logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + + +# environment variables +.env +.env.production + +# macOS-specific files +.DS_Store + +# jetbrains setting folder +.idea/ diff --git a/examples/server-islands/.gitignore b/examples/server-islands/.gitignore new file mode 100644 index 0000000000..16d54bb13c --- /dev/null +++ b/examples/server-islands/.gitignore @@ -0,0 +1,24 @@ +# build output +dist/ +# generated types +.astro/ + +# dependencies +node_modules/ + +# logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + + +# environment variables +.env +.env.production + +# macOS-specific files +.DS_Store + +# jetbrains setting folder +.idea/ diff --git a/examples/ssr/.gitignore b/examples/ssr/.gitignore new file mode 100644 index 0000000000..16d54bb13c --- /dev/null +++ b/examples/ssr/.gitignore @@ -0,0 +1,24 @@ +# build output +dist/ +# generated types +.astro/ + +# dependencies +node_modules/ + +# logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + + +# environment variables +.env +.env.production + +# macOS-specific files +.DS_Store + +# jetbrains setting folder +.idea/ diff --git a/examples/starlog/.gitignore b/examples/starlog/.gitignore new file mode 100644 index 0000000000..16d54bb13c --- /dev/null +++ b/examples/starlog/.gitignore @@ -0,0 +1,24 @@ +# build output +dist/ +# generated types +.astro/ + +# dependencies +node_modules/ + +# logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + + +# environment variables +.env +.env.production + +# macOS-specific files +.DS_Store + +# jetbrains setting folder +.idea/ diff --git a/examples/view-transitions/.gitignore b/examples/view-transitions/.gitignore new file mode 100644 index 0000000000..16d54bb13c --- /dev/null +++ b/examples/view-transitions/.gitignore @@ -0,0 +1,24 @@ +# build output +dist/ +# generated types +.astro/ + +# dependencies +node_modules/ + +# logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + + +# environment variables +.env +.env.production + +# macOS-specific files +.DS_Store + +# jetbrains setting folder +.idea/ diff --git a/packages/create-astro/src/actions/template.ts b/packages/create-astro/src/actions/template.ts index e1775ee51d..a5d217e0ea 100644 --- a/packages/create-astro/src/actions/template.ts +++ b/packages/create-astro/src/actions/template.ts @@ -72,13 +72,25 @@ const FILES_TO_UPDATE = { }; export function getTemplateTarget(tmpl: string, ref = 'latest') { + // Handle Starlight templates if (tmpl.startsWith('starlight')) { const [, starter = 'basics'] = tmpl.split('/'); - return `withastro/starlight/examples/${starter}`; + return `github:withastro/starlight/examples/${starter}`; } + + // Handle third-party templates const isThirdParty = tmpl.includes('/'); if (isThirdParty) return tmpl; - return `github:withastro/astro/examples/${tmpl}#${ref}`; + + // Handle Astro templates + if (ref === 'latest') { + // `latest` ref is specially handled to route to a branch specifically + // to allow faster downloads. Otherwise giget has to download the entire + // repo and only copy a sub directory + return `github:withastro/astro#examples/${tmpl}`; + } else { + return `github:withastro/astro/examples/${tmpl}#${ref}`; + } } export default async function copyTemplate(tmpl: string, ctx: Context) { @@ -88,7 +100,6 @@ export default async function copyTemplate(tmpl: string, ctx: Context) { try { await downloadTemplate(templateTarget, { force: true, - provider: 'github', cwd: ctx.cwd, dir: '.', });