Skip to content

Commit

Permalink
fix(#7471): fallback to npm registry if config command fails (#7527)
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re authored Jun 30, 2023
1 parent fcba0f0 commit 9e2426f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/fair-trees-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'create-astro': patch
'astro': patch
---

Default registry logic to fallback to NPM if registry command fails (sorry, Bun users!)
8 changes: 6 additions & 2 deletions packages/astro/src/core/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ const OFFICIAL_ADAPTER_TO_IMPORT_MAP: Record<string, string> = {
// A copy of this function also exists in the create-astro package
async function getRegistry(): Promise<string> {
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) {
Expand Down
8 changes: 6 additions & 2 deletions packages/create-astro/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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;
Expand Down

0 comments on commit 9e2426f

Please sign in to comment.