-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clean-ns: Introduce ^:keep metadata on libspecs #189
Conversation
This allows marking up required namespaces that should not be cleaned by clean-ns. This is useful to require namespaces only so they get loaded for side-effects. It can also be used in (ns user) to make functions available for the REPL. Example (ns user (:require [com.stuartsierra.component :as component] ^:keep [reloaded.repl :refer [system init start stop go reset]]])
parse/read-ns-decl) | ||
meta? (second ns-decl) | ||
ns-name (if (symbol? meta?) meta? (first (nnext ns-decl))) | ||
shorthand-meta? (-> (java.util.regex.Pattern/compile (str "\\^:([^\\s]+)\\s" ns-name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code was too eager, it would transform
(ns user (:require ^:keep [,,,]))
into
(ns ^:keep user)
I'd prefer
Agree with you on this. We can always revisit it later.
I don't think that's needed, when you mark it as
We do prefix re-writing today so we need at least partial support. (ns my-ns
(:require
[foo.bar :as bar]
^:refactor-nrepl/keep
[foo.baz :as baz])) With prefix rewriting this would look like: (ns my-ns
(:require
[foo
[bar :as bar]
^:refactor-nrepl/keep
[baz :as baz]])) But I don't think we need to worry about: (ns my-ns
(:require
^:refactor-nrepl/keep
[foo
[bar :as bar]
[baz :as baz]])) If it's easier to just support both, then that's fine I think, but I wouldn't bother adding complexity to support this final variant. |
That makes sense. I was thinking it could be a convention that other tools can also pick up, but that's probably not too likely anyway. |
Ping @plexus :) |
Hey, sorry for letting this sit. I've been completely swamped with other stuff, and given that it's still a bit of work to do this feature properly I won't get to it very soon. |
I'm closing this PR due to no recent activity. Feel free to re-open it if you ever come back to it. |
I would find this really useful. A common challenge for me with
The require is needed for the runtime generation of |
Here is the solution that was chosen for clj-kondo, which I think is a very wise choice. Any |
This allows marking up required namespaces that should not be cleaned by clean-ns.
This is useful to require namespaces only so they get loaded for side-effects. It can also be used in
(ns user)
to make functions available for the REPL.Example
This PR is not ready yet, I'm just at the point where I got it to work, and I'd appreciate feedback.
Questions:
^:keep
the best key to use? (bikeshedding time!):require
, does it make sense to also have it for:import
or:use
. (Probably not since you don't usually:import
for side effects, and:use
is deprecated, but maybe there's an argument to be made).:refer
macro?Todo for me:
Before submitting a PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):
lein do clean, test
)./build.sh install
-- takes a long time)Thanks!