I'm the author of ts-mixin-class, a program transformer built on ts-patch, and I ran into the following:
When a single package ships more than one moving part — e.g. a transformProgram transform plus a language-service plugin — the user has to wire up every piece by hand in plugins. I'd like a package to be able to describe its own required plugin entries so the user references it just once.
Currently
My package is one logical unit, but installing it means the user must know its internal composition and spell out two entries in the exact right shape:
This is easy to get wrong (miss the transformProgram: true, forget the LS plugin, misspell the sub-path), and it leaks implementation details of the package into every consumer's tsconfig.
Desired state
The user references the package once and gets the whole correct set:
or
Proposed mechanism
Let a plugin package optionally export (e.g. as its default export) an array of ts-patch plugin descriptors — the same descriptor objects one writes today in plugins. When ts-patch resolves an entry that points at such a package, it expands that entry into the exported descriptors, flattening the results into the effective plugin list before applying them.
Roughly:
- An entry like
"ts-mixin-class" / { "name": "ts-mixin-class" } resolves the package.
- If the package exports a descriptor array, ts-patch substitutes the single entry with those descriptors (flatten).
- Otherwise, behavior is unchanged (fully backward compatible).
The exported type could reuse the existing ts-patch plugin-descriptor type, so a package just does something like export default [ { transform: "...", transformProgram: true }, { name: "..." } ].
I'm the author of
ts-mixin-class, a program transformer built on ts-patch, and I ran into the following:When a single package ships more than one moving part — e.g. a
transformProgramtransform plus a language-service plugin — the user has to wire up every piece by hand inplugins. I'd like a package to be able to describe its own required plugin entries so the user references it just once.Currently
My package is one logical unit, but installing it means the user must know its internal composition and spell out two entries in the exact right shape:
This is easy to get wrong (miss the
transformProgram: true, forget the LS plugin, misspell the sub-path), and it leaks implementation details of the package into every consumer'stsconfig.Desired state
The user references the package once and gets the whole correct set:
or
Proposed mechanism
Let a plugin package optionally export (e.g. as its default export) an array of ts-patch plugin descriptors — the same descriptor objects one writes today in
plugins. When ts-patch resolves an entry that points at such a package, it expands that entry into the exported descriptors, flattening the results into the effective plugin list before applying them.Roughly:
"ts-mixin-class"/{ "name": "ts-mixin-class" }resolves the package.The exported type could reuse the existing ts-patch plugin-descriptor type, so a package just does something like
export default [ { transform: "...", transformProgram: true }, { name: "..." } ].