Skip to content

Commit

Permalink
fix :npm-module release output
Browse files Browse the repository at this point in the history
  • Loading branch information
thheller committed Jan 9, 2023
1 parent 2b91854 commit db9bf83
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
34 changes: 19 additions & 15 deletions src/main/shadow/build/closure.clj
Expand Up @@ -900,6 +900,7 @@
:js-module (get js-mods resource-id)
:sources [resource-id]}))
(into [{:module-id output/goog-base-id
:goog-mod true
:output-name "cljs_env.js"
:js-module goog-mod
:sources (->> goog-sources
Expand Down Expand Up @@ -1267,25 +1268,28 @@
;; FIXME: could do this in compile-modules
[{::keys [modules dead-modules dead-sources] :as state}]
(let [env-prepend
"var window=global;var $CLJS=require(\"./cljs_env\");"]
"var window=global;var $CLJS=require(\"./cljs_env.js\");"]

(update state ::modules
(fn [modules]
(->> modules
(map (fn [{:keys [name js-module] :as mod}]
(let [requires
(->> (get-js-module-requires state js-module)
(map #(.getName %))
(distinct)
(map #(str "require(\"./" % "\");"))
(str/join ""))]

(-> mod
;; the npm prepend must be one line, will mess up source lines otherwise
(update :prepend #(str env-prepend requires #_"$.module=module;\n" "\n" %))
;; the set this to null so it doesn't leak to other modules
;; (update :append str "$.module=null;")
))))
(map (fn [{:keys [goog-mod js-module] :as mod}]
(if goog-mod
(update mod :prepend #(str "var $CLJS = module.exports = {};\n" %))
(let [requires
(->> (get-js-module-requires state js-module)
(map #(.getName %))
(remove #{"cljs_env.js"})
(distinct)
(map #(str "require(\"./" % "\");"))
(str/join ""))]

(-> mod
;; the npm prepend must be one line, will mess up source lines otherwise
(update :prepend #(str env-prepend requires #_"$.module=module;\n" "\n" %))
;; the set this to null so it doesn't leak to other modules
;; (update :append str "$.module=null;")
)))))
(into []))))))

(defn- set-check-only
Expand Down
8 changes: 0 additions & 8 deletions src/main/shadow/build/output.clj
Expand Up @@ -398,14 +398,6 @@
(when-not (seq modules)
(throw (ex-info "flush before optimize?" {})))

(when (= :js (get-in state [:build-options :module-format]))
(let [env-file
(data/output-file state "cljs_env.js")]

(io/make-parents env-file)
(spit env-file
(str "module.exports = {};\n"))))

(util/with-logged-time
[state {:type :flush-optimized}]

Expand Down

0 comments on commit db9bf83

Please sign in to comment.