Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to default npm registry if config command fails #7527

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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