@@ -10,6 +10,7 @@ import path from 'path';
1010import fs from 'fs' ;
1111import net from 'net' ;
1212import { createRequire } from 'module' ;
13+ import { pathToFileURL } from 'url' ;
1314import { spawn , type ChildProcess } from 'child_process' ;
1415import chalk from 'chalk' ;
1516
@@ -49,27 +50,25 @@ export function resolveStudioPath(): string | null {
4950 }
5051 }
5152
52- // Fallback: resolve from node_modules
53- // Try resolving from the consumer's working directory first (important for
54- // pnpm strict isolation where the CLI cannot see the consumer's dependencies),
55- // then fall back to resolving from the CLI's own location.
53+ // Fallback: resolve from node_modules via createRequire.
54+ // Try the consumer's cwd first (pnpm strict isolation means the CLI's own
55+ // import.meta.url cannot see the consumer's dependencies), then the CLI itself.
5656 const resolutionBases = [
57- path . join ( cwd , '__placeholder__.js' ) , // consumer workspace
58- import . meta. url , // CLI package itself
57+ pathToFileURL ( path . join ( cwd , 'package.json' ) ) . href , // consumer workspace
58+ import . meta. url , // CLI package itself
5959 ] ;
6060
6161 for ( const base of resolutionBases ) {
6262 try {
6363 const req = createRequire ( base ) ;
6464 const resolved = req . resolve ( '@objectstack/studio/package.json' ) ;
6565 return path . dirname ( resolved ) ;
66- } catch ( e ) {
66+ } catch {
6767 // Not resolvable from this base — try next
68- if ( process . env . DEBUG ) console . error ( ` [studio] resolve from ${ base } failed:` , ( e as Error ) . message ) ;
6968 }
7069 }
7170
72- // Last resort: direct filesystem check in node_modules
71+ // Last resort: direct filesystem check in cwd/ node_modules
7372 const directPath = path . join ( cwd , 'node_modules' , '@objectstack' , 'studio' ) ;
7473 if ( fs . existsSync ( path . join ( directPath , 'package.json' ) ) ) {
7574 return directPath ;
0 commit comments