From 3bcc0c68f77fd866c579e3d3194a0ab9d67a0857 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 16 Jun 2024 22:07:17 +0800 Subject: [PATCH 1/2] fix: change debug prefix to @eggjs/koa --- .github/workflows/node.js.yml | 2 +- Readme.md | 8 ++++---- package.json | 2 +- src/application.ts | 14 +++++++------- test/application/use.test.ts | 7 +++---- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 5f903c9cd..8764d0373 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -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, 18, 20, 22' secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/Readme.md b/Readme.md index 199d7c2a6..08e3d568a 100644 --- a/Readme.md +++ b/Readme.md @@ -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. Koa middleware framework for nodejs @@ -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 diff --git a/package.json b/package.json index 0ad2cae0a..baf407490 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@eggjs/koa", "version": "2.18.2", "engines": { - "node": ">= 18.7.0" + "node": ">= 18.19.0" }, "publishConfig": { "access": "public" diff --git a/src/application.ts b/src/application.ts index f7cfb0392..5a48d1495 100644 --- a/src/application.ts +++ b/src/application.ts @@ -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 = new(...args: any[]) => T; export type Next = () => Promise; -export type MiddlewareFunc = (ctx: ContextDelegation, next: Next) => Promise | void; +type _MiddlewareFunc = (ctx: ContextDelegation, next: Next) => Promise | void; +export type MiddlewareFunc = _MiddlewareFunc & { _name?: string }; /** * Expose `Application` class. @@ -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); } @@ -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; } diff --git a/test/application/use.test.ts b/test/application/use.test.ts index c14fe3b63..905c3219a 100644 --- a/test/application/use.test.ts +++ b/test/application/use.test.ts @@ -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) => { From dc705bf2037ada584d1eb22a9d99372b5c5ff73e Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 16 Jun 2024 22:09:08 +0800 Subject: [PATCH 2/2] f --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 8764d0373..60edbce24 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -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.19, 18, 20, 22' + version: '18.19.0, 18, 20, 22' secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}