Skip to content

html-distiller: 実行時依存に prettier が残り、開発用の oxfmt と整形ツールが二重になっている #987

Open

Description

@YusukeHirao

As is

@d-zero/html-distiller(2.0.12)の distill()(packages/@d-zero/html-distiller/src/distill.ts)は、html-minifier-terser で最小化した HTML を、実行時依存(dependencies)の prettier(3.9.5)で整形してから parse5 に渡している。

const formatted = await format(minified, {
	parser: 'html',
	useTabs: true,
	printWidth: 100_000,
});
const ast = parse(formatted);

リポジトリの開発用ツールは ESLint・Prettier・cspell から oxlint・oxfmt に移行したため、整形ツールが 2 系統(開発用の oxfmt と、この実行時依存の prettier)になっている。prettier はこのパッケージの package.json にだけ残り、Renovate でも追い続ける必要がある。

distill() の後段 walk()(src/walk.ts)は #text を trim() し、空文字は結果に入れない。整形が結果の木に与える影響は、空白と、title / link / script / style / iframe の tagString() が連結する文字列に限られる見込みだが、これは出力を比べるまで確定しない。

To be

distill() が実行時に prettier を使わない。整形の依存はリポジトリで使う oxfmt に一本化するか、整形が不要と確認できれば依存ごと外す。distill() が返す木は、既存の入力すべてで変わらない(変わる場合は破壊的変更として版を上げる)。

Why

  • 置き換え先の候補は実在する。oxfmt@0.62.0 は Node API として format(fileName: string, sourceText: string, options?: FormatConfig): Promise<FormatResult> を公開し(dist/index.d.ts)、FormatResult は code と errors を返す。設定の useTabs と printWidth は Prettier と同じ名前のオプションで、bracketSameLine など HTML を対象言語に挙げるオプションもある。oxfmt の Prettier からの移行手順は oxfmt の README が https://oxc.rs/docs/guide/usage/formatter/migrate-from-prettier.html として案内している。
  • @d-zero/html-distiller は公開パッケージで、@d-zero/* を exact pin で使う社内の各リポジトリが使う。distill() の出力が変わると利用側を壊すため、置き換えは出力が同一であることの確認が前提になる。

How

  1. packages/@d-zero/html-distiller/src/distill.ts の import { format } from 'prettier' を oxfmt の format() に替える。ファイル名は *.html を渡し(拡張子で言語が決まる)、useTabs: true と printWidth: 100_000 を同じ値で渡す。戻り値は .code を使い、.errors が空でないときの扱いを決める(現状の prettier は構文エラーで throw する)。
  2. packages/@d-zero/html-distiller/package.json の dependencies から prettier を外し、oxfmt を exact pin で足す(ネイティブバインディングが optional dependencies に入るため、公開後の npm install でプラットフォーム別の取得になる点を確認する)。.github/renovate.json の oxlint グループ(oxlint・oxlint-tsgolint)に oxfmt を入れるか判断する。
  3. 出力の同一性を確認する。packages/@d-zero/html-distiller/src/distill.spec.ts を通すだけでなく、旧実装(prettier)と新実装(oxfmt)の distill() の結果を、distill.spec.ts の入力と packages/@d-zero/anatomist/src/__fixtures__/*.html の入力で比べる。差が出るなら、walk() の trim() で吸収できない差(tagString() の連結結果など)かを見て、破壊的変更として版を上げるか、整形自体が不要かを判断する。

Activity

  1. added
    enhancement
    on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions