From 16ca7bbc45f06c137bfc4528cf7ee57011201849 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 21 Feb 2024 22:35:30 +0100 Subject: [PATCH] Fix requires --- packages/string-templates/src/helpers/list.ts | 6 +++--- packages/string-templates/src/index.ts | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/string-templates/src/helpers/list.ts b/packages/string-templates/src/helpers/list.ts index fde42b659a..7b25216976 100644 --- a/packages/string-templates/src/helpers/list.ts +++ b/packages/string-templates/src/helpers/list.ts @@ -1,7 +1,7 @@ import { date, duration } from "./date" // https://github.com/evanw/esbuild/issues/56 -const externalCollections: Record any> = { +const getExternalCollections = (): Record any> => ({ math: require("@budibase/handlebars-helpers/lib/math"), array: require("@budibase/handlebars-helpers/lib/array"), number: require("@budibase/handlebars-helpers/lib/number"), @@ -11,7 +11,7 @@ const externalCollections: Record any> = { object: require("@budibase/handlebars-helpers/lib/object"), regex: require("@budibase/handlebars-helpers/lib/regex"), uuid: require("@budibase/handlebars-helpers/lib/uuid"), -} +}) export const helpersToRemoveForJs = ["sortBy"] @@ -28,7 +28,7 @@ export function getJsHelperList() { } helpers = {} - for (let collection of Object.values(externalCollections)) { + for (let collection of Object.values(getExternalCollections())) { for (let [key, func] of Object.entries(collection)) { // Handlebars injects the hbs options to the helpers by default. We are adding an empty {} as a last parameter to simulate it helpers[key] = (...props) => func(...props, {}) diff --git a/packages/string-templates/src/index.ts b/packages/string-templates/src/index.ts index 3a38c7868f..354af0f612 100644 --- a/packages/string-templates/src/index.ts +++ b/packages/string-templates/src/index.ts @@ -1,9 +1,9 @@ +import fs from "fs" import { createContext, runInNewContext } from "vm" import { create } from "handlebars" import { registerAll, registerMinimum } from "./helpers/index" import { preprocess, postprocess } from "./processors" import { atob, btoa, isBackendService } from "./utilities" -const manifest = require("../manifest.json") import { FIND_HBS_REGEX, FIND_ANY_HBS_REGEX, @@ -252,7 +252,11 @@ export function isValid(string, opts) { * This manifest provides information about each of the helpers and how it can be used. * @returns The manifest JSON which has been generated from the helpers. */ +let manifest export function getManifest() { + if (!manifest) { + manifest = fs.readFileSync(require.resolve("../manifest.json"), "utf-8") + } return manifest }