Code Monkey home page Code Monkey logo

lein2deps's Introduction

lein2deps

A leiningen project.clj to Clojure CLI deps.edn converter.

Usage

With babashka:

bb -Sdeps '{:deps {io.github.borkdude/lein2deps {:git/sha "..."}}}' \
   -m lein2deps.api --print --write-file deps.edn

With bbin:

bbin install https://raw.githubusercontent.com/borkdude/tools/main/lein2deps.clj
lein2deps --print --write-file deps.edn

With Clojure:

clj -Sdeps '{:deps {io.github.borkdude/lein2deps {:git/sha "..."}}}' \
    -M -m lein2deps.api --print --write-file deps.edn

With Clojure CLI Tools:

clojure -Ttools install-latest :lib io.github.borkdude/lein2deps :as lein2deps

clojure -Tlein2deps lein2deps :print true :write-file "deps.edn"

Java compilation

This tool respects :java-source-paths in project.clj and adds a :deps/prep-lib entry to your deps.edn so users of your project will have to execute:

clj -X:deps prep

to compile Java sources before being able to use your project.

For some reason this doesn't work from inside the project. To compile Java locally:

clojure -X:lein2deps compile-java

Lein plugin

You can use the leiningen plugin to automatically synchronize your project.clj to a deps.edn.

Add:

:plugins [[io.github.borkdude/lein-lein2deps "0.1.0"]]

to your project.clj and then run:

lein lein2deps --write-file deps.edn --print false

To run the plugin on any invocation of lein, add it to :prep-tasks:

(defproject my-project "0.1.0"
  :plugins [[io.github.borkdude/lein-lein2deps "0.1.0"]]
  :dependencies [[org.clojure/clojure "1.11.1"]]
  :prep-tasks [["lein2deps" "--write-file" "deps.edn" "--print" "false"]])

Test runner

Check out neil for easily adding a test runner to deps.edn.

How to proceed

If you are new to deps.edn, check out this blog article on how to get started quickly.

License

Copyright (c) 2022 Michiel Borkent.

Licensed under MIT, see LICENSE

lein2deps's People

Contributors

borkdude avatar dakra avatar eerohele avatar jeroenvandijk avatar vedang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lein2deps's Issues

add support for Leiningen's dependency scopes

Hi,

As far as I can tell, this tool doesn't support Leiningen's dependency scopes, eg.

[xxx "1.0.0" :scope "provided"]

As per discussion at ClojureVerse this could/should be done by converting these scopes to aliases with extra-deps/override-deps.

Parsing project.clj file fails with the error: Use the `:fn` option

When I try to run the lein2deps script on a project, the following error gets thrown:

❯ bb -Sdeps '{:deps {io.github.borkdude/lein2deps {:git/sha "4f6d4a0140ddea10c5ac28cc24b49643660f42f6"}}}' \
      -m lein2deps.api --print --write-file deps.edn
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Function literal not allowed. Use the `:fn` option
Data:     {:type :edamame/error, nil 30}
Location: .../.gitlibs/libs/io.github.borkdude/lein2deps/4f6d4a0140ddea10c5ac28cc24b49643660f42f6/src/lein2deps/internal.clj:23:63

----- Context ------------------------------------------------------------------
19:              :regex true}
20:         form (first (take-while #(or
21:                                   (and (seq? %)
22:                                        (= 'defproject (first %)))
23:                                   (= ::e/eof %)) (repeatedly #(e/parse-next parser cfg))))
                                                                  ^--- Function literal not allowed. Use the `:fn` option
24:         project-clj-edn form]
25:     (apply hash-map (drop 3 project-clj-edn))))
26:
27: (defn qualify-dep-name [d]
28:   (if (simple-symbol? d)

----- Stack trace --------------------------------------------------------------

The example project I was working with was https://github.com/clj-commons/durable-queue/

Add repositories from project.clj to deps.edn

I'm not really familiar with leinigen so not sure if :mvn/repos in deps.edn is the same as :repositories in project.clj.

E.g. the :repositories key like here could then end up in deps.edn like:

:mvn/repos {"confluent" {:url "https://packages.confluent.io/maven/"}} ?

Maintain order of original deps

I saw in a project that the deps order is shuffled (deps.edn vs project.clj). Do you agree it make sense to maintain the order?

I understand the generated deps.edn file is a compile artifact and should not be used as reference, but it is nice if you open it and the order somewhat makes sense. Also better if you want to migrate from lein to deps.edn at some point. Another argument would be smaller git diffs.

I think introducing an ordered hash-map instead of a normal hash-map should fix this, but I can experiment with this if you agree you want this change.

Exception with regex in project.clj

Creating a deps.edn for jackdaw works with --eval
but raises an exception without.

----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Regex not allowed. Use the `:regex` option
Data:     {:type :edamame/error, nil 41}
Location: /home/daniel/clojure/lein2deps/src/lein2deps/internal.clj:21:63

----- Context ------------------------------------------------------------------
17:         cfg {:read-eval identity}
18:         form (first (take-while #(or
19:                                   (and (seq? %)
20:                                        (= 'defproject (first %)))
21:                                   (= ::e/eof %)) (repeatedly #(e/parse-next parser cfg))))
                                                                  ^--- Regex not allowed. Use the `:regex` option
22:         project-clj-edn form]
23:     (apply hash-map (drop 3 project-clj-edn))))
24: 
25: (defn qualify-dep-name [d]
26:   (if (simple-symbol? d)

----- Stack trace --------------------------------------------------------------
edamame.impl.parser/throw-reader       - <built-in>
edamame.impl.parser/parse-sharp        - <built-in>
edamame.impl.parser/dispatch           - <built-in>
edamame.impl.parser/parse-next         - <built-in>
edamame.impl.parser/parse-to-delimiter - <built-in>
... (run with --debug to see elided elements)
lein2deps.api/lein2deps                - /home/daniel/clojure/lein2deps/src/lein2deps/api.clj:28:23
lein2deps.api/lein2deps                - /home/daniel/clojure/lein2deps/src/lein2deps/api.clj:11:1
lein2deps.api                          - /home/daniel/clojure/lein2deps/src/lein2deps/api.clj:63:11
clojure.core/apply                     - <built-in>
user                                   - <expr>:1:38

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.