Thanks to Microsoft’s diligent open-source work, we can now build an app on macOS in a modern Lisp, with a connected REPL and everything. For those of us who remember the 90s, this is truly the dankest timeline.

The only dependency Krell requires above vanilla React Native is react-native-tcp-socket, which as of 3.6.0 compiles just fine on macOS. Building a macOS app, then, just requires mashing together Microsoft’s macOS/RN instructions with Krell’s.

Start by creating a new React Native for Mac app:

npx react-native init KrellMacOS --version 0.61

cd KrellMacOS

npx react-native-macos-init

Note that you need to specify version 0.61 of React Native, as that’s where Microsoft’s fork has caught up to so far. Next, follow the Krell Reagent tutorial to set up your ClojureScript project. Add a deps.edn:

{:deps {io.vouch/krell {:git/url "https://github.com/vouch-opensource/krell.git"
                        :sha "77e0d607a0a62105829d1bc2991fd28ac60c0f57"}
        io.vouch/reagent-react-native {:git/url "https://github.com/vouch-opensource/reagent-react-native.git"
                                       :sha "54bf52788ab051920ed7641f386177374419e847"}
        reagent {:mvn/version "0.10.0"
                 :exclusions [cljsjs/react cljsjs/react-dom]}}}

(You should probably grab the latest SHA for io.vouch/krell, but this one at least has the correct deps).

Add a build.edn:

{:main krell-macos.core
 :output-to "target/main.js"
 :output-dir "target"}

Add a ClojureScript source file at src/krell_macos/core.cljs:

(ns krell-macos.core
  (:require [reagent.core :as r]
            [reagent.react-native :as rn]))

(defn hello []
  [rn/view {:style {:flex 1 :align-items "center" :justify-content "center"}}
   [rn/text {:style {:font-size 50}} "Hello Krell on macOS!"]])

(defn ^:export -main [& args]
  (r/as-element [hello]))

Run clj -m cljs.main --install-deps to install Krell’s NPM deps, then install the native dependencies:

cd macos
pod install
cd ..

You’re now ready to go. clj -m krell.main -co build.edn -c -r will build your ClojureScript source and start the REPL. npx react-native run-macos will build your project, launch it, and connect. From there you can interact from the REPL or change the source to see it hot-reload.

Can this work on Windows?

Microsoft’s React Native fork that supports Windows is actually ahead of its macOS fork. The missing piece is the react-native-tcp-socket library. Once native bindings for Windows are built for that, these instructions should work on Windows as well.