0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

fix(#7471): fallback to npm registry if config command fails (#7527)

This commit is contained in:
Nate Moore 2023-06-30 09:25:21 -05:00 committed by GitHub
parent fcba0f0199
commit 9e2426f756
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 4 deletions

View file

@ -0,0 +1,6 @@
---
'create-astro': patch
'astro': patch
---
Default registry logic to fallback to NPM if registry command fails (sorry, Bun users!)

View file

@ -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';
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) {

View file

@ -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';
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;