-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Feature] Self-contained runtime from workspaces package #1169
Comments
I'm happy to work on this, I think I can build on top of #489. I wanted to capture this in a separate ticket as it's explicitly trying to solve deploying to AWS Lambda. If anyone else has the same use case and would like to help. |
I also need to publish lambda functions. My lambdas rely on shared functionality in a sibling workspace package, so I use webpack to bundle the code up. Some packages, e.g. I guess the way I would do this with the solution proposed by @ojkelly is would be to make sure the sibling packages are in I also thought about some kind of API that says takes a list of package names and a basepath/source package, and gives you a |
@sjmeverett I've been making good progress on this, and a build command. Currently copying everything to a temp folder, removing all the un-referenced local packages (relative to the one being bundled), and then removing all devDeps and peerDeps. Then running Just need to work out actually running it in lambda. Probably going to drop an I think, we'll need a custom lambda runtime though, in order to work with pnp. Should have something to play with in a few days. |
Amazing, let me know if there's anything I can help with! |
@sjmeverett I've got the beginnings of the plugin here https://github.com/ojkelly/yarn.build/tree/master/packages/plugins/yarn-plugin-build I noticed a need to be able to build the local packages and their deps, so thats actually what i've spent the most time on. I've got that working now, so I'm going to come back and get the aws lambda runtime sorted out. There's a bunch of issues on that repo regarding stuff to do/improvements. Keen to hear feedback on if it works. |
It is not the same thing, but I think I could reuse some of your plugin code if I would try to implement a plugin for #1200 (if it is possible). About the zip, I don't know AWS lambda, but with docker images I think it is not a good idea, for 2 reasons:
|
@lmcarreiro the example packages in the repo I linked above are all The The So, where I'm working on much more detailed documentation and configurability.
I haven't thought a lot about I think theres a bunch of configuration to add to For docker, if your dependencies are all in
I think your use case may be solved by If not, I think this is where yarn's plugin model really suits. In that we can have both plugins targeted at slightly different problems. |
@sjmeverett I've just updated the repo to add a file It should setup pnp for you, and then rexport the main file. So I think it will work properly with aws lambda. Will confirm shortly. @lmcarreiro for docker I was just thinking, if you used build layers you could call
|
For anyone still watching this, I've picked up development of this and am maintaining a functional workspace exporter, linked here:
The approach is to pack the current workspace into a temporary folder and reimplement Since my implementation doesn't rely on anything PnP-specific, I've added a |
@kherock Looks interesting! I'll check it out. In the meantime, this is the approach I'm taking, specifically for TypeScript projects: In depends on a lot of the other plumbing in that CLI, but in summary, it:
That gives me a single directory to deploy. It would be great to have all this in a yarn plugin! |
@kherock that's an interesting approach. My solution does use I do still need to get around to documentation and some polish (2020 right..), but either https://github.com/ojkelly/yarn.build (and then running |
Just to finish off this ticket, I've found some time to write up some documentation on this plugin. And make a site with a bit more information. Theres some still to do things in the issues queue, but as it is, it's ready to start being used and tested. Here's a guide on how to use it owenkelly.com.au/posts/2020/yarn-build And here's a link to the plugin's site yarn.build |
Describe the user story
I want one command to create a zip file with the code from a workspaces package
and all its dependencies.
The primary reason for me, is deploying to AWS Lambda. But this feature is useful to anyone who wants to compile part of their monorepo and discard the rest. For example deploying into a container.
Describe the solution you'd like
I'm not sure how to implement this, though I can easily see this being served
by a plugin if they are capable of this.
A command such as
yarn bundle
which takes and argument of the local package tobundle, or if possible can work it out from the directory you're in.
Then likely following the pnp setting of the workspace, the required dependencies would be compiled and placed in a temporary folder with the contents of the package (such that they are usuable).
That temporary folder would then be zipped, and saved to a location defined either in package.json or but an argument passed in by the user.
We would also need the ability to exclude files or folders.
yarn bundle --out .dist/bundle.zip --exclude .dist
Describe the drawbacks of your solution
I think this is a mostly best practice approach to this type of bundling, but
it may be more opinionated than I'm aware of.
This is not a feature that would be useful for those developing packages that
are published. That use-case is already well covered, this serves a different purpose.
I think things like
postinstall
would not work, unless you ranyarn install
upon opening the package, which I think would defeat the purpose of this. It should be a zero-install, unzip and run situation. I don't thinkpostinstall
should run though, given the target outcome.Describe alternatives you've considered
In the past, I've used hacky approaches with yarn and npm, that keeps
node_modules
next to the source. The whole package is then zipped up.This no longer works with pnp.
Yarn already has
yarn pack
, this would be similar, but for the use-case of deploying, not publishing.Additional context
This may not fit exactly into the world of a package manager, but I think it does fit into the world that Yarn is heading too.
There's some existing tickets (#489 and #859) that I think touch on the same issue, and similar solution.
The text was updated successfully, but these errors were encountered: