Skip to content

Commit 7c0c72f

Browse files
committed
feat: support cjs and esm both by tshy
BREAKING CHANGE: drop Node.js < 18.19.0 support part of eggjs/egg#3644 eggjs/egg#5257
1 parent c60f540 commit 7c0c72f

28 files changed

+486
-382
lines changed

.autod.conf.js

-25
This file was deleted.

.eslintrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"extends": "eslint-config-egg"
2+
"extends": [
3+
"eslint-config-egg/typescript",
4+
"eslint-config-egg/lib/rules/enforce-node-prefix"
5+
]
36
}

.github/PULL_REQUEST_TEMPLATE.md

-24
This file was deleted.

.github/workflows/nodejs.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
Job:
11+
name: Node.js
12+
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
13+
with:
14+
version: '18.19.0, 20, 22'
15+
secrets:
16+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/pkg.pr.new.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Publish Any Commit
2+
on: [push, pull_request]
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- name: Checkout code
10+
uses: actions/checkout@v4
11+
12+
- run: corepack enable
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: 20
16+
17+
- name: Install dependencies
18+
run: npm install
19+
20+
- name: Build
21+
run: npm run prepublishOnly --if-present
22+
23+
- run: npx pkg-pr-new publish

.github/workflows/release.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
7+
jobs:
8+
release:
9+
name: Node.js
10+
uses: eggjs/github-actions/.github/workflows/node-release.yml@master
11+
secrets:
12+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
13+
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}

.gitignore

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ logs/
22
npm-debug.log
33
node_modules/
44
coverage/
5-
.idea/
6-
run/
5+
test/fixtures/**/run
76
.DS_Store
8-
*.swp
9-
7+
.tshy*
8+
.eslintcache
9+
dist
10+
package-lock.json
11+
.package-lock.json

.travis.yml

-13
This file was deleted.

History.md renamed to CHANGELOG.md

File renamed without changes.

README.md

+66-45
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,77 @@
1-
# egg-jsonp
1+
# @eggjs/jsonp
22

