diff options
author | 2023-06-30 09:25:21 -0500 | |
---|---|---|
committer | 2023-06-30 09:25:21 -0500 | |
commit | 9e2426f75637a6318961f483de90b635f3fdadeb (patch) | |
tree | 9a06b00f285b4517abe2ec6a91bee9030609a6bb | |
parent | fcba0f0199b53e2077aae36b4ea2b287482d5c5c (diff) | |
download | astro-9e2426f75637a6318961f483de90b635f3fdadeb.tar.gz astro-9e2426f75637a6318961f483de90b635f3fdadeb.tar.zst astro-9e2426f75637a6318961f483de90b635f3fdadeb.zip |
fix(#7471): fallback to npm registry if config command fails (#7527)
-rw-r--r-- | .changeset/fair-trees-jump.md | 6 | ||||
-rw-r--r-- | packages/astro/src/core/add/index.ts | 8 | ||||
-rw-r--r-- | packages/create-astro/src/messages.ts | 8 |
3 files changed, 18 insertions, 4 deletions
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<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) { 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<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; |