diff --git a/packages/server/src/jsRunner/index.ts b/packages/server/src/jsRunner/index.ts index 362dde1fb2..c70c239c48 100644 --- a/packages/server/src/jsRunner/index.ts +++ b/packages/server/src/jsRunner/index.ts @@ -4,11 +4,12 @@ import { context } from "@budibase/backend-core" import tracer from "dd-trace" import { BuiltInVM, IsolatedVM } from "./vm" +const USE_ISOLATED_VM = true + export function init() { setJSRunner((js: string, ctx: Record) => { return tracer.trace("runJS", {}, span => { - const useIsolatedVm = env.ISOLATEDVM_JS_RUNNER - if (!useIsolatedVm) { + if (!USE_ISOLATED_VM) { const vm = new BuiltInVM(ctx, span) return vm.execute(js) } @@ -31,8 +32,7 @@ export function init() { bbCtx.vm = vm } - const result = vm.execute(js) - return result + return vm.execute(js) } catch (error: any) { if (error.message === "Script execution timed out.") { throw new JsErrorTimeout() diff --git a/packages/server/src/jsRunner/tests/jsRunner.spec.ts b/packages/server/src/jsRunner/tests/jsRunner.spec.ts index 18dc694b3c..30e29885b1 100644 --- a/packages/server/src/jsRunner/tests/jsRunner.spec.ts +++ b/packages/server/src/jsRunner/tests/jsRunner.spec.ts @@ -1,7 +1,4 @@ -import vm from "vm" - import { validate as isValidUUID } from "uuid" - import { processStringSync, encodeJSBinding } from "@budibase/string-templates" const { runJsHelpersTests } = require("@budibase/string-templates/test/utils") @@ -9,19 +6,13 @@ const { runJsHelpersTests } = require("@budibase/string-templates/test/utils") import tk from "timekeeper" import { init } from ".." import TestConfiguration from "../../tests/utilities/TestConfiguration" -import environment from "../../environment" tk.freeze("2021-01-21T12:00:00") -describe.each([ - ["vm", false], - ["isolated-vm", true], -])("jsRunner (using %s)", (_, useIsolatedVM) => { +describe("jsRunner (using isolated-vm)", () => { const config = new TestConfiguration() beforeAll(async () => { - environment._set("ISOLATEDVM_JS_RUNNER", useIsolatedVM) - // Register js runner init() await config.init() @@ -51,13 +42,7 @@ describe.each([ const output = await processJS( `return this.constructor.constructor("return process.env")()` ) - if (useIsolatedVM) { - expect(output).toBe("Error while executing JS") - } else { - // This was not an issue without isolated-vm - expect(output).not.toBe("Error while executing JS") - expect(output).toEqual(process.env) - } + expect(output).toBe("Error while executing JS") }) describe("helpers", () => { diff --git a/packages/server/src/threads/query.ts b/packages/server/src/threads/query.ts index 2c8e59ce64..1f28034f60 100644 --- a/packages/server/src/threads/query.ts +++ b/packages/server/src/threads/query.ts @@ -18,7 +18,8 @@ import { Datasource, Query, SourceName, VM } from "@budibase/types" import { isSQL } from "../integrations/utils" import { interpolateSQL } from "../integrations/queries/sql" -import environment from "../environment" + +const USE_ISOLATED_VM = true class QueryRunner { datasource: Datasource @@ -129,7 +130,7 @@ class QueryRunner { // transform as required if (transformer) { let runner: VM - if (!environment.ISOLATEDVM_QUERY_TRANSFORMERS) { + if (!USE_ISOLATED_VM) { runner = new VM2({ data: rows, params: enrichedParameters,