Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 6ee24ca

Browse files
authored
feat(nextjs-component): introduce serverless-patched binary (#1658)
1 parent 5d6cc65 commit 6ee24ca

File tree

8 files changed

+3114
-148
lines changed

8 files changed

+3114
-148
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@
9595
"/scripts/",
9696
"babel.config.js",
9797
"jest.config.js",
98-
"<rootDir>/packages/serverless-components/aws-s3"
98+
"<rootDir>/packages/serverless-components/aws-s3",
99+
"<rootDir>/packages/serverless-components/nextjs-component/bin"
99100
],
100101
"watchPathIgnorePatterns": [
101102
"/fixture/",

packages/e2e-tests/test-utils/scripts/run-e2e-ci.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,12 @@ async function runEndToEndTest(): Promise<boolean> {
290290
{ stdio: "inherit" }
291291
);
292292

293-
// Sleep a few seconds to prevent exhausting API limits.
294-
// (likely not needed anymore due to changing retry policy)
295-
// await new Promise((resolve) => setTimeout(resolve, Math.random() * 15000));
296-
297293
// Deploy
298294
console.info("Deploying serverless-next.js app.");
299-
execSync("npx serverless", { stdio: "inherit" });
295+
execSync(
296+
"node ../../serverless-components/nextjs-component/dist/bin/serverless-patched.js --debug",
297+
{ stdio: "inherit" }
298+
);
300299

301300
// Get Next.js build ID and URL
302301
console.info("Getting Next.js build ID");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env node
2+
import { execSync } from "child_process";
3+
4+
console.info("Note: running patched serverless binary.");
5+
6+
const args = process.argv.slice(2).join(" ");
7+
// This executes package-local serverless which uses a patched @serverless/cli
8+
execSync(`${__dirname}/../../node_modules/.bin/serverless ${args}`, {
9+
stdio: "inherit"
10+
});

packages/serverless-components/nextjs-component/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"scripts": {
1616
"prepare": "yarn clean && yarn build",
1717
"build": "tsc -p tsconfig.build.json",
18-
"clean": "yarn rimraf dist"
18+
"clean": "yarn rimraf dist",
19+
"postinstall": "patch-package"
1920
},
2021
"keywords": [
2122
"serverless",
@@ -44,11 +45,17 @@
4445
"@sls-next/s3-static-assets": "link:../../libs/s3-static-assets",
4546
"aws-sdk": "^2.985.0",
4647
"fs-extra": "^9.1.0",
48+
"serverless": "^2.57.0",
4749
"webpack": "^5.52.0"
4850
},
4951
"devDependencies": {
5052
"@types/fs-extra": "^9.0.1",
53+
"patch-package": "^6.4.7",
54+
"postinstall-postinstall": "^2.1.0",
5155
"rimraf": "^3.0.2",
5256
"typescript": "^4.4.2"
57+
},
58+
"bin": {
59+
"serverless-patched": "./dist/bin/serverless-patched.js"
5360
}
5461
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
diff --git a/node_modules/@serverless/cli/src/Context.js b/node_modules/@serverless/cli/src/Context.js
2+
index 4fb9da9..f8919a4 100644
3+
--- a/node_modules/@serverless/cli/src/Context.js
4+
+++ b/node_modules/@serverless/cli/src/Context.js
5+
@@ -153,7 +153,11 @@ class CLI {
6+
process.stdout.write(ansiEscapes.cursorShow)
7+
if (!this.isStatusEngineActive()) {
8+
console.log() // eslint-disable-line
9+
- process.exit(0)
10+
+ if (reason === 'error') {
11+
+ process.exit(1)
12+
+ } else {
13+
+ process.exit(0)
14+
+ }
15+
return
16+
}
17+
return this.statusEngineStop(reason, message)
18+
@@ -244,44 +248,46 @@ class CLI {
19+
this._.entity = entity
20+
}
21+
22+
- // Loading dots
23+
- if (this._.status.loadingDotCount === 0) {
24+
- this._.status.loadingDots = `.`
25+
- } else if (this._.status.loadingDotCount === 2) {
26+
- this._.status.loadingDots = `..`
27+
- } else if (this._.status.loadingDotCount === 4) {
28+
- this._.status.loadingDots = `...`
29+
- } else if (this._.status.loadingDotCount === 6) {
30+
- this._.status.loadingDots = ''
31+
- }
32+
- this._.status.loadingDotCount++
33+
- if (this._.status.loadingDotCount > 8) {
34+
- this._.status.loadingDotCount = 0
35+
- }
36+
+ if (process.stdout.isTTY) {
37+
+ // Loading dots
38+
+ if (this._.status.loadingDotCount === 0) {
39+
+ this._.status.loadingDots = `.`
40+
+ } else if (this._.status.loadingDotCount === 2) {
41+
+ this._.status.loadingDots = `..`
42+
+ } else if (this._.status.loadingDotCount === 4) {
43+
+ this._.status.loadingDots = `...`
44+
+ } else if (this._.status.loadingDotCount === 6) {
45+
+ this._.status.loadingDots = ''
46+
+ }
47+
+ this._.status.loadingDotCount++
48+
+ if (this._.status.loadingDotCount > 8) {
49+
+ this._.status.loadingDotCount = 0
50+
+ }
51+
52+
- // Clear any existing content
53+
- process.stdout.write(ansiEscapes.eraseDown)
54+
+ // Clear any existing content
55+
+ process.stdout.write(ansiEscapes.eraseDown)
56+
57+
- // Write content
58+
- console.log() // eslint-disable-line
59+
- let content = ' '
60+
- if (this._.useTimer) {
61+
- content += ` ${grey(this._.seconds + 's')}`
62+
- content += ` ${grey(figures.pointerSmall)}`
63+
- }
64+
+ // Write content
65+
+ console.log() // eslint-disable-line
66+
+ let content = ' '
67+
+ if (this._.useTimer) {
68+
+ content += ` ${grey(this._.seconds + 's')}`
69+
+ content += ` ${grey(figures.pointerSmall)}`
70+
+ }
71+
72+
- content += ` ${this._.entity}`
73+
- content += ` ${grey(figures.pointerSmall)} ${grey(this._.status.message)}`
74+
- content += ` ${grey(this._.status.loadingDots)}`
75+
- process.stdout.write(content)
76+
- console.log() // eslint-disable-line
77+
+ content += ` ${this._.entity}`
78+
+ content += ` ${grey(figures.pointerSmall)} ${grey(this._.status.message)}`
79+
+ content += ` ${grey(this._.status.loadingDots)}`
80+
+ process.stdout.write(content)
81+
+ console.log() // eslint-disable-line
82+
83+
- // Get cursor starting position according to terminal & content width
84+
- const startingPosition = this.getRelativeVerticalCursorPosition(content)
85+
+ // Get cursor starting position according to terminal & content width
86+
+ const startingPosition = this.getRelativeVerticalCursorPosition(content)
87+
88+
- // Put cursor to starting position for next view
89+
- process.stdout.write(ansiEscapes.cursorUp(startingPosition))
90+
- process.stdout.write(ansiEscapes.cursorLeft)
91+
+ // Put cursor to starting position for next view
92+
+ process.stdout.write(ansiEscapes.cursorUp(startingPosition))
93+
+ process.stdout.write(ansiEscapes.cursorLeft)
94+
+ }
95+
}
96+
97+
renderLog(msg) {
98+
diff --git a/node_modules/@serverless/cli/src/index.js b/node_modules/@serverless/cli/src/index.js
99+
index ee52b08..9652a4e 100644
100+
--- a/node_modules/@serverless/cli/src/index.js
101+
+++ b/node_modules/@serverless/cli/src/index.js
102+
@@ -233,11 +233,9 @@ const runComponents = async (serverlessFileArg) => {
103+
}
104+
}
105+
context.close('done')
106+
- process.exit(0)
107+
} catch (e) {
108+
context.renderError(e)
109+
context.close('error', e)
110+
- process.exit(1)
111+
}
112+
}
113+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const component = require("./dist/component.js");
1+
const component = require("./dist/src/component.js");
22

33
module.exports = component.default;

packages/serverless-components/nextjs-component/tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"sourceMap": false,
55
"removeComments": true
66
},
7-
"include": ["./src/", ".d.ts"]
7+
"include": ["./src/", ".d.ts", "./bin/"]
88
}

0 commit comments

Comments
 (0)