From 2b71c1cd3e17dd46fb711779f9616d88ddeb4b7f Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 30 Oct 2024 13:37:18 +0100 Subject: [PATCH] refactor: remove __dirname from production code --- packages/config/src/utils.ts | 5 ++++- packages/core/src/log/shared.ts | 7 +------ packages/flash/src/cli.ts | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/config/src/utils.ts b/packages/config/src/utils.ts index 763431531e28..fd404c2b4810 100644 --- a/packages/config/src/utils.ts +++ b/packages/config/src/utils.ts @@ -7,7 +7,10 @@ import { PACKAGE_VERSION } from "./_version"; import type { DeviceConfigIndexEntry } from "./devices/DeviceConfig"; /** The absolute path of the embedded configuration directory */ -export const configDir = path.resolve(__dirname, "../config"); +export const configDir = path.resolve( + path.dirname(require.resolve("@zwave-js/config/package.json")), + "config", +); /** The (optional) absolute path of an external configuration directory */ export function externalConfigDir(): string | undefined { return process.env.ZWAVEJS_EXTERNAL_CONFIG; diff --git a/packages/core/src/log/shared.ts b/packages/core/src/log/shared.ts index 5c17177c3237..8cfac799f551 100644 --- a/packages/core/src/log/shared.ts +++ b/packages/core/src/log/shared.ts @@ -52,12 +52,7 @@ export class ZWaveLogContainer extends winston.Container { maxFiles: 7, nodeFilter: stringToNodeList(process.env.LOG_NODES), transports: undefined as any, - filename: require.main - ? path.join( - path.dirname(require.main.filename), - `zwavejs_%DATE%.log`, - ) - : path.join(__dirname, "../../..", `zwavejs_%DATE%.log`), + filename: path.join(process.cwd(), `zwavejs_%DATE%.log`), forceConsole: false, }; diff --git a/packages/flash/src/cli.ts b/packages/flash/src/cli.ts index ffa1d746dab7..e05f3e446d95 100644 --- a/packages/flash/src/cli.ts +++ b/packages/flash/src/cli.ts @@ -35,8 +35,8 @@ const driver = new Driver(port, { loadConfiguration: false, }, storage: { - cacheDir: path.join(__dirname, "cache"), - lockDir: path.join(__dirname, "cache/locks"), + cacheDir: path.join(process.cwd(), "cache"), + lockDir: path.join(process.cwd(), "cache/locks"), }, allowBootloaderOnly: true, })