feat: add React-free ./model entry point - #24
Merged
Merged
Conversation
Framework-agnostic model code only needs the GhostMakerModel decorator and the model name/id accessors, but the main entry loads react, react/jsx-runtime and @tanstack/react-query. The new @mittwald/react-ghostmaker/model entry exposes GhostMakerModel, ghostMakerModel, getModelName, getModelId and the GhostMakerModelMeta and DynamicModel types without importing React, not even in its type declarations. getModelName and getModelId move from queries.ts to metaData.ts, because queries.ts depends on the React-bound types.ts. The main entry keeps exporting them unchanged and now also exports the two types. react and @tanstack/react-query become optional peer dependencies, as only the main entry needs them. A test walks the import graph of the ./model and ./polytype entries (including type-only imports) and fails as soon as either reaches react, react-dom or @tanstack/react-query. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Why
Model definitions only need
GhostMakerModelandgetModelName, and both arefree of React. The main entry, however, pulls in
react,react/jsx-runtimeand@tanstack/react-queryas soon as it is imported. Any package that definesmodels therefore depends on React, even when it never renders anything — for
example a framework-agnostic domain-model package meant to run in Node or a CLI.
What
@mittwald/react-ghostmaker/model, built like./polytype.It exports
GhostMakerModel,ghostMakerModel,getModelName,getModelIdand the types
GhostMakerModelMetaandDynamicModel. It shares the modelregistry with the main entry, so models defined through
./modelresolve inReact ghosts as before.
reactand@tanstack/react-queryare now optional peers. Only the mainentry needs them, and anyone using it has React installed anyway. The version
ranges are unchanged.
getModelNameandgetModelIdmoved fromqueries.tstometaData.ts.queries.tscarries a type import fromtypes.ts, which references Reacttypes; left there,
model.d.tswould require@types/reactin consumerscompiling with
skipLibCheck: false.queries.tsre-exports them, so the mainentry is unchanged.
GhostMakerModelMetaandDynamicModelare now exported from the mainentry too, so it keeps offering everything
./modeldoes../model, and a note that Reactand TanStack Query are only required for the main entry.
Keeping it React-free
reactFreeEntries.test.tswalks the import graph ofmodel.tsandpolytype.tsstatically, type imports andexport … fromincluded, and failsas soon as it reaches
react,react/*,react-domor@tanstack/react-query. A self-test asserts that the walker does find Reactbehind the main entry, so it cannot pass vacuously.
Compatibility
Purely additive. The main entry's runtime exports and their signatures are
identical before and after (compared on the build output); the only additions
are the two type exports. Suggested release: 1.6.0.
Verification
pnpm testin the package: tsc, eslint, build, vitest (25/25), license check.dist/esm/model.jsloads onlymetaData.jsand@sindresorhus/is;dist/types/model.d.tsonly referencestype-fest.neither peer,
./modelruns (decorator,getModelName,getModelId), andtsc --skipLibCheck falsecompiles a file using the decorator andGhostMakerModelMeta.🤖 Generated with Claude Code