From e501dabac5ee93a02c86f78fbd7ba4872d56221d Mon Sep 17 00:00:00 2001 From: Nikolay Karadzhov Date: Tue, 7 Oct 2025 13:39:52 +0300 Subject: [PATCH] chore(build): fix npm run build command importing from 'package.json' messes typescript, as it starts thinking it depends on the files it wants to write, resulting in build errors if the dist folders are not deleted. ultimately it was very annoying to delete all dist folders and then build when you just want to build. and its also much slower because you loose all your cache --- packages/client/lib/client/index.ts | 29 +++++++++++++++---- .../client/lib/commands/CLIENT_INFO.spec.ts | 8 ++++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/packages/client/lib/client/index.ts b/packages/client/lib/client/index.ts index 919baab0df..d24f0796e2 100644 --- a/packages/client/lib/client/index.ts +++ b/packages/client/lib/client/index.ts @@ -19,8 +19,9 @@ import { RedisVariadicArgument, parseArgs, pushVariadicArguments } from '../comm import { BasicClientSideCache, ClientSideCacheConfig, ClientSideCacheProvider } from './cache'; import { BasicCommandParser, CommandParser } from './parser'; import SingleEntryCache from '../single-entry-cache'; -import { version } from '../../package.json' import EnterpriseMaintenanceManager, { MaintenanceUpdate, MovingEndpointType } from './enterprise-maintenance-manager'; +import { resolve } from 'node:path'; +import { readFile } from 'node:fs/promises'; export interface RedisClientOptions< M extends RedisModules = RedisModules, @@ -741,7 +742,7 @@ export default class RedisClient< if (!this.#options.disableClientInfo) { commands.push({ - cmd: ['CLIENT', 'SETINFO', 'LIB-VER', version], + cmd: ['CLIENT', 'SETINFO', 'LIB-VER', await getPackageVersion()], errorHandler: () => { // Client libraries are expected to pipeline this command // after authentication on all connections and ignore failures @@ -765,7 +766,7 @@ export default class RedisClient< } }); } - + if (this.#clientSideCache) { commands.push({cmd: this.#clientSideCache.trackingOn()}); } @@ -773,9 +774,9 @@ export default class RedisClient< if (this.#options?.emitInvalidate) { commands.push({cmd: ['CLIENT', 'TRACKING', 'ON']}); } - + const maintenanceHandshakeCmd = await EnterpriseMaintenanceManager.getHandshakeCommand(this.#options); - + if(maintenanceHandshakeCmd) { commands.push(maintenanceHandshakeCmd); }; @@ -1559,4 +1560,22 @@ export default class RedisClient< unref() { this._self.#socket.unref(); } + +} + +let cachedVersion = "error-fetching-version"; +async function getPackageVersion() { + if (cachedVersion) { + return cachedVersion; + } + try { + const filePath = resolve(__dirname, "..", "..", "package.json"); + const data = await readFile(filePath, "utf8"); + const parsed = JSON.parse(data); + cachedVersion = parsed.version; + return cachedVersion; + } catch (err) { + cachedVersion = "error-fetching-version"; + return cachedVersion; + } } diff --git a/packages/client/lib/commands/CLIENT_INFO.spec.ts b/packages/client/lib/commands/CLIENT_INFO.spec.ts index 96881e6c1a..5d03e55831 100644 --- a/packages/client/lib/commands/CLIENT_INFO.spec.ts +++ b/packages/client/lib/commands/CLIENT_INFO.spec.ts @@ -2,9 +2,15 @@ import { strict as assert } from 'node:assert'; import CLIENT_INFO from './CLIENT_INFO'; import testUtils, { GLOBAL } from '../test-utils'; import { parseArgs } from './generic-transformers'; -import { version } from '../../package.json'; +import { resolve } from 'node:path'; +import { readFileSync } from 'node:fs'; describe('CLIENT INFO', () => { + + const filePath = resolve(__dirname, "..", "..", "package.json"); + const data = readFileSync(filePath, "utf8"); + const version = JSON.parse(data).version; + testUtils.isVersionGreaterThanHook([6, 2]); it('transformArguments', () => {