kachick / times_kachick

`#times_kachick channel in chat` as a public repository. Personal Note and TODOs
https://github.com/kachick/times_kachick/issues?q=is%3Aissue+is%3Aclosed
6 stars 0 forks source link

2023-01-19 - deno で stylelint を走らせる #206

Closed kachick closed 1 year ago

kachick commented 1 year ago

https://github.com/kachick/times_kachick/issues/194 みたいな事をかいてはいたけれど、なんかどうも bun で stylelint 叩くときに node にもパスが通ってないと動かない感があった。 Nix に切り替えるときにちょっと触っていくと、nodejs の無い環境では次のようなエラーが出る

> bun run stylelint **/*.css

error: Cannot find package "vm" from "/home/kachick/repos/kachick.github.io/node_modules/v8-compile-cache/v8-compile-cache.js"
error: "stylelint" exited with code 1 (SIGHUP)
error: script "lint" exited with code 1 (SIGHUP)

この v8-compile-cache という名前が bun で出てくるというのが如何にも怪しい。 どうやら https://github.com/stylelint/stylelint/pull/4272 で速度向上を狙って eslint の PR https://github.com/eslint/eslint/pull/11921 を真似して突っ込んだということなんだけど、 eslint 側でも引っかかるようなら流石にもっと話題になってるやろと思ったら https://github.com/eslint/eslint/pull/16235 の中でなんか他の作業と混ぜつつ捨てられてた。 ほーん・・・これは外からなんか出来るんかなー

当時より deno の npm 対応が進んだということで、最終的に deno にしてしまった。速度面でのメリットは享受できなくなった気がするけど、ツールセット面での悩みが減るのはやはり嬉しい

https://github.com/kachick/kachick.github.io/pull/61

> deno cache --node-modules-dir npm:stylelint npm:stylelint-config-standard npm:stylelint-config-prettier

# stdbuf does not correctly handle the original color... :<
# unbuffer does not end in GitHub Actions... :<
# So add `unbuffer ` prefix into deno when I want local developping
> stylelintoutput="$(mktemp)" && \
  deno run --node-modules-dir --allow-env --allow-read npm:stylelint/stylelint '**/*.css' | tee "$stylelintoutput" && \
  ! [ -s "$stylelintoutput" ]

コマンドラインの組み立て方がピンと来ず四苦八苦したけれど、先に cache してやれば良さそう。 しかし、これだと stylelint でエラー扱いになっても、 deno としてはコマンドを正常に完了できたからなのか exit 0 になるというよくわからないことに・・・ 渋々色を残しつつ tee を挟んだけれど、シンプルとは・・・?みたいな気持ちにちょっとなってきたのでどっかでまだなんか触って見るかも

refs

kachick commented 1 year ago

stylelint 15 から prettier plugin が deprecated になったらしい https://github.com/prettier/stylelint-config-prettier/issues/140 ので、バージョン固定とかと併せるとこんな感じ

deno cache --node-modules-dir npm:stylelint@15.1.0 npm:stylelint-config-standard@30.0.1 --reload