From bf0045b27b1caab3a73c93aa286915c22cdbde88 Mon Sep 17 00:00:00 2001 From: Pooyan Khanjankhani Date: Thu, 28 Dec 2023 19:12:14 +0330 Subject: [PATCH] fix version cli bug --- src/cli.ts | 10 +++++++--- src/proxy.ts | 10 ++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 9592543..df70076 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -2,13 +2,14 @@ import { z } from "zod"; import minimist from "minimist"; import { NestFactory } from "@nestjs/core"; +import path, { dirname } from "node:path"; import { DynamicModule, Module } from "@nestjs/common"; +import { existsSync, readFileSync } from "node:fs"; import { UserModule } from "./user"; import { ProxyModule } from "./proxy"; import { DatabaseModule } from "./database/database.module"; import { ConfigModule, ConfigService } from "./config"; -import { readFileSync } from "node:fs"; @Module({}) export class AppModule { @@ -101,8 +102,11 @@ function parseSchema( } function showVersion() { - // TODO: fix this - const { version } = JSON.parse(readFileSync("package.json").toString()); + let dir = __filename; + while (dir && !existsSync(path.join(dir, "package.json"))) dir = dirname(dir); + + const filePath = path.join(dir, "package.json"); + const { version } = JSON.parse(readFileSync(filePath).toString()); console.log(`Version: ${version}`); process.exit(1); } diff --git a/src/proxy.ts b/src/proxy.ts index 30cd3c2..cbfa8eb 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -1,15 +1,9 @@ -import { - DynamicModule, - Inject, - Injectable, - Logger, - Module, -} from "@nestjs/common"; import * as net from "net"; import { Transform } from "node:stream"; +import { DynamicModule, Injectable, Logger, Module } from "@nestjs/common"; +import { UserProxyConfig } from "./config"; import { withErrorLogging } from "./utils"; -import { ProxyConfig, UserProxyConfig } from "./config"; import { UserFactory, UserStatsService } from "./user"; import { EventModule, MoxyEventEmitter } from "./event";