diff --git a/.changeset/fair-trees-jump.md b/.changeset/fair-trees-jump.md new file mode 100644 index 000000000..336faad84 --- /dev/null +++ b/.changeset/fair-trees-jump.md @@ -0,0 +1,6 @@ +--- +'create-astro': patch +'astro': patch +--- + +Default registry logic to fallback to NPM if registry command fails (sorry, Bun users!) diff --git a/packages/astro/src/core/add/index.ts b/packages/astro/src/core/add/index.ts index 1ce9163bf..12554409f 100644 --- a/packages/astro/src/core/add/index.ts +++ b/packages/astro/src/core/add/index.ts @@ -77,8 +77,12 @@ const OFFICIAL_ADAPTER_TO_IMPORT_MAP: Record = { // A copy of this function also exists in the create-astro package async function getRegistry(): Promise { const packageManager = (await preferredPM(process.cwd()))?.name || 'npm'; - const { stdout } = await execa(packageManager, ['config', 'get', 'registry']); - return stdout || 'https://registry.npmjs.org'; + try { + const { stdout } = await execa(packageManager, ['config', 'get', 'registry']); + return stdout || 'https://registry.npmjs.org'; + } catch (e) { + return 'https://registry.npmjs.org'; + } } export default async function add(names: string[], { cwd, flags, logging }: AddOptions) { diff --git a/packages/create-astro/src/messages.ts b/packages/create-astro/src/messages.ts index 2f8ca960b..4a51e0f80 100644 --- a/packages/create-astro/src/messages.ts +++ b/packages/create-astro/src/messages.ts @@ -13,8 +13,12 @@ import detectPackageManager from 'which-pm-runs'; // A copy of this function also exists in the astro package async function getRegistry(): Promise { const packageManager = detectPackageManager()?.name || 'npm'; - const { stdout } = await execa(packageManager, ['config', 'get', 'registry']); - return stdout || 'https://registry.npmjs.org'; + try { + const { stdout } = await execa(packageManager, ['config', 'get', 'registry']); + return stdout || 'https://registry.npmjs.org'; + } catch (e) { + return 'https://registry.npmjs.org'; + } } let stdout = process.stdout;