Skip to content

Commit 5abd86c

Browse files
committed
fix: case-insensitive index check, accurate server error message
1 parent 5df5f87 commit 5abd86c

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎src/application/builder.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export async function* executeBuild(
3535

3636
if (shipsServer(applicationOptions)) {
3737
context.logger.error(
38-
`❌ 'prerenderFormat: "file"' requires 'outputMode: "static"': ` +
39-
`the Angular SSR server looks up prerendered pages as 'index.html'.`
38+
`❌ 'prerenderFormat: "file"' is not supported when the build produces a server ` +
39+
`('outputMode: "server"', or 'ssr' without 'outputMode'): the Angular SSR server looks up prerendered pages as 'index.html'.`
4040
);
4141
yield { success: false };
4242

‎src/application/file-format.spec.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ describe('toFileOutput', () => {
5555
expect(errors[0]).toContain("would be served as '/'");
5656
});
5757

58+
it('reports routes named index regardless of case', () => {
59+
const { errors } = toFileOutput({ 'index.html': file('home'), 'Index/index.html': file('x') });
60+
61+
expect(errors).toEqual([expect.stringContaining("Route '/Index' cannot be prerendered")]);
62+
});
63+
5864
it('reports nested routes ending in index', () => {
5965
const { errors } = toFileOutput({ 'docs/index/index.html': file('x') });
6066

‎src/application/file-format.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export function toFileOutput(output: PrerenderOutput): FileOutputResult {
6868
const route = routeOf(outPath);
6969
const filePath = toFilePath(outPath);
7070

71-
if (outPath.endsWith('/index' + INDEX_SUFFIX) || outPath === 'index' + INDEX_SUFFIX) {
71+
// Case-insensitive: on macOS and Windows, 'Index.html' is the same file as 'index.html'.
72+
const lowerOutPath = outPath.toLowerCase();
73+
if (lowerOutPath.endsWith('/index' + INDEX_SUFFIX) || lowerOutPath === 'index' + INDEX_SUFFIX) {
7274
errors.push(
7375
`Route '${route}' cannot be prerendered with 'prerenderFormat: "file"': ` +
7476
`its file '${filePath}' would be served as '${route.slice(0, -'index'.length)}', not as '${route}'. ` +

‎src/ng-add.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export const ngAdd = (options: NgAddOptions) => async (tree: Tree, context: Sche
6464
if (configurationsWithServer.length) {
6565
throw new SchematicsException(
6666
`The build target of "${options.project}" ships an Angular SSR server (${configurationsWithServer.join(', ')}). ` +
67-
`prerenderFormat "file" requires "outputMode": "static", because the SSR server looks up prerendered pages as 'index.html'. ` +
68-
`Set "outputMode": "static" and run ng add again.`
67+
`prerenderFormat "file" is not supported when the build produces a server, because the SSR server looks up prerendered pages as 'index.html'. ` +
68+
`Use a static build ("outputMode": "static", or prerendering without "ssr") and run ng add again.`
6969
);
7070
}
7171

0 commit comments

Comments
 (0)