Skip to content

Commit

Permalink
fix classpath issue when files in ~/.m2 get deleted
Browse files Browse the repository at this point in the history
checks if all previously downloaded files still exist and
rebuilds everything when anything is missing.

see #77
  • Loading branch information
thheller committed Apr 10, 2018
1 parent 428c23d commit 36cbb4f
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/main/shadow/cljs/npm/cli.cljs
Expand Up @@ -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")

Expand All @@ -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}
Expand Down

0 comments on commit 36cbb4f

Please sign in to comment.