Skip to content

Commit b17b831

Browse files
anmonteirodnolen
authored andcommitted
CLJS-2238: Perf regression with node module indexing
1 parent efc7efa commit b17b831

1 file changed

Lines changed: 41 additions & 35 deletions

File tree

src/main/clojure/cljs/closure.clj

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,47 +2206,53 @@
22062206
(node-inputs [{:file (.getAbsolutePath deps-file)}] opts))
22072207
[]))))
22082208

2209+
(defn- node-file-seq->libs-spec*
2210+
[module-fseq]
2211+
(letfn [(package-json? [path]
2212+
(boolean (re-find #"node_modules[/\\](@[^/\\]+?[/\\])?[^/\\]+?[/\\]package\.json$" path)))]
2213+
(let [pkg-jsons (into {}
2214+
(comp
2215+
(map #(.getAbsolutePath %))
2216+
(filter package-json?)
2217+
(map (fn [path]
2218+
[path (json/read-str (slurp path))])))
2219+
module-fseq)]
2220+
(into []
2221+
(comp
2222+
(map #(.getAbsolutePath %))
2223+
(map (fn [path]
2224+
(merge
2225+
{:file path
2226+
:module-type :commonjs}
2227+
(when-not (package-json? path)
2228+
(let [pkg-json-main (some
2229+
(fn [[pkg-json-path {:strs [main name]}]]
2230+
(when-not (nil? main)
2231+
(let [main-path (str (string/replace pkg-json-path #"package\.json$" "")
2232+
main)]
2233+
(when (= main-path path)
2234+
name))))
2235+
pkg-jsons)]
2236+
{:provides (if (some? pkg-json-main)
2237+
[pkg-json-main]
2238+
(let [module-rel-name (string/replace
2239+
(subs path (.lastIndexOf path "node_modules"))
2240+
#"node_modules[\\\/]" "")]
2241+
(cond-> [module-rel-name (string/replace module-rel-name #"\.js(on)?$" "")]
2242+
(boolean (re-find #"[\\\/]index\.js(on)?$" module-rel-name))
2243+
(conj (string/replace module-rel-name #"[\\\/]index\.js(on)?$" "")))))}))))))
2244+
module-fseq))))
2245+
2246+
(def node-file-seq->libs-spec (memoize node-file-seq->libs-spec*))
2247+
22092248
(defn index-node-modules-dir
22102249
([]
22112250
(index-node-modules-dir
22122251
(when env/*compiler*
22132252
(:options @env/*compiler*))))
22142253
([{:keys [verbose target]}]
2215-
(letfn [(package-json? [path]
2216-
(boolean (re-find #"node_modules[/\\](@[^/\\]+?[/\\])?[^/\\]+?[/\\]package\.json$" path)))]
2217-
(let [module-fseq (util/module-file-seq)
2218-
pkg-jsons (into {}
2219-
(comp
2220-
(map #(.getAbsolutePath %))
2221-
(filter package-json?)
2222-
(map (fn [path]
2223-
[path (json/read-str (slurp path))])))
2224-
module-fseq)]
2225-
(into []
2226-
(comp
2227-
(map #(.getAbsolutePath %))
2228-
(map (fn [path]
2229-
(merge
2230-
{:file path
2231-
:module-type :commonjs}
2232-
(when-not (package-json? path)
2233-
(let [pkg-json-main (some
2234-
(fn [[pkg-json-path {:strs [main name]}]]
2235-
(when-not (nil? main)
2236-
(let [main-path (str (string/replace pkg-json-path #"package\.json$" "")
2237-
main)]
2238-
(when (= main-path path)
2239-
name))))
2240-
pkg-jsons)]
2241-
{:provides (if (some? pkg-json-main)
2242-
[pkg-json-main]
2243-
(let [module-rel-name (string/replace
2244-
(subs path (.lastIndexOf path "node_modules"))
2245-
#"node_modules[\\\/]" "")]
2246-
(cond-> [module-rel-name (string/replace module-rel-name #"\.js(on)?$" "")]
2247-
(boolean (re-find #"[\\\/]index\.js(on)?$" module-rel-name))
2248-
(conj (string/replace module-rel-name #"[\\\/]index\.js(on)?$" "")))))}))))))
2249-
module-fseq)))))
2254+
(let [module-fseq (util/module-file-seq)]
2255+
(node-file-seq->libs-spec module-fseq))))
22502256

22512257
(defn preprocess-js
22522258
"Given js-module map, apply preprocessing defined by :preprocess value in the map."

0 commit comments

Comments
 (0)