Skip to content
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

fix: change debug prefix to @eggjs/koa #8

Merged
merged 2 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, macos-latest, windows-latest'
version: '18, 20, 22'
version: '18.19.0, 18, 20, 22'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
8 changes: 4 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @eggjs/koa

@eggjs/koa is forked from [Koa v2.x](https://github.com/koajs/koa/tree/v2.x) for LTS and drop Node.js < 18.7.0 support.
@eggjs/koa is forked from [Koa v2.x](https://github.com/koajs/koa/tree/v2.x) for LTS and drop Node.js < 18.19.0 support.

<img height="240px" src="/docs/logo.png" alt="Koa middleware framework for nodejs"/>

Expand All @@ -12,14 +12,14 @@

Expressive HTTP middleware framework for node.js to make web applications and APIs more enjoyable to write. Koa's middleware stack flows in a stack-like manner, allowing you to perform actions downstream then filter and manipulate the response upstream.

Only methods that are common to nearly all HTTP servers are integrated directly into Koa's small ~570 SLOC codebase. This
includes things like content negotiation, normalization of node inconsistencies, redirection, and a few others.
Only methods that are common to nearly all HTTP servers are integrated directly into Koa's small codebase.
This includes things like content negotiation, normalization of node inconsistencies, redirection, and a few others.

Koa is not bundled with any middleware.

## Installation

@eggjs/koa requires __node v18.7.0__ or higher for Node.js LTS support.
@eggjs/koa requires __node v18.19.0__ or higher for Node.js LTS support.

```bash
npm install @eggjs/koa
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@eggjs/koa",
"version": "2.18.2",
"engines": {
"node": ">= 18.7.0"
"node": ">= 18.19.0"
},
"publishConfig": {
"access": "public"
Expand Down
14 changes: 7 additions & 7 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import { Response } from './response.js';
import type { ContextDelegation } from './context.js';
import type { CustomError, AnyProto } from './types.js';

const debug = debuglog('koa:application');
const debug = debuglog('@eggjs/koa:application');

export type ProtoImplClass<T = object> = new(...args: any[]) => T;
export type Next = () => Promise<void>;
export type MiddlewareFunc = (ctx: ContextDelegation, next: Next) => Promise<void> | void;
type _MiddlewareFunc = (ctx: ContextDelegation, next: Next) => Promise<void> | void;
export type MiddlewareFunc = _MiddlewareFunc & { _name?: string };

/**
* Expose `Application` class.
Expand Down Expand Up @@ -95,7 +96,7 @@ export class Application extends Emitter {
* http.createServer(app.callback()).listen(...)
*/
listen(...args: any[]) {
debug('listen');
debug('listen with args: %o', args);
const server = http.createServer(this.callback());
return server.listen(...args);
}
Expand Down Expand Up @@ -125,17 +126,16 @@ export class Application extends Emitter {

/**
* Use the given middleware `fn`.
*
* Old-style middleware will be converted.
*/
use(fn: MiddlewareFunc) {
if (typeof fn !== 'function') throw new TypeError('middleware must be a function!');
const name = fn._name || fn.name || '-';
if (isGeneratorFunction(fn)) {
throw new TypeError('Support for generators was removed. ' +
throw new TypeError(`Support for generators was removed, middleware: ${name}. ` +
'See the documentation for examples of how to convert old middleware ' +
'https://github.com/koajs/koa/blob/master/docs/migration.md');
}
debug('use %s #%d', (fn as any)._name || fn.name || '-', this.middleware.length);
debug('use %o #%d', name, this.middleware.length);
this.middleware.push(fn);
return this;
}
Expand Down
7 changes: 3 additions & 4 deletions test/application/use.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ describe('app.use(fn)', () => {
const app = new Koa();
const calls: number[] = [];

app.use((_ctx, next) => {
app.use(async function foo(_ctx, next) {
calls.push(1);
return next().then(() => {
calls.push(6);
});
await next();
calls.push(6);
});

app.use((_ctx, next) => {
Expand Down
Loading