lumo

:lumo: Standalone ClojureScript environment. Currently at version 1.9.0
borkdude 2018-05-29T15:19:18.000572Z

I do (:require [moment]) and sometimes I get the error:

No such namespace: moment, could not locate moment.cljs, moment.cljc, or JavaScript source providing “moment”

borkdude 2018-05-29T15:19:21.000014Z

but not always

borkdude 2018-05-29T15:23:13.000943Z

This is the classpath I feed into lumo:

src:/home/borkdude/.m2/repository/org/clojure/clojure/1.9.0/clojure-1.9.0.jar:/home/borkdude/.m2/repository/org/clojure/tools.cli/0.3.7/tools.cli-0.3.7.jar:/home/borkdude/.m2/repository/org/webjars/npm/moment/2.22.1/moment-2.22.1.jar:/home/borkdude/.m2/repository/org/webjars/npm/nodemailer/4.6.5/nodemailer-4.6.5.jar:/home/borkdude/.m2/repository/org/clojure/spec.alpha/0.1.143/spec.alpha-0.1.143.jar:/home/borkdude/.m2/repository/org/clojure/core.specs.alpha/0.1.24/core.specs.alpha-0.1.24.jar

borkdude 2018-05-29T15:27:57.000923Z

It’s this script that I’m using. Locally it works fine, on my server no. I’m using a newer lumo version on my server. https://github.com/borkdude/balcony/blob/master/lumo/scripts/balcony.cljs

borkdude 2018-05-29T15:28:17.000315Z

Execute by ./balcony.cljs

borkdude 2018-05-29T15:33:14.000348Z

I removed the -K option as well. I installed lumo 1.8.0 on my server and get:

No such namespace: moment, could not locate moment.cljs, moment.cljc, or JavaScript source providing “moment” in file cljs/tools/cli.cljs

borkdude 2018-05-29T15:38:53.000203Z

When I try:

(def moment (node/require "moment"))
I get:
Cannot find module ‘moment’

borkdude 2018-05-29T15:42:07.000897Z

I’m so close…

borkdude 2018-05-29T15:44:43.000043Z

ah wait, locally it was still using my node_modules folder probably…

borkdude 2018-05-29T15:45:47.000221Z

so I need to find a way how to get these webjars working, probably using foreign libs or something

borkdude 2018-05-29T15:49:22.000728Z

To summarize: can I load javascript from a jar file in lumo, preferably inside the script and not in some external file

richiardiandrea 2018-05-29T16:01:01.000194Z

@borkdude you are not compiling down with browserify anymore? Because I though it would just concatenate all the js deps with that so no need for carrying it with you

borkdude 2018-05-29T16:01:31.000372Z

@richiardiandrea I’m trying a different approach now, the one that I also took with clj. Using webjars it might be possible to avoid the build step.

richiardiandrea 2018-05-29T16:01:48.000387Z

If not then the customary method is to carry the node_modules folder with you

borkdude 2018-05-29T16:01:52.000766Z

For reference: https://github.com/borkdude/balcony/blob/master/balcony.clj

borkdude 2018-05-29T16:02:04.000452Z

so I’m not loading any deps via npm anymore

richiardiandrea 2018-05-29T16:02:10.000373Z

But I don't think the folder is read from inside the jar

borkdude 2018-05-29T16:02:50.000419Z

Well you can load .cljs files from a jar, why not .js files?

richiardiandrea 2018-05-29T16:03:16.000017Z

Uhm maybe :foreign-libs

richiardiandrea 2018-05-29T16:04:09.000978Z

Not sure at this point, I never really used :foreign-libs. It should maybe be possible given the cljsjs project is doing exactly that

borkdude 2018-05-29T16:05:12.000063Z

right

borkdude 2018-05-29T16:07:07.000454Z

now the thing I have to know is, can I load foreign libs from the repl

richiardiandrea 2018-05-29T16:08:08.000408Z

Never explored that path, let's wait for @anmonteiro. I would say you should be able to

borkdude 2018-05-29T16:14:41.000380Z

maybe I should use cljsjs instead, I didn’t even think of that…

borkdude 2018-05-29T16:19:08.000677Z

repro:

#!/usr/bin/env bash

":";momentjs='cljsjs/moment {:mvn/version "2.22.0-0"}'
":";src=$(clojure -Spath -Sdeps "{:deps {$momentjs}}")

"echo" "$src"

"exec" "lumo" "-c" "$src" "$0" "$@"

(ns balcony.core
  (:require
   [moment]))

(println (moment))

borkdude 2018-05-29T16:19:19.000626Z

doesn’t work btw

borkdude 2018-05-29T16:23:10.000493Z

I think the approach of bundling up to a single file is already cool, just seeing if I can get this approach to work

richiardiandrea 2018-05-29T16:23:33.000350Z

Yep I think it is nice to explore for sure

richiardiandrea 2018-05-29T16:24:08.000392Z

:foreign-libs are declared as compiler options so I was definitely wrong there

borkdude 2018-05-29T16:25:03.000115Z

