diff --git a/.changeset/tame-hats-give.md b/.changeset/tame-hats-give.md new file mode 100644 index 000000000..c4158a46b --- /dev/null +++ b/.changeset/tame-hats-give.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix crash with unexpected file types in pages directory diff --git a/packages/astro/src/core/ssr/routing.ts b/packages/astro/src/core/ssr/routing.ts index 1eedfb67f..d3d20c2d1 100644 --- a/packages/astro/src/core/ssr/routing.ts +++ b/packages/astro/src/core/ssr/routing.ts @@ -86,6 +86,7 @@ interface Item { export function createRouteManifest({ config, cwd }: { config: AstroConfig; cwd?: string }, logging: LogOptions): ManifestData { const components: string[] = []; const routes: RouteData[] = []; + const validExtensions: Set = new Set(['.astro', '.md']); function walk(dir: string, parentSegments: Part[][], parentParams: string[]) { let items: Item[] = []; @@ -104,7 +105,7 @@ export function createRouteManifest({ config, cwd }: { config: AstroConfig; cwd? return; } // filter out "foo.astro_tmp" files, etc - if (!isDir && !/^(\.[a-z0-9]+)+$/i.test(ext)) { + if (!isDir && !validExtensions.has(ext)) { return; } const segment = isDir ? basename : name; diff --git a/packages/astro/test/fixtures/route-manifest/invalid-extension/about.astro b/packages/astro/test/fixtures/route-manifest/invalid-extension/about.astro new file mode 100644 index 000000000..e69de29bb diff --git a/packages/astro/test/fixtures/route-manifest/invalid-extension/image.svg b/packages/astro/test/fixtures/route-manifest/invalid-extension/image.svg new file mode 100644 index 000000000..e69de29bb diff --git a/packages/astro/test/fixtures/route-manifest/invalid-extension/index.astro b/packages/astro/test/fixtures/route-manifest/invalid-extension/index.astro new file mode 100644 index 000000000..e69de29bb diff --git a/packages/astro/test/fixtures/route-manifest/invalid-extension/styles.css b/packages/astro/test/fixtures/route-manifest/invalid-extension/styles.css new file mode 100644 index 000000000..e69de29bb diff --git a/packages/astro/test/route-manifest.test.js b/packages/astro/test/route-manifest.test.js index 1f32ee6af..8ae58c1d6 100644 --- a/packages/astro/test/route-manifest.test.js +++ b/packages/astro/test/route-manifest.test.js @@ -184,6 +184,27 @@ describe('route manifest', () => { ]); }); + it('ignores invalid route extensions', () => { + const { routes } = create('invalid-extension', 'always'); + expect(cleanRoutes(routes)).to.deep.equal([ + { + type: 'page', + pattern: /^\/$/, + params: [], + component: 'invalid-extension/index.astro', + pathname: '/', + }, + + { + type: 'page', + pattern: /^\/about\/$/, + params: [], + component: 'invalid-extension/about.astro', + pathname: '/about', + }, + ]); + }); + it('allows multiple slugs', () => { const { routes } = create('multiple-slugs', 'always');