Skip to content

Commit 2bb0b2b

Browse files
authored
fix: generate .zenstack with the same level of @zenstackhq (#464)
1 parent f90e65a commit 2bb0b2b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/schema/src/plugins/plugin-utils.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export const ALL_OPERATION_KINDS: PolicyOperationKind[] = ['create', 'update', '
99
*/
1010
export function getNodeModulesFolder(startPath?: string): string | undefined {
1111
startPath = startPath ?? process.cwd();
12-
if (fs.existsSync(path.join(startPath, 'node_modules'))) {
12+
if (startPath.endsWith('node_modules')) {
13+
return startPath;
14+
} else if (fs.existsSync(path.join(startPath, 'node_modules'))) {
1315
return path.join(startPath, 'node_modules');
1416
} else if (startPath !== '/') {
1517
const parent = path.join(startPath, '..');
@@ -25,7 +27,14 @@ export function getNodeModulesFolder(startPath?: string): string | undefined {
2527
*/
2628
export function getDefaultOutputFolder() {
2729
// Find the real runtime module path, it might be a symlink in pnpm
28-
const runtimeModulePath = require.resolve('@zenstackhq/runtime');
30+
let runtimeModulePath = require.resolve('@zenstackhq/runtime');
31+
if (runtimeModulePath) {
32+
// start with the parent folder of @zenstackhq, supposed to be a node_modules folder
33+
while (!runtimeModulePath.endsWith('@zenstackhq') && runtimeModulePath !== '/') {
34+
runtimeModulePath = path.join(runtimeModulePath, '..');
35+
}
36+
runtimeModulePath = path.join(runtimeModulePath, '..');
37+
}
2938
const modulesFolder = getNodeModulesFolder(runtimeModulePath);
3039
return modulesFolder ? path.join(modulesFolder, '.zenstack') : undefined;
3140
}

0 commit comments

Comments
 (0)