-
Notifications
You must be signed in to change notification settings - Fork 417
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
Yarn support #340
Yarn support #340
Conversation
@franciscocpg This is the promised Yarn support. Can you give it a try and tell me, if it works for you? |
Unit tests Added unit tests for copy modules packager flag npm must copy modules Fixed unit tests Yarn does not need to copy modules to be fast Install/prune unit tests. Fixed typo. Copy lock file only if it can be read. AAdjust unit tests. Copy lock file into function directories Only stringify JSON or YML lock files Fixed unit tests Add basic Yarn functionality
@HyperBrain Hey, Frank! 👋 Thanks for your time and work on this! You're awesome. ❤️ Just tested this on my project, and I can confirm that it works! 💪 |
@HyperBrain |
❓ I don't know if I have to submit a different issue. If you prefer, I can remove my comment and create a separate issue. But I just tried on a project and got an error because of flatten deps. In my
Because winston requires the version 1.0.x:
When running
Which means during the
You do have Using only |
@j0k3r I'm not sure if that should be the default behavior when flattening as the resolution cannot be determined. We have to use non-interactive mode during packaging. Do you know if there's a specific resolution switch for yarn, where I can tell to use the latest version, or provide a resolution strategy to yarn? |
@HyperBrain That could be a good option but I've no idea of such option (and I'm not a yarn expert) |
Ok. Here's a feature request at Yarn: yarnpkg/yarn#1658 It seems that automatic resolution is not yet supported for the flat install option and it is not possible to resolve in non-interactive runs. We should then postpone the flat option support until a solution is available on the Yarn end. Right now I do not see any way to use that in the plugin. I will remove the option from the PR for now, if everyone agrees, ok? |
README.md
Outdated
|
||
#### Yarn | ||
|
||
Using yarn will switch the whole packaging pipeline to use yarn, so does it use a `yan.lock` file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be yarn.lock
not yan.lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Thanks. 👍
I removed the flat option as mentioned above for now. We can re-add it as soon as proper Yarn support is there. |
I'll give an other try tomorrow! |
@HyperBrain another Yarn success story here. Works like a charm 👍 |
@HyperBrain Works like a charm too. |
Merged. |
…support Yarn support
What did you implement:
Closes #286
How did you implement it:
Yarn support is provided by an additional packager class that uses the yarn executable instead of npm.
The packager is selected by the
webpack: packager
setting introduced in serverless-webpack version 5.0.0.The implementation honors any existing yarn.lock file and provides the same reproducibility as the locked npm packages. It even should behave better, because
--frozen-lockfile
is used with theyarn install
command. Additionally, some special packager options are supported inwebpack: packagerOptions
:How can we verify it:
Use Yarn in your project - preferably with a yarn.lock file - and set the packager accordingly in
serverless.yml
. Aserverless package
orserverless deploy
should do as before, but use yarn and the yarn.lock to create the packages.You can verify the installation by inspecting the generated zip files in
.serverless
(best to be done withserverless package
.With Yarn it is not needed to copy the modules explicitly into the function dependencies. For npm copy+prune was faster than install, but yarn is fast as hell here!
With that optimization, the yarn based package/deployment should take less than half of the time that npm does !!! Of course this heavily depends on the machine where it is executed. With a very large file system cache and big amounts of memory, the difference might be rather small.
Your help needed 😄
There are still some uncertainties, especially, if transient dependencies are handled correctly (i.e. if you bundle a first level dependency, its second level dependencies must become first level dependencies). With npm this works as expected and the behavior with yarn should be exactly the same.
Second, we should try this with the most common installation flavors of yarn, from a simple project up to yarn workspaces and shared modules.
Todos:
Unit tests and proper documentation in the README are yet missing. Working on that.
Is this ready for review?: YES
Is it a breaking change?: NO