|
2206 | 2206 | (node-inputs [{:file (.getAbsolutePath deps-file)}] opts)) |
2207 | 2207 | [])))) |
2208 | 2208 |
|
| 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 | + |
2209 | 2248 | (defn index-node-modules-dir |
2210 | 2249 | ([] |
2211 | 2250 | (index-node-modules-dir |
2212 | 2251 | (when env/*compiler* |
2213 | 2252 | (:options @env/*compiler*)))) |
2214 | 2253 | ([{: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)))) |
2250 | 2256 |
|
2251 | 2257 | (defn preprocess-js |
2252 | 2258 | "Given js-module map, apply preprocessing defined by :preprocess value in the map." |
|
0 commit comments