Fork me on GitHub
#clojurescript
<
2022-09-07
>
dabrazhe10:09:35

I've been away from ClojureScript for a while. What's the current vision on setting up a ClojureScript environment? With live reloading etc. I used to use shadow cljs.

p-himik10:09:56

I'd recommend still sticking to shadow-cljs.

dabrazhe10:09:06

Alright. If I want to use an older project which is build upon Clojurescript—Figwheel—Electron, how feasible is it to use it on shadow-cljs?

p-himik10:09:16

I haven't used figwheel in many years and have never used Electron, so can't tell for sure. But I'd guess that it's perfectly doable. At least in my experience, shadow-cljs works better than other tools - I've never seen something not working in shadow-cljs while working under some other tool.

p-himik10:09:40

And if you have any problems, the support in #shadow-cljs is great.

👍 1
CarnunMP14:09:18

Hey all. I have a question about writing Chrome extensions targeting Manifest V3: or, more specifically, https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/. I'm using #shadow-cljs and https://github.com/binaryage/chromex, which are both wonderful. And best I can tell, digging around, is that with a little tweaking both should just continue to work... with one major exception: https://github.com/thheller/shadow-cljs/issues/902#issuecomment-1021939651`unsafe-eval`https://github.com/thheller/shadow-cljs/issues/902#issuecomment-1021939651. So no REPL. Breaking changes! Yay! 🙃 1. One suggestion I came across (h/t @namy.19) was to https://github.com/thheller/shadow-cljs/issues/902#issuecomment-1021973818, for development. 2. Another possibility is that wasm-unsafe-eval can be utilised somehow, as https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#content-security-policy. But right now I know nothing about WebAssembly, nor how it would come into play. (@thheller, you might have some idea?) So I was wondering if yous lot have any experience solving these problems? Migrating is a necessity, unfortunately, as we're trying to get an extension published to the Chrome Web Store at work, and:

dvingo14:09:14

My plans changed and I am no longer working on the chrome extension, but I will run into this soon enough as I have a fork of the fulcro devtools which is a chrome extension and that is written in cljs. It seems like maintaining a chromium fork with that unsafe-eval support is the "easiest" solution (I don't know of any others). As I said in that comment, it was pretty straightforward to patch the codebase and compile a version. I imagine some members of the cljs community can maintain a fork and then host the binaries so everyone won't need to go through that slow process. It's really quite annoying. Another option is to make some noise on the chrome bugtracker about needing this feature, but not sure how far that will go.

❤️ 1
CarnunMP14:09:13

Yeah... I'm surprised there isn't a general solution already tbh! Are there really so few people writing Chrome extensions in cljs? 😕

dvingo14:09:24

I thought there would be more noise too, but yea, seems like not that many unfortunately. I was playing with a plain JS dev setup and I think that community uses dynamic script tags to reload code? so they don't care about this I think

CarnunMP14:09:11

@U05095F2K, https://github.com/homebaseio/datalog-console is Manifest V2. How are you planning to upgrade? (If you are?)

CarnunMP14:09:33

maybe we should just build a new browser, lol ditch JS while we're at it

CarnunMP15:09:39

> It seems like maintaining a chromium fork with that unsafe-eval support is the "easiest" solution (I don't know of any others). As I said in <https://github.com/thheller/shadow-cljs/issues/902#issuecomment-1124189411 > |that comment>, it was pretty straightforward to patch the codebase and compile a version. I imagine some members of the cljs community can maintain a fork and then host the binaries so everyone won't need to go through that slow process. It's really quite annoying. Any takers? 😛

CarnunMP15:09:39

> Another option is to make some noise on the chrome bugtracker about needing this feature, but not sure how far that will go. Well, they do seem receptive to feedback at least. E.g. here's re custom formatters: https://github.com/binaryage/cljs-devtools/issues/55#issuecomment-632384007

thheller16:09:13

why not just live without unsafe-eval? I mean you can still work on your code in a regular browser repl and then just have the extension specific parts without a REPL?

CarnunMP16:09:39

Well... the extension is a decently sized codebase in its own right, and set to continue to grow. Not just a little thing on the side. 🙂

thheller16:09:33

that might be but how much of that codebase is actually using chrome extension APIs?

thheller16:09:18

and how much do you actually use the REPL to work with those? 😛

CarnunMP17:09:26

> Well... the extension is a decently sized codebase in its own right, and set to continue to grow. Not just a little thing on the side. 🙂 And there are many "extension specific parts": https://developer.chrome.com/docs/extensions/mv3/architecture-overview/#arch And it's already a headache coordinating them! I dread to think about life without Chromex (https://github.com/binaryage/chromex/tree/master/examples/shadow#code-discussion, for one) + the REPL to hand... 😅

CarnunMP17:09:55

> and how much do you actually use the REPL to work with those? 😛 I use it constantly! But you make an interesting point... exactly how much is 'necessary'? :thinking_face:

CarnunMP17:09:46

How would I even isolate things? deep_thinking

thheller17:09:28

not a clue what you are building but should be straightforward given that a chrome extension is still essentially just a browser?

CarnunMP17:09:48

not sure I follow

thheller17:09:57

> not a clue what you are building

thheller17:09:12

so any comment I make is going to be a wild guess. might not apply in any way.

CarnunMP17:09:53

> but should be straightforward given that a chrome extension is still essentially just a browser I'm curious/confused what you meant here is all!

thheller17:09:47

again, without any information about what you are building this comment might not apply

thheller17:09:58

say you are building a chrome extension that displays some web UI (in its own tab, or popup, whatever)

thheller17:09:17

as far as that is concerned that is pretty much just a browser

CarnunMP17:09:46

ah, no that's just one part if I understand you right: 'UI elements' https://developer.chrome.com/docs/extensions/mv3/architecture-overview/#arch there are separate, isolated processes for other functionality: > Chrome extension development is more complex than regular ClojureScript front-end work. You are writing (and debugging) multiple parallel communicating processes: your background page, service worker, your popup, and all the browser pages running your content script. — https://github.com/binaryage/chromex/tree/master/examples/shadow#debugging

thheller17:09:59

I'm gonna stop commenting unless you want to provide specific examples of what you are trying to do (and maybe failing)

thheller17:09:10

it is a waste of time trying to speak generically about this

CarnunMP17:09:41

so, maybe I could develop the popup UI in a REPL on the side, or something... but what about all the other functionality? e.g. injecting a button into the DOM of a specific tab with a content script, sending a message to the background page service worker when it's pressed, so that it can send a http request with access to session storage to our backend... and so on there's lots to consider beyond the sort of thing which could be developed in a regular browser window 😕

CarnunMP17:09:51

apologies if this is still kinda vague! but I don't think this is a waste of time: I disagree that the specifics of what I'm building are relevant what's relevant are these more general details of extension development

CarnunMP17:09:50

thanks for jumping in in any case, @thheller appreciate it :))

CarnunMP15:09:39
replied to a thread:Hey all. I have a question about writing Chrome extensions targeting Manifest V3: or, more specifically, https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/. I'm using #shadow-cljs and https://github.com/binaryage/chromex, which are both wonderful. And best I can tell, digging around, is that with a little tweaking both should just continue to work... with one major exception: https://github.com/thheller/shadow-cljs/issues/902#issuecomment-1021939651`unsafe-eval`https://github.com/thheller/shadow-cljs/issues/902#issuecomment-1021939651. So no REPL. Breaking changes! Yay! :upside_down_face: 1. One suggestion I came across (h/t @namy.19) was to https://github.com/thheller/shadow-cljs/issues/902#issuecomment-1021973818, for development. 2. Another possibility is that `wasm-unsafe-eval` can be utilised somehow, as https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#content-security-policy. But right now I know nothing about WebAssembly, nor how it would come into play. (@thheller, you might have some idea?) *So I was wondering if yous lot have any experience solving these problems?* Migrating is a necessity, unfortunately, as we're trying to get an extension published to the Chrome Web Store at work, and:

