使用 tshy 来默认支持 cjs 和 esm
### 请详细告知你的新点子（Nice Ideas）：

https://github.com/node-modules/urllib/pull/468 目前看起来没有什么问题，非常轻松就支持了。

### 修改内容

- package.json

```json
  "engines": {
    "node": ">= 18.19.0"
  },
  "devDependencies": {
    "@arethetypeswrong/cli": "^0.17.4",
    "@eggjs/tsconfig": "2",
    "@types/node": "22",
    "@types/mocha": "10",
    "@eggjs/bin": "7",
    "husky": "9",
    "lint-staged": "15",
    "oxlint": "^0.16.2",
    "prettier": "3",
    "rimraf": "6",
    "tshy": "3",
    "tshy-after": "1",
    "typescript": "5"
  },
  "scripts": {
    "lint": "oxlint",
    "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": "rimraf dist",
    "prepublishOnly": "tshy && tshy-after && attw --pack",
    "prepare": "husky"
  },
  "lint-staged": {
    "*": "prettier --write --ignore-unknown --cache",
    "*.{ts,js,json,md,yml}": [
      "prettier --ignore-unknown --write",
      "oxlint --fix"
    ]
  },
  "type": "module",
  "tshy": {
    "exports": {
      ".": "./src/index.ts",
      "./package.json": "./package.json"
    }
  },
  "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"
  },
  "files": [
    "dist",
    "src"
  ],
  "types": "./dist/commonjs/index.d.ts",
  "main": "./dist/commonjs/index.js",
  "module": "./dist/esm/index.js"
```

`.oxlintrc.json`, `.prettierrc`, `.prettierignore`, `.husky/pre-commit`

https://gist.github.com/fengmk2/e984a0e91a719837fd459b290455689a

初始化 husky 和 prettier

```bash
npx husky init
npx prettier --write .
```

插件配置

```json
"eggPlugin": {
    "name": "development",
    "env": [
      "local"
    ],
    "dependencies": [
      "watcher"
    ],
    "exports": {
      "import": "./dist/esm",
      "require": "./dist/commonjs",
      "typescript": "./src"
    }
  },
```

- pr welcome

```md
[![Node.js Version](https://img.shields.io/node/v/{pkgName}.svg?style=flat)](https://nodejs.org/en/download/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/{group}/{repo})
```

- contributors

```md
## Contributors

[![Contributors](https://contrib.rocks/image?repo={group/repo})](https://github.com/{group/repo}/graphs/contributors)

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

- commit log

```bash
feat: support cjs and esm both by tshy

BREAKING CHANGE: drop Node.js < 18.19.0 support

part of https://github.com/eggjs/egg/issues/3644

https://github.com/eggjs/egg/issues/5257
```

- `__dirname` 单测中的 helper 方法

`test/helper.ts`

```ts
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export function getFixtures(filename: string) {
  return path.join(__dirname, filename);
}
```

- 获取代码根目录

```ts
export function getSourceDirname() {
  if (typeof __dirname === 'string') {
    return __dirname;
  }
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  // @ts-ignore
  const __filename = fileURLToPath(import.meta.url);
  return path.dirname(__filename);
}
```

- `.github/workflows/nodejs.yml`
```yml
name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  Job:
    name: Node.js
    uses: node-modules/github-actions/.github/workflows/node-test.yml@master
    with:
      os: 'ubuntu-latest, macos-latest, windows-latest'
      version: '18.19.0, 18, 20, 22'
    secrets:
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
```

- `.github/workflows/release.yml`
```yml
name: Release

on:
  push:
    branches: [ master ]

jobs:
  release:
    name: Node.js
    uses: node-modules/github-actions/.github/workflows/node-release.yml@master
    secrets:
      NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
      GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
```

- `.github/workflows/pkg.pr.new.yml`
```yml
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
```

- `tsconfig.json`
```json
{
  "extends": "@eggjs/tsconfig",
  "compilerOptions": {
  }
}
```

- `.eslintrc`
```json
{
  "extends": [
    "eslint-config-egg/typescript",
    "eslint-config-egg/lib/rules/enforce-node-prefix"
  ]
}
```

- `.gitignore`

```bash
.tshy*
.eslintcache
dist
coverage
```

### Sub Error

```ts
export class ClusterAgentWorkerError extends Error {
  id: number;
  /**
   * pid in process mode
   * tid in worker_threads mode
   */
  workerId: number;
  status: string;

  constructor(id: number, workerId: number, status: string, error: Error) {
    const message = `Got agent worker error: ${error.message}`;
    super(message, { cause: error });
    this.name = this.constructor.name;
    this.id = id;
    this.workerId = workerId;
    this.status = status;
    Error.captureStackTrace(this, this.constructor);
  }
}
```