From 49d1cf6c91387bd0d5477ab9721c7f69e721dda1 Mon Sep 17 00:00:00 2001 From: KobeNguyenT <7845001+kobenguyent@users.noreply.github.com> Date: Sun, 2 Jul 2023 10:41:56 +0200 Subject: [PATCH] fix: handle importing custom helper nicely (#3691) * fix: handle importing custom helper nicely * fix: address CR --- lib/container.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/container.js b/lib/container.js index 23e040106..37e8a2b59 100644 --- a/lib/container.js +++ b/lib/container.js @@ -165,7 +165,16 @@ function createHelpers(config) { } else { moduleName = `./helper/${helperName}`; // built-in helper } - const HelperClass = require(moduleName); + + // @ts-ignore + let HelperClass; + // check if the helper is the built-in, use the require() syntax. + if (moduleName.startsWith('./helper/')) { + HelperClass = require(moduleName); } + else { + // check if the new syntax export default HelperName is used and loads the Helper, otherwise loads the module that used old syntax export = HelperName. + HelperClass = require(moduleName).default || require(moduleName); } + if (HelperClass._checkRequirements) { const requirements = HelperClass._checkRequirements(); if (requirements) { @@ -351,8 +360,8 @@ function loadSupportObject(modulePath, supportObjectName) { } } if (typeof obj !== 'function' - && Object.getPrototypeOf(obj) !== Object.prototype - && !Array.isArray(obj) + && Object.getPrototypeOf(obj) !== Object.prototype + && !Array.isArray(obj) ) { const methods = getObjectMethods(obj); Object.keys(methods)