Skip to content

Commit 9b08d16

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 c524401 commit 9b08d16

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 {
@@ -32,7 +33,8 @@ class ServerlessWebpack {
3233
cleanup,
3334
run,
3435
serve,
35-
packExternalModules
36+
packExternalModules,
37+
makePathOptionAbsolute
3638
);
3739

3840
this.commands = {
@@ -99,7 +101,8 @@ class ServerlessWebpack {
99101

100102
'before:invoke:local:invoke': () => BbPromise.bind(this)
101103
.then(this.validate)
102-
.then(this.compile),
104+
.then(this.compile)
105+
.then(this.makePathOptionAbsolute),
103106

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