fix: remove monorepo
This commit is contained in:
6
app/lib/webcontainer/auth.client.ts
Normal file
6
app/lib/webcontainer/auth.client.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* This client-only module that contains everything related to auth and is used
|
||||
* to avoid importing `@webcontainer/api` in the server bundle.
|
||||
*/
|
||||
|
||||
export { auth, type AuthAPI } from '@webcontainer/api';
|
||||
37
app/lib/webcontainer/index.ts
Normal file
37
app/lib/webcontainer/index.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { WebContainer } from '@webcontainer/api';
|
||||
import { WORK_DIR_NAME } from '~/utils/constants';
|
||||
import { forgetAuth } from '~/lib/auth';
|
||||
|
||||
interface WebContainerContext {
|
||||
loaded: boolean;
|
||||
}
|
||||
|
||||
export const webcontainerContext: WebContainerContext = import.meta.hot?.data.webcontainerContext ?? {
|
||||
loaded: false,
|
||||
};
|
||||
|
||||
if (import.meta.hot) {
|
||||
import.meta.hot.data.webcontainerContext = webcontainerContext;
|
||||
}
|
||||
|
||||
export let webcontainer: Promise<WebContainer> = new Promise(() => {
|
||||
// noop for ssr
|
||||
});
|
||||
|
||||
if (!import.meta.env.SSR) {
|
||||
webcontainer =
|
||||
import.meta.hot?.data.webcontainer ??
|
||||
Promise.resolve()
|
||||
.then(() => {
|
||||
forgetAuth();
|
||||
return WebContainer.boot({ workdirName: WORK_DIR_NAME });
|
||||
})
|
||||
.then((webcontainer) => {
|
||||
webcontainerContext.loaded = true;
|
||||
return webcontainer;
|
||||
});
|
||||
|
||||
if (import.meta.hot) {
|
||||
import.meta.hot.data.webcontainer = webcontainer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user