From 37086eddb78cd0f0de66938de6188606dc2e36d8 Mon Sep 17 00:00:00 2001 From: Benjamin Wood <benjaminwood@gmail.com> Date: Fri, 14 Jul 2017 16:57:14 -0700 Subject: [PATCH 1/3] 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! --- index.js | 7 +++++-- lib/utils.js | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index c79f2dcff..04bb6c1d5 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ const wpwatch = require('./lib/wpwatch'); const cleanup = require('./lib/cleanup'); const run = require('./lib/run'); const serve = require('./lib/serve'); +const utils = require('./lib/utils'); const packExternalModules = require('./lib/packExternalModules'); class ServerlessWebpack { @@ -23,7 +24,8 @@ class ServerlessWebpack { cleanup, run, serve, - packExternalModules + packExternalModules, + utils ); this.commands = { @@ -90,7 +92,8 @@ class ServerlessWebpack { 'before:invoke:local:invoke': () => BbPromise.bind(this) .then(this.validate) - .then(this.compile), + .then(this.compile) + .then(this.makeProcessedInputPathAbsolutePath), 'webpack:validate': () => BbPromise.bind(this) .then(this.validate), diff --git a/lib/utils.js b/lib/utils.js index 38aca3db6..739dbbb2e 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,5 +1,8 @@ 'use strict'; +const BbPromise = require('bluebird'); +const path = require('path'); + function guid() { function s4() { return Math.floor((1 + Math.random()) * 0x10000) @@ -32,8 +35,18 @@ function searchCache(moduleName, callback) { } } +function makeProcessedInputPathAbsolutePath() { + var originalPath = this.serverless.config.serverless.processedInput.options.path + if (originalPath) { + var absolutePath = path.resolve(originalPath) + this.serverless.config.serverless.processedInput.options.path = absolutePath + } + return BbPromise.resolve(); +} + module.exports = { guid, purgeCache, searchCache, + makeProcessedInputPathAbsolutePath }; From 87160dcdd434c645c373d483afff9e7d24bff465 Mon Sep 17 00:00:00 2001 From: Benjamin Wood <benjaminwood@gmail.com> Date: Sun, 16 Jul 2017 19:58:32 -0700 Subject: [PATCH 2/3] Move execution building out of utils --- index.js | 6 +++--- lib/utils.js | 15 +-------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 04bb6c1d5..6b50a92a7 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ const wpwatch = require('./lib/wpwatch'); const cleanup = require('./lib/cleanup'); const run = require('./lib/run'); const serve = require('./lib/serve'); -const utils = require('./lib/utils'); +const makePathOptionAbsolute = require('./lib/makePathOptionAbsolute'); const packExternalModules = require('./lib/packExternalModules'); class ServerlessWebpack { @@ -25,7 +25,7 @@ class ServerlessWebpack { run, serve, packExternalModules, - utils + makePathOptionAbsolute ); this.commands = { @@ -93,7 +93,7 @@ class ServerlessWebpack { 'before:invoke:local:invoke': () => BbPromise.bind(this) .then(this.validate) .then(this.compile) - .then(this.makeProcessedInputPathAbsolutePath), + .then(this.makePathOptionAbsolute), 'webpack:validate': () => BbPromise.bind(this) .then(this.validate), diff --git a/lib/utils.js b/lib/utils.js index 739dbbb2e..e6e40564c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,8 +1,5 @@ 'use strict'; -const BbPromise = require('bluebird'); -const path = require('path'); - function guid() { function s4() { return Math.floor((1 + Math.random()) * 0x10000) @@ -35,18 +32,8 @@ function searchCache(moduleName, callback) { } } -function makeProcessedInputPathAbsolutePath() { - var originalPath = this.serverless.config.serverless.processedInput.options.path - if (originalPath) { - var absolutePath = path.resolve(originalPath) - this.serverless.config.serverless.processedInput.options.path = absolutePath - } - return BbPromise.resolve(); -} - module.exports = { guid, purgeCache, - searchCache, - makeProcessedInputPathAbsolutePath + searchCache }; From e7b43ed3008b368ddb725a2d53048c8e3efcdc7b Mon Sep 17 00:00:00 2001 From: Benjamin Wood <benjaminwood@gmail.com> Date: Sun, 16 Jul 2017 19:59:45 -0700 Subject: [PATCH 3/3] Add lib/makePathOptionAbsolute.js --- lib/makePathOptionAbsolute.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/makePathOptionAbsolute.js diff --git a/lib/makePathOptionAbsolute.js b/lib/makePathOptionAbsolute.js new file mode 100644 index 000000000..74976f344 --- /dev/null +++ b/lib/makePathOptionAbsolute.js @@ -0,0 +1,15 @@ +'use strict'; + +const BbPromise = require('bluebird'); +const path = require('path'); + +module.exports = { + makePathOptionAbsolute() { + const originalPath = this.serverless.config.serverless.processedInput.options.path; + if (originalPath) { + const absolutePath = path.resolve(originalPath); + this.serverless.config.serverless.processedInput.options.path = absolutePath; + }; + return BbPromise.resolve(); + } +};