cljsjs / boot-cljsjs

Helper tasks to aid the packaging of JS dependencies for Clojurescript projects
66 stars 22 forks source link

npm task #39

Closed Deraen closed 6 years ago

Deraen commented 8 years ago

From https://github.com/cljsjs/packages/issues/396

A common use case starts to be quite evident:

(deftask build []
  (let [tmp (boot/tmp-dir!)]
    (with-pre-wrap
      fileset
      (doseq [f (boot/input-files fileset)]
        (let [target (io/file tmp (tmpd/path f))]
          (io/make-parents target)
          (io/copy (tmpd/file f) target)))
      (io/copy
       (io/file tmp "webpack.config.js")
       (io/file tmp +lib-folder+ "webpack-cljsjs.config.js"))
      (binding [*sh-dir* (str (io/file tmp +lib-folder+))]
        ((sh "npm" "install"))
        ((sh "npm" "install" "webpack"))
        ((sh "npm" "run" "build"))
        ((sh "./node_modules/.bin/webpack" "--config" "webpack-cljsjs.config.js")))
      (-> fileset (boot/add-resource tmp) boot/commit!))))

We can parametrizize this like this:

(npm :import-files {"webpack-cljsjs.config.js" (str +lib-folder+ "webpack-cljsjs.config.js"}
     :commands [["npm" "install"]
                ["npm" "install" "webpack"]]
                ["npm" "run" "build"]]
                ["./node_modules/.bin/webpack" "--config" "webpack-cljsjs.config.js"]])

Where import-files is map of path in fileset to path in working dir for npm.

burn2delete commented 8 years ago

https://github.com/degree9/boot-npm Could be extended to support this, current options are limited but this was the direction I had originally planned for the task.

Deraen commented 8 years ago

Looking at it. The implementation code (without task options etc.) in boot-npm + boot-exec is only ~40 lines. Currently it has a few options we wouldn't need here and it is missing probably some others. I will probably prefer to implement this completely here as it will be easier for me to maintain.

PS. cache key use looks interesting!

Have you tested how it works if you remove some dependencies? I think one needs to run npm prune to remove removed packages from existing node_modules dir.

burn2delete commented 8 years ago

I have not tested that functionality specifically. I have just been deleting the cache folder and letting the task recreate it as needed. That is probably something which could be easily added tho. Each project gets its own cache folder so this is identical to having node_modules folder in project dir except it is hidden and managed by the boot task.

Feel free to use any of the code you like all MIT license.

Deraen commented 8 years ago

@flyboarder This is very low on my todo list as I hope this will not be needed in a few months time. If/when we get proper Closure Module Processing support running Webpack will be unncessary as we can directly consume CommonJS/ES6 etc. modules.

First issue in getting module processing workin is http://dev.clojure.org/jira/browse/CLJS-1762

Deraen commented 6 years ago

https://github.com/cljsjs/boot-cljsjs/commit/44075314ad9d8ee353b74182d4a81eb88db14677