Fork me on GitHub
#shadow-cljs
<
2023-01-31
>
Hankstenberg08:01:35

Good morning, does anybody know how shadow-cljs figures out which JDK to use? It's pointing to an no longer existing version on my disk and it doesn't seem to be the alias or JAVA_HOME.

thheller08:01:31

it doesn't figure anything. it executes java, whereever that leads is up to your system

2
🙌 2
Hankstenberg08:01:34

Ah you're right... it must be vscode then.

thheller08:01:12

I guess you can check via node -e "require('which').sync('java')" in the project dir

thheller08:01:55

should be equiv to which java or whereis java or whatever OS command you ahve

Hankstenberg08:01:05

Got it, thank you 🙂

pez09:01:36

I always start VS Code from a terminal where the environment is what I want it to be. Starting apps from the GUI has a tendency to start them in some weird environment.

pmooser13:01:20

What does this mean - does it indicate a syntax error, or a missing resource?

[2023-01-31 14:41:59.327 - INFO] :shadow.build.npm/js-invalid-requires - {:resource-name "node_modules/@automerge/automerge-wasm/nodejs/automerge_wasm.js", :requires [{:line 4, :column 37}]}

pmooser14:01:19

I'm trying to read this to understand a little better: https://github.com/thheller/wasm-pack-cljs

pmooser14:01:09

What I'm trying to do is migrate to the new automerge 2.0 project: https://automerge.org/blog/automerge-2/

thheller16:01:09

for some reason they use

const { TextDecoder, TextEncoder } = require(`util`);

thheller16:01:26

so backtick instead of quote

thheller16:01:42

this is not currently supported I guess

thheller16:01:15

you can open a ticket for what, that is fixable

thheller16:01:34

however I'm less optimistic about the wasm working 😉

thheller16:01:01

const path = require('path').join(__dirname, 'automerge_wasm_bg.wasm');

thheller16:01:11

will definitely 100% not work in the browser

thheller16:01:00

I give that package a 0% chance of working with shadow-cljs 😉

pmooser17:01:38

@thheller Thank you so much for your detailed response! I will take a look at that webpack thing ... is it possible to use it just for one library?

thheller17:01:03

nope, all or nothing

pmooser17:01:31

Ok, that is indeed how it appeared from the web page.

pmooser11:02:16

@thheller So if we use the :external js provider like that, is it still possible somehow to use shadow-cljs for interactive development (like with hot reloading and stuff)? Because if I understand the order of operations correctly, first we invoke shadow-cljs, which generates a js file, which then we feed into webpack, and then we have our index.html load both files ...

pmooser11:02:38

Is the idea that if I don't change the js requirements often, we don't actually have to do the webpack step very often, and we can just sort of use shadow-cljs like normal?

thheller11:02:53

yes, the only part that changes is that you can't dynamically change JS dependencies

thheller11:02:11

otherwise hot-reload works as before

pmooser11:02:20

Ok. I'm learning this stuff very slowly and I will give it a try. Is there any hope for more seamless support for WASM eventually, or is that really just dependent on the dust settling in the WASM ecosystem?

thheller11:02:11

eventually when there is a standard for this yes

thheller11:02:27

right now every wasm lib seems to do its own weird non-standard stuff

thheller11:02:38

most are specifically tailored for webpack

pmooser11:02:45

Ok, that seems very reasonable.

pmooser11:02:53

Thank you!

pmooser12:02:38

@thheller I sort of got it working (the build with webpack), but even after getting it to load the wasm and stuff, I seemingly can't resolve anything in the automerge package itself. Any further suggestions for debugging?

pmooser12:02:54

I suppose the concrete issues I'm seeing are not being able to use anything from automerge (like calling Automerge/init doesn't work - it can't find it), but also I think something about the build related to my inclusion of io.github.nextjournal/markdown didn't work, because I get this error upon loading:

thheller12:02:34

this is not an error you would get from a :js-provider :external build

thheller12:02:02

so I suspect you might be loading some outdated files. might be cache, might just be outdated files when you changed filenames or something

pmooser16:02:59

