cljs-dev

ClojureScript compiler & std lib dev, https://clojurescript.org/community/dev
2020-06-01T05:53:10.407500Z

Would it make sense for tools.deps to be extended to have a CommonJS Package Registry resolver?

2020-06-01T05:54:25.409Z

It would be a little tricky, since it would need to support package.json parsing to manage transitive deps as it does now for pom.xml with Maven registries

2020-06-01T05:55:28.410700Z

But if it did, one could depend on NPM deps freely. And one could have a ClojureScript lib with NPM dependencies. And tools.deps would be able to do a full dependency closure on all of it and resolve conflicts, pull down the defined versions, etc.

dominicm 2020-06-01T09:10:41.416600Z

Npm works differently to tdeps expectations because of hierarchical dependencies. Also, clojurescript doesn't search the classpath for node dependencies.

dominicm 2020-06-01T09:11:19.417700Z

You can already depend on npm dependencies. I think it's deps.cljs on the classpath

dominicm 2020-06-01T09:13:54.418300Z

https://github.com/vouch-opensource/krell/blob/master/src/deps.cljs I can't find docs, but krell uses this feature

bhauman 2020-06-01T16:07:38.424600Z

OK so I the behavior I see when using the :bundle target is that cljsjs libraries are not connected to the required namespace symbol. When using reagent for instance, in the expression (:require [react]) the react symbol does not get bound to the cljsjs/react library when the react npm package has not been installed to node_modules.

bhauman 2020-06-01T16:08:53.425500Z

what I see is an npm_deps.js with no entries, and in the compiled code I see reagent.impl.component.node$module$react = require('react');

bhauman 2020-06-01T16:10:04.426200Z

Just verifying that this is the expected behavior

bhauman 2020-06-01T16:22:56.428100Z

Folks probably need to understand the ins and outs of all this more as we move forward

dnolen 2020-06-01T16:30:23.429100Z

@bhauman not expected, file an issue in JIRA this seems pretty minimal

bhauman 2020-06-01T16:30:42.429300Z

got it

dnolen 2020-06-01T16:30:55.429700Z

basically if it's not in node_modules it should be resolved in the usual way

bhauman 2020-06-01T16:31:31.430400Z

cool that’s what I thought the behavior should be

dnolen 2020-06-01T16:31:34.430600Z

though you should check one thing

dnolen 2020-06-01T16:31:51.431100Z

whether cljsjs.react has a deps.cljs with :npm-deps in it

dnolen 2020-06-01T16:32:00.431600Z

@juhoteperi ^

bhauman 2020-06-01T16:33:11.431900Z

reagent does of course

dnolen 2020-06-01T16:33:27.432200Z

right so need to think about that then

bhauman 2020-06-01T16:34:56.432700Z

cljsjs/react does not though

dnolen 2020-06-01T16:35:08.432900Z

right sorry I mean reagent of course

bhauman 2020-06-01T16:35:15.433300Z

oh makes sense

dnolen 2020-06-01T16:35:16.433400Z

cljsjs/react wouldn't do that

dnolen 2020-06-01T16:35:54.433800Z

yeah open to ideas here, not sure what makes sense

dnolen 2020-06-01T16:36:04.434200Z

the first thing that comes to mind is :npm-deps supporting excludes

dnolen 2020-06-01T16:36:54.435Z

though my feeling is that this feels a bit like overkill

dnolen 2020-06-01T16:37:11.435800Z

if you're going to use :bundle mixing it with CLJSJS seems silly anyway

dnolen 2020-06-01T16:37:30.436600Z

especially if the lib you are using declared an npm dep

bhauman 2020-06-01T16:37:34.436700Z

yes it does but dependencies are trees

dnolen 2020-06-01T16:37:55.437100Z

but Reagent has done something funny

dnolen 2020-06-01T16:38:02.437400Z

which is to declare two different deps

dnolen 2020-06-01T16:38:21.437900Z

the same dep two very different ways

bhauman 2020-06-01T16:38:22.438100Z

I thought that was the pattern to support both

dnolen 2020-06-01T16:38:32.438500Z

not the way Reagent has done

dnolen 2020-06-01T16:38:38.438800Z

Reagent has created a conflict

dnolen 2020-06-01T16:38:49.439200Z

this is completely different from a user managing stuff

