summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar natemoo-re <natemoo-re@users.noreply.github.com> 2023-07-19 14:36:35 +0000
committerGravatar astrobot-houston <fred+astrobot@astro.build> 2023-07-19 14:36:35 +0000
commiteafe996b60b0cec8b9107a9afbed67f47b681835 (patch)
tree5c14be5b2b2427e2dd2e5ea46ae8de71deac0a75
parentd088351f54d2518e2bb539d7bbf8691427ff8a7a (diff)
downloadastro-eafe996b60b0cec8b9107a9afbed67f47b681835.tar.gz
astro-eafe996b60b0cec8b9107a9afbed67f47b681835.tar.zst
astro-eafe996b60b0cec8b9107a9afbed67f47b681835.zip
[ci] format
-rw-r--r--packages/astro/src/vite-plugin-scanner/index.ts25
-rw-r--r--packages/astro/src/vite-plugin-scanner/scan.ts14
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 439a56d46..a12357528 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 69a0945d6..3eb834ea2 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<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 {