Skip to content

Commit e3031e5

Browse files
benjaminwoodFrank Schmid
authored and
Frank Schmid
committed
Make processed input path absolute (#156)
* Make processed input path absolute When using the invoke local command with the --path (-p) flag, relative file paths will not be found because serverless will end up looking in the build directory later on. So, this commit ensures that the path is absolute, ensuring it will be found, even if the path was relative. Couldn't think of a good name for the function. Also, I'm not sure that this should go in the utils file. Happy to make revisions! * Move execution building out of utils * Add lib/makePathOptionAbsolute.js
1 parent dc9e551 commit e3031e5

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const wpwatch = require('./lib/wpwatch');
99
const cleanup = require('./lib/cleanup');
1010
const run = require('./lib/run');
1111
const serve = require('./lib/serve');
12+
const makePathOptionAbsolute = require('./lib/makePathOptionAbsolute');
1213
const packExternalModules = require('./lib/packExternalModules');
1314
const lib = require('./lib');
1415

@@ -40,7 +41,8 @@ class ServerlessWebpack {
4041
cleanup,
4142
run,
4243
serve,
43-
packExternalModules
44+
packExternalModules,
45+
makePathOptionAbsolute
4446
);
4547

4648
this.commands = {
@@ -115,7 +117,8 @@ class ServerlessWebpack {
115117

116118
'before:invoke:local:invoke': () => BbPromise.bind(this)
117119
.then(this.validate)
118-
.then(this.compile),
120+
.then(this.compile)
121+
.then(this.makePathOptionAbsolute),
119122

120123
'webpack:validate': () => BbPromise.bind(this)
121124
.then(this.validate),

lib/makePathOptionAbsolute.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
const BbPromise = require('bluebird');
4+
const path = require('path');
5+
6+
module.exports = {
7+
makePathOptionAbsolute() {
8+
const originalPath = this.serverless.config.serverless.processedInput.options.path;
9+
if (originalPath) {
10+
const absolutePath = path.resolve(originalPath);
11+
this.serverless.config.serverless.processedInput.options.path = absolutePath;
12+
};
13+
return BbPromise.resolve();
14+
}
15+
};

lib/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ function searchCache(moduleName, callback) {
3535
module.exports = {
3636
guid,
3737
purgeCache,
38-
searchCache,
38+
searchCache
3939
};

0 commit comments

Comments
 (0)