Skip to content

Commit

Permalink
Cljs 1.10.x worker target support (#659)
Browse files Browse the repository at this point in the history
* Check for new :webworker target and respect it during injection

* Add :webworker to compiler options :target spec

There's more where that came from...

* re-implement figwheel.client.utils/feature? as a macro
  • Loading branch information
milt authored and Bruce Hauman committed Mar 5, 2018
1 parent ffe0d10 commit db2cd28
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
12 changes: 9 additions & 3 deletions sidecar/src/figwheel_sidecar/build_middleware/injection.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
(when-let [target (get-in build [:build-options :target])]
(= target :nodejs)))

(defn- webworker? [build]
(when-let [target (get-in build [:build-options :target])]
(= target :webworker)))

(defn- has-main? [build]
(get-in build [:build-options :main]))

Expand Down Expand Up @@ -41,7 +45,8 @@
(fnil conj [])
(if (and (has-main? build)
(not (has-modules? build))
(not (node? build)))
(not (node? build))
(not (webworker? build)))
'figwheel.connect
'figwheel.preload))
(update-in [:build-options :external-config :figwheel/config] #(if % % (get build :figwheel {})))
Expand Down Expand Up @@ -70,7 +75,7 @@

(defn append-src-script [build src-code]
(let [output-to (has-output-to? build)
line (if (and (has-main? build) (not (node? build)))
line (if (and (has-main? build) (not (node? build)) (not (webworker? build)))
(str (document-write-src-script src-code))
(format "\n%s" src-code))]
(when (and output-to (.exists (io/file output-to)))
Expand All @@ -80,7 +85,8 @@
(when (and (config/figwheel-build? build)
(has-main? build)
(not (has-modules? build))
(not (node? build)))
(not (node? build))
(not (webworker? build)))
(append-src-script build "figwheel.connect.start();")))

(defn hook [build-fn]
Expand Down
2 changes: 1 addition & 1 deletion sidecar/src/figwheel_sidecar/schemas/cljs_options.clj
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ human-readable manner. Defaults to true.
:pretty-print false")

(def-key ::target #{:nodejs}
(def-key ::target #{:nodejs :webworker}

"If targeting nodejs add this line. Takes no other options at the
moment. The default (no :target specified) implies browsers are being
Expand Down
5 changes: 5 additions & 0 deletions support/src/figwheel/client/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@
(defmacro dev-assert [& body]
`(dev
~@(map (fn [pred-stmt] `(assert ~pred-stmt)) body)))

(defmacro feature?
[obj feature]
`(and (cljs.core/exists? ~obj)
(cljs.core/exists? (cljs.core/aget ~obj ~feature))))
9 changes: 2 additions & 7 deletions support/src/figwheel/client/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
[goog.userAgent.product :as product])
(:import [goog]
[goog.async Deferred]
[goog.string StringBuffer]))
[goog.string StringBuffer])
(:require-macros [figwheel.client.utils :refer [feature?]]))

;; don't auto reload this file it will mess up the debug printing

Expand Down Expand Up @@ -110,12 +111,6 @@
deferred coll)
(fn [_] (.succeed Deferred @results)))))


(defn- feature? [obj feature]
(and (exists? obj)
(exists? (aget obj feature))))


;; persistent storage of configuration keys

(defonce local-persistent-config
Expand Down

0 comments on commit db2cd28

Please sign in to comment.