2017-07-17 01:52:52 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const path = require('path');
|
2017-08-03 15:23:54 +02:00
|
|
|
const _ = require('lodash');
|
2018-03-20 13:04:24 +01:00
|
|
|
const Utils = require('./utils');
|
2017-07-17 01:52:52 -07:00
|
|
|
|
|
|
|
|
module.exports = {
|
2017-08-05 13:35:36 +02:00
|
|
|
prepareLocalInvoke() {
|
2017-07-17 01:52:52 -07:00
|
|
|
const originalPath = this.serverless.config.serverless.processedInput.options.path;
|
|
|
|
|
if (originalPath) {
|
|
|
|
|
const absolutePath = path.resolve(originalPath);
|
|
|
|
|
this.serverless.config.serverless.processedInput.options.path = absolutePath;
|
2017-08-03 15:23:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set service path to compiled code for local invoke.
|
2017-08-05 13:35:36 +02:00
|
|
|
this.originalServicePath = this.serverless.config.servicePath;
|
2017-08-03 15:23:54 +02:00
|
|
|
if (_.get(this.serverless, 'service.package.individually')) {
|
|
|
|
|
this.serverless.config.servicePath = path.join(this.webpackOutputPath, this.options.function);
|
|
|
|
|
} else {
|
|
|
|
|
this.serverless.config.servicePath = path.join(this.webpackOutputPath, 'service');
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-05 13:35:36 +02:00
|
|
|
// Set service path as CWD to allow accessing bundled files correctly
|
|
|
|
|
process.chdir(this.serverless.config.servicePath);
|
|
|
|
|
|
2018-03-20 13:04:24 +01:00
|
|
|
// Remove handler from module cache to allow load of changed code.
|
|
|
|
|
const func = this.serverless.service.getFunction(this.options.function);
|
|
|
|
|
const handlerFile = path.join(
|
|
|
|
|
this.serverless.config.servicePath,
|
|
|
|
|
this.options.extraServicePath || '',
|
|
|
|
|
_.join(_.initial(_.split(func.handler, '.')), '.')
|
|
|
|
|
);
|
|
|
|
|
return Utils.purgeCache(handlerFile);
|
2017-07-17 01:52:52 -07:00
|
|
|
}
|
|
|
|
|
};
|