From 03e91ebb5ac6309807107fd9d37370be07a9688f Mon Sep 17 00:00:00 2001 From: foxriver76 Date: Sat, 27 Jul 2024 15:44:05 +0200 Subject: [PATCH] added fallback not only for request --- README.md | 1 + lib/sandbox.js | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2aa56f0a4..6134c7554 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Executes Javascript, Typescript Scripts. --> ### **WORK IN PROGRESS** * (@klein0r) Fixed right aligned script names when using multiple instances +* (foxriver76) added fallback for all require calls in scripts ### 8.7.4 (2024-07-27) * (foxriver76) added fallback to require the adapters `request` module if no own installed diff --git a/lib/sandbox.js b/lib/sandbox.js index 9aecea7f5..796ef1814 100644 --- a/lib/sandbox.js +++ b/lib/sandbox.js @@ -539,11 +539,13 @@ function sandBox(script, name, verbose, debug, context) { sandbox.log(`request package is deprecated - please use httpGet (or a stable lib like axios) instead!`, 'warn'); sandbox.__engine.__deprecatedWarnings.push(md); } + } - if (!mods[md]) { - // for backward compatibility we require the adapters own request module as back in the days this module did not need to be specified in the additional npm modules - mods[md] = require(md); - } + if (!mods[md]) { + // the user requires a module which is not specified in the additional node modules + // for backward compatibility we check if the module can simply be required directly before we fail (e.g. direct dependencies of javascript adapter) + adapter.log.debug(`Try direct require of "${md}" as not specified in the additional dependencies`); + mods[md] = require(md); } if (mods[md]) {