From 8b1be69fc1f9717c1846456c4687d88a17a6ff66 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 22 Dec 2024 22:56:16 +0800 Subject: [PATCH] feat: auto copy egg meta properties (#3) ## Summary by CodeRabbit - **New Features** - Enhanced documentation in the README with new sections and badges for better visibility. - Added `eggPlugin` and `egg` properties to the output package metadata. - Introduced configuration options for Egg.js integration in package-init.json. - **Bug Fixes** - Improved test coverage with additional assertions for the generated package structure. - **Chores** - Updated Node.js version support in CI workflow. - Updated dependency versions in package.json. --- .github/workflows/nodejs.yml | 3 +-- README.md | 24 ++++++++++++++++++++++++ package.json | 4 ++-- src/index.ts | 2 ++ test/fixtures/demo/package-init.json | 10 ++++++++++ test/index.test.ts | 10 ++++++++++ 6 files changed, 49 insertions(+), 4 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 8f7d65c..625e294 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -3,7 +3,6 @@ name: CI on: push: branches: [ master ] - pull_request: branches: [ master ] @@ -13,4 +12,4 @@ jobs: uses: node-modules/github-actions/.github/workflows/node-test.yml@master with: os: 'ubuntu-latest, windows-latest' - version: '16, 18, 20, 22' + version: '16, 18, 20, 22, 23' diff --git a/README.md b/README.md index 7a94dee..5e3325c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,15 @@ # tshy-after +[![NPM version][npm-image]][npm-url] +[![Node.js CI](https://github.com/node-modules/tshy-after/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/tshy-after/actions/workflows/nodejs.yml) +[![npm download][download-image]][download-url] +[![Node.js Version](https://img.shields.io/node/v/tshy-after.svg?style=flat)](https://nodejs.org/en/download/) + +[npm-image]: https://img.shields.io/npm/v/tshy-after.svg?style=flat-square +[npm-url]: https://npmjs.org/package/tshy-after +[download-image]: https://img.shields.io/npm/dm/tshy-after.svg?style=flat-square +[download-url]: https://npmjs.org/package/tshy-after + Auto set package.json after [tshy](https://github.com/isaacs/tshy) run ## keep `types` @@ -28,3 +38,17 @@ export function getDirname() { return path.dirname(fileURLToPath(import.meta.url)); } ``` + +## Auto copy egg meta properties package.json + +Copy `eggPlugin`, `egg` to `dist/package.json` + +## License + +[MIT](LICENSE) + +## Contributors + +[![Contributors](https://contrib.rocks/image?repo=node-modules/tshy-after)](https://github.com/node-modules/tshy-after/graphs/contributors) + +Made with [contributors-img](https://contrib.rocks). diff --git a/package.json b/package.json index 26c34bb..125fc24 100644 --- a/package.json +++ b/package.json @@ -27,10 +27,10 @@ "homepage": "https://github.com/node-modules/tshy-after#readme", "devDependencies": { "@types/mocha": "^10.0.1", - "@types/node": "^20.6.2", + "@types/node": "^22.10.2", "coffee": "^5.5.0", "egg-bin": "^6.5.2", - "tshy": "^2.0.0" + "tshy": "^3.0.2" }, "type": "module", "tshy": { diff --git a/src/index.ts b/src/index.ts index 0161bf9..3270c07 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,8 @@ writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n') writeFileSync('dist/package.json', JSON.stringify({ name: pkg.name, version: pkg.version, + eggPlugin: pkg.eggPlugin, + egg: pkg.egg, }, null, 2) + '\n') // Replace all `( import.meta.url )` into `('import_meta_url_placeholder_by_tshy_after')` on commonjs. diff --git a/test/fixtures/demo/package-init.json b/test/fixtures/demo/package-init.json index 9154866..d29ae4b 100644 --- a/test/fixtures/demo/package-init.json +++ b/test/fixtures/demo/package-init.json @@ -25,6 +25,16 @@ "url": "https://github.com/node-modules/tshy-after/issues" }, "homepage": "https://github.com/node-modules/tshy-after#readme", + "eggPlugin": { + "name": "egg-mock", + "exports": { + "import": "./dist/esm", + "require": "./dist/commonjs" + } + }, + "egg": { + "framework": true + }, "devDependencies": { "@types/mocha": "^10.0.1", "@types/node": "^20.6.2", diff --git a/test/index.test.ts b/test/index.test.ts index 8c3a6e3..a9bf9ad 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -57,5 +57,15 @@ describe('test/index.test.ts', () => { const distPkg = JSON.parse(fs.readFileSync(distPackageFile, 'utf-8')); assert.equal(distPkg.name, 'tshy-after'); assert.equal(distPkg.version, '1.0.0'); + assert.deepEqual(distPkg.eggPlugin, { + "name": "egg-mock", + "exports": { + "import": "./dist/esm", + "require": "./dist/commonjs" + }, + }); + assert.deepEqual(distPkg.egg, { + framework: true, + }); }); });