Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support cjs and esm both by tshy #279

Merged
merged 28 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 25 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.

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]
Comment on lines +1 to +2
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add conditions to prevent unintended publishes

Running the publish workflow on both push and pull_request events without conditions could lead to unintended publishes.

Add conditions to ensure publishing only occurs on intended events. Here's a suggested change:

name: Publish Any Commit
-on: [push, pull_request]
+on:
+  push:
+    branches: [ master ]
+    tags: [ 'v*' ]
📝 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: Publish Any Commit
on: [push, pull_request]
name: Publish Any Commit
on:
push:
branches: [ master ]
tags: [ 'v*' ]


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
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add safeguards to the publish step

The publish step lacks version and authentication checks.

Consider adding these safeguards:

-      - run: npx pkg-pr-new publish
+      - name: Publish
+        if: startsWith(github.ref, 'refs/tags/v')
+        env:
+          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+        run: |
+          echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > .npmrc
+          npx pkg-pr-new publish
📝 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
- run: npx pkg-pr-new publish
- name: Publish
if: startsWith(github.ref, 'refs/tags/v')
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > .npmrc
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",
Comment on lines +2 to +3
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Breaking changes need to be documented in CHANGELOG.md and README.md

The package introduces significant breaking changes without proper documentation:

  • Package rename from egg-bin to @eggjs/bin
  • Major version bump to 7.0.0-beta.4
  • Node.js requirement increased to >= 18.19.0
  • Switch to dual ESM/CJS support with Oclif framework

While the README.md shows the new package name in badges and installation instructions, there's no clear migration guide or documentation of breaking changes for users upgrading from previous versions. The CHANGELOG.md also lacks entries for version 7.0.0-beta.4.

  • Add a "Breaking Changes" or "Migration Guide" section in README.md
  • Document the changes in CHANGELOG.md under version 7.0.0-beta.4
  • Include upgrade steps and new requirements
🔗 Analysis chain

Breaking changes need clear documentation

This update introduces significant breaking changes:

  1. Package renamed from egg-bin to @eggjs/bin
  2. Major version bump to 7.0.0-beta.4
  3. Minimum Node.js version increased to 18.19.0

Let's verify if these breaking changes are documented:

Also applies to: 17-19


Let's gather more information to check for documentation about the specific breaking changes in the current version.


Let's check one more thing to see if there are any recent commits or PRs that might document these changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if breaking changes are documented in changelog or readme
rg -i "breaking|migration|upgrade" README.md CHANGELOG.md

Length of output: 1234


Script:

#!/bin/bash
# Check recent changes and migration guides
rg -i "7\.0\.0|@eggjs/bin|node.*18" README.md CHANGELOG.md -A 3

# Check package.json for any migration or upgrade notes
cat package.json

Length of output: 4710


Script:

#!/bin/bash
# Check recent commits and PRs for documentation
git log -n 10 --oneline

# Check if there's a migration guide or docs directory
fd -t f -e md

Length of output: 38

"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
}
Comment on lines +38 to 43
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Pin beta dependencies to specific versions for better stability

Both packages have specific beta versions available that should be used instead of the generic "beta" tag:

  • @eggjs/mock has stable beta releases up to 6.0.0-beta.5
  • egg has stable beta releases up to 4.0.0-beta.7

Update the dependencies to use specific versions:

  • Replace "@eggjs/mock": "beta" with "@eggjs/mock": "6.0.0-beta.5"
  • Replace "egg": "beta" with "egg": "4.0.0-beta.7"

This ensures consistent builds and prevents unexpected updates to newer beta versions.

🔗 Analysis chain

Verify stability of beta dependencies

The following dependencies are using beta versions:

  • @eggjs/mock: "beta"
  • egg: "beta"

While this might be intentional during development, consider pinning to specific beta versions for better reproducibility.

Let's check the stability of these beta versions:

Also applies to: 59-59

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check beta dependencies stability
# Verify if specific beta versions are available

# Check available versions
npm view @eggjs/mock versions --json
npm view egg versions --json

Length of output: 2462

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