Skip to content

Commit e3ef17b

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 fcc80da commit e3ef17b

29 files changed

+493
-510
lines changed

.eslintrc

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

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 74 deletions
This file was deleted.

.github/workflows/nodejs.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ name: CI
33
on:
44
push:
55
branches: [ master ]
6-
76
pull_request:
87
branches: [ master ]
98

10-
workflow_dispatch: {}
11-
129
jobs:
1310
Job:
1411
name: Node.js
15-
uses: artusjs/github-actions/.github/workflows/node-test.yml@v1
12+
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
1613
with:
1714
os: 'ubuntu-latest, macos-latest'
18-
version: '14, 16, 18'
15+
version: '18.19.0, 18, 20, 22'
16+
secrets:
17+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

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

Lines changed: 23 additions & 0 deletions
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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@ on:
44
push:
55
branches: [ master ]
66

7-
workflow_dispatch: {}
8-
97
jobs:
108
release:
119
name: Node.js
12-
uses: artusjs/github-actions/.github/workflows/node-release.yml@v1
10+
uses: node-modules/github-actions/.github/workflows/node-release.yml@master
1311
secrets:
1412
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
1513
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
16-
with:
17-
checkTest: false

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ results
1313

1414
node_modules
1515
npm-debug.log
16+
.tshy*
17+
.eslintcache
18+
dist

History.md renamed to CHANGELOG.md

File renamed without changes.

README.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
[![NPM version][npm-image]][npm-url]
44
[![Test coverage][cov-image]][cov-url]
55
[![npm download][download-image]][download-url]
6+
[![Node.js Version](https://img.shields.io/node/v/graceful.svg?style=flat)](https://nodejs.org/en/download/)
67

78
[npm-image]: https://img.shields.io/npm/v/graceful.svg?style=flat-square
89
[npm-url]: https://npmjs.org/package/graceful
9-
[cov-image]: https://codecov.io/github/node-modules/cfork/coverage.svg?branch=master
10-
[cov-url]: https://codecov.io/github/node-modules/cfork?branch=master
10+
[cov-image]: https://codecov.io/github/node-modules/graceful/coverage.svg?branch=master
11+
[cov-url]: https://codecov.io/github/node-modules/graceful?branch=master
1112
[download-image]: https://img.shields.io/npm/dm/graceful.svg?style=flat-square
1213
[download-url]: https://npmjs.org/package/graceful
1314

@@ -23,7 +24,7 @@ It's the best way to handle `uncaughtException` on current situations.
2324
## Install
2425

2526
```bash
26-
$ npm install graceful
27+
npm install graceful
2728
```
2829

2930
## Usage
@@ -33,10 +34,10 @@ Please see [connect_with_cluster](https://github.com/fengmk2/graceful/tree/maste
3334
This below code just for dev demo, don't use it on production env:
3435

3536
```js
36-
var express = require('express');
37-
var graceful = require('graceful');
37+
const express = require('express');
38+
const { graceful } = require('graceful');
3839

39-
var app = express()
40+
const app = express()
4041
.use()
4142
.use(function(req, res){
4243
if (Math.random() > 0.5) {
@@ -59,7 +60,7 @@ var app = express()
5960
res.end(err.message);
6061
});
6162

62-
var server = app.listen(1984);
63+
const server = app.listen(1984);
6364

6465
graceful({
6566
servers: [server],
@@ -79,24 +80,18 @@ graceful({
7980
If you are using [pm](https://github.com/aleafs/pm),
8081
you can follow the [graceful_exit with pm demo](https://github.com/aleafs/pm/tree/master/demo/graceful_exit).
8182

82-
<!-- GITCONTRIBUTOR_START -->
83-
8483
## Contributors
8584

86-
|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/985607?v=4" width="100px;"/><br/><sub><b>dead-horse</b></sub>](https://github.com/dead-horse)<br/>|[<img src="https://avatars.githubusercontent.com/u/19908330?v=4" width="100px;"/><br/><sub><b>hyj1991</b></sub>](https://github.com/hyj1991)<br/>|[<img src="https://avatars.githubusercontent.com/u/2399123?v=4" width="100px;"/><br/><sub><b>imyelo</b></sub>](https://github.com/imyelo)<br/>|
87-
| :---: | :---: | :---: | :---: |
88-
89-
90-
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Thu Sep 22 2022 19:41:57 GMT+0800`.
85+
[![Contributors](https://contrib.rocks/image?repo=node-modules/graceful)](https://github.com/node-modules/graceful/graphs/contributors)
9186

92-
<!-- GITCONTRIBUTOR_END -->
87+
Made with [contributors-img](https://contrib.rocks).
9388

9489
## License
9590

9691
(The MIT License)
9792

98-
Copyright (c) 2013 - 2014 fengmk2 &lt;[email protected]&gt;
99-
Copyright (c) 2015 - 2016 node-modules and other contributors
93+
Copyright (c) 2013 - 2014 fengmk2
94+
Copyright (c) 2015 - present node-modules and other contributors
10095

10196
Permission is hereby granted, free of charge, to any person obtaining
10297
a copy of this software and associated documentation files (the

example/express_with_cluster/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# express with cluster example
22

3-
* Master: dispatch.js
4-
* Worker: worker.js
5-
* Your application logic: app.js
3+
* Master: dispatch.cjs
4+
* Worker: worker.cjs
5+
* Your application logic: app.cjs
66

77
## Run
88

99
```bash
10-
$ node example/express_with_cluster/dispatch.js
10+
$ node example/express_with_cluster/dispatch.cjs
1111
```
1212

1313
## Test
@@ -21,10 +21,10 @@ $ curl localhost:1337/asyncerror
2121

2222
```
2323

24-
[dispatch.js](https://github.com/node-modules/graceful/blob/master/example/express_with_cluster/dispatch.js) stdout:
24+
[dispatch.cjs](https://github.com/node-modules/graceful/blob/master/example/express_with_cluster/dispatch.cjs) stdout:
2525

2626
```bash
27-
$ node example/express_with_cluster/dispatch.js
27+
$ node example/express_with_cluster/dispatch.cjs
2828
[Thu Apr 11 2013 18:45:36 GMT+0800 (CST)] [worker:21711] start listen on 1337
2929
[Thu Apr 11 2013 18:45:36 GMT+0800 (CST)] [worker:21712] start listen on 1337
3030
[uncaughtException] throw error 1 times

example/express_with_cluster/dispatch.js renamed to example/express_with_cluster/dispatch.cjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
"use strict";
2-
31
// http://nodejs.org/docs/latest/api/domain.html#domain_warning_don_t_ignore_errors
42
var cluster = require('cluster');
53
var path = require('path');
64

75
cluster.setupMaster({
8-
exec: path.join(__dirname, 'worker.js')
6+
exec: path.join(__dirname, 'worker.cjs')
97
});
108

119
// In real life, you'd probably use more than just 2 workers,

example/express_with_cluster/worker.js renamed to example/express_with_cluster/worker.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
var PORT = +process.env.PORT || 1337;
4-
var graceful = require('../../');
4+
var { graceful } = require('../../');
55
var server = require('./app');
66
server.listen(PORT);
77
console.log('[%s] [worker:%s] web server start listen on %s', new Date(), process.pid, PORT);

example/failure.js renamed to example/failure.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var http = require('http');
44
var express = require('express');
5-
var graceful = require('../');
5+
var { graceful } = require('../');
66

77
var keepAliveClient = http.request({
88
host: 'www.google.com',

0 commit comments

Comments
 (0)