diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70ea34b..4781f22 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,12 @@ name: ci # 検査は PR でだけ回す。develop / main への push (= マージ) では、PR で確かめた中身を回し直さない。 -# 公開リポジトリなので Actions の時間の制約は無いが、同じ中身を 2 回回す意味が無い +# 公開リポジトリなので Actions の時間の制約は無いが、同じ中身を 2 回回す意味が無い。 +# main への push (= リリース PR のマージ) では release-please と公開 (release ジョブ) だけを回す on: pull_request: + push: + branches: [main] # 同じ PR への連続 push で古い run を取り消す concurrency: @@ -15,6 +18,7 @@ permissions: jobs: check: + if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -32,6 +36,7 @@ jobs: # 単独アプリ (apps/web) に対して現像の E2E を回す。WebGL は SwiftShader。公開リポジトリで時間の制約が無く、 # 30 秒ほどで終わるので、すべての PR で回す e2e: + if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -68,6 +73,7 @@ jobs: # シークレットの混入と高リスクの脆弱性。audit は警告に留める security: + if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -96,3 +102,41 @@ jobs: - name: pnpm audit (high 以上。警告) run: pnpm audit --audit-level=high --prod continue-on-error: true + + # main に積まれた Conventional Commits から release-please がリリース PR (版と CHANGELOG.md) を開き直す。 + # そのリリース PR をマージした push でリリース (vX.Y.Z のタグと GitHub Release) が作られ、3 つのパッケージを + # 同じ版で GitHub Packages に公開する (docs/adr/0007)。機能のマージだけでは公開しない + release: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + packages: write + steps: + # GITHUB_TOKEN が開いた PR では ci が走らない (Actions の再帰防止)。リリース PR は版と CHANGELOG だけなので + # 検査は要らないが、required check にするなら RELEASE_PLEASE_TOKEN (PAT) を secrets に入れる + - uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0 + id: release + with: + token: ${{ secrets.RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }} + - if: steps.release.outputs.release_created + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - if: steps.release.outputs.release_created + uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 + - if: steps.release.outputs.release_created + uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + with: + node-version: 24.21.0 + cache: pnpm + registry-url: https://npm.pkg.github.com + scope: "@lumorphia" + - if: steps.release.outputs.release_created + run: pnpm install --frozen-lockfile + - if: steps.release.outputs.release_created + run: pnpm build:packages + # workspace:* は公開のときに同じ版に置き換わる (3 つは同じ版でそろって入る) + - if: steps.release.outputs.release_created + run: pnpm --filter "./packages/**" publish --no-git-checks + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 256d763..ec991e2 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ test-results/ playwright-report/ # ブラウザ内の認識のモデルと WASM (editor-models fetch が揃える。git には入れない) apps/*/models/ + +# 公開のときにリポジトリの LICENSE を写す (prepack) +packages/*/LICENSE diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..e18ee07 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.0.0" +} diff --git a/AGENTS.md b/AGENTS.md index 7d3cb3d..f0c8577 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -38,6 +38,13 @@ apps/web -> 上の全部 コミットは `feat:` `fix:` `docs:` `test:` `refactor:` `build:` `ci:` の Conventional Commits、本文は日本語。 +## リリース + +- `main` への push で release-please がリリース PR (版と CHANGELOG.md) を開き直す。リリース PR をマージすると GitHub Release を作り、CI の release ジョブが 3 つのパッケージを同じ版で GitHub Packages に公開する ([ADR-0007](docs/adr/0007-distribution-github-packages.md)) +- `develop` → `main` の PR を作り、マージしてからリリース PR をマージする +- 版の上げ方は Conventional Commits から決まる (`feat:` で minor、`fix:` / `refactor:` / `perf:` で patch。0.x のあいだは破壊的変更も minor)。レシピの互換は [ADR-0008](docs/adr/0008-recipe-compatibility.md) +- 同じ版は出し直せない。公開の設定は `tooling/packages.test.ts` が確かめる + ## テストの書き方 - **1 つの `it` に 1 つの振る舞い**。名前は「何をすると何になる」を言い切る。落ちたときにテスト名だけで何が壊れたか分かるのが目安 diff --git a/README.md b/README.md index e976efd..474b3e6 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,23 @@ 中身は prismtone から履歴ごと移した (`git log --follow` で最初の現像までたどれる)。設計は [docs/design/](docs/design/)、判断は [docs/adr/](docs/adr/README.md)、開発の約束は [AGENTS.md](AGENTS.md)。 +## 使い方 + +GitHub Packages (`npm.pkg.github.com`) に公開している。読むには `read:packages` のトークンが要る。 + +```ini +# .npmrc +@lumorphia:registry=https://npm.pkg.github.com +//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN} +``` + +```sh +pnpm add @lumorphia/editor-react @lumorphia/editor-engine @lumorphia/editor-recipe +pnpm exec editor-models fetch --out models # 認識のモデルと WASM を揃え、/models/ で配る +``` + +ホストに求めること (オリジンの分離、CSP、モデル、CSS、Vite の設定) は [ADR-0009](docs/adr/0009-host-requirements.md)。組み込み方は [apps/web](apps/web/src/main.tsx) が最小の例。 + ## 開発 Node 24.21 以上と pnpm 12.8 以上。 diff --git a/docs/adr/0006-package-boundaries-and-host-adapter.md b/docs/adr/0006-package-boundaries-and-host-adapter.md new file mode 100644 index 0000000..29776f9 --- /dev/null +++ b/docs/adr/0006-package-boundaries-and-host-adapter.md @@ -0,0 +1,45 @@ +# ADR-0006: パッケージを 3 つに分け、ホストに頼むものは EditorHost で受け取る + +| 項目 | 内容 | +| -------- | ---------- | +| Status | Accepted | +| Date | 2026-10-06 | +| Deciders | t1nyb0x | + +## Context + +現像は prismtone に組み込まれて生まれ、i18n、ルーティング、投稿画面の IndexedDB、使用量の計測に直接つながっていた。切り出したあとは、prismtone、単独アプリ (apps/web)、今後のほかのアプリが使う。サーバーと DB はレシピだけを使う。 + +## Decision + +- **3 つのパッケージに分ける**。依存の向きは recipe ← engine ← react ← アプリ。ESLint が強制し、`tooling/eslint-boundaries.test.ts` がルールの効きを確かめる + - `@lumorphia/editor-recipe`: 編集レシピ (zod)。ブラウザでもサーバーでも動く。Node API を使わない + - `@lumorphia/editor-engine`: 状態、履歴、マスク、描画 (PixiJS)、推論 (Worker)、下書き。React を使わない。描画 (`./render`) と推論 (`./inference/face`、`./inference/segment`) は重いので、使う側が動的 import する入口に分ける + - `@lumorphia/editor-react`: UI。``。react-router を使わない +- **エディタはホストを知らない**。ホストに頼むものは `EditorHost` (`packages/editor-react/src/host.ts`) で受け取る + - 表示言語 + - 下書きの置き場所 (`DraftStore`) と開く下書き + - 送り先 (`destinations`)。書き出した画像、レシピ、原本、draftId を渡す + - 使用量の計測 (`telemetry`。誰かは渡さない) + - モデルの置き場所、保存ファイル名の接尾辞、E2E のフック +- 送り先が 0 件なら「端末に保存」だけを出す (単独アプリ)。prismtone は「投稿へ」の 1 件 + +## Consequences + +### 良い点 + +- ホストを足すときにエディタを直さなくてよい。prismtone 固有の仕組み (投稿画面、件数の数え方) はホストの側に閉じる +- サーバーは描画や React を持ち込まずにレシピを検証できる + +### 悪い点・受け入れるリスク + +- `EditorHost` を変えると、すべてのホストに波及する。足すときは省略できる形 (任意) にする + +## Alternatives + +- 1 つのパッケージにまとめる: サーバーが PixiJS や React まで依存に持つ +- ホストを props ではなく React の context で渡す: どれが必須か型で分からない + +## References + +- lumorphia/prismtone ADR-0035、lumorphia/prismtone#357、#358 diff --git a/docs/adr/0007-distribution-github-packages.md b/docs/adr/0007-distribution-github-packages.md new file mode 100644 index 0000000..ba43fdc --- /dev/null +++ b/docs/adr/0007-distribution-github-packages.md @@ -0,0 +1,46 @@ +# ADR-0007: GitHub Packages に 1 つの版で、ビルド済みの ESM として配る + +| 項目 | 内容 | +| -------- | ---------- | +| Status | Accepted | +| Date | 2026-10-06 | +| Deciders | t1nyb0x | + +## Context + +prismtone はパッケージを workspace のソース (.ts) のまま使っていた。別のリポジトリから使うには、配る形と置き場所を決める必要がある。Node は `node_modules` の中の .ts の型を剥がさないので、サーバーが使うレシピは JS で配る必要がある。 + +## Decision + +- **置き場所は GitHub Packages** (`npm.pkg.github.com`、スコープ `@lumorphia`)。読むには `read:packages` のトークンが要る +- **3 つを 1 つの版で上げる**。release-please がリポジトリの版を上げ、`extra-files` で 3 つの `package.json` の `version` を同じ値にする。リリース PR のマージで GitHub Release を作り、CI の release ジョブが 3 つを公開する。パッケージ同士の `workspace:*` は公開のときに同じ版 (固定) に置き換わる +- **ビルド済みの ESM を配る** (tsc。.d.ts と source map 付き、ESM のみ)。exports は条件付き: + - `source` (src): このリポジトリの型検査 (`customConditions`) と Vitest (`vitest.source.ts`)。ビルドせずにテストできる + - `types` / `default` (dist): それ以外 (ホストの Vite、Node の実行) + - `files` に src も入れる (source map の元。ホストが `source` 条件で読むこともできる) +- **Worker は束ねずに配る**。dist でも `new Worker(new URL("./x.worker.js", import.meta.url))` の形にし (`scripts/finish-dist.ts`)、ホストの Vite に束ねさせる。MediaPipe と transformers.js を dist に抱え込まない +- **モデルと WASM はパッケージに入れない**。engine の CLI `editor-models fetch --out ` が sha256 を固定して揃える (`bin/assets.ts`)。WASM は engine の依存からコピーするので、JS と WASM の版がずれない +- **zod は editor-recipe の `dependencies`** (peer にしない)。peer にすると、workspace のまま本番用の依存だけを入れた prismtone の Docker で、recipe から zod が見えなかった (lumorphia/prismtone#365)。ホストと同じ範囲 (`^4`) にして、pnpm の lockfile で 1 つの版に寄せる。ブラウザではホストの Vite の `resolve.dedupe` で 1 つにする (zod の jitless の設定は読み込んだ実体にだけ効く) + +## Consequences + +### 良い点 + +- ホストは版を固定して使え、Renovate で上げられる +- 3 つの版が常にそろうので、組み合わせの互換を考えなくてよい + +### 悪い点・受け入れるリスク + +- 読むのにトークンが要る (CI、Docker build、開発者の手元)。パッケージの設定で、使うリポジトリの Actions に読み取りを許す +- 変更がなくても 3 つとも版が上がる +- zod の版がホストとずれると、サーバーで 2 つの実体になりうる (サーバーは CSP の制約が無く、検証は動く) + +## Alternatives + +- npmjs.com に公開する: 公開範囲を広げる判断はまだしない +- パッケージごとに版を付ける (release-please の node-workspace): 組み合わせの互換表が要り、workspace:* の書き換えも入る +- Vite の lib モードで Worker まで束ねる: dist が重くなり、ホスト側の MediaPipe / transformers.js と二重に持つ + +## References + +- lumorphia/prismtone#359、#365 diff --git a/docs/adr/0008-recipe-compatibility.md b/docs/adr/0008-recipe-compatibility.md new file mode 100644 index 0000000..5e05013 --- /dev/null +++ b/docs/adr/0008-recipe-compatibility.md @@ -0,0 +1,34 @@ +# ADR-0008: レシピの互換は足すだけ、読めなくする変更は major + +| 項目 | 内容 | +| -------- | ---------- | +| Status | Accepted | +| Date | 2026-10-06 | +| Deciders | t1nyb0x | + +## Context + +レシピ (`@lumorphia/editor-recipe`) は、ホストの DB (prismtone の `edit_recipes`)、端末の下書き (IndexedDB)、今後は書き出した画像のメタデータ (lumorphia/prismtone#352) や送客 (#6) にも残る。エディタとホストは別々に版を上げるので、どちらが古くても読める必要がある。ADR-0003 (prismtone ADR-0009) の「変更は足すだけ」を、パッケージの版の決まりにつなげる。 + +## Decision + +- レシピの形式は **新しい版を足す** (`version` を上げ、`migrateV{n}toV{n+1}` を足す)。既存の版のスキーマは変えない。今は v4 +- 読む側は **必ず `migrateRecipe` (保存したものは `upgradeStoredRecipe`) を通す** +- パッケージの版 (semver) との対応: + - レシピの新しい版を足す: minor。古いエディタは新しい版を読めないので、ホストは先にサーバー (検証) を上げる + - 既存の版を読めなくする、`migrateRecipe` の結果を変える: major + - 0.x のあいだは minor を major として扱う (release-please の `bump-minor-pre-major`) + +## Consequences + +### 良い点 + +- 保存済みのレシピが、エディタの版を上げても読める + +### 悪い点・受け入れるリスク + +- 古い版のスキーマを持ち続ける + +## References + +- ADR-0003、lumorphia/prismtone ADR-0009 diff --git a/docs/adr/0009-host-requirements.md b/docs/adr/0009-host-requirements.md new file mode 100644 index 0000000..9985e73 --- /dev/null +++ b/docs/adr/0009-host-requirements.md @@ -0,0 +1,37 @@ +# ADR-0009: ホストに求めること (オリジンの分離、CSP、モデル、CSS、バンドラ) + +| 項目 | 内容 | +| -------- | ---------- | +| Status | Accepted | +| Date | 2026-10-06 | +| Deciders | t1nyb0x | + +## Context + +エディタはブラウザの WebGL、Web Worker、WebAssembly、SharedArrayBuffer を使い、ホストのヘッダと CSS とバンドラの設定に頼る。prismtone と単独アプリ (apps/web) で動いている設定を、ほかのホストにも求める形で書いておく。 + +## Decision + +ホストは次を満たす。apps/web と E2E が確かめる。 + +- **オリジンの分離**: エディタのページに `Cross-Origin-Opener-Policy: same-origin` と `Cross-Origin-Embedder-Policy: credentialless`。Worker のスクリプトとその import 先にも COEP が要る (文書以外の応答に付ける)。onnxruntime-web がマルチスレッドで動く +- **CSP**: `script-src` に `'wasm-unsafe-eval'` (`'unsafe-eval'` は要らない)、`worker-src 'self' blob:`、`img-src` に `data:` と `blob:`。エディタは外のオリジンに出ていかない +- **モデル**: `editor-models fetch --out ` で揃えたものを、同じオリジンで配る (既定の URL は `/models/`、変えるなら `EditorHost.inference.modelBaseUrl`)。ディレクトリは版付きなので immutable でキャッシュしてよい。dev の Vite の `public/` には置かない (`import()` に `?import` が足されて MediaPipe のローダーが読めない) +- **CSS**: Tailwind v4 で `@source` に `@lumorphia/editor-react` の場所を足す (`node_modules` は自分では走査しない。抜けると `touch-none` などが CSS に入らず、ピンチでページごと拡大する)。意味名のトークン (`surface*`、`ink*`、`line*`、`accent*`) を定義する +- **Vite**: `optimizeDeps.exclude: ["@lumorphia/editor-engine"]` (事前バンドルで Worker の相対 URL が壊れる)、`optimizeDeps.include` に `@mediapipe/tasks-vision` と `@huggingface/transformers` (dev で押したときの再読み込みを避ける)、`resolve.dedupe: ["react", "react-dom", "zod"]` +- **下書き**: IndexedDB の名前はホストごとに決め、変えない (変えると利用者の下書きが読めなくなる) + +## Consequences + +### 良い点 + +- 新しいホストが何を用意すればよいかが 1 か所で分かる + +### 悪い点・受け入れるリスク + +- オリジンの分離は、ページに埋め込む外部のリソース (画像、iframe) を制限する。エディタのページだけに付けるのがよい (prismtone は `/edit` だけ) +- オリジンの分離をしたページどうしでは `window.open` と `postMessage` で受け渡せない。送客 (#6) は別の方法にする + +## References + +- ADR-0005、lumorphia/prismtone ADR-0035、`apps/web/server/static.ts`、`apps/web/vite.config.ts` diff --git a/docs/adr/README.md b/docs/adr/README.md index bab020c..8f3c95d 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -1,12 +1,16 @@ # ADR の一覧 -| 番号 | 決めたこと | 元 | -| -------------------------------------------------- | ---------------------------------------------- | ------------------ | -| [0001](0001-record-architecture-decisions.md) | ADR を使う | | -| [0002](0002-client-side-editing-and-export.md) | 編集と書き出しはブラウザで行う | prismtone ADR-0005 | -| [0003](0003-versioned-edit-recipe.md) | 編集レシピは版付きの JSON、変更は足すだけ | prismtone ADR-0009 | -| [0004](0004-two-stage-render-local-adjustments.md) | 合成の段と表示の段、部分補正はフィルタを重ねる | prismtone ADR-0021 | -| [0005](0005-in-browser-inference-and-recipe-v3.md) | 認識はブラウザの中で、モデルは自前で配る | prismtone ADR-0025 | +| 番号 | 決めたこと | 元 | +| --------------------------------------------------- | --------------------------------------------------------------- | ------------------ | +| [0001](0001-record-architecture-decisions.md) | ADR を使う | | +| [0002](0002-client-side-editing-and-export.md) | 編集と書き出しはブラウザで行う | prismtone ADR-0005 | +| [0003](0003-versioned-edit-recipe.md) | 編集レシピは版付きの JSON、変更は足すだけ | prismtone ADR-0009 | +| [0004](0004-two-stage-render-local-adjustments.md) | 合成の段と表示の段、部分補正はフィルタを重ねる | prismtone ADR-0021 | +| [0005](0005-in-browser-inference-and-recipe-v3.md) | 認識はブラウザの中で、モデルは自前で配る | prismtone ADR-0025 | +| [0006](0006-package-boundaries-and-host-adapter.md) | パッケージを 3 つに分け、ホストに頼むものは EditorHost で | | +| [0007](0007-distribution-github-packages.md) | GitHub Packages に 1 つの版で、ビルド済みの ESM として配る | | +| [0008](0008-recipe-compatibility.md) | レシピの互換は足すだけ、読めなくする変更は major | | +| [0009](0009-host-requirements.md) | ホストに求めること (オリジンの分離、CSP、モデル、CSS、バンドラ) | | 0002〜0005 は lumorphia/prismtone から移植したもので、本文中の ADR の番号は prismtone のもの。対応は次のとおり。 diff --git a/packages/editor-engine/package.json b/packages/editor-engine/package.json index a0fc108..b8ad5dd 100644 --- a/packages/editor-engine/package.json +++ b/packages/editor-engine/package.json @@ -1,7 +1,16 @@ { "name": "@lumorphia/editor-engine", "version": "0.0.0", - "private": true, + "description": "現像のエンジン。状態、描画 (PixiJS / WebGL)、ブラウザ内の認識 (Worker)、下書き、モデル取得の CLI", + "license": "AGPL-3.0-only", + "repository": { + "type": "git", + "url": "git+https://github.com/lumorphia/editor.git", + "directory": "packages/editor-engine" + }, + "publishConfig": { + "registry": "https://npm.pkg.github.com" + }, "type": "module", "exports": { ".": { @@ -33,7 +42,9 @@ "scripts": { "build": "rm -rf dist && tsc -p tsconfig.build.json && node scripts/finish-dist.ts && tsc -p tsconfig.bin.json", "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.node.json", - "test": "vitest run" + "test": "vitest run", + "prepack": "cp ../../LICENSE LICENSE", + "postpack": "rm -f LICENSE" }, "dependencies": { "@huggingface/transformers": "^3.8.1", diff --git a/packages/editor-react/package.json b/packages/editor-react/package.json index 6cd90a4..3f9486c 100644 --- a/packages/editor-react/package.json +++ b/packages/editor-react/package.json @@ -1,7 +1,16 @@ { "name": "@lumorphia/editor-react", "version": "0.0.0", - "private": true, + "description": "現像の UI。 でホストに組み込む", + "license": "AGPL-3.0-only", + "repository": { + "type": "git", + "url": "git+https://github.com/lumorphia/editor.git", + "directory": "packages/editor-react" + }, + "publishConfig": { + "registry": "https://npm.pkg.github.com" + }, "type": "module", "exports": { ".": { @@ -13,7 +22,9 @@ "scripts": { "build": "rm -rf dist && tsc -p tsconfig.build.json", "typecheck": "tsc -p tsconfig.json", - "test": "vitest run" + "test": "vitest run", + "prepack": "cp ../../LICENSE LICENSE", + "postpack": "rm -f LICENSE" }, "dependencies": { "@lumorphia/editor-engine": "workspace:*", diff --git a/packages/editor-recipe/package.json b/packages/editor-recipe/package.json index b19707a..29f5f6c 100644 --- a/packages/editor-recipe/package.json +++ b/packages/editor-recipe/package.json @@ -1,7 +1,16 @@ { "name": "@lumorphia/editor-recipe", "version": "0.0.0", - "private": true, + "description": "現像の編集レシピ (zod)。ブラウザとサーバーの両方で動く", + "license": "AGPL-3.0-only", + "repository": { + "type": "git", + "url": "git+https://github.com/lumorphia/editor.git", + "directory": "packages/editor-recipe" + }, + "publishConfig": { + "registry": "https://npm.pkg.github.com" + }, "type": "module", "exports": { ".": { @@ -18,7 +27,9 @@ "scripts": { "build": "rm -rf dist && tsc -p tsconfig.build.json", "typecheck": "tsc -p tsconfig.json", - "test": "vitest run" + "test": "vitest run", + "prepack": "cp ../../LICENSE LICENSE", + "postpack": "rm -f LICENSE" }, "files": [ "dist", diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..ab512e0 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,28 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "release-type": "node", + "include-component-in-tag": false, + "bump-minor-pre-major": true, + "bootstrap-sha": "f92c3e49001908c53349890ca438dfc56efc4bbb", + "changelog-sections": [ + { "type": "feat", "section": "Features" }, + { "type": "fix", "section": "Bug Fixes" }, + { "type": "perf", "section": "Performance" }, + { "type": "refactor", "section": "Refactoring" }, + { "type": "docs", "section": "Documentation", "hidden": true }, + { "type": "test", "section": "Tests", "hidden": true }, + { "type": "build", "section": "Build", "hidden": true }, + { "type": "ci", "section": "CI", "hidden": true }, + { "type": "chore", "section": "Chores", "hidden": true } + ], + "packages": { + ".": { + "package-name": "lumorphia-editor", + "extra-files": [ + { "type": "json", "path": "packages/editor-recipe/package.json", "jsonpath": "$.version" }, + { "type": "json", "path": "packages/editor-engine/package.json", "jsonpath": "$.version" }, + { "type": "json", "path": "packages/editor-react/package.json", "jsonpath": "$.version" } + ] + } + } +} diff --git a/tooling/packages.test.ts b/tooling/packages.test.ts new file mode 100644 index 0000000..3ab2bc6 --- /dev/null +++ b/tooling/packages.test.ts @@ -0,0 +1,51 @@ +import { readFileSync } from "node:fs"; +import { describe, expect, it } from "vitest"; + +// 公開する 3 つのパッケージの package.json の決まり。公開してから気づくと直せない (同じ版は出し直せない) +const root = new URL("..", import.meta.url); +const read = (path: string) => + JSON.parse(readFileSync(new URL(path, root), "utf8")) as Record & { + version: string; + }; + +const PACKAGES = ["editor-recipe", "editor-engine", "editor-react"] as const; + +describe.each(PACKAGES)("@lumorphia/%s", (dir) => { + const pkg = read(`packages/${dir}/package.json`); + + it("is published to GitHub Packages", () => { + expect(pkg.private).toBeUndefined(); + expect(pkg.publishConfig).toEqual({ registry: "https://npm.pkg.github.com" }); + }); + + it("points at this repository so GitHub links the package to it", () => { + expect(pkg.repository).toEqual({ + type: "git", + url: "git+https://github.com/lumorphia/editor.git", + directory: `packages/${dir}`, + }); + }); + + it("carries the license of the repository", () => { + expect(pkg.license).toBe("AGPL-3.0-only"); + }); + + it("ships the built files", () => { + expect(pkg.files).toContain("dist"); + }); + + it("shares one version with the repository (release-please bumps them together)", () => { + expect(pkg.version).toBe(read("package.json").version); + }); +}); + +describe("release-please", () => { + const config = read("release-please-config.json") as unknown as { + packages: Record; + }; + + it("bumps the version of every published package", () => { + const files = config.packages["."]?.["extra-files"]?.map((f) => f.path) ?? []; + expect(files).toEqual(PACKAGES.map((dir) => `packages/${dir}/package.json`)); + }); +});