Ok, thanks - I will try clearing out everything and seeing if that helps.

pmooser16:02:20

No, I get exactly the same issue and error. I'm wondering if maybe some js or something is bundled in the nextjournal markdown project which is then somehow not visible to webpack.

pmooser16:02:54

All I am doing in terms of procedure is a shadow-cljs compile of my build, and then npx webpack (with a suitable config just telling it what to read from and where to write to) ...

thheller16:02:02

without seeing configs/code I cannot say much

pmooser16:02:49

Yeah. I am going to try to see if I can make it work with bare cljs, just to have some info from that perspective, with a new barebones project that just pulls in Automerge 2. If I manage to make THAT work, maybe I'll bug you about shadow-cljs.

thheller16:02:02

I'm happy to take a look at a repro that is failing, just need something to look at :P

pmooser16:02:43

Thank you very much for that - my company won't let me share what I am doing directly, but maybe I can make a simple repro case.

souenzzo17:01:21

I'm using shadow-cljs with :js-options :resolve:

"user-gql-query" {:target :global :global "UserGqlQuery"}
"all-gql-queries" {:target :file
                   :file   "dist/all_gql_queries_bundle.js"}
My all_gql_queries_bundle is generated from a JS file that does import * as UserGqlQuery "user.gql" window.UserGqlQuery = UserGqlQuery and uses webpack to "compile" gql files into js files. my cljs namespace imports both "all-gql-queries" and "user-gql-query" when the namespace tries to load, it fails with shadow-cljs - failed to load module$users_gql_queries Inspecting the browser, I am able to access window.UserGqlQuery without issues (it returns the value that I expect) but shadow$provide returns an empty object. then shadow$provide.module$users_gql_queries returns undefined.

thheller19:01:24

:target :file is really not recommended. neither is the :resolve config

thheller19:01:52

better to use :js-package-dirs ["node-modules" "your-modules"] in the build config

thheller19:01:17

then have your webpack output go to your-modules/all-gql-queries/index.js

thheller19:01:38

but be careful with running secondary bundlers, it may lead to duplicated packages

thheller19:01:42

I don't know why you have the global stuff

thheller19:01:07

just use js/UserGqlQuery?

souenzzo21:01:40

> but be careful with running secondary bundlers, it may lead to duplicated packages this is just for import .gql files directly into JS bundle Tomorrow I will try to access the globals directly. Maybe even add the external script src= and leave the cljs build way cleaner.

thheller21:01:46

I don't know what .gql files are, but webpack in the process of bundling them might include npm dependencies

thheller21:01:54

that shadow-cljs may not see and maybe import again

souenzzo21:01:48

GraphQL query files

thheller21:01:27

I guessed as much

Sam Ritchie20:01:21

I had a project where I included something from src/deps.cljs in peerDependencies, and found that shadow would try to install it every time. The problem was that the npm install call that shadow issued would destroy any npm link calls I had run, to get npm to look at local versions of one of the dependencies I was working on

thheller20:01:02

uhm aren't peerdependencies only relevant in libraries?

thheller20:01:36

I don't even know what npm link is, so no idea about that

Sam Ritchie20:01:37

same with devDependencies, right?

thheller20:01:57

I'm not really understanding your question I guess

Sam Ritchie20:01:23

@thheller you use npm link when you have an npm dependency like mathbox, and you want to develop against local copy of it

Sam Ritchie20:01:51

I was working a library that declared mathbox as a peerDependency

thheller20:01:17

doesn't peer dependency just mean "don't install it" when you run npm install?

Sam Ritchie20:01:33

it means “required but you bring your own version”

Sam Ritchie20:01:39

it actually DOES install by default

Sam Ritchie20:01:51

wait, sorry, let me be clear

Sam Ritchie20:01:49

if I declare a peerDependency in my own project, it is definitely installed. if someone then depends on me, npm install actually WILL install my declared peerDependencies; but usually it’s like a JVM “provided” dependency. It means “consumers have to have SOME version of this but I want to force you to declare it on your own”

Sam Ritchie20:01:58

