diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 38d6e684..41c100b6 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -7,7 +7,7 @@ import { Send, Settings, Play, CloudUpload } from 'lucide-react'; import { useAISettings } from '@/hooks/useAISettings'; import { useFS } from '@/hooks/useFS'; import { useJSRuntime } from '@/hooks/useJSRuntime'; -import { copyDirectory } from '@/lib/copyFiles'; +import { copyDirectory, copyFile } from '@/lib/copyFiles'; import { generateSecretKey, getPublicKey, nip19 } from 'nostr-tools'; import { bytesToHex } from 'nostr-tools/utils'; import { MessageItem } from '@/components/ai/MessageItem'; @@ -77,6 +77,15 @@ export function ChatPane({ projectId, projectName }: ChatPaneProps) { } catch (error) { console.error('Failed to copy dist:', error); } + + // Copy package-lock.json from runtime back to project filesystem + const packageLockPath = `/projects/${projectId}/package-lock.json`; + try { + await copyFile(runtimeFS, browserFS, 'package-lock.json', packageLockPath); + console.log('Successfully copied package-lock.json from runtime'); + } catch (error) { + console.error('Failed to copy package-lock.json:', error); + } }; const runDeploy = async () => { diff --git a/src/lib/copyFiles.ts b/src/lib/copyFiles.ts index 938710f9..d15fdd92 100644 --- a/src/lib/copyFiles.ts +++ b/src/lib/copyFiles.ts @@ -59,6 +59,41 @@ export async function copyFiles( } } +/** + * Copy a single file between JSRuntime filesystems + * @param sourceFS Source filesystem + * @param targetFS Target filesystem + * @param sourcePath Source file path + * @param targetPath Target file path + */ +export async function copyFile( + sourceFS: JSRuntimeFS, + targetFS: JSRuntimeFS, + sourcePath: string, + targetPath: string +): Promise { + try { + console.log(`Copying file: ${sourcePath} -> ${targetPath}`); + + // Check if source exists and is a file + const sourceStat = await sourceFS.stat(sourcePath); + if (!sourceStat.isFile()) { + throw new Error(`Source path ${sourcePath} is not a file`); + } + + // Read the file content + const content = await sourceFS.readFile(sourcePath); + + // Write to target + await targetFS.writeFile(targetPath, content); + + console.log(`Successfully copied file ${sourcePath} to ${targetPath}`); + } catch (error) { + console.error(`Failed to copy file ${sourcePath} to ${targetPath}:`, error); + throw error; + } +} + /** * Copy a directory between JSRuntime filesystems * Convenience wrapper for copyFiles with better error handling