From 225e3b1c2f22ee26dc5365296d95d150ef2a7234 Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Fri, 10 May 2024 13:17:26 -0300 Subject: [PATCH] DX: Preload user and dev.user namespace (#19927) Preload the user namespace (src/user.cljs and src/dev/user.cljs) for the mobile target and for dev-only purposes. The files are git-ignored. Just a reminder that you'll be responsible for making sure your user namespace is correct. If it's broken in any way (e.g. calling non-existent code) the app will crash at initialization (dev-only environment obviously). Why? When the app initializes, it loads namespaces that were required at least once. If you create a user namespace, it won't be automatically required for you. And if you, like some Clojure devs, like to use the user namespace as your safe heaven for experimentation and dev-only utilities, you'll need to remember to evaluate the namespace at least once. This is tedious and many times I forgot to do so and the app crashed because the compiler didn't know where the symbols were coming from. --- .clj-kondo/config.edn | 1 + .gitignore | 2 ++ shadow-cljs.edn | 9 ++++++++- src/dev/README.md | 23 +++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/dev/README.md diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index 6359b1f1e5..c45a7a5477 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -1,4 +1,5 @@ {:config-paths ["status-im"] + :output {:exclude-files ["src/user.cljs" "src/dev/user.cljs"]} :lint-as {legacy.status-im.utils.views/defview clojure.core/defn legacy.status-im.utils.views/letsubs clojure.core/let reagent.core/with-let clojure.core/let diff --git a/.gitignore b/.gitignore index ca93eceb4c..141275812b 100644 --- a/.gitignore +++ b/.gitignore @@ -127,6 +127,8 @@ fastlane/README.md # Clj .cpcache/ +src/user.cljs +src/dev/user.cljs # emacs .dir-locals.el diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 8daadec071..d4d7a5f2d0 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -53,7 +53,14 @@ :dev {:devtools {:before-load-async status-im.setup.hot-reload/before-reload :after-load-async status-im.setup.hot-reload/reload :build-notify status-im.setup.hot-reload/build-notify - :preloads [re-frisk-remote.preload + :preloads [;; We preload user namespaces so that + ;; their symbols are available without + ;; the developer having to manually + ;; evaluate them after app + ;; initialization. + user + dev.user + re-frisk-remote.preload status-im.setup.schema-preload ;; In order to use component test helpers in the REPL we ;; need to preload namespaces that are not normally required diff --git a/src/dev/README.md b/src/dev/README.md new file mode 100644 index 0000000000..884aa18614 --- /dev/null +++ b/src/dev/README.md @@ -0,0 +1,23 @@ +# The `dev/` directory + +The `src/dev/` directory is a place where developers can commit non-production +and non-test code which can facilitate development in general. The code should, +ideally, be useful to more than one team member. + +**Note**: As of today (2024-05-07), we don't have further guidelines or examples +about how mobile teams should use and maintain these dev-only namespaces. Before +opening a PR introducing new dev-only namespaces, consider sharing and +discussing with as many team members as you can. + +### The `user` namespace + +You may optionally create a `src/dev/user.cljs` and/or `src/user.cljs` file. +These files are git-ignored and are meant to be your own playground. Clojure +developers usually use such namespaces to create temporary utilities and +experiments that aren't necessarily useful to others. They are particularly +valuable for developers adept at the REPL-Driven Development workflow. + +Be careful with `make clean` because it will delete all non-tracked git files. +If you rely on this file, you may prefer to create a symbolic link and store the +original `user.cljs` file outside the `status-mobile` repository. Then, after +`make clean`, you will need to recreate the symlink.