diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index b235f1a1..6c4dd2d5 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -46,11 +46,12 @@ export function ChatPane({ projectId, projectName }: ChatPaneProps) { const runBuild = async () => { console.log('Running build for project:', projectId); + const runtimeFS = await runtime.fs(); // Copy project files to runtime filesystem const projectPath = `/projects/${projectId}`; try { - await copyDirectory(fs, runtime.fs, projectPath, '.'); + await copyDirectory(fs, runtimeFS, projectPath, '.'); console.log('Successfully copied project to runtime'); } catch (error) { console.error('Failed to copy project to runtime:', error); @@ -67,7 +68,7 @@ export function ChatPane({ projectId, projectName }: ChatPaneProps) { // Copy "dist" directory from runtime back to project filesystem const distPath = `/projects/${projectId}/dist`; try { - await copyDirectory(runtime.fs, fs, 'dist', distPath); + await copyDirectory(runtimeFS, fs, 'dist', distPath); console.log('Successfully copied dist from runtime'); } catch (error) { console.error('Failed to copy dist:', error); diff --git a/src/lib/JSRuntime.ts b/src/lib/JSRuntime.ts index cbb6f70e..2173c4d4 100644 --- a/src/lib/JSRuntime.ts +++ b/src/lib/JSRuntime.ts @@ -56,7 +56,7 @@ export interface JSRuntime { /** * Filesystem access */ - readonly fs: JSRuntimeFS; + fs(): Promise; /** * Spawn a process in the runtime environment diff --git a/src/lib/WebContainerAdapter.ts b/src/lib/WebContainerAdapter.ts index 413f0f9a..d6b1db9c 100644 --- a/src/lib/WebContainerAdapter.ts +++ b/src/lib/WebContainerAdapter.ts @@ -7,16 +7,13 @@ import type { JSRuntime, JSRuntimeFS, DirectoryEntry } from './JSRuntime'; export class WebContainerAdapter implements JSRuntime { private webcontainer: WebContainer | null = null; private bootPromise: Promise | null = null; - private _fs: JSRuntimeFS | null = null; /** * Get the filesystem interface */ - get fs(): JSRuntimeFS { - if (!this._fs) { - throw new Error('WebContainer not initialized. Call spawn() first to initialize.'); - } - return this._fs; + async fs(): Promise { + const webcontainer = await this.ensureBooted(); + return new WebContainerFSAdapter(webcontainer); } /** @@ -32,7 +29,6 @@ export class WebContainerAdapter implements JSRuntime { } this.webcontainer = await this.bootPromise; - this._fs = new WebContainerFSAdapter(this.webcontainer); return this.webcontainer; } diff --git a/src/lib/fs.ts b/src/lib/fs.ts index e888ec12..3f700a58 100644 --- a/src/lib/fs.ts +++ b/src/lib/fs.ts @@ -63,7 +63,6 @@ export class ProjectsManager { } async cloneTemplate(projectPath: string) { - // Create a LightningFS instance for git operations await git.clone({ fs: this.fs, http,