@aramassa/ai-rules 0.4.0 → 0.4.3
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/artifact/instructions/rules/workspace-management/nodejs.md +358 -0
- package/artifact/instructions/{python/workspace-management.md → rules/workspace-management/python.md} +12 -12
- package/artifact/instructions/rules/workspace-management/typescript.md +337 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +270 -202
- package/package.json +1 -1
- package/presets/monorepo/nodejs.yaml +14 -0
- package/presets/monorepo/typescript.yaml +25 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: package-management
|
|
3
|
+
category: workspace
|
|
4
|
+
language: typescript
|
|
5
|
+
applyTo: "**/tsconfig.json"
|
|
6
|
+
human-instruction: |-
|
|
7
|
+
## TypeScript Project References の特性
|
|
8
|
+
|
|
9
|
+
TypeScript のプロジェクト参照(Project References)は、複数のパッケージ間での型情報共有とビルド最適化を実現する仕組みです。
|
|
10
|
+
|
|
11
|
+
特に注意すべき点:
|
|
12
|
+
- `references` フィールドでパッケージ間の依存関係を明示する
|
|
13
|
+
- `composite: true` を設定することで、プロジェクト参照が有効になる
|
|
14
|
+
- `tsc --build` コマンドで依存関係を考慮した段階的ビルドが可能
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# TypeScript Workspace Management Rules
|
|
18
|
+
|
|
19
|
+
## 目次
|
|
20
|
+
|
|
21
|
+
- [Overview](#overview)
|
|
22
|
+
- [TypeScript Configuration](#typescript-configuration)
|
|
23
|
+
- [Project References](#project-references)
|
|
24
|
+
- [Build Strategy](#build-strategy)
|
|
25
|
+
- [Type Definition Management](#type-definition-management)
|
|
26
|
+
- [Common Issues](#common-issues)
|
|
27
|
+
- [Best Practices](#best-practices)
|
|
28
|
+
|
|
29
|
+
## Overview
|
|
30
|
+
|
|
31
|
+
このドキュメントは **TypeScript Project References** に特化したルールです。
|
|
32
|
+
|
|
33
|
+
基本的なワークスペース管理については [nodejs.md](./nodejs.md) を参照してください。
|
|
34
|
+
|
|
35
|
+
## TypeScript Configuration
|
|
36
|
+
|
|
37
|
+
### Root tsconfig.json
|
|
38
|
+
|
|
39
|
+
ルートの `tsconfig.json` は共通設定を定義します:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"compilerOptions": {
|
|
44
|
+
"target": "ES2020",
|
|
45
|
+
"module": "commonjs",
|
|
46
|
+
"lib": ["ES2020"],
|
|
47
|
+
"declaration": true,
|
|
48
|
+
"declarationMap": true,
|
|
49
|
+
"sourceMap": true,
|
|
50
|
+
"outDir": "./dist",
|
|
51
|
+
"rootDir": "./src",
|
|
52
|
+
"composite": true,
|
|
53
|
+
"strict": true,
|
|
54
|
+
"esModuleInterop": true,
|
|
55
|
+
"skipLibCheck": true,
|
|
56
|
+
"forceConsistentCasingInFileNames": true
|
|
57
|
+
},
|
|
58
|
+
"exclude": ["node_modules", "dist"]
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Package-level tsconfig.json
|
|
63
|
+
|
|
64
|
+
各パッケージの `tsconfig.json`:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"extends": "../../tsconfig.json",
|
|
69
|
+
"compilerOptions": {
|
|
70
|
+
"outDir": "./dist",
|
|
71
|
+
"rootDir": "./src"
|
|
72
|
+
},
|
|
73
|
+
"references": [
|
|
74
|
+
{ "path": "../common" }
|
|
75
|
+
],
|
|
76
|
+
"include": ["src/**/*"],
|
|
77
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Project References
|
|
82
|
+
|
|
83
|
+
### 依存関係の定義
|
|
84
|
+
|
|
85
|
+
パッケージ間の依存関係は `references` フィールドで明示します:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
// packages/core/tsconfig.json
|
|
89
|
+
{
|
|
90
|
+
"references": [
|
|
91
|
+
{ "path": "../common" }
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
// packages/cli/tsconfig.json
|
|
98
|
+
{
|
|
99
|
+
"references": [
|
|
100
|
+
{ "path": "../common" },
|
|
101
|
+
{ "path": "../core" }
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### composite フラグ(必須)
|
|
107
|
+
|
|
108
|
+
プロジェクト参照を有効にするため、各パッケージで `composite: true` を設定:
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"compilerOptions": {
|
|
113
|
+
"composite": true,
|
|
114
|
+
"declaration": true
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**composite: true の効果**:
|
|
120
|
+
- `.d.ts` ファイル(型定義)の生成を強制
|
|
121
|
+
- `tsconfig.tsbuildinfo` ファイルによる段階的ビルドの有効化
|
|
122
|
+
- プロジェクト参照による高速な型チェック
|
|
123
|
+
|
|
124
|
+
## Build Strategy
|
|
125
|
+
|
|
126
|
+
### 推奨ビルドコマンド
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# TypeScript の段階的ビルド(推奨)
|
|
130
|
+
npx tsc --build
|
|
131
|
+
|
|
132
|
+
# watch モード(開発時)
|
|
133
|
+
npx tsc --build --watch
|
|
134
|
+
|
|
135
|
+
# クリーンビルド
|
|
136
|
+
npx tsc --build --clean
|
|
137
|
+
npx tsc --build
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### package.json の scripts
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"scripts": {
|
|
145
|
+
"build": "tsc --build",
|
|
146
|
+
"build:clean": "tsc --build --clean",
|
|
147
|
+
"build:watch": "tsc --build --watch"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Type Definition Management
|
|
153
|
+
|
|
154
|
+
### 型定義の export
|
|
155
|
+
|
|
156
|
+
各パッケージで型定義を適切に export します:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
// packages/common/src/index.ts
|
|
160
|
+
export type { CommonConfig } from './types';
|
|
161
|
+
export { createCommon } from './common';
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
// packages/common/package.json
|
|
166
|
+
{
|
|
167
|
+
"main": "./dist/index.js",
|
|
168
|
+
"types": "./dist/index.d.ts",
|
|
169
|
+
"files": ["dist"]
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### 型定義の import
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
// packages/core/src/index.ts
|
|
177
|
+
import type { CommonConfig } from '@scope/common';
|
|
178
|
+
import { createCommon } from '@scope/common';
|
|
179
|
+
|
|
180
|
+
export function createCore(config: CommonConfig) {
|
|
181
|
+
const common = createCommon(config);
|
|
182
|
+
// ...
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### 共有型定義パッケージ
|
|
187
|
+
|
|
188
|
+
プロジェクト全体で使用する型定義は `types` パッケージに集約:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
// packages/types/src/index.ts
|
|
192
|
+
export type ProjectConfig = {
|
|
193
|
+
name: string;
|
|
194
|
+
version: string;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export type Result<T, E = Error> =
|
|
198
|
+
| { success: true; data: T }
|
|
199
|
+
| { success: false; error: E };
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Common Issues
|
|
203
|
+
|
|
204
|
+
### 型定義が認識されない
|
|
205
|
+
|
|
206
|
+
**原因**: プロジェクト参照の設定漏れ
|
|
207
|
+
|
|
208
|
+
```json
|
|
209
|
+
// packages/core/tsconfig.json
|
|
210
|
+
{
|
|
211
|
+
"references": [{ "path": "../common" }],
|
|
212
|
+
"compilerOptions": {
|
|
213
|
+
"composite": true
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
npx tsc --build
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### ビルドエラー: "Project references may not form a circular chain"
|
|
223
|
+
|
|
224
|
+
**原因**: 循環参照(`core` → `cli` → `core`)
|
|
225
|
+
|
|
226
|
+
解決策: 依存関係を見直し、共通機能を `common` に移動
|
|
227
|
+
|
|
228
|
+
### import の型解決ができない
|
|
229
|
+
|
|
230
|
+
**原因**: `declaration: true` の設定漏れ
|
|
231
|
+
|
|
232
|
+
```json
|
|
233
|
+
{
|
|
234
|
+
"compilerOptions": {
|
|
235
|
+
"composite": true,
|
|
236
|
+
"declaration": true,
|
|
237
|
+
"declarationMap": true
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Best Practices
|
|
243
|
+
|
|
244
|
+
1. **composite フラグの徹底**: 全パッケージで `composite: true` を設定
|
|
245
|
+
2. **型定義の明示的 export**: 公開する型は必ず `export type` で export
|
|
246
|
+
3. **段階的ビルドの活用**: `tsc --build` でビルド時間を短縮
|
|
247
|
+
4. **declarationMap の活用**: デバッグ時にソースコードにジャンプ可能
|
|
248
|
+
5. **tsconfig の継承**: 共通設定はルートで定義して `extends` で継承
|
|
249
|
+
|
|
250
|
+
### tsconfig.json テンプレート
|
|
251
|
+
|
|
252
|
+
```json
|
|
253
|
+
{
|
|
254
|
+
"extends": "../../tsconfig.json",
|
|
255
|
+
"compilerOptions": {
|
|
256
|
+
"composite": true,
|
|
257
|
+
"declaration": true,
|
|
258
|
+
"declarationMap": true,
|
|
259
|
+
"outDir": "./dist",
|
|
260
|
+
"rootDir": "./src"
|
|
261
|
+
},
|
|
262
|
+
"references": [
|
|
263
|
+
// 依存するパッケージのパスを記載
|
|
264
|
+
],
|
|
265
|
+
"include": ["src/**/*"],
|
|
266
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Example Project Structure
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
my-monorepo/
|
|
274
|
+
├── tsconfig.json # ルート設定
|
|
275
|
+
├── packages/
|
|
276
|
+
│ ├── types/
|
|
277
|
+
│ │ ├── tsconfig.json # composite: true
|
|
278
|
+
│ │ └── src/index.ts
|
|
279
|
+
│ ├── common/
|
|
280
|
+
│ │ ├── tsconfig.json # references: [types]
|
|
281
|
+
│ │ └── src/index.ts
|
|
282
|
+
│ ├── core/
|
|
283
|
+
│ │ ├── tsconfig.json # references: [types, common]
|
|
284
|
+
│ │ └── src/index.ts
|
|
285
|
+
│ └── cli/
|
|
286
|
+
│ ├── tsconfig.json # references: [types, common, core]
|
|
287
|
+
│ └── src/index.ts
|
|
288
|
+
└── tsconfig.tsbuildinfo # ビルドキャッシュ(.gitignore)
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Related Documentation
|
|
292
|
+
|
|
293
|
+
- [Node.js Workspace Management](./nodejs.md) - npm workspaces の基本ルール
|
|
294
|
+
"compilerOptions": {
|
|
295
|
+
"composite": true,
|
|
296
|
+
"declaration": true,
|
|
297
|
+
"declarationMap": true,
|
|
298
|
+
"outDir": "./dist",
|
|
299
|
+
"rootDir": "./src"
|
|
300
|
+
},
|
|
301
|
+
"references": [
|
|
302
|
+
// 依存するパッケージを記載
|
|
303
|
+
],
|
|
304
|
+
"include": ["src/**/*"],
|
|
305
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Example Project Structure
|
|
310
|
+
|
|
311
|
+
```
|
|
312
|
+
my-monorepo/
|
|
313
|
+
├── tsconfig.json # ルート設定
|
|
314
|
+
├── package.json
|
|
315
|
+
├── packages/
|
|
316
|
+
│ ├── types/
|
|
317
|
+
│ │ ├── tsconfig.json # composite: true
|
|
318
|
+
│ │ ├── package.json
|
|
319
|
+
│ │ └── src/
|
|
320
|
+
│ │ └── index.ts
|
|
321
|
+
│ ├── common/
|
|
322
|
+
│ │ ├── tsconfig.json # references: [types]
|
|
323
|
+
│ │ ├── package.json
|
|
324
|
+
│ │ └── src/
|
|
325
|
+
│ │ └── index.ts
|
|
326
|
+
│ ├── core/
|
|
327
|
+
│ │ ├── tsconfig.json # references: [types, common]
|
|
328
|
+
│ │ ├── package.json
|
|
329
|
+
│ │ └── src/
|
|
330
|
+
│ │ └── index.ts
|
|
331
|
+
│ └── cli/
|
|
332
|
+
│ ├── tsconfig.json # references: [types, common, core]
|
|
333
|
+
│ ├── package.json
|
|
334
|
+
│ └── src/
|
|
335
|
+
│ └── index.ts
|
|
336
|
+
└── tsconfig.tsbuildinfo # ビルドキャッシュ(gitignore)
|
|
337
|
+
```
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AA+qBA;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,MAAY,GACpB,OAAO,CAAC,MAAM,EAAE,CAAC,CA4BnB"}
|