workspace-utils 1.0.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/.github/workflows/mdbook.yml +64 -0
- package/.prettierignore +22 -0
- package/.prettierrc +13 -0
- package/LICENSE +21 -0
- package/README.md +278 -0
- package/docs/book.toml +10 -0
- package/docs/src/SUMMARY.md +24 -0
- package/docs/src/commands/build.md +110 -0
- package/docs/src/commands/dev.md +118 -0
- package/docs/src/commands/overview.md +239 -0
- package/docs/src/commands/run.md +153 -0
- package/docs/src/configuration.md +249 -0
- package/docs/src/examples.md +567 -0
- package/docs/src/installation.md +148 -0
- package/docs/src/introduction.md +117 -0
- package/docs/src/quick-start.md +278 -0
- package/docs/src/troubleshooting.md +533 -0
- package/index.ts +84 -0
- package/package.json +54 -0
- package/src/commands/build.ts +158 -0
- package/src/commands/dev.ts +192 -0
- package/src/commands/run.test.ts +329 -0
- package/src/commands/run.ts +118 -0
- package/src/core/dependency-graph.ts +262 -0
- package/src/core/process-runner.ts +355 -0
- package/src/core/workspace.test.ts +404 -0
- package/src/core/workspace.ts +228 -0
- package/src/package-managers/bun.test.ts +209 -0
- package/src/package-managers/bun.ts +79 -0
- package/src/package-managers/detector.test.ts +199 -0
- package/src/package-managers/detector.ts +111 -0
- package/src/package-managers/index.ts +10 -0
- package/src/package-managers/npm.ts +79 -0
- package/src/package-managers/pnpm.ts +101 -0
- package/src/package-managers/types.ts +42 -0
- package/src/utils/output.ts +301 -0
- package/src/utils/package-utils.ts +243 -0
- package/tests/bun-workspace/apps/web-app/package.json +18 -0
- package/tests/bun-workspace/bun.lockb +0 -0
- package/tests/bun-workspace/package.json +18 -0
- package/tests/bun-workspace/packages/shared-utils/package.json +15 -0
- package/tests/bun-workspace/packages/ui-components/package.json +17 -0
- package/tests/npm-workspace/package-lock.json +0 -0
- package/tests/npm-workspace/package.json +18 -0
- package/tests/npm-workspace/packages/core/package.json +15 -0
- package/tests/pnpm-workspace/package.json +14 -0
- package/tests/pnpm-workspace/packages/utils/package.json +15 -0
- package/tests/pnpm-workspace/pnpm-workspace.yaml +3 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# workspace-utils
|
|
2
|
+
|
|
3
|
+
A powerful **CLI tool** designed to orchestrate scripts across monorepo workspaces with **parallel execution**, **dependency-aware builds**, and **real-time log streaming**.
|
|
4
|
+
|
|
5
|
+
## What is workspace-utils?
|
|
6
|
+
|
|
7
|
+
`workspace-utils` simplifies working with monorepos by providing intelligent script orchestration across multiple packages. Whether you're using **Bun**, **pnpm**, or **npm** workspaces, this tool automatically detects your setup and provides a unified interface for running scripts efficiently.
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
### 🚀 **Parallel Execution by Default**
|
|
12
|
+
|
|
13
|
+
Run scripts across multiple packages simultaneously with configurable concurrency limits. Perfect for tests, linting, and development workflows.
|
|
14
|
+
|
|
15
|
+
### 🏗️ **Dependency-Aware Builds**
|
|
16
|
+
|
|
17
|
+
Automatically builds packages in the correct order using topological sorting. Dependencies are always built before their dependents.
|
|
18
|
+
|
|
19
|
+
### 🎨 **Real-time Log Streaming**
|
|
20
|
+
|
|
21
|
+
Color-coded, prefixed output makes it easy to track which package is doing what. Each package gets its own color for instant identification.
|
|
22
|
+
|
|
23
|
+
### 🔍 **Smart Package Filtering**
|
|
24
|
+
|
|
25
|
+
Use glob patterns to target specific packages:
|
|
26
|
+
|
|
27
|
+
- `--filter "@scope/*"` - All packages in a scope
|
|
28
|
+
- `--filter "apps/*"` - All apps
|
|
29
|
+
- `--filter "*-utils"` - All utility packages
|
|
30
|
+
|
|
31
|
+
### 📦 **Multi Package Manager Support**
|
|
32
|
+
|
|
33
|
+
Works seamlessly with:
|
|
34
|
+
|
|
35
|
+
- **Bun workspaces** (`package.json` + `bun.lockb`)
|
|
36
|
+
- **pnpm workspaces** (`pnpm-workspace.yaml` + `pnpm-lock.yaml`)
|
|
37
|
+
- **npm workspaces** (`package.json` + `package-lock.json`)
|
|
38
|
+
|
|
39
|
+
### 🎯 **Zero Configuration**
|
|
40
|
+
|
|
41
|
+
No config files needed. Just run it in any workspace and it automatically detects your setup.
|
|
42
|
+
|
|
43
|
+
## Why workspace-utils?
|
|
44
|
+
|
|
45
|
+
### Before workspace-utils
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Run tests manually in each package
|
|
49
|
+
cd packages/utils && npm test
|
|
50
|
+
cd ../ui-components && npm test
|
|
51
|
+
cd ../api-client && npm test
|
|
52
|
+
cd ../../apps/web-app && npm test
|
|
53
|
+
|
|
54
|
+
# Build in correct order manually
|
|
55
|
+
cd packages/utils && npm run build
|
|
56
|
+
cd ../ui-components && npm run build # depends on utils
|
|
57
|
+
cd ../api-client && npm run build # depends on utils
|
|
58
|
+
cd ../../apps/web-app && npm run build # depends on ui-components & api-client
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### After workspace-utils
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"scripts": {
|
|
66
|
+
"test": "wsu run test",
|
|
67
|
+
"build": "wsu build",
|
|
68
|
+
"dev": "wsu dev"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Run all tests in parallel
|
|
75
|
+
npm run test
|
|
76
|
+
|
|
77
|
+
# Build everything in correct dependency order
|
|
78
|
+
npm run build
|
|
79
|
+
|
|
80
|
+
# Start all dev servers with live logs
|
|
81
|
+
npm run dev
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## At a Glance
|
|
85
|
+
|
|
86
|
+
| Package.json Script | Purpose | Execution |
|
|
87
|
+
| ------------------------ | ------------------------- | ------------------------------ |
|
|
88
|
+
| `"test": "wsu run test"` | Run tests across packages | **Parallel** by default |
|
|
89
|
+
| `"build": "wsu build"` | Build packages | **Dependency order** (batched) |
|
|
90
|
+
| `"dev": "wsu dev"` | Start dev servers | **Parallel** with live logs |
|
|
91
|
+
|
|
92
|
+
## Quick Example
|
|
93
|
+
|
|
94
|
+
Given this monorepo structure:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
my-project/
|
|
98
|
+
├── package.json (workspaces: ["packages/*", "apps/*"])
|
|
99
|
+
├── packages/
|
|
100
|
+
│ ├── utils/ # no dependencies
|
|
101
|
+
│ ├── ui-components/ # depends on utils
|
|
102
|
+
│ └── api-client/ # depends on utils
|
|
103
|
+
└── apps/
|
|
104
|
+
└── web-app/ # depends on ui-components, api-client
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Running `npm run build` (with `"build": "wsu build"` in package.json) will:
|
|
108
|
+
|
|
109
|
+
1. **Batch 1:** Build `utils`
|
|
110
|
+
2. **Batch 2:** Build `ui-components` and `api-client` in parallel
|
|
111
|
+
3. **Batch 3:** Build `web-app`
|
|
112
|
+
|
|
113
|
+
Running `npm run test` (with `"test": "wsu run test"` in package.json) will run all tests in parallel across all packages simultaneously.
|
|
114
|
+
|
|
115
|
+
## Ready to Get Started?
|
|
116
|
+
|
|
117
|
+
Continue to [Installation](./installation.md) to set up workspace-utils in your project.
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
# Quick Start
|
|
2
|
+
|
|
3
|
+
Get up and running with workspace-utils in minutes. This guide assumes you have a monorepo with workspaces already set up.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- A monorepo with Bun, pnpm, or npm workspaces
|
|
8
|
+
- Node.js 18+ installed
|
|
9
|
+
- workspace-utils installed as a dev dependency ([Installation Guide](./installation.md))
|
|
10
|
+
|
|
11
|
+
## Setup Your Scripts
|
|
12
|
+
|
|
13
|
+
First, add workspace-utils scripts to your root `package.json`:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "wsu run test",
|
|
19
|
+
"build": "wsu build",
|
|
20
|
+
"dev": "wsu dev",
|
|
21
|
+
"lint": "wsu run lint"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Your First Command
|
|
27
|
+
|
|
28
|
+
Navigate to your monorepo root and run:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm run test
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This will:
|
|
35
|
+
|
|
36
|
+
1. 🔍 **Auto-detect** your package manager (Bun, pnpm, or npm)
|
|
37
|
+
2. 📦 **Discover** all packages in your workspace
|
|
38
|
+
3. ✅ **Filter** to packages that have a `test` script
|
|
39
|
+
4. 🚀 **Run tests** in parallel across all packages
|
|
40
|
+
5. 📊 **Display** a summary of results
|
|
41
|
+
|
|
42
|
+
## Core Commands
|
|
43
|
+
|
|
44
|
+
### Run Scripts Across Packages
|
|
45
|
+
|
|
46
|
+
Add these scripts to your `package.json`:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"scripts": {
|
|
51
|
+
"test": "wsu run test",
|
|
52
|
+
"test:sequential": "wsu run test --sequential",
|
|
53
|
+
"lint": "wsu run lint --concurrency 8"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Then run:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npm run test # Run tests in parallel (default)
|
|
62
|
+
npm run test:sequential # Run builds sequentially
|
|
63
|
+
npm run lint # Run linting with custom concurrency
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Build with Dependency Awareness
|
|
67
|
+
|
|
68
|
+
Add build scripts:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "wsu build",
|
|
74
|
+
"build:backend": "wsu build --filter '@myorg/backend-*'"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Then run:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm run build # Build all packages in dependency order
|
|
83
|
+
npm run build:backend # Build only backend packages
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Start Development Servers
|
|
87
|
+
|
|
88
|
+
Add dev scripts:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"scripts": {
|
|
93
|
+
"dev": "wsu dev",
|
|
94
|
+
"dev:apps": "wsu dev --filter 'apps/*'"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Then run:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm run dev # Start all dev servers
|
|
103
|
+
npm run dev:apps # Start only frontend packages
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Example Walkthrough
|
|
107
|
+
|
|
108
|
+
Let's say you have this monorepo structure:
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
my-project/
|
|
112
|
+
├── package.json
|
|
113
|
+
├── packages/
|
|
114
|
+
│ ├── utils/
|
|
115
|
+
│ │ └── package.json (scripts: test, build, lint)
|
|
116
|
+
│ └── ui-components/
|
|
117
|
+
│ └── package.json (scripts: test, build, dev, storybook)
|
|
118
|
+
└── apps/
|
|
119
|
+
└── web-app/
|
|
120
|
+
└── package.json (scripts: test, build, dev, start)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Step 1: Run Tests
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npm run test
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Output:**
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
🚀 Running script "test" across packages...
|
|
133
|
+
|
|
134
|
+
📁 Workspace root: /Users/you/my-project
|
|
135
|
+
📦 Found 3 packages
|
|
136
|
+
|
|
137
|
+
✅ Running "test" in 3 packages:
|
|
138
|
+
• utils
|
|
139
|
+
• ui-components
|
|
140
|
+
• web-app
|
|
141
|
+
|
|
142
|
+
🔧 Package manager: npm
|
|
143
|
+
⚡ Execution mode: parallel (concurrency: 4)
|
|
144
|
+
|
|
145
|
+
[utils] Starting: npm run test
|
|
146
|
+
[ui-components] Starting: npm run test
|
|
147
|
+
[web-app] Starting: npm run test
|
|
148
|
+
[utils] ✅ Completed in 1,234ms
|
|
149
|
+
[ui-components] ✅ Completed in 2,456ms
|
|
150
|
+
[web-app] ✅ Completed in 3,789ms
|
|
151
|
+
|
|
152
|
+
📊 Execution Summary:
|
|
153
|
+
✅ Successful: 3
|
|
154
|
+
⏱️ Total duration: 3,789ms
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Step 2: Build Everything
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
npm run build
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Output:**
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
🏗️ Building packages in dependency order...
|
|
167
|
+
|
|
168
|
+
📊 Building dependency graph...
|
|
169
|
+
✅ Build order determined: 2 batches
|
|
170
|
+
|
|
171
|
+
📋 Build Plan:
|
|
172
|
+
Batch 1: utils
|
|
173
|
+
Batch 2: ui-components, web-app
|
|
174
|
+
|
|
175
|
+
🔧 Package manager: npm
|
|
176
|
+
⚡ Batch concurrency: 4
|
|
177
|
+
|
|
178
|
+
🔄 Running batch 1/2 (1 packages)
|
|
179
|
+
[utils] Starting: npm run build
|
|
180
|
+
[utils] ✅ Completed in 2,000ms
|
|
181
|
+
✅ Batch 1 completed successfully
|
|
182
|
+
|
|
183
|
+
🔄 Running batch 2/2 (2 packages)
|
|
184
|
+
[ui-components] Starting: npm run build
|
|
185
|
+
[web-app] Starting: npm run build
|
|
186
|
+
[ui-components] ✅ Completed in 3,000ms
|
|
187
|
+
[web-app] ✅ Completed in 4,000ms
|
|
188
|
+
✅ Batch 2 completed successfully
|
|
189
|
+
|
|
190
|
+
🎉 All packages built successfully!
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Step 3: Start Development
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
npm run dev
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Output:**
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
🚀 Starting development servers with live log streaming...
|
|
203
|
+
|
|
204
|
+
✅ Starting dev servers for 2 packages:
|
|
205
|
+
• ui-components
|
|
206
|
+
• web-app
|
|
207
|
+
|
|
208
|
+
🔧 Package manager: npm
|
|
209
|
+
⚡ Running 2 dev servers simultaneously
|
|
210
|
+
|
|
211
|
+
🎬 Starting development servers...
|
|
212
|
+
|
|
213
|
+
────────────────────────────────────────────────────────
|
|
214
|
+
[ui-components] Starting: npm run dev
|
|
215
|
+
[web-app] Starting: npm run dev
|
|
216
|
+
[ui-components] Server running on http://localhost:6006
|
|
217
|
+
[web-app] Server running on http://localhost:3000
|
|
218
|
+
[ui-components] Hot reload enabled
|
|
219
|
+
[web-app] Hot reload enabled
|
|
220
|
+
...
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Filtering Examples
|
|
224
|
+
|
|
225
|
+
Use filtering options in your package.json scripts:
|
|
226
|
+
|
|
227
|
+
```json
|
|
228
|
+
{
|
|
229
|
+
"scripts": {
|
|
230
|
+
"test:scope": "wsu run test --filter '@myorg/*'",
|
|
231
|
+
"build:apps": "wsu build --filter 'apps/*'",
|
|
232
|
+
"dev:frontend": "wsu dev --filter '*frontend*'",
|
|
233
|
+
"lint:utils": "wsu run lint --filter '*utils*'"
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Then run:
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
npm run test:scope # Run tests only for scoped packages
|
|
242
|
+
npm run build:apps # Build only apps
|
|
243
|
+
npm run dev:frontend # Start dev servers for frontend packages
|
|
244
|
+
npm run lint:utils # Run linting for utility packages
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Common Patterns
|
|
248
|
+
|
|
249
|
+
### Package.json Scripts
|
|
250
|
+
|
|
251
|
+
Add these to your root `package.json` for convenient shortcuts:
|
|
252
|
+
|
|
253
|
+
```json
|
|
254
|
+
{
|
|
255
|
+
"scripts": {
|
|
256
|
+
"test": "wsu run test",
|
|
257
|
+
"test:sequential": "wsu run test --sequential",
|
|
258
|
+
"build": "wsu build",
|
|
259
|
+
"build:frontend": "wsu build --filter 'apps/*'",
|
|
260
|
+
"dev": "wsu dev",
|
|
261
|
+
"lint": "wsu run lint",
|
|
262
|
+
"lint:fix": "wsu run lint:fix"
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## What's Next?
|
|
268
|
+
|
|
269
|
+
- 📚 Learn about [Configuration](./configuration.md) options
|
|
270
|
+
- 🔧 Explore all [Commands](./commands/overview.md) in detail
|
|
271
|
+
- 🎯 Check out [Common Patterns](./examples/common-patterns.md)
|
|
272
|
+
- 🐛 See [Troubleshooting](./troubleshooting/common-issues.md) if you run into issues
|
|
273
|
+
|
|
274
|
+
## Need Help?
|
|
275
|
+
|
|
276
|
+
- View all available options: `npx wsu --help`
|
|
277
|
+
- Get help for specific commands: `npx wsu run --help`
|
|
278
|
+
- Check out the [CLI Reference](./reference/cli.md) for complete documentation
|