Skip to content

Commit

Permalink
fix #42
Browse files Browse the repository at this point in the history
  • Loading branch information
mj1618 committed Jul 29, 2019
1 parent d0ddfba commit 94cd3c0
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,39 +167,40 @@ class ServerlessOfflineSns {
this.log(`Creating topic: "${topicName}" for fn "${fnName}"`);
const data = await this.snsAdapter.createTopic(topicName);
this.debug("topic: " + JSON.stringify(data));
await this.snsAdapter.subscribe(fn, () => this.createHandler(fn), data.TopicArn, snsConfig);
await this.snsAdapter.subscribe(fn, this.createHandler(fn), data.TopicArn, snsConfig);
}

public createHandler(fn) {

// Options are passed from the command line in the options parameter
// ### OLD: use the main serverless config since this behavior is already supported there
if (!this.options.skipCacheInvalidation || Array.isArray(this.options.skipCacheInvalidation)) {
for (const key in require.cache) {

// don't invalidate cached modules from node_modules ...
if (key.match(/node_modules/)) {
continue;
}

// if an array is provided to the serverless config, check the entries there too
if (Array.isArray(this.options.skipCacheInvalidation) &&
this.options.skipCacheInvalidation.find(pattern => new RegExp(pattern).test(key))) {
continue;
return () => {
// Options are passed from the command line in the options parameter
// ### OLD: use the main serverless config since this behavior is already supported there
if (!this.options.skipCacheInvalidation || Array.isArray(this.options.skipCacheInvalidation)) {
for (const key in require.cache) {

// don't invalidate cached modules from node_modules ...
if (key.match(/node_modules/)) {
continue;
}

// if an array is provided to the serverless config, check the entries there too
if (Array.isArray(this.options.skipCacheInvalidation) &&
this.options.skipCacheInvalidation.find(pattern => new RegExp(pattern).test(key))) {
continue;
}

delete require.cache[key];
}

delete require.cache[key];
}
}

this.debug(process.cwd());
const handlerFnNameIndex = fn.handler.lastIndexOf(".");
const handlerPath = fn.handler.substring(0, handlerFnNameIndex);
const handlerFnName = fn.handler.substring(handlerFnNameIndex + 1);
const fullHandlerPath = resolve(this.location, handlerPath);
this.debug("require(" + fullHandlerPath + ")[" + handlerFnName + "]");
const handler = require(fullHandlerPath)[handlerFnName];
return handler;
this.debug(process.cwd());
const handlerFnNameIndex = fn.handler.lastIndexOf(".");
const handlerPath = fn.handler.substring(0, handlerFnNameIndex);
const handlerFnName = fn.handler.substring(handlerFnNameIndex + 1);
const fullHandlerPath = resolve(this.location, handlerPath);
this.debug("require(" + fullHandlerPath + ")[" + handlerFnName + "]");
const handler = require(fullHandlerPath)[handlerFnName];
return handler;
}
}

public log(msg, prefix = "INFO[serverless-offline-sns]: ") {
Expand Down

0 comments on commit 94cd3c0

Please sign in to comment.