From 781832a52a6bd7bcefda60f027717b0853fe214d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 13 Sep 2022 12:16:00 +0100 Subject: [PATCH] Fixing issue with plugin import for datasources - extract the integration correctly. --- packages/server/src/integrations/index.ts | 7 ++++++- packages/server/src/utilities/fileSystem/index.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/server/src/integrations/index.ts b/packages/server/src/integrations/index.ts index 007b7e91e6..000ab65a33 100644 --- a/packages/server/src/integrations/index.ts +++ b/packages/server/src/integrations/index.ts @@ -94,11 +94,16 @@ module.exports = { for (let plugin of plugins) { if (plugin.name === integration) { // need to use commonJS require due to its dynamic runtime nature - return getDatasourcePlugin( + const retrieved: any = await getDatasourcePlugin( plugin.name, plugin.jsUrl, plugin.schema?.hash ) + if (retrieved.integration) { + return retrieved.integration + } else { + return retrieved + } } } } diff --git a/packages/server/src/utilities/fileSystem/index.js b/packages/server/src/utilities/fileSystem/index.js index 40cc456356..1001cdcdb1 100644 --- a/packages/server/src/utilities/fileSystem/index.js +++ b/packages/server/src/utilities/fileSystem/index.js @@ -415,7 +415,7 @@ exports.getDatasourcePlugin = async (name, url, hash) => { const content = await response.text() fs.writeFileSync(filename, content) fs.writeFileSync(metadataName, hash) - require(filename) + return require(filename) } else { throw new Error( `Unable to retrieve plugin - reason: ${await response.text()}`