diff --git a/package.json b/package.json index 849b153..90bb18f 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "format": "prettier --write .", "lint": "eslint . --ext=.ts", "sync-labels": "github-label-sync --labels .github/labels.json poppinss/middleware", - "quick:test": "node --loader=ts-node/esm bin/test.ts" + "quick:test": "cross-env NODE_DEBUG=poppinss:middleware node --loader=ts-node/esm bin/test.ts" }, "keywords": [ "koa", @@ -52,6 +52,7 @@ "@types/node": "^20.10.4", "benchmark": "^2.1.4", "c8": "^8.0.1", + "cross-env": "^7.0.3", "del-cli": "^5.1.0", "eslint": "^8.55.0", "fastseries": "^2.0.0", diff --git a/src/runner.ts b/src/runner.ts index e2687ff..bd9f209 100644 --- a/src/runner.ts +++ b/src/runner.ts @@ -7,8 +7,11 @@ * file that was distributed with this source code. */ +import { debuglog } from 'node:util' import type { ErrorHandler, Executor, FinalHandler } from './types.js' +const debug = debuglog('poppinss:middleware') + /** * Run a function only once. Tightly coupled with the Runner class */ @@ -19,6 +22,7 @@ function once(scope: Runner, callback: (scope: Runner) => Promise { */ #invoke(self: Runner): Promise | void { const middleware = self.#middleware[self.#currentIndex++] + debug('running middleware at index', self.#currentIndex) /** * Empty stack @@ -95,6 +100,7 @@ export class Runner { */ #invokeWithErrorManagement(self: Runner): Promise | void { const middleware = self.#middleware[self.#currentIndex++] + debug('running middleware at index', self.#currentIndex) /** * Empty stack @@ -132,6 +138,7 @@ export class Runner { */ async run(cb: Executor): Promise { this.#executor = cb + debug('starting middleware chain with %d middleware', this.#middleware.length) if (this.#errorHandler) { return this.#invokeWithErrorManagement(this)