Skip to content

Commit f4fe082

Browse files
committed
fix: enhance studio path resolution for pnpm strict isolation
1 parent c8c93ba commit f4fe082

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

packages/cli/src/utils/studio.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import path from 'path';
1010
import fs from 'fs';
1111
import net from 'net';
12+
import { createRequire } from 'module';
1213
import { spawn, type ChildProcess } from 'child_process';
1314
import chalk from 'chalk';
1415

@@ -49,14 +50,32 @@ export function resolveStudioPath(): string | null {
4950
}
5051

5152
// Fallback: resolve from node_modules
52-
try {
53-
const { createRequire } = require('module');
54-
const req = createRequire(import.meta.url);
55-
const resolved = req.resolve('@objectstack/studio/package.json');
56-
return path.dirname(resolved);
57-
} catch {
58-
return null;
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.
56+
const resolutionBases = [
57+
path.join(cwd, '__placeholder__.js'), // consumer workspace
58+
import.meta.url, // CLI package itself
59+
];
60+
61+
for (const base of resolutionBases) {
62+
try {
63+
const req = createRequire(base);
64+
const resolved = req.resolve('@objectstack/studio/package.json');
65+
return path.dirname(resolved);
66+
} catch (e) {
67+
// Not resolvable from this base — try next
68+
if (process.env.DEBUG) console.error(` [studio] resolve from ${base} failed:`, (e as Error).message);
69+
}
5970
}
71+
72+
// Last resort: direct filesystem check in node_modules
73+
const directPath = path.join(cwd, 'node_modules', '@objectstack', 'studio');
74+
if (fs.existsSync(path.join(directPath, 'package.json'))) {
75+
return directPath;
76+
}
77+
78+
return null;
6079
}
6180

6281
/**

0 commit comments

Comments
 (0)