From 36cbb4fc883a40aa7a894a2b38efedd8f2d18f23 Mon Sep 17 00:00:00 2001
From: Thomas Heller
Date: Tue, 10 Apr 2018 09:45:57 +0200
Subject: [PATCH] fix classpath issue when files in ~/.m2 get deleted
checks if all previously downloaded files still exist and
rebuilds everything when anything is missing.
see #77
---
src/main/shadow/cljs/npm/cli.cljs | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/src/main/shadow/cljs/npm/cli.cljs b/src/main/shadow/cljs/npm/cli.cljs
index 4d2e8ddc..12cbc9e3 100644
--- a/src/main/shadow/cljs/npm/cli.cljs
+++ b/src/main/shadow/cljs/npm/cli.cljs
@@ -159,7 +159,7 @@
(reduce-kv conj [dep-id version] mods))))
(into [])))
-(defn get-classpath [project-root {:keys [cache-root version] :as config}]
+(defn get-classpath [project-root {:keys [cache-root] :as config}]
(let [cp-file
(path/resolve project-root cache-root "classpath.edn")
@@ -176,14 +176,27 @@
(modified-dependencies? cp-file classpath-config))
;; re-create classpath by running the java helper
(let [jar (js/require "shadow-cljs-jar/path")]
- (run-java project-root ["-jar" jar] {:input (pr-str classpath-config)
- :stdio [nil js/process.stdout js/process.stderr]})
- true))]
-
- ;; only return :files since the rest is just cache info
- (-> (util/slurp cp-file)
- (reader/read-string)
- (assoc :updated? updated?))))
+ (run-java
+ project-root
+ ["-jar" jar]
+ {:input (pr-str classpath-config)
+ :stdio [nil js/process.stdout js/process.stderr]})
+ true))
+
+ {:keys [files] :as classpath-data}
+ (-> (util/slurp cp-file)
+ (reader/read-string)
+ (assoc :updated? updated?))]
+
+ ;; if something in the ~/.m2 directory is deleted we need to re-fetch it
+ ;; otherwise we end up with weird errors at runtime
+ (if (every? #(fs/existsSync %) files)
+ classpath-data
+ ;; if anything is missing delete the classpath.edn and start over
+ (do (fs/unlinkSync cp-file)
+ (log "WARN: missing dependencies, reconstructing classpath.")
+ (recur project-root config)
+ ))))
(defn print-error [ex]
(let [{:keys [tag] :as data}