-
Notifications
You must be signed in to change notification settings - Fork 730
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 9 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,14 @@ | ||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||
|
|
||||||||||||||||||
| test() { | ||||||||||||||||||
| echo "Test $1" | ||||||||||||||||||
| cd "$1" || { echo "Error: Directory $1 not found"; return 1; } | ||||||||||||||||||
| pwd | ||||||||||||||||||
| rm -rf node_modules package-lock.json | ||||||||||||||||||
| npm install --registry=https://registry.npmmirror.com | ||||||||||||||||||
| 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 helloworld || exit 1 | ||||||||||||||||||
| test hello-tegg || exit 1 | ||||||||||||||||||
| 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,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": "git@github.com:eggjs/examples.git" | ||
| "repository": "git@github.com: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,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'); | ||
| }); | ||
| }); |
| 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)', | ||
| }, | ||
| }); | ||
| }); | ||
| }); |
| 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": [] | ||
| } |
| 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" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| node_modules | ||
| *.js |
This file was deleted.
| 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.
| 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'; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| 'use strict'; | ||
| import { Application } from 'egg'; | ||
|
|
||
| module.exports = app => { | ||
| export default (app: Application) => { | ||
| app.router.get('/', app.controller.home.render); | ||
| app.router.get('/foo', app.controller.foo.render); | ||
| }; |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { EggAppConfig } from 'egg'; | ||
|
|
||
| export default { | ||
| keys: 'my secret keys', | ||
| } as EggAppConfig; |
Uh oh!
There was an error while loading. Please reload this page.