Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/preset-previews.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
---

Add `previews/<preset>/vite.config.ts` and `pnpm preview:<preset>` scripts to
view each lint preset's effective rules with vite-plus-inspector. A
`pnpm preview:build` script plus a Preview workflow deploy a self-contained,
per-PR Cloudflare Pages site so each preset's effective rules can be browsed
from the PR. Dev tooling only — not part of the published package, so no
release.
48 changes: 48 additions & 0 deletions .github/scripts/preview-comment.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env node
// プリセットプレビューのデプロイ先URLをまとめたPRコメント本文(Markdown)を
// 標準出力に書く。Cloudflare Pages へのデプロイURLは PREVIEW_URL で受け取る。
//
// 使い方: PREVIEW_URL=https://pr-1.oxc-config-preview.pages.dev \
// node .github/scripts/preview-comment.mjs
import { readdirSync } from 'node:fs';
import { resolve } from 'node:path';

const marker = '<!-- oxc-config-preview -->';
const baseUrl = (process.env['PREVIEW_URL'] ?? '').replace(/\/+$/u, '');
const runUrl = process.env['RUN_URL'] ?? '';

const root = resolve(import.meta.dirname, '..', '..');
const presets = readdirSync(resolve(root, 'previews'), { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name)
.sort();

const lines = [marker, '## 🔍 Preset previews', ''];

if (baseUrl === '') {
// CLOUDFLARE_API_TOKEN 未登録などでデプロイをスキップした場合のフォールバック
lines.push(
'プレビューのデプロイはスキップされました(`CLOUDFLARE_API_TOKEN` 未登録の可能性)。',
);
if (runUrl !== '') {
lines.push('', `生成ログ: ${runUrl}`);
}
} else {
lines.push(
`各 lint プリセットの effective ルールをブラウザで確認できます → **[一覧を開く](${baseUrl}/)**`,
'',
'| preset | preview |',
'| --- | --- |',
);
for (const preset of presets) {
lines.push(
`| \`${preset}\` | [${preset}.html](${baseUrl}/${preset}.html) |`,
);
}
lines.push(
'',
'<sub>このPRのブランチに対応する最新のプレビューです。push のたびに更新されます。</sub>',
);
}

process.stdout.write(`${lines.join('\n')}\n`);
66 changes: 66 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Preview

on:
pull_request:

concurrency:
group: preview-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
pull-requests: write

jobs:
preview:
name: Preset previews
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false

- name: Install
uses: ./.github/composite-actions/install

- name: Build preset previews
# 各プリセットの effective ルールを自己完結HTMLに書き出す(dist-preview/)。
# npx/pnpx は使わず、ローカルの vp-inspect / vp バイナリだけを実行する。
run: pnpm preview:build

- name: Publish previews to Cloudflare Pages
id: pages
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: 31074c2d041f3ceb8a5bb3fc51dd3bfa
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
# トークン未登録の間はスキップし、コメントはフォールバック表示になる
if [ -z "$CLOUDFLARE_API_TOKEN" ]; then
echo 'CLOUDFLARE_API_TOKEN が未登録のためPagesへの公開をスキップ'
exit 0
fi
pnpm exec wrangler pages project create oxc-config-preview --production-branch=main 2>/dev/null || true
pnpm exec wrangler pages deploy dist-preview --project-name=oxc-config-preview --branch="pr-$PR_NUMBER" --commit-dirty=true
echo "url=https://pr-$PR_NUMBER.oxc-config-preview.pages.dev" >> "$GITHUB_OUTPUT"

- name: Comment preview links on PR
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
PREVIEW_URL: ${{ steps.pages.outputs.url }}
run: |
node .github/scripts/preview-comment.mjs > comment.md
marker='<!-- oxc-config-preview -->'
comment_id=$(gh api "repos/$REPO/issues/$PR_NUMBER/comments" --paginate --jq ".[] | select(.body | startswith(\"$marker\")) | .id" | head -n1)
# sticky comment: 既存があれば編集(PATCH)し、無ければ新規投稿する。
# push のたびに新規コメントが増えるのを防ぐ。
if [ -n "$comment_id" ]; then
gh api --method PATCH "repos/$REPO/issues/comments/$comment_id" -F body=@comment.md > /dev/null
else
gh api "repos/$REPO/issues/$PR_NUMBER/comments" -F body=@comment.md > /dev/null
fi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
dist
dist-preview
coverage
*.log
.DS_Store
Expand Down
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@
"check": "vp check",
"check:write": "vp check --fix",
"typecheck": "tsc --noEmit",
"preview": "vp-inspect previews/nextjs",
"preview:base": "vp-inspect previews/base",
"preview:typescript": "vp-inspect previews/typescript",
"preview:react": "vp-inspect previews/react",
"preview:nextjs": "vp-inspect previews/nextjs",
"preview:backend": "vp-inspect previews/backend",
"preview:test": "vp-inspect previews/test",
"preview:tailwind": "vp-inspect previews/tailwind",
"preview:build": "node scripts/build-previews.mjs",
"changeset": "changeset",
"version": "changeset version",
"release": "pnpm build && changeset publish",
Expand All @@ -114,7 +123,9 @@
"oxlint": "1.66.0",
"oxlint-tailwindcss": "0.8.0",
"typescript": "6.0.3",
"vite-plus": "0.1.22"
"vite-plus": "0.1.22",
"vite-plus-inspector": "0.1.0",
"wrangler": "4.98.0"
},
"peerDependencies": {
"oxfmt": ">=0.43.0",
Expand Down
Loading