jacobobryant / platypub

A publishing platform built with Biff
MIT License
65 stars 13 forks source link

Publish can't "zip-it-and-ship-it" #3

Closed jeffp42ker closed 2 years ago

jeffp42ker commented 2 years ago

I'm able to successfully "Export" and "Preview" a site as configured, yet when clicking "Publish", after a long pause I'm seeing "Preparing functions..." then after another long pause while npm runs, I'm getting this exception:

Done in 3649ms.
"Elapsed time: 24667.785 msecs"

Preparing functions...
"...AFTER npm install"
[qtp772154516-23] ERROR com.biffweb.impl.middleware - Exception while handling request
java.io.IOException: Cannot run program "zip-it-and-ship-it" (in directory "storage/deploys/4b8f7ba1-cc01-4b87-9a71-23389182e111"): error=2, No such file or directory
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
        at java.base/java.lang.Runtime.exec(Runtime.java:615)
        at clojure.java.shell$sh.invokeStatic(shell.clj:113)
        at clojure.java.shell$sh.doInvoke(shell.clj:79)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invokeStatic(core.clj:667)
        at clojure.core$apply.invoke(core.clj:662)
        at com.biffweb.impl.util$sh.invokeStatic(util.clj:63)
        at com.biffweb.impl.util$sh.doInvoke(util.clj:62)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.core$apply.invokeStatic(core.clj:667)
        at clojure.core$apply.invoke(core.clj:662)
        at com.biffweb$sh.invokeStatic(biffweb.clj:61)
        at com.biffweb$sh.doInvoke(biffweb.clj:56)
        at clojure.lang.RestFn.invoke(RestFn.java:482)
        at com.platypub.netlify$deploy_BANG_.invokeStatic(netlify.clj:15)
        at com.platypub.netlify$deploy_BANG_.invoke(netlify.clj:10)
        at com.platypub.feat.sites$publish.invokeStatic(sites.clj:156)
        at com.platypub.feat.sites$publish.invoke(sites.clj:152)
        at com.platypub.util$wrap_signed_in$fn__35716.invoke(util.clj:96)
jacobobryant commented 2 years ago

Oh, it's an oversight on this line: https://github.com/jacobobryant/platypub/blob/master/src/com/platypub/netlify.clj#L14. Quick fix is to install zip-it-and-ship-it globally: sudo npm install @netlify/zip-it-and-ship-it -g.

To avoid the need for a global install, we could include zip-it in themes/default/package.json and invoke with npx zip-it-and-..., however that'll make the npm install at https://github.com/jacobobryant/platypub/blob/master/src/com/platypub/netlify.clj#L13 even slower since it'll have to install every time you publish. Ideal solution is probably to add a package.json file to platypub's root folder and include a one-time npm install as part of platypub's setup process.

While we're on the topic, that npm install line linked above should probably be changed to omit dev dependencies, which are only needed for local theme development. That'll speed up publishing. (https://stackoverflow.com/questions/9268259/how-do-you-prevent-install-of-devdependencies-npm-modules-for-node-js-package). Though looks like for the default theme I do have at least one dev dependency that should be a production dependency (@tailwindcss/forms, https://github.com/jacobobryant/platypub/blob/master/themes.TEMPLATE/default/package.json#L17), so that would need to be fixed as well...

jeffp42ker commented 2 years ago

Thanks. As you've indicate, globally installing @netlify/zip-it-and-ship-it solves the issue. It still takes a significant time to publish.