|
2733 | 2733 | []))))
|
2734 | 2734 |
|
2735 | 2735 | (defn- node-file-seq->libs-spec*
|
2736 |
| - [module-fseq] |
| 2736 | + [module-fseq opts] |
2737 | 2737 | (letfn [(package-json? [path]
|
2738 | 2738 | (boolean (re-find #"node_modules[/\\](@[^/\\]+?[/\\])?[^/\\]+?[/\\]package\.json$" path)))]
|
2739 | 2739 | (let [pkg-jsons (into {}
|
|
2756 | 2756 | :module-type :es6}
|
2757 | 2757 | (when-not (package-json? path)
|
2758 | 2758 | (let [pkg-json-main (some
|
2759 |
| - (fn [[pkg-json-path {:strs [main name]}]] |
2760 |
| - (when-not (nil? main) |
2761 |
| - ;; should be the only edge case in |
2762 |
| - ;; the package.json main field - Antonio |
2763 |
| - (let [main (cond-> main |
2764 |
| - (string/starts-with? main "./") |
2765 |
| - (subs 2)) |
2766 |
| - main-path (-> pkg-json-path |
2767 |
| - (string/replace \\ \/) |
2768 |
| - trim-package-json |
2769 |
| - (str main))] |
2770 |
| - (some (fn [candidate] |
2771 |
| - (when (= candidate (string/replace path \\ \/)) |
2772 |
| - name)) |
2773 |
| - (cond-> [main-path] |
2774 |
| - (not (or (string/ends-with? main-path ".js") |
2775 |
| - (string/ends-with? main-path ".json"))) |
2776 |
| - (into [(str main-path ".js") (str main-path "/index.js") (str main-path ".json")])))))) |
| 2759 | + (fn [[pkg-json-path {:as pkg-json :strs [name]}]] |
| 2760 | + (let [entries (package-json-entries opts) |
| 2761 | + entry (first (keep (partial get pkg-json) entries))] |
| 2762 | + (when-not (nil? entry) |
| 2763 | + ;; should be the only edge case in |
| 2764 | + ;; the package.json main field - Antonio |
| 2765 | + (let [entry (cond-> entry |
| 2766 | + (string/starts-with? entry "./") |
| 2767 | + (subs 2)) |
| 2768 | + entry-path (-> pkg-json-path |
| 2769 | + (string/replace \\ \/) |
| 2770 | + trim-package-json |
| 2771 | + (str entry))] |
| 2772 | + (some (fn [candidate] |
| 2773 | + (when (= candidate (string/replace path \\ \/)) |
| 2774 | + name)) |
| 2775 | + (cond-> [entry-path] |
| 2776 | + (not (or (string/ends-with? entry-path ".js") |
| 2777 | + (string/ends-with? entry-path ".json"))) |
| 2778 | + (into [(str entry-path ".js") (str entry-path "/index.js") (str entry-path ".json")]))))))) |
2777 | 2779 | pkg-jsons)]
|
2778 | 2780 | {:provides (let [module-rel-name (-> (subs path (.lastIndexOf path "node_modules"))
|
2779 | 2781 | (string/replace \\ \/)
|
|
2797 | 2799 | (:options @env/*compiler*))))
|
2798 | 2800 | ([opts]
|
2799 | 2801 | (let [module-fseq (util/module-file-seq)]
|
2800 |
| - (node-file-seq->libs-spec module-fseq)))) |
| 2802 | + (node-file-seq->libs-spec module-fseq opts)))) |
2801 | 2803 |
|
2802 | 2804 | (defn preprocess-js
|
2803 | 2805 | "Given js-module map, apply preprocessing defined by :preprocess value in the map."
|
|
0 commit comments