Skip to content

Commit

Permalink
feat: support cjs and esm both by tshy (#38)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257
  • Loading branch information
fengmk2 authored Feb 2, 2025
1 parent aa2907d commit 8177649
Show file tree
Hide file tree
Showing 32 changed files with 950 additions and 814 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test/fixtures
coverage
__snapshots__
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "eslint-config-egg"
"extends": [
"eslint-config-egg/typescript",
"eslint-config-egg/lib/rules/enforce-node-prefix"
]
}
17 changes: 17 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
Job:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, macos-latest, windows-latest'
version: '18, 20, 22'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Release

on:
push:
branches: [ master ]

jobs:
release:
name: Node.js
uses: koajs/github-actions/.github/workflows/node-release.yml@master
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
36 changes: 11 additions & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules
logs/
npm-debug.log
node_modules/
coverage/
test/fixtures/**/run
.DS_Store
.tshy*
.eslintcache
dist
package-lock.json
.package-lock.json
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

File renamed without changes.
32 changes: 15 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
koa-onerror
=================
# koa-onerror

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/koa-onerror.svg?style=flat)](https://nodejs.org/en/download/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)

[npm-image]: https://img.shields.io/npm/v/koa-onerror.svg?style=flat
[npm-url]: https://npmjs.org/package/koa-onerror
[travis-image]: https://img.shields.io/travis/koajs/onerror.svg?style=flat
[travis-url]: https://travis-ci.org/koajs/onerror
[codecov-image]: https://codecov.io/gh/koajs/onerror/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/koajs/onerror
[david-image]: https://img.shields.io/david/koajs/onerror.svg?style=flat
[david-url]: https://david-dm.org/koajs/onerror
[snyk-image]: https://snyk.io/test/npm/koa-onerror/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/koa-onerror
[download-image]: https://img.shields.io/npm/dm/koa-onerror.svg?style=flat-square
Expand All @@ -24,6 +19,7 @@ koa-onerror
an error handler for koa, hack ctx.onerror.

different with [koa-error](https://github.com/koajs/error):

- we can not just use try catch to handle all errors, steams' and events'
errors are directly handle by `ctx.onerror`, so if we want to handle all
errors in one place, the only way i can see is to hack `ctx.onerror`.
Expand All @@ -39,10 +35,10 @@ npm install koa-onerror

```js
const fs = require('fs');
const koa = require('koa');
const onerror = require('koa-onerror');
const Koa = require('koa');
const { onerror } = require('koa-onerror');

const app = new koa();
const app = new Koa();

onerror(app);

Expand All @@ -58,11 +54,11 @@ app.use(ctx => {
onerror(app, options);
```

* **all**: if options.all exist, ignore negotiation
* **text**: text error handler
* **json**: json error handler
* **html**: html error handler
* **redirect**: if accepct html, can redirect to another error page
- **all**: if `options.all` exist, ignore negotiation
- **text**: text error handler
- **json**: json error handler
- **html**: html error handler
- **redirect**: if accept `html` or `text`, can redirect to another error page

check out default handler to write your own handler.

Expand All @@ -76,4 +72,6 @@ check out default handler to write your own handler.

## Contributors

[![](https://ergatejs.implements.io/badges/contributors/koajs/onerror.svg?size=96)](https://github.com/koajs/onerror/graphs/contributors)
[![Contributors](https://contrib.rocks/image?repo=koajs/onerror)](https://github.com/koajs/onerror/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).
15 changes: 0 additions & 15 deletions appveyor.yml

This file was deleted.

15 changes: 15 additions & 0 deletions example.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fs = require('node:fs');
const Koa = require('koa');
const { onerror } = require('./');

const app = new Koa();

onerror(app);

app.use(async ctx => {
foo();
ctx.body = fs.createReadStream('not exist');
});

app.listen(3000);
console.log('listening on port http://localhost:3000');
16 changes: 0 additions & 16 deletions example.js

This file was deleted.

143 changes: 0 additions & 143 deletions index.js

This file was deleted.

Loading

0 comments on commit 8177649

Please sign in to comment.