CLI: add prerelease warning (#2758)

* feat(cli): add prerelease and outdated warnings

* refactor: cleanup getLatestVersion code

* refactor: simplify isPrerelease logic

* chore: add changeset

* fix: do not require devStart for preview

* refactor: extract prerelase/outdated into own templates

* feat: remove upgrade warning

* feat: make prerelease less scary

* chore: update prerelease wording

* chore: update feedback copy
This commit is contained in:
Nate Moore 2022-03-10 17:25:06 -06:00 committed by GitHub
parent da826a6ba4
commit 499fb6a335
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Add CLI warnings when running a prerelease or outdated version of Astro

View file

@ -3,7 +3,7 @@ import type { AddressInfo } from 'net';
import { performance } from 'perf_hooks';
import type { AstroConfig } from '../../@types/astro';
import { createVite } from '../create-vite.js';
import { defaultLogOptions, info, LogOptions } from '../logger.js';
import { defaultLogOptions, info, warn, LogOptions } from '../logger.js';
import * as vite from 'vite';
import * as msg from '../messages.js';
import { getLocalAddress } from './util.js';
@ -37,6 +37,7 @@ export default async function dev(config: AstroConfig, options: DevOptions = { l
const viteConfig = await createVite(viteUserConfig, { astroConfig: config, logging: options.logging, mode: 'dev' });
const viteServer = await vite.createServer(viteConfig);
await viteServer.listen(config.devOptions.port);
const address = viteServer.httpServer!.address() as AddressInfo;
const localAddress = getLocalAddress(address.address, config.devOptions.hostname);
// Log to console
@ -47,6 +48,15 @@ export default async function dev(config: AstroConfig, options: DevOptions = { l
msg.devStart({ startupTime: performance.now() - devStart, port: address.port, localAddress, networkAddress: address.address, site, https: !!viteUserConfig.server?.https })
);
const currentVersion = process.env.PACKAGE_VERSION ?? '0.0.0';
if (currentVersion.includes('-')) {
warn(
options.logging,
null,
msg.prerelease({ currentVersion })
);
}
return {
address,
stop: () => viteServer.close(),

View file

@ -4,7 +4,7 @@
import type { AddressInfo } from 'net';
import stripAnsi from 'strip-ansi';
import { bold, dim, red, green, magenta, yellow, cyan, bgGreen, black } from 'kleur/colors';
import { bold, dim, red, green, underline, yellow, bgYellow, cyan, bgGreen, black } from 'kleur/colors';
import { pad, emoji } from './dev/util.js';
const PREFIX_PADDING = 6;
@ -47,6 +47,7 @@ export function devStart({
const version = process.env.PACKAGE_VERSION ?? '0.0.0';
const rootPath = site ? site.pathname : '/';
const toDisplayUrl = (hostname: string) => `${https ? 'https' : 'http'}://${hostname}:${port}${rootPath}`;
const messages = [
`${emoji('🚀 ', '')}${bgGreen(black(` astro `))} ${green(`v${version}`)} ${dim(`started in ${Math.round(startupTime)}ms`)}`,
'',
@ -57,6 +58,14 @@ export function devStart({
return messages.map((msg) => ` ${msg}`).join('\n');
}
export function prerelease({ currentVersion }: { currentVersion: string }) {
const tag = currentVersion.split('-').slice(1).join('-').replace(/\..*$/, '');
const badge = bgYellow(black(` ${tag} `));
const headline = yellow(`▶ This is a ${badge} prerelease build`);
const warning = ` Feedback? ${underline('https://astro.build/issues')}`
return [headline, warning, ''].map((msg) => ` ${msg}`).join('\n');
}
/** Display port in use */
export function portInUse({ port }: { port: number }): string {
return `Port ${port} in use. Trying a new one…`;