From 60c9e53da04864383fc2d67bfe9bc74ab268f683 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Mon, 4 Jul 2022 00:25:30 +0800 Subject: [PATCH 1/2] fix: load CJS appenders for ESM projects --- lib/appenders/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/appenders/index.js b/lib/appenders/index.js index 3e26c12..aa81599 100644 --- a/lib/appenders/index.js +++ b/lib/appenders/index.js @@ -22,10 +22,18 @@ coreAppenders.set('tcp', require('./tcp')); const appenders = new Map(); const tryLoading = (modulePath, config) => { - debug('Loading module from ', modulePath); + let resolvedPath; + try { + const modulePathCJS = `${modulePath}.cjs`; + resolvedPath = require.resolve(modulePathCJS); + debug('Loading module from ', modulePathCJS); + } catch (e) { + resolvedPath = modulePath; + debug('Loading module from ', modulePath); + } try { // eslint-disable-next-line global-require, import/no-dynamic-require - return require(modulePath); + return require(resolvedPath); } catch (e) { // if the module was found, and we still got an error, then raise it configuration.throwExceptionIf( From 2ff151bdc7140119a779d69a96f9a5e901d370ed Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Mon, 4 Jul 2022 01:25:22 +0800 Subject: [PATCH 2/2] test: renamed dummy-appender.js to dummy-appender.cjs for test coverage --- test/tap/{dummy-appender.js => dummy-appender.cjs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/tap/{dummy-appender.js => dummy-appender.cjs} (100%) diff --git a/test/tap/dummy-appender.js b/test/tap/dummy-appender.cjs similarity index 100% rename from test/tap/dummy-appender.js rename to test/tap/dummy-appender.cjs