This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-12
Channels
- # announcements (2)
- # beginners (36)
- # boot (6)
- # calva (2)
- # cider (18)
- # clj-kondo (1)
- # cljdoc (2)
- # cljs-dev (2)
- # clojure (130)
- # clojure-boston (1)
- # clojure-brasil (3)
- # clojure-czech (1)
- # clojure-europe (11)
- # clojure-italy (4)
- # clojure-losangeles (37)
- # clojure-nl (9)
- # clojure-seattle (2)
- # clojure-sweden (8)
- # clojure-uk (23)
- # clojurescript (13)
- # core-async (21)
- # cursive (13)
- # data-science (6)
- # datomic (12)
- # emacs (36)
- # figwheel-main (9)
- # fulcro (76)
- # juxt (2)
- # keechma (18)
- # leiningen (4)
- # off-topic (13)
- # pedestal (37)
- # re-frame (21)
- # reitit (2)
- # shadow-cljs (78)
- # spacemacs (23)
- # sql (13)
- # tools-deps (25)
- # uncomplicate (4)
- # unrepl (1)
- # vim (27)
Hi, I’m trying to make a Jupyter Lab Extension using ClojureScript and shadow-cljs. However, I’m stuck right at the beginning and am unsure about which environment to target (`:browser`, :node-library
or :npm-module
), and how to configure shadow-cljs.edn
and package.json
.
A template for a Javascript Extension can be found here: https://github.com/jupyterlab/extension-cookiecutter-js/tree/master/%7B%7Bcookiecutter.extension_name%7D%7D.
Furthermore the JupyterLab documentation states the following: “An Extension is a valid npm package that meets the following criteria:
• Exports one or more JupyterLab plugins as the default export in its main file.
• Has a jupyterlab key in its package.json which has “extension” metadata. The value can be true to use the main module of the package, or a string path to a specific module (e.g. “lib/foo”).
• It is also recommended to include the keyword jupyterlab-extension in the package.json, to aid with discovery (e.g. by the extension manager).
It would be great if someone could point me in the right direction!
@thheller I’m now getting TypeError: "FS.readFileSync is not a function"
in the browser console
I’ve been trying this way a couple of hours ago, but had trouble with getting the js exports right
I’ve been trying this way a couple of hours ago, but had trouble with getting the js exports right
Thanks, I will try it this way. It could be that :runtime :browser
was the part I was missing earlier
there could be a dedicated :target :jupyter
that takes care of all of that but I never used it before
@thheller one more question: I think I have the basics configured correctly now, because Jupyter is no longer complaining when I build and import the extension. However I don’t think my code is actually executed when I open Jupyter. Jupyter expects the extension object as the “default export in the extension main file”. How can I set my (def ^:export extension #js {:stuff :here})
to be the default export?
uhm that might not work because CLJS renames default
but maybe it does. so it would just be (def ^:export default ...)
then CLJS probably renamed it to default$
since default
used to be a reserved symbol
and just do something like import { x } from "./lib/your.ns.js"
and export default x;
Awesome, that did the trick! 🎉 Thanks a lot for all the help. Now on to the actual work of writing the extension 🙂
it would help others if you may be create a project template/scaffolding if you have spare time 🙂
@U3MRWH35M might do that if I manage to get it working and packaged correctly
@U3MRWH35M I made a PR for shadow-cljs/examples: https://github.com/shadow-cljs/examples/pull/14
how do you require e.g. the crypto or fs module from node?
or should I just use goog.crypt
? :thinking_face:
ended up just using goog.crypt 🎉
@martinklepsch on node you can call (js/require ...)
directly, but I guess if you use strings on the :require
block it works as well
i’m having trouble figuring out how to map var { createCanvas } = require("canvas");
to the namespace require in cljs
I tried
(ns ucv.controller.barcode
(:require
["canvas" :as createCanvas]))
and
(ns ucv.controller.barcode
(:require
["canvas" :refer [createCanvas]]))
but neither work
@currentoor the second one looks correct
if createCanvas
was exported default, (which does not look like the case looking at var { createCanvas } = require("canvas");
, it would have been (:require ["canvas" :as canvas :default createCanvas])
ah yeah i’ll try
(ns ucv.controller.barcode
(:require
["canvas" :as canvas]))
(def createCanvas (.-createCanvas canvas))
i had success with this second approach (instead of :refer) with react-native/expo components
nope that didn’t work either
this does work though
(def canvas (js/require "canvas"))
(js/console.log (.-createCanvas canvas))
@currentoor (:require ["canvas" :refer [createCanvas]])
would be the correct translation
@thheller yup that works, thank you!
@currentoor what is different between your second form and @thheller's answer? (just curious, i see both as same)
nothing, i think when trying different requires i got my repl into a bad state
Hello, I'm trying to require and use WalletConnectProvider
as it is defined here https://github.com/WalletConnect/walletconnect-monorepo/blob/53206bb3a6c9a7205942271f0433877f51763327/packages/web3-provider/src/index.js
I've required it as ["@walletconnect/web3-provider" :default WalletConnectProvider]
and used (new WalletConnectProvider ...)
hard to say what that is but it always helps to use ["@walletconnect/web3-provider" :as x :default WalletConnectProvider]
and then logging (js/console.dir x)
to verify if the properties you are looking for actually exist
Has anyone ever had a problem running shadow-cljs with chrome 75?
My browser freezes in a project we have in my company. It works with previous versions of chrome, though.
In chrome's network, almost all requests show (pending)
forever :thinking_face:
@estevam.machado if you import a whole lot of files it can get a bit slow to use. never seen a full freeze though
you can try https://clojureverse.org/t/improving-initial-load-time-for-browser-builds-during-development/2518 and see if that improves things
will :loader-mode :eval
be set as default in the future?
@thheller why? does thigns are breaking?
I'm wondering because of @estevam.machado, this seems to happen to a lot of Linux users at my workplace, my guess our app is getting too large, getting from slow down to total freeze