leiningen
leiningen copied to clipboard
Add `lein add <dependency>` command
One of the nice things about the NPM/Yarn ecosystem is that it is easy to add a dependency to your project by copy/pasting a line from the project's README which is something like:
npm install --save lodash
This will install the package and add it to the project's package.json
file. I wonder if something like this could be nice quality of life improvement for Leiningen users. As a sketch of how this could work:
lein add org.clojure/core.async
Leiningen would then look for the latest release version of the dependency, and update the user's project.clj
with the new dependency added to the :dependencies
vector. If you wanted to install the dependency to your :dev
profile you could do something like
lein add org.clojure/core.async --profile :dev
and Leiningen would add the dependency. Because a project.clj
is not pure data, it is probably tricky/impossible to handle this perfectly on 100% of existing project.clj
files. However we could still provide a good experience for the 95% (99%?) case of a standard project.clj file.
I'm not aware of any projects that exist for rewriting a project.clj, but perhaps others are aware?
The main challenges I see are:
- Being able to parse the project.clj file in such a way that you can add the dependency to the right spot in the textual file, and write the file back out again, preserving all of the other parts of the file. Something like this would be a lot easier to do if dependencies were specified in a data file, e.g.
deps.edn
. - Getting indentation right when writing back the dependency. If you were willing to apply a pretty printer to people's project.clj files then this wouldn't be too tricky, but I think that is probably a non starter.
What are people's thoughts on this? Does it seem like a useful kind of feature?