Skip to content

fix(types): expose middleware on koa and hono wrappers - #2489

Open
MehdiZare wants to merge 1 commit into
webpack:mainfrom
MehdiZare:codex/wrapper-middleware-types
Open

MehdiZare wants to merge 1 commit into
webpack:mainfrom
MehdiZare:codex/wrapper-middleware-types

Conversation

@MehdiZare

@MehdiZare MehdiZare commented Oct 20, 2026 •

Copy link
Copy Markdown

Summary

Both koaWrapper() and honoWrapper() attach the underlying middleware to the returned function at runtime, but the published declarations omit that property. TypeScript consumers cannot call wrapper.devMiddleware.waitUntilValid(), invalidate(), or close() without an assertion. This surfaced while migrating Strapi's webpack adapter to koaWrapper().

Expose the existing devMiddleware property in both wrapper return types by updating the JSDoc source and regenerating declarations. The callable intersection preserves the middleware API and its custom request/response generics. Include a patch changeset.

What kind of change does this PR introduce?

A TypeScript declaration bug fix. Runtime behavior is unchanged.

Did you add tests for your changes?

Yes. A consumer fixture is compiled through Jest under strict TypeScript settings. It covers both wrappers, middleware lifecycle methods, custom request/response types, and negative checks that prevent the API from degrading to any. The fixture fails against the original declarations and passes with this change.

Validation on Node 26.8.1:

  • npm run build:types
  • npm run lint
  • npm run test:only -- --runInBand test/wrapper-types.test.js
  • Regenerating declarations after committing leaves types/ unchanged.
  • Existing Koa/Hono constructor integration cases: 2 passed (selected with --testNamePattern; 6,647 other cases skipped).

The full runtime coverage run was interrupted after 18 minutes without a completed result, so it is not reported as passing.

Additional browser validation: npm run test:e2e reports 226 passed and 7 failed across 17 suites. The two indicator failures reproduce on untouched upstream commit 0ffba03. Five CORS cases time out navigating to 127.0.0.2; the first of those also reproduces on the untouched upstream commit. The declaration fix makes no runtime changes.

Does this PR introduce a breaking change?

No. It makes the declarations reflect properties already available at runtime.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

The changeset describes the corrected return types. No new runtime API is introduced.

Use of AI

Codex assisted with source inspection, the declaration change, regression tests, and local validation. The consumer fixture was tested against both the original and corrected declarations; unrelated browser failures were checked against untouched upstream code.

Summary by CodeRabbit

  • Improvements

    • Koa and Hono wrapper typings now expose the existing devMiddleware API on returned handlers.
    • Custom request and response types remain preserved for stronger type safety.
    • Updated documentation clarifies the Koa wrapper’s return type.
  • Tests

    • Added compile-time coverage validating middleware APIs, options, and custom request/response typings.

@changeset-bot

changeset-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9c50941

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack-dev-middleware Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: MehdiZare / name: Mehdi (9c50941)

@coderabbitai

coderabbitai Bot commented Oct 20, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c3d385d0-b7b1-4a1b-9843-ed8a3e8eaa54
📥 Commits

Reviewing files that changed from the base of the PR and between 0ffba03 and 9c50941.

📒 Files selected for processing: 5
  • .changeset/typed-wrapper-middleware.md
  • src/index.js
  • test/fixtures/types/wrappers.cts
  • test/wrapper-types.test.js
  • types/index.d.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

Koa and Hono wrapper return types now expose the existing devMiddleware API property while preserving custom request and response types. Type-level tests check API methods, option types, and custom request and response properties.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 9c509

The wrapper type update appears ready to merge after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: exposing the existing middleware API on the Koa and Hono wrappers through updated TypeScript types.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant