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

fix: scan getStaticPaths only in .astro files (#7876)

This commit is contained in:
Emanuele Stoppa 2023-07-31 17:24:13 +01:00 committed by GitHub
parent d495235d0f
commit 89d015db6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Check for `getStaticPaths` only if the file has the `.astro` extension.

View file

@ -8,12 +8,15 @@ import { warn } from '../core/logger/core.js';
import { isEndpoint, isPage, rootRelativePath } from '../core/util.js';
import { getPrerenderDefault, isServerLikeOutput } from '../prerender/utils.js';
import { scan } from './scan.js';
import { extname } from 'node:path';
export interface AstroPluginScannerOptions {
settings: AstroSettings;
logging: LogOptions;
}
const KNOWN_FILE_EXTENSIONS = ['.astro', '.js', '.ts'];
export default function astroScannerPlugin({
settings,
logging,
@ -43,12 +46,13 @@ export default function astroScannerPlugin({
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')
code.includes('getStaticPaths') &&
// this should only be valid for `.astro`, `.js` and `.ts` files
KNOWN_FILE_EXTENSIONS.includes(extname(filename))
) {
const reason = ` because \`output: "${settings.config.output}"\` is set`;
warn(