|
479 | 479 | (-compile uri (merge opts {:output-file js-file}))))
|
480 | 480 |
|
481 | 481 | (defn cljs-source-for-namespace
|
482 |
| - "Returns a map containing :relative-path, :uri referring to the resource that |
483 |
| -should contain the source for the given namespace name." |
| 482 | + "Given a namespace return the corresponding source with either a .cljc or |
| 483 | + .cljs extension." |
484 | 484 | [ns]
|
485 |
| - (as-> (munge ns) % |
486 |
| - (string/replace % \. \/) |
487 |
| - (str % ".cljs") |
488 |
| - {:relative-path % :uri (io/resource %)})) |
| 485 | + (let [path (-> (munge ns) (string/replace \. \/)) |
| 486 | + relpath (str path ".cljc")] |
| 487 | + (if-let [res (io/resource relpath)] |
| 488 | + {:relative-path relpath :uri res} |
| 489 | + (let [relpath (str path ".cljs")] |
| 490 | + (if-let [res (io/resource relpath)] |
| 491 | + {:relative-path relpath :uri res}))))) |
489 | 492 |
|
490 | 493 | (defn source-for-namespace
|
| 494 | + "Given a namespace and compilation environment return the relative path and |
| 495 | + uri of the corresponding source regardless of the source language extension: |
| 496 | + .cljc, .cljs, .js" |
491 | 497 | [ns compiler-env]
|
492 | 498 | (let [ns-str (str (comp/munge ns {}))
|
493 | 499 | path (string/replace ns-str \. \/)
|
494 |
| - relpath (str path ".cljs")] |
495 |
| - (if-let [cljs-res (io/resource relpath)] |
496 |
| - {:relative-path relpath :uri cljs-res} |
497 |
| - (let [relpath (:file (get-in @compiler-env [:js-dependency-index ns-str]))] |
498 |
| - (if-let [js-res (and relpath (io/resource relpath))] |
499 |
| - {:relative-path relpath :uri js-res} |
500 |
| - (throw |
501 |
| - (IllegalArgumentException. (str "Namespace " ns " does not exist")))))))) |
| 500 | + relpath (str path ".cljc")] |
| 501 | + (if-let [cljc-res (io/resource relpath)] |
| 502 | + {:relative-path relpath :uri cljc-res} |
| 503 | + (let [relpath (str path ".cljs")] |
| 504 | + (if-let [cljs-res (io/resource relpath)] |
| 505 | + {:relative-path relpath :uri cljs-res} |
| 506 | + (let [relpath (:file (get-in @compiler-env [:js-dependency-index ns-str]))] |
| 507 | + (if-let [js-res (and relpath (io/resource relpath))] |
| 508 | + {:relative-path relpath :uri js-res} |
| 509 | + (throw |
| 510 | + (IllegalArgumentException. (str "Namespace " ns " does not exist")))))))))) |
502 | 511 |
|
503 | 512 | (defn cljs-dependencies
|
504 | 513 | "Given a list of all required namespaces, return a list of
|
@@ -814,7 +823,7 @@ should contain the source for the given namespace name."
|
814 | 823 | (if (and provides source-url)
|
815 | 824 | (assoc relpaths
|
816 | 825 | (.getPath ^URL source-url)
|
817 |
| - (util/ns->relpath (first provides))) |
| 826 | + (util/ns->relpath (first provides) (util/ext source-url))) |
818 | 827 | relpaths))
|
819 | 828 | (if-let [url (:url source)]
|
820 | 829 | (let [path (.getPath ^URL url)]
|
@@ -1156,9 +1165,9 @@ should contain the source for the given namespace name."
|
1156 | 1165 | (write-javascript opts js)
|
1157 | 1166 | ;; always copy original ClojureScript sources to the output directory
|
1158 | 1167 | ;; when source maps enabled
|
1159 |
| - (let [out-file (if-let [ns (and (:source-map opts) (first (:provides js)))] |
| 1168 | + (let [out-file (when-let [ns (and (:source-map opts) (first (:provides js)))] |
1160 | 1169 | (io/file (io/file (util/output-directory opts))
|
1161 |
| - (util/ns->relpath ns))) |
| 1170 | + (util/ns->relpath ns (util/ext (:source-url js))))) |
1162 | 1171 | source-url (:source-url js)]
|
1163 | 1172 | (when (and out-file source-url
|
1164 | 1173 | (or (not (.exists ^File out-file))
|
@@ -1551,7 +1560,8 @@ should contain the source for the given namespace name."
|
1551 | 1560 | (some
|
1552 | 1561 | (fn [^WatchEvent e]
|
1553 | 1562 | (let [fstr (.. e context toString)]
|
1554 |
| - (and (or (. fstr (endsWith "cljs")) |
| 1563 | + (and (or (. fstr (endsWith "cljc")) |
| 1564 | + (. fstr (endsWith "cljs")) |
1555 | 1565 | (. fstr (endsWith "js")))
|
1556 | 1566 | (not (. fstr (startsWith ".#"))))))
|
1557 | 1567 | (seq (.pollEvents key))))
|
@@ -1596,9 +1606,9 @@ should contain the source for the given namespace name."
|
1596 | 1606 | ([src {:keys [wrap all-provides] :as options}]
|
1597 | 1607 | (let [goog-ns
|
1598 | 1608 | (case (util/ext src)
|
1599 |
| - "cljs" (comp/munge (:ns (ana/parse-ns src))) |
1600 |
| - "js" (cond-> (:provides (parse-js-ns src)) |
1601 |
| - (not all-provides) first) |
| 1609 | + ("cljc" "cljs") (comp/munge (:ns (ana/parse-ns src))) |
| 1610 | + "js" (cond-> (:provides (parse-js-ns src)) |
| 1611 | + (not all-provides) first) |
1602 | 1612 | (throw
|
1603 | 1613 | (IllegalArgumentException.
|
1604 | 1614 | (str "Can't create goog.require expression for " src))))]
|
|
0 commit comments