From 11fcdc71864f1266fc742a5381a1f860c265d744 Mon Sep 17 00:00:00 2001 From: Hamit Burak Emre Date: Tue, 16 Jul 2019 18:28:14 +0300 Subject: [PATCH] Prioritize user aws sdk --- src/plugins/integrations/AWSIntegration.ts | 7 ++++--- src/plugins/utils/Utils.ts | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/plugins/integrations/AWSIntegration.ts b/src/plugins/integrations/AWSIntegration.ts index e1dc0238..2ef9bc34 100644 --- a/src/plugins/integrations/AWSIntegration.ts +++ b/src/plugins/integrations/AWSIntegration.ts @@ -27,6 +27,7 @@ const get = require('lodash.get'); const thundraWrapped = '__thundra_wrapped'; const moduleName = 'aws-sdk'; +const resolvePaths = ['/var/task']; class AWSIntegration implements Integration { version: string; @@ -41,9 +42,9 @@ class AWSIntegration implements Integration { this.version = '2.x'; this.wrappedFuncs = {}; this.config = config; - this.lib = Utils.tryRequire(moduleName); + this.lib = Utils.tryRequire(moduleName, resolvePaths); if (this.lib) { - const { basedir } = Utils.getModuleInfo(moduleName); + const { basedir } = Utils.getModuleInfo(moduleName, resolvePaths); if (!basedir) { ThundraLogger.getInstance().error(`Base directory is not found for the package ${moduleName}`); return; @@ -694,7 +695,7 @@ class AWSIntegration implements Integration { if (has(this.lib, 'Request.prototype.send') && has(this.lib, 'Request.prototype.promise')) { shimmer.unwrap(this.lib.Request.prototype, 'send'); shimmer.unwrap(this.lib.Request.prototype, 'promise'); - this.setWrapped(this.lib); + this.setUnwrapped(this.lib); } } } diff --git a/src/plugins/utils/Utils.ts b/src/plugins/utils/Utils.ts index f51cc38f..c07b6b16 100644 --- a/src/plugins/utils/Utils.ts +++ b/src/plugins/utils/Utils.ts @@ -209,16 +209,30 @@ class Utils { return endpoint.split('.')[0]; } - static tryRequire(name: string): any { + static tryRequire(name: string, paths?: string[]): any { try { - return require(name); + let resolvedPath; + if (paths !== undefined) { + resolvedPath = require.resolve(name, { paths }); + } else { + resolvedPath = require.resolve(name); + } + + return require(resolvedPath); // tslint:disable-next-line:no-empty } catch (err) {} } - static getModuleInfo(name: string): any { + static getModuleInfo(name: string, paths?: string[]): any { try { - return parse(require.resolve(name)); + let modulePath; + if (paths !== undefined) { + modulePath = require.resolve(name, { paths }); + } else { + modulePath = require.resolve(name); + } + + return parse(modulePath); } catch (err) { return {}; }