From 8a8c448e0901865b0bd776d9ba4f06ef23aba81b Mon Sep 17 00:00:00 2001 From: Jairo Panduro Date: Mon, 21 Jul 2025 14:13:23 +0200 Subject: [PATCH 1/4] ref: STRF-13460 Refactor 3p modules import --- helpers/thirdParty.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/helpers/thirdParty.js b/helpers/thirdParty.js index 9854a629..380ba390 100644 --- a/helpers/thirdParty.js +++ b/helpers/thirdParty.js @@ -1,5 +1,20 @@ 'use strict'; +const thirdPartyHelpers = { + array: require('./3p/array'), + collection: require('./3p/collection'), + comparison: require('./3p/comparison'), + html: require('./3p/html'), + inflection: require('./3p/inflection'), + markdown: require('./3p/markdown'), + math: require('./3p/math'), + misc: require('./3p/misc'), + number: require('./3p/number'), + object: require('./3p/object'), + string: require('./3p/string'), + url: require('./3p/url'), +}; + const whitelist = [ { name: 'array', @@ -32,7 +47,6 @@ const whitelist = [ }, { name: 'comparison', - module: require('./3p/comparison'), include: [ 'and', 'gt', @@ -104,7 +118,6 @@ const whitelist = [ }, { name: 'string', - module: require('./3p/string'), include: [ 'camelcase', 'capitalize', @@ -140,12 +153,7 @@ const whitelist = [ const exportedHelpers = []; for (let i = 0; i < whitelist.length; i++) { const spec = whitelist[i]; - - // Initialize module - const module = require(`./3p/${spec.name}`); - if (typeof spec.init === 'function') { - spec.init(module); - } + const module = thirdPartyHelpers[spec.name]; // Pluck whitelisted functions from each helper module and wrap in object of expected format const moduleWhitelist = spec.include; From 19c6a2787d905069ba05f38f0367971f5d8628d0 Mon Sep 17 00:00:00 2001 From: Jairo Panduro Date: Tue, 29 Jul 2025 12:51:09 +0200 Subject: [PATCH 2/4] give helpers --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 84272c79..49b19307 100644 --- a/index.js +++ b/index.js @@ -81,6 +81,10 @@ class HandlebarsRenderer { this.overrideHelpers(); } + getHelpersForExternalUse() { + return helpers; + } + getResourceHints() { return this.helperContext.resourceHints; } From 44d2201fefd7f5cc0ff6aac17b42ceaabe769ccf Mon Sep 17 00:00:00 2001 From: Jairo Panduro Date: Fri, 12 Dec 2025 16:45:03 +0100 Subject: [PATCH 3/4] STRF-13946 Add Handlebars runtime option --- index.js | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 49b19307..04b3c7d0 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ 'use strict'; const HandlebarsV3 = require('handlebars'); const HandlebarsV4 = require('@bigcommerce/handlebars-v4'); +const HandlebarsV4Runtime = require('@bigcommerce/handlebars-v4').runtime; const helpers = require('./helpers'); const AppError = require('./lib/appError'); @@ -39,6 +40,9 @@ class HandlebarsRenderer { constructor(siteSettings, themeSettings, hbVersion, logger = console, logLevel = 'info', params = {}) { // Figure out which version of Handlebars to use. switch(hbVersion) { + case 'v4-runtime': + this.handlebars = HandlebarsV4Runtime; + break; case 'v4': this.handlebars = HandlebarsV4.create(); break; diff --git a/package.json b/package.json index 93dd89bd..bc955146 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ }, "homepage": "https://github.com/bigcommerce/paper-handlebars", "dependencies": { - "@bigcommerce/handlebars-v4": "4.7.8", + "@bigcommerce/handlebars-v4": "4.8.0", "chrono-node": "2.8.0", "handlebars": "3.0.8", "he": "^1.2.0", From e16c653d9ec9450c346496fcb10c9d86aa2ca916 Mon Sep 17 00:00:00 2001 From: Jairo Panduro Date: Fri, 12 Dec 2025 18:33:48 +0100 Subject: [PATCH 4/4] expose HandlebarsRuntime --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 04b3c7d0..af6942f6 100644 --- a/index.js +++ b/index.js @@ -437,3 +437,4 @@ class HandlebarsRenderer { } module.exports = HandlebarsRenderer; +module.exports.HandlebarsRuntime = HandlebarsV4Runtime;