Detect installed code formatters and format files with them.
Detect the preferred formatter used in the project.
import { detect } from "@changesets/format";
const result = await detect();
// => "prettier"Options can be passed to the first parameter:
cwd: The current working directory to start looking up for the formatter. Defaults toprocess.cwd().stopDir: The path to stop traversing up the directory.order: The order of formatters to check for. Defaults to["dprint", "deno", "oxfmt", "biome", "prettier"](fromdefaultDetectOrder)
Format the given patterns with a specified or auto-detected formatter. It returns true if a formatter is found and the formatting process passes, otherwise returns false.
import { format } from "@changesets/format";
await format(["src/index.ts"]);Options can be passed to the second parameter:
formatter: The formatter to use for formatting. It not specified, it will be auto-detected usingdetect. Usedetectdirectly if you want to have more control over the detection process.cwd: The current working directory to start looking up for the formatter and package manager, and to execute the formatter's command from. Defaults toprocess.cwd().stopDir: The path to stop traversing up the directory.packageManager: The package manager to use for executing the formatter's command. If not specified, it will usepackage-manager-detectorto detect the package manager.
MIT