|
2397 | 2397 | - index all the node node modules
|
2398 | 2398 | - process the JS modules (preprocess + convert to Closure JS)
|
2399 | 2399 | - save js-dependency-index for compilation"
|
2400 |
| - ([opts js-sources compiler-env] |
2401 |
| - (handle-js-modules opts js-sources compiler-env true)) |
2402 |
| - ([{:keys [npm-deps target] :as opts} js-sources compiler-env only-required?] |
2403 |
| - (let [;; Find all the top-level Node packages and their files |
2404 |
| - top-level (reduce |
2405 |
| - (fn [acc m] |
2406 |
| - (reduce (fn [acc p] (assoc acc p m)) acc (:provides m))) |
2407 |
| - {} (index-node-modules-dir)) |
2408 |
| - requires (set (mapcat deps/-requires js-sources)) |
2409 |
| - ;; Select Node files that are required by Cljs code, |
2410 |
| - ;; and create list of all their dependencies |
2411 |
| - node-required (if only-required? |
2412 |
| - (set/intersection (set (keys top-level)) requires) |
2413 |
| - (keys top-level))] |
2414 |
| - (if-not (= target :nodejs) |
2415 |
| - (let [opts (-> opts |
2416 |
| - (update :foreign-libs |
2417 |
| - (fn [libs] |
2418 |
| - (into (if-not (empty? npm-deps) |
2419 |
| - (index-node-modules node-required) |
2420 |
| - []) |
2421 |
| - (expand-libs libs)))) |
2422 |
| - process-js-modules)] |
2423 |
| - (swap! compiler-env assoc :js-dependency-index |
2424 |
| - (deps/js-dependency-index opts)) |
2425 |
| - opts) |
2426 |
| - (do |
2427 |
| - (swap! compiler-env update-in [:node-module-index] |
2428 |
| - (fnil into #{}) (map str node-required)) |
2429 |
| - opts))))) |
| 2400 | + [{:keys [npm-deps target] :as opts} js-sources compiler-env] |
| 2401 | + (let [;; Find all the top-level Node packages and their files |
| 2402 | + top-level (reduce |
| 2403 | + (fn [acc m] |
| 2404 | + (reduce (fn [acc p] (assoc acc p m)) acc (:provides m))) |
| 2405 | + {} (index-node-modules-dir)) |
| 2406 | + requires (set (mapcat deps/-requires js-sources)) |
| 2407 | + ;; Select Node files that are required by Cljs code, |
| 2408 | + ;; and create list of all their dependencies |
| 2409 | + node-required (set/intersection (set (keys top-level)) requires)] |
| 2410 | + (if-not (= target :nodejs) |
| 2411 | + (let [opts (-> opts |
| 2412 | + (update :foreign-libs |
| 2413 | + (fn [libs] |
| 2414 | + (into (if-not (empty? npm-deps) |
| 2415 | + (index-node-modules node-required) |
| 2416 | + []) |
| 2417 | + (expand-libs libs)))) |
| 2418 | + process-js-modules)] |
| 2419 | + (swap! compiler-env merge |
| 2420 | + ;; we need to also track the whole top level - this is to support |
| 2421 | + ;; cljs.analyze/analyze-deps, particularly in REPL contexts - David |
| 2422 | + {:js-dependency-index (deps/js-dependency-index opts) |
| 2423 | + :node-module-index (into #{} (map str (keys top-level)))}) |
| 2424 | + opts) |
| 2425 | + (do |
| 2426 | + (swap! compiler-env update-in [:node-module-index] |
| 2427 | + (fnil into #{}) (map str node-required)) |
| 2428 | + opts)))) |
2430 | 2429 |
|
2431 | 2430 | (defn build
|
2432 | 2431 | "Given a source which can be compiled, produce runnable JavaScript."
|
|
0 commit comments