Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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: '18, 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
pwd
rm -rf node_modules package-lock.json
npm install --registry=https://registry.npmmirror.com
npm run ci
cd ..
Comment thread
fengmk2 marked this conversation as resolved.
Outdated
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
test hello-tegg
Comment thread
fengmk2 marked this conversation as resolved.
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/
2 changes: 1 addition & 1 deletion hello-tegg/app/middleware/trace_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { EggContext, Next } from '@eggjs/tegg';

export async function traceMethod(ctx: EggContext, next: Next) {
await next();
ctx.body.data.message += ` (${ctx.method})`;
(ctx.body as any).data.message += ` (${ctx.method})`;
}
5 changes: 3 additions & 2 deletions hello-tegg/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { EggAppConfig, PowerPartial } from 'egg';
import { EggAppConfig } from 'egg';
// import { EggAppConfig, PowerPartial } from 'egg';

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

// override config from framework / plugin
config.keys = appInfo.name + '123456';
Expand Down
5 changes: 3 additions & 2 deletions hello-tegg/config/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EggPlugin } from 'egg';
// import { EggPlugin } from 'egg';

const plugin: EggPlugin = {
// const plugin: EggPlugin = {
const plugin = {
tegg: {
enable: true,
package: '@eggjs/tegg-plugin',
Expand Down
36 changes: 19 additions & 17 deletions hello-tegg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 | 🔴 Critical

🧩 Analysis chain

Pin specific beta versions to avoid breaking changes.

Using the "beta" tag for dependencies means the package will resolve to the latest beta version at install time, which can introduce breaking changes unexpectedly between installs. This can lead to inconsistent behavior across different environments and makes builds non-reproducible.

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'
done

Length of output: 16364


Pin specific beta versions to avoid non-reproducible builds.

Using "beta" as a version specifier resolves to the latest beta version at install time. This creates the reproducibility issues you've identified. The npm registry data confirms multiple beta versions are available for each package—installing at different times would pull different versions without a lock file.

Recommended pinned versions based on current latest betas:

  • "@eggjs/scripts": "5.0.0-beta.28"
  • "@eggjs/tegg": "4.0.0-beta.11"
  • "@eggjs/tegg-config": "4.0.0-beta.11"
  • "@eggjs/tegg-controller-plugin": "4.0.0-beta.11"
  • "@eggjs/tegg-plugin": "4.0.0-beta.11"
  • "egg": "4.1.0-beta.28"

Apply the same approach to the dependencies at lines 35-37.

🤖 Prompt for AI Agents
In hello-tegg/package.json around lines 25 to 30 (and apply same change to the
related dependencies at lines 35-37), the packages use the loose "beta" tag
which yields non-reproducible installs; replace each "beta" specifier with the
pinned beta versions provided by the reviewer: set "@eggjs/scripts" to
"5.0.0-beta.28", "@eggjs/tegg" to "4.0.0-beta.11", "@eggjs/tegg-config" to
"4.0.0-beta.11", "@eggjs/tegg-controller-plugin" to "4.0.0-beta.11",
"@eggjs/tegg-plugin" to "4.0.0-beta.11", and "egg" to "4.1.0-beta.28", and make
the same pinning for the matching entries at lines 35-37 to ensure reproducible
builds.

},
"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"
}
9 changes: 5 additions & 4 deletions hello-tegg/test/biz/HelloService.test.ts
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;

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

Avoid using any type

Using any for the ctx variable bypasses TypeScript's type checking benefits, which can lead to runtime errors. The commented alternative suggests EggContext might be a better option.

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 any.

📝 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
let ctx: any;
// let ctx: EggContext;
// Import EggContext at the top
let ctx: EggContext;

let helloService: HelloService;

beforeEach(async () => {
Expand Down
4 changes: 2 additions & 2 deletions hello-tegg/test/controller/HelloController.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app } from 'egg-mock/bootstrap';
import assert from 'assert';
import { strict as assert } from 'node:assert';
import { app } from '@eggjs/mock/bootstrap';

describe('test/controller/HelloController.test.ts', () => {
it('should work', async () => {
Expand Down
13 changes: 11 additions & 2 deletions hello-tegg/tsconfig.json
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"
]
}
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;
27 changes: 22 additions & 5 deletions helloworld/package.json
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

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 | 🟠 Major

Pin specific beta versions to avoid breaking changes.

Using the "beta" tag without version pinning can lead to non-reproducible builds and unexpected breaking changes. This is particularly risky during active beta development.

Consider pinning to specific beta versions as suggested for hello-tegg/package.json.

Also applies to: 10-12

🤖 Prompt for AI Agents
In helloworld/package.json around lines 6 to 7 (and also check lines 10-12), the
dependencies use the unpinned "beta" tag which risks non-reproducible builds and
breaking changes; update the "egg" and "@eggjs/scripts" entries to specific beta
release versions (e.g., "beta.X.Y" or the exact semver found in
hello-tegg/package.json) instead of the bare "beta", commit the updated
package.json, and run npm install/npm ci to update lockfile so CI and local
builds use the pinned beta versions.

},
"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

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 | 🟠 Major

Missing Node.js engine requirement.

Unlike hello-tegg/package.json, this package doesn't specify an engines field. Given that the PR drops support for Node.js < 18.19.0, all example packages should explicitly declare their minimum Node.js version to prevent users from running them on unsupported versions.

Add an engines field to enforce the minimum Node.js version:

   "repository": "git@github.com:eggjs/examples.git"
+  "engines": {
+    "node": ">=18.19.0"
+  }
 }
📝 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
{
"name": "helloworld",
"private": true,
"type": "module",
"dependencies": {
"egg": "^1.10.1"
"@eggjs/scripts": "beta",
"egg": "beta"
},
"devDependencies": {
"egg-bin": "^4.3.5",
"egg-mock": "^3.13.1"
"@eggjs/bin": "beta",
"@eggjs/mock": "beta",
"@eggjs/tsconfig": "beta",
"@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
"repository": "git@github.com:eggjs/examples.git"
}
{
"name": "helloworld",
"private": true,
"type": "module",
"dependencies": {
"@eggjs/scripts": "beta",
"egg": "beta"
},
"devDependencies": {
"@eggjs/bin": "beta",
"@eggjs/mock": "beta",
"@eggjs/tsconfig": "beta",
"@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",
"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"
},
"repository": "git@github.com:eggjs/examples.git",
"engines": {
"node": ">=18.19.0"
}
}
🤖 Prompt for AI Agents
In helloworld/package.json around lines 1 to 34, the package is missing an
"engines" field to enforce the minimum Node.js version; add an "engines" object
with "node": ">=18.19.0" (matching the repo minimum) so users are prevented from
running the example on unsupported Node versions, and commit the updated
package.json.

29 changes: 0 additions & 29 deletions helloworld/test/index.test.js

This file was deleted.

Loading