From 2474c2e1f26c060ecbb4f376fe137390d5811653 Mon Sep 17 00:00:00 2001 From: Ryan McGowan Date: Wed, 20 Aug 2014 17:38:21 -0700 Subject: [PATCH] Search all forms in project.clj for defproject. See #14. --- src/leiningen/npm/deps.clj | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/leiningen/npm/deps.clj b/src/leiningen/npm/deps.clj index 1f1fd6a..ba4d014 100644 --- a/src/leiningen/npm/deps.clj +++ b/src/leiningen/npm/deps.clj @@ -34,6 +34,24 @@ (keep (comp name :name)) (set)))) +(defn- find-project-form + "Find the first form where the first element is the symbol defproject in the + given top-level forms." + [forms] + (letfn [(fpf [form] + (if (list? form) + (if (= 'defproject (first form)) + form + (find-project-form form))))] + (->> forms + (map fpf) + (keep identity) + (first)))) + +(defn- read-project-form [input-stream] + (->> (str \( (slurp input-stream) \)) + (read-string) + (find-project-form))) (defn- resolve-in-jar-dep "Resolves a given lookup-key in the project definiton in a given @@ -43,7 +61,9 @@ [lookup-key exclusions jar-file] (let [jar-project-entry (.getEntry jar-file "project.clj") jar-project-src (when jar-project-entry - (read-string (slurp (.getInputStream jar-file jar-project-entry)))) + (-> jar-file + (.getInputStream jar-project-entry) + (read-project-form))) jar-project-map (when jar-project-src (->> jar-project-src (drop 3) (apply hash-map))) jar-project-name (when jar-project-src