Repository navigation
Expand file tree
/
Copy pathrush.mdc
More file actions
414 lines (353 loc) · 13.4 KB
/
Copy pathrush.mdc
File metadata and controls
414 lines (353 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
---
description:
globs:
alwaysApply: true
---
You are a Rush monorepo development and management expert. Your role is to assist with Rush-related tasks while following these key principles and best practices:
# 1. Core Principles
- Follow Monorepo best practices
- Adhere to Rush's project isolation principles
- Maintain clear dependency management
- Use standardized versioning and change management
- Implement efficient build processes
# 2. Project Structure and Organization
## 2.1 Standard Directory Structure
The standard directory structure for a Rush monorepo is as follows:
```
/
├── common/ # Rush common files directory
| ├── autoinstallers # Autoinstaller tool configuration
│ ├── config/ # Configuration files directory
│ │ ├── rush/ # Rush core configuration
│ │ │ ├── command-line.json # Command line configuration
│ │ │ ├── build-cache.json # Build cache configuration
│ │ │ └── subspaces.json # Subspace configuration
│ │ └── subspaces/ # Subspace configuration
│ │ └── <subspace-name> # Specific Subspace
│ │ ├── pnpm-lock.yaml # Subspace dependency lock file
│ │ ├── .pnpmfile.cjs # PNPM hook script
│ │ ├── common-versions.json # Subspace version configuration
│ │ ├── pnpm-config.json # PNPM configuration
│ │ └── repo-state.json # subspace state hash value
│ ├── scripts/ # Common scripts
│ └── temp/ # Temporary files
└── rush.json # Rush main configuration file
```
## 2.2 Important Configuration Files
1. `rush.json` (Root Directory)
- Rush's main configuration file
- Key configuration items:
```json
{
"rushVersion": "5.x.x", // Rush version
// Choose PNPM as package manager
"pnpmVersion": "8.x.x",
// Or use NPM
// "npmVersion": "8.x.x",
// Or use Yarn
// "yarnVersion": "1.x.x",
"projectFolderMinDepth": 1, // Minimum project depth
"projectFolderMaxDepth": 3, // Maximum project depth
"projects": [], // Project list
"nodeSupportedVersionRange": ">=14.15.0", // Node.js version requirement
// Project configuration
"projects": [
{
"packageName": "@scope/project-a", // Project package name
"projectFolder": "packages/project-a", // Project path
"shouldPublish": true, // Whether to publish
"decoupledLocalDependencies": [], // Cyclic dependency projects
"subspaceName": "subspaceA", // Which Subspace it belongs to
}
],
}
```
2. `common/config/rush/command-line.json`
- Custom commands and parameter configuration
- Command types:
1. `bulk`: Batch commands, executed separately for each project
```json
{
"commandKind": "bulk",
"name": "build",
"summary": "Build projects",
"enableParallelism": true, // Whether to allow parallelism
"ignoreMissingScript": false // Whether to ignore missing scripts
}
```
2. `global`: Global commands, executed once for the entire repository
```json
{
"commandKind": "global",
"name": "deploy",
"summary": "Deploy application",
"shellCommand": "node common/scripts/deploy.js"
}
```
- Parameter types:
```json
"parameters": [
{
"parameterKind": "flag", // Switch parameter --production
"longName": "--production"
},
{
"parameterKind": "string", // String parameter --env dev
"longName": "--env"
},
{
"parameterKind": "stringList", // String list --tag a --tag b
"longName": "--tag"
},
{
"parameterKind": "choice", // Choice parameter --locale en-us
"longName": "--locale",
"alternatives": ["en-us", "zh-cn"]
},
{
"parameterKind": "integer", // Integer parameter --timeout 30
"longName": "--timeout"
},
{
"parameterKind": "integerList" // Integer list --pr 1 --pr 2
"longName": "--pr"
}
]
```
3. `common/config/subspaces/<subspace-name>/common-versions.json`
- Configure NPM dependency versions affecting all projects
- Key configuration items:
```json
{
// Specify preferred versions for specific packages
"preferredVersions": {
"react": "17.0.2", // Restrict react version
"typescript": "~4.5.0" // Restrict typescript version
},
// Whether to automatically add all dependencies to preferredVersions
"implicitlyPreferredVersions": true,
// Allow certain dependencies to use multiple different versions
"allowedAlternativeVersions": {
"typescript": ["~4.5.0", "~4.6.0"]
}
}
```
4. `common/config/rush/subspaces.json`
- Purpose: Configure Rush Subspace functionality
- Key configuration items:
```json
{
// Whether to enable Subspace functionality
"subspacesEnabled": false,
// Subspace name list
"subspaceNames": ["team-a", "team-b"],
}
```
# 3. Command Usage
## 3.1 Command Tool Selection
Choose the correct command tool based on different scenarios:
1. `rush` command
- Purpose: Execute operations affecting the entire repository or multiple projects
- Features:
- Strict parameter validation and documentation
- Support for global and batch commands
- Suitable for standardized workflows
- Use cases: Dependency installation, building, publishing, and other standard operations
2. `rushx` command
- Purpose: Execute specific scripts for a single project
- Features:
- Similar to `npm run` or `pnpm run`
- Uses Rush version selector to ensure toolchain consistency
- Prepares shell environment based on Rush configuration
- Use cases:
- Running project-specific build scripts
- Executing tests
- Running development servers
3. `rush-pnpm` command
- Purpose: Replace direct use of pnpm in Rush repository
- Features:
- Sets correct PNPM workspace context
- Supports Rush-specific enhancements
- Provides compatibility checks with Rush
- Use cases: When direct PNPM commands are needed
## 3.2 Common Commands Explained
1. `rush update`
- Function: Install and update dependencies
- Important parameters:
- `-p, --purge`: Clean before installation
- `--bypass-policy`: Bypass gitPolicy rules
- `--no-link`: Don't create project symlinks
- `--network-concurrency COUNT`: Limit concurrent network requests
- Use cases:
- After first cloning repository
- After pulling new Git changes
- After modifying package.json
- When dependencies need updating
2. `rush install`
- Function: Install dependencies based on existing shrinkwrap file
- Features:
- Read-only operation, won't modify shrinkwrap file
- Suitable for CI environment
- Important parameters:
- `-p, --purge`: Clean before installation
- `--bypass-policy`: Bypass gitPolicy rules
- `--no-link`: Don't create project symlinks
- Use cases:
- CI/CD pipeline
- Ensuring dependency version consistency
- Avoiding accidental shrinkwrap file updates
3. `rush build`
- Function: Incremental project build
- Features:
- Only builds changed projects
- Supports parallel building
- Use cases:
- Daily development builds
- Quick change validation
4. `rush rebuild`
- Function: Complete clean build
- Features:
- Builds all projects
- Cleans previous build artifacts
- Use cases:
- When complete build cleaning is needed
- When investigating build issues
5. `rush add`
- Function: Add dependencies to project
- Usage: `rush add -p <package> [--dev] [--exact]`
- Important parameters:
- `-p, --package`: Package name
- `--dev`: Add as development dependency
- `--exact`: Use exact version
- Use cases: Adding new dependency packages
- Note: Must be run in corresponding project directory
6. `rush remove`
- Function: Remove project dependencies
- Usage: `rush remove -p <package>`
- Use cases: Clean up unnecessary dependencies
7. `rush purge`
- Function: Clean temporary files and installation files
- Use cases:
- Clean build environment
- Resolve dependency issues
- Free up disk space
# 4. Dependency Management
## 4.1 Package Manager Selection
Specify in `rush.json`:
```json
{
// Choose PNPM as package manager
"pnpmVersion": "8.x.x",
// Or use NPM
// "npmVersion": "8.x.x",
// Or use Yarn
// "yarnVersion": "1.x.x",
}
```
## 4.2 Version Management
- Location: `common/config/subspaces/<subspace-name>/common-versions.json`
- Configuration example:
```json
{
// Specify preferred versions for packages
"preferredVersions": {
"react": "17.0.2",
"typescript": "~4.5.0"
},
// Allow certain dependencies to use multiple versions
"allowedAlternativeVersions": {
"typescript": ["~4.5.0", "~4.6.0"]
}
}
```
## 4.3 Subspace
Using Subspace technology allows organizing related projects together, meaning multiple PNPM lock files can be used in a Rush Monorepo. Different project groups can have their own independent dependency version management without affecting each other, thus isolating projects, reducing risks from dependency updates, and significantly improving dependency installation and update speed.
Declare which Subspaces exist in `common/config/rush/subspaces.json`, and declare which Subspace each project belongs to in `rush.json`'s `subspaceName`.
# 5. Caching Capabilities
## 5.1 Cache Principles
Rush cache is a build caching system that accelerates the build process by caching project build outputs. Build results are cached in `common/temp/build-cache`, and when project source files, dependencies, environment variables, command line parameters, etc., haven't changed, the cache is directly extracted instead of rebuilding.
## 5.2 Core Configuration
Configuration file: `<project>/config/rush-project.json`
```json
{
"operationSettings": [
{
"operationName": "build", // Operation name
"outputFolderNames": ["lib", "dist"], // Output directories
"disableBuildCacheForOperation": false, // Whether to disable cache
"dependsOnEnvVars": ["MY_ENVIRONMENT_VARIABLE"], // Dependent environment variables
}
]
}
```
# 6. Best Practices
## 6.1 Selecting Specific Projects
When running commands like `install`, `update`, `build`, `rebuild`, etc., by default all projects under the entire repository are processed. To improve efficiency, Rush provides various project selection parameters that can be chosen based on different scenarios:
1. `--to <PROJECT>`
- Function: Select specified project and all its dependencies
- Use cases:
- Build specific project and its dependencies
- Ensure complete dependency chain build
- Example:
```bash
rush build --to @my-company/my-project
rush build --to my-project # If project name is unique, scope can be omitted
rush build --to . # Use current directory's project
```
2. `--to-except <PROJECT>`
- Function: Select all dependencies of specified project, but not the project itself
- Use cases:
- Update project dependencies without processing project itself
- Pre-build dependencies
- Example:
```bash
rush build --to-except @my-company/my-project
```
3. `--from <PROJECT>`
- Function: Select specified project and all its downstream dependencies
- Use cases:
- Validate changes' impact on downstream projects
- Build all projects affected by specific project
- Example:
```bash
rush build --from @my-company/my-project
```
4. `--impacted-by <PROJECT>`
- Function: Select projects that might be affected by specified project changes, excluding dependencies
- Use cases:
- Quick test of project change impacts
- Use when dependency status is already correct
- Example:
```bash
rush build --impacted-by @my-company/my-project
```
5. `--impacted-by-except <PROJECT>`
- Function: Similar to `--impacted-by`, but excludes specified project itself
- Use cases:
- Project itself has been manually built
- Only need to test downstream impacts
- Example:
```bash
rush build --impacted-by-except @my-company/my-project
```
6. `--only <PROJECT>`
- Function: Only select specified project, completely ignore dependency relationships
- Use cases:
- Clearly know dependency status is correct
- Combine with other selection parameters
- Example:
```bash
rush build --only @my-company/my-project
rush build --impacted-by projectA --only projectB
```
## 6.2 Troubleshooting
1. Dependency Issue Handling
- Avoid directly using `npm`, `pnpm`, `yarn` package managers
- Use `rush purge` to clean all temporary files
- Run `rush update --recheck` to force check all dependencies
2. Build Issue Handling
- Use `rush rebuild` to skip cache and perform complete build
- Check project's `rushx build` command output
3. Logging and Diagnostics
- Use `--verbose` parameter for detailed logs
- Verify command parameter correctness