Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Prioritize user aws sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
hamitb committed Jul 16, 2019
1 parent 3c817ef commit 11fcdc7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/plugins/integrations/AWSIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
22 changes: 18 additions & 4 deletions src/plugins/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
Expand Down

0 comments on commit 11fcdc7

Please sign in to comment.