-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
nx-json.ts
334 lines (305 loc) · 9.74 KB
/
nx-json.ts
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
import { existsSync } from 'fs';
import { dirname, join } from 'path';
import type { ChangelogRenderOptions } from '../../changelog-renderer';
import { readJsonFile } from '../utils/fileutils';
import { PackageManager } from '../utils/package-manager';
import { workspaceRoot } from '../utils/workspace-root';
import {
InputDefinition,
TargetConfiguration,
TargetDependencyConfig,
} from './workspace-json-project-json';
export type ImplicitDependencyEntry<T = '*' | string[]> = {
[key: string]: T | ImplicitJsonSubsetDependency<T>;
};
export interface ImplicitJsonSubsetDependency<T = '*' | string[]> {
[key: string]: T | ImplicitJsonSubsetDependency<T>;
}
export interface NxAffectedConfig {
/**
* Default based branch used by affected commands.
*/
defaultBase?: string;
}
export type TargetDefaults = Record<string, Partial<TargetConfiguration>>;
export type TargetDependencies = Record<
string,
(TargetDependencyConfig | string)[]
>;
export interface NrwlJsPluginConfig {
analyzeSourceFiles?: boolean;
analyzePackageJson?: boolean;
analyzeLockfile?: boolean;
}
interface NxInstallationConfiguration {
/**
* Version used for Nx
*/
version: string;
/**
* Record<pluginPackageName, pluginVersion>. e.g.
* plugins: { '@nx/angular': '1.0.0' }
*/
plugins?: Record<string, string>;
}
/**
* **ALPHA**
*/
interface NxReleaseVersionConfiguration {
generator?: string;
generatorOptions?: Record<string, unknown>;
}
/**
* **ALPHA**
*/
export interface NxReleaseChangelogConfiguration {
/**
* Optionally create a release containing all relevant changes on a supported version control system, it
* is false by default.
*
* NOTE: if createRelease is set on a group of projects, it will cause the default releaseTagPattern of
* "{projectName}@v{version}" to be used for those projects, even when versioning everything together.
*/
createRelease?: 'github' | false;
/**
* This can either be set to a string value that will be written to the changelog file(s)
* at the workspace root and/or within project directories, or set to `false` to specify
* that no changelog entry should be made when there are no code changes.
*
* NOTE: The string value has a sensible default value and supports interpolation of
* {projectName} when generating for project level changelogs.
*
* E.g. for a project level changelog you could customize the message to something like:
* "entryWhenNoChanges": "There were no code changes for {projectName}"
*/
entryWhenNoChanges?: string | false;
/**
* This is either a workspace path where the changelog markdown file will be created and read from,
* or set to false to disable file creation altogether (e.g. if only using Github releases).
*
* Interpolation of {projectName}, {projectRoot} and {workspaceRoot} is supported.
*
* The defaults are:
* - "{workspaceRoot}/CHANGELOG.md" at the workspace level
* - "{projectRoot}/CHANGELOG.md" at the project level
*/
file?: string | false;
/**
* A path to a valid changelog renderer function used to transform commit messages and other metadata into
* the final changelog (usually in markdown format). Its output can be modified using the optional `renderOptions`.
*
* By default, the renderer is set to "nx/changelog-renderer" which nx provides out of the box.
*/
renderer?: string;
renderOptions?: ChangelogRenderOptions;
}
/**
* **ALPHA**
*/
interface NxReleaseConfiguration {
/**
* @note: When no groups are configured at all (the default), all projects in the workspace are treated as
* if they were in a release group together.
*/
groups?: Record<
string, // group name
{
/**
* Required list of one or more projects to include in the release group. Any single project can
* only be used in a maximum of one release group.
*/
projects: string[] | string;
/**
* Optionally override version configuration for this group.
*/
version?: NxReleaseVersionConfiguration;
/**
* Optionally override project changelog configuration for this group.
*/
changelog?: NxReleaseChangelogConfiguration | false;
/**
* Optionally override the git/release tag pattern to use for this group.
*/
releaseTagPattern?: string;
}
>;
changelog?: {
workspaceChangelog?: NxReleaseChangelogConfiguration | false;
projectChangelogs?: NxReleaseChangelogConfiguration | false;
};
/**
* If no version config is provided, we will assume that @nx/js:release-version
* is the desired generator implementation, allowing for terser config for the common case.
*/
version?: NxReleaseVersionConfiguration;
/**
* Optional override the git/release tag pattern to use. This field is the source of truth
* for changelog generation and release tagging, as well as for conventional-commits parsing.
*
* It supports interpolating the version as {version} and (if releasing independently or forcing
* project level version control system releases) the project name as {projectName} within the string.
*
* The default releaseTagPattern for unified releases is: "v{version}"
* The default releaseTagPattern for releases at the project level is: "{projectName}@v{version}"
*/
releaseTagPattern?: string;
}
/**
* Nx.json configuration
*
* @note: when adding properties here add them to `allowedWorkspaceExtensions` in adapter/compat.ts
*/
export interface NxJsonConfiguration<T = '*' | string[]> {
/**
* Optional (additional) Nx.json configuration file which becomes a base for this one
*/
extends?: string;
/**
* Map of files to projects that implicitly depend on them
* @deprecated use {@link namedInputs} instead. For more information see https://nx.dev/deprecated/global-implicit-dependencies#global-implicit-dependencies
*/
implicitDependencies?: ImplicitDependencyEntry<T>;
/**
* Named inputs targets can refer to reduce duplication
*/
namedInputs?: { [inputName: string]: (string | InputDefinition)[] };
/**
* Dependencies between different target names across all projects
*/
targetDefaults?: TargetDefaults;
/**
* Default options for `nx affected`
*/
affected?: NxAffectedConfig;
/**
* Default value for --base used by `nx affected` and `nx format`.
*/
base?: string;
/**
* Where new apps + libs should be placed
*/
workspaceLayout?: {
libsDir?: string;
appsDir?: string;
};
/**
* Available Task Runners
*/
tasksRunnerOptions?: {
[tasksRunnerName: string]: {
/**
* Path to resolve the runner
*/
runner?: string;
/**
* Default options for the runner
*/
options?: any;
};
};
/**
* List of default values used by generators.
*
* These defaults are global. They are used when no other defaults are configured.
*
* Example:
*
* ```
* {
* "@nx/react": {
* "library": {
* "style": "scss"
* }
* }
* }
* ```
*/
generators?: { [collectionName: string]: { [generatorName: string]: any } };
/**
* Default generator collection. It is used when no collection is provided.
*/
cli?: {
packageManager?: PackageManager;
defaultProjectName?: string;
};
/**
* Plugins for extending the project graph
*/
plugins?: PluginConfiguration[];
/**
* Configuration for Nx Plugins
*/
pluginsConfig?: Record<string, Record<string, unknown>>;
/**
* Default project. When project isn't provided, the default project
* will be used. Convenient for small workspaces with one main application.
*/
defaultProject?: string;
/**
* Configures the Nx installation for a repo. Useful for maintaining a separate
* set of dependencies for Nx + Plugins compared to the base package.json, but also
* useful for workspaces that don't have a root package.json + node_modules.
*/
installation?: NxInstallationConfiguration;
/**
* **ALPHA**: Configuration for `nx release` (versioning and publishing of applications and libraries)
*/
release?: NxReleaseConfiguration;
/**
* If specified Nx will use nx-cloud by default with the given token.
* To use a different runner that accepts an access token, define it in {@link tasksRunnerOptions}
*/
nxCloudAccessToken?: string;
/**
* Specifies the url pointing to an instance of nx cloud. Used for remote
* caching and displaying run links.
*/
nxCloudUrl?: string;
/**
* Specifies the encryption key used to encrypt artifacts data before sending it to nx cloud.
*/
nxCloudEncryptionKey?: string;
/**
* Specifies how many tasks can be run in parallel.
*/
parallel?: number;
/**
* Changes the directory used by Nx to store its cache.
*/
cacheDirectory?: string;
/**
* Set this to false to disable the daemon.
*/
useDaemonProcess?: boolean;
}
export type PluginConfiguration =
| string
| { plugin: string; options?: unknown };
export function readNxJson(root: string = workspaceRoot): NxJsonConfiguration {
const nxJson = join(root, 'nx.json');
if (existsSync(nxJson)) {
const nxJsonConfiguration = readJsonFile<NxJsonConfiguration>(nxJson);
if (nxJsonConfiguration.extends) {
const extendedNxJsonPath = require.resolve(nxJsonConfiguration.extends, {
paths: [dirname(nxJson)],
});
const baseNxJson = readJsonFile<NxJsonConfiguration>(extendedNxJsonPath);
return {
...baseNxJson,
...nxJsonConfiguration,
};
} else {
return nxJsonConfiguration;
}
} else {
try {
return readJsonFile(join(__dirname, '..', '..', 'presets', 'core.json'));
} catch (e) {
return {};
}
}
}
export function hasNxJson(root: string): boolean {
const nxJson = join(root, 'nx.json');
return existsSync(nxJson);
}