Skip to content

Commit

Permalink
feat: auto copy egg meta properties (#3)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## 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.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored Dec 22, 2024
1 parent 262e73c commit 8b1be69
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
3 changes: 1 addition & 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,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'
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down Expand Up @@ -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).
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/demo/package-init.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
});

0 comments on commit 8b1be69

Please sign in to comment.