From 4b21a4dfc60d682976c1c8d829ed88928ad7d953 Mon Sep 17 00:00:00 2001 From: Alexander Rodionov Date: Thu, 24 Aug 2023 12:16:19 +0400 Subject: [PATCH 1/2] fix(*): load package data relatively to module dir --- src/Config/CliInfo.ts | 4 ++-- src/Config/container.ts | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Config/CliInfo.ts b/src/Config/CliInfo.ts index 2b17f78e..52c47b1b 100644 --- a/src/Config/CliInfo.ts +++ b/src/Config/CliInfo.ts @@ -7,13 +7,13 @@ export class CliInfo { public readonly version: string; public readonly distribution: string | undefined; - constructor(cwd: string = process.cwd()) { + constructor(cwd: string) { const packagePath = this.getPackagePath(cwd); const packageData = this.getPackageData(packagePath); this.cwd = packagePath ? path.dirname(packagePath) : cwd; this.version = process.env.VERSION ?? packageData?.version; - this.distribution = packageData.brightCli?.distribution; + this.distribution = packageData?.brightCli?.distribution; } private getPackageData(packagePath: string) { diff --git a/src/Config/container.ts b/src/Config/container.ts index 0464bb82..7afda5e9 100644 --- a/src/Config/container.ts +++ b/src/Config/container.ts @@ -59,12 +59,17 @@ import { DefaultRuntimeDetector } from '../Repeater'; import { container, Lifecycle } from 'tsyringe'; +import path from 'path'; container .register('tsyringe', { useValue: container }) - .register(CliInfo, { useValue: new CliInfo(process.cwd()) }) + .register(CliInfo, { + useValue: new CliInfo( + (require.main && path.dirname(require.main.filename)) ?? __dirname + ) + }) .register( RequestExecutor, { From 794b68a96dc52fc698bdd9be3119c33547f9a22c Mon Sep 17 00:00:00 2001 From: Alexander Rodionov Date: Thu, 24 Aug 2023 14:40:20 +0400 Subject: [PATCH 2/2] refactor: use only `__dirname` --- src/Config/container.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Config/container.ts b/src/Config/container.ts index 7afda5e9..8dd86a76 100644 --- a/src/Config/container.ts +++ b/src/Config/container.ts @@ -59,16 +59,13 @@ import { DefaultRuntimeDetector } from '../Repeater'; import { container, Lifecycle } from 'tsyringe'; -import path from 'path'; container .register('tsyringe', { useValue: container }) .register(CliInfo, { - useValue: new CliInfo( - (require.main && path.dirname(require.main.filename)) ?? __dirname - ) + useValue: new CliInfo(__dirname) }) .register( RequestExecutor,