From 4aa583e30a9acc3dc8060ebb71659e78c8c691d8 Mon Sep 17 00:00:00 2001 From: Ron Cohen Date: Sun, 19 Apr 2026 13:47:34 +0200 Subject: [PATCH 1/3] fix(node-sdk): honor REFLAG_CONFIG_FILE path --- packages/node-sdk/src/client.ts | 12 ++++++-- packages/node-sdk/test/client.test.ts | 42 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/packages/node-sdk/src/client.ts b/packages/node-sdk/src/client.ts index 89735ba2..1bcfbe71 100644 --- a/packages/node-sdk/src/client.ts +++ b/packages/node-sdk/src/client.ts @@ -387,12 +387,18 @@ export class ReflagClient { "flagsPushUrl must be a non-empty string", ); + const envConfigFile = + typeof process.env.REFLAG_CONFIG_FILE === "string" && + process.env.REFLAG_CONFIG_FILE.length > 0 + ? process.env.REFLAG_CONFIG_FILE + : undefined; + if (!options.configFile) { options.configFile = - (process.env.REFLAG_CONFIG_FILE ?? - fs.existsSync(reflagConfigDefaultFile)) + envConfigFile ?? + (fs.existsSync(reflagConfigDefaultFile) ? reflagConfigDefaultFile - : undefined; + : undefined); } const externalConfig = loadConfig(options.configFile); diff --git a/packages/node-sdk/test/client.test.ts b/packages/node-sdk/test/client.test.ts index e2cf65cb..5daee05e 100644 --- a/packages/node-sdk/test/client.test.ts +++ b/packages/node-sdk/test/client.test.ts @@ -1,3 +1,7 @@ +import { mkdtempSync, rmSync, writeFileSync } from "fs"; +import os from "os"; +import path from "path"; + import flushPromises from "flush-promises"; import { afterEach, @@ -261,6 +265,44 @@ describe("ReflagClient", () => { }); }); + it("should use the REFLAG_CONFIG_FILE path when set", () => { + const tempDir = mkdtempSync(path.join(os.tmpdir(), "reflag-node-sdk-")); + const originalCwd = process.cwd(); + const originalConfigFile = process.env.REFLAG_CONFIG_FILE; + const defaultConfigFile = path.join(tempDir, "reflag.config.json"); + const customConfigFile = path.join(tempDir, "custom.reflag.config.json"); + + writeFileSync( + defaultConfigFile, + JSON.stringify({ apiBaseUrl: "https://default-config.example/" }), + ); + writeFileSync( + customConfigFile, + JSON.stringify({ apiBaseUrl: "https://custom-config.example/" }), + ); + + process.chdir(tempDir); + process.env.REFLAG_CONFIG_FILE = customConfigFile; + + try { + const client = new ReflagClient({ + offline: true, + }); + + expect(client["_config"].apiBaseUrl).toBe( + "https://custom-config.example/", + ); + } finally { + process.chdir(originalCwd); + if (originalConfigFile === undefined) { + delete process.env.REFLAG_CONFIG_FILE; + } else { + process.env.REFLAG_CONFIG_FILE = originalConfigFile; + } + rmSync(tempDir, { recursive: true, force: true }); + } + }); + it("should create a client instance with valid options", () => { const client = new ReflagClient(validOptions); From e0e42d335373a0f1e33427f6b088cec201aae08a Mon Sep 17 00:00:00 2001 From: Ron Cohen Date: Sun, 19 Apr 2026 13:59:20 +0200 Subject: [PATCH 2/3] chore(changeset): add node-sdk release note --- .changeset/node-sdk-config-file-env-path.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/node-sdk-config-file-env-path.md diff --git a/.changeset/node-sdk-config-file-env-path.md b/.changeset/node-sdk-config-file-env-path.md new file mode 100644 index 00000000..09269542 --- /dev/null +++ b/.changeset/node-sdk-config-file-env-path.md @@ -0,0 +1,5 @@ +--- +"@reflag/node-sdk": patch +--- + +Fix `REFLAG_CONFIG_FILE` handling so the SDK loads the config file from the path provided by the environment variable. From 2f281f3b472e99f0898aab6b0974ad05712fd0eb Mon Sep 17 00:00:00 2001 From: Ron Cohen Date: Sun, 19 Apr 2026 14:14:25 +0200 Subject: [PATCH 3/3] test(node-sdk): avoid chdir in config env test --- packages/node-sdk/test/client.test.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/node-sdk/test/client.test.ts b/packages/node-sdk/test/client.test.ts index 5daee05e..98ab44fc 100644 --- a/packages/node-sdk/test/client.test.ts +++ b/packages/node-sdk/test/client.test.ts @@ -267,21 +267,14 @@ describe("ReflagClient", () => { it("should use the REFLAG_CONFIG_FILE path when set", () => { const tempDir = mkdtempSync(path.join(os.tmpdir(), "reflag-node-sdk-")); - const originalCwd = process.cwd(); const originalConfigFile = process.env.REFLAG_CONFIG_FILE; - const defaultConfigFile = path.join(tempDir, "reflag.config.json"); const customConfigFile = path.join(tempDir, "custom.reflag.config.json"); - writeFileSync( - defaultConfigFile, - JSON.stringify({ apiBaseUrl: "https://default-config.example/" }), - ); writeFileSync( customConfigFile, JSON.stringify({ apiBaseUrl: "https://custom-config.example/" }), ); - process.chdir(tempDir); process.env.REFLAG_CONFIG_FILE = customConfigFile; try { @@ -293,7 +286,6 @@ describe("ReflagClient", () => { "https://custom-config.example/", ); } finally { - process.chdir(originalCwd); if (originalConfigFile === undefined) { delete process.env.REFLAG_CONFIG_FILE; } else {