Skip to content

Commit

Permalink
feat: support cjs and esm both by tshy (#27)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

- **Project Configuration**
  - Updated Node.js version support to 18, 20, and 22
- Updated TypeScript configuration to ES2022 and NodeNext module
resolution
  - Updated minimum Node.js requirement to version 18
  - Added MIT license

- **Dependencies**
  - Upgraded several development dependencies
  - Updated testing and build tools to latest versions

- **Documentation**
  - Added Contributors section to README
  - Updated project requirements documentation

- **Maintenance**
  - Updated `.gitignore` to exclude `package-lock.json`
  - Removed pull request template
  - Introduced a new configuration file for unit tests
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored Feb 4, 2025
1 parent 4a77f8b commit b750157
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 57 deletions.
24 changes: 0 additions & 24 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

3 changes: 1 addition & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: CI
on:
push:
branches: [ master ]

pull_request:
branches: [ master ]

Expand All @@ -13,4 +12,4 @@ jobs:
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest'
version: '16, 18, 20'
version: '18, 20, 22'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ logs
run
*.sw*
*.un~
package-lock.json
.package-lock.json
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ open http://localhost:7001
```

See [egg-init](https://github.com/eggjs/egg-init) for more detail.

## License

[MIT](LICENSE)

## Contributors

[![Contributors](https://contrib.rocks/image?repo=eggjs/egg-boilerplate-ts)](https://github.com/eggjs/egg-boilerplate-ts/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).
4 changes: 2 additions & 2 deletions boilerplate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ npm start

### Requirement

- Node.js >= 16.x
- Typescript >= 4.x
- Node.js >= 18.x
- Typescript >= 5.x
2 changes: 2 additions & 0 deletions boilerplate/_.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ config/**/*.js
app/**/*.map
test/**/*.map
config/**/*.map
package-lock.json
.package-lock.json
33 changes: 18 additions & 15 deletions boilerplate/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,44 @@
"typescript": true
},
"scripts": {
"start": "egg-scripts start --daemon --title=egg-server-{{name}}",
"stop": "egg-scripts stop --title=egg-server-{{name}}",
"start": "eggctl start --daemon --title=egg-server-{{name}}",
"stop": "eggctl stop --title=egg-server-{{name}}",
"dev": "egg-bin dev",
"test:local": "egg-bin test -p",
"test": "npm run lint -- --fix && npm run test:local",
"cov": "egg-bin cov -p",
"ci": "npm run lint && npm run cov && npm run tsc && npm run clean",
"test:local": "egg-bin test",
"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 start && npm stop && npm run clean",
"lint": "eslint . --ext .ts --cache",
"tsc": "tsc",
"clean": "tsc -b --clean"
"clean": "tsc -b --clean",
"prepublishOnly": "npm run clean && npm run tsc"
},
"dependencies": {
"@eggjs/tegg": "^3.5.2",
"@eggjs/tegg-aop-plugin": "^3.5.2",
"@eggjs/tegg-config": "^3.2.3",
"@eggjs/tegg-config": "^3.5.2",
"@eggjs/tegg-controller-plugin": "^3.5.2",
"@eggjs/tegg-eventbus-plugin": "^3.5.2",
"@eggjs/tegg-plugin": "^3.5.2",
"@eggjs/tegg-schedule-plugin": "^3.5.2",
"egg": "^3.15.0",
"egg-scripts": "^2.17.0",
"egg": "^4.0.0",
"@eggjs/scripts": "^4.0.0",
"egg-tracer": "^2.0.0"
},
"devDependencies": {
"@types/mocha": "10",
"@types/node": "20",
"@types/node": "22",
"@eggjs/tsconfig": "1",
"egg-bin": "6",
"egg-mock": "5",
"@eggjs/bin": "7",
"@eggjs/mock": "6",
"eslint": "8",
"eslint-config-egg": "13",
"eslint-config-egg": "14",
"typescript": "5"
},
"engines": {
"node": ">=20.10.0"
"node": ">=20.18.1"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion boilerplate/app/module/bar/controller/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Inject, HTTPController, HTTPMethod, HTTPMethodEnum } from '@eggjs/tegg'
})
export class HomeController {
@Inject()
logger: EggLogger;
private logger: EggLogger;

@HTTPMethod({
method: HTTPMethodEnum.GET,
Expand Down
2 changes: 1 addition & 1 deletion boilerplate/app/module/bar/controller/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { HelloService } from '@/module/foo';
})
export class UserController {
@Inject()
helloService: HelloService;
private helloService: HelloService;

@HTTPMethod({
method: HTTPMethodEnum.GET,
Expand Down
2 changes: 1 addition & 1 deletion boilerplate/app/module/foo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"eggModule": {
"name": "foo"
}
}
}
2 changes: 1 addition & 1 deletion boilerplate/app/module/foo/service/HelloService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SingletonProto, AccessLevel, Inject } from '@eggjs/tegg';
export class HelloService {
// 注入一个 logger
@Inject()
logger: EggLogger;
private logger: EggLogger;

// 封装业务
async hello(userId: string): Promise<string> {
Expand Down
9 changes: 8 additions & 1 deletion boilerplate/config/config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ export default (appInfo: EggAppInfo) => {
// add your egg config in here
config.middleware = [];

// change multipart mode to file
// @see https://github.com/eggjs/multipart/blob/master/src/config/config.default.ts#L104
config.multipart = {
mode: 'file',
};

// add your special config in here
// Usage: `app.config.bizConfig.sourceUrl`
const bizConfig = {
sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
};

// the return config will combines to EggAppConfig
return {
...config,
...bizConfig,
bizConfig,
};
};
2 changes: 1 addition & 1 deletion boilerplate/config/config.local.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EggAppConfig, PowerPartial } from 'egg';

export default () => {
const config: PowerPartial<EggAppConfig> = {};
const config = {} as PowerPartial<EggAppConfig>;
return config;
};
2 changes: 1 addition & 1 deletion boilerplate/config/config.prod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EggAppConfig, PowerPartial } from 'egg';

export default () => {
const config: PowerPartial<EggAppConfig> = {};
const config = {} as PowerPartial<EggAppConfig>;
return config;
};
6 changes: 6 additions & 0 deletions boilerplate/config/config.unittest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { EggAppConfig, PowerPartial } from 'egg';

export default () => {
const config = {} as PowerPartial<EggAppConfig>;
return config;
};
2 changes: 1 addition & 1 deletion boilerplate/test/app/module/bar/controller/home.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { strict as assert } from 'node:assert';
import { app } from 'egg-mock/bootstrap';
import { app } from '@eggjs/mock/bootstrap';

describe('test/app/module/bar/controller/home.test.ts', () => {
it('should GET /', async () => {
Expand Down
2 changes: 1 addition & 1 deletion boilerplate/test/app/module/bar/controller/user.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { strict as assert } from 'node:assert';
import { app } from 'egg-mock/bootstrap';
import { app } from '@eggjs/mock/bootstrap';

describe('test/app/module/bar/controller/user.test.ts', () => {
it('should GET /', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { strict as assert } from 'node:assert';
import { app } from 'egg-mock/bootstrap';
import { app } from '@eggjs/mock/bootstrap';
import { HelloService } from '@/module/foo/service/HelloService';

describe('test/app/module/foo/service/HelloService.test.js', () => {
Expand Down
3 changes: 3 additions & 0 deletions boilerplate/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"extends": "@eggjs/tsconfig",
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"declaration": false,
"paths": {
"@/module/*": ["app/module/*"]
Expand Down
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
"test": "npm run lint -- --fix && npm run test-boilerplate",
"ci": "npm run lint && npm run ci-boilerplate",
"test-boilerplate": "npm run build && npm run install-deps && cd dist && npm test",
"test-boilerplate-from-cnpm": "npm run build && npm run install-deps-from-cnpm && cd dist && npm test",
"ci-boilerplate": "npm run build && npm run install-deps && cd dist && npm run ci",
"ci-boilerplate-from-cnpm": "npm run build && npm run install-deps-from-cnpm && cd dist && npm run ci",
"clean": "rm -rf dist",
"build": "npm run clean && egg-init dist --force --silent --template=./",
"install-deps": "cd dist && npm i"
"install-deps": "cd dist && npm i",
"install-deps-from-cnpm": "cd dist && cnpm i"
},
"homepage": "https://github.com/eggjs/egg-boilerplate-ts",
"bugs": "https://github.com/eggjs/egg/issues",
Expand All @@ -21,7 +24,8 @@
"author": "TZ <[email protected]>",
"devDependencies": {
"egg-init": "^3.0.2",
"eslint": "^8.34.0",
"eslint-config-egg": "13"
}
"eslint": "8",
"eslint-config-egg": "14"
},
"license": "MIT"
}

0 comments on commit b750157

Please sign in to comment.