Skip to content

Commit 3057bbe

Browse files
anmonteirodnolen
authored andcommitted
CLJS-2296: Foreign libs that expose modules are not being processed under target node
1 parent 0e3e485 commit 3057bbe

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed

src/main/clojure/cljs/closure.clj

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,23 +2408,24 @@
24082408
;; Select Node files that are required by Cljs code,
24092409
;; and create list of all their dependencies
24102410
node-required (set/intersection (set (keys top-level)) requires)]
2411-
(if-not (= target :nodejs)
2412-
(let [opts (-> opts
2413-
(update :foreign-libs
2414-
(fn [libs]
2415-
(into (index-node-modules node-required)
2416-
(expand-libs libs))))
2417-
process-js-modules)]
2418-
(swap! compiler-env merge
2419-
;; we need to also track the whole top level - this is to support
2420-
;; cljs.analyze/analyze-deps, particularly in REPL contexts - David
2421-
{:js-dependency-index (deps/js-dependency-index opts)
2422-
:node-module-index (into #{} (map str (keys top-level)))})
2423-
opts)
2424-
(do
2425-
(swap! compiler-env update-in [:node-module-index]
2426-
(fnil into #{}) (map str node-required))
2427-
opts))))
2411+
(let [opts (-> opts
2412+
(update :foreign-libs
2413+
(fn [libs]
2414+
(into (if (= target :nodejs)
2415+
[]
2416+
(index-node-modules node-required))
2417+
(expand-libs libs))))
2418+
process-js-modules)]
2419+
(swap! compiler-env (fn [cenv]
2420+
(-> cenv
2421+
;; we need to also track the whole top level - this is to support
2422+
;; cljs.analyze/analyze-deps, particularly in REPL contexts - David
2423+
(merge {:js-dependency-index (deps/js-dependency-index opts)})
2424+
(update-in [:node-module-index] (fnil into #{})
2425+
(if (= target :nodejs)
2426+
(map str node-required)
2427+
(map str (keys top-level)))))))
2428+
opts)))
24282429

24292430
(defn build
24302431
"Given a source which can be compiled, produce runnable JavaScript."
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
foo: 'bar',
3+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
;; Copyright (c) Rich Hickey. All rights reserved.
2+
;; The use and distribution terms for this software are covered by the
3+
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4+
;; which can be found in the file epl-v10.html at the root of this distribution.
5+
;; By using this software in any fashion, you are agreeing to be bound by
6+
;; the terms of this license.
7+
;; You must not remove this notice, or any other, from this software.
8+
9+
(ns foreign-libs-dir-test.core
10+
(:require [vendor.lib :as lib]))
11+
12+
(enable-console-print!)
13+
14+
(defn main []
15+
(println lib))

src/test/clojure/cljs/build_api_tests.clj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,19 @@
462462
(test/delete-out-files out)
463463
(test/delete-node-modules)
464464
(.delete (io/file "package.json"))))
465+
466+
(deftest test-cljs-2296
467+
(let [out (.getPath (io/file (test/tmp-dir) "cljs-2296-test-out"))
468+
{:keys [inputs opts]} {:inputs (str (io/file "src" "test" "cljs_build"))
469+
:opts {:main 'foreign_libs_dir_test.core
470+
:output-dir out
471+
:optimizations :none
472+
:target :nodejs
473+
;; :file is a directory
474+
:foreign-libs [{:file "src/test/cljs_build/foreign-libs-dir"
475+
:module-type :commonjs}]}}]
476+
(test/delete-out-files out)
477+
(build/build (build/inputs (io/file inputs "foreign_libs_dir_test/core.cljs")) opts)
478+
(is (.exists (io/file out "src/test/cljs_build/foreign-libs-dir/vendor/lib.js")))
479+
(is (true? (boolean (re-find #"goog\.provide\(\"module\$src\$test\$cljs_build\$foreign_libs_dir\$vendor\$lib\"\)"
480+
(slurp (io/file out "src/test/cljs_build/foreign-libs-dir/vendor/lib.js"))))))))

0 commit comments

Comments
 (0)