serverless-nextjs / serverless-next.js

⚡ Deploy your Next.js apps on AWS Lambda@Edge via Serverless Components
MIT License
4.46k stars 457 forks source link

serverless-patched with pnpm is broken #2492

Open matusfaro opened 2 years ago

matusfaro commented 2 years ago

Issue Summary

When using serverless-patched doesn't work with pnpm.

Actual behavior

Calling serverless-patched seems to work as the note is printed. but the Deploying logs are still present:

Note: running patched serverless binary.
...
81s › dataspray › Deploying 
81s › dataspray › Deploying .
81s › dataspray › Deploying .
81s › dataspray › Deploying ..

The findUpSync logic finds an unpatched serverless instance due to pnpm's node_modules structure.

Expected behavior

Deploying ... logs should not be printed

Steps to reproduce

pnpm with serverless-patched

Versions

Checklist

Possible issues to address:

  1. Use the proper patched serverless binary
  2. Don't print Note: running patched serverless binary. inside bin/serverless-patched.ts but add this log line to the patch @serverless+cli+1.5.3.patch itself. It was very confusing to track down this issue because of this. Bonus: detect whether the patch is present.
  3. Upstream this to @serverless/cli

To be honest, the amount of work put into this workaround, it seems upstreaming is the best option unless they are hesitant to accept patches.

matusfaro commented 2 years ago

For others stumbling here with pnpm:

Don't use serverless-patched, use pnpm to apply the patch directly onto serverless like this:

package.json:


  "scripts": {
    "deploy": "SERVERLESS_CLI=true serverless --debug",
  },
  "devDependencies": {
    "serverless": "^2.72.2",
  },
  "pnpm": {
    "patchedDependencies": {
      "@serverless/cli@1.6.0": "patches/@serverless__cli@1.6.0.patch"
    }
  }

@serverless__cli@1.6.0.patch:

diff --git a/src/Context.js b/src/Context.js
index 4fb9da9b8a10ba8bc4ff82adab17e9605bf6d53e..ea13d974159fc17203d9dfa7dd5930a1dc29c9fb 100644
--- a/src/Context.js
+++ b/src/Context.js
@@ -153,7 +153,11 @@ class CLI {
     process.stdout.write(ansiEscapes.cursorShow)
     if (!this.isStatusEngineActive()) {
       console.log() // eslint-disable-line
-      process.exit(0)
+      if (reason === 'error') {
+        process.exit(1)
+      } else {
+        process.exit(0)
+      }
       return
     }
     return this.statusEngineStop(reason, message)
@@ -244,6 +248,10 @@ class CLI {
       this._.entity = entity
     }

+    if (!process.stdout.isTTY || !!process.env.SERVERLESS_CI) {
+      return;
+    }
+
     // Loading dots
     if (this._.status.loadingDotCount === 0) {
       this._.status.loadingDots = `.`