From 64aa903f04cd3fe1f531f577bf8900bf098006dc Mon Sep 17 00:00:00 2001 From: matthewp Date: Fri, 16 Sep 2022 15:31:14 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/@types/astro.ts | 2 +- packages/astro/src/cli/index.ts | 11 +++++++++-- packages/astro/src/core/build/index.ts | 6 +++++- packages/astro/src/core/build/static-build.ts | 3 +-- packages/astro/src/core/build/vite-plugin-css.ts | 1 - packages/astro/src/core/build/vite-plugin-ssr.ts | 6 +++++- packages/astro/src/core/config/config.ts | 5 ++--- packages/astro/src/core/config/index.ts | 16 +++------------- packages/astro/src/core/config/settings.ts | 11 ++--------- packages/astro/src/core/dev/index.ts | 15 ++++++++++++--- packages/astro/src/core/render/dev/index.ts | 6 ++++-- packages/astro/src/core/render/dev/scripts.ts | 9 ++------- .../astro/src/core/routing/manifest/create.ts | 6 +----- packages/astro/src/integrations/index.ts | 4 ++-- packages/astro/src/vite-plugin-env/index.ts | 4 +--- packages/astro/src/vite-plugin-jsx/index.ts | 2 +- .../astro/src/vite-plugin-scripts/page-ssr.ts | 6 +++++- packages/astro/test/test-utils.js | 2 +- .../test/units/config/config-server.test.js | 14 +++++++------- 19 files changed, 64 insertions(+), 65 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 7589534c7..835be849a 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -882,7 +882,7 @@ export interface AstroSettings { renderers: AstroRenderer[]; scripts: { stage: InjectedScriptStage; - content: string + content: string; }[]; tsConfig: TsConfigJson | undefined; tsConfigPath: string | undefined; diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 064a2b5b3..8263cc19b 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -7,7 +7,14 @@ import yargs from 'yargs-parser'; import { z } from 'zod'; import add from '../core/add/index.js'; import build from '../core/build/index.js'; -import { openConfig, resolveConfigPath, resolveFlags, resolveRoot, createSettings, loadTSConfig } from '../core/config/index.js'; +import { + createSettings, + loadTSConfig, + openConfig, + resolveConfigPath, + resolveFlags, + resolveRoot, +} from '../core/config/index.js'; import devServer from '../core/dev/index.js'; import { collectErrorMetadata } from '../core/errors.js'; import { debug, error, info, LogOptions } from '../core/logger/core.js'; @@ -210,7 +217,7 @@ async function runCommand(cmd: string, flags: yargs.Arguments) { settings = createSettings({ config: astroConfig, tsConfig: tsconfig?.config, - tsConfigPath: tsconfig?.path + tsConfigPath: tsconfig?.path, }); await stop(); await startDevServer({ isRestart: true }); diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 7a3b9760f..33e7d1626 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -62,7 +62,11 @@ class AstroBuilder { debug('build', 'Initial setup...'); const { logging } = this; this.timer.init = performance.now(); - this.settings = await runHookConfigSetup({ settings: this.settings, command: 'build', logging }); + this.settings = await runHookConfigSetup({ + settings: this.settings, + command: 'build', + logging, + }); this.manifest = createRouteManifest({ settings: this.settings }, this.logging); const viteConfig = await createVite( diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 9afa3ed32..dfaad12bd 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -151,8 +151,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp }), ...(viteConfig.plugins || []), // SSR needs to be last - settings.config.output === 'server' && - vitePluginSSR(internals, settings.adapter!), + settings.config.output === 'server' && vitePluginSSR(internals, settings.adapter!), vitePluginAnalyzer(internals), ], publicDir: ssr ? false : viteConfig.publicDir, diff --git a/packages/astro/src/core/build/vite-plugin-css.ts b/packages/astro/src/core/build/vite-plugin-css.ts index 1ef7202d5..5dd680c04 100644 --- a/packages/astro/src/core/build/vite-plugin-css.ts +++ b/packages/astro/src/core/build/vite-plugin-css.ts @@ -1,5 +1,4 @@ import type { GetModuleInfo, OutputChunk } from 'rollup'; -import type { AstroConfig } from '../../@types/astro'; import type { BuildInternals } from './internal'; import type { PageBuildData, StaticBuildOptions } from './types'; diff --git a/packages/astro/src/core/build/vite-plugin-ssr.ts b/packages/astro/src/core/build/vite-plugin-ssr.ts index e2e6ff326..3e7fa7b62 100644 --- a/packages/astro/src/core/build/vite-plugin-ssr.ts +++ b/packages/astro/src/core/build/vite-plugin-ssr.ts @@ -103,7 +103,11 @@ export async function injectManifest(buildOpts: StaticBuildOptions, internals: B const staticFiles = internals.staticFiles; const manifest = buildManifest(buildOpts, internals, Array.from(staticFiles)); - await runHookBuildSsr({ config: buildOpts.settings.config, manifest, logging: buildOpts.logging }); + await runHookBuildSsr({ + config: buildOpts.settings.config, + manifest, + logging: buildOpts.logging, + }); const chunk = internals.ssrEntryChunk; const code = chunk.code; diff --git a/packages/astro/src/core/config/config.ts b/packages/astro/src/core/config/config.ts index 2c60257f4..a5c8faa14 100644 --- a/packages/astro/src/core/config/config.ts +++ b/packages/astro/src/core/config/config.ts @@ -1,9 +1,9 @@ import type { Arguments as Flags } from 'yargs-parser'; import type { AstroConfig, AstroUserConfig, CLIFlags } from '../../@types/astro'; -import fs from 'fs'; import load, { ProloadError, resolve } from '@proload/core'; import loadTypeScript from '@proload/plugin-tsm'; +import fs from 'fs'; import * as colors from 'kleur/colors'; import path from 'path'; import { fileURLToPath, pathToFileURL } from 'url'; @@ -27,7 +27,6 @@ export const LEGACY_ASTRO_CONFIG_KEYS = new Set([ 'devOptions', ]); - /** Turn raw config values into normalized values */ export async function validateConfig( userConfig: any, @@ -85,7 +84,7 @@ export async function validateConfig( /* eslint-enable no-console */ const AstroConfigRelativeSchema = createRelativeSchema(cmd, fileProtocolRoot); - + // First-Pass Validation const result = await AstroConfigRelativeSchema.parseAsync(userConfig); diff --git a/packages/astro/src/core/config/index.ts b/packages/astro/src/core/config/index.ts index b22083c4a..4984b3b91 100644 --- a/packages/astro/src/core/config/index.ts +++ b/packages/astro/src/core/config/index.ts @@ -1,8 +1,3 @@ - -export type { - AstroConfigSchema -} from './schema'; - export { openConfig, resolveConfigPath, @@ -10,11 +5,6 @@ export { resolveRoot, validateConfig, } from './config.js'; - -export { - createSettings -} from './settings.js'; - -export { - loadTSConfig -} from './tsconfig.js'; +export type { AstroConfigSchema } from './schema'; +export { createSettings } from './settings.js'; +export { loadTSConfig } from './tsconfig.js'; diff --git a/packages/astro/src/core/config/settings.ts b/packages/astro/src/core/config/settings.ts index 57af38618..a69697726 100644 --- a/packages/astro/src/core/config/settings.ts +++ b/packages/astro/src/core/config/settings.ts @@ -1,8 +1,5 @@ -import type { - AstroConfig, - AstroSettings, -} from '../../@types/astro'; import type { TsConfigJson } from 'tsconfig-resolver'; +import type { AstroConfig, AstroSettings } from '../../@types/astro'; import jsxRenderer from '../../jsx/renderer.js'; @@ -12,11 +9,7 @@ export interface CreateSettings { tsConfigPath?: string; } -export function createSettings({ - config, - tsConfig, - tsConfigPath, -}: CreateSettings): AstroSettings { +export function createSettings({ config, tsConfig, tsConfigPath }: CreateSettings): AstroSettings { return { config, tsConfig, diff --git a/packages/astro/src/core/dev/index.ts b/packages/astro/src/core/dev/index.ts index 0466d826b..9d4b58580 100644 --- a/packages/astro/src/core/dev/index.ts +++ b/packages/astro/src/core/dev/index.ts @@ -28,7 +28,10 @@ export interface DevServer { } /** `astro dev` */ -export default async function dev(settings: AstroSettings, options: DevOptions): Promise { +export default async function dev( + settings: AstroSettings, + options: DevOptions +): Promise { const devStart = performance.now(); applyPolyfill(); await options.telemetry.record([]); @@ -58,7 +61,9 @@ export default async function dev(settings: AstroSettings, options: DevOptions): await viteServer.listen(port); const devServerAddressInfo = viteServer.httpServer!.address() as AddressInfo; - const site = settings.config.site ? new URL(settings.config.base, settings.config.site) : undefined; + const site = settings.config.site + ? new URL(settings.config.base, settings.config.site) + : undefined; info( options.logging, null, @@ -80,7 +85,11 @@ export default async function dev(settings: AstroSettings, options: DevOptions): warn(options.logging, null, msg.fsStrictWarning()); } - await runHookServerStart({ config: settings.config, address: devServerAddressInfo, logging: options.logging }); + await runHookServerStart({ + config: settings.config, + address: devServerAddressInfo, + logging: options.logging, + }); return { address: devServerAddressInfo, diff --git a/packages/astro/src/core/render/dev/index.ts b/packages/astro/src/core/render/dev/index.ts index 3003d6417..56e556976 100644 --- a/packages/astro/src/core/render/dev/index.ts +++ b/packages/astro/src/core/render/dev/index.ts @@ -1,8 +1,8 @@ import { fileURLToPath } from 'url'; import type { ViteDevServer } from 'vite'; import type { - AstroSettings, AstroRenderer, + AstroSettings, ComponentInstance, RouteData, RuntimeMode, @@ -191,7 +191,9 @@ export async function render( request, route, routeCache, - site: settings.config.site ? new URL(settings.config.base, settings.config.site).toString() : undefined, + site: settings.config.site + ? new URL(settings.config.base, settings.config.site).toString() + : undefined, ssr: settings.config.output === 'server', streaming: true, }); diff --git a/packages/astro/src/core/render/dev/scripts.ts b/packages/astro/src/core/render/dev/scripts.ts index 1297a8a92..fc8967f40 100644 --- a/packages/astro/src/core/render/dev/scripts.ts +++ b/packages/astro/src/core/render/dev/scripts.ts @@ -1,8 +1,6 @@ import type { ModuleInfo } from 'rollup'; -import slash from 'slash'; -import { fileURLToPath } from 'url'; import vite from 'vite'; -import type { AstroConfig, SSRElement } from '../../../@types/astro'; +import type { SSRElement } from '../../../@types/astro'; import type { PluginMetadata as AstroPluginMetadata } from '../../../vite-plugin-astro/types'; import { viteID } from '../../util.js'; import { createModuleScriptElementWithSrc } from '../ssr-element.js'; @@ -27,10 +25,7 @@ export async function getScriptsForURL( return elements; } -function addHoistedScripts( - set: Set, - info: ModuleInfo | null, -) { +function addHoistedScripts(set: Set, info: ModuleInfo | null) { if (!info?.meta?.astro) { return; } diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index f2bcd9b4b..c5b19bf1a 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -196,11 +196,7 @@ export function createRouteManifest( ): ManifestData { const components: string[] = []; const routes: RouteData[] = []; - const validPageExtensions: Set = new Set([ - '.astro', - '.md', - ...settings.pageExtensions, - ]); + const validPageExtensions: Set = new Set(['.astro', '.md', ...settings.pageExtensions]); const validEndpointExtensions: Set = new Set(['.js', '.ts']); function walk(dir: string, parentSegments: RoutePart[][], parentParams: string[]) { diff --git a/packages/astro/src/integrations/index.ts b/packages/astro/src/integrations/index.ts index aec6fa881..99aae5f77 100644 --- a/packages/astro/src/integrations/index.ts +++ b/packages/astro/src/integrations/index.ts @@ -3,8 +3,8 @@ import type { AddressInfo } from 'net'; import type { ViteDevServer } from 'vite'; import { AstroConfig, - AstroSettings, AstroRenderer, + AstroSettings, BuildConfig, HookParameters, RouteData, @@ -47,7 +47,7 @@ export async function runHookConfigSetup({ if (settings.config.adapter) { settings.config.integrations.push(settings.config.adapter); } - + let updatedConfig: AstroConfig = { ...settings.config }; let updatedSettings: AstroSettings = { ...settings, config: updatedConfig }; for (const integration of settings.config.integrations) { diff --git a/packages/astro/src/vite-plugin-env/index.ts b/packages/astro/src/vite-plugin-env/index.ts index 2eeccc886..08332d717 100644 --- a/packages/astro/src/vite-plugin-env/index.ts +++ b/packages/astro/src/vite-plugin-env/index.ts @@ -50,9 +50,7 @@ function getReferencedPrivateKeys(source: string, privateEnv: Record | null; let config: vite.ResolvedConfig; let replacements: Record; diff --git a/packages/astro/src/vite-plugin-jsx/index.ts b/packages/astro/src/vite-plugin-jsx/index.ts index ca0885343..5c84ec512 100644 --- a/packages/astro/src/vite-plugin-jsx/index.ts +++ b/packages/astro/src/vite-plugin-jsx/index.ts @@ -1,7 +1,7 @@ import type { TransformResult } from 'rollup'; import type { TsConfigJson } from 'tsconfig-resolver'; import type { Plugin, ResolvedConfig } from 'vite'; -import type { AstroSettings, AstroRenderer } from '../@types/astro'; +import type { AstroRenderer, AstroSettings } from '../@types/astro'; import type { LogOptions } from '../core/logger/core.js'; import type { PluginMetadata } from '../vite-plugin-astro/types'; diff --git a/packages/astro/src/vite-plugin-scripts/page-ssr.ts b/packages/astro/src/vite-plugin-scripts/page-ssr.ts index 4307b9d42..d5dc819f8 100644 --- a/packages/astro/src/vite-plugin-scripts/page-ssr.ts +++ b/packages/astro/src/vite-plugin-scripts/page-ssr.ts @@ -6,7 +6,11 @@ import ancestor from 'common-ancestor-path'; import MagicString from 'magic-string'; import { isPage } from '../core/util.js'; -export default function astroScriptsPostPlugin({ settings }: { settings: AstroSettings }): VitePlugin { +export default function astroScriptsPostPlugin({ + settings, +}: { + settings: AstroSettings; +}): VitePlugin { function normalizeFilename(filename: string) { if (filename.startsWith('/@fs')) { filename = filename.slice('/@fs'.length); diff --git a/packages/astro/test/test-utils.js b/packages/astro/test/test-utils.js index b53e1acca..c70e6bc1d 100644 --- a/packages/astro/test/test-utils.js +++ b/packages/astro/test/test-utils.js @@ -99,7 +99,7 @@ export async function loadFixture(inlineConfig) { let settings = createSettings({ config, tsConfig: tsconfig?.config, - tsConfigPath: tsconfig?.path + tsConfigPath: tsconfig?.path, }); if (config.integrations.find((integration) => integration.name === '@astrojs/mdx')) { // Enable default JSX integration. It needs to come first, so unshift rather than push! diff --git a/packages/astro/test/units/config/config-server.test.js b/packages/astro/test/units/config/config-server.test.js index cdfe3d35d..881122321 100644 --- a/packages/astro/test/units/config/config-server.test.js +++ b/packages/astro/test/units/config/config-server.test.js @@ -11,7 +11,7 @@ describe('config.server', () => { cwd: flags.root || cwd, flags, cmd: 'dev', - logging + logging, }); } @@ -20,7 +20,7 @@ describe('config.server', () => { const projectRootURL = new URL('../../fixtures/astro-basic/', import.meta.url); const { astroConfig } = await openConfigWithFlags({ root: fileURLToPath(projectRootURL), - host: true + host: true, }); expect(astroConfig.server.host).to.equal(true); @@ -34,7 +34,7 @@ describe('config.server', () => { const configFileURL = 'my-config.mjs'; const { astroConfig } = await openConfigWithFlags({ root: fileURLToPath(projectRootURL), - config: configFileURL + config: configFileURL, }); expect(astroConfig.server.port).to.equal(8080); }); @@ -46,7 +46,7 @@ describe('config.server', () => { const configFileURL = './my-config.mjs'; const { astroConfig } = await openConfigWithFlags({ root: fileURLToPath(projectRootURL), - config: configFileURL + config: configFileURL, }); expect(astroConfig.server.port).to.equal(8080); }); @@ -59,13 +59,13 @@ describe('config.server', () => { try { await openConfigWithFlags({ root: fileURLToPath(projectRootURL), - config: configFileURL + config: configFileURL, }); expect(false).to.equal(true, 'this should not have resolved'); - } catch(err) { + } catch (err) { expect(err.message).to.match(/Unable to resolve/); } }); }); }); -}) +});