From ca46647a733a8d043b22fa67a2f64c02766b3708 Mon Sep 17 00:00:00 2001 From: Paul Bakaus Date: Tue, 16 Dec 2025 14:49:57 -0800 Subject: [PATCH] Fix: Use import.meta.url for reliable path resolution in API handlers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit process.cwd() is unreliable in Vercel serverless functions. Using import.meta.url + dirname to resolve PROJECT_ROOT ensures the source/ and dist/ directories are found correctly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- server/lib/api-handlers.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server/lib/api-handlers.js b/server/lib/api-handlers.js index 168113257..77e5e69d9 100644 --- a/server/lib/api-handlers.js +++ b/server/lib/api-handlers.js @@ -1,6 +1,12 @@ import { readdir, readFile } from "fs/promises"; -import { basename, join } from "path"; +import { basename, join, dirname } from "path"; import { existsSync } from "fs"; +import { fileURLToPath } from "url"; + +// Get project root directory (works in both Node.js and Bun, including Vercel) +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +const PROJECT_ROOT = join(__dirname, "..", ".."); // Helper to read file content (works in both Node.js and Bun) async function readFileContent(filePath) { @@ -9,7 +15,7 @@ async function readFileContent(filePath) { // Read all skills from source directory export async function getSkills() { - const sourceDir = join(process.cwd(), "source"); + const sourceDir = join(PROJECT_ROOT, "source"); const skillsDir = join(sourceDir, "skills"); const files = await readdir(skillsDir); const skills = []; @@ -38,7 +44,7 @@ export async function getSkills() { // Read all commands from source directory export async function getCommands() { - const sourceDir = join(process.cwd(), "source"); + const sourceDir = join(PROJECT_ROOT, "source"); const commandsDir = join(sourceDir, "commands"); const files = await readdir(commandsDir); const commands = []; @@ -67,7 +73,7 @@ export async function getCommands() { // Get the appropriate file path for a provider export function getFilePath(type, provider, id) { - const distDir = join(process.cwd(), "dist"); + const distDir = join(PROJECT_ROOT, "dist"); if (type === "skill") { if (provider === "cursor") { @@ -126,7 +132,7 @@ export async function handleFileDownload(type, provider, id) { // Read patterns from source/patterns.md export async function getPatterns() { - const sourceDir = join(process.cwd(), "source"); + const sourceDir = join(PROJECT_ROOT, "source"); const filePath = join(sourceDir, "patterns.md"); try { @@ -203,7 +209,7 @@ export async function getPatterns() { // Handle bundle download export async function handleBundleDownload(provider) { - const distDir = join(process.cwd(), "dist"); + const distDir = join(PROJECT_ROOT, "dist"); const zipPath = join(distDir, `${provider}.zip`); try {