> It seems like maintaining a chromium fork with that unsafe-eval support is the "easiest" solution (I don't know of any others). As I said in <https://github.com/thheller/shadow-cljs/issues/902#issuecomment-1124189411 > |that comment>, it was pretty straightforward to patch the codebase and compile a version. I imagine some members of the cljs community can maintain a fork and then host the binaries so everyone won't need to go through that slow process. It's really quite annoying. Any takers? 😛

Steph Crown16:09:48

Hello everyone. I am trying to set up a Phoenix and ClojureScript project but I did not seem to find a lot of resource online to do that. I found this though https://darioghilardi.com/how-to-setup-a-phoenix-and-clojurescript-project/. I followed the guide but it seems it's outdated. Has anyone been able to successfully create a Phoenix and ClojureScript project recently?

thheller16:09:03

not a clue about any of the phoenix parts but the shadow-cljs parts of the first post are still the same

Steph Crown20:09:53

@thheller Please is the following code snippet a valid shadow-cljs configuration?

;; shadow-cljs configuration
{:source-paths
 ["src"]

 :dependencies
 []

 :dev-http {9080 "priv/static/assets/js"}

 :builds {:app {:output-dir "priv/static/assets/js"
                :asset-path "priv/static/assets/js",
                :target :browser
                :modules {:app {:init-fn app.main/main!}}
                :devtools {:after-load app.main/reload!}}}}
Because I keep getting errors that /js/cljs-runtime/goog.dom.nodetype.js.map cannot be found.

thheller20:09:39

:asset-path "priv/static/assets/js" is incorrect

thheller20:09:06

:dev-http {9080 "priv/static/assets/js"} also looks incorrect?

thheller20:09:49

it likely also isn't needed at all. I assume phoenix is capable of serving static files on its own

thheller20:09:26

:asset-path "/static/assets/js" is likely what you need? depending on how you access the js in the page

thheller20:09:13

might be just /js. really don't know how phoenix handles static files

Steph Crown21:09:25

Thanks for your reply. Currently, my system is down. As soon as I'm able to power it, I'll try your suggestion and read up the article that you linked. If I'm not able to get it to work, I'll send my folder structure so it's easier for your to help me. Thanks.

Steph Crown08:09:44

Hi, Please do you know the cause of this error.

c:\Users\Admin\Documents\new-things\phoenix_cljs\assets\node_modules\.bin\shadow-cljs:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1032:15)
    at Module._compile (node:internal/modules/cjs/loader:1067:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)       
    at node:internal/main/run_main_module:17:47
I tried to start the development process by running node_modules/.bin/shadow-cljs watch app and I got that error. What could I be doing wrong?

thheller08:09:19

sorry I don't know bash. this is not from any shadow-cljs code, and you likely want to call npx shadow-cljs watch app

thheller08:09:19

accessing code in node_modules/.bin is not how things should be used

Steph Crown08:09:26

So the problem is I don't know how possible it is for me to call npx directly from the config with Phoenix. It seems a lot of the problem I'm facing is more Phoenix related than cljs.

thheller08:09:00

I mean how do you run commands in general? I see this

node: [
      "node_modules/webpack/bin/webpack.js",
      "--mode",
      "development",
      "--watch-stdin",
      cd: Path.expand("../assets", __DIR__)
    ],

thheller08:09:11

which it incorrect even for webpack

thheller08:09:31

so likely you be node: ["npx", "webpack", "--mode", ...]

thheller08:09:50

or ["npx", "shadow-cljs", ...] in case of shadow-cljs

thheller08:09:15

sorry, I really know nothing about phoenix so I'm just guessing all the way

thheller08:09:36

I don't know why you need to be touching phoenix config in any way

thheller08:09:57

is there any place or way you can put a foo.txt in any folder and load that over http?

thheller08:09:12

that is the place the CLJS output should go and phoenix doesn't need to know anything about it

Steph Crown08:09:13

Yeah, I tried that, but I get this error

Error: Cannot find module 'c:\Users\Admin\Documents\new-things\phoenix_cljs\assets\npx'
So I think it's reading npx as a directory.

thheller08:09:21

it doesn't need to process any JS at all

thheller08:09:31

no, thats a node error

thheller08:09:45

what is the full command you have?

Steph Crown08:09:59

node: [
      "npx",
      "shadow-cljs",
      "watch",
      "app",
      cd: Path.expand("../assets", __DIR__)
    ]

thheller08:09:25

I'm guessing that part already implies that it runs node

thheller08:09:45

maybe that should be npx and then drop the first "npx"?

thheller08:09:20

