babashka / neil

A CLI to add common aliases and features to deps.edn-based projects
MIT License
377 stars 27 forks source link

`neil new` throws if there's no `deps.edn` file into which to add its data #241

Closed bobisageek closed 1 month ago

bobisageek commented 1 month ago

I was experimenting with making deps-new templates that are aimed at babashka. These templates don't end up with a deps.edn file for neil to add an alias to (there's a bb.edn, but bb.edn doesn't use aliases afaik).

deps-new is quite happy to process one of these templates:

$ clojure -Sdeps '{:deps {bobisageek/bb-template {:local/root "./bb-template"}}}' -Tnew create :template bobisageek/bb-template :name bbt :target-dir bbt2 :overwrite true
Creating project from bobisageek/bb-template in bbt2

Using the template from neil works, but throws after deps-new runs:

$ neil new bobisageek/bb-template bbt2 --overwrite true --local/root "./bb-template"
Creating project from bobisageek/bb-template in bbt2
----- Error --------------------------------------------------------------------
Type:     java.io.FileNotFoundException
Message:  bbt2/deps.edn (No such file or directory)
Location: /home/linuxbrew/.linuxbrew/bin/neil:236:18

----- Context ------------------------------------------------------------------
232: 
233: (defn ensure-neil-project [{:keys [dir deps-file]}]
234:   (let [deps-file (resolve-deps-file dir deps-file)
235:         _ (println "deps file:" deps-file)
236:         deps-edn (slurp deps-file)
                      ^--- bbt2/deps.edn (No such file or directory)
237:         edn (edn/read-string deps-edn)]

At first I thought, "well, bb.edn is sort of the deps-file in this case, and indeed, adding --deps-file "bb.edn" to the neil command line quells the error, but in a way, that's not an ideal outcome, because it adds the neil alias, and since bb.edn doesn't use aliases, it's a little superfluous.

The solution I had in mind is basically to swallow the exception, and if there's no deps file to which to add the alias, then :shrug: . I suppose there could also be an option to disable the call to assoc-project-meta! (which adds the neil alias), but that feels a bit "neither necessary nor sufficient" to me, because it says that a consumer needs to know that neil is going to try to add the alias (which isn't clear in neil new --help) and needs to sort of preempt the exception caused by the assumption of a deps.edn file.

borkdude commented 1 month ago

The solution I had in mind is basically to swallow the exception, and if there's no deps file to which to add the alias, then 🤷

Seems good to me