serverless / serverless-optimizer-plugin

Serverless Optimizer Plugin: Optimizers for reducing Lambda file sizes and improving their performance -
http://www.serverless.com
102 stars 30 forks source link

includePaths and folder structure issue #53

Open hakenmt opened 8 years ago

hakenmt commented 8 years ago

I'm running serverless version 0.5.5 on Windows 10 1511 with node.js version 5.6.0 and serverless-optimizer version 2.5.1.

First, given a folder structure like:

MyProject
|--lib
    |--common.js
|--functions
   |--myFunction1
       |--handler.js 
       |--s-function.json

and my optimize section looks like:

"custom": {
    "optimize": {
      "exclude": [ "aws-sdk" ],
      "require": [ "q", "jsonwebtoken", "rsa-pem-from-mod-exp", "node-uuid" ],
      "excludeStage": [ "dev", "test" ],
      "includePaths": [ "./lib" ]
    }
  }

and my handler is defined as

"handler" : "myFunction1/handler.handler"

When I run sls function deploy myFunction1 it always fails with an error: myFunction1: ENOENT: no such file or directory, lstat 'C:\Workspaces\AWS\LambdaFunctions\MyProject\_meta\_tmp\myFunction1@1464958827455\lib'. So, when I create an empty lib folder in the functions folder, it succeeds. However, the contents of MyProject/functions/lib are not included in the resulting zip file. I'm expecting there to be a folder called lib with the contents of the lib folder in the project, namely common.js. Now, if I put the common.js file in that new empty lib folder, then it does end up in the zip. But, if I delete the lib folder in the project root, because it appears to not actually get utilized, then I get an error: myFunction1: ENOENT: no such file or directory, lstat 'C:\Workspaces\AWS\LambdaFunctions\MyProject\lib'. So it appears that the optimizer is checking for the folder to actually exist in both places, but only taking the content from the one in the functions folder. This is not what I would expect or desire, I want the includePaths to be relative to the project root and actually take the files/folders defined there and not need to maintain a shadow copy somewhere in subfolders.

skilledDeveloper commented 8 years ago

Related https://github.com/serverless/serverless-optimizer-plugin/issues/49