-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show a compile-time warning when required under non-dev builds (#37)
The solution with devtools.optional namespace didn't work in scenario when cljs-devtools was required as a library via maven dependency. In that case we cannot (goog/require "devtools.optional") because the \ file is not compiled/present. There does not seem to be a way how to conditionally require something based on compiler options. So I decided just emit a compile-time warning to warn users and leave it as is. People should not use cljs-devtools in :advanced mode. And ideally they should include it via :preloads which has no effect in :advanced mode.
- Loading branch information
Showing
7 changed files
with
64 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
(ns devtools.compiler | ||
(:require [cljs.env] | ||
[devtools.prefs :refer [get-pref]])) | ||
|
||
(def preloads-url "https://github.com/binaryage/cljs-devtools/blob/master/docs/installation.md#install-it-via-preloads") | ||
(def issue-37-url "https://github.com/binaryage/cljs-devtools/issues/37") | ||
|
||
(defn ^:dynamic make-optimizations-warning-msg [mode] | ||
(str "WARNING: You required cljs-devtools library in a project which is currently compiled with :optimizations " mode ".\n" | ||
" You should remove this library from non-dev builds completely because it impedes dead code elimination.\n" | ||
" The best way is to use :preloads compiler option: " preloads-url ".\n" | ||
" To silence this warning please set :silence-optimizations-warning config key to true.\n" | ||
" More details: " issue-37-url ".")) | ||
|
||
(defn get-compiler-optimizations-mode [] | ||
(or (if cljs.env/*compiler* | ||
(get-in @cljs.env/*compiler* [:options :optimizations])) | ||
:none)) | ||
|
||
(defn compiler-in-dev-mode? [] | ||
(= (get-compiler-optimizations-mode) :none)) | ||
|
||
(defn emit-compiler-warning! [msg] | ||
(binding [*out* *err*] | ||
(println msg))) | ||
|
||
(def emit-compiler-warning-once! (memoize emit-compiler-warning!)) | ||
|
||
(defn warn-if-optimizations! [] | ||
(if-not (compiler-in-dev-mode?) | ||
(emit-compiler-warning-once! (make-optimizations-warning-msg (get-compiler-optimizations-mode))))) | ||
|
||
(defn silence-optimizations-warnings? [] | ||
(true? (get-pref :silence-optimizations-warning))) | ||
|
||
(defmacro check-compiler-options! [] | ||
(if-not (silence-optimizations-warnings?) | ||
(warn-if-optimizations!)) | ||
nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters