This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-14
Channels
@thheller I was looking into how to use shadow-cljs
for creating chrome extension and came across this https://github.com/thheller/shadow-cljs/issues/279. It seems to have been inactive since 2020. Has there been any new update since then?
nowadays likely :target :esm
is the better fit https://clojureverse.org/t/generating-es-modules-browser-deno/6116
I found this https://github.com/binaryage/chromex/tree/master/examples/shadow and it's looking pretty good actually.
Hey I'm working on a strange project that is targeting google apps script. I started out with this template: https://github.com/chrisfarnham/cljs_clamp, but struggled a lot with getting a proper nrepl working with just lein and piggieback. I've since tried moving the project over to shadow-cljs, with pretty good success. Currently I can run a node repl successfully for development, but I'm still running into a couple problems:
1. When I try to push my Code.js file built with shadow-cljs to google apps script, it complains about a bunch of missing names that I think node provides to its scripts. Is there any way to tell shadow-cljs to build my script for node when i'm developing, and without these names when I'm deploying to google apps script (like lein cljsbuild once
does in the linked repo)? I can just use lein cljsbuild once
for deployment, but it feels weird to depend on two build tools like that. Maybe there's a simple solution?
2. Google Apps Script provides some names that are only available when running in Google Apps Script (not node). An example would be js/SpreadsheetApp
(https://github.com/kovasap/autojournal-on-gas/blob/cbfa522932d3b60d3a915dd8e6ff7505935ee26b/src/autojournal/sheets.cljs#L6). When I try to run with these names uncommented in my shadow-cljs node environment I (rightly) get an error. What I would like to do is to have some kind of "if" branch in my code that uses e.g. js/SpreadsheetApp
when running in google apps script, but a mock or fake that I define when running in node. Any tips for how to accomplish this? In other languages I feel like compiler macros would be the solution.
@kovas.palunas sorry but I know absolutely nothing about google apps script and the environment it runs in. :target :node-script
assumes to be running in node, so that might explain errors. which errors would that be though? you didn't say.
The first part of the shadow-cljs generated code (for node) looks like this:
#!/usr/bin/env node
(function(){
var shadow$provide = {};
var SHADOW_IMPORT_PATH = __dirname + '/.shadow-cljs/builds/autojournal/dev/out/cljs-runtime';
if (__dirname == '.') { SHADOW_IMPORT_PATH = "/home/kovas/cljs_clamp/.shadow-cljs/builds/autojournal/dev/out/cljs-runtime"; }
global.$CLJS = global;
global.shadow$provide = {};
try {require('source-map-support').install();} catch (e) {console.warn('no "source-map-support" (run "npm install source-map-support --save-dev" to get it)');}
global.CLOSURE_NO_DEPS = true;
apps script complains when I try to run it because __dirname
and global
are not defined in it's environmentwhen i build with lein cljsbuild once
, my file does not have those names referenced
shadow-cljs: https://github.com/kovasap/autojournal-on-gas/blob/main/dev-Code.js cljsbuild: https://github.com/kovasap/autojournal-on-gas/blob/main/Code.js
i guess what i'm really looking for is a way to use shadow-cljs to build my final js file in the same way that cljsbuild does it
so i don't have parallel dependency files
BTW, my question 2 was answered in another channel, the solution I have is at https://github.com/kovasap/autojournal-on-gas/blob/main/src/autojournal/env_switching.cljc. I still am looking for a way to reference an env var or something in this macro that would let me know that shadow-cljs is building my code (vs lein, or shadow-cljs with different parameters if I find a solution to my question 1)
Maybe another way to phrase the question is: can shadow-cljs make a :target :browser
build where all the code is in one self-contained file?