Skip to content

Commit 53070a2

Browse files
Deraendnolen
authored andcommitted
CLJS-2430: Fix foreign-libs with Node target
Foreign libraries need to be loaded using nodeGlobalRequire instead of Node require. This will emit opt_loadFlag for foreign lib deps to cljs_deps.js and check that in CLOSURE_IMPORT_SCRIPT to select Node require or nodeGlobalRequire.
1 parent d98c00f commit 53070a2

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/main/cljs/cljs/bootstrap_node.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ global.CLOSURE_IMPORT_SCRIPT = function(src, opt_sourceText) {
7373
// Sources are always expressed relative to closure's base.js, but
7474
// require() is always relative to the current source.
7575
if (opt_sourceText === undefined) {
76-
require(path.join(".", "..", src));
76+
var flags = goog.dependencies_.loadFlags[src];
77+
if (flags && flags["foreign-lib"]) {
78+
nodeGlobalRequire(path.resolve(__dirname, "..", src));
79+
} else {
80+
require(path.join(".", "..", src));
81+
}
7782
} else {
7883
eval(opt_sourceText);
7984
}

src/main/clojure/cljs/closure.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,9 @@
14461446
;; under Node.js we emit native `require`s for these
14471447
(= :nodejs (:target opts))
14481448
(filter (complement ana/node-module-dep?))))
1449-
"]);\n")))
1449+
"]"
1450+
(if (deps/-foreign? input) ", {'foreign-lib': true}")
1451+
");\n")))
14501452

14511453
(defn deps-file
14521454
"Return a deps file string for a sequence of inputs."

0 commit comments

Comments
 (0)