From adec8ee05aff31499946cfd3e98d77620bfab4e2 Mon Sep 17 00:00:00 2001 From: JG Date: Mon, 5 Jun 2023 22:00:48 +0100 Subject: [PATCH 1/2] fix: generate .zenstack with the same level of @zenstackhq --- packages/schema/src/plugins/plugin-utils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/schema/src/plugins/plugin-utils.ts b/packages/schema/src/plugins/plugin-utils.ts index 546166892..522645060 100644 --- a/packages/schema/src/plugins/plugin-utils.ts +++ b/packages/schema/src/plugins/plugin-utils.ts @@ -25,7 +25,11 @@ export function getNodeModulesFolder(startPath?: string): string | undefined { */ export function getDefaultOutputFolder() { // Find the real runtime module path, it might be a symlink in pnpm - const runtimeModulePath = require.resolve('@zenstackhq/runtime'); + let runtimeModulePath = require.resolve('@zenstackhq/runtime'); + if (runtimeModulePath) { + // generate to the same level as @zenstackhq + runtimeModulePath = path.join(runtimeModulePath, '../..'); + } const modulesFolder = getNodeModulesFolder(runtimeModulePath); return modulesFolder ? path.join(modulesFolder, '.zenstack') : undefined; } From e7be30af4749f3bd278d7a85f9a0f91dd46e11aa Mon Sep 17 00:00:00 2001 From: JG Date: Tue, 6 Jun 2023 10:30:39 +0100 Subject: [PATCH 2/2] fix: fix comments --- packages/schema/src/plugins/plugin-utils.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/schema/src/plugins/plugin-utils.ts b/packages/schema/src/plugins/plugin-utils.ts index 522645060..482f7a7bd 100644 --- a/packages/schema/src/plugins/plugin-utils.ts +++ b/packages/schema/src/plugins/plugin-utils.ts @@ -9,7 +9,9 @@ export const ALL_OPERATION_KINDS: PolicyOperationKind[] = ['create', 'update', ' */ export function getNodeModulesFolder(startPath?: string): string | undefined { startPath = startPath ?? process.cwd(); - if (fs.existsSync(path.join(startPath, 'node_modules'))) { + if (startPath.endsWith('node_modules')) { + return startPath; + } else if (fs.existsSync(path.join(startPath, 'node_modules'))) { return path.join(startPath, 'node_modules'); } else if (startPath !== '/') { const parent = path.join(startPath, '..'); @@ -27,8 +29,11 @@ export function getDefaultOutputFolder() { // Find the real runtime module path, it might be a symlink in pnpm let runtimeModulePath = require.resolve('@zenstackhq/runtime'); if (runtimeModulePath) { - // generate to the same level as @zenstackhq - runtimeModulePath = path.join(runtimeModulePath, '../..'); + // start with the parent folder of @zenstackhq, supposed to be a node_modules folder + while (!runtimeModulePath.endsWith('@zenstackhq') && runtimeModulePath !== '/') { + runtimeModulePath = path.join(runtimeModulePath, '..'); + } + runtimeModulePath = path.join(runtimeModulePath, '..'); } const modulesFolder = getNodeModulesFolder(runtimeModulePath); return modulesFolder ? path.join(modulesFolder, '.zenstack') : undefined;