0
# Configuration
1
2
Types and interfaces for nx.json configuration management and workspace setup. Provides comprehensive type definitions for configuring Nx workspaces, build targets, and development tools.
3
4
## Capabilities
5
6
### Nx Configuration Interface
7
8
Main configuration interface for nx.json files with all supported options.
9
10
```typescript { .api }
11
/**
12
* Main nx.json configuration interface
13
*/
14
export interface NxJsonConfiguration<T = "*"> {
15
/** Base configuration file to extend from */
16
extends?: string;
17
/** Implicit dependencies configuration */
18
implicitDependencies?: ImplicitDependencyEntry<T>;
19
/** Target dependencies mapping (deprecated) */
20
targetDependencies?: TargetDependencies;
21
/** Named inputs for target caching */
22
namedInputs?: { [inputName: string]: (string | InputDefinition)[] };
23
/** Default configurations for targets */
24
targetDefaults?: TargetDefaults;
25
/** NPM scope for the workspace */
26
npmScope?: string;
27
/** Configuration for affected commands */
28
affected?: NxAffectedConfig;
29
/** Workspace layout configuration */
30
workspaceLayout?: { libsDir: string; appsDir: string };
31
/** Task runner configurations */
32
tasksRunnerOptions?: { [tasksRunnerName: string]: { runner: string; options?: any } };
33
/** Generator configurations */
34
generators?: { [collectionName: string]: { [generatorName: string]: any } };
35
/** CLI configuration */
36
cli?: { packageManager?: PackageManager; defaultCollection?: string; defaultProjectName?: string };
37
/** Plugin configurations */
38
plugins?: string[];
39
/** Plugin-specific configurations */
40
pluginsConfig?: Record<string, unknown>;
41
/** Default project for commands */
42
defaultProject?: string;
43
/** Installation configuration */
44
installation?: NxInstallationConfiguration;
45
}
46
47
/** Installation configuration for Nx */
48
export interface NxInstallationConfiguration {
49
/** Installation method */
50
method?: 'package-manager' | 'nx-cloud';
51
/** Version information */
52
version?: string;
53
}
54
```
55
56
### Executor and Generator Types
57
58
Types for executors and generators in the Nx ecosystem.
59
60
```typescript { .api }
61
/** Configuration for an executor */
62
export interface ExecutorConfig {
63
/** Schema for the executor options */
64
schema: any;
65
/** Implementation function or module path */
66
implementation: any;
67
/** Whether this executor is a builder (Angular CLI compatibility) */
68
isBuilder?: boolean;
69
/** Batch execution support */
70
hasher?: any;
71
/** Batch execution implementation */
72
batchImplementation?: any;
73
}
74
75
/** Information about a generator/schematic */
76
export interface GeneratorInfo {
77
/** Name of the generator */
78
name: string;
79
/** Schema for the generator options */
80
schema: any;
81
/** Implementation function or factory */
82
factory: any;
83
/** Description of what the generator does */
84
description?: string;
85
/** Whether this is a collection or individual generator */
86
type?: 'generator' | 'schematic';
87
}
88
```
89
90
### Package Manager Types
91
92
Type definitions for supported package managers and their configurations.
93
94
```typescript { .api }
95
/** Supported package managers */
96
export type PackageManager = 'yarn' | 'pnpm' | 'npm';
97
98
/** Command structure interface for package managers */
99
export interface PackageManagerCommands {
100
install: string;
101
add: string;
102
addDev: string;
103
rm: string;
104
exec: string;
105
dlx: string;
106
list: string;
107
}
108
```
109
110
### Project Configuration Types
111
112
Core types for project and workspace configuration.
113
114
```typescript { .api }
115
/** Configuration for individual projects */
116
export interface ProjectConfiguration {
117
/** Project name */
118
name?: string;
119
/** Root directory of the project */
120
root: string;
121
/** Source root directory */
122
sourceRoot?: string;
123
/** Type of project */
124
projectType?: 'application' | 'library';
125
/** Build targets for the project */
126
targets?: Record<string, TargetConfiguration>;
127
/** Tags for the project */
128
tags?: string[];
129
/** Implicit dependencies */
130
implicitDependencies?: string[];
131
/** Named inputs for the project */
132
namedInputs?: Record<string, (string | InputDefinition)[]>;
133
}
134
135
/** Complete workspace projects configuration */
136
export interface ProjectsConfigurations {
137
/** Version of the configuration format */
138
version: number;
139
/** Map of project names to their configurations */
140
projects: Record<string, ProjectConfiguration>;
141
}
142
```
143
144
### Target Configuration Types
145
146
Configuration types for build targets and their dependencies.
147
148
```typescript { .api }
149
/** Target defaults mapping */
150
export type TargetDefaults = Record<string, Partial<TargetConfiguration>>;
151
152
/** Target dependencies mapping (deprecated) */
153
export type TargetDependencies = Record<string, (TargetDependencyConfig | string)[]>;
154
155
/** Configuration for a single target */
156
export interface TargetConfiguration {
157
executor?: string;
158
command?: string;
159
options?: any;
160
configurations?: Record<string, any>;
161
inputs?: (InputDefinition | string)[];
162
outputs?: string[];
163
dependsOn?: (TargetDependencyConfig | string)[];
164
cache?: boolean;
165
}
166
167
/** Target dependency configuration */
168
export interface TargetDependencyConfig {
169
target: string;
170
projects?: string[] | string;
171
params?: 'forward' | 'ignore';
172
}
173
174
/** Input definition for target caching */
175
export interface InputDefinition {
176
input?: string;
177
fileset?: string;
178
projects?: string | string[];
179
dependencies?: boolean;
180
dependentTasksOutputFiles?: string;
181
externalDependencies?: string[];
182
}
183
```
184
185
### Affected Configuration
186
187
Configuration for affected command behavior and default branches.
188
189
```typescript { .api }
190
/**
191
* Configuration for affected commands
192
*/
193
export interface NxAffectedConfig {
194
/** Default branch for affected commands */
195
defaultBase?: string;
196
}
197
```
198
199
### Implicit Dependencies
200
201
Types for configuring implicit dependencies between projects.
202
203
```typescript { .api }
204
/**
205
* Configuration for implicit dependencies
206
*/
207
export type ImplicitDependencyEntry<T> = Record<string, T[] | "*">;
208
209
/**
210
* Interface for nested implicit dependencies
211
*/
212
export interface ImplicitJsonSubsetDependency<T> {
213
[key: string]: T[] | "*" | ImplicitJsonSubsetDependency<T>;
214
}
215
```
216
217
### Plugin Configuration
218
219
Configuration types for Nx plugins and their options.
220
221
```typescript { .api }
222
/**
223
* Configuration for Nx JS plugin
224
*/
225
export interface NrwlJsPluginConfig {
226
/** Whether to analyze source files for dependencies */
227
analyzeSourceFiles?: boolean;
228
/** Whether to analyze package.json for dependencies */
229
analyzePackageJson?: boolean;
230
}
231
```
232
233
## Usage Examples
234
235
### Basic nx.json Configuration
236
237
```typescript
238
import type { NxJsonConfiguration, PackageManager } from "@nrwl/tao/shared/nx";
239
240
const nxConfig: NxJsonConfiguration = {
241
npmScope: "myorg",
242
affected: {
243
defaultBase: "main"
244
},
245
cli: {
246
packageManager: "npm" as PackageManager,
247
defaultCollection: "@nx/workspace"
248
},
249
targetDefaults: {
250
build: {
251
cache: true,
252
inputs: ["production", "^production"]
253
},
254
test: {
255
cache: true,
256
inputs: ["default", "^production", { externalDependencies: ["jest"] }]
257
}
258
},
259
namedInputs: {
260
default: ["{projectRoot}/**/*", "sharedGlobals"],
261
production: ["default", "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)", "!{projectRoot}/tsconfig.spec.json"]
262
}
263
};
264
```
265
266
### Target Configuration
267
268
```typescript
269
import type { TargetConfiguration } from "@nrwl/tao/shared/nx";
270
271
const buildTarget: TargetConfiguration = {
272
executor: "@nx/webpack:webpack",
273
options: {
274
outputPath: "dist/apps/myapp",
275
main: "apps/myapp/src/main.ts",
276
tsConfig: "apps/myapp/tsconfig.app.json"
277
},
278
configurations: {
279
production: {
280
fileReplacements: [{
281
replace: "apps/myapp/src/environments/environment.ts",
282
with: "apps/myapp/src/environments/environment.prod.ts"
283
}]
284
}
285
},
286
dependsOn: ["^build"],
287
cache: true
288
};
289
```
290
291
### Plugin Configuration
292
293
```typescript
294
import type { NxJsonConfiguration, NrwlJsPluginConfig } from "@nrwl/tao/shared/nx";
295
296
const configWithPlugins: NxJsonConfiguration = {
297
plugins: ["@nx/js"],
298
pluginsConfig: {
299
"@nx/js": {
300
analyzeSourceFiles: true,
301
analyzePackageJson: true
302
} as NrwlJsPluginConfig
303
}
304
};
305
```