-
Notifications
You must be signed in to change notification settings - Fork 737
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
Open
fengmk2
wants to merge
10
commits into
master
Choose a base branch
from
egg-v4
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
511dd6d
feat: hello world for egg v4
fengmk2 62be764
feat: upgrade to egg v4
fengmk2 8ceb918
update eggbin
fengmk2 67321cd
test on tegg v3
fengmk2 07ac2b3
use egg-scripts v3
fengmk2 6dac52f
use @eggjs/scripts v4
fengmk2 be4466b
f
fengmk2 93a6ea1
Update bin/test.sh
fengmk2 75dd0ef
Update bin/test.sh
fengmk2 97125cb
add body-parser-example
fengmk2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
npm install --registry=https://registry.npmmirror.com | ||
npm run ci | ||
cd .. | ||
} | ||
|
||
test body-parser-example | ||
test helloworld | ||
test hello-tegg | ||
fengmk2 marked this conversation as resolved.
Show resolved
Hide resolved
|
File renamed without changes.
4 changes: 1 addition & 3 deletions
4
bodyParser/app/controller/home.js → body-parser-example/app/controller/home.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 0 additions & 2 deletions
2
bodyParser/config/config.default.js → body-parser-example/config/config.default.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
'use strict'; | ||
|
||
exports.keys = '123456'; | ||
|
||
exports.bodyParser = { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "4", | ||
"xml-js": "^1.6.9" | ||
}, | ||
"devDependencies": { | ||
"egg-bin": "^4.3.5", | ||
"egg-mock": "^3.13.1" | ||
"@eggjs/bin": "7", | ||
"@eggjs/mock": "6" | ||
}, | ||
"scripts": { | ||
"dev": "egg-bin dev", | ||
"test": "egg-bin test", | ||
"cov": "egg-bin cov" | ||
"ci": "egg-bin cov" | ||
}, | ||
"private": true | ||
} |
7 changes: 2 additions & 5 deletions
7
bodyParser/test/home.test.js → body-parser-example/test/home.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ test/**/*.map | |
config/**/*.map | ||
*.d.ts | ||
*.tsbuildinfo | ||
.egg/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
"name": "biz-module", | ||
"eggModule": { | ||
"name": "biz" | ||
} | ||
}, | ||
"type": "module" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "^4.0.0", | ||
"@eggjs/tegg": "^4.0.0-beta.2", | ||
"@eggjs/tegg-config": "^4.0.0-beta.2", | ||
"@eggjs/tegg-controller-plugin": "^4.0.0-beta.2", | ||
"@eggjs/tegg-plugin": "^4.0.0-beta.2", | ||
"egg": "^4.0.10" | ||
}, | ||
"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": "2", | ||
"@eggjs/bin": "7", | ||
"@eggjs/mock": "6", | ||
"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" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,16 @@ | ||
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.js'; | ||
|
||
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'); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
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)', | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
{ | ||
"extends": "@eggjs/tsconfig", | ||
"compilerOptions": { | ||
"baseUrl": "./" | ||
} | ||
"baseUrl": ".", | ||
"declaration": false | ||
}, | ||
"exclude": [] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "@eggjs/tsconfig", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"declaration": false | ||
}, | ||
"exclude": [] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": [ | ||
"eslint-config-egg/typescript", | ||
"eslint-config-egg/lib/rules/enforce-node-prefix" | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
*.js |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Controller } from 'egg'; | ||
|
||
export default class FooController extends Controller { | ||
async render() { | ||
const ctx = this.ctx; | ||
ctx.status = 400; | ||
ctx.body = { | ||
foo: 'bar', | ||
}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Controller } from 'egg'; | ||
|
||
export default class HomeController extends Controller { | ||
async render() { | ||
const ctx = this.ctx; | ||
ctx.body = 'Hello World'; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🛠️ Refactor suggestion
Add error handling for npm commands.
The script currently doesn't preserve exit codes from the npm commands. If
npm run ci
fails, the script will still continue to the next test. This could hide test failures.📝 Committable suggestion