feat: make the Inertia class macroable#102
Open
filipebraida wants to merge 4 commits into
Open
Conversation
Extend @poppinss/macroable so packages can add methods via Inertia.macro()
instead of monkey-patching the prototype, matching how other AdonisJS core
classes (Request, Response, ...) are extended.
Use case: adonis-inertia-modal currently patches Inertia.prototype.modal;
with this it can register Inertia.macro('modal', ...) idiomatically.
Import the Inertia type from the package entrypoint instead of the internal module path, so that every program type-checking ctx.inertia also loads the entrypoint declarations. Without this, third-party augmentations via `declare module '@adonisjs/inertia'` silently fail in programs that never import the entrypoint themselves (e.g. a Tuyau client tsconfig pulling controllers in through the generated registry). The import is type-only, so no runtime import of the entrypoint is added to the compiled middleware.
filipebraida
added a commit
to filipebraida/adonis-inertia-modal
that referenced
this pull request
Jul 20, 2026
This branch depends on unreleased @adonisjs/inertia changes (adonisjs/inertia#102). Build and install the PR branch in the typecheck and tests jobs until it ships. To be reverted once the upstream release is out and the peer dependency is bumped.
filipebraida
force-pushed
the
feat/macroable
branch
from
July 20, 2026 17:24
0f2425d to
5e9d100
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
Resolves the feature request discussed in adonisjs/core#5121.
❓ Type of change
📚 Description
Makes the
Inertiaclass extensible through the standard AdonisJS extensionpattern, in two parts:
1. Make
InertiaextendMacroablePackages can register methods with
Inertia.macro()/Inertia.getter()instead of patching
Inertia.prototype— same pattern asRequest,Response,BriskRoute, etc.@poppinss/macroableis added as a dependency(already used across AdonisJS core packages).
2. Type
ctx.inertiaagainst the package entrypointThe
HttpContextaugmentation ininertia_middleware.tsnow imports theInertiatype from the package entrypoint instead of the internal modulepath. Without this, a third-party
declare module '@adonisjs/inertia'augmentation silently no-ops in TS programs that never import the entrypoint
themselves (e.g. a Tuyau client tsconfig that pulls controllers in through the
generated registry):
error TS2664: Invalid module name in augmentation, module '@adonisjs/inertia' cannot be found.
error TS2339: Property 'modal' does not exist on type 'Inertia'.
With the entrypoint import, any program that type-checks
ctx.inertiaalsoloads the entrypoint declarations, so the interface → class merge always
attaches. The import is type-only, so the compiled middleware gains no runtime
import.
Real-world validation
I migrated adonis-inertia-modal
to this branch — diff:
main...feat/inertia-macroablemodal()viaInertia.macro(); the package'stest suite (116 tests, provider booted for real) passes against this branch.
import kept alive by a dummy marker export) is deleted entirely, and both
the server tsconfig and the Tuyau-style client tsconfig of a real app
type-check
inertia.modal(...)correctly.📝 Checklist