This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-15
Channels
- # announcements (20)
- # babashka (281)
- # beginners (13)
- # biff (8)
- # calva (20)
- # cider (5)
- # clj-commons (1)
- # clojure (46)
- # clojure-boston (1)
- # clojure-europe (6)
- # clojure-losangeles (24)
- # clojuredesign-podcast (3)
- # clojurescript (12)
- # datomic (1)
- # events (1)
- # fulcro (12)
- # guix (2)
- # honeysql (1)
- # integrant (1)
- # introduce-yourself (1)
- # rdf (16)
- # reagent (3)
- # reitit (14)
- # releases (3)
- # sci (28)
- # shadow-cljs (122)
- # specter (1)
- # tools-deps (10)
- # xtdb (6)
@kovas.palunas I don't expect a development build to work. as I said it expects not and as such uses node features. shadow-cljs release app
might.
regarding q2 I made this gist a long time ago https://gist.github.com/thheller/fa044450a6470fdd1afdbcf3f37a65e3
can you point me to some documentation about apps scripts? do they support ES modules? ie. import/export?
the whole point of the shadow-cljs :target
abstraction is to make target specific builds. there could absolutely be a :target :google-apps-script
. I just have never used that so I don't know how it needs to be bundled
thanks for the gist link! i ended up solving that problem with a simple defn that takes in anonymous functions to execute: https://github.com/kovasap/autojournal-on-gas/blob/fe8e80c358f0dce2e9852f8d2f6f7813b23008be/src/autojournal/env_switching.cljs#L3. the resolve call i'm using now works well - is exists?
just a better name for the same functionality?
apps script is interesting in that it's a (AFAIK) totally self contained development environment: https://developers.google.com/apps-script/overview?hl=en
usually you would write code in their browser editor and run it. it interacts with various google products via its own special API
it has a CLI utility for local development (not in their browser editor) https://github.com/google/clasp
my understanding is that apps script code should be bundled as just one big flat js file with everything in it
and no undefined names (that would otherwise be defined in other places)
AFAIK apps script does not support js dependencies of any kind (although if they were inlined in the bit flat file that would work)
one interesting quirk of apps script also is that it doesn't like namespaced names. https://lambdaisland.com/blog/2016-10-01-clojurescript-and-google-apps-script describes a workaround. i'm currently just appending some non-namespaced functions that call my core functionality to my big js file in a bash script
btw it looks like shadow-cljs release app
does not work due to google apps script seeing a syntax error in the generated js file. perhaps this is because of subtle differences between javascript and google apps script
strangely, the lein cljsbuild once
command's output is interpreted just fine. i think this has to do with the clojurescript version. I'm using "1.10.439" in my project.clj
and saw that using "1.10.773" led to this syntax error
i should probably try using this older version in my shadow-cljs
yeah i know, one sec
the message is 'Syntax error: Missing ; before statement. line: 24 file: Code',
, let me get a link to the file
getting it, one sec
also try :compiler-options {:output-feature-set :es5}
in your build config. maybe it doesn't like newer syntax
i just tried a release build here, but got the same syntax errors
errors: [
{
message: 'Syntax error: Missing ) after formal parameters. line: 1420 file: Code',
domain: 'global',
reason: 'badRequest'
}
]
https://github.com/kovasap/autojournal-on-gas/blob/5b07d2ea8a8eb0909638eab0a8f73130ebdebc68/Code.js
goog.loadModule(function(exports) {
"use strict";
goog.module("goog.debug.Error");
goog.module.declareLegacyNamespace();
function DebugError(msg = undefined, cause = undefined) { // <- 1420
if (Error.captureStackTrace) {
Error.captureStackTrace(this, DebugError);
} else {
const stack = (new Error()).stack;
if (stack) {
this.stack = stack;
}
}
the :es5
option didn't work
but i feel like that might be the right idea
it would make sense that apps script is equivalent to a certain version of javascript that is not the latest one
--pseudo-names
didn't work either
i figured out that I can set the javascript version used by apps script to use Chrome V8 instead of rhino, which makes the syntax errors go away!
now i'm simply getting ErrorReferenceError: global is not defined
when i try to run my code
using :target :browser
gives
12:35:01 PM Error Cannot use default debug loader outside of HTML documents.
12:35:01 PM Error Consider setting CLOSURE_IMPORT_SCRIPT before loading base.js, or setting CLOSURE_NO_DEPS to true.
12:35:01 PM Error
TypeError: Cannot set property 'NodeType' of undefined
so yeah i think the syntax error problem is solved, but there is still an issue with shadow-cljs output expecting names that are not provided by the apps script environment (the global
name at least)
yes this is a release build
that makes sense
if i add var global = {};
to the top i get another error:
goog.dom.NodeType = {ELEMENT:1, ATTRIBUTE:2, TEXT:3, CDATA_SECTION:4, ENTITY_REFERENCE:5, ENTITY:6, PROCESSING_INSTRUCTION:7, COMMENT:8, DOCUMENT:9, DOCUMENT_TYPE:10, DOCUMENT_FRAGMENT:11, NOTATION:12};
TypeError: Cannot set property 'NodeType' of undefined
because i think
var goog = goog || {};
goog.global = global;
there are
goog.module.get = function(name) {
return goog.module.getInternal_(name);
};
https://github.com/kovasap/autojournal-on-gas/blob/347a4578351fdce53f52bf9cb05a1e3a0a256450/Code.js
yes those lines exist goog.module("goog.debug.Error");
should they not exist in a release build?
i'm calling (run "npx" "shadow-cljs" "release" "autojournal")
i still have the missing global
problem without :optimizations :whitespace
i tried that
i get ErrorReferenceError: process is not defined
here
;af(function() {
return dt();
}, process.argv.slice(2));
this is the very last bit of code in the file!
I'm not asking about v8 in general. I need to know in the context of google apps script what features it supports
so, are there any docs specifically about what the google apps script runtime is capable of?
i haven't found them yet
I would write a custom :target
for this that handles all the appscript specific stuff. I just don't have time to look into that currently
you can try :target :esm
instead of browser as well https://clojureverse.org/t/generating-es-modules-browser-deno/6116
maybe the v8 supports import
, then dev builds might work. otherwise release
only again
no dice on the :esm
yet: message: "Syntax error: SyntaxError: Unexpected token 'export' line: 14202 file:
no worries!! I'm super grateful for all the tips so far!
I believe you can also just leave out exports in the build config and just use :entries [your.ns]
ok i got something working
i needed to add "var global = {}; var process = {\"argv\": [\"one\", \"two\"]};"
to the top of my file
and i needed to remove the (function(){ ... })();
wrapping the entire file
hacky but it seems to work
haha this is kinda silly but i'm glad the problem is solved. i'll make a note to myself to write this up somewhere. or would you take this hack as a contribution for :target :apps-script
ok that makes sense
https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/build/targets/node_script.clj
you can try to create your own impl. can be in your repo. doesn't need to be part of shadow-cljs itself. no fork or so needed
how can i reference my own impl from my shadow-cljs.edn
?
this namespace is in a clj file that I reference with shadow-cljs?
or in a fork of shadow-cljs i make?
right i guess when you say "your repo" do you mean my own copy of the shadow-cljs repo, or my project repo?
just needs to be on the classpath. no modification in shadow-cljs required whatsoever
can i specify the classpath in shadow-cljs.edn
?
(i've not worked with clj much, only cljs)
you already do. :source-paths ["src"]
so just src/shadow/build/targets/google_apps_script.clj
or whatever name you want
ah ok cool!
thanks!!
do you know if the function that wraps everything is described in https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/build/targets/node_script.clj ?
sorry way too late to walk you through this. that part happens in the flush call, so the node/flush-optimized
no worries!