Add object-literal plugin types and deprecate class-based plugins - #139
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #139 +/- ##
=======================================
Coverage 98.78% 98.78%
=======================================
Files 77 77
Lines 1233 1235 +2
Branches 357 357
=======================================
+ Hits 1218 1220 +2
Partials 15 15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ate class-based plugins Plugins can now be plain object literals typed as FormatterPluginObject or ParserPluginObject, which statically reject keys that collide with built-in tokens. The built-in formatter and parser are rewritten as object literals so the reserved token set is derived from their keys instead of a hand-written list. FormatterPlugin/ParserPlugin are marked @deprecated but still accepted by the plugins option until the next major version.
Convert all nine bundled plugins from class-based to object literals typed as FormatterPluginObject/ParserPluginObject so they are also protected from built-in token collisions. Exported names and behavior are unchanged.
Add a "Writing Your Own Plugin" section, show the 3.x extend to 4.x plugins migration, and update the plugins option type in the format/parse API docs.
Explain that only annotated object literals are checked against built-in tokens, document what a parser token can and cannot do, and note that the class-based plugin types are deprecated.
Notably vitest and @vitest/coverage-v8 to 5.x, astro to 7.3 and @astrojs/starlight to 0.42.
Register an empty i18n entry so the optional collection is present in the data store, and provide docs/404.md with disable404Route so the 404 page comes from a real entry instead of Starlight's fallback.
Persist transformed modules under node_modules/.vitest-cache for faster local reruns. Keep isolate enabled because the tests change process.env.TZ and would leak it across files in shared workers.
knowledgecode
force-pushed
the
develop
branch
from
September 21, 2026 09:26
beb8c0c to
5a2069b
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.
Summary
FormatterPluginObject/ParserPluginObject, which let a plugin be written as a plain object literal (the v4 counterpart of 3.xdate.extend(...)) and statically reject keys that collide with built-in tokens.ReservedFormatterToken/ReservedParserToken), andsatisfies Record<Reserved…, …>on the built-in objects keeps it exactly in sync with their keys. The bundled plugins usesatisfiesrather than a type annotation, so each token keeps its own function type instead of widening to a string-indexed record.FormatterPlugin/ParserPluginas@deprecated. Thepluginsoption now accepts(FormatterPluginObject | FormatterPlugin)[](likewise for the parser), so existing class-based plugins keep compiling until the classes are removed in the next major version.pluginsoption type in the format/parse API docs, and clarify that only annotated object literals are checked against built-in tokens, what a parser token can and cannot do, and that the class-based types are deprecated.@vitest/coverage-v85.x, astro 7.3,@astrojs/starlight0.42).i18ncollection, missing404entry).docs/404.mdis added anddisable404Routeis set, so the 404 page is generated from a real entry.fsModuleCachefor faster local reruns and setisolate: trueexplicitly. The tests changeprocess.env.TZ, which would leak across files if workers were shared.Test plan
npm run tsnpm run lintnpm run test(72 files / 2310 tests)npm run buildnpm run docs:build(no warnings)dist/*.d.tsfrom a consumer's perspective: object literals, class instances, and bundled plugins (with their per-token types) are accepted; a key redefining a built-in token and a non-function token are rejected