mirror of
https://github.com/withastro/astro.git
synced 2025-02-17 22:44:24 -05:00
Remove create-astro
version cache (#9817)
* fix(create-astro): remove version cache * fix(create-astro): select typescript first * chore(create-astro): remove unused import
This commit is contained in:
parent
d777adc5ca
commit
e5276f097b
3 changed files with 9 additions and 10 deletions
|
@ -5,7 +5,6 @@ import { readFile, rm, writeFile } from 'node:fs/promises';
|
|||
import path from 'node:path';
|
||||
import stripJsonComments from 'strip-json-comments';
|
||||
import { error, getVersion, info, title, typescriptByDefault } from '../messages.js';
|
||||
import { shell } from '../shell.js';
|
||||
|
||||
type PickedTypeScriptContext = Pick<
|
||||
Context,
|
||||
|
|
|
@ -36,8 +36,8 @@ export async function main() {
|
|||
intro,
|
||||
projectName,
|
||||
template,
|
||||
dependencies,
|
||||
typescript,
|
||||
dependencies,
|
||||
|
||||
// Steps which write to files need to go above git
|
||||
git,
|
||||
|
|
|
@ -9,13 +9,16 @@ 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;
|
||||
async function getRegistry(packageManager: string): Promise<string> {
|
||||
if (_registry) return _registry;
|
||||
try {
|
||||
const { stdout } = await shell(packageManager, ['config', 'get', 'registry']);
|
||||
return stdout?.trim()?.replace(/\/$/, '') || 'https://registry.npmjs.org';
|
||||
_registry = stdout?.trim()?.replace(/\/$/, '') || 'https://registry.npmjs.org';
|
||||
} catch (e) {
|
||||
return 'https://registry.npmjs.org';
|
||||
_registry = 'https://registry.npmjs.org';
|
||||
}
|
||||
return _registry;
|
||||
}
|
||||
|
||||
let stdout = process.stdout;
|
||||
|
@ -54,19 +57,16 @@ export const getName = () =>
|
|||
});
|
||||
});
|
||||
|
||||
let v: string;
|
||||
export const getVersion = (packageManager: string, packageName: string) =>
|
||||
export const getVersion = (packageManager: string, packageName: string, fallback = '') =>
|
||||
new Promise<string>(async (resolve) => {
|
||||
if (v) return resolve(v);
|
||||
let registry = await getRegistry(packageManager);
|
||||
const { version } = await fetch(`${registry}/${packageName}/latest`, {
|
||||
redirect: 'follow',
|
||||
}).then(
|
||||
(res) => res.json(),
|
||||
() => ({ version: '' })
|
||||
() => ({ version: fallback })
|
||||
);
|
||||
v = version;
|
||||
resolve(version);
|
||||
return resolve(version);
|
||||
});
|
||||
|
||||
export const log = (message: string) => stdout.write(message + '\n');
|
||||
|
|
Loading…
Add table
Reference in a new issue