ryanmcg / lein-npm Goto Github PK
View Code? Open in Web Editor NEWManage Node dependencies for CLJS projects
Manage Node dependencies for CLJS projects
Hi,
Leiningen (2.x?) allows for dependency resolution in development using a checkouts/
directory with symlinks to other projects. This is useful for developing projects in parallel and not having to build-install-run to see updates. Checkouts are used by lein automatically when a valid link is present, even if the version in :dependencies
is different.
lein-npm appears to collect transitive node deps by directly calling Pomegranate, then looking for a jar file. This seems to bypass lein checkouts. So if a checkout dependency's :node-dependencies
changes, the downstream project won't see it, without a rebuild-install-run cycle (and the :dependencies
version being bumped).
I'm not sure how to wire up checkouts into this flow, but I hope leiningen exports enough of an API to go through it. Any thoughts on this approach?
Currently lein-npm looks inside all of the JARs on the classpath to find any project.clj's with lein-npm
dependencies specified. I'm not 100% sure of the use case for this, but I guess it's so that library writers can ensure that their dependencies are downloaded. This behaviour is a little bit counterintuitive for people (see: http://stackoverflow.com/questions/41910529/lein-npm-downloads-dependencies-of-dependencies-re-frame-template), and I've had the same thing happen to me in the past. This is hinted at in
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.
I'm not really sure what the right answer here is:
My feeling is that lein-npm would mostly be used for tooling/processing purposes, but that it is unlikely that consumers of a project that uses lein-npm would need the node modules to be downloaded themselves.
After upgrading to lein 2.8.3:
Warning: implicit hook found: lein-npm.plugin/hooks
Hooks are deprecated and will be removed in a future version.
I run into this strange issue at the moment. Whenever I point the project.cljs of my application to a SNAPSHOT version of my library, it picks up transitive dependencies without a problem. However, once I release a new version of the same library and update the dependency in my main project, lein npm doesn't recognize the npm dependency anymore. I have tried many things, but I cannot find the cause of this problem.
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
...
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!
Just wondering if line run hook should or should not generate the package.json file. I am trying to use lein-npm with node-webkit. Spawning node-webkit looks for package.json which isn't created when lein run
is run.
As a workaround I do this:
:scripts {:start "node ./bootstrap.js"}
directive under :nodejs
.lein npm start
From the README, it seems that lein-npm accesses several keys from the project file. These include:
:node-dependencies
:nodejs
and then :scripts
:npm-root
I propose looking in an alternative location, all under some map at :npm
in the leiningen project map.
:npm {:dependencies [...]
:scripts { ... }
:root :target-path}
We can deprecate the old search path, but still support it for backwards compatibility.
I'm making this an issue to get feedback from others (specifically @bodil).
Is there a way to configure lein-npm to automagically install npm dependencies when running lein
?
As stated in the "Clean code" book, there should be only one command to run the build. It would be nice if projects could include npm deps in their bootstrapping.
Hi, this might be kind of a stupid question, but I'm having a lot of trouble actually using the nodejs javascript libraries that I add in. For example, I want to use the twitter library so I add this to :npm { :dependencies } in my project.clj:
[twitter "1.7.1"]
That seems to work fine, and I can see the library being downloaded when I run lein deps
.
However, then in my core.cljs file I want to bring in this javascript library and use it:
(ns my-proj.core
(:require [twitter :as twitter]))
Problem is, I always get errors saying "this namespace cannot be found". :/
It is giving me so much trouble that I even opened this stack overflow issue. Can someone pls tell me what I'm doing wrong here? ๐ thanks!
I've been working on a ClojureScript app that uses node-webkit for its frontend, necessitating the presence of a valid package.json
at the project root. Since lein-npm refuses to run if a package.json
file is already present (presumably to avoid clobbering it with the temporary one generated from the project.clj
), I can't use lein-npm to pull in transitive npm dependencies from other ClojureScript projects using lein-npm upstream.
I'd love it if there was an option to automatically back up the contents of the existing package.json
file, do whatever is necessary with the temporary one generated by lein-npm, and then restore the contents from the backup. That way, I could use lein-npm without having to worry about doing this dance myself.
Granted, this is a pretty weird use-case, but it's something that'd definitely be helpful to me. I can always make a pull request, but I wanted to see if you'd be interested in having this behavior first.
I wouild like to be able to use lein-npm most of the time, but also have the raw package.json file when I need it
(defproject npm-error "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]]
:plugins [[lein-npm "0.6.0"]]
:npm {:dependencies [[@blueprintjs/core "*"]]
:root "resources/chrome_extension/npm"}
)
For the simple project.clj above I am seeing this wierd error
java.lang.IllegalArgumentException: No value supplied for key:
at clojure.lang.PersistentHashMap.create (PersistentHashMap.java:77)
clojure.core$hash_map.invokeStatic (core.clj:387)
clojure.core$hash_map.doInvoke (core.clj:379)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invokeStatic (core.clj:646)
clojure.core$apply.invoke (core.clj:641)
I am able to import other dependencies like react and stuff.
Also I am able to successfully install via npm install @blueprintjs/core
Is there something I am missing here ?
Hi
I am getting an error when installing a github dependency for https://github.com/nimaai/nlr-core with lein npm install
.
My project.clj
looks like this:
(defproject nlr-web-cljs "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.170" :classifier "aot"
:exclusion [org.clojure/data.json]]
[org.clojure/data.json "0.2.6" :classifier "aot"]]
:jvm-opts ^:replace ["-Xmx1g" "-server"]
:plugins [[lein-npm "0.6.1"]]
:npm {:dependencies [[source-map-support "0.3.2"]
["nimaai/nlr-core" "1.1.4"]]}
:source-paths ["src" "target/classes"]
:clean-targets ["out" "release"]
:target-path "target")
And the error I am getting:
npm ERR! addLocal Could not install /home/nimaai/src/private/nlr/nlr-web-cljs/nimaai/[email protected]
npm ERR! Linux 3.19.0-32-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v4.0.0
npm ERR! npm v2.14.2
npm ERR! path /home/nimaai/src/private/nlr/nlr-web-cljs/nimaai/[email protected]
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/home/nimaai/src/private/nlr/nlr-web-cljs/nimaai/[email protected]'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /home/nimaai/src/private/nlr/nlr-web-cljs/npm-debug.log
It's probably just a matter of the wrong format I used in project.clj
, but I didn't find any precise documentation for it in this repo, except:
;; Other types of dependencies (github, private npm, etc.) can be passed as a string
["your_username/your-module" "0.1.0"]]}
Thanks
nimaai
Hi. Can you publish new release? I am interested in 8089dce and it looks like even though 0.7.0-rc2
is in releases (https://github.com/RyanMcG/lein-npm/releases) - it is not available:
$ lein npm install
Could not find artifact lein-npm:lein-npm:jar:0.7.0-rc2 in central (https://repo1.maven.org/maven2/)
Could not find artifact lein-npm:lein-npm:jar:0.7.0-rc2 in clojars (https://repo.clojars.org/)
I added a :devDependencies section to the :package map as a vector in the same way the :dependencies are specified, and they were not generated properly. I changed the :devDependencies back to a map and it worked just fine. It seems like these should behave consistently.
When you're installing a large package like Karma, it can take a while for it to install. lein-npm currently just sits there and it's not obvious what's happening. It could be good to show some output here, though I'm not sure whether you could show the npm output or something else.
lein-npm
always returns an exit status 0
no matter which of that by npm
. This makes it impossible to define CI tasks with lein-npm
I am developing a nodejs-based CLI tool which I intend to publish on the NPM. When trying to do so, I get the following error:
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/Cellar/node/6.9.1/bin/node" "/usr/local/bin/npm" "publish"
npm ERR! node v6.9.1
npm ERR! npm v3.10.8
npm ERR! This package has been marked as private
npm ERR! Remove the 'private' field from the package.json to publish it.
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
As I understand from #7 the :private true
was included to remove NPM warnings, but this prevents me from publishing my project.
Hello guys
With this plugin npm install
is invoked when calling lein deps
. How can I add a npm prune
before npm install
? Is there a hook for that I can add in the project.clj file?
I'm sure this is incredibly simple but I added lein-npm to my project.clj and I get this:
> lein npm install
'npm' is not a task. See 'lein help'.
Tried running lein install, but still get this.
Hello again
Any chance this plugin could respect any existing package.json if there are any? This instead of creating a temporary one.
Currently when you do a direct npm install
, it sorts the dependencies by name in the package.json. Do you think you could do the same here? That would be great. Thanks
I updated my lein-npm dependency to 0.6.1, and it seems to be behaving pretty differently to 0.6.0. Example:
(defproject lein-npm-bug "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.7.0"]]
:plugins [[lein-npm "0.6.1"]]
:npm {:dependencies [[buffer-crc32 "0.2.5"]]})
โ lein-npm-bug rm -rf node_modules package.json
โ lein-npm-bug lein npm install
โ lein-npm-bug echo $?
0
โ lein-npm-bug ls
doc LICENSE package.json...
โ lein-npm-bug cat package.json
{
"dependencies" : {
"buffer-crc32" : "0.2.5"
},
"version" : "0.1.0-SNAPSHOT",
"description" : null,
"name" : "lein-npm-bug",
"private" : true
}%
โ lein-npm-bug
i.e. lein npm install
exits successfully, but doesn't run npm install
, and doesn't remove the package.json file. Running npm install
manually on the generated package file works fine. I haven't had time to delve into the details - what should I expect here?
On the latest leiningen version (2.8.1), lein-npm does not seem to pick up transitive dependencies. 2.7.1 works just fine.
My project.clj
has:
:npm {:dependencies [["material-ui" "^0.18.1"]
["react" "15.5.4"]
["react-dom" "15.5.4"]
["webpack" "^2.5.1"]]
:package {:scripts [[:dev "webpack -p"]
[:build "webpack -p --config webpack.production.config.js"]]}}
But when I run lein npm run dev
it complains:
npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/Cellar/node/5.9.0/bin/node" "/usr/local/bin/npm" "run" "dev"
npm ERR! node v6.2.2
npm ERR! npm v3.9.5
npm ERR! missing script: dev
Am I missing something?
I'm a beginner of Clojurescript.
I don't know how to import node modules.
ไฝฟ็จ FastHub ไปๆ็ Samsung SM-G9500 ๅ้
If the target folder does not exist you will get a java.io.FileNotFoundException: /package.json (No such file or directory)...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.