can I read files from the classpath from the REPL in lumo? if so, I think it’s a small step to loading the file?

borkdude 2018-05-29T16:25:20.000313Z

there is no classpath of course

borkdude 2018-05-29T16:25:25.000582Z

but you know what I mean

futuro 2018-05-29T16:26:01.000755Z

Read in what way?

borkdude 2018-05-29T16:26:22.000646Z

like slurp

futuro 2018-05-29T16:26:49.000464Z

Ah, and to just give it a filename of something that exists on the classpath. Hmm...

borkdude 2018-05-29T16:27:10.000070Z

yeah and then eval it in node

futuro 2018-05-29T16:27:12.000735Z

That's a good question; I've never tried, but presumably there's a way to find files inside the classpath...?

richiardiandrea 2018-05-29T16:27:46.000041Z

Yes you can I think, the facilities are all there because this is what -D does

futuro 2018-05-29T16:28:00.000417Z

Ah, then eval it. I'm missing something I'm sure, but wouldn't require fit the bill there?

borkdude 2018-05-29T16:28:25.000881Z

yeah, definitely

richiardiandrea 2018-05-29T16:28:26.000588Z

The only thing I don't know is if require can read from jars at the moment in the REPL

borkdude 2018-05-29T16:28:31.000135Z

maybe read back a little 🙂

futuro 2018-05-29T16:29:02.000506Z

Ha, my bad.

futuro 2018-05-29T16:29:05.000435Z

🙂

richiardiandrea 2018-05-29T16:32:23.000004Z

I am exploring

richiardiandrea 2018-05-29T16:36:46.000343Z

Seems like it should be doing it: https://github.com/anmonteiro/lumo/blob/master/src/cljs/snapshot/lumo/repl.cljs#L233

richiardiandrea 2018-05-29T16:37:28.000277Z

But you need to declare them somehow

richiardiandrea 2018-05-29T16:37:36.000404Z

Not sure how

richiardiandrea 2018-05-29T16:43:16.000118Z

Ok found

richiardiandrea 2018-05-29T16:43:55.000620Z

There should be a deps.cljs in the jar

anmonteiro 2018-05-29T16:44:14.000729Z

@borkdude node/require only looks in node_modules

anmonteiro 2018-05-29T16:44:28.000379Z

if you have the moment cljsjs thingy, you have to require it by its name

anmonteiro 2018-05-29T16:44:34.000584Z

(require 'cljsjs.moment) or something

anmonteiro 2018-05-29T16:44:42.000027Z

then use js/Moment or whatever global it exposes

richiardiandrea 2018-05-29T16:46:22.000777Z

Cool Antonio saves me from rabbit holing ;)

anmonteiro 2018-05-29T16:47:25.000293Z

let me reiterate that none of this is specific to Lumo at all

👍 2
anmonteiro 2018-05-29T16:47:30.000376Z

this is how it works in JVM CLJS too..

borkdude 2018-05-29T16:57:57.000527Z

Cool!

borkdude 2018-05-29T16:59:34.000922Z

Can I load js from an npm webjar from the REPL though?

richiardiandrea 2018-05-29T17:00:08.000157Z

I think it needs to have the deps.cljs file?

borkdude 2018-05-29T20:06:19.000318Z

ah:

cljs.user=> (require ’[lumo.classpath :as cp])
nil
cljs.user=> (cp/classpath-jarfiles)
(“/Users/Borkdude/.m2/repository/org/clojure/clojure/1.9.0/clojure-1.9.0.jar”
 “/Users/Borkdude/.m2/repository/org/clojure/tools.cli/0.3.7/tools.cli-0.3.7.jar”
 “/Users/Borkdude/.m2/repository/org/webjars/npm/moment/2.22.1/moment-2.22.1.jar”
 “/Users/Borkdude/.m2/repository/org/webjars/npm/nodemailer/4.6.5/nodemailer-4.6.5.jar”
 “/Users/Borkdude/.m2/repository/org/clojure/spec.alpha/0.1.143/spec.alpha-0.1.143.jar”
 “/Users/Borkdude/.m2/repository/org/clojure/core.specs.alpha/0.1.24/core.specs.alpha-0.1.24.jar”)

borkdude 2018-05-29T20:07:20.000281Z

(cp/filenames-in-jar “/Users/Borkdude/.m2/repository/org/webjars/npm/nodemailer/4.6.5/nodemailer-4.6.5.jar”)
...

borkdude 2018-05-29T20:19:38.000119Z

it’s a start… if the jar would have the minified version, it would probably work:

(.runInThisContext vm (.-source (js/$$LUMO_GLOBALS.readSource “META-INF/resources/webjars/nodemailer/4.6.5/lib/nodemailer.js”)))

borkdude 2018-05-29T20:22:21.000708Z

I’m beginning to see why people just install yarn on their servers, because this is quite involved. In theory, we could make module loading work with npm webjars as well

richiardiandrea 2018-05-29T20:44:43.000487Z

Yes I think we actually could, maybe open an issue @borkdude?

borkdude 2018-05-29T20:47:36.000142Z

