Fork me on GitHub
#cljs-dev
<
2017-08-23
>
anmonteiro16:08:11

@juhoteperi btw I have a patch for that issue yesterday about node deps in JS foreign libs

anmonteiro16:08:20

Just need to get the windows tests to pass

anmonteiro16:08:39

Turns out the solution was simply to pass the absolute path to Closure

anmonteiro16:08:53

Otherwise it cant find node modules

juhoteperi16:08:56

Heh, that was simple

anmonteiro16:08:25

This is yet another step in making js<-> cljs even easier

anmonteiro16:08:56

Plus my conj talk about this stuff got accepeted yesterday!

juhoteperi16:08:42

Will that be about the latest changes in Cljs in general or more specifically about JS integration?

juhoteperi16:08:12

Btw. I'll be speaking at ClojuTRE about recent Cljs changes, probably with emphasis on how the libs can use the same code to work with both foreign-libs and Node (i.e. global-exports and related things), and what this requires from Cljsjs and libs

anmonteiro16:08:50

I'm going to touch on the major things happening in CLJS land: node modules, js integration, code splitting, maybe selfhosted

anmonteiro16:08:09

@juhoteperi looking forward to hanging out at ClojuTRE!

anmonteiro16:08:19

^ my Lumo talk also briefly mentions implicit requires in Lumo/Node

juhoteperi16:08:55

@anmonteiro Will you be staying here before/after the conf?

anmonteiro16:08:09

I arrive the 31st at night

anmonteiro16:08:30

I leave San Francisco the 30th at 1pm lol :(

anmonteiro16:08:10

Only day I'm staying extra is Sunday

juhoteperi16:08:55

@anmonteiro That's the best day for hanging out 😄

juhoteperi16:08:19

I'll have to think about how to top last year, especially if @martinklepsch is present again

martinklepsch17:08:53

just booked my flights ✌️

anmonteiro17:08:28

just attached this patch to CLJS-2334

juhoteperi17:08:25

@anmonteiro Cool. Is it our code or Closure code which requires absolute paths? All this handling of file paths as strings is quite complex.

anmonteiro17:08:57

Closure won’t find the node modules if we don’t pass absolute paths

anmonteiro17:08:13

putting together an example for you

anmonteiro17:08:09

@juhoteperi given test.js and npm install left-pad:

var leftPad = require('left-pad');

console.log(leftPad(42,5,0));

anmonteiro17:08:21

this works:

java -jar closure.jar /Users/anmonteiro/Documents/github/clojurescript/test.js /Users/anmonteiro/Documents/github/clojurescript/node_modules/left-pad/package.json /Users/anmonteiro/Documents/github/clojurescript/node_modules/left-pad/index.js --process_common_js_modules --module_resolution NODE > bundle.js

anmonteiro17:08:31

this doesn’t:

java -jar closure.jar test.js /Users/anmonteiro/Documents/github/clojurescript/node_modules/left-pad/package.json /Users/anmonteiro/Documents/github/clojurescript/node_modules/left-pad/index.js --process_common_js_modules --module_resolution NODE > bundle.js
test.js:1: WARNING - Failed to load module "left-pad"
var leftPad = require('left-pad');
    ^

test.js:1: WARNING - Failed to load module "left-pad"
var leftPad = require('left-pad');
              ^

0 error(s), 2 warning(s)

juhoteperi17:08:07

Oh so because we use absolute paths for node modules, we need to use absolute paths for all files JS being processed

juhoteperi17:08:51

Another part I wondered was, why Closure wants the paths as strings, instead of File objects, but that is probably because some of the sources are not Files: https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/closure.clj#L86-L93

shaunlebron19:08:27

would it be a good idea to make NodeList ISeqable?

shaunlebron19:08:28

so querySelectorAll can be iterated like a sequence

martinklepsch19:08:19

@shaunlebron I think that has been considered and was rejected because it’s “to much implicitness” or so

shaunlebron19:08:41

how do cljs people iterate a NodeList then?

Roman Liutikov19:08:10

In such cases I do Array.from first

martinklepsch19:08:19

also CLJS targets multiple platforms, some of which don’t have the concept of NodeList

shaunlebron19:08:37

Array.from is not supported in IE, lemme check goog

Roman Liutikov19:08:29

the old way is Array.prototype.slice.call(coll)

shaunlebron19:08:57

goog.array.toArray will convert any object with a .length property to an array: https://google.github.io/closure-library/api/goog.array.html#toArray

shaunlebron19:08:15

guess I’ll be using this!

shaunlebron19:08:59

yup, that did it, thanks @juhoteperi !

shaunlebron19:08:03

apparently prim-seq works the same way goog.array.toArray does, but produces a sequence

shaunlebron19:08:28

i’ll document this

shaunlebron19:08:19

ha, it’s been in core since the first cljs release

shaunlebron19:08:29

documented

rauh19:08:04

aclone is also a good option to copy an array like object to a real array. I'd hesitate to use prim-seq to wrap a NodeList.

juhoteperi20:08:35

array-seq docstring says "from a JavaScript array or array-like object" so I think it should be fine, NodeList is "array-like"

juhoteperi20:08:50

lol no, I was looking at the docs written by @shaunlebron 😄

juhoteperi20:08:21

okay, yeah, that also says array-like