feat(server): multiple island exports (#1397)

This commit is contained in:
Reed von Redwitz
2023-07-03 09:59:38 +02:00
committed by GitHub
parent 16be99e69b
commit a3f7c212f4
9 changed files with 166 additions and 70 deletions
+14 -7
View File
@@ -286,14 +286,21 @@ export class ServerContext {
}
const path = url.substring(baseUrl.length).substring("islands".length);
const baseRoute = path.substring(1, path.length - extname(path).length);
const name = sanitizeIslandName(baseRoute);
const id = name.toLowerCase();
if (typeof module.default !== "function") {
throw new TypeError(
`Islands must default export a component ('${self}').`,
);
for (const [exportName, exportedFunction] of Object.entries(module)) {
if (typeof exportedFunction !== "function") {
continue;
}
const name = sanitizeIslandName(baseRoute);
const id = `${name}_${exportName}`.toLowerCase();
islands.push({
id,
name,
url,
component: exportedFunction,
exportName,
});
}
islands.push({ id, name, url, component: module.default });
}
const staticFiles: StaticFile[] = [];