Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ name: CI
on:
push:
branches: [ master ]

pull_request:
branches: [ master ]

workflow_dispatch: {}

jobs:
Job:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-test.yml@master
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest'
version: '14, 16, 18'
version: '20, 22'
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# Examples for [egg](https://github.com/eggjs/egg)

---

[![build status][travis-image]][travis-url]
[![CI](https://github.com/eggjs/examples/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/eggjs/examples/actions/workflows/ci.yml)
[![node version][node-image]][node-url]
[![egg version][egg-image]][egg-url]

[travis-image]: https://img.shields.io/travis/eggjs/examples.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/examples
[node-image]: https://img.shields.io/badge/node.js-%3E=_8-green.svg?style=flat-square
[node-image]: https://img.shields.io/badge/node.js-%3E=_18-green.svg?style=flat-square
Comment thread
fengmk2 marked this conversation as resolved.
Outdated
[node-url]: http://nodejs.org/download/
[egg-image]: https://img.shields.io/badge/egg-%3E=_1-green.svg?style=flat-square
[egg-image]: https://img.shields.io/badge/egg-%3E=_4-green.svg?style=flat-square
[egg-url]: https://github.com/eggjs/egg

## Usage
Expand All @@ -23,7 +19,7 @@ $ npm install
$ npm run dev
```

**Recommend to use Node >= 8**
**Recommend to use Node >= 18**

## List of examples

Expand Down Expand Up @@ -64,12 +60,6 @@ You can use `--verbose` to show more infomation
$ npm test -- --verbose
```

### Generate dependencies

```bash
$ npm run autod
```

### Show list of examples

```bash
Expand Down
14 changes: 14 additions & 0 deletions bin/test.sh
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

Copy link
Copy Markdown
Contributor

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.

- npm run ci
- cd ..
+ if ! npm run ci; then
+   echo "Tests failed in $1"
+   cd ..
+   return 1
+ fi
+ cd ..
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
npm run ci
cd ..
if ! npm run ci; then
echo "Tests failed in $1"
cd ..
return 1
fi
cd ..

}

test helloworld || exit 1
test hello-tegg || exit 1
1 change: 1 addition & 0 deletions hello-tegg/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ test/**/*.map
config/**/*.map
*.d.ts
*.tsbuildinfo
.egg/
3 changes: 2 additions & 1 deletion hello-tegg/app/biz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"name": "biz-module",
"eggModule": {
"name": "biz"
}
},
"type": "module"
}
4 changes: 2 additions & 2 deletions hello-tegg/app/controller/HelloController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
Inject,
} from '@eggjs/tegg';
import { EggLogger } from 'egg';
import { traceMethod } from 'app/middleware/trace_method';
import { HelloService } from 'app/biz/HelloService';
import { traceMethod } from '../middleware/trace_method.js';
import { HelloService } from '../biz/HelloService.js';

@HTTPController()
@Middleware(traceMethod)
Expand Down
4 changes: 2 additions & 2 deletions hello-tegg/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EggAppConfig, PowerPartial } from 'egg';
import { EggAppInfo, EggAppConfig, PowerPartial } from 'egg';

export default (appInfo: EggAppConfig) => {
export default (appInfo: EggAppInfo) => {
const config = {} as PowerPartial<EggAppConfig>;

// override config from framework / plugin
Expand Down
53 changes: 29 additions & 24 deletions hello-tegg/package.json
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Node.js version requirement mismatch with PR description.

The PR description states "drop Node.js < 18.19.0 support," but this package requires >=20.0.0. This inconsistency may cause confusion. Additionally, the helloworld package doesn't specify an engines field at all.

Please clarify:

  • Is the minimum Node.js version 18.19.0 or 20.0.0?
  • Should all example packages have consistent engine requirements?
🤖 Prompt for AI Agents
In hello-tegg/package.json around lines 43-45 the "engines" field requires
"node": ">=20.0.0" which conflicts with the PR description that drops Node.js
<18.19.0; decide the project-wide minimum (either 18.19.0 or 20.0.0), update
this package.json to use "node": ">=<chosen_version>", add the same "engines"
entry to the helloworld package.json to keep examples consistent, and update the
PR description to state the chosen minimum Node.js version so they match.

}
19 changes: 6 additions & 13 deletions hello-tegg/test/biz/HelloService.test.ts
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');
});
});
22 changes: 10 additions & 12 deletions hello-tegg/test/controller/HelloController.test.ts
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)',
},
});
});
});
6 changes: 4 additions & 2 deletions hello-tegg/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"extends": "@eggjs/tsconfig",
"compilerOptions": {
"baseUrl": "./"
}
"baseUrl": ".",
"declaration": false
},
"exclude": []
}
8 changes: 8 additions & 0 deletions hello-tegg/tsconfig.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@eggjs/tsconfig",
"compilerOptions": {
"baseUrl": ".",
"declaration": false
},
"exclude": []
}
6 changes: 6 additions & 0 deletions helloworld/.eslintrc
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"
]
}
2 changes: 2 additions & 0 deletions helloworld/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
*.js
13 changes: 0 additions & 13 deletions helloworld/app/controller/foo.js

This file was deleted.

11 changes: 11 additions & 0 deletions helloworld/app/controller/foo.ts
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',
};
}
}
13 changes: 0 additions & 13 deletions helloworld/app/controller/home.js

This file was deleted.

8 changes: 8 additions & 0 deletions helloworld/app/controller/home.ts
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';
}
}
4 changes: 2 additions & 2 deletions helloworld/app/router.js → helloworld/app/router.ts
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);
};
3 changes: 0 additions & 3 deletions helloworld/config/config.default.js

This file was deleted.

5 changes: 5 additions & 0 deletions helloworld/config/config.default.ts
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;
Loading