summaryrefslogtreecommitdiff
path: root/packages/create-astro
diff options
context:
space:
mode:
Diffstat (limited to 'packages/create-astro')
-rw-r--r--packages/create-astro/CHANGELOG.md6
-rwxr-xr-xpackages/create-astro/create-astro.mjs2
-rw-r--r--packages/create-astro/package.json4
-rw-r--r--packages/create-astro/src/actions/template.ts10
-rw-r--r--packages/create-astro/src/actions/verify.ts60
-rw-r--r--packages/create-astro/src/index.ts4
6 files changed, 15 insertions, 71 deletions
diff --git a/packages/create-astro/CHANGELOG.md b/packages/create-astro/CHANGELOG.md
index 59f6ab93f..2238bc056 100644
--- a/packages/create-astro/CHANGELOG.md
+++ b/packages/create-astro/CHANGELOG.md
@@ -1,5 +1,11 @@
# create-astro
+## 4.9.2
+
+### Patch Changes
+
+- [#12143](https://github.com/withastro/astro/pull/12143) [`2385d58`](https://github.com/withastro/astro/commit/2385d58389ee975a53f4089f2a7220d97cf3cdff) Thanks [@bluwy](https://github.com/bluwy)! - Uses `@bluwy/giget-core` instead of `giget` for smaller installation size when downloading the CLI
+
## 4.9.1
### Patch Changes
diff --git a/packages/create-astro/create-astro.mjs b/packages/create-astro/create-astro.mjs
index f9df779d8..5e25e5e94 100755
--- a/packages/create-astro/create-astro.mjs
+++ b/packages/create-astro/create-astro.mjs
@@ -1,5 +1,5 @@
#!/usr/bin/env node
-/* eslint-disable no-console */
+
'use strict';
const currentVersion = process.versions.node;
diff --git a/packages/create-astro/package.json b/packages/create-astro/package.json
index 35f29e83c..f7aaa96a1 100644
--- a/packages/create-astro/package.json
+++ b/packages/create-astro/package.json
@@ -1,6 +1,6 @@
{
"name": "create-astro",
- "version": "4.9.1",
+ "version": "4.9.2",
"type": "module",
"author": "withastro",
"license": "MIT",
@@ -32,7 +32,7 @@
"//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES",
"dependencies": {
"@astrojs/cli-kit": "^0.4.1",
- "giget": "1.2.3"
+ "@bluwy/giget-core": "^0.1.0"
},
"devDependencies": {
"arg": "^5.0.2",
diff --git a/packages/create-astro/src/actions/template.ts b/packages/create-astro/src/actions/template.ts
index d67b54ee0..e1775ee51 100644
--- a/packages/create-astro/src/actions/template.ts
+++ b/packages/create-astro/src/actions/template.ts
@@ -3,7 +3,7 @@ import type { Context } from './context.js';
import fs from 'node:fs';
import path from 'node:path';
import { color } from '@astrojs/cli-kit';
-import { downloadTemplate } from 'giget';
+import { downloadTemplate } from '@bluwy/giget-core';
import { error, info, title } from '../messages.js';
export async function template(
@@ -125,14 +125,6 @@ export default async function copyTemplate(tmpl: string, ctx: Context) {
throw new Error(`Unable to download template ${color.reset(tmpl)}`);
}
- // It's possible the repo exists (ex. `withastro/astro`),
- // But the template route is invalid (ex. `withastro/astro/examples/DNE`).
- // `giget` doesn't throw for this case,
- // so check if the directory is still empty as a heuristic.
- if (fs.readdirSync(ctx.cwd).length === 0) {
- throw new Error(`Template ${color.reset(tmpl)} ${color.dim('is empty!')}`);
- }
-
// Post-process in parallel
const removeFiles = FILES_TO_REMOVE.map(async (file) => {
const fileLoc = path.resolve(path.join(ctx.cwd, file));
diff --git a/packages/create-astro/src/actions/verify.ts b/packages/create-astro/src/actions/verify.ts
index e620a9ca8..7f446c869 100644
--- a/packages/create-astro/src/actions/verify.ts
+++ b/packages/create-astro/src/actions/verify.ts
@@ -2,6 +2,7 @@ import type { Context } from './context.js';
import dns from 'node:dns/promises';
import { color } from '@astrojs/cli-kit';
+import { verifyTemplate } from '@bluwy/giget-core';
import { bannerAbort, error, info, log } from '../messages.js';
import { getTemplateTarget } from './template.js';
@@ -19,7 +20,8 @@ export async function verify(
}
if (ctx.template) {
- const ok = await verifyTemplate(ctx.template, ctx.ref);
+ const target = getTemplateTarget(ctx.template, ctx.ref);
+ const ok = await verifyTemplate(target);
if (!ok) {
bannerAbort();
log('');
@@ -36,59 +38,3 @@ function isOnline(): Promise<boolean> {
() => false,
);
}
-
-async function verifyTemplate(tmpl: string, ref?: string) {
- const target = getTemplateTarget(tmpl, ref);
- const { repo, subdir, ref: branch } = parseGitURI(target.replace('github:', ''));
- const url = new URL(`/repos/${repo}/contents${subdir}?ref=${branch}`, 'https://api.github.com/');
-
- let res = await fetch(url.toString(), {
- headers: {
- Accept: 'application/vnd.github+json',
- 'X-GitHub-Api-Version': '2022-11-28',
- },
- });
-
- // If users hit a ratelimit, fallback to the GitHub website
- if (res.status === 403) {
- res = await fetch(`https://github.com/${repo}/tree/${branch}${subdir}`);
- }
-
- return res.status === 200;
-}
-
-// Adapted from https://github.com/unjs/giget/blob/main/src/_utils.ts
-// MIT License
-
-// Copyright (c) Pooya Parsa <pooya@pi0.io>
-
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-
-// The above copyright notice and this permission notice shall be included in all
-// copies or substantial portions of the Software.
-
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-// SOFTWARE.
-// Disable eslint rule to not touch the original code
-// eslint-disable-next-line regexp/no-misleading-capturing-group
-const GIT_RE = /^(?<repo>[\w.-]+\/[\w.-]+)(?<subdir>[^#]+)?(?<ref>#[\w.-]+)?/;
-
-function parseGitURI(input: string) {
- const m = GIT_RE.exec(input)?.groups;
- if (!m) throw new Error(`Unable to parse "${input}"`);
- return {
- repo: m.repo,
- subdir: m.subdir || '/',
- ref: m.ref ? m.ref.slice(1) : 'main',
- };
-}
diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts
index 9f2a50a8b..fdd0aa32c 100644
--- a/packages/create-astro/src/index.ts
+++ b/packages/create-astro/src/index.ts
@@ -18,7 +18,7 @@ process.on('SIGTERM', exit);
export async function main() {
// Add some extra spacing from the noisy npm/pnpm init output
- // eslint-disable-next-line no-console
+ // biome-ignore lint/suspicious/noConsoleLog: allowed
console.log('');
// NOTE: In the v7.x version of npm, the default behavior of `npm init` was changed
// to no longer require `--` to pass args and instead pass `--` directly to us. This
@@ -47,7 +47,7 @@ export async function main() {
await step(ctx);
}
- // eslint-disable-next-line no-console
+ // biome-ignore lint/suspicious/noConsoleLog: allowed
console.log('');
const labels = {