Skip to content

Allow a plugin config entry to expand into multiple entries #194

Description

@tonyboho

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:

"plugins": [
    {
        "transform": "ts-mixin-class",
        "transformProgram": true
    },
    {
        "name": "ts-mixin-class/language-service-plugin"
    }
]

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:

"plugins": [
    "ts-mixin-class"
]

or

"plugins": [
    { "name": "ts-mixin-class" }
]

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: "..." } ].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions