From eafe996b60b0cec8b9107a9afbed67f47b681835 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Wed, 19 Jul 2023 14:36:35 +0000 Subject: [PATCH] [ci] format --- .../astro/src/vite-plugin-scanner/index.ts | 25 ++++++++++++++----- .../astro/src/vite-plugin-scanner/scan.ts | 14 ++++++++--- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/packages/astro/src/vite-plugin-scanner/index.ts b/packages/astro/src/vite-plugin-scanner/index.ts index 439a56d464..a12357528b 100644 --- a/packages/astro/src/vite-plugin-scanner/index.ts +++ b/packages/astro/src/vite-plugin-scanner/index.ts @@ -2,8 +2,8 @@ import type { Plugin as VitePlugin } from 'vite'; import type { AstroSettings } from '../@types/astro.js'; import { type LogOptions } from '../core/logger/core.js'; -import { normalizePath } from 'vite'; import { bold } from 'kleur/colors'; +import { normalizePath } from 'vite'; import { warn } from '../core/logger/core.js'; import { isEndpoint, isPage, rootRelativePath } from '../core/util.js'; import { getPrerenderDefault, isServerLikeOutput } from '../prerender/utils.js'; @@ -14,7 +14,10 @@ export interface AstroPluginScannerOptions { logging: LogOptions; } -export default function astroScannerPlugin({ settings, logging }: AstroPluginScannerOptions): VitePlugin { +export default function astroScannerPlugin({ + settings, + logging, +}: AstroPluginScannerOptions): VitePlugin { return { name: 'astro:scanner', enforce: 'post', @@ -40,11 +43,21 @@ export default function astroScannerPlugin({ settings, logging }: AstroPluginSca if (typeof pageOptions.prerender === 'undefined') { pageOptions.prerender = defaultPrerender; } - + // `getStaticPaths` warning is just a string check, should be good enough for most cases - if (!pageOptions.prerender && isServerLikeOutput(settings.config) && code.includes('getStaticPaths')) { - const reason = ` because \`output: "${settings.config.output}"\` is set` - warn(logging, "getStaticPaths", `The getStaticPaths() statement in ${bold(rootRelativePath(settings.config.root, fileURL, true))} has been ignored${reason}.\n\nAdd \`export const prerender = true;\` to prerender this page.`); + if ( + !pageOptions.prerender && + isServerLikeOutput(settings.config) && + code.includes('getStaticPaths') + ) { + const reason = ` because \`output: "${settings.config.output}"\` is set`; + warn( + logging, + 'getStaticPaths', + `The getStaticPaths() statement in ${bold( + rootRelativePath(settings.config.root, fileURL, true) + )} has been ignored${reason}.\n\nAdd \`export const prerender = true;\` to prerender this page.` + ); } const { meta = {} } = this.getModuleInfo(id) ?? {}; diff --git a/packages/astro/src/vite-plugin-scanner/scan.ts b/packages/astro/src/vite-plugin-scanner/scan.ts index 69a0945d6b..3eb834ea24 100644 --- a/packages/astro/src/vite-plugin-scanner/scan.ts +++ b/packages/astro/src/vite-plugin-scanner/scan.ts @@ -1,5 +1,5 @@ -import type { PageOptions } from '../vite-plugin-astro/types.js'; import type { AstroSettings } from '../@types/astro.js'; +import type { PageOptions } from '../vite-plugin-astro/types.js'; import * as eslexer from 'es-module-lexer'; import { AstroError, AstroErrorData } from '../core/errors/index.js'; @@ -36,7 +36,11 @@ function isFalsy(value: string) { let didInit = false; -export async function scan(code: string, id: string, settings?: AstroSettings): Promise { +export async function scan( + code: string, + id: string, + settings?: AstroSettings +): Promise { if (!includesExport(code)) return {}; if (!didInit) { await eslexer.init; @@ -65,7 +69,11 @@ export async function scan(code: string, id: string, settings?: AstroSettings): if (prefix !== 'const' || !(isTruthy(suffix) || isFalsy(suffix))) { throw new AstroError({ ...AstroErrorData.InvalidPrerenderExport, - message: AstroErrorData.InvalidPrerenderExport.message(prefix, suffix, settings?.config.output === 'hybrid' ?? false), + message: AstroErrorData.InvalidPrerenderExport.message( + prefix, + suffix, + settings?.config.output === 'hybrid' ?? false + ), location: { file: id }, }); } else {