Skip to content

Commit

Permalink
fix: Defer loading @iopipe/core (#45, #64)
Browse files Browse the repository at this point in the history
Merge pull request #66 from mrickard/issue/45-fix-local-invocation-failure
  • Loading branch information
mrickard authored Jul 12, 2019
2 parents 8f4058e + 0c0304e commit 3a63dbf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
"aws-lambda-mock-context": "^3.2.1",
"lodash": "^4.17.11",
"nock": "^9.4.1",
"pre-commit": "^1.2.2"
"pre-commit": "^1.2.2",
"@iopipe/core": "^1.19.1"
},
"dependencies": {
"@iopipe/core": "^1.19.1",
"archiver": "^2.1.1",
"lodash.get": "^4.4.2",
"simple-get": "^3.0.3"
Expand Down
14 changes: 10 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { promisify } from 'util';
import * as inspector from 'inspector';
import get from 'lodash.get';
import * as archiver from 'archiver';
import { util as coreUtil } from '@iopipe/core';
import { concat } from 'simple-get';

import enabled from './enabled';

const request = promisify(concat);
Expand Down Expand Up @@ -58,6 +56,8 @@ class ProfilerPlugin {
});
};

this.coreUtil = null;

return this;
}

Expand Down Expand Up @@ -107,7 +107,13 @@ class ProfilerPlugin {
}
}

getFileUploadMeta() {
async getFileUploadMeta() {
// patch for potential circular dependency with core
if (!this.coreUtil) {
const core = await require('@iopipe/core');
this.coreUtil = core.util;
}

// returns a promise here
let { invokedFunctionArn: arn } = this.invocationInstance.context;

Expand All @@ -120,7 +126,7 @@ class ProfilerPlugin {
arn = `arn:aws:lambda:local:0:function:${functionName}`;
}

return coreUtil.getFileUploadMeta({
return this.coreUtil.getFileUploadMeta({
auth: this.token,
networkTimeout: this.config.networkTimeout,
arn,
Expand Down

0 comments on commit 3a63dbf

Please sign in to comment.