Skip to content

Commit

Permalink
Fix admin dynamic import (#303)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia authored Jan 13, 2024
1 parent b8be6b1 commit 7bc97b3
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions decohub/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { App, FnContext } from "deco/mod.ts";
import { buildSourceMap } from "deco/blocks/utils.tsx";
import { context, type App, type FnContext } from "deco/mod.ts";
import { Markdown } from "./components/Markdown.tsx";
import manifest, { Manifest } from "./manifest.gen.ts";

Expand All @@ -8,10 +9,35 @@ export type State = {};
/**
* @title Deco Hub
*/
export default function App(
const ADMIN_APP = "decohub/apps/admin.ts";
export default async function App(
state: State,
): App<Manifest, State> {
return { manifest, state };
): Promise<App<Manifest, State>> {
const resolvedImport = import.meta.resolve("../admin/mod.ts");
return {
manifest: {
...manifest,
apps: {
...manifest.apps,
...context.play // this is an optimization to not include the admin code for everyone in case of play is not being used.
? {
[ADMIN_APP]: await import(
resolvedImport
),
}
: {},
},
} as Manifest,
state,
...context.play
? {
sourceMap: {
...buildSourceMap(manifest),
[ADMIN_APP]: resolvedImport,
},
}
: {},
};
}

export type AppContext = FnContext<State, Manifest>;
Expand Down

0 comments on commit 7bc97b3

Please sign in to comment.