Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make processed input path absolute #156

Merged
merged 3 commits into from
Jul 17, 2017
Merged

Make processed input path absolute #156

merged 3 commits into from
Jul 17, 2017

Conversation

benjaminwood
Copy link
Contributor

@benjaminwood benjaminwood commented Jul 15, 2017

What did you implement:

Related: #151

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 PR ensures that the path is absolute, ensuring it will be found, even if the path was relative.

How did you implement it:

I added a function in utils.js that gets the --path option if present. It then uses path.resolve to resolve it, then assigns it back to serverless config.

How can we verify it:

Just use invoke local with the --path option:

serverless invoke local -f function_name --path data.json

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors (not yet implemented)
  • Make sure code coverage hasn't dropped (not yet implemented)
  • Provide verification config / commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: NO

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!
@benjaminwood
Copy link
Contributor Author

I'm thinking that makeProcessedInputPathAbsolutePath may not belong in utils. Should I create a file for this in the spirit of compile and validate? It'd be more consistent that way, it just seems like such a small thing, limited usefulness to invoke local... thoughts?

@HyperBrain
Copy link
Member

Yes, agree. makeProcessedInputPathAbsolutePath is not an utility function. It is a execution building block needed to execute invoke local. So an own file would be the best solution.

Copy link
Member

@HyperBrain HyperBrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As soon as you moved it to its own file, you also should add unit tests for the feature that check the resulting output of the function with various inputs.

Just thought about unit tests. I will take care of them - as this PR is only a correction of the main PR :)

lib/utils.js Outdated
@@ -32,8 +35,18 @@ function searchCache(moduleName, callback) {
}
}

function makeProcessedInputPathAbsolutePath() {
var originalPath = this.serverless.config.serverless.processedInput.options.path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be const instead of var. Also a missing semicolon.

lib/utils.js Outdated
function makeProcessedInputPathAbsolutePath() {
var originalPath = this.serverless.config.serverless.processedInput.options.path
if (originalPath) {
var absolutePath = path.resolve(originalPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const and semicolon.

Did you check this for a given absolute path (i.e. if originalPath is already absolute) too?

Copy link
Contributor Author

@benjaminwood benjaminwood Jul 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check this for a given absolute path (i.e. if originalPath is already absolute) too?

Yes, this works with absolute paths as well.

> path.resolve('foo')
'/Users/Ben/js_projects/serverless-webpack/foo'
> path.resolve('./foo')
'/Users/Ben/js_projects/serverless-webpack/foo'
> path.resolve('/Users/Ben/js_projects/serverless-webpack/foo')
'/Users/Ben/js_projects/serverless-webpack/foo'

@benjaminwood
Copy link
Contributor Author

@HyperBrain thanks, I've made some revisions:

  1. Rename the function to: makePathOptionAbsolute.
  2. Move the function to its own file in lib makePathOptionAbsolute.js.
  3. Made use of const and added missing semicolons.

Let me know if there is anything else I can do!

@HyperBrain
Copy link
Member

@benjaminwood It's good to go now 🙌 . I'll merge it into the feature branch and continue with the finalization. Then we have a PR for the complete feature onto master and can do a final test and review.

I'll let you know if there is anything you can jump in - just thought about something 😄 : If you don't mind, you could dive a bit into the source-map stuff mentioned in #108 and check how sourcemaps can be used properly with local invoke. If they work, we should create a PR to update the documentation (README) and show users how to setup a working system.

@HyperBrain HyperBrain merged commit 05f076f into serverless-heaven:v3.0.0-invoke-local Jul 17, 2017
@benjaminwood
Copy link
Contributor Author

Thanks @HyperBrain! I'll take a look at #108.

HyperBrain pushed a commit that referenced this pull request Jul 24, 2017
* 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
HyperBrain pushed a commit that referenced this pull request Jul 24, 2017
* 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
HyperBrain pushed a commit that referenced this pull request Jul 27, 2017
* 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
HyperBrain pushed a commit that referenced this pull request Jul 28, 2017
* 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
HyperBrain pushed a commit that referenced this pull request Aug 1, 2017
* 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
@benjaminwood benjaminwood deleted the v3.0.0-invoke-local branch August 17, 2017 15:00
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants