Skip to content

Commit 89d015d

Browse files
authored
fix: scan getStaticPaths only in .astro files (#7876)
1 parent d495235 commit 89d015d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.changeset/sour-pants-agree.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Check for `getStaticPaths` only if the file has the `.astro` extension.

packages/astro/src/vite-plugin-scanner/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ import { warn } from '../core/logger/core.js';
88
import { isEndpoint, isPage, rootRelativePath } from '../core/util.js';
99
import { getPrerenderDefault, isServerLikeOutput } from '../prerender/utils.js';
1010
import { scan } from './scan.js';
11+
import { extname } from 'node:path';
1112

1213
export interface AstroPluginScannerOptions {
1314
settings: AstroSettings;
1415
logging: LogOptions;
1516
}
1617

18+
const KNOWN_FILE_EXTENSIONS = ['.astro', '.js', '.ts'];
19+
1720
export default function astroScannerPlugin({
1821
settings,
1922
logging,
@@ -43,12 +46,13 @@ export default function astroScannerPlugin({
4346
if (typeof pageOptions.prerender === 'undefined') {
4447
pageOptions.prerender = defaultPrerender;
4548
}
46-
4749
// `getStaticPaths` warning is just a string check, should be good enough for most cases
4850
if (
4951
!pageOptions.prerender &&
5052
isServerLikeOutput(settings.config) &&
51-
code.includes('getStaticPaths')
53+
code.includes('getStaticPaths') &&
54+
// this should only be valid for `.astro`, `.js` and `.ts` files
55+
KNOWN_FILE_EXTENSIONS.includes(extname(filename))
5256
) {
5357
const reason = ` because \`output: "${settings.config.output}"\` is set`;
5458
warn(

0 commit comments

Comments
 (0)