Skip to content

Commit 0082be5

Browse files
Copilotaaronpowell
andcommitted
Document RunWithPackageManager method for Nx and Turborepo
Co-authored-by: aaronpowell <434140+aaronpowell@users.noreply.github.com>
1 parent 39c33be commit 0082be5

File tree

2 files changed

+71
-5
lines changed

2 files changed

+71
-5
lines changed

src/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions/MONOREPO.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,32 @@ Both Nx and Turborepo support all three package managers:
5252
- `.WithYarnPackageInstaller()` - uses yarn
5353
- `.WithPnpmPackageInstaller()` - uses pnpm
5454

55+
### Configuring Package Manager for App Execution
56+
57+
Use `RunWithPackageManager()` to configure which package manager command is used when running individual apps:
58+
59+
```csharp
60+
// Auto-infer from package installer annotation
61+
var nx = builder.AddNxApp("nx", workingDirectory: "../frontend")
62+
.WithYarnPackageInstaller()
63+
.RunWithPackageManager(); // Will use 'yarn' command
64+
65+
// Explicitly specify package manager (independent of installer)
66+
var turbo = builder.AddTurborepoApp("turbo", workingDirectory: "../frontend")
67+
.WithNpmPackageInstaller()
68+
.RunWithPackageManager("pnpm"); // Uses 'pnpm' despite npm installer
69+
70+
// Without RunWithPackageManager - uses default commands
71+
var nxDefault = builder.AddNxApp("nx-default", workingDirectory: "../frontend");
72+
nxDefault.AddApp("app1"); // Runs: nx serve app1 (no package manager prefix)
73+
```
74+
75+
**Command Generation Examples:**
76+
- `RunWithPackageManager("npm")``npx nx serve app1` or `npx turbo run dev --filter app1`
77+
- `RunWithPackageManager("yarn")``yarn nx serve app1` or `yarn turbo run dev --filter app1`
78+
- `RunWithPackageManager("pnpm")``pnpm nx serve app1` or `pnpm turbo run dev --filter app1`
79+
- No `RunWithPackageManager()``nx serve app1` or `turbo run dev --filter app1`
80+
5581
## How It Works
5682

5783
1. **Shared Installer**: The top-level resource (`NxResource` or `TurborepoResource`) manages a single package installation
@@ -89,11 +115,29 @@ You can migrate to:
89115
```csharp
90116
// New monorepo approach
91117
var nx = builder.AddNxApp("nx", workingDirectory: "./Frontend")
92-
.WithYarnPackageInstaller();
118+
.WithYarnPackageInstaller()
119+
.RunWithPackageManager(); // Configure package manager for app execution
93120
94121
var app1 = nx.AddApp("app-1", appName: "app1");
95-
var app2 = nx.AddApp("app-2", appName: "app2");
122+
var app2 = nx.AddApp("app-2", appName: "app2");
96123
var app3 = nx.AddApp("app-3", appName: "app3");
97124
```
98125

99-
This provides cleaner syntax and automatic dependency management.
126+
This provides cleaner syntax and automatic dependency management.
127+
128+
## Key Configuration Options
129+
130+
### Package Installation vs App Execution
131+
132+
It's important to understand the difference between package installation and app execution:
133+
134+
- **Package Installer** (`.WithNpmPackageInstaller()`, etc.) - Controls how packages are installed in the workspace
135+
- **Package Manager for Apps** (`.RunWithPackageManager()`) - Controls which command is used to run individual apps
136+
137+
```csharp
138+
var nx = builder.AddNxApp("nx", workingDirectory: "../frontend")
139+
.WithNpmPackageInstaller() // Install packages with: npm install
140+
.RunWithPackageManager("yarn"); // Run apps with: yarn nx serve app1
141+
142+
// This is valid - you can install with npm but run apps with yarn
143+
```

src/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions/README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,43 @@ For Nx and Turborepo monorepos, use the dedicated monorepo methods to avoid pack
3131
```csharp
3232
// Nx workspace
3333
var nx = builder.AddNxApp("nx", workingDirectory: "../frontend")
34-
.WithNpmPackageInstaller();
34+
.WithNpmPackageInstaller()
35+
.RunWithPackageManager(); // Automatically uses npm from installer
3536
3637
var app1 = nx.AddApp("app1");
3738
var app2 = nx.AddApp("app2", appName: "my-app-2");
3839

3940
// Turborepo workspace
4041
var turbo = builder.AddTurborepoApp("turbo", workingDirectory: "../frontend")
41-
.WithYarnPackageInstaller();
42+
.WithYarnPackageInstaller()
43+
.RunWithPackageManager("yarn"); // Explicitly specify yarn
4244
4345
var turboApp1 = turbo.AddApp("app1");
4446
var turboApp2 = turbo.AddApp("app2", filter: "custom-filter");
4547
```
4648

4749
See [MONOREPO.md](./MONOREPO.md) for detailed documentation on monorepo support.
4850

51+
### Configuring Package Manager for Monorepos
52+
53+
The `RunWithPackageManager()` method configures which package manager command is used when running individual apps in Nx or Turborepo workspaces:
54+
55+
```csharp
56+
// Auto-infer from package installer
57+
var nx = builder.AddNxApp("nx", workingDirectory: "../frontend")
58+
.WithYarnPackageInstaller()
59+
.RunWithPackageManager(); // Uses 'yarn' command
60+
61+
// Explicitly specify package manager
62+
var turbo = builder.AddTurborepoApp("turbo", workingDirectory: "../frontend")
63+
.WithNpmPackageInstaller()
64+
.RunWithPackageManager("pnpm"); // Uses 'pnpm' command despite npm installer
65+
66+
// Generated commands:
67+
// Nx with yarn: yarn nx serve app1
68+
// Turborepo with pnpm: pnpm turbo run dev --filter app1
69+
```
70+
4971
### Package installation with custom flags
5072

5173
You can pass additional flags to package managers during installation:

0 commit comments

Comments
 (0)