Skip to content

feat(definePlugin): helper function to create plugins#1229

Merged
chimurai merged 5 commits into
masterfrom
define-plugin
May 9, 2026
Merged

feat(definePlugin): helper function to create plugins#1229
chimurai merged 5 commits into
masterfrom
define-plugin

Conversation

@chimurai
Copy link
Copy Markdown
Owner

@chimurai chimurai commented May 9, 2026

Summary by CodeRabbit

  • New Features

    • Added a definePlugin helper to simplify creating custom plugins with improved TypeScript support
  • Documentation

    • Added README guide and examples showing how to create and register custom plugins
  • Chores

    • Added a top-level "next" changelog section and updated the changelog
  • Refactor

    • Consolidated plugin exports behind a single plugins entry point and updated library exports to use it
  • Tests

    • Updated type, unit and e2e tests to exercise and validate the new definePlugin helper

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f5192093-054d-4603-a1cb-6946f1841fc4

📥 Commits

Reviewing files that changed from the base of the PR and between dc340f2 and 697d14c.

📒 Files selected for processing (1)
  • README.md
✅ Files skipped from review due to trivial changes (1)
  • README.md

📝 Walkthrough

Walkthrough

This PR adds a generic definePlugin helper, re-exports it via a consolidated src/plugins entrypoint, refactors the four default plugins to use definePlugin, and updates README, CHANGELOG, type/unit/e2e tests to use and document the helper.

Changes

definePlugin Helper Introduction

Layer / File(s) Summary
Plugin Helper Type Definition
src/plugins/define-plugin.ts
New module exports definePlugin, a generic function parameterized over request/response types, returning the passed Plugin unchanged.
Public API Export
src/plugins/index.ts, src/index.ts
Adds a src/plugins entrypoint that re-exports define-plugin and default plugins; package entrypoint now re-exports from ./plugins/index.js.
Default Plugins Refactored
src/plugins/default/debug-proxy-errors-plugin.ts, src/plugins/default/error-response-plugin.ts, src/plugins/default/logger-plugin.ts, src/plugins/default/proxy-events.ts
All default plugins are wrapped with definePlugin(...), changing exported initialization syntax while preserving internal handler logic; logger-plugin also relaxes an explicit request param typing in a handler.
Tests and Documentation
CHANGELOG.md, README.md, test/types.spec.ts, test/unit/get-plugins.spec.ts, test/e2e/plugins.spec.ts
Changelog records feature. README TOC and new "definePlugin helper" section with TS example. Type tests add definePlugin() typing checks; unit/e2e tests updated to import/use definePlugin and switch some assertions to structural equality.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • chimurai/http-proxy-middleware#1215: Also modifies logger-plugin.ts; that PR changes URL construction and IPv6/protocol handling while this PR wraps the logger with definePlugin and updates parameter typing.
  • chimurai/http-proxy-middleware#1195: Related edits under src/plugins/default and changes to plugin typing/imports; both touch plugin modules and type-only import patterns.

Poem

🐰 I shape plugins with gentle paws and cheer,
definePlugin whispers types so clear,
Four old friends wrapped in a typed embrace,
Docs and tests confirm each place,
Hooray — plugins now hop with grace!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: introducing a new definePlugin helper function for creating plugins.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch define-plugin

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 and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 9, 2026

npm i https://pkg.pr.new/http-proxy-middleware@1229

commit: 697d14c

@coveralls
Copy link
Copy Markdown

coveralls commented May 9, 2026

Coverage Status

coverage: 94.086% (+0.02%) from 94.07% — define-plugin into master

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/unit/get-plugins.spec.ts (1)

10-10: ⚡ Quick win

Prefer importing definePlugin from the public entrypoint in this test.

Using ../../src/index.js here keeps the test aligned with public API usage and avoids coupling to internal module paths.

Suggested change
 import {
   debugProxyErrorsPlugin,
+  definePlugin,
   errorResponsePlugin,
   loggerPlugin,
   proxyEventsPlugin,
 } from '../../src/index.js';
-import { definePlugin } from '../../src/plugins/define-plugin.js';
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/unit/get-plugins.spec.ts` at line 10, The test imports definePlugin
directly from an internal module; change the import in
test/unit/get-plugins.spec.ts to pull definePlugin from the public entrypoint
(the package's main export, e.g. '../../src/index.js') instead of
'../../src/plugins/define-plugin.js' so the test uses the public API; keep the
named import (definePlugin) the same and update only the module path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 305-314: The example is missing imports for definePlugin and
createProxyMiddleware; update the snippet to explicitly import these symbols
(e.g., add an import that includes definePlugin and createProxyMiddleware from
the library) so readers can copy/paste and run the definePlugin(...) and
createProxyMiddleware(...) example without errors.

---

Nitpick comments:
In `@test/unit/get-plugins.spec.ts`:
- Line 10: The test imports definePlugin directly from an internal module;
change the import in test/unit/get-plugins.spec.ts to pull definePlugin from the
public entrypoint (the package's main export, e.g. '../../src/index.js') instead
of '../../src/plugins/define-plugin.js' so the test uses the public API; keep
the named import (definePlugin) the same and update only the module path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bdf84f0d-3172-4762-9f00-397275ec0fa9

📥 Commits

Reviewing files that changed from the base of the PR and between ba9f262 and e69397a.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • README.md
  • src/index.ts
  • src/plugins/default/debug-proxy-errors-plugin.ts
  • src/plugins/default/error-response-plugin.ts
  • src/plugins/default/logger-plugin.ts
  • src/plugins/default/proxy-events.ts
  • src/plugins/define-plugin.ts
  • test/types.spec.ts
  • test/unit/get-plugins.spec.ts

Comment thread README.md
@chimurai chimurai merged commit 9ac59c4 into master May 9, 2026
26 checks passed
@chimurai chimurai deleted the define-plugin branch May 9, 2026 17:05
@chimurai chimurai added this to the v4.1 milestone May 17, 2026
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.

2 participants