33
[![NPM version][npm-image]][npm-url]
4-
[![build status][travis-image]][travis-url]
4+
[![Node.js CI](https://github.com/eggjs/jsonp/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/jsonp/actions/workflows/nodejs.yml)
55
[![Test coverage][codecov-image]][codecov-url]
6-
[![David deps][david-image]][david-url]
76
[![Known Vulnerabilities][snyk-image]][snyk-url]
87
[![npm download][download-image]][download-url]
9-
10-
[npm-image]: https://img.shields.io/npm/v/egg-jsonp.svg?style=flat-square
11-
[npm-url]: https://npmjs.org/package/egg-jsonp
12-
[travis-image]: https://img.shields.io/travis/eggjs/egg-jsonp.svg?style=flat-square
13-
[travis-url]: https://travis-ci.org/eggjs/egg-jsonp
14-
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-jsonp.svg?style=flat-square
15-
[codecov-url]: https://codecov.io/github/eggjs/egg-jsonp?branch=master
16-
[david-image]: https://img.shields.io/david/eggjs/egg-jsonp.svg?style=flat-square
17-
[david-url]: https://david-dm.org/eggjs/egg-jsonp
18-
[snyk-image]: https://snyk.io/test/npm/egg-jsonp/badge.svg?style=flat-square
19-
[snyk-url]: https://snyk.io/test/npm/egg-jsonp
20-
[download-image]: https://img.shields.io/npm/dm/egg-jsonp.svg?style=flat-square
21-
[download-url]: https://npmjs.org/package/egg-jsonp
8+
[![Node.js Version](https://img.shields.io/node/v/@eggjs/jsonp.svg?style=flat)](https://nodejs.org/en/download/)
9+
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)
10+
11+
[npm-image]: https://img.shields.io/npm/v/@eggjs/jsonp.svg?style=flat-square
12+
[npm-url]: https://npmjs.org/package/@eggjs/jsonp
13+
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/jsonp.svg?style=flat-square
14+
[codecov-url]: https://codecov.io/github/eggjs/jsonp?branch=master
15+
[snyk-image]: https://snyk.io/test/npm/@eggjs/jsonp/badge.svg?style=flat-square
16+
[snyk-url]: https://snyk.io/test/npm/@eggjs/jsonp
17+
[download-image]: https://img.shields.io/npm/dm/@eggjs/jsonp.svg?style=flat-square
18+
[download-url]: https://npmjs.org/package/@eggjs/jsonp
2219

2320
An egg plugin for jsonp support.
2421

22+
## Requirements
23+
24+
- egg >= 4.x
25+
2526
## Install
2627

2728
```bash
28-
$ npm i egg-jsonp --save
29+
npm i @eggjs/jsonp
2930
```
3031

3132
## Usage
3233

33-
```js
34-
// {app_root}/config/plugin.js
35-
exports.jsonp = {
36-
enable: true,
37-
package: 'egg-jsonp',
34+
```ts
35+
// {app_root}/config/plugin.ts
36+
37+
export default {
38+
jsonp: {
39+
enable: true,
40+
package: '@eggjs/jsonp',
41+
},
3842
};
3943
```
4044

4145
## Configuration
4246

43-
* {String|Array} callback - jsonp callback method key, default to `[ '_callback', 'callback' ]`
44-
* {Number} limit - callback method name's max length, default to `50`
45-
* {Boolean} csrf - enable csrf check or not. default to false
46-
* {String|RegExp|Array} whiteList - referrer white list
47+
- {String|Array} callback - jsonp callback method key, default to `[ '_callback', 'callback' ]`
48+
- {Number} limit - callback method name's max length, default to `50`
49+
- {Boolean} csrf - enable csrf check or not. default to false
50+
- {String|RegExp|Array} whiteList - referrer white list
4751

4852
if whiteList's type is `RegExp`, referrer must match `whiteList`, pay attention to the first `^` and last `/`.
4953

50-
```js
51-
exports.jsonp = {
52-
whiteList: /^https?:\/\/test.com\//,
53-
}
54+
```ts
55+
export default {
56+
jsonp: {
57+
whiteList: /^https?:\/\/test.com\//,
58+
},
59+
};
60+
5461
// matchs referrer:
5562
// https://test.com/hello
5663
// http://test.com/
5764
```
5865

5966
if whiteList's type is `String` and starts with `.`:
6067

61-
```js
62-
exports.jsonp = {
63-
whiteList: '.test.com',
68+
```ts
69+
export default {
70+
jsonp: {
71+
whiteList: '.test.com',
72+
},
6473
};
74+
6575
// matchs domain test.com:
6676
// https://test.com/hello
6777
// http://test.com/
@@ -73,40 +83,46 @@ exports.jsonp = {
7383

7484
if whiteList's type is `String` and not starts with `.`:
7585

76-
```js
77-
exports.jsonp = {
78-
whiteList: 'sub.test.com',
86+
```ts
87+
export default {
88+
jsonp: {
89+
whiteList: 'sub.test.com',
90+
},
7991
};
92+
8093
// only matchs domain sub.test.com:
8194
// https://sub.test.com/hello
8295
// http://sub.test.com/
8396
```
8497

8598
whiteList also can be an array:
8699

87-
```js
88-
exports.jsonp = {
89-
whiteList: [ '.foo.com', '.bar.com' ],
100+
```ts
101+
export default {
102+
jsonp: {
103+
whiteList: [ '.foo.com', '.bar.com' ],
104+
},
90105
};
91106
```
92107

93-
see [config/config.default.js](https://github.com/eggjs/egg-jsonp/blob/master/config/config.default.js) for more detail.
108+
see [config/config.default.ts](https://github.com/eggjs/jsonp/blob/master/src/config/config.default.ts) for more detail.
94109

95110
## API
96111

97-
* ctx.acceptJSONP - detect if response should be jsonp, readonly
112+
- ctx.acceptJSONP - detect if response should be jsonp, readonly
98113

99114
## Example
100115

101-
In `app/router.js`
116+
In `app/router.ts`
102117

103-
```js
118+
```ts
104119
// Create once and use in any router you want to support jsonp.
105120
const jsonp = app.jsonp();
121+
106122
app.get('/default', jsonp, 'jsonp.index');
107123
app.get('/another', jsonp, 'jsonp.another');
108124

109-
// Customize by create another jsonp middleware with specific sonfigurations.
125+
// Customize by create another jsonp middleware with specific configurations.
110126
app.get('/customize', app.jsonp({ callback: 'fn' }), 'jsonp.customize');
111127
```
112128

@@ -116,5 +132,10 @@ Please open an issue [here](https://github.com/eggjs/egg/issues).
116132

117133
## License
118134

119-
[MIT](https://github.com/eggjs/egg-jsonp/blob/master/LICENSE)
135+
[MIT](LICENSE)
136+
137+
## Contributors
138+
139+
[![Contributors](https://contrib.rocks/image?repo=eggjs/jsonp)](https://github.com/eggjs/jsonp/graphs/contributors)
120140

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

0 commit comments

Comments
 (0)