Fork me on GitHub
#boot
<
2016-08-19
>
dominicm09:08:09

My goal for today: Get autoprefixer to run in the JVM via J2V8.

dominicm09:08:15

Step 1: console.log

pesterhazy09:08:39

wouldn't nashorn work for this sort of thing as well?

dominicm09:08:13

autoprefixer is fairly dependent on Node.js, I could browserify it and run it through nashorn. But I'm going for a general solution to all the great npm ecosystem.

dominicm09:08:08

Well, maybe I could do it and run through nashorn. Yeah, probably.

dominicm09:08:37

I think it has an in-browser version, which doesn't touch the FS. But things which aren't so usable elsewhere is harder.

pesterhazy09:08:16

it'd be exciting to tap all the node-based tooling inside boot

pesterhazy09:08:41

although I guess you can shell out to node even now

dominicm09:08:10

I don't like that much as a solution. My ultimate goal is to have npm modules via webjars, and be completely independent of tools installed on the host.

dominicm09:08:11

I'm a bit overzealous about being within a single system

pesterhazy09:08:35

only good things can come out of experiments like that

dominicm09:08:49

Let's hope!

dominicm09:08:22

I actually think this will work ๐Ÿ˜ฎ

dominicm14:08:36

I'm less sure. Module dependencies are really hard to match up.

dominicm14:08:51

This will work great for dependency-less modules that use the nodejs api though!

dominicm14:08:02

I theorize that you could have a task which downloads the latest npm, and runs that inside J2V8 to download all your dependencies for you (outside of webjars). That wouldn't leave the platform then.

dominicm14:08:12

> supports npm module loading

dominicm14:08:37

That's great!

dominicm14:08:10

I wonder how it does npm module loading

alandipert14:08:13

unfortunately it's built on dynjs, not nashorn

dominicm14:08:31

J2V8 is really fast. I think I read it was faster than nashorn

alandipert14:08:46

and appears abandoned. i looked at it recently as a way to get our node ad server on the jvm

dominicm14:08:05

Nodyn or J2V8?

alandipert14:08:28

nodyn, j2v8 looks alive

alandipert14:08:47

j2v8 looks cool but our goal is to leave node

dominicm14:08:53

Yeah, it is.

dominicm14:08:01

Why leave node?

alandipert14:08:39

it's missing lots of things that the jvm has that will help us run our ad servers much more efficiently

dominicm14:08:00

So you want to migrate the codebase to JVM?

alandipert14:08:03

also the profiling and debugging tools don't hold a candle to jvm stuff

alandipert14:08:13

well, it was an option i was exploring

dominicm14:08:58

J2V8 makes sense then in my opinion. You can dump the codebase into J2V8. Then start replacing a few of the callbacks, and over time rewrite large parts in JVM.

dominicm14:08:49

Oh I see, dynjs is active. Just not Nodyn.

dominicm14:08:41

This is interesting (for my problem) https://github.com/dynjs/dynjs/blob/d89b684c317f5668cb5e982aade35ec39b235599/src/main/java/org/dynjs/runtime/builtins/Require.java They implement their own require, so it can be classpath aware. J2V8 is only aware of file paths, because it uses the built-in require. For better or worse.

alandipert14:08:16

that's great, that's a major problem with node, the file orientation

dominicm14:08:36

Yeah, J2V8 suggests doing java.io.File/createTempFile for a lot of things to get round this.

dominicm14:08:44

I've opened an issue on J2V8, but I'm not hopeful it will be resolved. A shame really. I like my idea of running npm inside J2V8 to create the necessary files.

alandipert15:08:08

where did you see that it can't run npm?

alandipert15:08:25

because maybe you can do it in 2 steps

dominicm15:08:49

Well, it can't require npm modules from webjars, because it can't handle non-files (as they're on the classpath)

dominicm15:08:48

But if I could automate the loading of npm into J2V8 somehow, I'd be happy.

dominicm15:08:53

Do you have an evil scheme in order to get it to work? ๐Ÿ˜›

alandipert15:08:39

not anything concrete, just thinking about how you might be able to run npm first and have it output to temp dir. then run 2nd program, aiming it at temp dir

dominicm15:08:43

Ah, yep. But I can't guarantee the environments running this will have npm installed.

dominicm15:08:05

But if I can get npm to run inside the JVM somehow, then it is possible.

flyboarder17:08:52

@dominicm: You may just be better off writing an npm task that duplicates the behaviour instead of running npm itself

flyboarder17:08:07

I mean cljs has better dependency resolution anyway imho

dominicm17:08:38

@flyboarder: you mean using the npm http Api?

flyboarder17:08:54

@dominicm: yeah, I havnt looked at it before but my experience with getting node apps to work mostly includes rewriting

flyboarder17:08:18

I rewrote the polymer vulcanize tool as a boot task and it doesnt have any of the issues the original app has

flyboarder17:08:32

you could also use the boot-npm task, which installs npm if itโ€™s missing

dominicm17:08:34

Oh interesting. Didn't see that part.

dominicm17:08:44

Hmm, I don't see that.

flyboarder17:08:00

@dominicm: yeah new feature I put in last week, my idea is that as a developer you shouldnt need care about the env that boot runs in, the tasks should construct everything you need, so if you use the bower task it will make sure bower is there without you needing to install it.

dominicm17:08:19

@flyboarder: I don't see the code to do that?

flyboarder17:08:21

@dominicm: as you are correct the npm task itself needs npm installed, I can fix that, the exec wrapper is here: https://github.com/degree9/boot-npm/blob/master/src/degree9/boot_npm.clj#L34-L53

dominicm17:08:28

Oh, I do. But not for npm itself.

dominicm17:08:54

Ah, there we are. How would you auto install npm?

flyboarder17:08:12

@dominicm: Maybe a homebrew task or download the binary

dominicm17:08:04

Hmm. Not super localized. You might be able to install npm into node modules dir... but you still need node

dominicm17:08:51

Plus there are nvm problems. Plus other platforms.

flyboarder17:08:01

@dominicm: yeah you can update npm with npm, but it needs it installed first, looks like the binary option will work tho

flyboarder17:08:21

@micha does boot have a way to get the host platform?

dominicm17:08:31

The binary npm I mean

dominicm17:08:36

But does it need node to piggieback first?

flyboarder17:08:44

@dominicm: thats a good question, looking at the node.js binary package it has npm in it but npm is just a node module, so maybe?

flyboarder17:08:18

There is also a unix exec in the folder maybe we can just pull that out, trying it now ๐Ÿ™‚

dominicm17:08:29

Is there much chance of us breaking someone's node/npm setup by doing this?

dominicm17:08:48

Especially if they use things like nvm

flyboarder17:08:11

since itโ€™s only affecting the local node_modules and only if they dont already have it installed

dominicm17:08:09

You're going to put npm into a folder of some kind? And the node binary?

flyboarder17:08:36

right, ill pull the npm binary into the node_modules folder as if it was installed locally with npm itself, then check this location just like the other node modules, node.js would get discarded as we only care about npm itself, but thats only if this unix exec will work without node installed

dominicm17:08:26

I see. Interesting strategy. I'm excited to see how it pans out.

flyboarder17:08:52

yeah testing the binary right now, gonna remove nodejs first so I know itโ€™s not causing issues

flyboarder17:08:12

@micha anyway we can get an env var with the current platform? I think this will make a difference as boot becomes more cross platform, right now I dont know if Im on OS X or Linux

micha17:08:35

you can use that method, if you need to

micha17:08:42

it's accessible anywhere

micha17:08:06

otherwise you should use System.getProperty("os.name") i would think

flyboarder17:08:36

ah yeah ok so just do the same thing as that function, awesome!

micha17:08:29

i think that function might have a potential bug, i'm not exactly sure about using toLowerCase() and locales

flyboarder18:08:16

@dominicm: yeah npm does indeed require node, which I think will be fine in this case since it will be a local version and only fetched if npm is not already installed

dominicm18:08:37

Cool! ๐Ÿ˜ƒ

kenny18:08:28

@micha From our previous discussion: clojure-alpha11 allows you to control if a map prints out with the namespace map syntax (http://dev.clojure.org/jira/browse/CLJ-1993). Also, still haven't had time to look into adding the update-file ability to sift ๐Ÿ™ . I think I'll have some time this weekend though ๐Ÿ™‚

Alex Miller (Clojure team)18:08:45

also, it defaults to false (but true in the repl), so if you had issues from boot with this, they might actually be gone (but Iโ€™m assuming things)

micha18:08:32

excellent, that was the issue in boot, so defaulting to false would fix it

kenny18:08:15

Latest Clojure alpha release already found a bug in boot lein-generate (https://github.com/boot-clj/boot/wiki/For-Cursive-Users) ๐Ÿ™‚ Fixed in wiki