dnolen 2020-06-01T16:40:05.440400Z

which is why I'm suggesting :excludes to remove an upstream conflict

bhauman 2020-06-01T16:40:56.441500Z

So install-deps is inly intended to work for libraries that declare npm-deps by default

juhoteperi 2020-06-01T16:41:01.441700Z

Huh, what's the problem?

dnolen 2020-06-01T16:41:36.442900Z

the issue is that Reagent I believe both declared a dep on Maven dep and a NPM dep for the same library

dnolen 2020-06-01T16:41:45.443200Z

in this case React

dnolen 2020-06-01T16:42:11.444400Z

though ...

dnolen 2020-06-01T16:42:20.445100Z

I guess we could only believe node_modules

dnolen 2020-06-01T16:42:23.445500Z

and ignore :npm-deps

juhoteperi 2020-06-01T16:42:24.445600Z

deps.cljs is only used if install-deps is enabled?

bhauman 2020-06-01T16:42:48.446300Z

@juhoteperi uh no

dnolen 2020-06-01T16:42:48.446400Z

no no

bhauman 2020-06-01T16:43:18.447100Z

@juhoteperi we pinged you to find out something we answered already

bhauman 2020-06-01T16:43:56.447800Z

@dnolen that makes sense to me

dnolen 2020-06-01T16:46:11.448400Z

hrm

dnolen 2020-06-01T16:46:15.448600Z

I audited the code a little bit

dnolen 2020-06-01T16:46:26.449Z

I'm not saying you aren't observing what you're observing

dnolen 2020-06-01T16:46:58.449800Z

but I don't see how it wouldn't pick up cljsjs/react , it appears we do use node_modules as the source of truth

bhauman 2020-06-01T16:47:17.450200Z

yeah it is strange for sure

dnolen 2020-06-01T16:47:38.450700Z

please make something tiny and I can poke around - it's might be something else

bhauman 2020-06-01T16:48:04.450900Z

I’ll put it in the jira

dnolen 2020-06-01T16:48:08.451200Z

thanks!

bhauman 2020-06-01T16:48:30.451700Z

its just the simplest example without installing react via npm

bhauman 2020-06-01T16:48:47.452100Z

i’m actually using the the webpack guide example

bhauman 2020-06-01T16:49:20.453100Z

just skipping the npm add react react-dom step

dnolen 2020-06-01T16:49:20.453200Z

but there are many strange things about what you're talking about - no errors

dnolen 2020-06-01T16:49:23.453400Z

which seems impossible

dnolen 2020-06-01T16:49:36.453800Z

it's either in node_modules or the classpath or you're going to get an error

bhauman 2020-06-01T16:49:52.454200Z

I’m not excluding cljsjs

dnolen 2020-06-01T16:50:52.455200Z

but that's what I'm talking about

dnolen 2020-06-01T16:50:58.455400Z

so it must have found the classpath one

bhauman 2020-06-01T16:52:03.456100Z

it does find the classpath one and includes it

bhauman 2020-06-01T16:52:17.456600Z

but doesn’t bind it to the namespace symbol

bhauman 2020-06-01T16:53:15.457300Z

BTW sorry for punctuating your days like this

dnolen 2020-06-01T16:53:37.458100Z

no what I mean is there are two incompatible things

dnolen 2020-06-01T16:53:44.458400Z

A) classpath library is found

dnolen 2020-06-01T16:54:12.459500Z

B) node.js require emitted even though A) means it cannot be indexed under :node-module-index

thheller 2020-06-01T16:54:35.460Z

FWIW in shadow-cljs I completely dropped support for foreign-libs because I didn't want to deal with "mixing" dependencies. one library depending on cljsjs while the other going to npm directly. you might want to do the same for :bundle builds?

dnolen 2020-06-01T16:54:54.460800Z

there's no need as far as I can tell as of yet

bhauman 2020-06-01T16:55:12.461500Z

but there are foreign-libs that are just javascript includes for the local build

dnolen 2020-06-01T16:55:16.461600Z

just a hassle for existing users who are transitioning too

bhauman 2020-06-01T16:55:55.462200Z

yeah that’s the problem that someone came to me with this morning

dnolen 2020-06-01T16:56:11.462700Z

in anycase what you're observing seems like an impossible situation - from looking over the code

dnolen 2020-06-01T16:56:25.463400Z

you somehow have a node lib and a foreign dep

bhauman 2020-06-01T16:56:33.463600Z

OK it’ll be in the JIRA

thheller 2020-06-01T16:56:41.464100Z

I just wrote a stub library that maps the most common cljsjs package pack to a regular require and exposing the global

dominicm 2020-06-01T16:56:46.464600Z

Could it be a transitive dependency?

dominicm 2020-06-01T16:57:03.465700Z

Eg webpack depends on react or something

dnolen 2020-06-01T16:57:05.465800Z

he never ran --install-deps so I doubt it

dnolen 2020-06-01T16:57:34.466500Z

making :bundle work w/ everything that came before isn't that hard and is in the spirit of not breaking stuff that used to work

dnolen 2020-06-01T16:57:39.466700Z

not going to change anything here

dominicm 2020-06-01T16:58:17.467500Z

Must have installed webpack though, regardless of using cljs.main to do so?

bhauman 2020-06-01T16:58:45.468400Z

let me detail the steps so there is little confusion

dnolen 2020-06-01T16:58:49.468500Z

@bhauman you verified react isn't at the top level yes?

dnolen 2020-06-01T16:58:56.468800Z

it does not matter who installed it by the way

bhauman 2020-06-01T16:58:58.469Z

yes

dnolen 2020-06-01T16:59:05.469200Z

k

bhauman 2020-06-01T17:22:54.469400Z

https://clojure.atlassian.net/browse/CLJS-3258

bhauman 2020-06-01T17:23:10.469900Z

I double checked it to make sure

dnolen 2020-06-01T17:25:02.470200Z

thanks!!! will take a look

2020-06-01T17:30:46.471200Z

Hey, I’m the one chatting to @bhauman. Wasn’t really expecting this to go here =)…

bhauman 2020-06-01T18:18:02.472200Z

And here is another question: is this code broken or are we supporting it? https://github.com/JulianBirch/cljs-ajax/blob/master/src/ajax/xml_http_request.cljs#L29

bhauman 2020-06-01T18:19:21.473600Z

