has anyone used closure library (not compiler) in a cherry app? in cljs mindset i’m so used to requiring goog.whatever stuff, which doesn’t work. so far, looking at the npm instructions which say to do the following:
require("google-closure-library");
goog.require("goog.crypt.Sha1");
var sha1 = new goog.crypt.Sha1();
sha1.update("foobar");
var hash = sha1.digest();
leads me to
(ns foo
(:require ["google-closure-library" :as goog]))
(js/console.log goog["require"])
which simply yields
$ npx cherry run foo.cljs
[cherry] Running foo.cljs
[Module: null prototype] { default: {} } {
meta: null,
D: 1,
shift: 5,
root: ei {
ba: null,
A: [
null, null, null, null, null,
null, null, null, null, null,
null, null, null, null, null,
null, null, null, null, null,
null, null, null, null, null,
null, null, null, null, null,
null, null
]
},
'$a': [ 'require' ],
F: null,
C: 167666463,
J: 139268
}I noticed the bug you were encountering with $default also happened here (see error in console):
https://squint-cljs.github.io/cherry/
I now have a repro :)
Neat! Sorry I didn’t get the bug filed yet — I started down the rabbit hole of trying to simplify from the closure library and realized that library is too much of a black box with its requires for me to do without reading that dang book, which I suppose is the ultimate yak shave
no problem
@wcohen The $default thing should now work as expected in 0.0.3
It looks as if what gets logged is a CLJS data structure
could be wrong. could you try
(ns foo
(:require ["google-closure-library$default" :as goog]))so try the $default
that results in:
import * as goog from 'google-closure-library';
^^^^^^^^^^^^^^^^
SyntaxError: Identifier 'goog' has already been declaredah — trying $require
that won't work. can you try goog.default.require?
goog.default doesn’t exist.
goog["default"] gives a global object with lots of junk that includes require:
[cherry] Running resource.cljs
<ref *2> {
global: <ref *1> Object [global] {
global: [Circular *1],
queueMicrotask: [Function: queueMicrotask],
clearImmediate: [Function: clearImmediate],
setImmediate: [Function: setImmediate] {
[Symbol(nodejs.util.promisify.custom)]: [Getter]
...i think that’s it — (.-require goog["default"])
yes, but goog["default"] or goog.default or goog/default should be the same thing
that’s what i assumed too! but only the one works
the others are undefined
I think that might be a bug in cherry then
welcome to post an issue about it
will do!
either way — once I get to (.-require goog[“default”]), that yields a [Function [anonymous]] — if this were a situation where google closure library weren’t totally nuts nominally i could invoke it with something like ((.-require goog["default"]) a b c )?
Yeah, you can do:
(def goog-require (.-require goog["default"]))
and then:
(goog-require a b c)
it seems like if I can just figure out how to run this require function the rest should proceed just fine