0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

[ci] format

This commit is contained in:
natemoo-re 2023-07-19 14:36:35 +00:00 committed by astrobot-houston
parent d088351f54
commit eafe996b60
2 changed files with 30 additions and 9 deletions

View file

@ -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) ?? {};

View file

@ -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<PageOptions> {
export async function scan(
code: string,
id: string,
settings?: AstroSettings
): Promise<PageOptions> {
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 {