basically its using cljs.core/*target* to detect if its in node.js

bhauman 2020-06-01T18:19:46.474100Z

unfortunately under :bundle its “nodejs”

dnolen 2020-06-01T18:59:17.474400Z

not really interested in making a new target

bhauman 2020-06-01T18:59:26.475Z

actually

dnolen 2020-06-01T18:59:31.475300Z

people should detect the platform by some other means

bhauman 2020-06-01T18:59:43.475700Z

its a problem with the way its written

bhauman 2020-06-01T18:59:48.475900Z

I was wrong

bhauman 2020-06-01T18:59:58.476200Z

the require is emitted

bhauman 2020-06-01T19:00:18.476500Z

either way so it doesn’t work in advanced

dnolen 2020-06-01T19:01:12.477500Z

right that code just seems problematic

bhauman 2020-06-01T19:01:13.477600Z

and we can override the *target* in closure defines

bhauman 2020-06-01T19:01:29.477900Z

if we someone needs to

bhauman 2020-06-01T19:03:00.478400Z

unfortunately a very popular library

dnolen 2020-06-01T19:06:58.479Z

I debated whether or not to actually emit a new target

dnolen 2020-06-01T19:07:10.479400Z

but in the end that just means another thing for people to hook onto that they probably shouldn't

bhauman 2020-06-01T19:14:38.481800Z

yeah I’m going to advise they use goog.global.require to not trigger the bundler, and use a different way to detect nodejs

thheller 2020-06-01T19:17:26.482Z

that won't work. require is not a global.

bhauman 2020-06-01T19:18:31.482400Z

@thheller oh cool

bhauman 2020-06-01T19:18:38.482600Z

bad idea then

bhauman 2020-06-01T19:19:11.483100Z

@thheller how do you solve this problem, you must have come across it

bhauman 2020-06-01T19:19:32.483400Z

cljs-ajax specifically

thheller 2020-06-01T19:20:34.484300Z

its not a problem since I don't extract js/require calls in the code for normal builds

thheller 2020-06-01T19:20:46.484600Z

so for node builds it takes the correct path and just requires at runtime

thheller 2020-06-01T19:21:12.485100Z

for browser builds it also does the correct thing and just uses XHR

bhauman 2020-06-01T19:21:26.485800Z

and that’s the trick

bhauman 2020-06-01T19:21:54.486500Z

do you special case other things besides XHR?

thheller 2020-06-01T19:22:19.487100Z

no special case at all here. it is the logic in their code that does this.

thheller 2020-06-01T19:22:55.487700Z

the problem only appears if you try to extract js/require calls when trying to feed them to the other bundler

thheller 2020-06-01T19:23:09.488Z

I only do this for react-native builds but not browser/etc

bhauman 2020-06-01T19:23:56.489200Z

OK I’m trying to understand here the

bhauman 2020-06-01T19:24:14.489600Z

CLJS is emitting require("xhr...")

bhauman 2020-06-01T19:24:24.489900Z

and we pass that to the bundler

bhauman 2020-06-01T19:24:34.490200Z

and the bundler does the wrong thing

bhauman 2020-06-01T19:24:57.490700Z

I’m not understanding the word extract in this context

bhauman 2020-06-01T19:25:25.491100Z

well we pass all the code to the bundler so that it resolves the requires

bhauman 2020-06-01T19:26:02.491500Z

oh and I’m talking about advanced builds here

bhauman 2020-06-01T19:26:07.491700Z

not normal builds

bhauman 2020-06-01T19:26:22.492Z

advanced or simple builds

thheller 2020-06-01T19:29:29.493400Z

oh right .. well I don't pass anything to a bundler so the "rogue" require call does nothing

thheller 2020-06-01T19:29:49.494Z

its only for react-native builds that I actually extract js/require calls from the code since that will go through metro

thheller 2020-06-01T19:29:53.494300Z

but all other builds won't

bhauman 2020-06-01T19:31:07.495100Z

well that’s food for thought

bhauman 2020-06-01T19:32:08.496Z

and this case is particularly interesting because I don’t see how to make this code work at all now, if its getting passed to a bundler

bhauman 2020-06-01T19:32:18.496400Z

a macro won’t work

bhauman 2020-06-01T19:32:30.496900Z

because target is “nodejs”

dnolen 2020-06-01T19:32:44.497200Z

to be honest I still think the library should just fix this

thheller 2020-06-01T19:32:52.497800Z

yeah its not a great pattern but I've seen other libs doing this

bhauman 2020-06-01T19:32:52.497900Z

the question is how?

dnolen 2020-06-01T19:32:56.498Z

because it's hard coded to a dynamic require

bhauman 2020-06-01T19:33:10.498400Z

but how do they fix it?

thheller 2020-06-01T19:33:42.499600Z

well its not a problem in shadow-cljs so doesn't require fixing. no clue about :bundle.

thheller 2020-06-01T19:35:43.001700Z

but conditional requires are not fun to work with at all so I'd like there to be a better solution. just not sure how.

dnolen 2020-06-01T19:35:46.001800Z

I don't have any interesting ideas that I'd be willing to implement or see implemented at the moment

dnolen 2020-06-01T19:36:29.002400Z

the issue is way beyond this particular lib

dnolen 2020-06-01T19:36:44.002800Z

any library that leaks js/require has this problem

bhauman 2020-06-01T19:37:08.003500Z

they can’t use :npm-deps

bhauman 2020-06-01T19:38:22.004400Z

they want a library thats cross-platform but it doesn’t look possible

dnolen 2020-06-01T19:38:39.004900Z

doing this in JS wouldn't work either?

dnolen 2020-06-01T19:38:45.005200Z

it's not specific to ClojureScript

thheller 2020-06-01T19:39:07.005600Z

it does work in JS and is quite common. webpack eliminates some basic conditionals

thheller 2020-06-01T19:39:28.006100Z

eg. https://unpkg.com/react@16.13.1/index.js

bhauman 2020-06-01T19:39:28.006200Z

oh freak

dnolen 2020-06-01T19:39:29.006300Z

"webpack eliminates some basic conditionals" != "it does work"

dnolen 2020-06-01T19:39:36.006700Z

you mean some cases work no?

dnolen 2020-06-01T19:40:00.007400Z

but that honestly looks like the answer

thheller 2020-06-01T19:40:00.007500Z

yes, it works for some cases

dnolen 2020-06-01T19:40:03.007700Z

not our problem

dnolen 2020-06-01T19:40:05.007900Z

do what JS does

thheller 2020-06-01T19:41:28.009200Z

problem is that it likely won't understand the cljs.core/*target* conditional. I have only seen this work for actual const locals and process.env.NODE_ENV

dnolen 2020-06-01T19:41:37.009500Z

but that's what I mean

bhauman 2020-06-01T19:42:00.010100Z

oh OK then that’s doable

bhauman 2020-06-01T19:42:03.010400Z

kinda

dnolen 2020-06-01T19:42:04.010500Z

you would emit that process.env.NODE_ENV

dnolen 2020-06-01T19:42:13.010900Z

the important thing here is this

dnolen 2020-06-01T19:42:29.011500Z

:bundle has to mean stuff that Webpack could consume sensibly if used

dnolen 2020-06-01T19:42:40.012100Z

so for a library to adopt :bundle it has to adopt these bundler conventions

dnolen 2020-06-01T19:42:41.012400Z

about platforms

dnolen 2020-06-01T19:42:48.012700Z

inventing stuff is not that appealing IMO

thheller 2020-06-01T19:43:57.013400Z

NODE_ENV is only about development and production though

thheller 2020-06-01T19:44:44.014800Z

you can always ignore the xmlhttprequest require via webpack config when building for the browser

bhauman 2020-06-01T19:45:10.015300Z

oh well that’s interesting as well

thheller 2020-06-01T19:45:36.015800Z

resolve: {"xmlhttprequest":false} or whatever the config for that was

bhauman 2020-06-01T19:46:37.016500Z

resolve alias

bhauman 2020-06-01T19:46:40.016700Z

got it

thheller 2020-06-01T19:47:39.017400Z

yeah I have something similar in shadow-cljs https://shadow-cljs.github.io/docs/UsersGuide.html#js-resolve .. for some npm packages there is just no other way without manual intervention

bhauman 2020-06-01T19:47:57.018Z

good stuff

dominicm 2020-06-01T19:48:15.018600Z

That means that libraries couldn't change their underlying library without breakage. But that's js too

bhauman 2020-06-01T19:49:00.019100Z

so yeah day8.re-frame/http-fx doesn’t work for advanced because

bhauman 2020-06-01T19:49:02.019300Z

of this

dnolen 2020-06-01T19:58:54.020800Z

but if the underlying lib fixes the issue then it goes away right?

dnolen 2020-06-01T19:59:12.021100Z

to be honest I don't see any simple way to fix this

dnolen 2020-06-01T19:59:31.021800Z

you could legitimately sprinkle your code with js/require knowing you will use a bundler

dnolen 2020-06-01T19:59:59.022200Z

btw, above I wasn't shooting down ideas to fix it - just stating I don't have any good ones

dnolen 2020-06-01T20:01:23.022500Z

which is why I was suggesting adopting bundler conventions

dnolen 2020-06-01T20:01:55.023100Z

because I'm afraid we would just interfere with established conventions

jsa-aerial 2020-06-01T20:24:19.027Z

Can anyone here shed some light on an aspect of the compiler analysis state cache? In particular, in the following JS console inspect snippet, • why isn't the macros field at the "top" level (same level as extrerns? • how can you have multiple null keys in the map and what does that entail?? • what does edit mean?

6: {ns: null, name: "cljs.core.async", str: "cljs.core.async", _hash: -159169011, _meta: null, …}
7:
meta: null
cnt: 16
root:
edit: {}
bitmap: 221921953
arr: Array(24)
0: null
1: {edit: {…}, bitmap: 34603008, arr: Array(8), cljs$lang$protocol_mask$partition1$: 131072, cljs$lang$protocol_mask$partition0$: 0}
2: {ns: null, name: "externs", fqn: "externs", _hash: 221720677, cljs$lang$protocol_mask$partition0$: 2153775105, …}
3: {meta: null, cnt: 3, arr: Array(6), __hash: null, cljs$lang$protocol_mask$partition0$: 16647951, …}
4: null
5:
edit: {}
bitmap: 3211264
arr: Array(8)
0: {ns: null, name: "use-macros", fqn: "use-macros", _hash: -905638393, cljs$lang$protocol_mask$partition0$: 2153775105, …}
1: {meta: null, cnt: 2, arr: Array(4), __hash: null, cljs$lang$protocol_mask$partition0$: 16647951, …}
2: {ns: null, name: "excludes", fqn: "excludes", _hash: -1791725945, cljs$lang$protocol_mask$partition0$: 2153775105, …}
3: {meta: null, hash_map: {…}, __hash: null, cljs$lang$protocol_mask$partition0$: 15077647, cljs$lang$protocol_mask$partition1$: 139268}
4: {ns: null, name: "macros", fqn: "macros", _hash: 811339431, cljs$lang$protocol_mask$partition0$: 2153775105, …}
5:
meta: null
cnt: 3
arr: Array(6)
0: {ns: null, name: "go", str: "go", _hash: 1493584872, _meta: null, …}
1: {meta: null, cnt: 8, arr: Array(16), __hash: null, cljs$lang$protocol_mask$partition0$: 16647951, …}
2: {ns: null, name: "alt!", str: "alt!", _hash: 1759993452, _meta: null, …}
3: {meta: null, cnt: 8, arr: Array(16), __hash: null, cljs$lang$protocol_mask$partition0$: 16647951, …}
4: {ns: null, name: "go-loop", str: "go-loop", _hash: 692273294, _meta: null, …}
5: {meta: null, cnt: 8, arr: Array(16), __hash: null, cljs$lang$protocol_mask$partition0$: 16647951, …}
The context for this is getting the macros to be visible to the compiler

jsa-aerial 2020-06-01T20:25:36.028100Z

An odd (to me) thing is if you look at this in cljs-repl there are no null keys and :macros is at the top level of the map

thheller 2020-06-01T20:36:35.029300Z

you are looking at the internal structure of the map implementation. thats not very interesting. use cljs-devtools or just prn the result to get a useful representation

jsa-aerial 2020-06-01T20:42:04.032700Z

As I mentioned, the 'useful' representation has the :macros field at the top level of the map. Here's a snippet:

((-> state deref :cljs.analyzer/namespaces) 'cljs.core.async)
{:rename-macros {},
 :renames {},
 :externs {Error {}, Array {}, Object {}},
 :use-macros {go cljs.core.async, go-loop cljs.core.async},
 :excludes
 #{reduce take map transduce into partition merge partition-by},
 :macros
 {go
  {:arglists ([& body]),
   :doc
   "Asynchronously executes the body, returning immediately to the\n  calling thread. Additionally, any visible calls to <!, >! and alt!/alts!\n  channel operations within the body will block (if necessary) by\n  'parking' the calling thread rather than tying up an OS thread (or\n  the only JS thread when in ClojureScript). Upon completion of the\n  operation, the body will be resumed.\n\n  Returns a channel which will receive the result of the body when\n  completed",
   :line 4,
   :column 1,
   :file "cljs/core/async.clj",
   :name cljs.core.async/go,
   :ns cljs.core.async,
   :macro true},
  alt!
  {:arglists ([& clauses]),
   :doc
   "Makes a single choice between one of several channel operations,\n  as if by alts!, returning the value of the result expr corresponding\n  to the operation completed. Must be called inside a (go ...) block.\n\n  Each clause takes the form of:\n\n  channel-op[s] result-expr\n\n  where channel-ops is one of:\n\n  take-port - a single port to take\n  [take-port | [put-port put-val] ...] - a vector of ports as per alts!\n  :default | :priority - an option for alts!\n\n  and result-expr is either a list beginning with a vector, whereupon that\n  vector will be treated as a binding for the [val port] return of the\n  operation, else any other expression.\n\n  (alt!\n    [c t] ([val ch] (foo ch val))\n    x ([v] v)\n    [[out val]] :wrote\n    :default 42)\n\n  Each option may appear at most once. The choice and parking\n  characteristics are those of alts!.",
   :line 63,
   :column 1,
   :file "cljs/core/async.clj",
   :name cljs.core.async/alt!,
   :ns cljs.core.async,
   :macro true},
  go-loop
  {:arglists ([bindings & body]),
   :doc "Like (go (loop ...))",
   :line 95,
   :column 1,
   :file "cljs/core/async.clj",
   :name cljs.core.async/go-loop,
   :ns cljs.core.async,
   :macro true}},
 :name cljs.core.async,
But the compiler claims, for example, that the go macro does not exist in the cljs.core.async namespace

thheller 2020-06-01T20:43:00.033200Z

this is self hosted and core.async isn't self-host compatible

jsa-aerial 2020-06-01T20:44:50.034800Z

I am using Andare which is supposed to be self-host compatible. I did discuss a bit with mfikes, but it seemed the issue was more related to the compiler

jsa-aerial 2020-06-01T20:46:16.036500Z

I find it strange that the internal structure differs in the simple respect that the array map impl has (multiple?) null keys

thheller 2020-06-01T20:46:34.036700Z

don't look at the JS representations of the CLJS data structures. they are just going to confuse you. :P

thheller 2020-06-01T20:46:56.037100Z

they are null in clojure too .. you are just not looking at the internal java representation ...

thheller 2020-06-01T20:47:33.037800Z

eg. {ns: null, name: "cljs.core.async", str: "cljs.core.async", _hash: -159169011, _meta: null, …} ... this is the cljs.core.async symbol but its really hard to tell that from the output

jsa-aerial 2020-06-01T20:48:22.038500Z

Yeah, understand that - but it does not have null keys

thheller 2020-06-01T20:49:33.039600Z

watch some talks or read some blog posts about how the CLJ(S) data structures work. it'll make more sense then.

👍 1
jsa-aerial 2020-06-01T20:51:53.041600Z

Putting that aside then (representation aspects), it would then seem that the compiler state does have the macros as in the cljs.core.async name space. But any attempt to reference them gives an analyzer error that the do not exist

thheller 2020-06-01T20:52:36.042200Z

for self hosted the macros will live in cljs.core.async$macros but I'm honestly not entirely sure how self-hosted macros work

thheller 2020-06-01T20:52:58.042600Z

but I do know that they live in a secondary namespace

jsa-aerial 2020-06-01T20:53:24.043100Z

Yeah, that stuff is there as well - and the macros are listed in there too

thheller 2020-06-01T20:54:46.044300Z

I don't know what you actual question is though. the JS "mess" you posted doesn't really tell you anything about the data you actually have. just pprint it or something to get a useful view of the data

thheller 2020-06-01T20:55:01.044700Z

trying to deciper the JS objs is just not useful

jsa-aerial 2020-06-01T20:56:25.045800Z

??? I posted the actual 'useful view' of the compiler state above

thheller 2020-06-01T20:56:46.046100Z

ah thought you got that from somewhere else

jsa-aerial 2020-06-01T20:57:00.046300Z

No, that is the real live data

lilactown 2020-06-01T20:58:29.048200Z

@jsa-aerial it sounds like you’re trying to debug some issue with andare. Like @thheller is saying, the three questions you posted above about the JS is a red herring, it probably has nothing to do with your issue. can you explain the issue you’re having with andare?

jsa-aerial 2020-06-01T21:00:33.049400Z

As mentioned at 4:51 msg, despite the macros being in the compiler state for cljs.core.async, the analyzer claims they do not exist

jsa-aerial 2020-06-01T21:01:54.050300Z

Maybe this is just a fool's errand and unless you know some deep (and apparently opaque) magic, it just isn't possible to get this to work

thheller 2020-06-01T21:02:40.050700Z

where or how does it claim it? maybe your use is just incorrect?

thheller 2020-06-01T21:04:45.053200Z

but self-host macros are definitely magic ... 🙂

jsa-aerial 2020-06-01T21:05:08.053600Z

In a namespace if you issue (require '[cljs.core.async :refer-macros [go]]) for example, it just errors with illegal refer that macro cljs.core.aync/go does not exist.

thheller 2020-06-01T21:05:56.054900Z

what about (require '[cljs.core.async :refer [go]]) or (require-macros '[cljs.core.async :refer [go]])?

thheller 2020-06-01T21:06:34.055700Z

also I'm assuming you are talking about a REPL right? otherwise requires should be in the ns

jsa-aerial 2020-06-01T21:07:51.057200Z

You can (require-macros '[cljs.core.async.macros :refer [go]]) w/o analyzer error, but any attempt to use it (for example with <!) just errors with &lt;! not in a go block.

thheller 2020-06-01T21:08:55.057900Z

where does cljs.core.async.macros suddenly come from?

jsa-aerial 2020-06-01T21:09:42.058800Z

That's the separate namespace you mentioned - cljs.core.async require-macros that

thheller 2020-06-01T21:10:28.059700Z

no I didn't. I said cljs.core.async$macros. which is different. thats the "secondary" namespace self-hosted will be using for macros

thheller 2020-06-01T21:10:50.060200Z

cljs.core.async.macros is another actual ns, which will also have the secondary cljs.core.async.macros$macros

thheller 2020-06-01T21:11:10.060700Z

again ... macros in self-hosted are weird 😛

jsa-aerial 2020-06-01T21:11:19.061Z

> also I'm assuming you are talking about a REPL right? otherwise requires should be in the ns either repl or ns - either way behaves the same

jsa-aerial 2020-06-01T21:11:44.061300Z

Well, there is no cljs.core.async$macros in any of the code

thheller 2020-06-01T21:11:52.061500Z

then there is your problem

thheller 2020-06-01T21:12:04.061800Z

well it shouldn't be in your code .. but it should be in the analyzer state

jsa-aerial 2020-06-01T21:12:52.062700Z

OK, that seems to be how Andare is written. It uses this cljs.core.async.macros namespace

jsa-aerial 2020-06-01T21:16:04.064600Z

It's definitely not in the analyzer state. Does that get generated or is it how the code is expected to be written?

thheller 2020-06-01T21:16:43.065100Z

that you'll have to ask someone that actually knows how self-hosted works 😛

lilactown 2020-06-01T21:16:58.065300Z

does (require '[cljs.core.async :refer [go]]) not work?

jsa-aerial 2020-06-01T21:17:09.065500Z

It does not work

jsa-aerial 2020-06-01T21:17:30.065800Z

It just says it does not exist

thheller 2020-06-01T21:18:32.066200Z

if the analyzer state has no cljs.core.async$macros then it does in fact not exist

jsa-aerial 2020-06-01T21:22:06.068100Z

Well, I guess this just goes back to the 'deep / opaque' magic bit. Andare does not have any such namespace (that I can find) but the claim is that it does work

thheller 2020-06-01T21:22:51.068700Z

it is the namespace the is created when the .clj files are compiled as macros

jsa-aerial 2020-06-01T21:23:10.069400Z

Oh, so it is generated

thheller 2020-06-01T21:23:24.069700Z

it doesn't exist on disk yes ... it is the result of compiling cljs/core/async.clj as a macro namespace

jsa-aerial 2020-06-01T21:23:49.070300Z

Well, there you are - maybe I just need to grab and cache that at compile time

thheller 2020-06-01T21:24:36.070700Z

probably, no clue how self-host handles that.

jsa-aerial 2020-06-01T21:25:22.071Z

Let me try that and see what happens

2020-06-01T21:36:02.071200Z

Dependencies are hierarchical in tools.deps as well. Its a big tree

2020-06-01T21:38:01.071400Z

And ya, I would assume the resolver would make symlinks into a local node_modules folder, or to be honest, it be nice if the compiler did look them up in the classpath, and when :bundle target is chosen it would go and create the node_modules symlinks needed for the js bundler to run over afterwards.

2020-06-01T21:39:36.071600Z

I don't see much issue here. NPM seems pretty standard, it's got packages with versions, which can depend on other packages and optionally their versions if provided a package.lock

2020-06-01T21:41:08.071800Z

At any rate, the compiler is just trying to re-implemented what looks to me like a worse version of tools.deps bit for cljs specifically. So I feel that effort would make sense to be consolidated into tools.deps

2020-06-01T22:13:40.074100Z

Wouldn't that kind of conflict be something that would be solved if we reconcile it all in tools.deps? Tools.deps could find conflicts between a cljsjs and a node_modules or a git deps, etc. And just resolve which one to pull down

jsa-aerial 2020-06-01T22:39:58.074600Z

> maybe I just need to grab and cache that at compile time Nope that doesn't work either. In fact the compiler state at build time claims there is no cljs.core.async$macros namespace. I think I am going to give up and approach originating problem in a (less general, less simple, and less clean) fashion - but which should work, as I will be using core.async at the app (non self hosted) level (which definitely does work). 😒 this was one of the more total wastes of time I've had the misery to have engaged in.