|
2141 | 2141 | (defn maybe-install-node-deps!
|
2142 | 2142 | [{:keys [npm-deps verbose] :as opts}]
|
2143 | 2143 | (let [npm-deps (merge npm-deps (compute-upstream-npm-deps opts))]
|
2144 |
| - (if-not (empty? npm-deps) |
| 2144 | + (when-not (empty? npm-deps) |
2145 | 2145 | (let [pkg-json (io/file "package.json")]
|
2146 | 2146 | (when (or ana/*verbose* verbose)
|
2147 | 2147 | (util/debug-prn "Installing Node.js dependencies"))
|
|
2165 | 2165 | (bound-fn [] (pipe proc es ew)))))
|
2166 | 2166 | err (.waitFor proc)]
|
2167 | 2167 | (when (and (not (zero? err)) (not (.isAlive proc)))
|
2168 |
| - (println (str ew))) |
2169 |
| - opts)) |
2170 |
| - opts))) |
| 2168 | + (println (str ew))))) |
| 2169 | + true))) |
2171 | 2170 |
|
2172 | 2171 | (defn node-module-deps
|
2173 | 2172 | "EXPERIMENTAL: return the foreign libs entries as computed by running
|
|
2232 | 2231 | (let [node-modules (io/file "node_modules")]
|
2233 | 2232 | (if (and (not (empty? modules)) (.exists node-modules) (.isDirectory node-modules))
|
2234 | 2233 | (let [modules (into #{} (map name) modules)
|
2235 |
| - deps-file (io/file (util/output-directory opts) "cljs$node_modules.js")] |
| 2234 | + deps-file (io/file (util/output-directory opts) "cljs$node_modules.js") |
| 2235 | + old-contents (when (.exists deps-file) |
| 2236 | + (slurp deps-file)) |
| 2237 | + new-contents (let [sb (StringBuffer.)] |
| 2238 | + (run! #(.append sb (str "require('" % "');\n")) modules) |
| 2239 | + (str sb))] |
2236 | 2240 | (util/mkdirs deps-file)
|
2237 |
| - (with-open [w (io/writer deps-file)] |
2238 |
| - (run! #(.write w (str "require('" % "');\n")) modules)) |
2239 |
| - (node-inputs [{:file (.getAbsolutePath deps-file)}] opts)) |
| 2241 | + (if-not (= old-contents new-contents) |
| 2242 | + (do |
| 2243 | + (spit deps-file new-contents) |
| 2244 | + (let [transitive-js (node-inputs [{:file (.getAbsolutePath deps-file)}] opts)] |
| 2245 | + (when-not (nil? env/*compiler*) |
| 2246 | + (swap! env/*compiler* update-in [::transitive-dep-set] |
| 2247 | + assoc modules transitive-js)) |
| 2248 | + transitive-js)) |
| 2249 | + (when-not (nil? env/*compiler*) |
| 2250 | + (get-in @env/*compiler* [::transitive-dep-set modules])))) |
2240 | 2251 | []))))
|
2241 | 2252 |
|
2242 | 2253 | (defn- node-file-seq->libs-spec*
|
|
2454 | 2465 | - process the JS modules (preprocess + convert to Closure JS)
|
2455 | 2466 | - save js-dependency-index for compilation"
|
2456 | 2467 | [{:keys [npm-deps target] :as opts} js-sources compiler-env]
|
2457 |
| - (let [;; Find all the top-level Node packages and their files |
2458 |
| - top-level (reduce |
| 2468 | + ;; Find all the top-level Node packages and their files |
| 2469 | + (let [top-level (reduce |
2459 | 2470 | (fn [acc m]
|
2460 | 2471 | (reduce (fn [acc p] (assoc acc p m)) acc (:provides m)))
|
2461 | 2472 | {} (index-node-modules-dir))
|
|
2464 | 2475 | ;; and create list of all their dependencies
|
2465 | 2476 | node-required (set/intersection (set (keys top-level)) requires)
|
2466 | 2477 | expanded-libs (expand-libs (:foreign-libs opts))
|
2467 |
| - opts (-> opts |
2468 |
| - (update :foreign-libs |
2469 |
| - (fn [libs] |
2470 |
| - (into (if (= target :nodejs) |
2471 |
| - [] |
2472 |
| - (index-node-modules node-required)) |
2473 |
| - (into expanded-libs |
2474 |
| - (node-inputs (filter (fn [{:keys [module-type]}] |
2475 |
| - (and (some? module-type) |
2476 |
| - (not= module-type :amd))) |
2477 |
| - expanded-libs)))))) |
2478 |
| - process-js-modules)] |
| 2478 | + output-dir (util/output-directory opts) |
| 2479 | + opts (update opts :foreign-libs |
| 2480 | + (fn [libs] |
| 2481 | + (into (if (= target :nodejs) |
| 2482 | + [] |
| 2483 | + (index-node-modules node-required)) |
| 2484 | + (into expanded-libs |
| 2485 | + (node-inputs (filter (fn [{:keys [module-type]}] |
| 2486 | + (and (some? module-type) |
| 2487 | + (not= module-type :amd))) |
| 2488 | + expanded-libs)))))) |
| 2489 | + opts (if (some |
| 2490 | + (fn [ijs] |
| 2491 | + (let [dest (io/file output-dir (rel-output-path (assoc ijs :foreign true) opts))] |
| 2492 | + (util/changed? (deps/-url ijs opts) dest))) |
| 2493 | + (:foreign-libs opts)) |
| 2494 | + (process-js-modules opts) |
| 2495 | + (:options @compiler-env))] |
2479 | 2496 | (swap! compiler-env (fn [cenv]
|
2480 | 2497 | (-> cenv
|
2481 | 2498 | ;; we need to also track the whole top level - this is to support
|
|
2503 | 2520 | ;; we want to warn about NPM dep conflicts before installing the modules
|
2504 | 2521 | (when (:install-deps opts)
|
2505 | 2522 | (check-npm-deps opts)
|
2506 |
| - (maybe-install-node-deps! opts)) |
| 2523 | + (swap! compiler-env update-in [:npm-deps-installed?] |
| 2524 | + (fn [installed?] |
| 2525 | + (when-not installed? |
| 2526 | + (maybe-install-node-deps! opts))))) |
2507 | 2527 | (let [compiler-stats (:compiler-stats opts)
|
2508 | 2528 | checked-arrays (or (:checked-arrays opts)
|
2509 | 2529 | ana/*checked-arrays*)
|
|
2569 | 2589 | (-> (-find-sources source all-opts)
|
2570 | 2590 | (add-dependency-sources compile-opts)))
|
2571 | 2591 | all-opts (handle-js-modules all-opts js-sources compiler-env)
|
| 2592 | + _ (swap! env/*compiler* update-in [:options] merge all-opts) |
2572 | 2593 | js-sources (-> js-sources
|
2573 | 2594 | deps/dependency-order
|
2574 | 2595 | (compile-sources compiler-stats compile-opts)
|
|
0 commit comments