Skip to content

Commit

Permalink
CLI: add prerelease warning (#2758)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
natemoo-re committed Mar 10, 2022
1 parent da826a6 commit 499fb6a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-pots-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Add CLI warnings when running a prerelease or outdated version of Astro
12 changes: 11 additions & 1 deletion packages/astro/src/core/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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(),
Expand Down
11 changes: 10 additions & 1 deletion packages/astro/src/core/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'}:https://${hostname}:${port}${rootPath}`;

const messages = [
`${emoji('🚀 ', '')}${bgGreen(black(` astro `))} ${green(`v${version}`)} ${dim(`started in ${Math.round(startupTime)}ms`)}`,
'',
Expand All @@ -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…`;
Expand Down

0 comments on commit 499fb6a

Please sign in to comment.