Repository navigation
chore(deps): 依存を更新して脆弱性を解消し astro 7 へ移行 - #334
Merged
Merged
Conversation
脆弱性の解消を目的に、破壊的変更の影響が小さい依存をまとめて更新する。 - @astrojs/check 0.9.4 -> 0.9.10 (cross-spawn / fast-uri / lodash 経由の high を解消) - sass 1.57.1 -> 1.104.0 (immutable / picomatch 経由の high を解消) - dayjs 1.11.7 -> 1.11.23 - typescript 5.2.2 -> 5.9.3 - @types/node 18.11.18 -> 24.13.3 (.node-version の Node 24 に合わせる) - prettier 2.8.7 -> 3.9.6 - prettier-plugin-astro 0.7.2 -> 0.14.1 (prettier 3 対応) typescript は 7.0.2 が最新だが @astrojs/check 0.9.10 の peerDependencies が ^5.0.0 || ^6.0.0 のため 5 系に留める。 prettier 3 では trailingComma の既定が es5 から all に変わる。format スクリプトが無く既存ファイルは無変更だが、以降エディタで保存したファイル には差分が出る。
astro の critical (AVIF 画像最適化経由の RCE, GHSA-26w7-cxv4-gfx2) は 修正が 7.2.8 以降にしか入っておらず 5 系にバックポートされていないため、 7 系まで更新する。 astro 6 でレガシー content collections (src/content/config.ts と defineCollection の type: "data") が削除され、astro 7 には legacy.collectionsBackwardsCompat という一時的な逃げ道しか残っていない ため、loader API へ移行する。 - src/content/config.ts を src/content.config.ts へ移し glob() loader 化 - z は astro:content からの re-export が astro 8 で削除予定のため astro/zod から import する - post.render() を render(post) に変更 - params に渡す post.slug を post.id に変更 URL は変わらない。glob loader の id 生成は frontmatter の slug を優先 する実装で、全 69 件の md が slug: "YYYY-MM" を持つため従来どおり /posts/YYYY-MM/ が生成される。 lookback はトップレベルが配列の JSON だが、glob() loader と z.array() スキーマの組み合わせでそのまま読めるため JSON 側の変更は不要。 astro check / tsc --noEmit は 0 errors 0 warnings、生成ページ数は移行前 と同じ 72。
あわせて import 先を github-markdown.css から github-markdown-light.css に変更する。 v5 の github-markdown.css は prefers-color-scheme: dark で自動的に ダーク配色へ切り替わるが、このサイトは light 固定 (.main の color は #24292e、背景は指定なし) のため、OS がダーク設定のユーザーで記事本文 だけがダークになって崩れる。現状の見た目を維持するため light 版を 明示的に指定する。ダークモード対応自体は別途デザインの判断が必要。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
npm auditで検出された脆弱性(GitHub の Dependabot でも default branch に 82 件検出)を解消するために依存を更新しました。あわせて astro 7 への追随に必要な content collections の移行を行っています。更新後の
npm auditはfound 0 vulnerabilitiesです。更新内容
バージョン選定は
.npmrcのmin-release-age=14に従い、公開から 14 日以上経過したものに限定しています。なぜ astro 7 まで上げるのか
critical だった astro の AVIF 画像最適化経由の RCE(GHSA-26w7-cxv4-gfx2)は、修正が 7.2.8 以降にしか入っておらず 5 系にバックポートされていません。astro 5 系最新(5.18.2)に留めた場合、critical 1 件と high 4 件を含む 13 件が残ります。
content collections の移行(破壊的変更への対応)
astro 6 でレガシー content collections(
src/content/config.tsとdefineCollectionのtype: "data")が削除され、astro 7 にはlegacy.collectionsBackwardsCompatという一時的な逃げ道しか残っていないため、loader API へ移行しました。src/content/config.tsをsrc/content.config.tsへ移しglob()loader 化zはastro:contentからの re-export が astro 8 で削除予定のためastro/zodから importpost.render()→render(post)paramsに渡すpost.slug→post.idURL は変わりません。 glob loader の id 生成は frontmatter の
slugを優先する実装で、全 69 件の md がslug: "YYYY-MM"を持つため従来どおり/posts/YYYY-MM/が生成されます。lookbackはトップレベルが配列の JSON ですが、glob()loader とz.array()スキーマの組み合わせでそのまま読めたため、JSON データ側の変更は不要でした。github-markdown-css v5 での import 先変更
v5 の
github-markdown.cssはprefers-color-scheme: darkで自動的にダーク配色へ切り替わります。このサイトは light 固定(.mainのcolorは#24292e、背景は指定なし)のため、OS がダーク設定のユーザーで記事本文だけがダークになって崩れます。現状の見た目を維持するためgithub-markdown-light.cssを明示的に指定しました。ダークモード対応自体は別途デザインの判断が必要です。確認したこと
npm run build(astro check && tsc --noEmit && astro build)が 0 errors / 0 warnings、生成ページ数は移行前と同じ 72npm ci --ignore-scriptsでクリーンインストールが成功(lockfile は CI で再現可能)astro previewでトップ / 記事ページ(本文・メンバーアバター・シンタックスハイライト)//lookback/2024/のタイムライン(月別グルーピング)を目視確認申し送り
formatスクリプトが無いため既存ファイルは無変更ですが、prettier 3 でtrailingCommaの既定がes5→allに変わるため、今後エディタで保存したファイルには差分が出ます。一括整形するなら独立した PR にするのが無難ですtypescriptは 7.0.2 が最新ですが、@astrojs/check@0.9.10の peerDependencies が^5.0.0 || ^6.0.0のため 5 系に留めていますmin-release-ageの都合で今回見送ったもの(14 日経過後に追随可能): astro 7.3.3 / sass 1.104.1 / prettier 3.9.8 / prettier-plugin-astro 1.0.1