-
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 6 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 | ||||||||||||||||||
| pwd | ||||||||||||||||||
| rm -rf node_modules package-lock.json | ||||||||||||||||||
| npm install --registry=https://registry.npmmirror.com | ||||||||||||||||||
| npm run ci | ||||||||||||||||||
| cd .. | ||||||||||||||||||
|
fengmk2 marked this conversation as resolved.
Outdated
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 | ||||||||||||||||||
| test hello-tegg | ||||||||||||||||||
|
fengmk2 marked this conversation as resolved.
|
||||||||||||||||||
| 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 |
|---|---|---|
|
|
@@ -3,39 +3,41 @@ | |
| "private": true, | ||
| "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", | ||
| "pretest": "npm run clean && npm run lint -- --fix", | ||
| "test": "egg-bin test", | ||
| "tsc": "tsc -p tsconfig.json", | ||
| "ci": "npm run lint && npm run cov && npm run tsc", | ||
| "preci": "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/scripts": "^4.0.0", | ||
| "@eggjs/tegg": "^3.2.1", | ||
| "@eggjs/tegg-config": "^3.1.0", | ||
| "@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" | ||
| "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/bin": "7", | ||
| "@eggjs/mock": "6", | ||
| "eslint": "8", | ||
| "eslint-config-egg": "14", | ||
| "typescript": "5" | ||
| }, | ||
| "repository": "git@github.com:eggjs/examples.git" | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,11 @@ | ||||||||||
| import { Context } from 'egg'; | ||||||||||
| import assert from 'assert'; | ||||||||||
| import { app } from 'egg-mock/bootstrap'; | ||||||||||
| import { strict as assert } from 'node:assert'; | ||||||||||
| // import { EggContext } from 'egg'; | ||||||||||
| import { app } from '@eggjs/mock/bootstrap'; | ||||||||||
| import { HelloService } from '../../app/biz/HelloService'; | ||||||||||
|
|
||||||||||
| describe('test/biz/HelloService.test.ts', () => { | ||||||||||
| let ctx: Context; | ||||||||||
| let ctx: any; | ||||||||||
| // let ctx: EggContext; | ||||||||||
|
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 Avoid using Using Consider uncommenting and using the proper type: - let ctx: any;
- // let ctx: EggContext;
+ // Import EggContext at the top
+ let ctx: EggContext;If EggContext is not available in egg v4, check the documentation for the appropriate type to use instead of 📝 Committable suggestion
Suggested change
|
||||||||||
| let helloService: HelloService; | ||||||||||
|
|
||||||||||
| beforeEach(async () => { | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,15 @@ | ||
| { | ||
| "extends": "@eggjs/tsconfig", | ||
| "compilerOptions": { | ||
| "baseUrl": "./" | ||
| } | ||
| "baseUrl": ".", | ||
| "strict": true, | ||
| "noImplicitAny": true, | ||
| "target": "ES2022", | ||
| "module": "NodeNext", | ||
| "moduleResolution": "NodeNext", | ||
| "declaration": false | ||
| }, | ||
| "exclude": [ | ||
| "test" | ||
| ] | ||
| } |
| 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; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,16 +1,33 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "name": "helloworld", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "dependencies": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "egg": "^1.10.1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@eggjs/scripts": "^4.0.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "egg": "beta" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+6
to
+7
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. Pin specific beta versions to avoid breaking changes. Using the Consider pinning to specific beta versions as suggested for Also applies to: 10-12 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "devDependencies": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "egg-bin": "^4.3.5", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "egg-mock": "^3.13.1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@eggjs/bin": "7", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@eggjs/mock": "6", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@eggjs/tsconfig": "1", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@types/mocha": "10", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@types/node": "22", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "eslint": "8", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "eslint-config-egg": "14", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "typescript": "5" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "scripts": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "start": "eggctl start --daemon", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "stop": "eggctl stop", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "lint": "eslint . --ext .ts", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "predev": "npm run clean && npm run lint -- --fix", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "dev": "egg-bin dev", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "pretest": "npm run clean && npm run lint -- --fix", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "test": "egg-bin test", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "cov": "egg-bin cov" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "preci": "npm run clean && npm run lint", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "ci": "egg-bin cov", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "postci": "npm run prepublishOnly && npm run clean", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "clean": "tsc -b --clean", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "prepublishOnly": "npm run clean && tsc" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "private": true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "private": true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "repository": "git@github.com:eggjs/examples.git" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
1
to
34
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. Missing Node.js engine requirement. Unlike Add an "repository": "git@github.com:eggjs/examples.git"
+ "engines": {
+ "node": ">=18.19.0"
+ }
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.