Skip to content

Commit

Permalink
fix server manifest generation (#6507)
Browse files Browse the repository at this point in the history
* fix server manifest generation

* ok think i fixed it

* oops
  • Loading branch information
Rich-Harris committed Sep 2, 2022
1 parent d9a8f4b commit 4f5e266
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-brooms-relate.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Fix server manifest generation
28 changes: 21 additions & 7 deletions packages/kit/src/core/generate_manifest/index.js
Expand Up @@ -60,13 +60,13 @@ export function generate_manifest({ build_data, relative_path, routes, format =
if (!route.page && !route.endpoint) return;
return `{
id: ${s(route.id)},
pattern: ${route.pattern},
names: ${s(route.names)},
types: ${s(route.types)},
page: ${s(route.page)},
endpoint: ${route.endpoint ? loader(`${relative_path}/${build_data.server.vite_manifest[route.endpoint.file].file}`) : 'null'}
}`;
id: ${s(route.id)},
pattern: ${route.pattern},
names: ${s(route.names)},
types: ${s(route.types)},
page: ${route.page ? `{ layouts: ${get_nodes(route.page.layouts)}, errors: ${get_nodes(route.page.errors)}, leaf: ${route.page.leaf} }` : 'null'},
endpoint: ${route.endpoint ? loader(`${relative_path}/${build_data.server.vite_manifest[route.endpoint.file].file}`) : 'null'}
}`;
}).filter(Boolean).join(',\n\t\t\t\t')}
],
matchers: async () => {
Expand All @@ -76,3 +76,17 @@ export function generate_manifest({ build_data, relative_path, routes, format =
}
}`.replace(/^\t/gm, '');
}

/** @param {Array<number | undefined>} indexes */
function get_nodes(indexes) {
let string = indexes.map((n) => n ?? '').join(',');

if (indexes.at(-1) === undefined) {
// since JavaScript ignores trailing commas, we need to insert a dummy
// comma so that the array has the correct length if the last item
// is undefined
string += ',';
}

return `[${string}]`;
}

0 comments on commit 4f5e266

Please sign in to comment.