Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Optimizer fails when deploy is started from project root #37

Open
HyperBrain opened this issue Apr 8, 2016 · 2 comments
Open

Optimizer fails when deploy is started from project root #37

HyperBrain opened this issue Apr 8, 2016 · 2 comments

Comments

@HyperBrain
Copy link

The optimizer will fail if you run a sls function deploy -a from the project root and have multiple function roots in a deeper level. It does not find the inclusion paths.

It seems the plugin does not use the magic handler strategy to find the function root from the function definitions.

If you start the deploy from the function root, it works as expected.

@doapp-ryanp I suggest that the plugin uses SLS Project to get the function root and sets its CWD to there and then executes all the stuff. Then it should work.

@hollanddd
Copy link

hollanddd commented Apr 25, 2016

I'm leaving this here to add to the discussion. I think i have identified the problem. I believe the issue is a result of the ternary operator on line 288 of index.js:

destDir = (fs.lstatSync(p).isDirectory()) ? destPath : path.dirname(destPath);

If p does not exist fs.lstatSync(p) will fail and exit. This is the case when you have includesPath in your function but are deploying from the sls project root. My attempt to fix the issue was to use a try catch around fs.lstatSync() although I'm not satisfied with that solution.

@malatasf
Copy link

I just recently came across this issue, the deployment and packaging works when it is ran from the function root but failed when ran from project root.

I've modified the line of code that @hollanddd found to

destDir = (fs.lstatSync(srcPath).isDirectory()) ? destPath : path.dirname(destPath);

and that seems to make includePaths work to my expectations (there is no comment as to why the includePath are used rather than the srcPath forthe parameter to lstatSync)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants