summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Emanuele Stoppa <my.burning@gmail.com> 2023-07-31 17:24:13 +0100
committerGravatar GitHub <noreply@github.com> 2023-07-31 17:24:13 +0100
commit89d015db6ce4d15b5b1140f0eb6bfbef187d6ad7 (patch)
tree9e6c5b9cba64d8bd4a37498da17f8c02914d3f7c
parentd495235d0f154bb51b2b26a4faf4ee3b37fa09ef (diff)
downloadastro-89d015db6ce4d15b5b1140f0eb6bfbef187d6ad7.tar.gz
astro-89d015db6ce4d15b5b1140f0eb6bfbef187d6ad7.tar.zst
astro-89d015db6ce4d15b5b1140f0eb6bfbef187d6ad7.zip
fix: scan `getStaticPaths` only in `.astro` files (#7876)
-rw-r--r--.changeset/sour-pants-agree.md5
-rw-r--r--packages/astro/src/vite-plugin-scanner/index.ts8
2 files changed, 11 insertions, 2 deletions
diff --git a/.changeset/sour-pants-agree.md b/.changeset/sour-pants-agree.md
new file mode 100644
index 000000000..d6482595e
--- /dev/null
+++ b/.changeset/sour-pants-agree.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Check for `getStaticPaths` only if the file has the `.astro` extension.
diff --git a/packages/astro/src/vite-plugin-scanner/index.ts b/packages/astro/src/vite-plugin-scanner/index.ts
index a12357528..643b445fa 100644
--- a/packages/astro/src/vite-plugin-scanner/index.ts
+++ b/packages/astro/src/vite-plugin-scanner/index.ts
@@ -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(