mozilla / addons

☂ Umbrella repository for Mozilla Addons ✨
Other
127 stars 41 forks source link

Consider replacing `piping` with `nodemon` or other modern/maintained nodejs hot reloader #14532

Closed diox closed 2 years ago

diox commented 2 years ago

We have been using piping for nodejs hot-reloading since the beginning (e8499f7e85).

piping is not maintained though. It's only for local development anyway, but it'd be best if we could stick to what the community is using modernly, and that's not it. nodemon is the most popular (and maintained) option, https://github.com/mozilla/addons-frontend/pull/5777 mentions that it was tried before and it was too slow, but maybe that's worth looking at again. Note that getting rid of piping would unblock some dependency updates.

A typical STR to ensure nodejs hot reloading works:

If nodejs hot reloading is working, you should see that change reflected in curl output. Note that this differs from hot reloading of client-side code, which is handled by webpack automatically (hence the STR using curl).

diox commented 2 years ago

Trivial patch to try out nodemon (also available in this branch) (run yarn after applying to install everything):

diff --git a/bin/server.js b/bin/server.js
index e83b59ca0..23c4669e5 100644
--- a/bin/server.js
+++ b/bin/server.js
@@ -10,13 +10,6 @@ const config = require('config');
 const touch = require('touch');

 if (process.env.NODE_ENV === 'development') {
-  if (!require('piping')({
-    hook: true,
-    ignore: /(\/\.|~$|\.json|\.scss$)/i,
-  })) {
-    return;
-  }
-
   if (process.env.USE_HTTPS_FOR_DEV) {
     // Skip SSL check to avoid the 'self signed certificate in certificate
     // chain' error.
diff --git a/package.json b/package.json
index 20b438bcb..89adf68cf 100644
--- a/package.json
+++ b/package.json
@@ -101,18 +101,16 @@
       }
     },
     "start-dev": {
-      "command": "npm run clean && concurrently 'npm run webpack-dev-server' 'node bin/server.js | pino-devtools --mode buffer --tee | pino-pretty'",
+      "command": "npm run clean && concurrently 'npm run webpack-dev-server' 'nodemon bin/server.js | pino-devtools --mode buffer --tee | pino-pretty'",
       "env": {
-        "ENABLE_PIPING": "true",
         "NODE_ENV": "development",
         "NODE_ICU_DATA": "./node_modules/full-icu",
         "NODE_PATH": "./:./src"
       }
     },
     "start-dev-proxy": {
-      "command": "npm run clean && concurrently -c 'dim' 'npm run webpack-dev-server' 'node bin/server.js | pino-devtools --mode buffer --tee | pino-pretty' 'node bin/proxy.js | pino-pretty'",
+      "command": "npm run clean && concurrently -c 'dim' 'npm run webpack-dev-server' 'nodemon bin/server.js | pino-devtools --mode buffer --tee | pino-pretty' 'node bin/proxy.js | pino-pretty'",
       "env": {
-        "ENABLE_PIPING": "true",
         "NODE_ENV": "development",
         "NODE_ICU_DATA": "./node_modules/full-icu",
         "NODE_PATH": "./:./src"
@@ -306,10 +304,10 @@
     "mock-express-response": "^0.3.0",
     "node-fetch": "^3.1.1",
     "node-sass": "^7.0.0",
+    "nodemon": "2.0.15",
     "object.values": "^1.0.4",
     "pino-devtools": "^2.1.0",
     "pino-pretty": "^7.0.0",
-    "piping": "^1.0.0-rc.4",
     "po2json": "mikeedwards/po2json#51e2310485bbe35e9e57f2eee238185459ca0eab",
     "postcss": "^8.2.10",
     "postcss-loader": "^6.0.0",