Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/usrrname/cursorrules. A wicked npx-able lib of Cursor rules with Otaku AI agents, optional lean workflow ๐ usrrname.github.io/cursorrules
agent cursor cursor-ai cursorrules
Something went wrong. Try again.
1.2 kB ยท 39 lines
JavaScript
at main
123456789101112131415161718192021222324252627282930313233343536373839import { readFileSync, statSync } from "node:fs";import { dirname, resolve } from "node:path";/** * @param {string} startPath * @param {string} packageName * @returns {string} */export function findPackageRoot(startPath, packageName) { let currentPath = startPath;
while (currentPath !== dirname(currentPath)) { // Look for package.json or your package-specific markers try { const packageJsonPath = resolve(currentPath, 'package.json'); const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
// Verify package if (packageJson.name === packageName) { return currentPath; } } catch (e) { // Continue searching up }
// Also check for .cursor directory as a marker try { const cursorPath = resolve(currentPath, '.cursor'); if (statSync(cursorPath).isDirectory()) { return currentPath; } } catch (e) { // Continue searching up }
currentPath = dirname(currentPath); }
throw new Error('Package root not found');}