Skip to content

Commit

Permalink
feat: support cjs and esm both by tshy (#279)
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

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 -->
  • Loading branch information
fengmk2 authored Dec 27, 2024
1 parent f477435 commit 7078748
Show file tree
Hide file tree
Showing 74 changed files with 1,459 additions and 1,222 deletions.
24 changes: 0 additions & 24 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

5 changes: 3 additions & 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,6 @@ jobs:
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, macos-latest, windows-latest'
version: '16.19.0, 16, 18, 20, 22'
version: '18.19.0, 18, 20, 22, 23'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/pkg.pr.new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish Any Commit
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Build
run: npm run prepublishOnly --if-present

- run: npx pkg-pr-new publish
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
node_modules/
node_modules
coverage/
test/fixtures/custom-framework-app/node_modules/

test/fixtures/demo-app/node_modules/aliyun-egg/
!test/fixtures/demo-app/node_modules/aliyun-egg/node_modules/
!test/fixtures/demo-app-esm/node_modules/

test/fixtures/ts/node_modules/aliyun-egg/
!test/fixtures/ts/node_modules/aliyun-egg/node_modules/
Expand All @@ -29,11 +30,10 @@ yarn.lock
.c8_output
.idea

bin/*.js
cmd/*.js
!bin/postinstall.js
.eslintcache
dist
test/fixtures/example-declarations/typings/
!test/fixtures/example-declarations/node_modules
.package-lock.json
.tshy*
.eslintcache
42 changes: 19 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[![Node.js Version][node-version-image]][node-version-url]

[npm-image]: https://img.shields.io/npm/v/egg-bin.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-bin
[ci-image]: https://github.com/eggjs/egg-bin/actions/workflows/nodejs.yml/badge.svg
[ci-url]: https://github.com/eggjs/egg-bin/actions/workflows/nodejs.yml
[codecov-image]: https://codecov.io/gh/eggjs/egg-bin/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/eggjs/egg-bin
[snyk-image]: https://snyk.io/test/npm/egg-bin/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-bin
[download-image]: https://img.shields.io/npm/dm/egg-bin.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-bin
[node-version-image]: https://img.shields.io/node/v/egg-bin.svg?style=flat-square
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)

[npm-image]: https://img.shields.io/npm/v/@eggjs/bin.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@eggjs/bin
[ci-image]: https://github.com/eggjs/bin/actions/workflows/nodejs.yml/badge.svg
[ci-url]: https://github.com/eggjs/bin/actions/workflows/nodejs.yml
[codecov-image]: https://codecov.io/gh/eggjs/bin/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/eggjs/bin
[snyk-image]: https://snyk.io/test/npm/@eggjs/bin/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/@eggjs/bin
[download-image]: https://img.shields.io/npm/dm/@eggjs/bin.svg?style=flat-square
[download-url]: https://npmjs.org/package/@eggjs/bin
[node-version-image]: https://img.shields.io/node/v/@eggjs/bin.svg?style=flat-square
[node-version-url]: https://nodejs.org/en/download/

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

---

## Install

```bash
npm i egg-bin --save-dev
npm i @eggjs/bin --save-dev
```

## Usage
Expand Down Expand Up @@ -77,7 +78,7 @@ egg-bin dev
#### dev options

- `--framework` egg web framework root path.
- `--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.
- `--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.
- `--workers` worker process number, default to `1` worker at local mode.
- `--sticky` start a sticky cluster server, default to `false`.

Expand All @@ -102,8 +103,6 @@ Create `.vscode/launch.json` file:
],
"console": "integratedTerminal",
"restart": true,
"protocol": "auto",
"port": 9229,
"autoAttachChildProcesses": true
},
{
Expand All @@ -117,8 +116,6 @@ Create `.vscode/launch.json` file:
"--",
"--inspect-brk"
],
"protocol": "auto",
"port": 9229,
"autoAttachChildProcesses": true
}
]
Expand Down Expand Up @@ -191,7 +188,7 @@ You can pass any mocha argv.

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

## Custom egg-bin for your team

See <https://artus-cli.github.io>
See <https://oclif.io/docs/configuring_your_cli/>

## License

[MIT](LICENSE)

## Contributors

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

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

[mocha]: https://mochajs.org
[glob]: https://github.com/isaacs/node-glob
[@artus-cli/artus-cli]: https://github.com/artus-cli/artus-cli
3 changes: 3 additions & 0 deletions bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
8 changes: 8 additions & 0 deletions bin/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env -S node --loader ts-node/esm --disable-warning=ExperimentalWarning --no-deprecation

import { execute } from '@oclif/core';

await execute({
// development: true,
dir: import.meta.url,
});
3 changes: 3 additions & 0 deletions bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
5 changes: 5 additions & 0 deletions bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

import { execute } from '@oclif/core';

await execute({ dir: import.meta.url });
140 changes: 88 additions & 52 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,86 +1,122 @@
{
"name": "egg-bin",
"version": "6.13.0",
"name": "@eggjs/bin",
"version": "7.0.0-beta.4",
"publishConfig": {
"tag": "latest"
"access": "public"
},
"description": "egg developer tool",
"files": [
"dist",
"scripts"
],
"main": "dist/index.js",
"bin": {
"egg-bin": "dist/bin/cli.js"
"repository": {
"type": "git",
"url": "git@github.com:eggjs/bin.git"
},
"bug": {
"url": "https://github.com/eggjs/egg/issues"
},
"homepage": "https://github.com/eggjs/bin",
"author": "fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)",
"engines": {
"node": ">= 18.19.0"
},
"dependencies": {
"@artus-cli/artus-cli": "^0.2.9",
"@artus-cli/plugin-autocomplete": "^0.1.1",
"@artus-cli/plugin-version": "^1.0.1",
"@eggjs/utils": "^4.0.2",
"@eggjs/utils": "^4.1.2",
"@oclif/core": "^4.2.0",
"@types/mocha": "^10.0.10",
"@types/supertest": "^6.0.2",
"c8": "^10.0.0",
"detect-port": "^2.0.0",
"egg-ts-helper": "^2.1.0",
"globby": "^11.1.0",
"jest-changed-files": "^29.4.2",
"mocha": "^10.2.0",
"mocha": "^11.0.1",
"mochawesome-with-mocha": "^7.1.3",
"runscript": "^2.0.0",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.1.2"
"tsconfig-paths": "^4.1.2",
"utility": "^2.4.0"
},
"peerDependencies": {
"egg-mock": ">=5.10.2"
"@eggjs/mock": "beta"
},
"peerDependenciesMeta": {
"egg-mock": {
"@eggjs/mock": {
"optional": true
}
},
"devDependencies": {
"@eggjs/tsconfig": "^1.3.0",
"@arethetypeswrong/cli": "^0.17.1",
"@eggjs/mock": "beta",
"@eggjs/tsconfig": "1",
"@swc-node/register": "^1.6.1",
"@swc/core": "^1.3.35",
"@types/mocha": "^10.0.1",
"@types/node": "^22.10.1",
"@types/node": "22",
"assert-file": "^1.0.0",
"coffee": "^5.4.0",
"coffee": "^5.5.1",
"cpy": "^8.1.2",
"egg": "^3.9.1",
"egg-mock": "^5.10.2",
"cpy-cli": "^5.0.0",
"cross-env": "^7.0.3",
"egg": "beta",
"esbuild": "^0.17.7",
"esbuild-register": "^3.4.2",
"eslint": "^8.16.0",
"eslint-config-egg": "^13.1.0",
"npminstall": "^7.5.0",
"typescript": "^5.2.2"
"eslint": "8",
"eslint-config-egg": "14",
"npminstall": "^7.12.0",
"rimraf": "6",
"supertest": "^7.0.0",
"tshy": "3",
"tshy-after": "1",
"typescript": "5"
},
"repository": {
"type": "git",
"url": "git@github.com:eggjs/egg-bin.git"
"scripts": {
"postinstall-skip": "node scripts/postinstall.mjs",
"lint": "eslint --cache src test --ext .ts",
"pretest": "npm run clean && npm run lint -- --fix && npm run prepublishOnly",
"test": "node bin/run.js test",
"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",
"preci": "npm run clean && npm run lint && npm run prepublishOnly",
"ci": "npm run cov",
"clean": "rimraf dist",
"copyScripts": "rimraf dist/scripts && cpy scripts dist",
"prepublishOnly": "tshy && tshy-after && attw --pack && npm run copyScripts"
},
"bug": {
"url": "https://github.com/eggjs/egg/issues"
"type": "module",
"tshy": {
"exports": {
".": "./src/index.ts",
"./package.json": "./package.json"
}
},
"homepage": "https://github.com/eggjs/egg-bin",
"author": "fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)",
"scripts": {
"postinstall": "node scripts/postinstall.js",
"contributor": "git-contributor",
"lint": "eslint . --cache --ext ts",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "npm run tsc && node dist/bin/cli.js test",
"test-local-with-ts-node-transpile-only": "node -r ts-node/register/transpile-only src/bin/cli.ts test",
"test-local-with-swc": "node -r @swc-node/register src/bin/cli.ts test",
"test-local-with-esbuild": "node -r esbuild-register src/bin/cli.ts test",
"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",
"cov": "c8 -r lcov -r text-summary -x 'test/**' npm run test-local -- --timeout 120000",
"ci": "npm run lint && npm run test-local && npm run test-tsc",
"prepublishOnly": "npm run clean && npm run tsc",
"tsc": "tsc",
"clean": "rm -rf dist"
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
},
"./package.json": "./package.json"
},
"engines": {
"node": ">= 16.19.0"
"files": [
"bin",
"dist",
"src",
"scripts"
],
"bin": {
"egg-bin": "./bin/run.js"
},
"types": "./dist/commonjs/index.d.ts",
"main": "./dist/commonjs/index.js",
"module": "./dist/esm/index.js",
"oclif": {
"bin": "egg-bin",
"commands": "./dist/esm/commands",
"dirname": "egg-bin",
"topicSeparator": " ",
"additionalHelpFlags": [
"-h"
]
}
}
4 changes: 0 additions & 4 deletions scripts/.eslintrc

This file was deleted.

Loading

0 comments on commit 7078748

Please sign in to comment.