Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: scan getStaticPaths only in .astro files #7876

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sour-pants-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Check for `getStaticPaths` only if the file has the `.astro` extension.
8 changes: 6 additions & 2 deletions packages/astro/src/vite-plugin-scanner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
Loading