@@ -44,6 +44,9 @@ const appRoot = fileURLToPath(new URL("../", import.meta.url));
4444const nodeModulesRoot = fileURLToPath (
4545 new URL ( "../../../node_modules/" , import . meta. url )
4646) ;
47+ const localNodeModulesRoot = fileURLToPath (
48+ new URL ( "../node_modules/" , import . meta. url )
49+ ) ;
4750
4851async function pathExists ( path : string ) {
4952 try {
@@ -54,18 +57,38 @@ async function pathExists(path: string) {
5457 }
5558}
5659
60+ async function findPackageJson ( packagePath : string ) : Promise < string | null > {
61+ // Try root node_modules first (for npm/yarn)
62+ const rootPath = join ( nodeModulesRoot , packagePath , "package.json" ) ;
63+ if ( await pathExists ( rootPath ) ) {
64+ return rootPath ;
65+ }
66+
67+ // Try local node_modules (for pnpm)
68+ const localPath = join ( localNodeModulesRoot , packagePath , "package.json" ) ;
69+ if ( await pathExists ( localPath ) ) {
70+ return localPath ;
71+ }
72+
73+ return null ;
74+ }
75+
5776async function ensureOpenTuiCorePackage ( packageName : string ) {
5877 const packageJsonPath = join ( nodeModulesRoot , packageName , "package.json" ) ;
5978 if ( await pathExists ( packageJsonPath ) ) {
6079 return ;
6180 }
6281
63- const corePackageJsonPath = join (
64- nodeModulesRoot ,
65- "@opentui" ,
66- "core" ,
67- "package.json"
68- ) ;
82+ // Try to find @opentui /core package.json in multiple locations
83+ const corePackageJsonPath = await findPackageJson ( "@opentui/core" ) ;
84+ if ( ! corePackageJsonPath ) {
85+ throw new Error (
86+ `Could not find @opentui/core package.json. Checked:\n` +
87+ ` - ${ join ( nodeModulesRoot , "@opentui/core" , "package.json" ) } \n` +
88+ ` - ${ join ( localNodeModulesRoot , "@opentui/core" , "package.json" ) } `
89+ ) ;
90+ }
91+
6992 const corePackage = JSON . parse (
7093 await readFile ( corePackageJsonPath , "utf8" )
7194 ) as {
0 commit comments