Maybe first discuss if this is a good idea. The benefit would be avoiding npm and still being able to write a script with deps, like above, without polluting the script dir with node_modules, package.json etc

richiardiandrea 2018-05-29T20:49:44.000751Z

Personally I am specifically trying to port all the maven deps I use to npm

borkdude 2018-05-29T20:49:50.000210Z

and there is one caveat. if you do something like

(.runInThisContext vm (.-source (js/$$LUMO_GLOBALS.readSource "META-INF/resources/webjars/nodemailer/4.6.5/lib/nodemailer.js")))
that file will do require(./mailer), I don’t know if we could trick node into reading the right file from the jar there

richiardiandrea 2018-05-29T20:50:15.000448Z

Right

richiardiandrea 2018-05-29T20:51:01.000210Z

I found that my company is more js oriented so we are trying not to use JVM stuff

borkdude 2018-05-29T20:52:04.000367Z

for popular things we could always write a cljsjs, but then the repo already should have a minified version: e.g. https://github.com/moment/moment/tree/develop/min

borkdude 2018-05-29T20:52:48.000191Z

and if it already has a minified version, it’s very easy to load it in node via webjars

richiardiandrea 2018-05-29T20:52:58.000088Z

Yeah, that has always been the deal breaker for me, why do I need another package

richiardiandrea 2018-05-29T20:53:21.000070Z

Yeah cljs could be greatly simplified if its only target is node

borkdude 2018-05-29T20:53:39.000114Z

I think cljsjs was mainly built with browser in mind

borkdude 2018-05-29T20:55:34.000706Z

maybe it’s not so hard to automate though, the minification step, so cljsjs could also be purposed for node

richiardiandrea 2018-05-29T21:02:04.000344Z

Given also that lumo does not know maven, I am not so convinced it is a good idea tbh ... You never know of course ;)

anmonteiro 2018-05-29T21:02:29.000636Z

CLJSJS should include minified files

anmonteiro 2018-05-29T21:02:44.000481Z

or rather, I know for a fact they do

richiardiandrea 2018-05-29T21:03:36.000369Z

Oh that's good to know, I actually thought they could be there already

borkdude 2018-05-29T21:03:54.000097Z

@anmonteiro yes, but the examples I’ve looked at so far just get the minified file from e.g. http://registry.npmjs.org/moment/-/moment-2.22.0.tgz but for example http://registry.npmjs.org/nodemailer/-/nodemailer-4.6.5.tgz has no minified file

borkdude 2018-05-29T21:04:24.000178Z

they just sift/move the files

borkdude 2018-05-29T21:04:47.000327Z

e.g. this one: https://github.com/cljsjs/packages/blob/master/firebase/build.boot

anmonteiro 2018-05-29T21:05:10.000445Z

ah well

anmonteiro 2018-05-29T21:05:15.000427Z

Node.js packages are not minified

borkdude 2018-05-29T21:05:17.000431Z

(sift :move {#“package/firebase-([a-z\-]*).js” “cljsjs/development/firebase-$1.inc.js”
                #“package/firebase=([a-z\-]*).js.map” “cljsjs/development/firebase-$1.inc.js.map”
                #“package/externs/” “cljsjs/common/“}
         :include #{#“^cljsjs”
                    #“^deps.cljs”})

borkdude 2018-05-29T21:05:31.000517Z

I think this firebase thing is used from node as well

richiardiandrea 2018-05-29T21:05:41.000727Z

The community effort is smaller if the community is small. I guess.

borkdude 2018-05-29T21:06:14.000138Z

anyway, I see why people say things like: yarn install on the server. because another way is quite complicated

richiardiandrea 2018-05-29T21:07:21.000171Z

Yeah, I am quite happy with it. JS tooling is smooth imho

borkdude 2018-05-29T21:08:26.000663Z

what’s the benefit of yarn again though? it keeps a repo from which it copies deps, instead of downloading them all the time?

borkdude 2018-05-29T21:08:53.000584Z

I don’t know enough about JS tooling. I hear mixed stories about it. Some people do everything to avoid it.

borkdude 2018-05-29T21:11:17.000298Z

why doesn’t yarn make symbolic links to the cache dir though?

borkdude 2018-05-29T21:12:35.000091Z

https://github.com/yarnpkg/yarn/issues/499

borkdude 2018-05-29T21:13:09.000337Z

comes with it’s own set of problems

richiardiandrea 2018-05-29T21:21:57.000417Z

They say yarn has reproducible dep management

richiardiandrea 2018-05-29T21:22:16.000011Z

Dunno if it's true still though

richiardiandrea 2018-05-29T21:22:22.000595Z

Npm usually catches up quickly

borkdude 2018-05-29T21:23:41.000389Z

because of the lock file right?

richiardiandrea 2018-05-29T21:24:21.000512Z

I think not because of that, probably the algo is different or something, not sure though

borkdude 2018-05-29T22:10:43.000331Z

btw, the npm webjar idea might still be feasible with a tool like this: https://unix.stackexchange.com/questions/168807/mount-zip-file-as-a-read-only-filesystem mount the jar/zip into node_modules…