diff --git a/copy-api.js b/copy-api.js index e015022a..a41d2090 100644 --- a/copy-api.js +++ b/copy-api.js @@ -2,11 +2,10 @@ import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; -import { execSync } from "child_process"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); -function copyDir(src, dest) { +function processDir(src, dest, processFile) { if (!fs.existsSync(src)) { console.warn(`Source directory not found: ${src}`); return; @@ -25,13 +24,49 @@ function copyDir(src, dest) { const destPath = path.join(dest, entry.name); if (entry.isDirectory()) { - copyDir(srcPath, destPath); + processDir(srcPath, destPath, processFile); } else { - fs.copyFileSync(srcPath, destPath); + processFile(srcPath, destPath); } } +} - console.log(`✓ Copied ${src} to ${dest}`); +function copyFile(src, dest) { + fs.copyFileSync(src, dest); +} + +function processAndCopyFile(src, dest) { + let content = fs.readFileSync(src, "utf-8"); + + // Fix relative imports to include .ts extension for Vercel + // This helps Node.js module resolution work correctly at runtime + if (src.endsWith(".ts")) { + // Add .ts extension to relative imports if not already present + content = content.replace( + /from\s+['"](\.[^'"]*?)(?