Skip to content
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

resolve-in-jar-dep is a wee bit brittle #14

Open
RyanMcG opened this issue Aug 14, 2014 · 29 comments
Open

resolve-in-jar-dep is a wee bit brittle #14

RyanMcG opened this issue Aug 14, 2014 · 29 comments

Comments

@RyanMcG
Copy link
Owner

RyanMcG commented Aug 14, 2014

I received the following error message when running lein deps.

java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to clojure.lang.Named
 at clojure.core$name.invoke (core.clj:1518)
    leiningen.npm.deps$resolve_in_jar_dep.invoke (deps.clj:51)
    clojure.lang.AFn.applyToHelper (AFn.java:160)
    clojure.lang.AFn.applyTo (AFn.java:144)
    clojure.core$apply.invoke (core.clj:628)
    clojure.core$partial$fn__4230.doInvoke (core.clj:2470)
    clojure.lang.RestFn.invoke (RestFn.java:408)
    clojure.core$keep$fn__6402.invoke (core.clj:6713)
    clojure.lang.LazySeq.sval (LazySeq.java:40)
    clojure.lang.LazySeq.seq (LazySeq.java:56)
    clojure.lang.RT.seq (RT.java:484)
    clojure.core$seq.invoke (core.clj:133)
    clojure.core.protocols$seq_reduce.invoke (protocols.clj:26)
    clojure.core.protocols/fn (protocols.clj:53)
    clojure.core.protocols$fn__6031$G__6026__6044.invoke (protocols.clj:13)
    clojure.core$reduce.invoke (core.clj:6287)
    leiningen.npm.deps$resolve_in_jar_deps.invoke (deps.clj:63)
    leiningen.npm.deps$resolve_node_deps.invoke (deps.clj:82)
(let [jar-project-entry (.getEntry jar-file "project.clj")
      jar-project-src (when jar-project-entry
                        (read-string                                        ; 1
                          (slurp                                            ;
                            (.getInputStream jar-file jar-project-entry)))) ;
      jar-project-map (when jar-project-src
                        (->> jar-project-src (drop 3) (apply hash-map)))
      jar-project-name (when jar-project-src
                         (name (second jar-project-src))) ; 2
      ...
  1. This may not actually get a form with defproject being invoked in it. I've done this before:
(read-string (str \( a-string-of-clojure-code \)))

Of course, this will change result in a list of forms so some searching needs to take place to find the defproject usage.
2. Here we assume, we've found a totally normal defproject, we call second and name to get a string representing the name of the project. Unfortunately, for a project.clj like reply's this fails and breaks the whole thing.

(let [dev-deps '[[speclj "2.7.2"]
             [classlojure "0.6.6"]]]

(defproject reply "0.3.5-SNAPSHOT" ...

I am not convinced that pulling node dependencies of maven dependencies is the right thing to do. I'd like to get a better understanding of why this is done. Regardless, I think and ideal solution would put the dependencies in the pom and interpret them from there instead of trying to read project.clj.

A good, short term solution would be to provide better error handling so that when a project.clj is improperly interpreted, it is simply ignored. Another, would be to surface an option which disables gathering node-dependencies on sub projects. I think there are cases where it is undesired.

I would be happy to submit a pull-request once we know what might work best!

@RyanMcG
Copy link
Owner Author

RyanMcG commented Aug 19, 2014

I'll post a PR with a fix for the assumptions made about the forms in project.clj soon, it's already done, it's just on my personal computer.

@RyanMcG
Copy link
Owner Author

RyanMcG commented Sep 14, 2014

ping

@radhikalism
Copy link
Contributor

As a sidenote, leiningen 2.4 begins to deal with a similar problem, which supposes a general solution for project map processing that might apply to lein-npm.

The newly introduced 'release' task involves reflecting on the contents of project.clj, and Phil H notes that a general 'change' task for reading and rewriting project maps might eventually be useful.
http://librelist.com/browser//leiningen/2014/5/1/release-task/

If that ever materializes as a robust API in leiningen, it could be reused by plugins that extract or inject values like lein-npm does. So I don't know if transmitting data via the pom file is the best course of action.

+1 for this PR.

@RyanMcG
Copy link
Owner Author

RyanMcG commented Sep 14, 2014

@arbscht I may be mis-interpretting you or the linked post to the leiningen mailinglist. But this seems to be referring to leiningen tasks which rewrite project.clj. Though I think this could be useful for leningen or lein-npm I am not sure it is solving the problem I am bringing up here.

Our issue is with reliable reading a project definition of a dependency. This is because (defproject ...) is code. Through the beauty of LISP we are able to read this trivially, but not necessarily perfectly (we've the PR I've already posted is a good example of how making assumptions about the structure of project.clj can bite us). I do not think we have to wait for some yet-to-be-implemented change task. Leiningen already provides functions for reading project.clj files. I feel like we should probably use one, if we can't read pom files directly. (Maybe this will be my next PR)

I was originally under the impression that just reading pom files would be a significant performance improvement, but I don't think that is the case anymore.

@radhikalism
Copy link
Contributor

@RyanMcG You're right, of course. I just mean that working with project.clj and not pom files is likely to be a better long-term direction, as this is where all the action happens in a leiningen context (including unrelated rewrites, eventually). The pom file should probably remain an implementation detail for leiningen itself to manage, even for lein plugins, rather than making it a leaky abstraction.

Using leiningen's read for project files sounds like an excellent idea — if it is now in a workable state. I forget now why it wasn't sufficient when I last looked at it, but there have been many changes to that namespace since then.

@RyanMcG
Copy link
Owner Author

RyanMcG commented Sep 15, 2014

@arbscht Alright, I agree. We should avoid relying on pom and go the read route, if it works.

@bodil thoughts on #15?

@bodil
Copy link
Contributor

bodil commented Sep 21, 2014

I think this project needs a maintainer (I'm not doing Clojure anymore, so not able to support it). Anyone interested?

@RyanMcG
Copy link
Owner Author

RyanMcG commented Sep 21, 2014

I am. Full disclosure, I might ask for some non-clojure-specific library maintenance help though.

I'd be happy to co-maintain with someone else too. We could have a cljs-npm organization or something.

@bodil
Copy link
Contributor

bodil commented Sep 21, 2014

OK, how about I just transfer it to you, then you're free to create an organisation if more people want to pitch in?

@radhikalism
Copy link
Contributor

Excellent, thanks @RyanMcG!

(I'm very much interested in this project but cannot help as a maintainer at this time. Happy to contribute and support otherwise.)

@RyanMcG
Copy link
Owner Author

RyanMcG commented Sep 22, 2014

@bodil transfer away!

@bodil
Copy link
Contributor

bodil commented Sep 22, 2014

Transfer in progress!

@bodil
Copy link
Contributor

bodil commented Sep 22, 2014

Oh, actually, @RyanMcG, you'll need to delete your fork first, getting "ryanmcg/lein-npm already exists" sort of errors.

@RyanMcG
Copy link
Owner Author

RyanMcG commented Sep 22, 2014

@bodil done!

Well, I renamed my current fork at least, but that should fix it.

@bodil
Copy link
Contributor

bodil commented Sep 23, 2014

Apparently not.

"RyanMcG already has a repository in the bodil/lein-npm network"

@RyanMcG
Copy link
Owner Author

RyanMcG commented Sep 24, 2014

OK, deleted. Take 3. Sorry about that. https://github.com/RyanMcG/lein-npm 404s now instead of redirecting

@bodil
Copy link
Contributor

bodil commented Sep 24, 2014

Seems to have worked. Enjoy the repo. :)

@RyanMcG
Copy link
Owner Author

RyanMcG commented Sep 24, 2014

Ha, thanks.

@RyanMcG
Copy link
Owner Author

RyanMcG commented Sep 24, 2014

Well, I am going to merge in #15 then.

@olivergeorge
Copy link

I think this bug renders lein-npm incompatible with chestnut.

@RyanMcG
Copy link
Owner Author

RyanMcG commented Dec 26, 2014

@olivergeorge can you elaborate? Have you tried current master?

@olivergeorge
Copy link

Hi Ryan

Just tried "0.5.0-SNAPSHOT" and that works.

Test was:

  • lein new chestnut npmtest
  • add npm plugin and node-dependenies to project.clj based on readme

  • lein npm install
  • See error with 0.4.0
  • update npm plugin reference to 0.5.0-SNAPSHOT

  • lein npm install
  • See install work

cheers, Oliver

@RyanMcG
Copy link
Owner Author

RyanMcG commented Dec 26, 2014

OK, so it sounds like I should cut a release. I'll try to do that in the
next couple of days.
On Dec 26, 2014 4:04 PM, "Oliver George" [email protected] wrote:

Hi Ryan

Just tried "0.5.0-SNAPSHOT" and that works.

Test was:

  • lein new chestnut npmtest
  • add npm plugin and node-dependenies to project.clj based on readme

  • lein npm install
  • See error with 0.4.0
  • update npm plugin reference to 0.5.0-SNAPSHOT

  • lein npm install
  • See install work

cheers, Oliver


Reply to this email directly or view it on GitHub
#14 (comment).

@olivergeorge
Copy link

Brilliant, thanks.

On 27 December 2014 at 08:39, Ryan McGowan [email protected] wrote:

OK, so it sounds like I should cut a release. I'll try to do that in the
next couple of days.
On Dec 26, 2014 4:04 PM, "Oliver George" [email protected]
wrote:

Hi Ryan

Just tried "0.5.0-SNAPSHOT" and that works.

Test was:

  • lein new chestnut npmtest
  • add npm plugin and node-dependenies to project.clj based on readme

  • lein npm install
  • See error with 0.4.0
  • update npm plugin reference to 0.5.0-SNAPSHOT

  • lein npm install
  • See install work

cheers, Oliver


Reply to this email directly or view it on GitHub
#14 (comment).


Reply to this email directly or view it on GitHub
#14 (comment).

@RyanMcG
Copy link
Owner Author

RyanMcG commented Dec 27, 2014

@bodil I'm trying to cut a release but I am getting an "Access denied" error.

Can you add me to the lein-npm group on clojars?
https://clojars.org/groups/lein-npm

Thanks 😄

@bodil
Copy link
Contributor

bodil commented Dec 28, 2014

Oops, sorry, was sure I already had.

@RyanMcG
Copy link
Owner Author

RyanMcG commented Dec 28, 2014

@bodil that did it!
@olivergeorge release cut!

@olivergeorge
Copy link

Thanks Ryan.

Seems like a interesting time for CLJS with JS dependencies.

What are you making of the JS build conversations happening at the moment?
David's raised a ticket about tweaking :foreign-libs and boot-cljsjs was
announced recently. Sounds like Google Closure is working towards AMD
support too. Related discussions happening on the mailing list.

On 29 December 2014 at 07:58, Ryan McGowan [email protected] wrote:

@bodil https://github.com/bodil that did it!
@olivergeorge https://github.com/olivergeorge release cut!


Reply to this email directly or view it on GitHub
#14 (comment).

@RyanMcG
Copy link
Owner Author

RyanMcG commented Jan 8, 2015

No problem.

Honestly, I haven't looked into much. Any chance you can link me that ticket?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants