Fix multiple create-astro
registry issues (#7539)
* fix: getVersion Error when registry ends with '/' * Update .changeset/old-seahorses-fold.md * Update .changeset/old-seahorses-fold.md * refactor: cleanup registry logic * chore: update changeset * fix(create-astro): update registry logic to rely on `fetch` * chore: update changeset * chore: update lockfile * Update old-seahorses-fold.md --------- Co-authored-by: jincheng32537 <jincheng32537@hundsun.com> Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> Co-authored-by: Nate Moore <nate@astro.build>
This commit is contained in:
parent
2172dd4f0d
commit
1170877b51
5 changed files with 20 additions and 16 deletions
6
.changeset/old-seahorses-fold.md
Normal file
6
.changeset/old-seahorses-fold.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
'astro': patch
|
||||
'create-astro': patch
|
||||
---
|
||||
|
||||
Update registry logic, improving edge cases (http support, redirects, registries ending with '/')
|
|
@ -79,7 +79,7 @@ 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';
|
||||
return stdout?.trim()?.replace(/\/$/, '') || 'https://registry.npmjs.org';
|
||||
} catch (e) {
|
||||
return 'https://registry.npmjs.org';
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
"execa": "^6.1.0",
|
||||
"giget": "1.0.0",
|
||||
"mocha": "^9.2.2",
|
||||
"node-fetch-native": "^1.2.0",
|
||||
"which-pm-runs": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -3,7 +3,7 @@ import { color, label, say as houston, spinner as load } from '@astrojs/cli-kit'
|
|||
import { align, sleep } from '@astrojs/cli-kit/utils';
|
||||
import { execa } from 'execa';
|
||||
import { exec } from 'node:child_process';
|
||||
import { get } from 'node:https';
|
||||
import fetch from 'node-fetch-native';
|
||||
import stripAnsi from 'strip-ansi';
|
||||
import detectPackageManager from 'which-pm-runs';
|
||||
|
||||
|
@ -15,7 +15,7 @@ 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';
|
||||
return stdout?.trim()?.replace(/\/$/, '') || 'https://registry.npmjs.org';
|
||||
} catch (e) {
|
||||
return 'https://registry.npmjs.org';
|
||||
}
|
||||
|
@ -81,17 +81,11 @@ let v: string;
|
|||
export const getVersion = () =>
|
||||
new Promise<string>(async (resolve) => {
|
||||
if (v) return resolve(v);
|
||||
const registry = await getRegistry();
|
||||
get(`${registry}/astro/latest`, (res) => {
|
||||
let body = '';
|
||||
res.on('data', (chunk) => (body += chunk));
|
||||
res.on('end', () => {
|
||||
const { version } = JSON.parse(body);
|
||||
let registry = await getRegistry();
|
||||
const { version } = await fetch(`${registry}/astro/latest`, { redirect: 'follow' }).then(res => res.json());
|
||||
v = version;
|
||||
resolve(version);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
export const log = (message: string) => stdout.write(message + '\n');
|
||||
export const banner = async (version: string) =>
|
||||
|
|
|
@ -3574,6 +3574,9 @@ importers:
|
|||
mocha:
|
||||
specifier: ^9.2.2
|
||||
version: 9.2.2
|
||||
node-fetch-native:
|
||||
specifier: ^1.2.0
|
||||
version: 1.2.0
|
||||
which-pm-runs:
|
||||
specifier: ^1.1.0
|
||||
version: 1.1.0
|
||||
|
@ -11921,7 +11924,7 @@ packages:
|
|||
defu: 6.1.2
|
||||
https-proxy-agent: 5.0.1
|
||||
mri: 1.2.0
|
||||
node-fetch-native: 1.1.1
|
||||
node-fetch-native: 1.2.0
|
||||
pathe: 1.1.0
|
||||
tar: 6.1.14
|
||||
transitivePeerDependencies:
|
||||
|
@ -14162,8 +14165,8 @@ packages:
|
|||
engines: {node: '>=10.5.0'}
|
||||
dev: false
|
||||
|
||||
/node-fetch-native@1.1.1:
|
||||
resolution: {integrity: sha512-9VvspTSUp2Sxbl+9vbZTlFGq9lHwE8GDVVekxx6YsNd1YH59sb3Ba8v3Y3cD8PkLNcileGGcA21PFjVl0jzDaw==}
|
||||
/node-fetch-native@1.2.0:
|
||||
resolution: {integrity: sha512-5IAMBTl9p6PaAjYCnMv5FmqIF6GcZnawAVnzaCG0rX2aYZJ4CxEkZNtVPuTRug7fL7wyM5BQYTlAzcyMPi6oTQ==}
|
||||
dev: false
|
||||
|
||||
/node-fetch@2.6.11:
|
||||
|
|
Loading…
Reference in a new issue