-
Notifications
You must be signed in to change notification settings - Fork 10
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
WIP - Add lumo script for building the lambda zip #6
Conversation
serverless-cljs-plugin/js_build.cljs
Outdated
;; TODO serverless-opts? | ||
(let [{:keys [compiler functions resource-dirs env]} cljs-lambda-opts | ||
{:keys [inputs options]} compiler | ||
;; recurring :keys don't word in a let |
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.
word -> work?
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.
👍
serverless-cljs-plugin/js_build.cljs
Outdated
) | ||
|
||
|
||
(comment |
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 this be in an examples.cljs
file?
@arichiardi I appreciate this - I'm going to have to learn a little about lumo before merging - a couple of high-level things maybe you can help with:
To keep it simple, let's keep serverless.yml the same, and have the 'use-lumo' thing be a switch accepted by serverless-cljs-plugin. Either all |
Lumo is like the vanilla cljs compiler, so you pass things in. I will probably then need to read the project.clj file from the script. The output of the zip can be passed to the zip! function. Now it is hardcoded to .serverless About index.js, I thought it was a convention coming from the cljs-lambda template but you are right, somebody could choose not to use that. |
@arichiardi - in order:
|
@arichiardi This is a great idea! |
Just to give more context, this has to be executed with:
So we can pass things from the command line as well as reading project.clj directly |
custom:
lumo:
optimizations: none
sourceMap: true Or whatever is applicable to lumo. We should default everything, and make up our own
|
Ok so basically what you'd need is to modify the build! function, it seems all the parameters you describe are already input to compile! and zip! at the moment.
One of the nice conventions that I have seen more and more around is to have edn files. So we could baptize here our cljs-lambda.edn which will contain compiler options, inputs..same as the :cljs-lambda that at the moment is nested in project.clj.
How does it sound?
Also, are you going to spawn a new branch or you want to continue on this one? Just so I don't rebase it.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
That's fine if you prefer that, it ends up being more or less the same thing - as long as the file is optional, and the script uses sensible defaults both for values unspecified in the file, and when the file does not exist. Do you want to implement that bit? I'll branch from these changes. |
Well it is definitely easier to start from edn, then once the feature is ready we can think of parsing yaml (which is definitely more familiar for JS users, but is always limited)... I guess that yes I can hook the edn. The plugin in the feature if necessary could in order scan:
But ok step by step. In any case cool stuff! |
A question, should I keep the structure of the current For me, I like something like:
Where What do you think? Ps.: For the generation there is either https://github.com/fotoetienne/cljstache or https://github.com/janl/mustache.js. |
@@ -54,6 +54,9 @@ function cljsLambdaBuild(serverless, opts) { | |||
const cmd = (`lein update-in :cljs-lambda assoc :functions '${fns}' ` + | |||
`-- cljs-lambda build :output ${serverless.service.__cljsArtifact} ` + | |||
`:quiet`); | |||
// TODO if it is a lumo function use our lumo script for compiling | |||
// const cmd = (`lumo -c serverless-cljs-plugin -m lumo.build` + |
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.
This is the command that works, but you need lumo
on master
for it to work, I am patching lumo
, see anmonteiro/lumo#237
It is very similar to: | ||
|
||
https://github.com/nervous-systems/cljs-lambda/wiki/Plugin-Reference#exhaustive-config-map" | ||
[zip-path cljs-lambda-opts] |
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.
Now we pass the path of the zip (output) and the options
conf (read-conf!)] | ||
(if-not (instance? js/Error opts-or-err) | ||
(do (.info js/console "Building" (get-in conf [:project :name])) | ||
(build! (:z opts-or-err) (read-conf!))) |
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.
The options are read from cljs-lambda.edn
but read-conf!
can be augmented in order to handle reading from anywhere basically.
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.
serverless-lumo.edn might be a more appropriate name?
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.
Yes I like it.
(defn build! | ||
"Build a project. | ||
|
||
The cljs-lambda-opts map is: |
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.
The shape of the map of course is debatable
|
||
(defn compiler-defaults | ||
"Generate the compiler options map part for the output." | ||
[target-path project-name] |
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.
I think we should remove references to project-name - here and in the function at the top of the module - as far the args here, we should consider just defaulting to {:output-to "out/lambda.js" :output-dir "out" :target nodejs}
or something simple like that. What about defaulting optimisation level?
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.
Well :optimizations
might be good to have configurable, for dead code elimination. I would not want to restrict that.
About the output, I am still torn, I like the way normal serveless
does it, prepending even the stage
in front of the name of the .js
file. So I think at some point we'll need to configure it...
Also, there is another issue, if we have output-dir
we force to split the files...otherwise one .js
file will be generated. No sure here, but can the split impact performance?
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.
Regarding optimisations - these are defaults, right? They should all be trivial to override if the user supplies alternate values in the config, but we should have sensible, well defined defaults - like optimizations: none
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.
Does that happen even with optimizations :none - you get a single file if you don't specify output-dir? In any case, I'm fine with separate files - advanced compilation will yield a single file, so the user can specify that if they want.
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.
If I remember correctly it always happens, in any case the defaults now are:
{:output-to "out/lambda.js",
:output-dir "out",
:target :nodejs,
:optimizations :none}
yarn.lock
Outdated
@@ -0,0 +1,241 @@ | |||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. |
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.
I'm not familiar with this format. Do we actually need this?
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.
oh sorry, the yarn.lock
is generated by yarn
and usually committed, I though we were already using it, will remove.
@arichiardi I added some superficial commentary - when you're ready, if you reopen the pull request against the branch |
I am actually thinking about a change that will pass
What do you think? I see that |
That's what we need, yeah - it's edn, so e.g. --functions '[{:name ...} ...]' - see index.js for specifics. |
5e67969
to
40e4350
Compare
Ok so this last version works fine with:
Quotes are necessary. I will push the changes to |
Ok @moea no objections but I need to be Collaborator in order to push to |
Btw thanks to this the lumo command will be greatly simplified. |
@arichiardi I can add you as a collaborator, but can't you just open a PR against that branch and I can merge it? |
Oh, never tried that, I thought you can only merge to master from github unless you change the default branch. Are you sure it is going to work? |
Wow awesome did not know that :) |
@arichiardi I am pressed for time, but hope to have an example with index generation etc. working by the end of the week. |
I will try that too then, I am pressed for time as well ;) Thanks for your hints, this is going to be a very nice feature |
@arichiardi Let's not both do the same thing! |
Ok you are right let me do that then, I need to make this work soon...I was wondering if the local invoke can be worked on as well...for sure you are more familiar with it. What do you think? |
@arichiardi I wouldn't feel comfortable delegating the index generation task, it needs to be as similar as possible to what cljs-lambda is doing, and work for all optimization levels. If you are in a hurry to get it working, just manually write an index file once for your project, and add it to the zip. I am personally not particularly interested in local invoke - I can just call the exposed function from a REPL. If you are interested in it, and it doesn't involve far reaching changes, then I am happy to include it. |
Ok sounds good. |
@arichiardi If you create a project which depends on serverless-cljs-plugin 0.2.0-alpha, then |
Note that I changed the format of the config file and made it optional - see commits in the branch for details. |
Oh you went for a cmd line option for that, I was thinking of having a |
Having lumo instead of cljs would be per-handler, so it would give the mistaken impression that it's possible to mix both cljs and lumo handlers in a single serverless.yml, which it's not. It would be possible to also support a top level custom |
I like the lumo: true option better - or even cljs-compiler: lumo. I can
contribute that, is it going to be in opts in the plugin?
|
Yeah, so ideally it should work if you do either this:
or deploy with |
* Add lumo script for deploying self-host lambdas (#6) * Simplify option parsing, misc. fixes * Working end-to-end example * Misc improvements to lumo build (#7) * Handle archive warning * Use apply for sequable :files entries in zip! * Make keyword lookup idiomatic * Handle custom.cljsCompiler option in serverless.yml This patch allows to specify the cljs compiler of the build. At the moment only lumo is the alternative to the default JVM compiler (which requires lein), but in the future others can be added (a vanilla cljs script, shadow-cljs, boot-cljs...). * Add Lumo compiler section to README * Work-around lumo's command-line-args bug and support all versions * Use `simple` template for `advanced` compilation * 0.2.0
Hi! 😄 here I am with the script 🎉
Path is maybe off for a script, I just wanted to put it out there.
Thanks to this I am able to compile (cljs bootstrap compatible) lambdas. I am now missing the deploy part and that is why I am going to ask some help here 😄
I also have a question about the
serverless.yml
file itself, because maybe we could define custom entries for bootstrapped compilation (which requires extra care), for instance:Open to thoughts - suggestions - corrections!