Skip to content

refactor: plugin hooks order#3913

Merged
mrlubos merged 1 commit into
mainfrom
refactor/plugin-hooks-order
May 19, 2026
Merged

refactor: plugin hooks order#3913
mrlubos merged 1 commit into
mainfrom
refactor/plugin-hooks-order

Conversation

@mrlubos

@mrlubos mrlubos commented May 19, 2026

Copy link
Copy Markdown
Member

No description provided.

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@vercel

vercel Bot commented May 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web Ready Ready Preview, Comment May 19, 2026 1:05pm

Request Review

@changeset-bot

changeset-bot Bot commented May 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7c330bc

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

This PR includes changesets to release 3 packages
Name Type
@hey-api/shared Patch
@hey-api/openapi-python Patch
@hey-api/openapi-ts 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

@mrlubos mrlubos marked this pull request as ready for review May 19, 2026 13:04
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. internal ⚙️ Internal development work. labels May 19, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Mechanical refactor that centralizes plugin hook resolution behind PluginInstance.getHooks. Hook ordering and runtime semantics are preserved across all five processors and the symbol/instance utilities.

TL;DR — Replaces the repeated [plugin.config['~hooks']?.X, plugin.context.config.parser.hooks.X] pattern with a single plugin.getHooks(selector, ...customHooks) helper, then threads it through every processor and the symbol resolver. Net effect is less boilerplate without behavioral change.

Key changes

  • Add getHooks to PluginInstance — single entry point that returns a filtered array of [...customHooks, local, global] hooks, dropping undefined entries.
  • Migrate schema extractorspydantic/v2, @hey-api/typescript/v1, valibot/v1, zod/{mini,v3,v4} all swap their hand-rolled hook arrays for plugin.getHooks((hooks) => hooks.schemas?.shouldExtract).
  • Migrate symbol resolversgetSymbolExportFromFilePath, getSymbolFilePath, and buildSymbolIn now use getHooks and drop their inline null-guard loop.
  • Simplify boolean-or-call branchhook?.(ctx) ?? false becomes hook(ctx) since getHooks already filters undefined; downstream if (result) truthiness still folds boolean false and undefined together.

Summary | 9 files | 1 commit | base: mainrefactor/plugin-hooks-order


Centralized hook resolution

Before: every processor inlined [plugin.config['~hooks']?.schemas?.shouldExtract, plugin.context.config.parser.hooks.schemas?.shouldExtract] and each loop guarded hook?.(ctx) ?? false.
After: plugin.getHooks((hooks) => hooks.schemas?.shouldExtract) returns the filtered, ordered array; pydantic additionally passes its two built-in extractor predicates as varargs so they're prepended ahead of user hooks.

Ordering is [customHooks…, local (config['~hooks']), global (parser.hooks)], which matches every call site's previous order — pydantic kept its built-in object/enum predicates first, and every other processor's [local, global] ordering is preserved. The boolean-vs-function dispatch inside each extractor loop is unchanged.

instance.ts · symbol.ts · pydantic/v2/processor.ts

Pullfrog  | View workflow run | Using Claude Opus𝕏

@pkg-pr-new

pkg-pr-new Bot commented May 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

@hey-api/codegen-core

npm i https://pkg.pr.new/@hey-api/codegen-core@3913

@hey-api/json-schema-ref-parser

npm i https://pkg.pr.new/@hey-api/json-schema-ref-parser@3913

@hey-api/nuxt

npm i https://pkg.pr.new/@hey-api/nuxt@3913

@hey-api/openapi-ts

npm i https://pkg.pr.new/@hey-api/openapi-ts@3913

@hey-api/shared

npm i https://pkg.pr.new/@hey-api/shared@3913

@hey-api/spec-types

npm i https://pkg.pr.new/@hey-api/spec-types@3913

@hey-api/types

npm i https://pkg.pr.new/@hey-api/types@3913

@hey-api/vite-plugin

npm i https://pkg.pr.new/@hey-api/vite-plugin@3913

commit: 7c330bc

@codecov

codecov Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 4.34783% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.70%. Comparing base (e79a80a) to head (7c330bc).

Files with missing lines Patch % Lines
...ckages/shared/src/plugins/shared/utils/instance.ts 0.00% 9 Missing and 4 partials ⚠️
...ges/openapi-ts/src/plugins/valibot/v1/processor.ts 0.00% 1 Missing and 1 partial ⚠️
...kages/openapi-ts/src/plugins/zod/mini/processor.ts 0.00% 1 Missing and 1 partial ⚠️
...ackages/openapi-ts/src/plugins/zod/v3/processor.ts 0.00% 1 Missing and 1 partial ⚠️
...ackages/openapi-ts/src/plugins/zod/v4/processor.ts 0.00% 1 Missing and 1 partial ⚠️
...ts/src/plugins/@hey-api/typescript/v1/processor.ts 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3913      +/-   ##
==========================================
- Coverage   37.73%   37.70%   -0.03%     
==========================================
  Files         582      582              
  Lines       20837    20844       +7     
  Branches     6066     6063       -3     
==========================================
- Hits         7862     7860       -2     
- Misses      10567    10570       +3     
- Partials     2408     2414       +6     
Flag Coverage Δ
unittests 37.70% <4.34%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mrlubos mrlubos merged commit 0c865e1 into main May 19, 2026
10 of 12 checks passed
@mrlubos mrlubos deleted the refactor/plugin-hooks-order branch May 19, 2026 13:10
@hey-api hey-api Bot mentioned this pull request May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal ⚙️ Internal development work. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant