Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Merge branch 'npm-root'

  • Loading branch information...
commit c07c0c4c68918e4ef392bcd2ec6682d28bb9139d 2 parents ce1863e + 63ba7c1
@ninjudd authored
Showing with 30 additions and 6 deletions.
  1. +17 −0
  2. +13 −6 src/leiningen/npm.clj
@@ -65,6 +65,23 @@ If `:main` is a string that refers to a file that exists and ends with
install` if necessary. Any command line arguments following `lein run`
will be passed through to the Node process.
+## Changing the directory used
+npm does not allow you to put stuff anywhere besides `node_modules`, even
+if that name is [against your religion](,
+however, you can change the root used by lein-npm to be something other than
+your project root like this:
+:npm-root "resources/public/js"
+Or you can use a keyword to look the path up in your project map:
+:npm-root :target-path
## License
Copyright 2012 Bodil Stokke and Hoang Minh Thang
19 src/leiningen/npm.clj
@@ -9,9 +9,16 @@
+(defn- root [project]
+ (if-let [root (project :npm-root)]
+ (if (keyword? root)
+ (project root) ;; e.g. support using :target-path
+ root)
+ (project :root)))
(defn- json-file
[filename project]
- (io/file (project :root) filename))
+ (io/file (root project) filename))
(defn- locate-npm
@@ -35,7 +42,7 @@
(defn- invoke
[project & args]
- (let [return-code (exec (project :root) (cons "npm" args))]
+ (let [return-code (exec (root project) (cons "npm" args))]
(when (> return-code 0)
(main/exit return-code))))
@@ -72,10 +79,10 @@
(finally (remove-json-file ~filename ~project))))
(defn npm-debug
- [project]
- (with-json-file "package.json" (project->package project) project
+ [project filename]
+ (with-json-file filename (project->package project) project
(println "lein-npm generated package.json:\n")
- (println (slurp "package.json"))))
+ (println (slurp (json-file filename project)))))
(defn npm
"Invoke the NPM package manager."
@@ -87,7 +94,7 @@
(environmental-consistency project "package.json")
(= ["pprint"] args)
- (npm-debug project)
+ (npm-debug project "package.json")
(with-json-file "package.json" (project->package project) project
(apply invoke project args)))))
Please sign in to comment.
Something went wrong with that request. Please try again.