@changesets/format

中文文档
0.1.3发布于 2026/10/23MITES Module构建来源已验证近 30 天下载 813.9万

Detect and format files

原始使用文档
文档目录5 节
  1. Usage
  2. detect()
  3. format()
  4. Thanks
  5. License

@changesets/format

Detect installed code formatters and format files with them.

Usage

detect()

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 to process.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"] (from defaultDetectOrder)

format()

Format the given patterns with a specified or auto-detected formatter. It returns true if a formatter is found and the formatting process passes (even if the patterns didn't match any files), 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 using detect. Use detect directly 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 to process.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 use package-manager-detector to detect the package manager.

Thanks

The core idea of this package is based on formatly, but implemented for Changesets' needs. However, it is still generic enough to be used by other projects than Changesets.

License

MIT

版本与发布记录

@changesets/format 共发布 5 个版本,首次发布于 2026/05/12;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.3latest2026/10/2317 天前
0.1.22026/08/142 个月前
0.1.12026/07/193 个月前
0.1.02026/05/125 个月前
0.0.02026/05/125 个月前

关于 @changesets/format 的常见问题

@changesets/format 是什么?

Detect and format files

如何安装 @changesets/format?

在项目目录运行 npm install @changesets/format,或使用 pnpm add / yarn add / bun add。

@changesets/format 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/changesets__format 是否存在。

@changesets/format 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@changesets/format 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.11 || ^24 || >=26。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@changesets/format 可以商用吗?

@changesets/format 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@changesets/format 的下载量有多少?

根据 npm 官方下载统计,@changesets/format 在 2026/10/10 – 2026/11/08 这 30 天内被下载 8,138,786 次,日均约 271,293 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@changesets/format 还在维护吗?

最新版本 0.1.3 发布于 2026/10/23(17 天前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2026/05/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。