From b4e1d6c9748c0d67381b5ac5e043a59675aaff56 Mon Sep 17 00:00:00 2001 From: Roman Kuznetsov Date: Thu, 7 Mar 2024 14:16:18 +0300 Subject: [PATCH] feat: add ability to use default export in .hermione.conf file --- src/config/index.ts | 5 ++++- test/src/config/index.js | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/config/index.ts b/src/config/index.ts index 384bf6b6f..2f7432ff3 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -15,7 +15,10 @@ export class Config { static read(configPath: string): unknown { try { - return require(path.resolve(process.cwd(), configPath)); + // eslint-disable-next-line @typescript-eslint/no-var-requires + const configModule = require(path.resolve(process.cwd(), configPath)); + + return configModule.__esModule ? configModule.default : configModule; } catch (e) { logger.error(`Unable to read config from path ${configPath}`); throw e; diff --git a/test/src/config/index.js b/test/src/config/index.js index b97eed8c1..55a39d652 100644 --- a/test/src/config/index.js +++ b/test/src/config/index.js @@ -43,6 +43,12 @@ describe("config", () => { assert.calledWithMatch(parseOptions, { options: "some-options", env: process.env, argv: process.argv }); }); + it("should support default export", () => { + initConfig({ requireConfigReturns: { __esModule: true, default: { foo: "bar" } } }); + + assert.calledWithMatch(parseOptions, { options: { foo: "bar" }, env: process.env, argv: process.argv }); + }); + it("should parse config from object", () => { initConfig({ config: { someOption: "some-value" } });