Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
make npm deps tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed May 6, 2018
1 parent 8a5b001 commit 0419276
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 4 additions & 1 deletion build.boot
Expand Up @@ -129,12 +129,14 @@

(deftask sift-cljs-resources []
(comp
(sift :add-jar
{'org.clojure/clojurescript #"\.class$"}
:invert true)
(sift :add-jar
{'org.clojure/clojure #"^clojure[\\\/]template\.clj"
'org.clojure/google-closure-library #"^goog[\\\/].*(?<!_test)\.js$"
'org.clojure/google-closure-library-third-party #"^goog[\\\/].*(?<!_test)\.js$"
'org.clojure/tools.reader #"^cljs.*clj$"
'org.clojure/clojurescript #"(cljs|clojure|process)[\\\/].*(\.clj.?|\.js|\.cache\.json|\.aot\.edn|\.aot\.js\.map)$"
'org.clojure/test.check #""}
:move {#"^main.out[\\\/]((cljs|clojure|cognitect|lumo|lazy_map|fipp|process).*)" "$1"})
(sift :include #{#"^main.js" #"^bundle.js" #"^cljs(?!\.js)" #"core\$macros"
Expand All @@ -161,6 +163,7 @@
:dump-core false
:static-fns true
:optimize-constants false
:npm-deps false
:verbose true
:closure-defines {'cljs.core/*target* "nodejs"
'lumo.core/*lumo-version* lumo-version}
Expand Down
4 changes: 3 additions & 1 deletion src/cljs/bundled/lumo/closure.cljs
Expand Up @@ -2418,7 +2418,9 @@
(binding [comp/*recompiled* (when-not (false? (:recompile-dependents opts))
(atom #{}))
ana/*checked-arrays* checked-arrays
lana/parse-ns (memoize lana/parse-ns)
;; TODO: investigate why this causes npm deps string requires tests
;; to fail. Disabled for now.
;; lana/parse-ns (memoize lana/parse-ns)
ana/*cljs-static-fns* static-fns?
ana/*fn-invoke-direct* (or (and static-fns?
(:fn-invoke-direct opts))
Expand Down
9 changes: 8 additions & 1 deletion src/cljs/bundled/lumo/util.cljs
Expand Up @@ -188,8 +188,15 @@
(let [user-dir (path/join (js/process.cwd) path/sep)
s (normalize-path s)]
(string/replace s user-dir "")))]
(if (string? x)
(cond
(string? x)
(strip-user-dir (path/resolve x))

(resource? x)
;; TODO: check if we need path/resolve
(strip-user-dir (.-src x))

:else
(throw (js/Error. "What to do with JARs in lumo.util/relative-name?"))
#_(let [f (URLDecoder/decode (.getFile x))]
(if (string/includes? f ".jar!/")
Expand Down
8 changes: 4 additions & 4 deletions src/test/lumo/lumo/build_api_tests.cljs
Expand Up @@ -231,8 +231,7 @@
;; (build/build (build/inputs inputs) opts)
;; (is (not (nil? (re-find #"foreignA[\s\S]+foreignB" (slurp (io/file out "foo.js"))))))))))

;; This is failing: https://github.com/anmonteiro/lumo/issues/392
#_(deftest test-npm-deps-simple
(deftest test-npm-deps-simple
(let [out (path/join (test/tmp-dir) "npm-deps-simple-test-out")
{:keys [inputs opts]} {:inputs (path/join "src" "test" "cljs_build")
:opts {:main 'npm-deps-test.core
Expand All @@ -253,7 +252,7 @@
(is (fs/existsSync (path/join out "node_modules/left-pad/index.js")))
(is (contains? (:js-module-index @cenv) "left-pad"))))

#_(deftest test-npm-deps
(deftest test-npm-deps
(let [cenv (env/default-compiler-env)
out (path/join (test/tmp-dir) "npm-deps-test-out")
{:keys [inputs opts]} {:inputs (path/join "src" "test" "cljs_build")
Expand All @@ -274,7 +273,8 @@
(build/build (build/inputs (path/join inputs "npm_deps_test/string_requires.cljs")) opts cenv)
(is (fs/existsSync (path/join out "node_modules/react/react.js")))
(is (contains? (:js-module-index @cenv) "react"))
(is (contains? (:js-module-index @cenv) "react-dom/server")))
(is (contains? (:js-module-index @cenv) "react-dom/server"))
(is (not (nil? (re-find #"\.\.[\\/]node_modules[\\/]react-dom[\\/]server\.js" (slurp (path/join out "cljs_deps.js")))))))

(testing "builds with string requires are idempotent"
(build/build (build/inputs (path/join inputs "npm_deps_test/string_requires.cljs")) opts cenv)
Expand Down

0 comments on commit 0419276

Please sign in to comment.