-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Produce a warning when acting as plugin but no matching project depen…
…dency Fixes #45
- Loading branch information
Showing
3 changed files
with
32 additions
and
9 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
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 |
---|---|---|
@@ -1,19 +1,33 @@ | ||
(ns pretty.plugin | ||
"A plugin for Leiningen that automatically enables pretty printing." | ||
{:added "0.1.19"} | ||
(:require [io.aviso.repl :as repl])) | ||
(:require [io.aviso.repl :as repl] | ||
[leiningen.core.main :as main])) | ||
|
||
(defn hooks | ||
"Enables pretty printing of exceptions within Leiningen. This is evaluated in the Leinigen classpath, not the project's | ||
(if any)." | ||
[] | ||
(repl/install-pretty-exceptions)) | ||
|
||
|
||
(def ^:private warning (atom true)) | ||
|
||
(defn middleware | ||
"Automatically adds the :injections that enable Pretty." | ||
[project] | ||
(update-in project [:injections] | ||
(fnil into []) | ||
['(require 'io.aviso.repl) | ||
'(io.aviso.repl/install-pretty-exceptions)])) | ||
(if (contains? (->> project | ||
:dependencies | ||
(map first) | ||
set) | ||
'io.aviso/pretty) | ||
(update-in project [:injections] | ||
(fnil into []) | ||
['(require 'io.aviso.repl) | ||
'(io.aviso.repl/install-pretty-exceptions)]) | ||
(do | ||
;; Ugly! But necessary since middleware gets invoked more than once for some unknown reason. | ||
(when (compare-and-set! warning true false) | ||
(main/warn "Unable to enable pretty exception reporting, as io.aviso/pretty is not a project dependency.")) | ||
project))) | ||
|