Skip to content

Commit 7078748

Browse files
authored
feat: support cjs and esm both by tshy (#279)
BREAKING CHANGE: drop Node.js < 18.19.0 support part of eggjs/egg#3644 eggjs/egg#5257 use https://oclif.io <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Removed pull request template for contributors. - Introduced a new workflow for automating commit publishing. - Added scripts for executing Node.js applications in development mode. - Updated the README to reflect the new package name and other details. - Enhanced command classes for testing and development functionalities. - Added new utility functions for better path handling in tests. - Introduced new interface for package configuration. - Added support for TypeScript with updated configurations. - Implemented a new logging mechanism in hooks for better debugging. - Introduced a new class for managing server readiness in demo applications. - **Bug Fixes** - Adjusted import paths in tests for compatibility with new module structure. - **Documentation** - Updated README and various documentation links to reflect changes in package structure. - **Chores** - Updated package configurations, including versioning and dependencies. - Removed obsolete files and configurations from the project. - Enhanced test suite structure and clarity. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent f477435 commit 7078748

74 files changed

Lines changed: 1459 additions & 1222 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/nodejs.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: CI
33
on:
44
push:
55
branches: [ master ]
6-
76
pull_request:
87
branches: [ master ]
98

@@ -13,4 +12,6 @@ jobs:
1312
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
1413
with:
1514
os: 'ubuntu-latest, macos-latest, windows-latest'
16-
version: '16.19.0, 16, 18, 20, 22'
15+
version: '18.19.0, 18, 20, 22, 23'
16+
secrets:
17+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/pkg.pr.new.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Publish Any Commit
2+
on: [push, pull_request]
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- name: Checkout code
10+
uses: actions/checkout@v4
11+
12+
- run: corepack enable
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: 20
16+
17+
- name: Install dependencies
18+
run: npm install
19+
20+
- name: Build
21+
run: npm run prepublishOnly --if-present
22+
23+
- run: npx pkg-pr-new publish

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
node_modules/
1+
node_modules
22
coverage/
33
test/fixtures/custom-framework-app/node_modules/
44

55
test/fixtures/demo-app/node_modules/aliyun-egg/
66
!test/fixtures/demo-app/node_modules/aliyun-egg/node_modules/
7+
!test/fixtures/demo-app-esm/node_modules/
78

89
test/fixtures/ts/node_modules/aliyun-egg/
910
!test/fixtures/ts/node_modules/aliyun-egg/node_modules/
@@ -29,11 +30,10 @@ yarn.lock
2930
.c8_output
3031
.idea
3132

32-
bin/*.js
33-
cmd/*.js
34-
!bin/postinstall.js
3533
.eslintcache
3634
dist
3735
test/fixtures/example-declarations/typings/
3836
!test/fixtures/example-declarations/node_modules
3937
.package-lock.json
38+
.tshy*
39+
.eslintcache

README.md

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,29 @@
66
[![Known Vulnerabilities][snyk-image]][snyk-url]
77
[![npm download][download-image]][download-url]
88
[![Node.js Version][node-version-image]][node-version-url]
9-
10-
[npm-image]: https://img.shields.io/npm/v/egg-bin.svg?style=flat-square
11-
[npm-url]: https://npmjs.org/package/egg-bin
12-
[ci-image]: https://github.com/eggjs/egg-bin/actions/workflows/nodejs.yml/badge.svg
13-
[ci-url]: https://github.com/eggjs/egg-bin/actions/workflows/nodejs.yml
14-
[codecov-image]: https://codecov.io/gh/eggjs/egg-bin/branch/master/graph/badge.svg
15-
[codecov-url]: https://codecov.io/gh/eggjs/egg-bin
16-
[snyk-image]: https://snyk.io/test/npm/egg-bin/badge.svg?style=flat-square
17-
[snyk-url]: https://snyk.io/test/npm/egg-bin
18-
[download-image]: https://img.shields.io/npm/dm/egg-bin.svg?style=flat-square
19-
[download-url]: https://npmjs.org/package/egg-bin
20-
[node-version-image]: https://img.shields.io/node/v/egg-bin.svg?style=flat-square
9+
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
10+
11+
[npm-image]: https://img.shields.io/npm/v/@eggjs/bin.svg?style=flat-square
12+
[npm-url]: https://npmjs.org/package/@eggjs/bin
13+
[ci-image]: https://github.com/eggjs/bin/actions/workflows/nodejs.yml/badge.svg
14+
[ci-url]: https://github.com/eggjs/bin/actions/workflows/nodejs.yml
15+
[codecov-image]: https://codecov.io/gh/eggjs/bin/branch/master/graph/badge.svg
16+
[codecov-url]: https://codecov.io/gh/eggjs/bin
17+
[snyk-image]: https://snyk.io/test/npm/@eggjs/bin/badge.svg?style=flat-square
18+
[snyk-url]: https://snyk.io/test/npm/@eggjs/bin
19+
[download-image]: https://img.shields.io/npm/dm/@eggjs/bin.svg?style=flat-square
20+
[download-url]: https://npmjs.org/package/@eggjs/bin
21+
[node-version-image]: https://img.shields.io/node/v/@eggjs/bin.svg?style=flat-square
2122
[node-version-url]: https://nodejs.org/en/download/
2223

23-
egg developer tool, extends [@artus-cli/artus-cli].
24+
egg developer tool, base on [oclif](https://oclif.io/).
2425

2526
---
2627

2728
## Install
2829

2930
```bash
30-
npm i egg-bin --save-dev
31+
npm i @eggjs/bin --save-dev
3132
```
3233

3334
## Usage
@@ -77,7 +78,7 @@ egg-bin dev
7778
#### dev options
7879

7980
- `--framework` egg web framework root path.
80-
- `--port` server port. If not specified, the port is obtained in the following order: [_egg.js_ configuration](https://www.eggjs.org/basics/config) `config/config.*.js` > `process.env.EGG_BIN_DEFAULT_PORT` > 7001 > other available ports.
81+
- `--port` server port. If not specified, the port is obtained in the following order: [_egg.js_ configuration](https://eggjs.org/basics/config) `config/config.*.js` > `process.env.EGG_BIN_DEFAULT_PORT` > 7001 > other available ports.
8182
- `--workers` worker process number, default to `1` worker at local mode.
8283
- `--sticky` start a sticky cluster server, default to `false`.
8384

@@ -102,8 +103,6 @@ Create `.vscode/launch.json` file:
102103
],
103104
"console": "integratedTerminal",
104105
"restart": true,
105-
"protocol": "auto",
106-
"port": 9229,
107106
"autoAttachChildProcesses": true
108107
},
109108
{
@@ -117,8 +116,6 @@ Create `.vscode/launch.json` file:
117116
"--",
118117
"--inspect-brk"
119118
],
120-
"protocol": "auto",
121-
"port": 9229,
122119
"autoAttachChildProcesses": true
123120
}
124121
]
@@ -191,7 +188,7 @@ You can pass any mocha argv.
191188

192189
- `-x` add dir ignore coverage, support multiple argv
193190
- `--prerequire` prerequire files for coverage instrument, you can use this options if load files slowly when call `mm.app` or `mm.cluster`
194-
- `--typescript` / `--ts` enable typescript support. If true, will auto add `.ts` extension and ignore `typings` and `d.ts`.
191+
- `--typescript` enable typescript support. If `true`, will auto add `.ts` extension and ignore `typings` and `d.ts`.
195192
- `--c8` c8 instruments passthrough. you can use this to overwrite egg-bin's default c8 instruments and add additional ones.
196193
>
197194
> - egg-bin have some default instruments passed to c8 like `-r` and `--temp-directory`
@@ -209,18 +206,17 @@ COV_EXCLUDES="app/plugins/c*,app/autocreate/**" egg-bin cov
209206

210207
## Custom egg-bin for your team
211208

212-
See <https://artus-cli.github.io>
209+
See <https://oclif.io/docs/configuring_your_cli/>
213210

214211
## License
215212

216213
[MIT](LICENSE)
217214

218215
## Contributors
219216

220-
[![Contributors](https://contrib.rocks/image?repo=eggjs/egg-bin)](https://github.com/eggjs/egg-bin/graphs/contributors)
217+
[![Contributors](https://contrib.rocks/image?repo=eggjs/bin)](https://github.com/eggjs/bin/graphs/contributors)
221218

222219
Made with [contributors-img](https://contrib.rocks).
223220

224221
[mocha]: https://mochajs.org
225222
[glob]: https://github.com/isaacs/node-glob
226-
[@artus-cli/artus-cli]: https://github.com/artus-cli/artus-cli

bin/dev.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*

bin/dev.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env -S node --loader ts-node/esm --disable-warning=ExperimentalWarning --no-deprecation
2+
3+
import { execute } from '@oclif/core';
4+
5+
await execute({
6+
// development: true,
7+
dir: import.meta.url,
8+
});

bin/run.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
node "%~dp0\run" %*

bin/run.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
import { execute } from '@oclif/core';
4+
5+
await execute({ dir: import.meta.url });

package.json

Lines changed: 88 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,122 @@
11
{
2-
"name": "egg-bin",
3-
"version": "6.13.0",
2+
"name": "@eggjs/bin",
3+
"version": "7.0.0-beta.4",
44
"publishConfig": {
5-
"tag": "latest"
5+
"access": "public"
66
},
77
"description": "egg developer tool",
8-
"files": [
9-
"dist",
10-
"scripts"
11-
],
12-
"main": "dist/index.js",
13-
"bin": {
14-
"egg-bin": "dist/bin/cli.js"
8+
"repository": {
9+
"type": "git",
10+
"url": "git@github.com:eggjs/bin.git"
11+
},
12+
"bug": {
13+
"url": "https://github.com/eggjs/egg/issues"
14+
},
15+
"homepage": "https://github.com/eggjs/bin",
16+
"author": "fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)",
17+
"engines": {
18+
"node": ">= 18.19.0"
1519
},
1620
"dependencies": {
17-
"@artus-cli/artus-cli": "^0.2.9",
18-
"@artus-cli/plugin-autocomplete": "^0.1.1",
19-
"@artus-cli/plugin-version": "^1.0.1",
20-
"@eggjs/utils": "^4.0.2",
21+
"@eggjs/utils": "^4.1.2",
22+
"@oclif/core": "^4.2.0",
23+
"@types/mocha": "^10.0.10",
24+
"@types/supertest": "^6.0.2",
2125
"c8": "^10.0.0",
2226
"detect-port": "^2.0.0",
2327
"egg-ts-helper": "^2.1.0",
2428
"globby": "^11.1.0",
2529
"jest-changed-files": "^29.4.2",
26-
"mocha": "^10.2.0",
30+
"mocha": "^11.0.1",
2731
"mochawesome-with-mocha": "^7.1.3",
2832
"runscript": "^2.0.0",
2933
"ts-node": "^10.9.2",
30-
"tsconfig-paths": "^4.1.2"
34+
"tsconfig-paths": "^4.1.2",
35+
"utility": "^2.4.0"
3136
},
3237
"peerDependencies": {
33-
"egg-mock": ">=5.10.2"
38+
"@eggjs/mock": "beta"
3439
},
3540
"peerDependenciesMeta": {
36-
"egg-mock": {
41+
"@eggjs/mock": {
3742
"optional": true
3843
}
3944
},
4045
"devDependencies": {
41-
"@eggjs/tsconfig": "^1.3.0",
46+
"@arethetypeswrong/cli": "^0.17.1",
47+
"@eggjs/mock": "beta",
48+
"@eggjs/tsconfig": "1",
4249
"@swc-node/register": "^1.6.1",
4350
"@swc/core": "^1.3.35",
44-
"@types/mocha": "^10.0.1",
45-
"@types/node": "^22.10.1",
51+
"@types/node": "22",
4652
"assert-file": "^1.0.0",
47-
"coffee": "^5.4.0",
53+
"coffee": "^5.5.1",
4854
"cpy": "^8.1.2",
49-
"egg": "^3.9.1",
50-
"egg-mock": "^5.10.2",
55+
"cpy-cli": "^5.0.0",
56+
"cross-env": "^7.0.3",
57+
"egg": "beta",
5158
"esbuild": "^0.17.7",
5259
"esbuild-register": "^3.4.2",
53-
"eslint": "^8.16.0",
54-
"eslint-config-egg": "^13.1.0",
55-
"npminstall": "^7.5.0",
56-
"typescript": "^5.2.2"
60+
"eslint": "8",
61+
"eslint-config-egg": "14",
62+
"npminstall": "^7.12.0",
63+
"rimraf": "6",
64+
"supertest": "^7.0.0",
65+
"tshy": "3",
66+
"tshy-after": "1",
67+
"typescript": "5"
5768
},
58-
"repository": {
59-
"type": "git",
60-
"url": "git@github.com:eggjs/egg-bin.git"
69+
"scripts": {
70+
"postinstall-skip": "node scripts/postinstall.mjs",
71+
"lint": "eslint --cache src test --ext .ts",
72+
"pretest": "npm run clean && npm run lint -- --fix && npm run prepublishOnly",
73+
"test": "node bin/run.js test",
74+
"cov": "c8 --temp-directory node_modules/.c8_output -r text-summary -r json-summary -r json -r lcov -r cobertura node bin/run.js test",
75+
"preci": "npm run clean && npm run lint && npm run prepublishOnly",
76+
"ci": "npm run cov",
77+
"clean": "rimraf dist",
78+
"copyScripts": "rimraf dist/scripts && cpy scripts dist",
79+
"prepublishOnly": "tshy && tshy-after && attw --pack && npm run copyScripts"
6180
},
62-
"bug": {
63-
"url": "https://github.com/eggjs/egg/issues"
81+
"type": "module",
82+
"tshy": {
83+
"exports": {
84+
".": "./src/index.ts",
85+
"./package.json": "./package.json"
86+
}
6487
},
65-
"homepage": "https://github.com/eggjs/egg-bin",
66-
"author": "fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)",
67-
"scripts": {
68-
"postinstall": "node scripts/postinstall.js",
69-
"contributor": "git-contributor",
70-
"lint": "eslint . --cache --ext ts",
71-
"test": "npm run lint -- --fix && npm run test-local",
72-
"test-local": "npm run tsc && node dist/bin/cli.js test",
73-
"test-local-with-ts-node-transpile-only": "node -r ts-node/register/transpile-only src/bin/cli.ts test",
74-
"test-local-with-swc": "node -r @swc-node/register src/bin/cli.ts test",
75-
"test-local-with-esbuild": "node -r esbuild-register src/bin/cli.ts test",
76-
"test-tsc": "npm run clean && npm run tsc && node dist/bin/cli.js && node dist/bin/cli.js test --base test/fixtures/example-ts && node dist/bin/cli.js dev --base test/fixtures/example-ts",
77-
"cov": "c8 -r lcov -r text-summary -x 'test/**' npm run test-local -- --timeout 120000",
78-
"ci": "npm run lint && npm run test-local && npm run test-tsc",
79-
"prepublishOnly": "npm run clean && npm run tsc",
80-
"tsc": "tsc",
81-
"clean": "rm -rf dist"
88+
"exports": {
89+
".": {
90+
"import": {
91+
"types": "./dist/esm/index.d.ts",
92+
"default": "./dist/esm/index.js"
93+
},
94+
"require": {
95+
"types": "./dist/commonjs/index.d.ts",
96+
"default": "./dist/commonjs/index.js"
97+
}
98+
},
99+
"./package.json": "./package.json"
82100
},
83-
"engines": {
84-
"node": ">= 16.19.0"
101+
"files": [
102+
"bin",
103+
"dist",
104+
"src",
105+
"scripts"
106+
],
107+
"bin": {
108+
"egg-bin": "./bin/run.js"
109+
},
110+
"types": "./dist/commonjs/index.d.ts",
111+
"main": "./dist/commonjs/index.js",
112+
"module": "./dist/esm/index.js",
113+
"oclif": {
114+
"bin": "egg-bin",
115+
"commands": "./dist/esm/commands",
116+
"dirname": "egg-bin",
117+
"topicSeparator": " ",
118+
"additionalHelpFlags": [
119+
"-h"
120+
]
85121
}
86122
}

0 commit comments

Comments
 (0)