mirror of
https://github.com/status-im/status-react.git
synced 2025-01-09 18:46:19 +00:00
c1dcd7a764
This commit is the foundational step to start using malli (https://github.com/metosin/malli) in this project. Take in consideration we will only be able to realize malli's full power in future iterations. For those without context: the mobile team watched a presentation about malli and went through a light RFC to put everyone on the same page, among other discussions here and there in PRs. To keep things relatively short: 1. Unit, integration and component tests will short-circuit (fail) when inputs/outputs don't conform to their respective function schemas (CI should fail too). 2. Failed schema checks will not block the app from initializing, nor throw an exception that would trigger the LogBox. Exceptions are only thrown in the scope of automated tests. 3. There's zero performance impact in production code because we only instrument. Instrumentation is removed from the compiled code due to the usage of "^boolean js.goog/DEBUG". 4. We shouldn't expect any meaningful slowdown during development. **What are we instrumenting in this PR?** Per our team's agreement, we're only instrumenting the bare minimum to showcase 2 examples. - Instrument a utility function utils.money/format-amount using the macro approach. - Instrument a quo component quo.components.counter.step.view/view using the functional approach. Both approaches are useful, the functional approach is powerful and allow us to instrument anonymous functions, like the ones we pass to subscriptions or event handlers, or the higher-order function quo.theme/with-theme. The macro approach is perfect for functions already defined with defn. **I evaluated the schema or function in the REPL but nothing changes** - If you evaluate the source function, you need to evaluate schema/=> or schema/instrument as well. - Remember to *var quote* when using schema/instrument. - You must call "(status-im2.setup.schema/setup!)" after any var is re-instrumented. It's advisable to add a keybinding in your editor to send this expression automatically to the CLJS REPL, or add the call at the end of the namespace you are working on (similar to how some devs add "(run-tests)" at the end of test namespaces). **Where should schemas be defined?** For the moment, we should focus on instrumenting quo components, so define each function schema in the same namespace as the component's public "view" var. To be specific: - A schema used only to instrument a single function and not used elsewhere, like a quo component schema, wouldn't benefit from being defined in a separate namespace because that would force the developer to constantly open two files instead of one to check function signatures. - A common schema reused across the repo, like ":schema.common/theme" should be registered in the global registry "schema.registry" so that consumers can just refer to it by keyword, as if it was a built-in malli schema. - A common schema describing status-go entities like message, notification, community, etc can be stored either in the respective "src/status_im2/contexts/*" or registered globally, or even somewhere else. This is yet to be defined, but since I chose not to include schemas for them, we can postpone this guideline.
164 lines
8.5 KiB
Clojure
164 lines
8.5 KiB
Clojure
;; shadow-cljs configuration
|
|
{:source-paths ["src" "test/cljs"]
|
|
|
|
:dependencies [[reagent "1.2.0"]
|
|
[re-frame "1.3.0"]
|
|
[binaryage/oops "0.7.2"]
|
|
[com.andrewmcveigh/cljs-time "0.5.2"]
|
|
[com.taoensso/timbre "6.3.1"]
|
|
[cljs-bean "1.9.0"]
|
|
[com.cognitect/transit-cljs "0.8.280"]
|
|
[camel-snake-kebab "0.4.3"]
|
|
[metosin/malli "0.13.0"]
|
|
|
|
;; Dev dependencies
|
|
[refactor-nrepl "2.5.0"]
|
|
[cider/cider-nrepl "0.25.3"]
|
|
[cider/piggieback "0.4.1"]
|
|
[re-frisk-remote "1.6.0"]
|
|
|
|
;; Use the same version specified in the Nix dependency.
|
|
[clj-kondo/clj-kondo "2023.09.07"]
|
|
|
|
;; Routing
|
|
[bidi "2.1.6"]
|
|
;; Test dependencies
|
|
[day8.re-frame/test "0.1.5"]
|
|
[com.taoensso/tufte "2.6.3"]]
|
|
|
|
;; port and middleware for repl in development
|
|
:nrepl {:port 7888
|
|
:middleware [cider.piggieback/wrap-cljs-repl
|
|
refactor-nrepl.middleware/wrap-refactor]}
|
|
|
|
;; shadow-cljs web interface
|
|
:http {:port 3449
|
|
:host "0.0.0.0"}
|
|
|
|
:cache-blockers #{status-im.utils.js-resources status-im.ui.components.icons.icons}
|
|
|
|
:builds
|
|
{:mobile
|
|
{:target :react-native
|
|
;; To match the folder created by Nix build of JSBundle.
|
|
:output-dir "result"
|
|
:init-fn status-im2.core/init
|
|
;; When false, the Shadow-CLJS watcher won't automatically refresh
|
|
;; the target files (a.k.a hot reload). When false, you can manually
|
|
;; reload by calling `shadow.cljs.devtools.api/watch-compile-all!`.
|
|
:devtools {:autobuild #shadow/env ["SHADOW_AUTOBUILD_ENABLED" :default true :as :bool]}
|
|
:dev {:devtools {:before-load-async status-im2.setup.hot-reload/before-reload
|
|
:after-load-async status-im2.setup.hot-reload/reload
|
|
:build-notify status-im2.setup.hot-reload/build-notify
|
|
:preloads [re-frisk-remote.preload
|
|
status-im2.setup.schema-preload
|
|
;; In order to use component test helpers in the REPL we
|
|
;; need to preload namespaces that are not normally required
|
|
;; by production code, such as
|
|
;; @testing-library/react-native.
|
|
test-helpers.component]}
|
|
:closure-defines
|
|
{status-im2.config/POKT_TOKEN #shadow/env "POKT_TOKEN"
|
|
status-im2.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN"
|
|
status-im2.config/OPENSEA_API_KEY #shadow/env "OPENSEA_API_KEY"
|
|
status-im2.config/ALCHEMY_ARBITRUM_GOERLI_TOKEN #shadow/env "ALCHEMY_ARBITRUM_GOERLI_TOKEN"
|
|
status-im2.config/ALCHEMY_OPTIMISM_GOERLI_TOKEN #shadow/env "ALCHEMY_OPTIMISM_GOERLI_TOKEN"
|
|
status-im2.config/ALCHEMY_OPTIMISM_MAINNET_TOKEN #shadow/env "ALCHEMY_OPTIMISM_MAINNET_TOKEN"
|
|
status-im2.config/ALCHEMY_ARBITRUM_MAINNET_TOKEN #shadow/env "ALCHEMY_ARBITRUM_MAINNET_TOKEN"}
|
|
:compiler-options {:output-feature-set :es5
|
|
;; We disable `:fn-deprecated` warnings because we
|
|
;; are managing deprecation via clj-kondo and we
|
|
;; don't want the terminal output to be littered
|
|
;; with warnings on every code reload.
|
|
:warnings {:fn-deprecated false}
|
|
:closure-defines {re-frame.trace/trace-enabled? true}
|
|
:source-map false
|
|
;; This seems to be necessary while using the REPL,
|
|
;; otherwise sometimes you'll get weird errors when
|
|
;; instrumenting functions.
|
|
:static-fns false
|
|
:infer-externs true}
|
|
;; if you want to use a real device, set your local ip
|
|
;; in the SHADOW_HOST env variable to make sure that
|
|
;; it will use the right interface
|
|
:local-ip #shadow/env "SHADOW_HOST"}
|
|
:chunks {:fleets status-im.fleet.default-fleet/default-fleets}
|
|
:release
|
|
{:closure-defines
|
|
{status-im2.config/POKT_TOKEN #shadow/env "POKT_TOKEN"
|
|
status-im2.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN"
|
|
status-im2.config/OPENSEA_API_KEY #shadow/env "OPENSEA_API_KEY"
|
|
status-im2.config/ALCHEMY_ARBITRUM_GOERLI_TOKEN #shadow/env "ALCHEMY_ARBITRUM_GOERLI_TOKEN"
|
|
status-im2.config/ALCHEMY_OPTIMISM_GOERLI_TOKEN #shadow/env "ALCHEMY_OPTIMISM_GOERLI_TOKEN"
|
|
status-im2.config/ALCHEMY_OPTIMISM_MAINNET_TOKEN #shadow/env "ALCHEMY_OPTIMISM_MAINNET_TOKEN"
|
|
status-im2.config/ALCHEMY_ARBITRUM_MAINNET_TOKEN #shadow/env "ALCHEMY_ARBITRUM_MAINNET_TOKEN"}
|
|
:compiler-options {:output-feature-set :es6
|
|
;;disable for android build as there
|
|
;;is an intermittent warning with deftype
|
|
:warnings-as-errors false
|
|
:infer-externs :auto
|
|
:static-fns true
|
|
:fn-invoke-direct true
|
|
:optimizations :advanced
|
|
:js-options {:js-provider :closure}}}}
|
|
;; the tests are ran with node, react-native dependencies are mocked
|
|
;; by using node --require override.js, which uses the node-library
|
|
;; produced by the target :mocks below and redefines node require
|
|
;; function to use the mocks instead of the rn libraries
|
|
:test
|
|
{:output-to "target/test/test.js"
|
|
:output-dir "target/test"
|
|
:optimizations :simple
|
|
:target :node-test
|
|
:dev {:devtools {:preloads [status-im2.setup.schema-preload]}}
|
|
;; Uncomment line below to `make test-watch` a specific file
|
|
;; :ns-regexp "status-im2.subs.messages-test$"
|
|
:main status-im.test-runner/main
|
|
;; set :ui-driven to true to let shadow-cljs inject node-repl
|
|
:ui-driven true
|
|
:closure-defines
|
|
{schema.core/throw-on-error? true
|
|
status-im2.config/POKT_TOKEN #shadow/env "POKT_TOKEN"
|
|
status-im2.config/INFURA_TOKEN #shadow/env "INFURA_TOKEN"
|
|
status-im2.config/OPENSEA_API_KEY #shadow/env "OPENSEA_API_KEY"
|
|
status-im2.config/ALCHEMY_ARBITRUM_GOERLI_TOKEN #shadow/env "ALCHEMY_ARBITRUM_GOERLI_TOKEN"
|
|
status-im2.config/ALCHEMY_OPTIMISM_GOERLI_TOKEN #shadow/env "ALCHEMY_OPTIMISM_GOERLI_TOKEN"
|
|
status-im2.config/ALCHEMY_OPTIMISM_MAINNET_TOKEN #shadow/env "ALCHEMY_OPTIMISM_MAINNET_TOKEN"
|
|
status-im2.config/ALCHEMY_ARBITRUM_MAINNET_TOKEN #shadow/env "ALCHEMY_ARBITRUM_MAINNET_TOKEN"}
|
|
:compiler-options
|
|
{;; needed because we override require and it
|
|
;; messes with source-map which reports callstack
|
|
;; exceeded exceptions instead of real issues
|
|
:source-map false
|
|
;; needed because we use deref in tests
|
|
:static-fns false
|
|
:optimizations :simple
|
|
:warnings {:fn-deprecated false}
|
|
:infer-externs true}}
|
|
|
|
;; mock.js-dependencies is mocking the react-native libraries
|
|
;; we build it as a node library so that it can be required by
|
|
;; override.js
|
|
:mocks
|
|
{:target :node-library
|
|
:exports {:mocks mocks.js-dependencies/mock}
|
|
:output-to "target/mocks/mocks.js"
|
|
:output-dir "target/mocks"
|
|
:compiler-options {:optimizations :simple
|
|
:source-map false}}
|
|
:component-test {:target :npm-module
|
|
:entries [;; We need to tell shadow-cljs to compile
|
|
;; the preloads namespace because it will
|
|
;; be used directly by Jest in the option
|
|
;; setupFilesAfterEnv.
|
|
status-im2.setup.schema-preload
|
|
|
|
quo.core-spec
|
|
status-im2.core-spec]
|
|
:ns-regexp "component-spec$"
|
|
:output-dir "component-spec"
|
|
:closure-defines {schema.core/throw-on-error? true}
|
|
:compiler-options {:warnings-as-errors false
|
|
:static-fns false
|
|
:infer-externs true}}}}
|