Skip to content

Commit

Permalink
Permit nodejs targets to have a preamble.
Browse files Browse the repository at this point in the history
  • Loading branch information
grzm authored and swannodette committed Feb 21, 2014
1 parent e6f0f30 commit 4b7cdd4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/clj/cljs/closure.clj
Expand Up @@ -712,11 +712,9 @@
(str (apply str (map #(slurp (io/resource %)) paths)) "\n"))

(defn make-preamble [{:keys [target preamble hashbang]}]
(if preamble
(preamble-from-paths preamble)
(if (= :nodejs target)
(str "#!" (or hashbang "/usr/bin/env node") "\n")
"")))
(str (when (= :nodejs target)
(str "#!" (or hashbang "/usr/bin/env node") "\n"))
(when preamble (preamble-from-paths preamble))))

(comment
;; add dependencies to literal js
Expand Down
19 changes: 19 additions & 0 deletions test/clj/cljs/closure_tests.clj
@@ -1,2 +1,21 @@
(ns cljs.closure-tests
(:use cljs.closure)
(:use clojure.test))

(deftest test-make-preamble
(testing "no options"
(is (= "" (make-preamble {}))))
(testing "nodejs"
(testing "with default hashbang"
(is (= "#!/usr/bin/env node\n" (make-preamble {:target :nodejs}))))
(testing "with custom hashbang"
(is (= "#!/bin/env node\n" (make-preamble {:target :nodejs
:hashbang "/bin/env node"}))))
(testing "with preamble"
(is (= "#!/usr/bin/env node\nvar preamble1 = require(\"preamble1\");\n"
(make-preamble {:target :nodejs
:preamble ["cljs/preamble1.js"]})))))
(testing "preamble"
(is (= "var preamble1 = require(\"preamble1\");var preamble2 = require(\"preamble2\");\n"
(make-preamble {:preamble ["cljs/preamble1.js"
"cljs/preamble2.js"]})))))
1 change: 1 addition & 0 deletions test/clj/cljs/preamble1.js
@@ -0,0 +1 @@
var preamble1 = require("preamble1");
1 change: 1 addition & 0 deletions test/clj/cljs/preamble2.js
@@ -0,0 +1 @@
var preamble2 = require("preamble2");

0 comments on commit 4b7cdd4

Please sign in to comment.