diff --git a/.github/workflows/pkg.pr.new.yml b/.github/workflows/pkg.pr.new.yml new file mode 100644 index 00000000..ebe7c34d --- /dev/null +++ b/.github/workflows/pkg.pr.new.yml @@ -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 + + - run: npx pkg-pr-new publish diff --git a/package.json b/package.json index e26e6d84..2f69db64 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "coffee": "5", "egg-bin": "6", "eslint": "8", - "eslint-config-egg": "13", + "eslint-config-egg": "14", "gals": "1", "js-yaml": "3", "mm": "3", @@ -69,7 +69,7 @@ "tshy": "1", "tshy-after": "1", "typescript": "5", - "urllib": "3" + "urllib": "4" }, "files": [ "dist", diff --git a/src/egg.ts b/src/egg.ts index 938ceede..08976ca7 100644 --- a/src/egg.ts +++ b/src/egg.ts @@ -3,7 +3,7 @@ import assert from 'node:assert'; import { debuglog } from 'node:util'; import is from 'is-type-of'; import KoaApplication from '@eggjs/koa'; -import type { ContextDelegation, Next } from '@eggjs/koa'; +import type { ContextDelegation, MiddlewareFunc } from '@eggjs/koa'; import { EggConsoleLogger } from 'egg-logger'; import { RegisterOptions, ResourcesController, EggRouter as Router } from '@eggjs/router'; import type { ReadyFunctionArg } from 'get-ready'; @@ -28,13 +28,8 @@ export interface EggCoreOptions { export type EggCoreInitOptions = Partial; -type Middleware = (ctx: EggCoreContext, next: Next) => Promise | void; -export type MiddlewareFunc = Middleware & { - _name?: string; -}; +export type { ContextDelegation, MiddlewareFunc, Next } from '@eggjs/koa'; -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore export interface EggCoreContext extends ContextDelegation { app: EggCore; } @@ -58,9 +53,6 @@ export class EggCore extends KoaApplication { readonly controller: Record = {}; /** auto inject on loadMiddleware() */ readonly middlewares: Record MiddlewareFunc> = {}; - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - declare middleware: MiddlewareFunc[]; /** * @class diff --git a/src/loader/egg_loader.ts b/src/loader/egg_loader.ts index 635612b8..8edb1558 100644 --- a/src/loader/egg_loader.ts +++ b/src/loader/egg_loader.ts @@ -7,7 +7,7 @@ import homedir from 'node-homedir'; import type { Logger } from 'egg-logger'; import { getParamNames, readJSONSync } from 'utility'; import { extend } from 'extend2'; -import { Request, Response, Context, Application, Next } from '@eggjs/koa'; +import { Request, Response, Context, Application } from '@eggjs/koa'; import { pathMatching, type PathMatchingOptions } from 'egg-path-matching'; import { now, diff } from 'performance-ms'; import { FULLPATH, FileLoader, FileLoaderOptions } from './file_loader.js'; @@ -1601,7 +1601,7 @@ function wrapMiddleware(mw: MiddlewareFunc, } const match = pathMatching(options); - const fn = (ctx: EggCoreContext, next: Next) => { + const fn: MiddlewareFunc = (ctx, next) => { if (!match(ctx)) return next(); return mw(ctx, next); }; @@ -1610,7 +1610,7 @@ function wrapMiddleware(mw: MiddlewareFunc, } function debugMiddlewareWrapper(mw: MiddlewareFunc): MiddlewareFunc { - const fn = async (ctx: EggCoreContext, next: Next) => { + const fn: MiddlewareFunc = async (ctx, next) => { const startTime = now(); debug('[debugMiddlewareWrapper] [%s %s] enter middleware: %s', ctx.method, ctx.url, mw._name); await mw(ctx, next);