Skip to content
Prev Previous commit
Next Next commit
* breakout get-pkg-json to simplify testing
  • Loading branch information
swannodette committed May 19, 2023
commit 3f34a4c3482f62dbbc8a520a33b672f28ac0b0a5
20 changes: 13 additions & 7 deletions src/main/clojure/cljs/foreign/node.clj
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,28 @@
(not (some #{index-replaced} provides)))
(conj index-replaced)))}))))

(defn get-pkg-jsons
"Given all a seq of files in node_modules return a map of all package.json
files indexed by path. Includes any `export` package.json files as well"
[module-fseq]
(->> module-fseq
(into {}
(comp (map #(.getAbsolutePath %))
(filter top-level-package-json?)
(map (fn [path] [path (json/read-str (slurp path))]))))
add-exports))

(defn node-file-seq->libs-spec*
"Given a sequence of non-nested node_module paths where the extension ends in
`.js/.json`, return lib-spec maps for each path containing at least :file,
:module-type, and :provides."
[module-fseq opts]
(let [;; a map of all the *top-level* package.json paths and their exports
;; to the package.json contents as EDN
pkg-jsons (into {}
(comp (map #(.getAbsolutePath %))
(filter top-level-package-json?)
(map (fn [path] [path (json/read-str (slurp path))])))
module-fseq)
pkg-jsons+exports (add-exports pkg-jsons)]
pkg-jsons (get-pkg-jsons module-fseq)]
(into []
(comp
(map #(.getAbsolutePath %))
;; for each file, figure out what it will provide to ClojureScript
(map #(path->provides % pkg-jsons+exports opts)))
(map #(path->provides % pkg-jsons opts)))
module-fseq)))