Skip to content

Commit 05f076f

Browse files
benjaminwoodHyperBrain
authored andcommitted
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 49dda48 commit 05f076f

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
@@ -8,6 +8,7 @@ const wpwatch = require('./lib/wpwatch');
88
const cleanup = require('./lib/cleanup');
99
const run = require('./lib/run');
1010
const serve = require('./lib/serve');
11+
const makePathOptionAbsolute = require('./lib/makePathOptionAbsolute');
1112
const packExternalModules = require('./lib/packExternalModules');
1213

1314
class ServerlessWebpack {
@@ -23,7 +24,8 @@ class ServerlessWebpack {
2324
cleanup,
2425
run,
2526
serve,
26-
packExternalModules
27+
packExternalModules,
28+
makePathOptionAbsolute
2729
);
2830

2931
this.commands = {
@@ -90,7 +92,8 @@ class ServerlessWebpack {
9092

9193
'before:invoke:local:invoke': () => BbPromise.bind(this)
9294
.then(this.validate)
93-
.then(this.compile),
95+
.then(this.compile)
96+
.then(this.makePathOptionAbsolute),
9497

9598
'webpack:validate': () => BbPromise.bind(this)
9699
.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)