Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving design section JS binding performance #15431

Merged
merged 9 commits into from
Jan 24, 2025
1 change: 1 addition & 0 deletions packages/string-templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"dependencies": {
"@budibase/handlebars-helpers": "^0.13.2",
"@budibase/vm-browserify": "^1.1.4",
"dayjs": "^1.10.8",
"handlebars": "^4.7.8",
"lodash.clonedeep": "^4.5.0"
Expand Down
15 changes: 8 additions & 7 deletions packages/string-templates/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createContext, runInNewContext } from "vm"
import browserVM from "@budibase/vm-browserify"
import vm from "vm"
import { create, TemplateDelegate } from "handlebars"
import { registerAll, registerMinimum } from "./helpers/index"
import { postprocess, postprocessWithLogs, preprocess } from "./processors"
Expand All @@ -14,10 +15,10 @@ import {
} from "./utilities"
import { convertHBSBlock } from "./conversion"
import { removeJSRunner, setJSRunner } from "./helpers/javascript"

import manifest from "./manifest.json"
import { Log, ProcessOptions } from "./types"
import { UserScriptError } from "./errors"
import { isTest } from "./environment"

export type { Log, LogType } from "./types"
export { setTestingBackendJS } from "./environment"
Expand Down Expand Up @@ -507,15 +508,15 @@ export function convertToJS(hbs: string) {
export { JsTimeoutError, UserScriptError } from "./errors"

export function browserJSSetup() {
/**
* Use polyfilled vm to run JS scripts in a browser Env
*/
// tests are in jest - we need to use node VM for these
const jsSandbox = isTest() ? vm : browserVM
// Use polyfilled vm to run JS scripts in a browser Env
setJSRunner((js: string, context: Record<string, any>) => {
createContext(context)
jsSandbox.createContext(context)

const wrappedJs = frontendWrapJS(js)

const result = runInNewContext(wrappedJs, context, { timeout: 1000 })
const result = jsSandbox.runInNewContext(wrappedJs, context)
if (result.error) {
throw new UserScriptError(result.error)
}
Expand Down
18 changes: 15 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2131,9 +2131,9 @@
through2 "^2.0.0"

"@budibase/pro@npm:@budibase/pro@latest":
version "3.2.44"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-3.2.44.tgz#90367bb2167aafd8c809e000a57d349e5dc4bb78"
integrity sha512-Zv2PBVUZUS6/psOpIRIDlW3jrOHWWPhpQXzCk00kIQJaqjkdcvuTXSedQ70u537sQmLu8JsSWbui9MdfF8ksVw==
version "3.2.47"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-3.2.47.tgz#150d7b16b14932d03c84bdb0e6d570d490c28a5c"
integrity sha512-UeTIq7yzMUK6w/akUsRafoD/Kif6PXv4d7K1arn8GTMjwFm9QYu2hg1YkQ+duNdwyZ/GEPlEAV5SYK+NDgtpdA==
dependencies:
"@anthropic-ai/sdk" "^0.27.3"
"@budibase/backend-core" "*"
Expand All @@ -2152,6 +2152,13 @@
scim-patch "^0.8.1"
scim2-parse-filter "^0.2.8"

"@budibase/vm-browserify@^1.1.4":
version "1.1.4"
resolved "https://registry.yarnpkg.com/@budibase/vm-browserify/-/vm-browserify-1.1.4.tgz#eecb001bd9521cb7647e26fb4d2d29d0a4dce262"
integrity sha512-/dyOLj+jQNKe6sVfLP6NdwA79OZxEWHCa41VGsjKJC9DYo6l2fEcL5BNXq2pATqrbgWmOlEbcRulfZ+7W0QRUg==
dependencies:
indexof "^0.0.1"

"@bull-board/[email protected]":
version "5.10.2"
resolved "https://registry.yarnpkg.com/@bull-board/api/-/api-5.10.2.tgz#ae8ff6918b23897bf879a6ead3683f964374c4b3"
Expand Down Expand Up @@ -11925,6 +11932,11 @@ indexes-of@^1.0.1:
resolved "https://registry.yarnpkg.com/indexes-of/-/indexes-of-1.0.1.tgz#f30f716c8e2bd346c7b67d3df3915566a7c05607"
integrity sha512-bup+4tap3Hympa+JBJUG7XuOsdNQ6fxt0MHyXMKuLBKn0OqsTfvUxkUrroEX1+B2VsSHvCjiIcZVxRtYa4nllA==

indexof@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/indexof/-/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d"
integrity sha512-i0G7hLJ1z0DE8dsqJa2rycj9dBmNKgXBvotXtZYXakU9oivfB9Uj2ZBC27qqef2U58/ZLwalxa1X/RDCdkHtVg==

infer-owner@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/infer-owner/-/infer-owner-1.0.4.tgz#c4cefcaa8e51051c2a40ba2ce8a3d27295af9467"
Expand Down
Loading