From 2319ed9ed381457572539ab0521b9e58e78f5fdc Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 21 Jul 2018 10:38:53 -0400 Subject: [PATCH] dont create fallback components --- src/core/create_routes.ts | 30 ++++++++++++++++-------------- src/interfaces.ts | 1 + 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/core/create_routes.ts b/src/core/create_routes.ts index 14e2040..a9c695e 100644 --- a/src/core/create_routes.ts +++ b/src/core/create_routes.ts @@ -4,21 +4,11 @@ import { locations } from '../config'; import { Page, PageComponent, ServerRoute } from '../interfaces'; import { posixify } from './utils'; -const fallback_file = posixify(path.resolve( - __dirname, - '../fallback.html' -)); - export default function create_routes(cwd = locations.routes()) { const components: PageComponent[] = []; const pages: Page[] = []; const server_routes: ServerRoute[] = []; - const fallback = { - name: 'fallback', - file: path.relative(cwd, fallback_file) - }; - function walk( dir: string, parent_segments: Part[][], @@ -111,8 +101,6 @@ export default function create_routes(cwd = locations.routes()) { if (component) { components.push(component); - } else if (components.indexOf(fallback) === -1) { - components.push(fallback); } walk( @@ -120,7 +108,11 @@ export default function create_routes(cwd = locations.routes()) { segments, params, stack.concat({ - component: component || fallback, + component: component || { + missing: true, + name: null, + file: path.join(item.file, 'index.html') + }, params }) ); @@ -186,9 +178,19 @@ export default function create_routes(cwd = locations.routes()) { walk(cwd, [], [], []); - // check for clashes const seen_pages: Map = new Map(); pages.forEach(page => { + // check for missing intermediate index.html files + let i = page.parts.length; + const last_part = page.parts[i - 1]; + while (i--) { + const part = page.parts[i]; + if (part.component.missing) { + throw new Error(`Missing ${part.component.file}, which is required for ${last_part.component.file} to be valid`); + } + } + + // check for clashes const pattern = page.pattern.toString(); if (seen_pages.has(pattern)) { const file = page.parts.pop().component.file; diff --git a/src/interfaces.ts b/src/interfaces.ts index a01fda7..1e8a2ca 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -21,6 +21,7 @@ export type Store = { }; export type PageComponent = { + missing?: boolean; name: string; file: string; };