This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-14
Channels
- # beginners (74)
- # boot (1)
- # cider (6)
- # clj-kondo (8)
- # cljs-dev (30)
- # clojure (195)
- # clojure-ecuador (1)
- # clojure-europe (2)
- # clojure-italy (51)
- # clojure-nl (47)
- # clojure-spec (9)
- # clojure-sweden (27)
- # clojure-uk (63)
- # clojurescript (84)
- # cursive (41)
- # datascript (17)
- # datomic (16)
- # docker (1)
- # emacs (10)
- # events (2)
- # graalvm (2)
- # graphql (37)
- # juxt (2)
- # nrepl (20)
- # nyc (2)
- # off-topic (26)
- # onyx (3)
- # pedestal (4)
- # perun (19)
- # planck (1)
- # reagent (9)
- # reitit (4)
- # shadow-cljs (208)
- # spacemacs (6)
- # tools-deps (4)
I'm trying to use this library https://rete.js.org/#/, but seems like it depends on some webpack magic to work, when I try to require it I get
js.js:133 Uncaught ReferenceError: regeneratorRuntime is not defined
at rete.common.js:418
at rete.common.js:415
at Object.shadow$provide.module$node_modules$rete$build$rete_common (rete.common.js:396)
at Object.shadow.js.jsRequire (js.js:122)
at Object.shadow.js.require (js.js:158)
at com.wsscode.wise.client.ui.rete.core.js:5
, I guess it may be some webpack polyfill, not sure, is there any way around it?is there syntax for specifying a local cljs dependency for a shadow-cljs project similar to lein-install
?
@mss not directly, but you can add directly to the source-paths, or use deps.edn
, its local deps support works with shadow
@haiyuan.vinurs lein-shadow
is a 3rd party project I have no control over and no it does not read that config
I recommend using the regular shadow-cljs
cmd. you only lose functionality by moving to lein-shadow
and gain absolutely nothing (IMHO)
What would be the right way to do dev dependencies in shadow-cljs without leiningen?
And dev source paths
If I put them under :dependencies
would that bloat my production build?
Okay thanks 🙂
@caleb.macdonaldblack when building :browser
targets always check the build reports https://shadow-cljs.github.io/docs/UsersGuide.html#_build_report
Hmm. Just added it to my CI and it actually takes 1s longer to run than the release build.
hmm yeah the build reports do kinda require their own thing since they adjust some settings to get all the necessary info
@lilactown :none
is not possible. otherwise just set the usual :compile-options {:optimizations :simple}
if you want to do it via release
options and not in the config itself use (shadow/release :build-id {:config-merge [{:compiler-options ...}]})
Gotcha. Not a big deal. Was trying to figure out if it should go in it's own build step or just be added to the release step given it'd run fast.
Seems like a very useful tool though. Thanks! Will always output one as a build artifact. Great to compare build sizes after adding deps.
so that would invalidate the cache since that isn't true by default for release builds
hrm annoying. datascript isn’t working for me in advanced optimizations, but works in simple 😧
We use FontAwesome's React package in our app. After generating a build report, I see the icons deps take up nearly 30% of the build size. We explicitly import icons which supposedly allows tree shaking to work. I'm guessing that however FontAwesome expects tree shaking to work is not the same way it works in shadow-cljs? Is there way to make it work or no dice?
I don't know the fontawesome package but if you require separate files it should work
Is that the same as this?
(:require
["@fortawesome/free-solid-svg-icons" :as solid-icons])
solid-icons/faCircle
["@fortawesome/free-solid-svg-icons" :as solid-icons]
only that matters. there is no DCE for npm packages
This might do it: https://fontawesome.com/how-to-use/with-the-api/other/tree-shaking#deep-imports
To clarify, when I do this
(:require
["@fortawesome/free-solid-svg-icons" :as solid-icons])
it imports an index.js
file. If I were to do this:
(:require
["@fortawesome/free-solid-svg-icons/faCoffee" :as fa-coffee])
it'd import faCoffee.js
?["@fortawesome/free-solid-svg-icons/faCoffee.js" :as fa-coffee]
also works if you want to be sure 😉
And when I run a build, it will just throw the code (minified?) into the final JS file?
Gotcha. Curious, given this library supports tree shaking, does that mean it'd be compatible with closure's tree shaking?
They use the same terminology - "dead code elimination". A bit annoying how everything is so overloaded.
Oh I see. If I know that all the npm deps I use would be compatible with Closure, is there a way to enable it?
I haven't tested this in a rather long time and wouldn't consider it supported at this time
Oh, yeah - we definitely use those. I assumed it'd "just work" given how popular those are.
for example:
------ WARNING #9 --------------------------------------------------------------
File: node_modules/react-dom/cjs/react-dom.production.min.js:176:316
unreachable code
--------------------------------------------------------------------------------
especially if you expect the webpack tree shaking stuff to trigger since that will not
@wilkerlucio I saw the ticket regarding class
. do you have an actual example where this fails? which class?
gotta be careful with code on npm since its often babel rewritten code which has other semantics than ES6 has
@thheller I was doing in browser, I'm loading strait from script tags, those using native ES6 classes, you can see the discussion I have around it yesterday: https://clojurians.slack.com/archives/C03S1L9DN/p1557803014008100, please let me know if you need more clarifications about it
@thheller I'm not sure, I wasn't able to use that loading from NPM (that issue we discussed on the polyfill)
var Control =
/*#__PURE__*/
function () {
function Control(key) {
_classCallCheck(this, Control);
_defineProperty(this, "key", void 0);
_defineProperty(this, "data", {});
_defineProperty(this, "parent", null);
if (this.constructor === Control) throw new TypeError('Can not construct abstract class');
if (!key) throw new Error('The key parameter is missing in super() of Control ');
this.key = key;
}
_createClass(Control, [{
key: "getNode",
value: function getNode() {
if (this.parent === null) throw new Error('Control isn\'t added to Node/Input');
if (this.parent instanceof Node) return this.parent;
if (!this.parent.node) throw new Error('Control hasn\'t be added to Input or Node');
return this.parent.node;
}
}, {
key: "getData",
value: function getData(key) {
return this.getNode().data[key];
}
}, {
key: "putData",
value: function putData(key, data) {
this.getNode().data[key] = data;
}
}]);
return Control;
}();
<script src=""></script>
<script src=""></script>
<script src=""></script>
interesting, still having the problem when trying to call the construct, maybe that generating the native class somehow?
the issue I'm having is how to extend it and call the parent constructor
because its required by the api design
even though the package contains a build/rete.esm.js
file but thats still rewritten by babel and not ES6 code
and their docs point to use of native classes, so I'm not sure whats going on inside of it
they probably assume that you'll use babel which would rewrite the code in a compatible way?
they provide docs for the .min
usage as well, also suggesting usage of ES6 classeasa
you have a guess why/how parent constructor calling is blocked?
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
so they polyfill the check
there is nothing ESM about it ... but lots of packages on npm pretend to be ESM when they are not
yeah, but seems like this is just mimics the ES6 behavior
I mean mimics in the sense it blocks direct calls to the constructor fn (using that validator)
in your ticket you mention Reflect.setPrototypeOf(B.prototype, A.prototype)
and stuff
gotcha, but still that wasn't the main problem, sorry to insist in this point, but the real blocker to me is the parent constructor, fixing prototypes is easy, but thanks for pointing it, I'll improve the example there
is not that I want, its required by the lib, unless there is some way around that I'm missing
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
thanks, I'll try that
I can't find an actual example of how to use the rete stuff in your discussion in #cljs-dev
that's a bit far in the setup, in the construction of the editor, but you can replicate by simply trying to instantiate the class
raw messy stuff, but this is my setup for init it:
(fp/defsc ReteEditor
[this {::keys []}]
{:pre-merge (fn [{:keys [current-normalized data-tree]}]
(merge {::editor-id (random-uuid)} current-normalized data-tree))
:ident [::editor-id ::editor-id]
:query [::editor-id]
:componentDidMount (fn []
(go-catch
(let [container (gobj/get this "editorContainer")
editor (js/Rete.NodeEditor. "[email protected]" container)
num-comp (new NumComponent)
_ (do
(.use editor js/ConnectionPlugin.default)
(.use editor js/ReactRenderPlugin.default)
(.register editor num-comp))
engine (js/Rete.Engine. "[email protected]")
_ (.register engine num-comp)
n1 (<!p (.createNode num-comp #js {:num 3}))
n2 (<!p (.createNode num-comp #js {:num 5}))]
(.addNode editor n1)
(.addNode editor n2)
(.on editor "process nodecreated noderemoved connectioncreated connectionremoved"
(fn []
(js/console.log "EVENT")))
(.. editor -view resize)
(.trigger editor "process"))))
:css [[:.container {:width "500px"}]]}
(dom/div :.container {:ref #(gobj/set this "editorContainer" %)}))
(def NumControl
(js-class
{::extends js/Rete.Control
::constructor (fn [emitter key readonly]
(let [this (js-this)]
(.call js/Rete.Control this key)
(gobj/set this "render" "react")
(gobj/set this "component" ReactNumControl)
(gobj/set this "props" {:emitter emitter :ikey key :readonly readonly})))}))
(defn js-class [{::keys [constructor] :as definition}]
(let [c (or constructor (fn []))
proto (gobj/get c "prototype")]
(doseq [[k v] (dissoc definition ::constructor)]
(case k
::extends
(goog/inherits c v)
(gobj/set proto (name k) v)))
c))
the use is in the Fulcro component, num-comp (new NumComponent)
that's not actually possible, hehe, rete depends on some rendering to create some parts of it, but you can ignore the react/fulcro part, its just one container element and using componentDidMount to start
here you can see a full demo from Rete: https://codepen.io/Ni55aN/full/xzgQYq/
I mostly copied from that
(defn NumComponent
{:jsdoc ["@constructor"]}
[]
(this-as this
(.call (js/Object.getPrototypeOf NumComponent) this "Number")
this))
(set! NumComponent -prototype
(js/Object.create r/Component.prototype
#js {:constructor
#js {:value NumComponent
:writeable true
:configurable true}
:builder
#js {:value
(fn [node]
(this-as this
;; do stuff
))}
:worker
#js {:value
(fn [node inputs outputs]
;; do stuff
)}}))
(js/Object.setPrototypeOf NumComponent r/Component)
@thheller maybe something is wrong, I got Uncaught TypeError: Object.getPrototypeOf(...).call is not a function
running new ns.NumComponent()
on the console
ok, I fixed that line, swiped with: (.call (gobj/get (js/Object.getPrototypeOf NumComponent) "constructor") this "Number")
now it works! 🙂
thanks for looking it up, really helpful
but there is something about that puzzling me, I don't really understand how (.call (gobj/get (js/Object.getPrototypeOf NumComponent) "constructor") this "Number")
works, the way I'm seeing it, the constructor
in NumComponent is a js value, which contains a value
to NumComponent
, how does that line figures the parent constructor and call it? its some JS magic going on inside?
I want to write a small library for myself in cljc where I expose apis that work for both clojure and clojurescript. Some of the implementations for these apis will use java/clojure external libraries and npm libraries using reader conditionals so that I can and export it as jar files and use them in both clojure and clojurescript world. Is there a way to achieve this with a shadow-cljs? Is there any template for such kind of library projects?
alright, back to my chrome extension after awhile. I think I ran into this before, but I’m currently getting: [chromex] an error occurred during the call to chromex.ext.tabs/execute-script: Could not load file 'out/content-script.js' for content script. It isn't UTF-8 encoded.
I am a first-time shadow-cljs user. In trying it out today, I hit an INTERNAL COMPILER ERROR
🙁
I created a minimal reproduction in this repository: https://github.com/Dept24c/viz-min
The README has instructions on how to reproduce the error. Can anyone help me with this?
@chad.harrington please include the full error you get
It's pretty big, but it starts with: `[:app] Compiling ... [:app] Build failure: failed to convert sources {:tag :shadow.build.closure/convert-error, :sources [[:shadow.build.npm/empty "shadow$empty.js"] [:shadow.build.npm/resource "node_modules/base64-js/index.js"] [:shadow.build.npm/resource "node_modules/ieee754/index.js"] [:shadow.build.npm/resource "node_modules/isarray/index.js"] [:shadow.build.npm/resource "node_modules/buffer/index.js"] [:shadow.build.npm/resource "node_modules/viz_DOT_js/full.render.js"]]} ExceptionInfo: failed to convert sources shadow.build.closure/convert-sources-simple*/fn--14326 (closure.clj:1809) shadow.build.closure/convert-sources-simple* (closure.clj:1803) shadow.build.closure/convert-sources-simple* (closure.clj:1684) shadow.build.closure/convert-sources-simple (closure.clj:1960) shadow.build.closure/convert-sources-simple (closure.clj:1912) shadow.build.compiler/maybe-closure-convert (compiler.clj:1016) shadow.build.compiler/maybe-closure-convert (compiler.clj:1009) shadow.build.compiler/compile-all (compiler.clj:1267) shadow.build.compiler/co mpile-all (compiler.clj:1128) shadow.build.api/compile-sources (api.clj:256) shadow.build.api/compile-sources (api.clj:248) shadow.build/compile (build.clj:377) shadow.build/compile (build.clj:368) shadow.cljs.devtools.server.worker.impl/build-compile (impl.clj:304) shadow.cljs.devtools.server.worker.impl/build-compile (impl.clj:290) shadow.cljs.devtools.server.worker.impl/do-resource-update (impl.clj:887) shadow.cljs.devtools.server.worker.impl/do-resource-update (impl.clj:850) shadow.cljs.devtools.server.util/server-thread/fn--16766/fn--16767/fn--16775 (util.clj:304) shadow.cljs.devtools.server.util/server-thread/fn--16766/fn--16767 (util.clj:303) shadow.cljs.devtools.server.util/server-thread/fn--16766 (util.clj:276) java.lang.Thread.run (Thread.java:748) Caused by: RuntimeException: INTERNAL COMPILER ERROR. Please report this problem. An enclosing scope is required for change reports but node LABEL 13 [length: 2] [source_file: node_modules/viz_DOT_js/full.render.js] doesn't have one. Node(F OR): node_modules/viz_DOT_js/full.render.js:13:4095 function Rv(a,b,d,e){a=a|0;b=b|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0,j=0,k=0;f=a;while(1){j=c[f>>2]|0;if(!j){k=6;break}if((c[j>>2]|0)==(b|0))b...`
yeah its a closure compiler issue as expected. too tired to look into it now. headed to bed.
Okay. Thanks.
@lilactown dunno what that means. it should be utf-8