@ryusenkei/conventions 0.8.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +97 -4
- package/dist/affected-check.d.ts +31 -0
- package/dist/affected-check.js +119 -0
- package/dist/affected.d.ts +32 -0
- package/dist/affected.js +38 -0
- package/dist/check-record.d.ts +4 -0
- package/dist/check-record.js +20 -0
- package/dist/cli.js +16 -2
- package/dist/files.js +8 -3
- package/dist/hook.js +7 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/policy.d.ts +2 -0
- package/dist/policy.js +8 -6
- package/dist/test-exclude.d.ts +11 -0
- package/dist/test-exclude.js +22 -0
- package/files/gitignore +2 -0
- package/package.json +3 -2
- package/rules-ts.md +2 -2
- package/rules.md +3 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
- `runAffectedCheck`: the pre-push `pnpm check` from `scripts/check.ts`. It type checks the changed packages and their dependents and runs the tests that import a changed file, against the nearest of `origin/main` and `origin/dev/*`; `--all` checks everything. The type check and the tests run one after the other to keep the peak memory low. See [Pre-push check](README.md#pre-push-check).
|
|
6
|
+
- The `check` script that `check` asks for is now `node scripts/check.ts` with `runAffectedCheck`. Repositories with their own `scripts/check.ts` (zrgn, pcpalette.com) can replace the shared part with it.
|
|
7
|
+
- `pnpm check` records each passing commit in the common git directory, and the hook lets `gh pr merge` through without passing checks when the PR's head passed `pnpm check --base origin/<base>` (or `--all`). A PR doesn't get stuck when CI doesn't run.
|
|
8
|
+
- `reusable-ci.yaml` skips draft PRs, caches the pnpm store, and takes `affected: true` to run `pnpm check --base origin/<base>` instead of the full check. Add `ready_for_review` to the caller's `types` so a PR is checked when it's marked ready.
|
|
9
|
+
- `rules.md`: open PRs to `main` as drafts and mark them ready before merging; run `pnpm check --all` locally before deploying.
|
|
10
|
+
|
|
11
|
+
## 0.9.0
|
|
12
|
+
|
|
13
|
+
- `TEST_EXCLUDE` (`.claude/**`, `**/.terraform/**`): patterns to add to Vitest's default `exclude`.
|
|
14
|
+
- `check` reports a root Vitest config without them, or a repository that depends on `vitest` without a root config. Add `exclude: [...configDefaults.exclude, ...TEST_EXCLUDE]` to the root `vitest.config.ts`.
|
|
15
|
+
- The shared `.gitignore` ignores `.terraform/`. Run `ryusenkei-conventions sync`.
|
|
16
|
+
- `rules-ts.md` names `execSync` from `@ryusenkei/scripts` 0.4 (`exec` was renamed) and the Vitest exclude.
|
|
17
|
+
- The CLI exits with 2 for an unknown option (it crashed with 1) and takes `--help`.
|
|
18
|
+
|
|
19
|
+
## 0.8.2 and earlier
|
|
20
|
+
|
|
21
|
+
See the git history of `packages/conventions`.
|
package/README.md
CHANGED
|
@@ -9,6 +9,8 @@ Shared conventions for RYUSENKEI monorepos created from monorepo-template. Rules
|
|
|
9
9
|
| `dist/hook.js` | Claude Code hook: blocks tool calls that break the rules, and optionally runs lint and tests before Claude finishes |
|
|
10
10
|
| `files/` | Master copies of the shared files, synced into each repository |
|
|
11
11
|
| `ryusenkei-conventions` | CLI: `sync` writes the shared files, `check` reports drift |
|
|
12
|
+
| `TEST_EXCLUDE` | Patterns to add to Vitest's default `exclude` |
|
|
13
|
+
| `runAffectedCheck` | The pre-push `pnpm check`: type checks and tests only what the change affects |
|
|
12
14
|
|
|
13
15
|
## Install
|
|
14
16
|
|
|
@@ -37,6 +39,7 @@ Requires Node.js 24 or later.
|
|
|
37
39
|
|
|
38
40
|
2. Write the shared files: `npx ryusenkei-conventions sync` (add `--stop` to run lint and tests before Claude finishes).
|
|
39
41
|
3. Add `ryusenkei-conventions check` to the `lint` script.
|
|
42
|
+
4. With Vitest, exclude `TEST_EXCLUDE` in the root `vitest.config.ts` (see [Vitest](#vitest)).
|
|
40
43
|
|
|
41
44
|
- Claude Code expands the import when a session starts. Run `pnpm install` first, or the rules are not loaded.
|
|
42
45
|
- The import resolves inside the working directory, so Claude Code does not ask for approval of external imports.
|
|
@@ -55,7 +58,7 @@ The PreToolUse hook blocks the call and tells Claude why, so Claude can fix it a
|
|
|
55
58
|
| PR title = squash commit message | Checks `gh pr create` / `gh pr edit` titles with prose-lint's commit rules |
|
|
56
59
|
| No AI signature | `attribution` is empty, and the hook blocks PR bodies with an AI signature |
|
|
57
60
|
| Squash merge | Blocks `gh pr merge --rebase` and `--merge`, also for a `dev/*` → `main` PR with the epic flow |
|
|
58
|
-
| Merge only after CI passes | Blocks `gh pr merge` unless every check of the PR has passed (`gh pr checks`). Pending, failed, missing, or unreadable checks are blocked, also with `--auto`. A PR may have no checks only when the repository has no enabled workflow that runs on `pull_request` (workflows disabled on GitHub with `gh workflow disable` don't count; the pre-push `pnpm check` is the gate), or with the epic flow when it targets `dev/*`. Right after a push, the checks may not be registered yet, so the hook points to `gh pr checks --watch` |
|
|
61
|
+
| Merge only after CI passes | Blocks `gh pr merge` unless every check of the PR has passed (`gh pr checks`), or the PR's head commit passed the local `pnpm check` against the PR's base (see [Pre-push check](#pre-push-check)). Pending, failed, missing, or unreadable checks are blocked, also with `--auto`. A PR may have no checks only when the repository has no enabled workflow that runs on `pull_request` (workflows disabled on GitHub with `gh workflow disable` don't count; the pre-push `pnpm check` is the gate), or with the epic flow when it targets `dev/*`. Right after a push, the checks may not be registered yet, so the hook points to `gh pr checks --watch` |
|
|
59
62
|
| Epic flow (opt-in) | See [Epic flow](#epic-flow) |
|
|
60
63
|
| Do not edit `node_modules` | Blocks Edit and Write under `node_modules` |
|
|
61
64
|
| Secrets | `permissions.deny` blocks reading `.env` and `.dev.vars` with Claude's file tools (not Bash) |
|
|
@@ -106,10 +109,69 @@ Opt in per repository in the root `package.json`:
|
|
|
106
109
|
|
|
107
110
|
When the `rules.md` import is present, `sync` adds the missing ones right after it.
|
|
108
111
|
|
|
109
|
-
`check` also reports a root `package.json` without a `check` script, since the pre-push hook runs `pnpm check` and pushes unchecked without one. Add it by hand
|
|
112
|
+
`check` also reports a missing or incomplete root Vitest config when the root `package.json` depends on `vitest` (see [Vitest](#vitest)), and a root `package.json` without a `check` script, since the pre-push hook runs `pnpm check` and pushes unchecked without one. Add it by hand, as `node scripts/check.ts` with [`runAffectedCheck`](#pre-push-check).
|
|
110
113
|
|
|
111
114
|
Dependabot runs monthly with `rebase-strategy: disabled` to save GitHub Actions minutes, so rebase a Dependabot PR (`@dependabot rebase`) before merging it. The `cooldown` excludes `@ryusenkei/*`. To pick up a new version sooner, run `pnpm update "@ryusenkei/*"`. After an update, `check` fails until `sync` is run.
|
|
112
115
|
|
|
116
|
+
## Vitest
|
|
117
|
+
|
|
118
|
+
`TEST_EXCLUDE` is what every repository adds to Vitest's default `exclude`:
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
// vitest.config.ts
|
|
122
|
+
import { TEST_EXCLUDE } from '@ryusenkei/conventions';
|
|
123
|
+
import { configDefaults, defineConfig } from 'vitest/config';
|
|
124
|
+
|
|
125
|
+
export default defineConfig({
|
|
126
|
+
test: {
|
|
127
|
+
exclude: [...configDefaults.exclude, ...TEST_EXCLUDE],
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
| Pattern | Why |
|
|
133
|
+
| --- | --- |
|
|
134
|
+
| `.claude/**` | Agents' worktrees inside the repository would run the same tests twice |
|
|
135
|
+
| `**/.terraform/**` | `terraform init` downloads a Git module source as the whole repository (toolkit's tests included) into `.terraform/modules/` |
|
|
136
|
+
|
|
137
|
+
`check` reports a root `vitest.config.*` that neither uses `TEST_EXCLUDE` nor lists every pattern, and a repository that depends on `vitest` without one. It can't fix this by itself, since each repository's config differs. The shared `.gitignore` ignores `.terraform/` as well (`.terraform.lock.hcl` stays tracked).
|
|
138
|
+
|
|
139
|
+
`ryusenkei-conventions` exits with 0 when nothing drifts, 1 when something does, and 2 for a usage error; `--help` exits with 0.
|
|
140
|
+
|
|
141
|
+
## Pre-push check
|
|
142
|
+
|
|
143
|
+
`runAffectedCheck` runs the type checks and tests a change affects, so a push doesn't wait for the whole repository. Each repository passes its own fast checks:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
// scripts/check.ts (package.json: "check": "node scripts/check.ts")
|
|
147
|
+
import { runAffectedCheck } from '@ryusenkei/conventions';
|
|
148
|
+
|
|
149
|
+
const results = await runAffectedCheck({
|
|
150
|
+
steps: () => [
|
|
151
|
+
{ name: 'prose-lint', command: 'pnpm', args: ['exec', 'prose-lint'] },
|
|
152
|
+
{ name: 'conventions', command: 'pnpm', args: ['exec', 'ryusenkei-conventions', 'check'] },
|
|
153
|
+
{ name: 'deps', command: 'node', args: ['scripts/deps.ts'] },
|
|
154
|
+
],
|
|
155
|
+
});
|
|
156
|
+
process.exitCode = results.every((r) => r.ok) ? 0 : 1;
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
| Scope | What runs |
|
|
160
|
+
| --- | --- |
|
|
161
|
+
| Base | The merge base with the nearest of `origin/main` and `origin/dev/*` (fewest commits to `HEAD`), excluding the branch's own remote. A sub-issue branch is checked against its epic's `dev/*`, and a `dev/*` branch against `main` |
|
|
162
|
+
| Changes | Committed, uncommitted and untracked files since the base. Markdown doesn't count |
|
|
163
|
+
| Type check | `typecheck` of the changed packages and their dependents (`pnpm -r --filter ...<name>`), and the root `tsc` when a `.ts` file outside the packages changed. Packages that import the root `scripts/` count as changed with it |
|
|
164
|
+
| Tests | `vitest run --changed <base>` (tests that import a changed file) |
|
|
165
|
+
| Everything | `pnpm typecheck` and all tests, with `--all`, without a base, or when a root config changed (`package.json`, `pnpm-workspace.yaml`, `tsconfig*.json`, `vitest.config.*`, `mise.toml`, `.npmrc`, or `pnpm-lock.yaml` without a package's `package.json`) |
|
|
166
|
+
|
|
167
|
+
- The type check and the tests run one after the other, and `steps` run beside them. This keeps the peak memory to one heavy process tree, so parallel pushes from other worktrees fit (`concurrency` sets how many packages `tsc` checks at once, default 2).
|
|
168
|
+
- `--base <ref>` sets the base. `globalFiles` adds files that mean everything, and `testArgs` adds Vitest arguments such as reporters.
|
|
169
|
+
- Run it through `pnpm` (`pnpm check`). It starts `pnpm` from `npm_execpath`.
|
|
170
|
+
|
|
171
|
+
The whole repository is checked with `pnpm check --all` locally before deploying.
|
|
172
|
+
|
|
173
|
+
When `pnpm check` passes with a clean working tree, it records the commit and the base it checked in the common git directory (`ryusenkei-check/<sha>`). `gh pr merge` accepts a PR without passing checks when its head commit has a record for the PR's base (`origin/<base>`) or for `--all`. So when CI doesn't run (the free minutes ran out, or the workflow is disabled), run `pnpm check --base origin/main` on the PR's head and merge. A push of a `dev/*` branch is checked against `origin/main`, so it records that already.
|
|
174
|
+
|
|
113
175
|
## Dependency direction
|
|
114
176
|
|
|
115
177
|
`runDepsCheck` checks imports in the sources and the dependencies in each `package.json` against the layer rules of the repository. Each repository keeps only its rules:
|
|
@@ -153,7 +215,7 @@ name: CI
|
|
|
153
215
|
on:
|
|
154
216
|
pull_request:
|
|
155
217
|
branches: [main]
|
|
156
|
-
types: [opened, synchronize, reopened]
|
|
218
|
+
types: [opened, synchronize, reopened, ready_for_review]
|
|
157
219
|
concurrency:
|
|
158
220
|
group: ci-${{ github.ref }}
|
|
159
221
|
cancel-in-progress: true
|
|
@@ -167,6 +229,32 @@ jobs:
|
|
|
167
229
|
pnpm lint:deps
|
|
168
230
|
```
|
|
169
231
|
|
|
232
|
+
- The job is skipped while the PR is a draft and runs when it is marked ready (`ready_for_review`), to save the free minutes.
|
|
233
|
+
- `affected: true` runs `pnpm check --base origin/<base>` ([Pre-push check](#pre-push-check)) instead of the full type check, tests and prose-lint. Use it where the full check takes too long for the free minutes; the full check then runs locally before deploying.
|
|
234
|
+
|
|
235
|
+
Go, with releases on `v*` tags:
|
|
236
|
+
|
|
237
|
+
```yaml
|
|
238
|
+
# in .github/workflows/ci.yaml, next to the ci job
|
|
239
|
+
go:
|
|
240
|
+
uses: ryusenkei-inc/toolkit/.github/workflows/reusable-go.yaml@main
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
```yaml
|
|
244
|
+
# .github/workflows/release.yaml
|
|
245
|
+
name: Release
|
|
246
|
+
on:
|
|
247
|
+
push:
|
|
248
|
+
tags: ['v*']
|
|
249
|
+
permissions:
|
|
250
|
+
contents: write
|
|
251
|
+
jobs:
|
|
252
|
+
release:
|
|
253
|
+
uses: ryusenkei-inc/toolkit/.github/workflows/reusable-go-release.yaml@main
|
|
254
|
+
with:
|
|
255
|
+
checks: test "v$(node -p "require('./package.json').version")" = "$GITHUB_REF_NAME"
|
|
256
|
+
```
|
|
257
|
+
|
|
170
258
|
```yaml
|
|
171
259
|
# .github/workflows/pr-title.yaml
|
|
172
260
|
name: PR title
|
|
@@ -188,9 +276,12 @@ jobs:
|
|
|
188
276
|
| --- | --- |
|
|
189
277
|
| `reusable-ci.yaml` | Checkout (full history), mise, pnpm, `pnpm install --frozen-lockfile`, `pnpm typecheck`, `pnpm test`, `pnpm lint:prose`, the `checks` input, the PR title with prose-lint's commit rules (not for Dependabot), and a gitleaks scan with `.gitleaks.toml` |
|
|
190
278
|
| `reusable-pr-title.yaml` | Re-checks the PR title when it is edited, with the `@ryusenkei/prose-lint` version from `package.json` and no install |
|
|
279
|
+
| `reusable-go.yaml` | `go vet` and `go test` on each OS in `os` (Ubuntu, macOS, Windows by default), then `go build` for each `GOOS/GOARCH` in `targets` on Ubuntu. The Go version comes from `go.mod` |
|
|
280
|
+
| `reusable-go-release.yaml` | For a `v*` tag: `go test`, the `checks` input, then GoReleaser with the caller's `.goreleaser.yaml`. The caller grants `contents: write` |
|
|
191
281
|
|
|
192
282
|
- `terraform`: space-separated directories to check with `terraform fmt -check` and `validate` (no backend, so no credentials). Terraform comes from the caller's `mise.toml`.
|
|
193
|
-
-
|
|
283
|
+
- Go uses `reusable-go.yaml` as a second job next to `ci`; on a private repository, set `os: '["ubuntu-latest"]'`, since macOS and Windows minutes count several times. Rust jobs stay in the calling workflow.
|
|
284
|
+
- npm license checks: add `pnpm exec ryusenkei-licenses` from `@ryusenkei/scripts` to `checks` (see its README).
|
|
194
285
|
- PR title edits run in their own workflow. In the same workflow, the later `edited` run would overwrite the `ci` job's result with "skipped" and hide a failure.
|
|
195
286
|
- `@main` follows toolkit's `main`, so fixes reach every repository at once. A breaking change gets a new file name instead of changing these.
|
|
196
287
|
|
|
@@ -199,3 +290,5 @@ jobs:
|
|
|
199
290
|
- major: a rule is removed or reversed, or a synced file changes incompatibly
|
|
200
291
|
- minor: a rule, a hook check, or a synced file is added
|
|
201
292
|
- patch: fixes and wording
|
|
293
|
+
|
|
294
|
+
See the [CHANGELOG](CHANGELOG.md) for what each version changed.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type CheckStep = {
|
|
2
|
+
name: string;
|
|
3
|
+
command: string;
|
|
4
|
+
args: string[];
|
|
5
|
+
};
|
|
6
|
+
export type CheckContext = {
|
|
7
|
+
base: string | undefined;
|
|
8
|
+
changed: string[];
|
|
9
|
+
full: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type CheckResult = {
|
|
12
|
+
name: string;
|
|
13
|
+
ok: boolean;
|
|
14
|
+
output: string;
|
|
15
|
+
};
|
|
16
|
+
export type AffectedCheckOptions = {
|
|
17
|
+
/** GLOBAL_FILES に足す、変更されたらすべてを検査するファイル */
|
|
18
|
+
globalFiles?: (string | RegExp)[];
|
|
19
|
+
/** 型検査・テストと並列に実行する軽い検査(数秒で終わる、全体にかかるもの) */
|
|
20
|
+
steps?: (ctx: CheckContext) => CheckStep[];
|
|
21
|
+
/** vitest に足す引数(reporter など) */
|
|
22
|
+
testArgs?: string[];
|
|
23
|
+
/** 型検査で同時に動かすパッケージの数(`pnpm -r --workspace-concurrency`) */
|
|
24
|
+
concurrency?: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* リポのルートで push の前の検査を実行し、結果を返す(終了コードは呼ぶ側が設定)
|
|
28
|
+
* - 引数: `--all` ですべて、`--base <ref>` で基準を指定(省略時は origin/main と origin/dev/* のうち最も近いもの)
|
|
29
|
+
* - 成功し、作業ツリーに変更がなければ HEAD の検査の記録を書く(check-record.ts)
|
|
30
|
+
*/
|
|
31
|
+
export declare function runAffectedCheck(options?: AffectedCheckOptions, argv?: string[]): Promise<CheckResult[]>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// push の前の検査の実行(各リポの scripts/check.ts から呼ぶ、範囲の決定は affected.ts)
|
|
2
|
+
// - pnpm check: 基準(PR の向き先との分岐点)からの変更(コミット済み・作業中・未追跡)に絞って型検査とテスト
|
|
3
|
+
// - pnpm check --all: すべて(デプロイの前)
|
|
4
|
+
// - 重い検査(型検査・テスト)は順に、軽い検査はそれと並列に実行(push の前のメモリのピークを1つの重い検査に抑えるため)
|
|
5
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
6
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
7
|
+
import { GLOBAL_FILES, nearestBase, scopeOf } from "./affected.js";
|
|
8
|
+
import { writeCheckRecord } from "./check-record.js";
|
|
9
|
+
import { workspaceDirs } from "./deps-check.js";
|
|
10
|
+
const git = (args) => {
|
|
11
|
+
const r = spawnSync('git', ['-c', 'core.quotepath=off', ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
12
|
+
return r.status === 0 ? r.stdout.trim() : null;
|
|
13
|
+
};
|
|
14
|
+
const lines = (text) => (text ?? '').split('\n').filter(Boolean);
|
|
15
|
+
const nameOf = (dir) => JSON.parse(readFileSync(`${dir}/package.json`, 'utf8')).name;
|
|
16
|
+
function candidates() {
|
|
17
|
+
const branch = git(['branch', '--show-current']);
|
|
18
|
+
const refs = ['origin/main', ...lines(git(['for-each-ref', '--format=%(refname:short)', 'refs/remotes/origin/dev/'])).filter((r) => r !== `origin/${branch}`)];
|
|
19
|
+
return refs.flatMap((ref) => {
|
|
20
|
+
const mergeBase = git(['merge-base', 'HEAD', ref]);
|
|
21
|
+
const ahead = mergeBase === null ? null : git(['rev-list', '--count', `${mergeBase}..HEAD`]);
|
|
22
|
+
return mergeBase === null || ahead === null ? [] : [{ ref, mergeBase, ahead: Number(ahead) }];
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function baseOf(argv) {
|
|
26
|
+
const i = argv.indexOf('--base');
|
|
27
|
+
if (i === -1)
|
|
28
|
+
return nearestBase(candidates());
|
|
29
|
+
const ref = argv[i + 1];
|
|
30
|
+
const mergeBase = git(['merge-base', 'HEAD', ref]);
|
|
31
|
+
return mergeBase === null ? undefined : { ref, mergeBase };
|
|
32
|
+
}
|
|
33
|
+
/** 検査の計画(表示する行と、重い検査・軽い検査) */
|
|
34
|
+
function planOf(options, argv) {
|
|
35
|
+
const { globalFiles = [], testArgs = [], concurrency = 2 } = options;
|
|
36
|
+
const all = argv.includes('--all');
|
|
37
|
+
const base = all ? undefined : baseOf(argv);
|
|
38
|
+
const changed = base === undefined ? [] : [...new Set([...lines(git(['diff', '--name-only', base.mergeBase])), ...lines(git(['ls-files', '--others', '--exclude-standard']))])];
|
|
39
|
+
const dirs = workspaceDirs();
|
|
40
|
+
const scriptsChanged = changed.some((f) => f.startsWith('scripts/'));
|
|
41
|
+
// ルートの scripts/ を相対パスで import するパッケージ(apps/api/scripts など)は、scripts/ の変更で型の検査の結果に影響
|
|
42
|
+
const importers = scriptsChanged && dirs.length > 0 ? lines(git(['grep', '-l', '-E', String.raw `from '(\.\./)+scripts/`, '--', ...dirs])) : [];
|
|
43
|
+
const scope = base === undefined ? { full: true, reason: all ? '--all' : 'no base (origin/main or origin/dev/*)' } : scopeOf(changed, dirs, importers, [...GLOBAL_FILES, ...globalFiles]);
|
|
44
|
+
const vitest = (args) => ({ name: 'test', command: 'pnpm', args: ['exec', 'vitest', 'run', '--passWithNoTests', ...args, ...testArgs] });
|
|
45
|
+
const ctx = { base: base?.mergeBase, changed, full: scope.full };
|
|
46
|
+
if (scope.full)
|
|
47
|
+
return { plan: [`all (${scope.reason})`], heavy: [{ name: 'typecheck', command: 'pnpm', args: ['typecheck'] }, vitest([])], ctx, covered: 'all' };
|
|
48
|
+
const sha = base.mergeBase.slice(0, 7);
|
|
49
|
+
const plan = [`base: ${base.ref} (merge base ${sha}), ${changed.length} changed files`];
|
|
50
|
+
const heavy = [];
|
|
51
|
+
const names = scope.dirs.map(nameOf).sort();
|
|
52
|
+
if (names.length > 0) {
|
|
53
|
+
plan.push(`typecheck: ${names.join(', ')} and dependents`);
|
|
54
|
+
heavy.push({ name: 'typecheck (packages)', command: 'pnpm', args: ['-r', '--if-present', `--workspace-concurrency=${concurrency}`, ...names.flatMap((n) => ['--filter', `...${n}`]), 'typecheck'] });
|
|
55
|
+
}
|
|
56
|
+
if (scope.root && existsSync('tsconfig.json')) {
|
|
57
|
+
plan.push('typecheck: root (tsc)');
|
|
58
|
+
heavy.push({ name: 'typecheck (root)', command: 'pnpm', args: ['exec', 'tsc'] });
|
|
59
|
+
}
|
|
60
|
+
if (heavy.length === 0)
|
|
61
|
+
plan.push('typecheck: none');
|
|
62
|
+
if (scope.tests) {
|
|
63
|
+
plan.push(`test: related to changes (vitest --changed ${sha})`);
|
|
64
|
+
heavy.push(vitest(['--changed', base.mergeBase]));
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
plan.push('test: none (Markdown only)');
|
|
68
|
+
return { plan, heavy, ctx, covered: base.ref };
|
|
69
|
+
}
|
|
70
|
+
const seconds = (from) => `${((Date.now() - from) / 1000).toFixed(1)}s`;
|
|
71
|
+
// pnpm は実行中の pnpm(npm_execpath)を node で起動(Windows の pnpm.cmd をシェルなしで起動できないため)
|
|
72
|
+
function capture(command, args) {
|
|
73
|
+
const pnpm = command === 'pnpm' ? process.env.npm_execpath : undefined;
|
|
74
|
+
const [file, argv] = pnpm ? [process.execPath, [pnpm, ...args]] : [command, args];
|
|
75
|
+
return new Promise((resolve) => {
|
|
76
|
+
const child = spawn(file, argv, { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
77
|
+
let output = '';
|
|
78
|
+
child.stdout.on('data', (chunk) => (output += chunk.toString()));
|
|
79
|
+
child.stderr.on('data', (chunk) => (output += chunk.toString()));
|
|
80
|
+
child.on('close', (status) => resolve({ status: status ?? 1, output }));
|
|
81
|
+
child.on('error', (error) => resolve({ status: 1, output: `${output}${error.message}\n` }));
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async function run(step) {
|
|
85
|
+
const from = Date.now();
|
|
86
|
+
const { status, output } = await capture(step.command, step.args);
|
|
87
|
+
console.log(`\n${status === 0 ? '[ok]' : '[failed]'} ${step.name} (${seconds(from)})`);
|
|
88
|
+
if (status !== 0)
|
|
89
|
+
console.log(output.trimEnd());
|
|
90
|
+
return { name: step.name, ok: status === 0, output };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* リポのルートで push の前の検査を実行し、結果を返す(終了コードは呼ぶ側が設定)
|
|
94
|
+
* - 引数: `--all` ですべて、`--base <ref>` で基準を指定(省略時は origin/main と origin/dev/* のうち最も近いもの)
|
|
95
|
+
* - 成功し、作業ツリーに変更がなければ HEAD の検査の記録を書く(check-record.ts)
|
|
96
|
+
*/
|
|
97
|
+
export async function runAffectedCheck(options = {}, argv = process.argv.slice(2)) {
|
|
98
|
+
const { plan, heavy, ctx, covered } = planOf(options, argv);
|
|
99
|
+
const light = options.steps?.(ctx) ?? [];
|
|
100
|
+
if (light.length > 0)
|
|
101
|
+
plan.push(`${light.map((s) => s.name).join(', ')}: all`);
|
|
102
|
+
console.log(['pnpm check', ...plan.map((p) => `- ${p}`)].join('\n'));
|
|
103
|
+
const started = Date.now();
|
|
104
|
+
const sequential = async () => {
|
|
105
|
+
const results = [];
|
|
106
|
+
for (const step of heavy)
|
|
107
|
+
results.push(await run(step));
|
|
108
|
+
return results;
|
|
109
|
+
};
|
|
110
|
+
const [heavyResults, lightResults] = await Promise.all([sequential(), Promise.all(light.map(run))]);
|
|
111
|
+
const results = [...heavyResults, ...lightResults];
|
|
112
|
+
const failed = results.filter((r) => !r.ok).length;
|
|
113
|
+
console.log(`\n${failed === 0 ? 'all passed' : `${failed} check(s) failed`} (${seconds(started)})`);
|
|
114
|
+
const commonDir = git(['rev-parse', '--path-format=absolute', '--git-common-dir']);
|
|
115
|
+
const head = git(['rev-parse', 'HEAD']);
|
|
116
|
+
if (failed === 0 && commonDir && head && git(['status', '--porcelain']) === '')
|
|
117
|
+
writeCheckRecord(commonDir, head, covered);
|
|
118
|
+
return results;
|
|
119
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** 変更されたらすべてを検査するルートのファイル(依存の解決・テスト・TypeScript の設定など、影響の範囲を辿れないもの) */
|
|
2
|
+
export declare const GLOBAL_FILES: (string | RegExp)[];
|
|
3
|
+
export type Candidate = {
|
|
4
|
+
ref: string;
|
|
5
|
+
mergeBase: string;
|
|
6
|
+
ahead: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* 基準: PR の向き先として最も近いもの(分岐点から HEAD までのコミットが最も少ない候補、同数なら先の候補)
|
|
10
|
+
* 候補は origin/main と epic の origin/dev/*。sub-issue のブランチは dev のブランチが、dev のブランチ自体は main が基準になる
|
|
11
|
+
*/
|
|
12
|
+
export declare function nearestBase(candidates: Candidate[]): Candidate | undefined;
|
|
13
|
+
export type Scope = {
|
|
14
|
+
full: true;
|
|
15
|
+
reason: string;
|
|
16
|
+
} | {
|
|
17
|
+
full: false;
|
|
18
|
+
dirs: string[];
|
|
19
|
+
root: boolean;
|
|
20
|
+
tests: boolean;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* 変更から検査の範囲を決定
|
|
24
|
+
* @param dirs ワークスペースのパッケージのディレクトリ
|
|
25
|
+
* @param importers ルートの scripts/ を import するファイル(scripts/ の変更で型の検査の結果が変わる)
|
|
26
|
+
* - pnpm-lock.yaml: package.json を変えたパッケージの依存の追加として扱い、どのパッケージの package.json も変わっていなければすべて
|
|
27
|
+
* - root: パッケージの外の .ts の変更(ルートの tsc の対象)
|
|
28
|
+
* - Markdown の変更は型検査・テストの対象にしない
|
|
29
|
+
*/
|
|
30
|
+
export declare function scopeOf(changed: string[], dirs: string[], importers: string[], globalFiles: (string | RegExp)[]): Scope;
|
|
31
|
+
/** ファイルを含むワークスペースのパッケージ(最も深いディレクトリ、どれにも含まれなければ undefined) */
|
|
32
|
+
export declare function packageDirOf(dirs: string[], file: string): string | undefined;
|
package/dist/affected.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// push の前の検査の範囲の決定(純粋な関数、実行は affected-check.ts)
|
|
2
|
+
/** 変更されたらすべてを検査するルートのファイル(依存の解決・テスト・TypeScript の設定など、影響の範囲を辿れないもの) */
|
|
3
|
+
export const GLOBAL_FILES = ['package.json', 'pnpm-workspace.yaml', 'mise.toml', '.npmrc', /^vitest\.config\.[cm]?[jt]s$/, /^tsconfig(\.[\w-]+)?\.json$/];
|
|
4
|
+
/**
|
|
5
|
+
* 基準: PR の向き先として最も近いもの(分岐点から HEAD までのコミットが最も少ない候補、同数なら先の候補)
|
|
6
|
+
* 候補は origin/main と epic の origin/dev/*。sub-issue のブランチは dev のブランチが、dev のブランチ自体は main が基準になる
|
|
7
|
+
*/
|
|
8
|
+
export function nearestBase(candidates) {
|
|
9
|
+
return candidates.reduce((best, c) => (best === undefined || c.ahead < best.ahead ? c : best), undefined);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 変更から検査の範囲を決定
|
|
13
|
+
* @param dirs ワークスペースのパッケージのディレクトリ
|
|
14
|
+
* @param importers ルートの scripts/ を import するファイル(scripts/ の変更で型の検査の結果が変わる)
|
|
15
|
+
* - pnpm-lock.yaml: package.json を変えたパッケージの依存の追加として扱い、どのパッケージの package.json も変わっていなければすべて
|
|
16
|
+
* - root: パッケージの外の .ts の変更(ルートの tsc の対象)
|
|
17
|
+
* - Markdown の変更は型検査・テストの対象にしない
|
|
18
|
+
*/
|
|
19
|
+
export function scopeOf(changed, dirs, importers, globalFiles) {
|
|
20
|
+
const hit = changed.find((f) => globalFiles.some((g) => (typeof g === 'string' ? f === g : g.test(f))));
|
|
21
|
+
if (hit !== undefined)
|
|
22
|
+
return { full: true, reason: `${hit} changed` };
|
|
23
|
+
const manifests = changed.filter((f) => dirs.some((d) => f === `${d}/package.json`));
|
|
24
|
+
if (changed.includes('pnpm-lock.yaml') && manifests.length === 0)
|
|
25
|
+
return { full: true, reason: 'pnpm-lock.yaml changed without a package.json' };
|
|
26
|
+
const code = changed.filter((f) => !f.endsWith('.md'));
|
|
27
|
+
const affected = [...code, ...importers].map((f) => packageDirOf(dirs, f)).filter((d) => d !== undefined);
|
|
28
|
+
return {
|
|
29
|
+
full: false,
|
|
30
|
+
dirs: [...new Set(affected)].sort(),
|
|
31
|
+
root: code.some((f) => packageDirOf(dirs, f) === undefined && /\.[cm]?tsx?$/.test(f)),
|
|
32
|
+
tests: code.length > 0,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** ファイルを含むワークスペースのパッケージ(最も深いディレクトリ、どれにも含まれなければ undefined) */
|
|
36
|
+
export function packageDirOf(dirs, file) {
|
|
37
|
+
return dirs.filter((dir) => file.startsWith(`${dir}/`)).sort((a, b) => b.length - a.length)[0];
|
|
38
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function writeCheckRecord(commonDir: string, sha: string, covered: string): void;
|
|
2
|
+
export declare function readCheckRecord(commonDir: string, sha: string): string | undefined;
|
|
3
|
+
/** PR の base に向けた検査として足りるか(`origin/<base>` を基準にした検査か、すべての検査) */
|
|
4
|
+
export declare const coversBase: (covered: string | undefined, base: string) => boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// 手元の検査の記録(CI が走らない・止まったときに、gh pr merge の関門を手元の検査で通すため)
|
|
2
|
+
// - pnpm check が成功し、作業ツリーに変更がないときに HEAD のコミットごとに書く。中身は検査した範囲(基準の ref、すべてなら `all`)
|
|
3
|
+
// - 置き場は git の共通のディレクトリ(worktree をまたいで1つ、追跡しない)
|
|
4
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
const dirOf = (commonDir) => join(commonDir, 'ryusenkei-check');
|
|
7
|
+
export function writeCheckRecord(commonDir, sha, covered) {
|
|
8
|
+
mkdirSync(dirOf(commonDir), { recursive: true });
|
|
9
|
+
writeFileSync(join(dirOf(commonDir), sha), `${covered}\n`);
|
|
10
|
+
}
|
|
11
|
+
export function readCheckRecord(commonDir, sha) {
|
|
12
|
+
try {
|
|
13
|
+
return readFileSync(join(dirOf(commonDir), sha), 'utf8').trim();
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** PR の base に向けた検査として足りるか(`origin/<base>` を基準にした検査か、すべての検査) */
|
|
20
|
+
export const coversBase = (covered, base) => covered === 'all' || covered === `origin/${base}`;
|
package/dist/cli.js
CHANGED
|
@@ -3,10 +3,24 @@
|
|
|
3
3
|
// ryusenkei-conventions check マスタとの差分の検査(差分あり → 終了コード1)
|
|
4
4
|
// ryusenkei-conventions sync [--stop] マスタに合わせて書き込み
|
|
5
5
|
// --stop: 完了前の `pnpm lint`・`pnpm test` を Stop の hook に登録(省略時は現在の登録を維持)
|
|
6
|
+
// - 終了の状態: 差分なしは0、差分ありは1、使い方の誤りは2(`--help` は0)
|
|
6
7
|
import { execFileSync } from 'node:child_process';
|
|
7
8
|
import { parseArgs } from 'node:util';
|
|
8
9
|
import { drifts, sync } from "./files.js";
|
|
9
|
-
const
|
|
10
|
+
const USAGE = 'usage: ryusenkei-conventions <check|sync> [--stop]';
|
|
11
|
+
let parsed;
|
|
12
|
+
try {
|
|
13
|
+
parsed = parseArgs({ allowPositionals: true, options: { stop: { type: 'boolean' }, help: { type: 'boolean', short: 'h' } } });
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
console.error(`${e instanceof Error ? e.message : String(e)}\n${USAGE}`);
|
|
17
|
+
process.exit(2);
|
|
18
|
+
}
|
|
19
|
+
const { values, positionals } = parsed;
|
|
20
|
+
if (values.help) {
|
|
21
|
+
console.log(USAGE);
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
10
24
|
const root = execFileSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8' }).trim();
|
|
11
25
|
const options = values.stop === undefined ? {} : { stop: values.stop };
|
|
12
26
|
switch (positionals[0]) {
|
|
@@ -27,6 +41,6 @@ switch (positionals[0]) {
|
|
|
27
41
|
break;
|
|
28
42
|
}
|
|
29
43
|
default:
|
|
30
|
-
console.error(
|
|
44
|
+
console.error(USAGE);
|
|
31
45
|
process.exitCode = 2;
|
|
32
46
|
}
|
package/dist/files.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import { dirname, join } from 'node:path';
|
|
8
8
|
import { hasStop, managedSettings } from "./settings.js";
|
|
9
|
+
import { testExcludeProblem } from "./test-exclude.js";
|
|
9
10
|
const FILES = [
|
|
10
11
|
{ from: 'editorconfig', to: '.editorconfig' },
|
|
11
12
|
{ from: 'gitattributes', to: '.gitattributes' },
|
|
@@ -86,13 +87,17 @@ export function drifts(root, options = {}) {
|
|
|
86
87
|
out.push({ path: WORKSPACE, expected: `${workspace.trimEnd()}\n\n${RELEASE_AGE.join('\n')}\n`, message: '`minimumReleaseAge` が未設定' });
|
|
87
88
|
}
|
|
88
89
|
// pre-push の関門は `pnpm check`(`check` がないと何も検査されずに push される)
|
|
89
|
-
let
|
|
90
|
+
let manifest = {};
|
|
90
91
|
try {
|
|
91
|
-
|
|
92
|
+
manifest = JSON.parse(read(join(root, 'package.json')) ?? '{}');
|
|
92
93
|
}
|
|
93
94
|
catch { }
|
|
94
|
-
if (typeof scripts
|
|
95
|
+
if (typeof manifest.scripts?.check !== 'string')
|
|
95
96
|
out.push({ path: 'package.json', message: '`check` の script を追加(pre-push で動かす検査。型検査、テスト、lint など)' });
|
|
97
|
+
// Vitest の除外(作業用の worktree と、Terraform が取得したモジュールのテストを集めない)
|
|
98
|
+
const excludeProblem = testExcludeProblem(Object.keys({ ...manifest.dependencies, ...manifest.devDependencies }), (file) => read(join(root, file)));
|
|
99
|
+
if (excludeProblem)
|
|
100
|
+
out.push(excludeProblem);
|
|
96
101
|
const claude = read(join(root, 'CLAUDE.md')) ?? '';
|
|
97
102
|
const lines = claude.split('\n');
|
|
98
103
|
const at = lines.findIndex((l) => l.trim() === IMPORT);
|
package/dist/hook.js
CHANGED
|
@@ -8,13 +8,14 @@ import { mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'n
|
|
|
8
8
|
import { homedir, tmpdir } from 'node:os';
|
|
9
9
|
import { isAbsolute, join, resolve } from 'node:path';
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { readCheckRecord } from "./check-record.js";
|
|
11
12
|
import { denyReason } from "./policy.js";
|
|
12
13
|
const input = JSON.parse(readFileSync(0, 'utf8'));
|
|
13
14
|
const root = process.env.CLAUDE_PROJECT_DIR ?? input.cwd ?? process.cwd();
|
|
14
15
|
// Windows の `pnpm` は `.cmd` → シェル経由でのみ起動可能
|
|
15
16
|
const shell = process.platform === 'win32';
|
|
16
17
|
if (input.hook_event_name === 'PreToolUse') {
|
|
17
|
-
const reason = denyReason(input, { root, repoRoot, resolveDir, titleIssues, readFile, currentBranch, prHead, prBase, hasPrWorkflow, prChecks });
|
|
18
|
+
const reason = denyReason(input, { root, repoRoot, resolveDir, titleIssues, readFile, currentBranch, prHead, prBase, hasPrWorkflow, prChecks, localCheck });
|
|
18
19
|
if (reason) {
|
|
19
20
|
process.stderr.write(`${reason}\n`);
|
|
20
21
|
process.exit(2);
|
|
@@ -70,6 +71,11 @@ function prBase(pr, cwd) {
|
|
|
70
71
|
const r = spawnSync('gh', ['pr', 'view', ...(pr ? [pr] : []), '--json', 'baseRefName', '--jq', '.baseRefName'], { cwd: cwd ?? root, encoding: 'utf8' });
|
|
71
72
|
return (r.status === 0 && r.stdout.trim()) || undefined;
|
|
72
73
|
}
|
|
74
|
+
function localCheck(pr, cwd) {
|
|
75
|
+
const sha = spawnSync('gh', ['pr', 'view', ...(pr ? [pr] : []), '--json', 'headRefOid', '--jq', '.headRefOid'], { cwd: cwd ?? root, encoding: 'utf8' }).stdout?.trim();
|
|
76
|
+
const commonDir = spawnSync('git', ['rev-parse', '--path-format=absolute', '--git-common-dir'], { cwd: cwd ?? root, encoding: 'utf8' }).stdout?.trim();
|
|
77
|
+
return sha && commonDir ? readCheckRecord(commonDir, sha) : undefined;
|
|
78
|
+
}
|
|
73
79
|
// GitHub で無効にしたワークフローはチェックを出さない → 有効なものだけを数える
|
|
74
80
|
// 読めなければ「ある」とみなす(チェックなしのマージを許可しない側に倒す)
|
|
75
81
|
function hasPrWorkflow(cwd) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { drifts, sync, IMPORT, type Drift } from './files.ts';
|
|
2
2
|
export { runDepsCheck } from './deps-check.ts';
|
|
3
3
|
export type { Exception, Rule } from './deps.ts';
|
|
4
|
+
export { TEST_EXCLUDE } from './test-exclude.ts';
|
|
5
|
+
export { runAffectedCheck, type AffectedCheckOptions, type CheckContext, type CheckResult, type CheckStep } from './affected-check.ts';
|
package/dist/index.js
CHANGED
package/dist/policy.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export type Context = {
|
|
|
28
28
|
hasPrWorkflow: (cwd: string | undefined) => boolean;
|
|
29
29
|
/** PR のチェックの集計(`pr` の省略時は現在のブランチの PR) */
|
|
30
30
|
prChecks: (pr: string | undefined, cwd: string | undefined) => Checks;
|
|
31
|
+
/** PR の head のコミットで手元の `pnpm check` が通った範囲(check-record.ts、記録がなければ `undefined`) */
|
|
32
|
+
localCheck: (pr: string | undefined, cwd: string | undefined) => string | undefined;
|
|
31
33
|
};
|
|
32
34
|
/** 拒否の理由(許可する場合は `undefined`) */
|
|
33
35
|
export declare function denyReason(use: ToolUse, ctx: Context): string | undefined;
|
package/dist/policy.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// - 拒否の理由は Claude に返却 → Claude が修正して再実行
|
|
4
4
|
// - 対象のリポ・ブランチはコマンドから解決: `cd`・`git -C` の後はその git のルート、ブランチの切り替えの後はその先のブランチ
|
|
5
5
|
import { isAbsolute, join } from 'node:path';
|
|
6
|
+
import { coversBase } from "./check-record.js";
|
|
6
7
|
import { commands, option } from "./shell.js";
|
|
7
8
|
const TYPES = ['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test'];
|
|
8
9
|
const BRANCH = new RegExp(`^(${TYPES.join('|')})/[a-z0-9][a-z0-9._-]*$`);
|
|
@@ -236,6 +237,7 @@ function prReasons(sub, args, st, ctx) {
|
|
|
236
237
|
// `--auto` も対象(必須のチェックがないリポでは即時にマージされる)
|
|
237
238
|
// - マージは常に squash(org のリポの設定が squash だけを許可。epic のフローの dev/* から main へも同じ)
|
|
238
239
|
// - epic のフローの dev/* への PR: チェックなしを許可(CI を実行せず pre-push の `pnpm check` が関門)
|
|
240
|
+
// - CI が通っていなくても、PR の head で base に向けた手元の `pnpm check` が通っていれば許可(無料枠の超過などで CI が走らないときに詰まらないため)
|
|
239
241
|
function mergeReasons(args, st, ctx) {
|
|
240
242
|
const { cwd } = st;
|
|
241
243
|
if (args.some((a) => a === '--rebase' || a === '-r'))
|
|
@@ -249,12 +251,12 @@ function mergeReasons(args, st, ctx) {
|
|
|
249
251
|
// PR で動く有効なワークフローがないリポ: CI の代わりに pre-push の `pnpm check` が関門
|
|
250
252
|
if (checks === 'none' && !ctx.hasPrWorkflow(cwd))
|
|
251
253
|
return [];
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return [CHECKS_REASON[checks]];
|
|
254
|
+
const base = ctx.prBase(pr, cwd);
|
|
255
|
+
if (checks === 'none' && epicFlow(st, ctx) && base !== undefined && DEV_BRANCH.test(base))
|
|
256
|
+
return [];
|
|
257
|
+
if (base !== undefined && coversBase(ctx.localCheck(pr, cwd), base))
|
|
258
|
+
return [];
|
|
259
|
+
return [`${CHECKS_REASON[checks]}。CI が走らない・止まったときは、PR の head のコミットで手元の \`pnpm check --base origin/${base ?? 'main'}\` を通すとマージできる`];
|
|
258
260
|
}
|
|
259
261
|
// epic のフロー: main への PR は dev/* から、それ以外のブランチの PR は dev/* へ
|
|
260
262
|
// - `gh pr create` の base の省略 = main(既定のブランチ)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Vitest の既定の `exclude` に足すパターン */
|
|
2
|
+
export declare const TEST_EXCLUDE: readonly [".claude/**", "**/.terraform/**"];
|
|
3
|
+
/**
|
|
4
|
+
* ルートの Vitest の設定が除外を含むかの検査。問題がなければ `undefined`、あれば対処の文
|
|
5
|
+
* - `vitest` に依存しないリポは対象の外
|
|
6
|
+
* - 設定が `TEST_EXCLUDE` を使うか、すべてのパターンを書いていれば通す
|
|
7
|
+
*/
|
|
8
|
+
export declare function testExcludeProblem(dependencies: readonly string[], read: (file: string) => string | undefined): {
|
|
9
|
+
path: string;
|
|
10
|
+
message: string;
|
|
11
|
+
} | undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Vitest の既定に足す除外(各リポの vitest.config で `[...configDefaults.exclude, ...TEST_EXCLUDE]` にする)
|
|
2
|
+
// - `.claude/**`: リポの中の作業用の worktree(同じテストを重複して集める)
|
|
3
|
+
// - `**/.terraform/**`: Terraform の作業のディレクトリ。git の Terraform のモジュールの取得で、toolkit などのリポ全体(テストを含む)が置かれる
|
|
4
|
+
/** Vitest の既定の `exclude` に足すパターン */
|
|
5
|
+
export const TEST_EXCLUDE = ['.claude/**', '**/.terraform/**'];
|
|
6
|
+
const CONFIG_FILES = ['vitest.config.ts', 'vitest.config.mts', 'vitest.config.js', 'vitest.config.mjs'];
|
|
7
|
+
/**
|
|
8
|
+
* ルートの Vitest の設定が除外を含むかの検査。問題がなければ `undefined`、あれば対処の文
|
|
9
|
+
* - `vitest` に依存しないリポは対象の外
|
|
10
|
+
* - 設定が `TEST_EXCLUDE` を使うか、すべてのパターンを書いていれば通す
|
|
11
|
+
*/
|
|
12
|
+
export function testExcludeProblem(dependencies, read) {
|
|
13
|
+
if (!dependencies.includes('vitest'))
|
|
14
|
+
return undefined;
|
|
15
|
+
const found = CONFIG_FILES.map((file) => ({ file, text: read(file) })).find((c) => c.text !== undefined);
|
|
16
|
+
const usage = '`import { TEST_EXCLUDE } from \'@ryusenkei/conventions\'` を読み、`test.exclude` を `[...configDefaults.exclude, ...TEST_EXCLUDE]` にする';
|
|
17
|
+
if (!found)
|
|
18
|
+
return { path: 'vitest.config.ts', message: `Vitest の設定がない → ${usage}` };
|
|
19
|
+
if (found.text.includes('TEST_EXCLUDE') || TEST_EXCLUDE.every((p) => found.text.includes(p)))
|
|
20
|
+
return undefined;
|
|
21
|
+
return { path: found.file, message: `テストの除外(${TEST_EXCLUDE.map((p) => `\`${p}\``).join('・')})がない → ${usage}` };
|
|
22
|
+
}
|
package/files/gitignore
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryusenkei/conventions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "RYUSENKEI のモノリポの共通の規約(Claude Code の規約・hook、共通ファイルの同期)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "RYUSENKEI",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"dist",
|
|
26
26
|
"files",
|
|
27
|
-
"rules*.md"
|
|
27
|
+
"rules*.md",
|
|
28
|
+
"CHANGELOG.md"
|
|
28
29
|
],
|
|
29
30
|
"engines": {
|
|
30
31
|
"node": ">=24"
|
package/rules-ts.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
- エントリポイントはパッケージごとの `src/index.ts`
|
|
4
4
|
- TypeScript はビルドせず、Node で直接実行する(`node scripts/x.ts`)
|
|
5
|
-
- テストは Vitest で書き、対象と同じディレクトリに `*.test.ts`
|
|
6
|
-
- 子プロセスは `@ryusenkei/scripts` の `
|
|
5
|
+
- テストは Vitest で書き、対象と同じディレクトリに `*.test.ts` を置く。ルートの vitest.config の `test.exclude` は `[...configDefaults.exclude, ...TEST_EXCLUDE]`(`@ryusenkei/conventions`)
|
|
6
|
+
- 子プロセスは `@ryusenkei/scripts` の `execSync` などで起動する。Windows の `.cmd` に対応するため
|
|
7
7
|
- 層の依存の向きは `scripts/lib/deps-rules.ts` に規則を書き、`@ryusenkei/conventions` の `runDepsCheck` で検査する(`pnpm lint` に含める)
|
|
8
8
|
|
|
9
9
|
## 定数
|
package/rules.md
CHANGED
|
@@ -57,9 +57,12 @@
|
|
|
57
57
|
|
|
58
58
|
- add は変更・追加したファイルをパスで指定する。一括の add はフックで止まる
|
|
59
59
|
- push の前に `pnpm check` を通す。pre-push で強制される(`check` の script はどのリポにも置く)
|
|
60
|
+
- `pnpm check` は PR の向き先(`origin/main` か epic の `origin/dev/*`)からの変更の影響の範囲だけを検査する。全体の検査の `pnpm check --all` はデプロイの前に手元で回す
|
|
60
61
|
- PR の本文は背景、変更、検証の順に書く
|
|
61
62
|
- 前の PR のブランチから PR を重ねた場合は、親のマージの後にスキル `stacked-pr` の手順で整理する
|
|
62
63
|
- マージは squash で、CI の全チェックの成功を確かめてから行う(フックで強制)
|
|
64
|
+
- `main` 行きの PR は draft で作り、マージの前に ready にする。CI は ready の PR だけで回る(GitHub Actions の無料枠の節約)
|
|
65
|
+
- CI が走らない・止まったとき(無料枠の超過など)は、PR の head のコミットで手元の `pnpm check --base origin/<base>` を通せばマージできる
|
|
63
66
|
- epic のフロー(有効にしたリポだけ)
|
|
64
67
|
- epic ごとに `dev/<issue の番号>-<内容>` を作り、sub-issue の PR は dev のブランチに向ける
|
|
65
68
|
- dev のブランチへのマージに CI は使わず、pre-push の `pnpm check` を関門にする。チェックがある場合は成功が必要
|