Skip to content

Commit a0ed8c4

Browse files
anmonteiroswannodette
authored andcommitted
CLJS-2245: Add support for using a local node_modules installation through a new :node-modules compiler flag
1 parent afe65a0 commit a0ed8c4

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ node_js:
66
- "8"
77

88
before_install:
9+
- npm install -g yarn
910
- wget https://ftp.mozilla.org/pub/firefox/nightly/latest-mozilla-central/jsshell-linux-x86_64.zip
1011
- unzip jsshell-linux-x86_64.zip -d spidermoney
1112
- sudo apt-get install -y libjavascriptcoregtk-3.0-bin

src/main/clojure/cljs/closure.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,7 +2397,7 @@
23972397
- index all the node node modules
23982398
- process the JS modules (preprocess + convert to Closure JS)
23992399
- save js-dependency-index for compilation"
2400-
[{:keys [npm-deps target] :as opts} js-sources compiler-env]
2400+
[{:keys [npm-deps node-modules target] :as opts} js-sources compiler-env]
24012401
(let [;; Find all the top-level Node packages and their files
24022402
top-level (reduce
24032403
(fn [acc m]
@@ -2411,7 +2411,7 @@
24112411
(let [opts (-> opts
24122412
(update :foreign-libs
24132413
(fn [libs]
2414-
(into (if-not (empty? npm-deps)
2414+
(into (if (or (not (empty? npm-deps)) (true? node-modules))
24152415
(index-node-modules node-required)
24162416
[])
24172417
(expand-libs libs))))

src/test/clojure/cljs/build_api_tests.clj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
(:refer-clojure :exclude [compile])
1111
(:import java.io.File)
1212
(:require [clojure.test :refer [deftest is testing]]
13+
[clojure.data.json :as json]
1314
[clojure.java.io :as io]
15+
[clojure.java.shell :as sh]
1416
[cljs.env :as env]
1517
[cljs.analyzer :as ana]
1618
[cljs.test-util :as test]
@@ -374,3 +376,29 @@
374376
(test/delete-out-files out)
375377
(build/build (build/inputs (io/file inputs "data_readers_test")) opts cenv)
376378
(is (contains? (-> @cenv ::ana/data-readers) 'test/custom-identity))))
379+
380+
(deftest test-node-modules-cljs-2245
381+
(test/delete-node-modules)
382+
(spit (io/file "package.json") (json/json-str {:dependencies {:left-pad "1.1.3"}
383+
:devDependencies {:module-deps "*"
384+
:resolve "*"
385+
:browser-resolve "*"}}))
386+
(sh/sh "yarn" "install")
387+
(let [ws (atom [])
388+
out (.getPath (io/file (test/tmp-dir) "node-modules-opt-test-out"))
389+
{:keys [inputs opts]} {:inputs (str (io/file "src" "test" "cljs_build"))
390+
:opts {:main 'node-modules-opt-test.core
391+
:output-dir out
392+
:optimizations :none
393+
:node-modules true
394+
:closure-warnings {:check-types :off}}}
395+
cenv (env/default-compiler-env opts)]
396+
(test/delete-out-files out)
397+
(ana/with-warning-handlers [(collecting-warning-handler ws)]
398+
(build/build (build/inputs (io/file inputs "node_modules_opt_test/core.cljs")) opts cenv))
399+
(is (.exists (io/file out "node_modules/left-pad/index.js")))
400+
(is (contains? (:js-module-index @cenv) "left-pad"))
401+
(is (empty? @ws)))
402+
(.delete (io/file "package.json"))
403+
(.delete (io/file "yarn.lock"))
404+
(test/delete-node-modules))

0 commit comments

Comments
 (0)