Skip to content

Commit

Permalink
do not inject playground when shadow-cljs is present
Browse files Browse the repository at this point in the history
playground is compiled with normal cljs compiler and shadow-cljs
applies some modifications, loading playground over shadow-cljs
project can potentially break it.
  • Loading branch information
darwin committed Feb 8, 2020
1 parent 2cb7156 commit 375c694
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/implant/dirac/implant/eval.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,15 @@

; -- probing of page context ------------------------------------------------------------------------------------------------

(defn go-ask-is-shadow-present? []
(go
(let [res (<! (go-call-eval-with-timeout! :default "typeof SHADOW_ENV" 2000 true))]
(if-not (= (first res) ::ok)
(do
(error "Failed to detect shadow-cljs presence" (pr-str res))
false)
(= (second res) "object")))))

(defn go-ask-is-runtime-present? []
(go
(let [[value error] (<! (go-eval-in-context! :default "dirac.runtime" true))]
Expand Down
15 changes: 11 additions & 4 deletions src/implant/dirac/implant/intercom.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
(if-not (or (re-find #"Cannot read property 'installed_QMARK_' of undefined" reason) (= reason "Uncaught")) ; this is known and expected error when dirac.runtime is not present
(str "\n" (cuerdas/escape-html reason))))))

(defn ^:dynamic no-playground-due-to-shadow-msg []
(str "Dirac runtime wasn't detected but it appears you are using shadow-cljs as the build tool.\n"
"Normally we would inject playground project to get ad-hoc REPL working here "
"but it is currently not supported with shadow-cljs."))

(defn check-agent-version! [agent-version]
(let [our-version implant-version/version]
(when-not (= agent-version our-version)
Expand Down Expand Up @@ -327,14 +332,16 @@
(when-not *last-connection-url*
(reset-eval!)
(display-prompt-status "Checking for Dirac Runtime presence in your app..." :info)
(let [present? (<! (eval/go-ask-is-runtime-present?))]
(if (true? present?)
(let [runtime-present? (<! (eval/go-ask-is-runtime-present?))]
(if (true? runtime-present?)
(if (<! (eval/go-ask-is-runtime-repl-enabled?))
(<! (go-start-repl!))
(display-prompt-status (repl-support-not-enabled-msg)))
(if (or no-playground? (hosted?))
(display-prompt-status (missing-runtime-msg present?))
(<! (go-start-playground-repl!))))))))
(display-prompt-status (missing-runtime-msg runtime-present?))
(if (eval/go-ask-is-shadow-present?)
(display-prompt-status (no-playground-due-to-shadow-msg))
(<! (go-start-playground-repl!)))))))))

(defn go-react-on-global-object-cleared! []
(reset-repl-state!)
Expand Down

0 comments on commit 375c694

Please sign in to comment.