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

Misc improvements to lumo build #7

Merged
merged 6 commits into from
Aug 24, 2017

Conversation

arichiardi
Copy link
Contributor

@arichiardi arichiardi commented Aug 23, 2017

This patch adds various improvements to the lumo build, notably:

  • handle archiver warning
  • add some useful debug logging
  • fully forward vector as params to archiver's directory() and file()
  • handle custom.cljsCompiler option in serverless.yml

@arichiardi arichiardi changed the title Misc improvements Misc improvements to lumo build Aug 23, 2017
@arichiardi
Copy link
Contributor Author

I don't know how to change it against wip/lumo...

:let [k (keyword (str/replace k #"^-{1,2}" ""))
k (cli-option-map k k)]]
[k (parse-option k v)])))
(for [[k v] (partition 2 argv)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I will fix this change, it slipped in.

@moea moea changed the base branch from master to wip/lumo August 23, 2017 18:18
index.js Outdated
@@ -52,8 +52,13 @@ function basepath(config, service, opts) {

function cljsLambdaBuild(serverless, opts) {
const fns = slsToCljsLambda(serverless.service.functions, opts);
const compiler = _.get(serverless.service, 'custom.cljs-compiler');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hyphenated keys are going to look out of place in a serverless.yml. Please use lumo: true.

index.js Outdated
if (process.env.SLS_DEBUG) {
serverless.cli.log(`Compiler is set to: ${compiler}`);
}

Copy link
Member

@moea moea Aug 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is gratuitous, it will fail immediately if the compiler is incompatible with the project, so we don't need a log message.

(doseq [d (zip-opts :dirs)]
(.directory archiver d))
(.file archiver (zip-opts :index) #js {:name "index.js"})
(doseq [d (:dirs zip-opts)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the log messages, it makes the code noisy and is not particularly helpful here.

(.file archiver (zip-opts :index) #js {:name "index.js"})
(doseq [d (:dirs zip-opts)]
(js/console.log "adding directory %s" (.stringify js/JSON (clj->js d)))
(if (string? d)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this conditional and always assume a directory is a string. If we need this in the future for some reason, we can add it.


(defn write-index [content outpath]
(js/console.log "writing %s..." outpath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these log messages.


(defn ^:export -main [& args]
(let [opts (cli-options *command-line-args*)
conf (read-conf!)]
(build! opts (merge-with merge default-config (read-conf!)))))
file-config (read-conf!)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also remove these log calls.

(js/console.log "config is %s" (.stringify js/JSON (clj->js config) nil 2))
(.then (build! opts config)
#(js/console.log "zip created: %s" %1)
#(js/console.error "Error:" (.-message %1)))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please set the process exit code to 1 if we catch an error here.

(.on output-stream "close" #(resolve-fn output-path))
(.on archiver "warning" #(if (= (.-code %1) "ENOENT")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a function with named parameters.

@arichiardi
Copy link
Contributor Author

arichiardi commented Aug 23, 2017 via email

@moea
Copy link
Member

moea commented Aug 23, 2017

@arichiardi That hasn't been my experience - it's not helpful enough to justify the clutter. The serverless plugin logs the parameters it's passing to the script - everything else that's being logged could just as well be obtained by asking for the config file, or asking for a directory listing.

@arichiardi
Copy link
Contributor Author

arichiardi commented Aug 23, 2017 via email

@arichiardi
Copy link
Contributor Author

arichiardi commented Aug 23, 2017 via email

@moea
Copy link
Member

moea commented Aug 23, 2017

If you prefer that, use camel case.

@arichiardi
Copy link
Contributor Author

arichiardi commented Aug 23, 2017 via email

@arichiardi
Copy link
Contributor Author

arichiardi commented Aug 23, 2017 via email

@arichiardi arichiardi force-pushed the lumo-improvements1 branch 6 times, most recently from 748cb7d to a590a65 Compare August 23, 2017 22:24
@arichiardi
Copy link
Contributor Author

Ok addressed all the change requests and added some doc to the README

@moea
Copy link
Member

moea commented Aug 23, 2017

Thanks - why is 1.7.0+ required, just so I know?

@arichiardi
Copy link
Contributor Author

Because there is was a breaking change from lumo.core/command-line-args to cljs.core.

We could actually support both namespaces in our code but 1.7.0 will be broken unless we use an unmangled get on global.

anmonteiro/lumo#237

@moea
Copy link
Member

moea commented Aug 24, 2017

@arichiardi Why are we using *command-line-args* if the -main function receives the args as a sequence? With older versions of lumo, can you verify that receiving the arg vector still works? I would very much like to remove the version restriction.

@arichiardi
Copy link
Contributor Author

The reason is node sends all the args, even the ones passed to lumo itself and we don't want those.

Sure I can tweak that.

@moea
Copy link
Member

moea commented Aug 24, 2017

Yeah, let's work around it.

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...).
@moea
Copy link
Member

moea commented Aug 24, 2017

@arichiardi Regarding the fix, is command-line-args empty, or unbound in older versions of lumo?

@arichiardi
Copy link
Contributor Author

arichiardi commented Aug 24, 2017

Premise: the above works for the three versions regardless, so seq does the right thing even when unbound.

In 1.6.0 we have only bound lumo.core, in 1.7.0 bound only cljs.core. In the bugged version, the lumo.core JS mangled object is filled but not bound in cljs, where cljs.core is but will always be nil.

@arichiardi
Copy link
Contributor Author

Fix anmonteiro/lumo@fcba19a

@arichiardi
Copy link
Contributor Author

Btw I have just noticed there that I don't need seq because it is already done in lumo.

@moea
Copy link
Member

moea commented Aug 24, 2017

Presumably you can use the unmangled syntax to refer to the lumo.core var -
lumo.core/*command-line-args*?

@arichiardi
Copy link
Contributor Author

arichiardi commented Aug 24, 2017

@moea not that would not work in 1.7.0. That is why I used the mangled version 😉

@moea
Copy link
Member

moea commented Aug 24, 2017

If lumo.core is required, why would it not work?

@arichiardi
Copy link
Contributor Author

Good point! Maybe it is not required anymore? I have not investigated the why in depth, a bit in a hurry today.

@moea
Copy link
Member

moea commented Aug 24, 2017

I mean if you just add (:require [lumo.core]) to the module, I don't see how it cannot work.

@arichiardi
Copy link
Contributor Author

No I don't think it can work because the defonce is missing and therefore it is not in the compiler state.

However the global JS object is filled up at runtime so we can query it.

@moea
Copy link
Member

moea commented Aug 24, 2017

If the namespace is required, you will get a compiler warning about an undefined var, and nil at runtime. Please make the change.

@arichiardi
Copy link
Contributor Author

Will do, probably more verbose and uglier than what is now, but hey, you're the boss 😄

@moea moea merged commit 3bb0de4 into nervous-systems:wip/lumo Aug 24, 2017
@arichiardi arichiardi deleted the lumo-improvements1 branch August 24, 2017 11:19
@arichiardi
Copy link
Contributor Author

Awesome, it seems like it is nice and working now 😉

moea added a commit that referenced this pull request Aug 24, 2017
* 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
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

Successfully merging this pull request may close these issues.

2 participants