“npm link” replaces the node_modules entry of a library with a symlink to a local path. the problem is that shadow-cljs is calling npm install inappopriately, since its is-installed? filter is not catching things I have in peerDependencies; and that npm install call blows away my npm link symlinks

thheller20:01:08

so why do any of this at all?

thheller20:01:34

I'm still seriously considering removing npm-deps install thing entirely

👍 2
thheller20:01:40

it has been nothing but trouble 😛

thheller20:01:58

you can set :npm-deps {:install false} in shadow-cljs.edn

thheller20:01:02

then it won't do anything 😛

Sam Ritchie20:01:09

I want it to install dependencies!

Sam Ritchie20:01:17

I just want it to realize that I’ve already installed stuff in peerDependencies

Sam Ritchie20:01:17

it’s great, I think it would be a sad experience to have to tell users to manually install the npm deps my libraries are building on, especially multiple levels deep; users shouldn’t be manually resolving dependency trees

thheller20:01:20

but shipping libraries is entirely different from developing libraries

Sam Ritchie20:01:29

I develop, then I ship…

thheller20:01:42

so you during development can skip the automated install entirely, especially if you are doing npm link and whatever

thheller20:01:52

the end user can still install everything normally, without any of your custom things going on?

Sam Ritchie20:01:59

ah, I see what you’re saying

thheller20:01:33

I mean I'm fine with adding peerDependencies in the lookup stuff

thheller20:01:01

but doesn't seem like that would totally prevent this from accidentally nuking your custom setups

Sam Ritchie20:01:22

yeah, you’re right that it would still nuke them the first time, until the deps.cljs entries had made it into package.json

Sam Ritchie20:01:25

so this is good to know for sure

thheller20:01:06

but you are a developer of a library, should not be dependent of transfering your OWN npm dependencies out of deps.cljs if you ask me

thheller20:01:14

you should manage and maintain your own package.json

thheller20:01:21

and more importantly your own lock files

thheller20:01:29

including keeping them in git

thheller20:01:47

what the end user gets is entirely different story if you ask me

thheller20:01:31

I even go so far as having an entirely separate package.json file for published packages

Sam Ritchie20:01:12

> but you are a developer of a library, should not be dependent of transfering your OWN npm dependencies out of deps.cljs if you ask me I agree but this happens automatically if you include a src/deps.cljs in your classpath

thheller20:01:25

then don't include it 😛

Sam Ritchie20:01:59

it comes in via my :deps dependencies

Sam Ritchie20:01:00

I’m not sure what problem I solve by excluding it? I basically don’t want to care at all about npm after declaring the dep, so it actually feels like the right thing to do to get my deps in via deps.cljs

Sam Ritchie20:01:09

what if I forget to add something new to it, or update a version

Sam Ritchie20:01:13

I mean I totally trust you that deps.cljs is causing trouble, you’re the expert here… maybe I’m too used to the status quo to imagine other solutions

thheller20:01:03

does this work with regular cljs?

thheller20:01:21

ie. having a cljs namespace including a npm package of the same name?

thheller20:01:26

it doesn't right?

thheller20:01:58

shadow-cljs has a special case where a string always only refers to JS requires

thheller20:01:15

in regular CLJS (:require ["clojure.string" :as x]) is valid, which I consider a bug

thheller20:01:00

but I'd assume that the ["mafs" :as m] is treated as a self-require and would error out?

thheller20:01:18

also single segment namespaces in cljs are kind of problematic, so not recommended

Sam Ritchie20:01:11

sorry looking now

Sam Ritchie20:01:42

@thheller I had asked here a while ago and it sounded like it was supported; `“mafs” here is an npm dependency

Sam Ritchie20:01:55

@thheller I should probably rename the cljs namespace mafs.core

Sam Ritchie21:01:29

> but I’d assume that the ["mafs" :as m] is treated as a self-require and would error out? I have only tried it with shadow, where it works fine… I should get a proper vanilla build going

thheller21:01:17

I mean if you are care just mafs is fine

thheller21:01:30

but I don't think the regular CLJS build process will like that

Sam Ritchie21:01:18

yeah, you’re probably right. I should change it and folks can always alias