This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-14
Channels
- # ai (3)
- # babashka (45)
- # beginners (81)
- # biff (26)
- # calva (10)
- # cider (5)
- # clj-kondo (55)
- # cljfx (6)
- # clojure (125)
- # clojure-berlin (1)
- # clojure-europe (37)
- # clojure-italy (7)
- # clojure-nl (3)
- # clojure-norway (79)
- # clojure-uk (1)
- # clojurescript (63)
- # clojutre (1)
- # conjure (5)
- # cursive (37)
- # data-science (1)
- # datalevin (4)
- # datomic (28)
- # eastwood (6)
- # fulcro (26)
- # graphql (20)
- # honeysql (6)
- # humbleui (4)
- # jobs-discuss (5)
- # kaocha (1)
- # leiningen (8)
- # missionary (5)
- # nbb (4)
- # observability (3)
- # off-topic (7)
- # pathom (8)
- # podcasts-discuss (1)
- # rewrite-clj (18)
- # ring (6)
- # sci (23)
- # scittle (9)
- # shadow-cljs (49)
- # squint (10)
- # testing (11)
- # xtdb (17)
Has anyone successfully built a VS-Code Web Extension with shadow-cljs?
I need to target the browser, but cannot use any kind of library loading, and need to export functions to the exports
symbol. It seems that when using the :export
metadata on a function shadow emits a goog.exportSymbol
call, but this one is not picked up by VS-Code. I think it "exports" to goog.global
, which is this || self
, but not exports
.
I can set the JavaScript properties to js/exports
manually and it seems to work, but this seems like a hack?
I think it does not. I tried using the :esm
target but this threw errors that export
was not defined
https://code.visualstudio.com/api/extension-guides/web-extensions
Similarly, I need to keep using require
for "vscode"
, but not for others. I am using this in my build config:
:js-options {:js-provider :shadow
:keep-native-requires true
:keep-as-require #{"vscode"}}
This seems to work; however, for some reason my compile output now also wants to require("path")
which does not exist, when I (:require ["vscode-languageclient/browser" :as browser])
. The browser
lib is specifically for this purpose and should not use "path"...I tried :node-library
but get errors about global
being undefined. I figured this is just for node, not for browsers
Interesting. We're using :node-library
in both Calva and Joyride. Maybe that closes the door for enabling them for the Web version of VS Code...
Probably. Meanwhile I am following Thomas' hints and build :npm-module
s and process them with webpack. I hope I never have to step through the resulting JavaScript by hand 😄
We're also using Webpack. Very happy there are these tools like shadow and webpack and such!
But they make me dizzy 🙂
ClojureScript, Closure Compiler, Shadow, Webpack -> Who is contributing what? 😄
your best bet is probably using :target :npm-module
and using their webpack example config
Yeah, I figured that much, as I need "all in one JS file"
Trying this path... I now get "`process` is not defined", and indeed the beginning of cljs_env.js
reads:
var $CLJS = {};
var CLJS_GLOBAL = process.browser ? (typeof(window) != 'undefined' ? window : self) : global;
Looks like this, too, is targeting node?Oh, nevermind, I think I am entering the dark realms of polyfills 😕
not polyfills but yeah. the targets are all designed to make specific assumptions about their environment
so your web extensions is just another very locked down target with very specific kind of expectations
so this would be a custom :target
that just emits exactly what the web extensions expects
Maybe I can help one day, currently I am not too deep into the muddy waters of JavaScript builds 🙂
I said polyfills because I needed to configure webpack to provide polyfills for process
(among others), and then it worked. Even though I am probably pulling in a process
implementation just for the process.browser
flag 😄
I should just get rid of it entirely but don't want to break stuff for people that may rely on it 😛
Get rid of what?
Ah, I was not even aware that this is yours 😄
Is there a way to do !process || process.browser
?
typeof(process) === undefined
?
Let's see!
In the end it will run in a browser
And for testing they have some kind of fake for that
Hm, does not seem to make a difference. But I also don't see the process.browser
bit anymore in the output files. Will keep an eye on it
Maybe of particular interest to shadow-cljs users (at least the ones also using #calva). @danielamber2 and I have made a video about using Calva with shadow-cljs, where we also try to reveal some of the details and how things are composed to make it all work. Some of it applies generally to nREPL tooling, so CIDER (and other nREPL clients) users might also enjoy. I do hope I am not misinforming too much about things there, please let me know if you spot any such. https://www.youtube.com/watch?v=islMjv55cN8 I have also written an article about the same subject. https://blog.agical.se/en/posts/shadow-cljs-clojure-cljurescript-calva-nrepl-basics/ Pick whichever way you fancy. I think they go great together. 😃