From 7fa68731d250ad8d2faf4f2d5efed915fa509307 Mon Sep 17 00:00:00 2001 From: DaPutzy <9727551+DaPutzy@users.noreply.github.com> Date: Wed, 25 Oct 2023 23:16:28 +0000 Subject: [PATCH] feat: allow multiple script context roots --- packages/bruno-js/src/runtime/script-runtime.js | 7 ++++++- packages/bruno-js/src/runtime/test-runtime.js | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/bruno-js/src/runtime/script-runtime.js b/packages/bruno-js/src/runtime/script-runtime.js index 391d047d..a39e00a5 100644 --- a/packages/bruno-js/src/runtime/script-runtime.js +++ b/packages/bruno-js/src/runtime/script-runtime.js @@ -46,6 +46,11 @@ class ScriptRuntime { const req = new BrunoRequest(request); const allowScriptFilesystemAccess = get(scriptingConfig, 'filesystemAccess.allow', false); const moduleWhitelist = get(scriptingConfig, 'moduleWhitelist', []); + const additionalContextRoots = get(scriptingConfig, 'additionalContextRoots', []); + const additionalContextRootsAbsolute = lodash + .chain(additionalContextRoots) + .map((acr) => (acr.startsWith('/') ? acr : path.join(collectionPath, acr))) + .value(); const whitelistedModules = {}; @@ -83,7 +88,7 @@ class ScriptRuntime { require: { context: 'sandbox', external: true, - root: [collectionPath], + root: [collectionPath, ...additionalContextRootsAbsolute], mock: { // node libs path, diff --git a/packages/bruno-js/src/runtime/test-runtime.js b/packages/bruno-js/src/runtime/test-runtime.js index 9da2cb28..fcaa750c 100644 --- a/packages/bruno-js/src/runtime/test-runtime.js +++ b/packages/bruno-js/src/runtime/test-runtime.js @@ -48,6 +48,11 @@ class TestRuntime { const res = new BrunoResponse(response); const allowScriptFilesystemAccess = get(scriptingConfig, 'filesystemAccess.allow', false); const moduleWhitelist = get(scriptingConfig, 'moduleWhitelist', []); + const additionalContextRoots = get(scriptingConfig, 'additionalContextRoots', []); + const additionalContextRootsAbsolute = lodash + .chain(additionalContextRoots) + .map((acr) => (acr.startsWith('/') ? acr : path.join(collectionPath, acr))) + .value(); const whitelistedModules = {}; @@ -101,7 +106,7 @@ class TestRuntime { require: { context: 'sandbox', external: true, - root: [collectionPath], + root: [collectionPath, ...additionalContextRootsAbsolute], mock: { // node libs path,