-
Notifications
You must be signed in to change notification settings - Fork 13
feat: support cjs and esm both by tshy #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "extends": [ | ||
| "eslint-config-egg/typescript", | ||
| "eslint-config-egg/lib/rules/enforce-node-prefix" | ||
| ] | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,6 @@ results | |
|
|
||
| node_modules | ||
| npm-debug.log | ||
| .tshy* | ||
| .eslintcache | ||
| dist | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| The MIT License (MIT) | ||
|
|
||
| Copyright (c) 2013 - 2014 fengmk2 | ||
| Copyright (c) 2015 - present node-modules and other contributors | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,12 @@ | |
| [![NPM version][npm-image]][npm-url] | ||
| [![Test coverage][cov-image]][cov-url] | ||
| [![npm download][download-image]][download-url] | ||
| [](https://nodejs.org/en/download/) | ||
|
|
||
| [npm-image]: https://img.shields.io/npm/v/graceful.svg?style=flat-square | ||
| [npm-url]: https://npmjs.org/package/graceful | ||
| [cov-image]: https://codecov.io/github/node-modules/cfork/coverage.svg?branch=master | ||
| [cov-url]: https://codecov.io/github/node-modules/cfork?branch=master | ||
| [cov-image]: https://codecov.io/github/node-modules/graceful/coverage.svg?branch=master | ||
| [cov-url]: https://codecov.io/github/node-modules/graceful?branch=master | ||
| [download-image]: https://img.shields.io/npm/dm/graceful.svg?style=flat-square | ||
| [download-url]: https://npmjs.org/package/graceful | ||
|
|
||
|
|
@@ -17,26 +18,25 @@ Graceful exit when `uncaughtException` emit, base on `process.on('uncaughtExcept | |
|
|
||
| It's the best way to handle `uncaughtException` on current situations. | ||
|
|
||
| * [domain failure](https://github.com/fengmk2/domain-middleware/blob/master/example/failure.js). | ||
| * [Node.js 异步异常的处理与domain模块解析](http://deadhorse.me/nodejs/2013/04/13/exception_and_domain.html) | ||
|
|
||
| ## Install | ||
|
|
||
| ```bash | ||
| $ npm install graceful | ||
| npm install graceful | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| Please see [connect_with_cluster](https://github.com/fengmk2/graceful/tree/master/example/connect_with_cluster) example. | ||
| Please see [express_with_cluster](https://github.com/node-modules/graceful/tree/master/example/express_with_cluster) example. | ||
|
|
||
| This below code just for dev demo, don't use it on production env: | ||
|
|
||
| ```js | ||
| var express = require('express'); | ||
| var graceful = require('graceful'); | ||
| const express = require('express'); | ||
| const { graceful } = require('graceful'); | ||
|
Comment on lines
+36
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add ESM import example alongside CJS The example only shows CommonJS require syntax, but the PR adds ESM support. Should include both import styles for completeness. Add ESM example: +// CommonJS
const express = require('express');
const { graceful } = require('graceful');
+// ESM
+import express from 'express';
+import { graceful } from 'graceful';Also applies to: 40-40, 63-63 |
||
|
|
||
| var app = express() | ||
| const app = express() | ||
| .use() | ||
| .use(function(req, res){ | ||
| if (Math.random() > 0.5) { | ||
|
|
@@ -59,7 +59,7 @@ var app = express() | |
| res.end(err.message); | ||
| }); | ||
|
|
||
| var server = app.listen(1984); | ||
| const server = app.listen(1984); | ||
|
|
||
| graceful({ | ||
| servers: [server], | ||
|
|
@@ -76,43 +76,18 @@ graceful({ | |
| }); | ||
| ``` | ||
|
|
||
| If you are using [pm](https://github.com/aleafs/pm), | ||
| you can follow the [graceful_exit with pm demo](https://github.com/aleafs/pm/tree/master/demo/graceful_exit). | ||
| ### ESM and TypeScript | ||
|
|
||
| <!-- GITCONTRIBUTOR_START --> | ||
| ```ts | ||
| import { graceful } from 'graceful'; | ||
| ``` | ||
|
|
||
| ## Contributors | ||
|
|
||
| |[<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/>| | ||
| | :---: | :---: | :---: | :---: | | ||
|
|
||
|
|
||
| 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`. | ||
| [](https://github.com/node-modules/graceful/graphs/contributors) | ||
|
|
||
| <!-- GITCONTRIBUTOR_END --> | ||
| Made with [contributors-img](https://contrib.rocks). | ||
|
|
||
| ## License | ||
|
|
||
| (The MIT License) | ||
|
|
||
| Copyright (c) 2013 - 2014 fengmk2 <fengmk2@gmail.com> | ||
| Copyright (c) 2015 - 2016 node-modules and other contributors | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining | ||
| a copy of this software and associated documentation files (the | ||
| 'Software'), to deal in the Software without restriction, including | ||
| without limitation the rights to use, copy, modify, merge, publish, | ||
| distribute, sublicense, and/or sell copies of the Software, and to | ||
| permit persons to whom the Software is furnished to do so, subject to | ||
| the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be | ||
| included in all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
| TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
| SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| [MIT](LICENSE) | ||
Uh oh!
There was an error while loading. Please reload this page.