Skip to content

Commit

Permalink
fix: handle importing custom helper nicely (#3691)
Browse files Browse the repository at this point in the history
* fix: handle importing custom helper nicely

* fix: address CR
  • Loading branch information
kobenguyent committed Jul 2, 2023
1 parent 4891132 commit 49d1cf6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 49d1cf6

Please sign in to comment.