add scripts context to response scripts

This commit is contained in:
Carlos Florêncio 2024-01-16 14:39:56 +00:00
parent b5fccef417
commit 8426c585a4

View File

@ -144,6 +144,11 @@ class ScriptRuntime {
const res = new BrunoResponse(response); const res = new BrunoResponse(response);
const allowScriptFilesystemAccess = get(scriptingConfig, 'filesystemAccess.allow', false); const allowScriptFilesystemAccess = get(scriptingConfig, 'filesystemAccess.allow', false);
const moduleWhitelist = get(scriptingConfig, 'moduleWhitelist', []); 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 = {}; const whitelistedModules = {};
@ -181,7 +186,7 @@ class ScriptRuntime {
require: { require: {
context: 'sandbox', context: 'sandbox',
external: true, external: true,
root: [collectionPath], root: [collectionPath, ...additionalContextRootsAbsolute],
mock: { mock: {
// node libs // node libs
path, path,