Skip to content

Patchers Overview

The @xtarterize/patchers package provides safe ways to modify configuration files. Patchers return new content, and the caller decides whether to write it.

  • JSON merge: deep merges objects with defu, so existing keys win and incoming values only fill gaps.
  • Vite plugin injection: inserts an import and a plugin call into Vite config source using magicast.

Injection is idempotent: a plugin that is already imported is not added again. The patcher parses the config, inserts the import, appends the plugin call to the plugins array, and returns the generated source.

When the config structure is non-standard, such as a factory function or a conditional export, the patcher returns manual instructions instead of rewriting the file.

The merge combines objects with existing keys winning, and a second patcher applies the result to JSON text so comments, key order, and formatting survive. See JSON Merge for merge behavior in detail.