@@ -9,7 +9,9 @@ export const ALL_OPERATION_KINDS: PolicyOperationKind[] = ['create', 'update', '
9
9
*/
10
10
export function getNodeModulesFolder ( startPath ?: string ) : string | undefined {
11
11
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' ) ) ) {
13
15
return path . join ( startPath , 'node_modules' ) ;
14
16
} else if ( startPath !== '/' ) {
15
17
const parent = path . join ( startPath , '..' ) ;
@@ -25,7 +27,14 @@ export function getNodeModulesFolder(startPath?: string): string | undefined {
25
27
*/
26
28
export function getDefaultOutputFolder ( ) {
27
29
// 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
+ }
29
38
const modulesFolder = getNodeModulesFolder ( runtimeModulePath ) ;
30
39
return modulesFolder ? path . join ( modulesFolder , '.zenstack' ) : undefined ;
31
40
}
0 commit comments