Files
serverless-webpack/lib/prepareLocalInvoke.js
T
Frank Schmid 7ed3803fb6 Change CWD before local invoke and restore it afterwards (#182)
* Change CWD before local invoke and restore it afterwards

* Adapted unit tests

* Renamed module
2017-08-05 13:35:36 +02:00

29 lines
987 B
JavaScript

'use strict';
const BbPromise = require('bluebird');
const path = require('path');
const _ = require('lodash');
module.exports = {
prepareLocalInvoke() {
const originalPath = this.serverless.config.serverless.processedInput.options.path;
if (originalPath) {
const absolutePath = path.resolve(originalPath);
this.serverless.config.serverless.processedInput.options.path = absolutePath;
}
// Set service path to compiled code for local invoke.
this.originalServicePath = this.serverless.config.servicePath;
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');
}
// Set service path as CWD to allow accessing bundled files correctly
process.chdir(this.serverless.config.servicePath);
return BbPromise.resolve();
}
};