-
Notifications
You must be signed in to change notification settings - Fork 735
feat: upgrade to egg v4 #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
511dd6d
62be764
8ceb918
67321cd
07ac2b3
6dac52f
be4466b
93a6ea1
75dd0ef
97125cb
5a8f80d
d1f7158
48a1c95
342d5db
75eeb47
3338771
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||
|
|
||||||||||||||||||
| set -eux -o pipefail | ||||||||||||||||||
|
|
||||||||||||||||||
| test() { | ||||||||||||||||||
| echo "Test $1" | ||||||||||||||||||
| cd "$1" | ||||||||||||||||||
| pwd | ||||||||||||||||||
| rm -rf node_modules package-lock.json | ||||||||||||||||||
| npmupdate -c | ||||||||||||||||||
| npm run ci | ||||||||||||||||||
| cd .. | ||||||||||||||||||
|
Comment on lines
+11
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for npm commands. The script currently doesn't preserve exit codes from the npm commands. If - npm run ci
- cd ..
+ if ! npm run ci; then
+ echo "Tests failed in $1"
+ cd ..
+ return 1
+ fi
+ cd ..📝 Committable suggestion
Suggested change
|
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| test body-parser-example | ||||||||||||||||||
| test helloworld | ||||||||||||||||||
| test hello-tegg | ||||||||||||||||||
fengmk2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| 'use strict'; | ||
|
|
||
| exports.keys = '123456'; | ||
|
|
||
| exports.bodyParser = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,18 +1,18 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "name": "bodyParser", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "name": "body-parser-example", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "version": "1.0.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "dependencies": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "egg": "^2", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "egg": "beta", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainAvoid loose "beta" version tags; pin to specific beta releases. Using "beta" as a version spec is too permissive and may introduce non-deterministic installs. Different CI runs or developer machines could resolve to different beta patch versions, breaking reproducibility. Since this is an example repo migrating to egg v4 (beta), pin to specific versions or use a narrower semver range. Apply this diff to pin specific beta versions: "dependencies": {
- "egg": "beta",
+ "egg": "^4.0.0-beta",
"xml-js": "^1.6.9"
},
"devDependencies": {
- "@eggjs/bin": "beta",
- "@eggjs/mock": "beta"
+ "@eggjs/bin": "^4.0.0-beta",
+ "@eggjs/mock": "^4.0.0-beta"
},Alternatively, inspect the eggjs org releases to find the latest stable beta tag (e.g., Also applies to: 9-10 I'll verify the review comment by examining the package.json file and checking the available beta versions from the eggjs organization. import json
# Try to parse package.json if accessible
try:
with open("body-parser-example/package.json", "r") as f:
data = json.load(f)
print("Dependencies:")
if "dependencies" in data:
for dep, version in data.get("dependencies", {}).items():
if "egg" in dep.lower():
print(f" {dep}: {version}")
print("\nDevDependencies:")
if "devDependencies" in data:
for dep, version in data.get("devDependencies", {}).items():
if "egg" in dep.lower() or "eggjs" in dep.lower():
print(f" {dep}: {version}")
except Exception as e:
print(f"Error: {e}")🏁 Script executed: #!/bin/bash
# Inspect the package.json file to verify current state
if [ -f "body-parser-example/package.json" ]; then
cat body-parser-example/package.json
else
echo "File not found"
fiLength of output: 321 🏁 Script executed: #!/bin/bash
# Search for egg, @eggjs/bin, and @eggjs/mock version references
rg -n '"egg"|"@eggjs/bin"|"@eggjs/mock"' body-parser-example/package.json -A 0 -B 0Length of output: 77 🏁 Script executed: #!/bin/bash
# Check if there are any other package.json files that might reference these packages
fd 'package.json' --exec grep -l "egg\|@eggjs" {} \;Length of output: 1277 🌐 Web query: 💡 Result: You can find Egg v4 beta releases on the npm registry and install them either by the beta version tag or the Quick options:
References:
🌐 Web query: 💡 Result:
Sources: Pin specific beta versions instead of loose "beta" dist-tag for reproducibility. Using "beta" as a version specifier is a floating dist-tag that will resolve to different versions as new beta releases are published. This breaks reproducibility—installations at different times will pull different beta patch versions, complicating debugging and testing. Since the eggjs org has published specific beta versions (e.g., egg 4.1.0-beta.13, @eggjs/bin 7.3.1-beta.6, @eggjs/mock 6.1.0-beta.8), pin to a specific beta release instead. Apply this diff: "dependencies": {
- "egg": "beta",
+ "egg": "^4.0.0-beta",
"xml-js": "^1.6.9"
},
"devDependencies": {
- "@eggjs/bin": "beta",
- "@eggjs/mock": "beta"
+ "@eggjs/bin": "^4.0.0-beta",
+ "@eggjs/mock": "^4.0.0-beta"
},Alternatively, pin exact versions (e.g., Also applies to: lines 9–10 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "xml-js": "^1.6.9" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "devDependencies": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "egg-bin": "^4.3.5", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "egg-mock": "^3.13.1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@eggjs/bin": "beta", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@eggjs/mock": "beta" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "scripts": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "dev": "egg-bin dev", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "test": "egg-bin test", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "cov": "egg-bin cov" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "ci": "egg-bin cov" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "private": true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
1
to
18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add Node.js engine constraint to enforce minimum version. Per the PR objectives, egg v4 requires Node.js >= 18.19.0. Add an "engines" field to package.json to enforce this constraint for developers and CI environments. Apply this diff to add the engines field: "scripts": {
"dev": "egg-bin dev",
"test": "egg-bin test",
"ci": "egg-bin cov"
},
+ "engines": {
+ "node": ">=18.19.0"
+ },
"private": trueBased on learnings about egg v4 migration requirements. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,3 +19,4 @@ test/**/*.map | |
| config/**/*.map | ||
| *.d.ts | ||
| *.tsbuildinfo | ||
| .egg/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,5 +2,6 @@ | |
| "name": "biz-module", | ||
| "eggModule": { | ||
| "name": "biz" | ||
| } | ||
| }, | ||
| "type": "module" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,8 @@ | ||
| import { EggAppConfig, PowerPartial } from 'egg'; | ||
| import { defineConfigFactory } from 'egg'; | ||
|
|
||
| export default (appInfo: EggAppConfig) => { | ||
| const config = {} as PowerPartial<EggAppConfig>; | ||
|
|
||
| // override config from framework / plugin | ||
| config.keys = appInfo.name + '123456'; | ||
|
|
||
| return config; | ||
| }; | ||
| export default defineConfigFactory(appInfo => { | ||
| return { | ||
| // override config from framework / plugin | ||
| keys: appInfo.name + '123456', | ||
| }; | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { EggPlugin } from 'egg'; | ||
| import type { EggPlugin } from 'egg'; | ||
|
|
||
| const plugin: EggPlugin = { | ||
| tegg: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,46 @@ | ||
| { | ||
| "name": "hello-tegg", | ||
| "private": true, | ||
| "type": "module", | ||
| "description": "tegg application example", | ||
| "scripts": { | ||
| "start": "egg-scripts start", | ||
| "stop": "egg-scripts stop", | ||
| "start": "eggctl start --daemon", | ||
| "stop": "eggctl stop", | ||
| "dev": "egg-bin dev", | ||
| "debug": "egg-bin debug", | ||
| "test-local": "egg-bin test", | ||
| "test": "npm run lint -- --fix && npm run test-local", | ||
| "cov": "egg-bin cov", | ||
| "tsc": "tsc -p tsconfig.json", | ||
| "ci": "npm run lint && npm run cov && npm run tsc", | ||
| "pretest": "npm run clean && npm run lint -- --fix", | ||
| "test": "egg-bin test", | ||
| "tsc": "tsc -p tsconfig.prod.json", | ||
| "preci": "npm run clean && npm run lint", | ||
| "ci": "egg-bin cov", | ||
| "postci": "npm run tsc && npm run clean", | ||
| "lint": "eslint .", | ||
| "clean": "tsc -b --clean" | ||
| "clean": "tsc -b --clean", | ||
| "prepublishOnly": "npm run clean && tsc" | ||
| }, | ||
| "egg": { | ||
| "typescript": true | ||
| }, | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "@eggjs/tegg": "^3.2.1", | ||
| "@eggjs/tegg-controller-plugin": "^3.2.1", | ||
| "@eggjs/tegg-plugin": "^3.2.1", | ||
| "@eggjs/tsconfig": "^1.2.0", | ||
| "@eggjs/tegg-config": "^3.1.0", | ||
| "egg": "^3.9.1", | ||
| "egg-scripts": "^2.17.0" | ||
| "@eggjs/scripts": "beta", | ||
| "@eggjs/tegg": "beta", | ||
| "@eggjs/tegg-config": "beta", | ||
| "@eggjs/tegg-controller-plugin": "beta", | ||
| "@eggjs/tegg-plugin": "beta", | ||
| "egg": "beta" | ||
|
Comment on lines
+25
to
+30
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainPin specific beta versions to avoid breaking changes. Using the Consider pinning to specific beta versions. Run this script to check the current beta versions available: Also applies to: 35-37 🏁 Script executed: #!/bin/bash
# Description: Check latest beta versions for @eggjs packages
echo "Checking beta versions for @eggjs packages..."
for pkg in "@eggjs/scripts" "@eggjs/tegg" "@eggjs/tegg-config" "@eggjs/tegg-controller-plugin" "@eggjs/tegg-plugin" "egg" "@eggjs/tsconfig" "@eggjs/bin" "@eggjs/mock"; do
echo "=== $pkg ==="
npm view "$pkg" dist-tags.beta versions --json | jq -r 'if type == "array" then .[-5:] else . end'
doneLength of output: 16364 Pin specific beta versions to avoid non-reproducible builds. Using Recommended pinned versions based on current latest betas:
Apply the same approach to the dependencies at lines 35-37. 🤖 Prompt for AI Agents |
||
| }, | ||
| "devDependencies": { | ||
| "@types/mocha": "^10.0.1", | ||
| "@types/node": "^16.18.10", | ||
| "egg-bin": "^6.0.0", | ||
| "egg-mock": "^5.4.0", | ||
| "eslint": "^8.30.0", | ||
| "eslint-config-egg": "^12.1.0", | ||
| "typescript": "^4.9.4" | ||
| "@types/mocha": "10", | ||
| "@types/node": "22", | ||
| "@eggjs/tsconfig": "beta", | ||
| "@eggjs/bin": "beta", | ||
| "@eggjs/mock": "beta", | ||
| "eslint": "8", | ||
| "eslint-config-egg": "14", | ||
| "typescript": "5" | ||
| }, | ||
| "repository": "[email protected]:eggjs/examples.git" | ||
| "repository": "[email protected]:eggjs/examples.git", | ||
| "engines": { | ||
| "node": ">=20.0.0" | ||
| } | ||
|
Comment on lines
+43
to
+45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Node.js version requirement mismatch with PR description. The PR description states "drop Node.js < 18.19.0 support," but this package requires Please clarify:
🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,17 @@ | ||
| import { Context } from 'egg'; | ||
| import assert from 'assert'; | ||
| import { app } from 'egg-mock/bootstrap'; | ||
| import { HelloService } from '../../app/biz/HelloService'; | ||
| import assert from 'node:assert/strict'; | ||
| import { app } from '@eggjs/mock/bootstrap'; | ||
|
|
||
| import { HelloService } from '../../app/biz/HelloService.ts'; | ||
|
|
||
| describe('test/biz/HelloService.test.ts', () => { | ||
| let ctx: Context; | ||
| let helloService: HelloService; | ||
|
|
||
| beforeEach(async () => { | ||
| ctx = await app.mockModuleContext(); | ||
| helloService = await ctx.getEggObject(HelloService); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await app.destroyModuleContext(ctx); | ||
| before(async () => { | ||
| helloService = await app.getEggObject(HelloService); | ||
| }); | ||
|
|
||
| it('should work', async () => { | ||
| const msg = await helloService.hello('killa'); | ||
| assert(msg === 'hello, killa'); | ||
| assert.equal(msg, 'hello, killa'); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,17 @@ | ||
| import { app } from 'egg-mock/bootstrap'; | ||
| import assert from 'assert'; | ||
| import assert from 'node:assert/strict'; | ||
|
|
||
| import { app } from '@eggjs/mock/bootstrap'; | ||
|
|
||
| describe('test/controller/HelloController.test.ts', () => { | ||
| it('should work', async () => { | ||
| await app.httpRequest() | ||
| const res = await app.httpRequest() | ||
| .get('/hello?name=killa') | ||
| .expect(200) | ||
| .expect(res => { | ||
| assert.deepStrictEqual(res.body, { | ||
| success: true, | ||
| data: { | ||
| message: 'hello, killa (GET)', | ||
| }, | ||
| }); | ||
| }); | ||
| .expect(200); | ||
| assert.deepEqual(res.body, { | ||
| success: true, | ||
| data: { | ||
| message: 'hello, killa (GET)', | ||
| }, | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| { | ||
| "extends": "@eggjs/tsconfig", | ||
| "compilerOptions": { | ||
| "baseUrl": "./" | ||
| } | ||
| "baseUrl": ".", | ||
| "declaration": false | ||
| }, | ||
| "exclude": [] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "extends": "@eggjs/tsconfig", | ||
| "compilerOptions": { | ||
| "baseUrl": ".", | ||
| "declaration": false | ||
| }, | ||
| "exclude": [] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert emphasis to proper heading to resolve markdown lint warning.
The line uses bold emphasis instead of a proper heading structure, which triggers
MD036from markdownlint-cli2.Apply this diff:
📝 Committable suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.18.1)
22-22: Emphasis used instead of a heading
(MD036, no-emphasis-as-heading)
🤖 Prompt for AI Agents