mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Fix invalid URLs being returned from getRegistry
, synchronize all copies (#10117)
This commit is contained in:
parent
ef080d5b93
commit
51b6ff7403
4 changed files with 28 additions and 6 deletions
7
.changeset/twelve-waves-matter.md
Normal file
7
.changeset/twelve-waves-matter.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
"create-astro": patch
|
||||
"@astrojs/upgrade": patch
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Fixes an issue where `create astro`, `astro add` and `@astrojs/upgrade` would fail due to unexpected package manager CLI output.
|
|
@ -81,14 +81,20 @@ const OFFICIAL_ADAPTER_TO_IMPORT_MAP: Record<string, string> = {
|
|||
// checks the user's project type and will return the proper npm registry
|
||||
//
|
||||
// A copy of this function also exists in the create-astro package
|
||||
let _registry: string;
|
||||
async function getRegistry(): Promise<string> {
|
||||
if (_registry) return _registry;
|
||||
const fallback = 'https://registry.npmjs.org';
|
||||
const packageManager = (await preferredPM(process.cwd()))?.name || 'npm';
|
||||
try {
|
||||
const { stdout } = await execa(packageManager, ['config', 'get', 'registry']);
|
||||
return stdout?.trim()?.replace(/\/$/, '') || 'https://registry.npmjs.org';
|
||||
_registry = stdout?.trim()?.replace(/\/$/, '') || fallback;
|
||||
// Detect cases where the shell command returned a non-URL (e.g. a warning)
|
||||
if (!new URL(_registry).host) _registry = fallback;
|
||||
} catch (e) {
|
||||
return 'https://registry.npmjs.org';
|
||||
_registry = fallback;
|
||||
}
|
||||
return _registry;
|
||||
}
|
||||
|
||||
export async function add(names: string[], { flags }: AddOptions) {
|
||||
|
|
|
@ -12,11 +12,14 @@ import { shell } from './shell.js';
|
|||
let _registry: string;
|
||||
async function getRegistry(packageManager: string): Promise<string> {
|
||||
if (_registry) return _registry;
|
||||
const fallback = 'https://registry.npmjs.org';
|
||||
try {
|
||||
const { stdout } = await shell(packageManager, ['config', 'get', 'registry']);
|
||||
_registry = stdout?.trim()?.replace(/\/$/, '') || 'https://registry.npmjs.org';
|
||||
_registry = stdout?.trim()?.replace(/\/$/, '') || fallback;
|
||||
// Detect cases where the shell command returned a non-URL (e.g. a warning)
|
||||
if (!new URL(_registry).host) _registry = fallback;
|
||||
} catch (e) {
|
||||
_registry = 'https://registry.npmjs.org';
|
||||
_registry = fallback;
|
||||
}
|
||||
return _registry;
|
||||
}
|
||||
|
|
|
@ -10,14 +10,20 @@ import { shell } from './shell.js';
|
|||
// checks the user's project type and will return the proper npm registry
|
||||
//
|
||||
// A copy of this function also exists in the astro package
|
||||
let _registry: string;
|
||||
export async function getRegistry(): Promise<string> {
|
||||
if (_registry) return _registry;
|
||||
const fallback = 'https://registry.npmjs.org';
|
||||
const packageManager = detectPackageManager()?.name || 'npm';
|
||||
try {
|
||||
const { stdout } = await shell(packageManager, ['config', 'get', 'registry']);
|
||||
return stdout?.trim()?.replace(/\/$/, '') || 'https://registry.npmjs.org';
|
||||
_registry = stdout?.trim()?.replace(/\/$/, '') || fallback;
|
||||
// Detect cases where the shell command returned a non-URL (e.g. a warning)
|
||||
if (!new URL(_registry).host) _registry = fallback;
|
||||
} catch (e) {
|
||||
return 'https://registry.npmjs.org';
|
||||
_registry = fallback;
|
||||
}
|
||||
return _registry;
|
||||
}
|
||||
|
||||
let stdout = process.stdout;
|
||||
|
|
Loading…
Reference in a new issue