[ci] format

This commit is contained in:
matthewp 2022-09-09 16:00:38 +00:00 committed by fredkbot
parent 255636cc7b
commit 64f11c4cee
4 changed files with 29 additions and 25 deletions

View file

@ -1,17 +1,19 @@
/* eslint-disable no-console */ /* eslint-disable no-console */
import type { Arguments as Flags } from 'yargs-parser'
import * as colors from 'kleur/colors'; import * as colors from 'kleur/colors';
import { pathToFileURL } from 'url';
import { normalizePath } from 'vite';
import type { Arguments as Flags } from 'yargs-parser';
import yargs from 'yargs-parser'; import yargs from 'yargs-parser';
import { z } from 'zod'; import { z } from 'zod';
import { normalizePath } from 'vite';
import add from '../core/add/index.js'; import add from '../core/add/index.js';
import build from '../core/build/index.js'; import build from '../core/build/index.js';
import { openConfig, resolveConfigPath, resolveFlags, resolveRoot } from '../core/config.js'; import { openConfig, resolveConfigPath, resolveFlags, resolveRoot } from '../core/config.js';
import devServer from '../core/dev/index.js'; import devServer from '../core/dev/index.js';
import { collectErrorMetadata } from '../core/errors.js'; import { collectErrorMetadata } from '../core/errors.js';
import { debug, error, info, LogOptions, warn } from '../core/logger/core.js'; import { debug, error, info, LogOptions } from '../core/logger/core.js';
import { enableVerboseLogging, nodeLogDestination } from '../core/logger/node.js'; import { enableVerboseLogging, nodeLogDestination } from '../core/logger/node.js';
import { formatConfigErrorMessage, formatErrorMessage, printHelp } from '../core/messages.js'; import { formatConfigErrorMessage, formatErrorMessage, printHelp } from '../core/messages.js';
import { appendForwardSlash } from '../core/path.js';
import preview from '../core/preview/index.js'; import preview from '../core/preview/index.js';
import { ASTRO_VERSION, createSafeError } from '../core/util.js'; import { ASTRO_VERSION, createSafeError } from '../core/util.js';
import * as event from '../events/index.js'; import * as event from '../events/index.js';
@ -19,8 +21,6 @@ import { eventConfigError, eventError, telemetry } from '../events/index.js';
import { check } from './check/index.js'; import { check } from './check/index.js';
import { openInBrowser } from './open.js'; import { openInBrowser } from './open.js';
import * as telemetryHandler from './telemetry.js'; import * as telemetryHandler from './telemetry.js';
import { appendForwardSlash } from '../core/path.js';
import { pathToFileURL } from 'url'
type Arguments = yargs.Arguments; type Arguments = yargs.Arguments;
type CLICommand = type CLICommand =
@ -84,13 +84,18 @@ function resolveCommand(flags: Arguments): CLICommand {
return 'help'; return 'help';
} }
async function handleConfigError(e: any, { cwd, flags, logging }: { cwd?: string; flags?: Flags, logging: LogOptions }) { async function handleConfigError(
e: any,
{ cwd, flags, logging }: { cwd?: string; flags?: Flags; logging: LogOptions }
) {
const path = await resolveConfigPath({ cwd, flags }); const path = await resolveConfigPath({ cwd, flags });
if (e instanceof Error) { if (e instanceof Error) {
if (path) { if (path) {
error(logging, 'astro', `Unable to load ${colors.bold(path)}\n`); error(logging, 'astro', `Unable to load ${colors.bold(path)}\n`);
} }
console.error(formatErrorMessage(collectErrorMetadata(e, path ? pathToFileURL(path) : undefined)) + '\n') console.error(
formatErrorMessage(collectErrorMetadata(e, path ? pathToFileURL(path) : undefined)) + '\n'
);
} }
} }
@ -145,16 +150,16 @@ async function runCommand(cmd: string, flags: yargs.Arguments) {
} }
} }
let { astroConfig, userConfig } = await openConfig({ let { astroConfig, userConfig } = await openConfig({
cwd: root, cwd: root,
flags, flags,
cmd, cmd,
logging, logging,
}).catch(async (e) => { }).catch(async (e) => {
await handleConfigError(e, { cwd: root, flags, logging }) await handleConfigError(e, { cwd: root, flags, logging });
return {} as any; return {} as any;
}); });
if (!astroConfig) return; if (!astroConfig) return;
telemetry.record(event.eventCliSession(cmd, userConfig, flags)); telemetry.record(event.eventCliSession(cmd, userConfig, flags));
// Common CLI Commands: // Common CLI Commands:
@ -184,7 +189,7 @@ async function runCommand(cmd: string, flags: yargs.Arguments) {
).test(normalizePath(changedFile))) ).test(normalizePath(changedFile)))
) { ) {
restartInFlight = true; restartInFlight = true;
console.clear() console.clear();
try { try {
const newConfig = await openConfig({ const newConfig = await openConfig({
cwd: root, cwd: root,
@ -198,11 +203,10 @@ async function runCommand(cmd: string, flags: yargs.Arguments) {
await stop(); await stop();
await startDevServer({ isRestart: true }); await startDevServer({ isRestart: true });
} catch (e) { } catch (e) {
await handleConfigError(e, { cwd: root, flags, logging }) await handleConfigError(e, { cwd: root, flags, logging });
await stop(); await stop();
info(logging, 'astro', 'Continuing with previous valid configuration\n'); info(logging, 'astro', 'Continuing with previous valid configuration\n');
await startDevServer({ isRestart: true }); await startDevServer({ isRestart: true });
} }
} }
}; };

View file

@ -1,9 +1,9 @@
import type { RehypePlugin, RemarkPlugin, RemarkRehype } from '@astrojs/markdown-remark'; import type { RehypePlugin, RemarkPlugin, RemarkRehype } from '@astrojs/markdown-remark';
import fs from 'fs';
import type * as Postcss from 'postcss'; import type * as Postcss from 'postcss';
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki'; import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
import type { Arguments as Flags } from 'yargs-parser'; import type { Arguments as Flags } from 'yargs-parser';
import type { AstroConfig, AstroUserConfig, CLIFlags, ViteUserConfig } from '../@types/astro'; import type { AstroConfig, AstroUserConfig, CLIFlags, ViteUserConfig } from '../@types/astro';
import fs from 'fs';
import load, { ProloadError, resolve } from '@proload/core'; import load, { ProloadError, resolve } from '@proload/core';
import loadTypeScript from '@proload/plugin-tsm'; import loadTypeScript from '@proload/plugin-tsm';
@ -437,7 +437,7 @@ export async function resolveConfigPath(
if (e instanceof ProloadError && flags.config) { if (e instanceof ProloadError && flags.config) {
throw new Error(`Unable to resolve --config "${flags.config}"! Does the file exist?`); throw new Error(`Unable to resolve --config "${flags.config}"! Does the file exist?`);
} }
throw e throw e;
} }
} }

View file

@ -68,7 +68,7 @@ export default async function dev(config: AstroConfig, options: DevOptions): Pro
devServerAddressInfo, devServerAddressInfo,
site, site,
https: !!viteConfig.server?.https, https: !!viteConfig.server?.https,
isRestart isRestart,
}) })
); );

View file

@ -58,14 +58,14 @@ export function devStart({
config, config,
https, https,
site, site,
isRestart = false isRestart = false,
}: { }: {
startupTime: number; startupTime: number;
devServerAddressInfo: AddressInfo; devServerAddressInfo: AddressInfo;
config: AstroConfig; config: AstroConfig;
https: boolean; https: boolean;
site: URL | undefined; site: URL | undefined;
isRestart?: boolean isRestart?: boolean;
}): string { }): string {
// PACKAGE_VERSION is injected at build-time // PACKAGE_VERSION is injected at build-time
const version = process.env.PACKAGE_VERSION ?? '0.0.0'; const version = process.env.PACKAGE_VERSION ?? '0.0.0';