I don't have any of the necessary tools installed so I can't easily run any of this

Steph Crown08:09:16

Let me try this.

thheller08:09:06

I honestly don't know why you need to be running shadow-cljs as part of phoenix though

thheller08:09:17

that is just a hinderance and provides no benefit to shadow-cljs or phoenix

thheller08:09:37

so I would just run things separately and without them knowing about each other

Steph Crown08:09:47

The suggestion for npx did not work.

Steph Crown08:09:57

It's possible for me to run them separately?

thheller08:09:13

can you open two terminals and run two commands? 😛

thheller08:09:00

I'd say yes. but again: I know absolutely nothing about phoenix. It might be putting you into some kind of jail that doesn't actually allow this

Steph Crown08:09:11

I think I see what you mean. I run the npx command for cljs separately, then I run the mix command after the development server has started.

thheller08:09:30

I cannot answer that. I don't even know what mix is

Steph Crown08:09:43

mix starts the Phonix server.

thheller08:09:50

> then I run the mix command after the development server has started.

thheller08:09:02

then this statement confuses me

thheller08:09:15

you run both completely independently without knowing about each other whatsoever

thheller08:09:33

as far as phoenix is concerned there are just some static .js files it serves

thheller08:09:43

it never looks at or modifies them in any way

Steph Crown08:09:57

Alright, makes sense. I'll try that. Thanks.

thheller08:09:17

as far as I can tell the priv/static folder is meant for that

thheller08:09:39

on the other side you just have shadow-cljs output the files to that dir

thheller08:09:50

without it knowing about phoenix in any way or working with it

Steph Crown08:09:22

Now, I'll try to check the article you linked yesterday so I can fix the shadow-cljs.edn config issue from yesterday

Steph Crown10:09:38

@thheller I really appreciate you for your help, you've been a saviour. I have been able to fix the issue from yesterday. Also, I'm now running both servers independently of each other. Thanks again.

Steph Crown11:09:05

Talking about starting the shadow-cljs server directly from Phoenix config, with a bit of experiment, I have been able to make that work. I used bash instead of node

bash: [
    "node_modules/.bin/shadow-cljs",
    "watch",
    "app",
    cd: Path.expand("../assets", __DIR__)
]
And it was successful.

jpmonettas17:09:31

Hi everybody! Is this a bug or is it imposible to alter meta on ClojureScript?

cljs.user=> (def a 5)
#'cljs.user/a
cljs.user=> (meta #'a)
{:ns cljs.user, :name a, :file "cljs/user.cljs", :end-column 7, :source "a", :column 1, :line 1, :end-line 1, :arglists (), :doc nil, :test nil}
cljs.user=> (alter-meta! #'a assoc :foo true)
{:foo true}
cljs.user=> (meta #'a)
{:ns cljs.user, :name a, :file "cljs/user.cljs", :end-column 7, :source "a", :column 1, :line 1, :end-line 1, :arglists (), :doc nil, :test nil}

thheller17:09:09

correct. not a bug. CLJS essentially doesn't have vars at runtime.

jpmonettas17:09:13

yeah I was almost sure about that, but why is there alter-meta! and reset-meta! that doesn't complain, any idea?

thheller17:09:24

not a clue to be honest.

jpmonettas17:09:58

does anybody knows of a way of manipulating those fields? Because lets say I grab the source of #'clojure.core/map using cljs.repl/source-fn and re evaluate it on the repl, then I don't have those fields anymore and I can't get the source a second time, I'm creating tooling and would like to grab meta, re-evaluate the source of a function and then restore that meta, any ideas?

dpsutton17:09:11

i have an open ticket that is a bit similar: https://clojure.atlassian.net/browse/CLJS-3277 . Def’d vars don’t preserve the metadata given to them

👍 1
Steph Crown08:09:44

Hi, Please do you know the cause of this error.

c:\Users\Admin\Documents\new-things\phoenix_cljs\assets\node_modules\.bin\shadow-cljs:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1032:15)
    at Module._compile (node:internal/modules/cjs/loader:1067:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)       
    at node:internal/main/run_main_module:17:47
I tried to start the development process by running node_modules/.bin/shadow-cljs watch app and I got that error. What could I be doing wrong?