|
2517 | 2517 | (add-externs-sources (dissoc opts :foreign-libs)))))) |
2518 | 2518 | ([source opts compiler-env] |
2519 | 2519 | (env/with-compiler-env compiler-env |
2520 | | - ;; we want to warn about NPM dep conflicts before installing the modules |
2521 | | - (when (:install-deps opts) |
2522 | | - (check-npm-deps opts) |
2523 | | - (swap! compiler-env update-in [:npm-deps-installed?] |
2524 | | - (fn [installed?] |
2525 | | - (when-not installed? |
2526 | | - (maybe-install-node-deps! opts))))) |
2527 | | - (let [compiler-stats (:compiler-stats opts) |
| 2520 | + (let [opts (add-implicit-options opts) |
| 2521 | + ;; we want to warn about NPM dep conflicts before installing the modules |
| 2522 | + _ (when (:install-deps opts) |
| 2523 | + (check-npm-deps opts) |
| 2524 | + (swap! compiler-env update-in [:npm-deps-installed?] |
| 2525 | + (fn [installed?] |
| 2526 | + (when-not installed? |
| 2527 | + (maybe-install-node-deps! opts))))) |
| 2528 | + |
| 2529 | + compiler-stats (:compiler-stats opts) |
2528 | 2530 | checked-arrays (or (:checked-arrays opts) |
2529 | 2531 | ana/*checked-arrays*) |
2530 | 2532 | static-fns? (or (and (= (:optimizations opts) :advanced) |
2531 | 2533 | (not (false? (:static-fns opts)))) |
2532 | 2534 | (:static-fns opts) |
2533 | 2535 | ana/*cljs-static-fns*) |
2534 | | - sources (-find-sources source opts) |
2535 | | - all-opts (add-implicit-options opts)] |
| 2536 | + sources (-find-sources source opts)] |
2536 | 2537 | (check-output-to opts) |
2537 | 2538 | (check-output-dir opts) |
2538 | 2539 | (check-source-map opts) |
2539 | 2540 | (check-source-map-path opts) |
2540 | 2541 | (check-output-wrapper opts) |
2541 | 2542 | (check-node-target opts) |
2542 | | - (check-preloads all-opts) |
| 2543 | + (check-preloads opts) |
2543 | 2544 | (check-cache-analysis-format opts) |
2544 | 2545 | (swap! compiler-env |
2545 | 2546 | #(-> % |
2546 | | - (update-in [:options] merge all-opts) |
| 2547 | + (update-in [:options] merge opts) |
2547 | 2548 | (assoc :target (:target opts)) |
2548 | | - ;; Save the current js-dependency index once we have computed all-opts |
| 2549 | + ;; Save the current js-dependency index once we have computed opts |
2549 | 2550 | ;; or the analyzer won't be able to find upstream dependencies - Antonio |
2550 | | - (assoc :js-dependency-index (deps/js-dependency-index all-opts)) |
| 2551 | + (assoc :js-dependency-index (deps/js-dependency-index opts)) |
2551 | 2552 | ;; Save list of sources for cljs.analyzer/locate-src - Juho Teperi |
2552 | 2553 | (assoc :sources sources))) |
2553 | 2554 | (binding [comp/*recompiled* (when-not (false? (:recompile-dependents opts)) |
|
2571 | 2572 | (repeat warnings)) |
2572 | 2573 | warnings))) |
2573 | 2574 | ana/*verbose* (:verbose opts)] |
2574 | | - (let [one-file? (and (:main all-opts) |
2575 | | - (#{:advanced :simple :whitespace} (:optimizations all-opts))) |
| 2575 | + (let [one-file? (and (:main opts) |
| 2576 | + (#{:advanced :simple :whitespace} (:optimizations opts))) |
2576 | 2577 | source (if one-file? |
2577 | | - (let [main (:main all-opts) |
| 2578 | + (let [main (:main opts) |
2578 | 2579 | uri (:uri (cljs-source-for-namespace main))] |
2579 | 2580 | (assert uri (str "No file for namespace " main " exists")) |
2580 | 2581 | uri) |
2581 | 2582 | source) |
2582 | 2583 | compile-opts (if one-file? |
2583 | | - (assoc all-opts :output-file (:output-to all-opts)) |
2584 | | - all-opts) |
| 2584 | + (assoc opts :output-file (:output-to opts)) |
| 2585 | + opts) |
2585 | 2586 | _ (load-data-readers! compiler-env) |
2586 | 2587 | ;; reset :js-module-index so that ana/parse-ns called by -find-sources |
2587 | 2588 | ;; can find the missing JS modules |
2588 | 2589 | js-sources (env/with-compiler-env (dissoc @compiler-env :js-module-index) |
2589 | | - (-> (-find-sources source all-opts) |
| 2590 | + (-> (-find-sources source opts) |
2590 | 2591 | (add-dependency-sources compile-opts))) |
2591 | | - all-opts (handle-js-modules all-opts js-sources compiler-env) |
2592 | | - _ (swap! env/*compiler* update-in [:options] merge all-opts) |
| 2592 | + opts (handle-js-modules opts js-sources compiler-env) |
| 2593 | + _ (swap! env/*compiler* update-in [:options] merge opts) |
2593 | 2594 | js-sources (-> js-sources |
2594 | 2595 | deps/dependency-order |
2595 | 2596 | (compile-sources compiler-stats compile-opts) |
2596 | 2597 | (#(map add-core-macros-if-cljs-js %)) |
2597 | | - (add-js-sources all-opts) |
2598 | | - (cond-> (= :nodejs (:target all-opts)) (concat [(-compile (io/resource "cljs/nodejs.cljs") all-opts)])) |
| 2598 | + (add-js-sources opts) |
| 2599 | + (cond-> (= :nodejs (:target opts)) (concat [(-compile (io/resource "cljs/nodejs.cljs") opts)])) |
2599 | 2600 | deps/dependency-order |
2600 | | - (add-preloads all-opts) |
| 2601 | + (add-preloads opts) |
2601 | 2602 | add-goog-base |
2602 | | - (cond-> (= :nodejs (:target all-opts)) (concat [(-compile (io/resource "cljs/nodejscli.cljs") all-opts)])) |
2603 | | - (->> (map #(source-on-disk all-opts %)) doall) |
2604 | | - (compile-loader all-opts)) |
2605 | | - _ (when (:emit-constants all-opts) |
| 2603 | + (cond-> (= :nodejs (:target opts)) (concat [(-compile (io/resource "cljs/nodejscli.cljs") opts)])) |
| 2604 | + (->> (map #(source-on-disk opts %)) doall) |
| 2605 | + (compile-loader opts)) |
| 2606 | + _ (when (:emit-constants opts) |
2606 | 2607 | (comp/emit-constants-table-to-file |
2607 | 2608 | (::ana/constant-table @env/*compiler*) |
2608 | | - (constants-filename all-opts))) |
2609 | | - _ (when (:infer-externs all-opts) |
| 2609 | + (constants-filename opts))) |
| 2610 | + _ (when (:infer-externs opts) |
2610 | 2611 | (comp/emit-inferred-externs-to-file |
2611 | 2612 | (reduce util/map-merge {} |
2612 | 2613 | (map (comp :externs second) |
2613 | 2614 | (get @compiler-env ::ana/namespaces))) |
2614 | | - (str (util/output-directory all-opts) "/inferred_externs.js"))) |
2615 | | - optim (:optimizations all-opts) |
| 2615 | + (str (util/output-directory opts) "/inferred_externs.js"))) |
| 2616 | + optim (:optimizations opts) |
2616 | 2617 | ret (if (and optim (not= optim :none)) |
2617 | 2618 | (do |
2618 | | - (when-let [fname (:source-map all-opts)] |
2619 | | - (assert (or (nil? (:output-to all-opts)) (:modules opts) (string? fname)) |
| 2619 | + (when-let [fname (:source-map opts)] |
| 2620 | + (assert (or (nil? (:output-to opts)) (:modules opts) (string? fname)) |
2620 | 2621 | (str ":source-map must name a file when using :whitespace, " |
2621 | 2622 | ":simple, or :advanced optimizations with :output-to"))) |
2622 | | - (if (:modules all-opts) |
| 2623 | + (if (:modules opts) |
2623 | 2624 | (->> |
2624 | 2625 | (util/measure compiler-stats |
2625 | 2626 | (str "Optimizing " (count js-sources) " sources") |
2626 | | - (apply optimize-modules all-opts js-sources)) |
2627 | | - (output-modules all-opts js-sources)) |
2628 | | - (let [fdeps-str (foreign-deps-str all-opts |
| 2627 | + (apply optimize-modules opts js-sources)) |
| 2628 | + (output-modules opts js-sources)) |
| 2629 | + (let [fdeps-str (foreign-deps-str opts |
2629 | 2630 | (filter foreign-source? js-sources)) |
2630 | | - all-opts (assoc all-opts |
| 2631 | + opts (assoc opts |
2631 | 2632 | :foreign-deps-line-count |
2632 | 2633 | (- (count (.split #"\r?\n" fdeps-str -1)) 1))] |
2633 | 2634 | (->> |
2634 | 2635 | (util/measure compiler-stats |
2635 | 2636 | (str "Optimizing " (count js-sources) " sources") |
2636 | | - (apply optimize all-opts |
| 2637 | + (apply optimize opts |
2637 | 2638 | (remove foreign-source? js-sources))) |
2638 | | - (add-wrapper all-opts) |
2639 | | - (add-source-map-link all-opts) |
| 2639 | + (add-wrapper opts) |
| 2640 | + (add-source-map-link opts) |
2640 | 2641 | (str fdeps-str) |
2641 | | - (add-header all-opts) |
2642 | | - (output-one-file all-opts))))) |
2643 | | - (apply output-unoptimized all-opts js-sources))] |
| 2642 | + (add-header opts) |
| 2643 | + (output-one-file opts))))) |
| 2644 | + (apply output-unoptimized opts js-sources))] |
2644 | 2645 | ;; emit Node.js bootstrap script for :none & :whitespace optimizations |
2645 | 2646 | (when (and (= (:target opts) :nodejs) |
2646 | 2647 | (not= (:optimizations opts) :whitespace)) |
|
0 commit comments