@ryusenkei/conventions 0.8.2 → 0.9.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 +13 -0
- package/README.md +57 -2
- package/dist/cli.js +16 -2
- package/dist/files.js +8 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- 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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
- `TEST_EXCLUDE` (`.claude/**`, `**/.terraform/**`): patterns to add to Vitest's default `exclude`.
|
|
6
|
+
- `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`.
|
|
7
|
+
- The shared `.gitignore` ignores `.terraform/`. Run `ryusenkei-conventions sync`.
|
|
8
|
+
- `rules-ts.md` names `execSync` from `@ryusenkei/scripts` 0.4 (`exec` was renamed) and the Vitest exclude.
|
|
9
|
+
- The CLI exits with 2 for an unknown option (it crashed with 1) and takes `--help`.
|
|
10
|
+
|
|
11
|
+
## 0.8.2 and earlier
|
|
12
|
+
|
|
13
|
+
See the git history of `packages/conventions`.
|
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ 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` |
|
|
12
13
|
|
|
13
14
|
## Install
|
|
14
15
|
|
|
@@ -37,6 +38,7 @@ Requires Node.js 24 or later.
|
|
|
37
38
|
|
|
38
39
|
2. Write the shared files: `npx ryusenkei-conventions sync` (add `--stop` to run lint and tests before Claude finishes).
|
|
39
40
|
3. Add `ryusenkei-conventions check` to the `lint` script.
|
|
41
|
+
4. With Vitest, exclude `TEST_EXCLUDE` in the root `vitest.config.ts` (see [Vitest](#vitest)).
|
|
40
42
|
|
|
41
43
|
- Claude Code expands the import when a session starts. Run `pnpm install` first, or the rules are not loaded.
|
|
42
44
|
- The import resolves inside the working directory, so Claude Code does not ask for approval of external imports.
|
|
@@ -106,10 +108,35 @@ Opt in per repository in the root `package.json`:
|
|
|
106
108
|
|
|
107
109
|
When the `rules.md` import is present, `sync` adds the missing ones right after it.
|
|
108
110
|
|
|
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 (for example `pnpm typecheck && pnpm test && pnpm lint:prose && ryusenkei-conventions check`).
|
|
111
|
+
`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 (for example `pnpm typecheck && pnpm test && pnpm lint:prose && ryusenkei-conventions check`).
|
|
110
112
|
|
|
111
113
|
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
114
|
|
|
115
|
+
## Vitest
|
|
116
|
+
|
|
117
|
+
`TEST_EXCLUDE` is what every repository adds to Vitest's default `exclude`:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
// vitest.config.ts
|
|
121
|
+
import { TEST_EXCLUDE } from '@ryusenkei/conventions';
|
|
122
|
+
import { configDefaults, defineConfig } from 'vitest/config';
|
|
123
|
+
|
|
124
|
+
export default defineConfig({
|
|
125
|
+
test: {
|
|
126
|
+
exclude: [...configDefaults.exclude, ...TEST_EXCLUDE],
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
| Pattern | Why |
|
|
132
|
+
| --- | --- |
|
|
133
|
+
| `.claude/**` | Agents' worktrees inside the repository would run the same tests twice |
|
|
134
|
+
| `**/.terraform/**` | `terraform init` downloads a Git module source as the whole repository (toolkit's tests included) into `.terraform/modules/` |
|
|
135
|
+
|
|
136
|
+
`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).
|
|
137
|
+
|
|
138
|
+
`ryusenkei-conventions` exits with 0 when nothing drifts, 1 when something does, and 2 for a usage error; `--help` exits with 0.
|
|
139
|
+
|
|
113
140
|
## Dependency direction
|
|
114
141
|
|
|
115
142
|
`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:
|
|
@@ -167,6 +194,29 @@ jobs:
|
|
|
167
194
|
pnpm lint:deps
|
|
168
195
|
```
|
|
169
196
|
|
|
197
|
+
Go, with releases on `v*` tags:
|
|
198
|
+
|
|
199
|
+
```yaml
|
|
200
|
+
# in .github/workflows/ci.yaml, next to the ci job
|
|
201
|
+
go:
|
|
202
|
+
uses: ryusenkei-inc/toolkit/.github/workflows/reusable-go.yaml@main
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
```yaml
|
|
206
|
+
# .github/workflows/release.yaml
|
|
207
|
+
name: Release
|
|
208
|
+
on:
|
|
209
|
+
push:
|
|
210
|
+
tags: ['v*']
|
|
211
|
+
permissions:
|
|
212
|
+
contents: write
|
|
213
|
+
jobs:
|
|
214
|
+
release:
|
|
215
|
+
uses: ryusenkei-inc/toolkit/.github/workflows/reusable-go-release.yaml@main
|
|
216
|
+
with:
|
|
217
|
+
checks: test "v$(node -p "require('./package.json').version")" = "$GITHUB_REF_NAME"
|
|
218
|
+
```
|
|
219
|
+
|
|
170
220
|
```yaml
|
|
171
221
|
# .github/workflows/pr-title.yaml
|
|
172
222
|
name: PR title
|
|
@@ -188,9 +238,12 @@ jobs:
|
|
|
188
238
|
| --- | --- |
|
|
189
239
|
| `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
240
|
| `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 |
|
|
241
|
+
| `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` |
|
|
242
|
+
| `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
243
|
|
|
192
244
|
- `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
|
-
-
|
|
245
|
+
- 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.
|
|
246
|
+
- npm license checks: add `pnpm exec ryusenkei-licenses` from `@ryusenkei/scripts` to `checks` (see its README).
|
|
194
247
|
- 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
248
|
- `@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
249
|
|
|
@@ -199,3 +252,5 @@ jobs:
|
|
|
199
252
|
- major: a rule is removed or reversed, or a synced file changes incompatibly
|
|
200
253
|
- minor: a rule, a hook check, or a synced file is added
|
|
201
254
|
- patch: fixes and wording
|
|
255
|
+
|
|
256
|
+
See the [CHANGELOG](CHANGELOG.md) for what each version changed.
|
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/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -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.9.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
|
## 定数
|