nx-lifecycle 1.0.0 → 1.1.1
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/README.md +42 -4
- package/WHY-NX-LIFECYCLE.md +1 -1
- package/dist/bin.d.ts +0 -603
- package/dist/bin.js +3 -13
- package/dist/cli.d.ts +8 -6
- package/dist/cli.js +17 -20
- package/dist/commands/explain-command.d.ts +13 -0
- package/dist/commands/explain-command.js +60 -0
- package/dist/commands/lib/types.d.ts +14 -4
- package/dist/commands/lib/types.js +2 -1
- package/dist/commands/lifecycle-command.d.ts +2 -11
- package/dist/commands/lifecycle-command.js +16 -22
- package/dist/container.d.ts +3 -0
- package/dist/container.js +8 -0
- package/dist/executors/lifecycle/index.d.ts +1 -4
- package/dist/executors/lifecycle/index.js +1 -4
- package/dist/executors/lifecycle/lifecycle.d.ts +8 -9
- package/dist/executors/lifecycle/lifecycle.js +13 -20
- package/dist/lifecycle/explain.d.ts +68 -0
- package/dist/lifecycle/explain.js +157 -0
- package/dist/lifecycle/lifecycle-internal.d.ts +4 -12
- package/dist/lifecycle/lifecycle-internal.js +92 -109
- package/dist/lifecycle/normalizer.d.ts +13 -7
- package/dist/lifecycle/normalizer.js +29 -36
- package/dist/lifecycle/processor.d.ts +1 -3
- package/dist/lifecycle/processor.js +22 -14
- package/dist/lifecycle/schema.d.ts +244 -714
- package/dist/lifecycle/schema.js +3 -2
- package/dist/plugin/index.d.ts +1 -277
- package/dist/plugin/index.js +1 -3
- package/dist/plugin/lifecycle-plugin.d.ts +18 -15
- package/dist/plugin/lifecycle-plugin.js +90 -106
- package/dist/plugin/schema.d.ts +33 -343
- package/dist/plugin/schema.js +0 -2
- package/dist/schemas/configurations.d.ts +5 -6
- package/dist/schemas/depend-on.d.ts +38 -74
- package/dist/schemas/depend-on.js +5 -4
- package/dist/schemas/nx-json.d.ts +38 -223
- package/dist/schemas/nx-json.js +0 -2
- package/dist/schemas/project-json.d.ts +38 -223
- package/dist/schemas/project-json.js +0 -2
- package/dist/schemas/target.d.ts +72 -140
- package/out/nx-executor/schema.json +2 -2
- package/out/schema.json +1 -1
- package/package.json +29 -14
- package/.npmignore +0 -20
- package/dist/commands/index.d.ts +0 -755
- package/dist/commands/index.js +0 -14
- package/dist/commands/lib/dependencies.d.ts +0 -10
- package/dist/commands/lib/dependencies.js +0 -12
- package/dist/executors/lifecycle/container.d.ts +0 -603
- package/dist/executors/lifecycle/container.js +0 -8
- package/dist/lifecycle/dependencies.d.ts +0 -16
- package/dist/lifecycle/dependencies.js +0 -14
- package/dist/lifecycle/index.d.ts +0 -756
- package/dist/lifecycle/index.js +0 -25
- package/dist/plugin/container.d.ts +0 -855
- package/dist/plugin/container.js +0 -13
- package/dist/plugin/dependencies.d.ts +0 -860
- package/dist/plugin/dependencies.js +0 -9
package/dist/lifecycle/schema.js
CHANGED
|
@@ -6,7 +6,7 @@ const checkAndDryRunSchema = objectSchema({
|
|
|
6
6
|
$schema: stringSchema({
|
|
7
7
|
description: 'Path or URL to the JSON schema for this file',
|
|
8
8
|
format: 'uri-reference'
|
|
9
|
-
}).example('https://raw.githubusercontent.com/JacobLey/leyman/refs/heads/main/apps/nx-lifecycle/
|
|
9
|
+
}).example('https://raw.githubusercontent.com/JacobLey/leyman/refs/heads/main/apps/nx-lifecycle/out/schema.json'),
|
|
10
10
|
check: booleanSchema({
|
|
11
11
|
description: 'Fails if references are not already updated, will not overwrite. Defaults to true during CI, false otherwise.'
|
|
12
12
|
}),
|
|
@@ -15,13 +15,14 @@ const checkAndDryRunSchema = objectSchema({
|
|
|
15
15
|
})
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
const hooksSchema = arraySchema(stringSchema());
|
|
18
19
|
export const stagesSchema = objectSchema({
|
|
19
20
|
description: 'Lifecycle stages by name',
|
|
20
21
|
properties: {},
|
|
21
22
|
additionalProperties: objectSchema({
|
|
22
23
|
properties: {
|
|
23
24
|
dependsOn: dependsOnSchema,
|
|
24
|
-
hooks:
|
|
25
|
+
hooks: hooksSchema
|
|
25
26
|
}
|
|
26
27
|
})
|
|
27
28
|
});
|
package/dist/plugin/index.d.ts
CHANGED
|
@@ -3,281 +3,5 @@ export type { LifecyclePluginOptions } from './schema.js';
|
|
|
3
3
|
* Plugin name, as Nx can't attach one to an ES module.
|
|
4
4
|
*/
|
|
5
5
|
export declare const name = "nx-lifecycle";
|
|
6
|
-
export
|
|
7
|
-
stages: Record<string, Partial<{
|
|
8
|
-
dependsOn: (string | (Partial<{
|
|
9
|
-
dependencies: boolean;
|
|
10
|
-
projects: never;
|
|
11
|
-
}> & Partial<{
|
|
12
|
-
target: string;
|
|
13
|
-
params: string;
|
|
14
|
-
}> & Required<Pick<{
|
|
15
|
-
target: string;
|
|
16
|
-
params: string;
|
|
17
|
-
}, "target">>) | (string & Partial<{
|
|
18
|
-
dependencies: boolean;
|
|
19
|
-
projects: never;
|
|
20
|
-
}> & Partial<{
|
|
21
|
-
target: string;
|
|
22
|
-
params: string;
|
|
23
|
-
}> & Required<Pick<{
|
|
24
|
-
target: string;
|
|
25
|
-
params: string;
|
|
26
|
-
}, "target">>) | (Partial<{
|
|
27
|
-
dependencies: boolean;
|
|
28
|
-
projects: never;
|
|
29
|
-
}> & Partial<{
|
|
30
|
-
target: string;
|
|
31
|
-
params: string;
|
|
32
|
-
}> & Required<Pick<{
|
|
33
|
-
target: string;
|
|
34
|
-
params: string;
|
|
35
|
-
}, "target">> & string) | (Partial<{
|
|
36
|
-
dependencies: never;
|
|
37
|
-
projects: string | string[];
|
|
38
|
-
}> & Required<Pick<{
|
|
39
|
-
dependencies: never;
|
|
40
|
-
projects: string | string[];
|
|
41
|
-
}, "projects">> & Partial<{
|
|
42
|
-
target: string;
|
|
43
|
-
params: string;
|
|
44
|
-
}> & Required<Pick<{
|
|
45
|
-
target: string;
|
|
46
|
-
params: string;
|
|
47
|
-
}, "target">>) | (string & Partial<{
|
|
48
|
-
dependencies: never;
|
|
49
|
-
projects: string | string[];
|
|
50
|
-
}> & Required<Pick<{
|
|
51
|
-
dependencies: never;
|
|
52
|
-
projects: string | string[];
|
|
53
|
-
}, "projects">> & Partial<{
|
|
54
|
-
target: string;
|
|
55
|
-
params: string;
|
|
56
|
-
}> & Required<Pick<{
|
|
57
|
-
target: string;
|
|
58
|
-
params: string;
|
|
59
|
-
}, "target">>) | (Partial<{
|
|
60
|
-
dependencies: never;
|
|
61
|
-
projects: string | string[];
|
|
62
|
-
}> & Required<Pick<{
|
|
63
|
-
dependencies: never;
|
|
64
|
-
projects: string | string[];
|
|
65
|
-
}, "projects">> & Partial<{
|
|
66
|
-
target: string;
|
|
67
|
-
params: string;
|
|
68
|
-
}> & Required<Pick<{
|
|
69
|
-
target: string;
|
|
70
|
-
params: string;
|
|
71
|
-
}, "target">> & string))[];
|
|
72
|
-
hooks: string[];
|
|
73
|
-
}>>;
|
|
74
|
-
bindings: Record<string, string>;
|
|
75
|
-
}> & Required<Pick<{
|
|
76
|
-
stages: Record<string, Partial<{
|
|
77
|
-
dependsOn: (string | (Partial<{
|
|
78
|
-
dependencies: boolean;
|
|
79
|
-
projects: never;
|
|
80
|
-
}> & Partial<{
|
|
81
|
-
target: string;
|
|
82
|
-
params: string;
|
|
83
|
-
}> & Required<Pick<{
|
|
84
|
-
target: string;
|
|
85
|
-
params: string;
|
|
86
|
-
}, "target">>) | (string & Partial<{
|
|
87
|
-
dependencies: boolean;
|
|
88
|
-
projects: never;
|
|
89
|
-
}> & Partial<{
|
|
90
|
-
target: string;
|
|
91
|
-
params: string;
|
|
92
|
-
}> & Required<Pick<{
|
|
93
|
-
target: string;
|
|
94
|
-
params: string;
|
|
95
|
-
}, "target">>) | (Partial<{
|
|
96
|
-
dependencies: boolean;
|
|
97
|
-
projects: never;
|
|
98
|
-
}> & Partial<{
|
|
99
|
-
target: string;
|
|
100
|
-
params: string;
|
|
101
|
-
}> & Required<Pick<{
|
|
102
|
-
target: string;
|
|
103
|
-
params: string;
|
|
104
|
-
}, "target">> & string) | (Partial<{
|
|
105
|
-
dependencies: never;
|
|
106
|
-
projects: string | string[];
|
|
107
|
-
}> & Required<Pick<{
|
|
108
|
-
dependencies: never;
|
|
109
|
-
projects: string | string[];
|
|
110
|
-
}, "projects">> & Partial<{
|
|
111
|
-
target: string;
|
|
112
|
-
params: string;
|
|
113
|
-
}> & Required<Pick<{
|
|
114
|
-
target: string;
|
|
115
|
-
params: string;
|
|
116
|
-
}, "target">>) | (string & Partial<{
|
|
117
|
-
dependencies: never;
|
|
118
|
-
projects: string | string[];
|
|
119
|
-
}> & Required<Pick<{
|
|
120
|
-
dependencies: never;
|
|
121
|
-
projects: string | string[];
|
|
122
|
-
}, "projects">> & Partial<{
|
|
123
|
-
target: string;
|
|
124
|
-
params: string;
|
|
125
|
-
}> & Required<Pick<{
|
|
126
|
-
target: string;
|
|
127
|
-
params: string;
|
|
128
|
-
}, "target">>) | (Partial<{
|
|
129
|
-
dependencies: never;
|
|
130
|
-
projects: string | string[];
|
|
131
|
-
}> & Required<Pick<{
|
|
132
|
-
dependencies: never;
|
|
133
|
-
projects: string | string[];
|
|
134
|
-
}, "projects">> & Partial<{
|
|
135
|
-
target: string;
|
|
136
|
-
params: string;
|
|
137
|
-
}> & Required<Pick<{
|
|
138
|
-
target: string;
|
|
139
|
-
params: string;
|
|
140
|
-
}, "target">> & string))[];
|
|
141
|
-
hooks: string[];
|
|
142
|
-
}>>;
|
|
143
|
-
bindings: Record<string, string>;
|
|
144
|
-
}, "bindings" | "stages">>>, createDependencies: (options: (Partial<{
|
|
145
|
-
stages: Record<string, Partial<{
|
|
146
|
-
dependsOn: (string | (Partial<{
|
|
147
|
-
dependencies: boolean;
|
|
148
|
-
projects: never;
|
|
149
|
-
}> & Partial<{
|
|
150
|
-
target: string;
|
|
151
|
-
params: string;
|
|
152
|
-
}> & Required<Pick<{
|
|
153
|
-
target: string;
|
|
154
|
-
params: string;
|
|
155
|
-
}, "target">>) | (string & Partial<{
|
|
156
|
-
dependencies: boolean;
|
|
157
|
-
projects: never;
|
|
158
|
-
}> & Partial<{
|
|
159
|
-
target: string;
|
|
160
|
-
params: string;
|
|
161
|
-
}> & Required<Pick<{
|
|
162
|
-
target: string;
|
|
163
|
-
params: string;
|
|
164
|
-
}, "target">>) | (Partial<{
|
|
165
|
-
dependencies: boolean;
|
|
166
|
-
projects: never;
|
|
167
|
-
}> & Partial<{
|
|
168
|
-
target: string;
|
|
169
|
-
params: string;
|
|
170
|
-
}> & Required<Pick<{
|
|
171
|
-
target: string;
|
|
172
|
-
params: string;
|
|
173
|
-
}, "target">> & string) | (Partial<{
|
|
174
|
-
dependencies: never;
|
|
175
|
-
projects: string | string[];
|
|
176
|
-
}> & Required<Pick<{
|
|
177
|
-
dependencies: never;
|
|
178
|
-
projects: string | string[];
|
|
179
|
-
}, "projects">> & Partial<{
|
|
180
|
-
target: string;
|
|
181
|
-
params: string;
|
|
182
|
-
}> & Required<Pick<{
|
|
183
|
-
target: string;
|
|
184
|
-
params: string;
|
|
185
|
-
}, "target">>) | (string & Partial<{
|
|
186
|
-
dependencies: never;
|
|
187
|
-
projects: string | string[];
|
|
188
|
-
}> & Required<Pick<{
|
|
189
|
-
dependencies: never;
|
|
190
|
-
projects: string | string[];
|
|
191
|
-
}, "projects">> & Partial<{
|
|
192
|
-
target: string;
|
|
193
|
-
params: string;
|
|
194
|
-
}> & Required<Pick<{
|
|
195
|
-
target: string;
|
|
196
|
-
params: string;
|
|
197
|
-
}, "target">>) | (Partial<{
|
|
198
|
-
dependencies: never;
|
|
199
|
-
projects: string | string[];
|
|
200
|
-
}> & Required<Pick<{
|
|
201
|
-
dependencies: never;
|
|
202
|
-
projects: string | string[];
|
|
203
|
-
}, "projects">> & Partial<{
|
|
204
|
-
target: string;
|
|
205
|
-
params: string;
|
|
206
|
-
}> & Required<Pick<{
|
|
207
|
-
target: string;
|
|
208
|
-
params: string;
|
|
209
|
-
}, "target">> & string))[];
|
|
210
|
-
hooks: string[];
|
|
211
|
-
}>>;
|
|
212
|
-
bindings: Record<string, string>;
|
|
213
|
-
}> & Required<Pick<{
|
|
214
|
-
stages: Record<string, Partial<{
|
|
215
|
-
dependsOn: (string | (Partial<{
|
|
216
|
-
dependencies: boolean;
|
|
217
|
-
projects: never;
|
|
218
|
-
}> & Partial<{
|
|
219
|
-
target: string;
|
|
220
|
-
params: string;
|
|
221
|
-
}> & Required<Pick<{
|
|
222
|
-
target: string;
|
|
223
|
-
params: string;
|
|
224
|
-
}, "target">>) | (string & Partial<{
|
|
225
|
-
dependencies: boolean;
|
|
226
|
-
projects: never;
|
|
227
|
-
}> & Partial<{
|
|
228
|
-
target: string;
|
|
229
|
-
params: string;
|
|
230
|
-
}> & Required<Pick<{
|
|
231
|
-
target: string;
|
|
232
|
-
params: string;
|
|
233
|
-
}, "target">>) | (Partial<{
|
|
234
|
-
dependencies: boolean;
|
|
235
|
-
projects: never;
|
|
236
|
-
}> & Partial<{
|
|
237
|
-
target: string;
|
|
238
|
-
params: string;
|
|
239
|
-
}> & Required<Pick<{
|
|
240
|
-
target: string;
|
|
241
|
-
params: string;
|
|
242
|
-
}, "target">> & string) | (Partial<{
|
|
243
|
-
dependencies: never;
|
|
244
|
-
projects: string | string[];
|
|
245
|
-
}> & Required<Pick<{
|
|
246
|
-
dependencies: never;
|
|
247
|
-
projects: string | string[];
|
|
248
|
-
}, "projects">> & Partial<{
|
|
249
|
-
target: string;
|
|
250
|
-
params: string;
|
|
251
|
-
}> & Required<Pick<{
|
|
252
|
-
target: string;
|
|
253
|
-
params: string;
|
|
254
|
-
}, "target">>) | (string & Partial<{
|
|
255
|
-
dependencies: never;
|
|
256
|
-
projects: string | string[];
|
|
257
|
-
}> & Required<Pick<{
|
|
258
|
-
dependencies: never;
|
|
259
|
-
projects: string | string[];
|
|
260
|
-
}, "projects">> & Partial<{
|
|
261
|
-
target: string;
|
|
262
|
-
params: string;
|
|
263
|
-
}> & Required<Pick<{
|
|
264
|
-
target: string;
|
|
265
|
-
params: string;
|
|
266
|
-
}, "target">>) | (Partial<{
|
|
267
|
-
dependencies: never;
|
|
268
|
-
projects: string | string[];
|
|
269
|
-
}> & Required<Pick<{
|
|
270
|
-
dependencies: never;
|
|
271
|
-
projects: string | string[];
|
|
272
|
-
}, "projects">> & Partial<{
|
|
273
|
-
target: string;
|
|
274
|
-
params: string;
|
|
275
|
-
}> & Required<Pick<{
|
|
276
|
-
target: string;
|
|
277
|
-
params: string;
|
|
278
|
-
}, "target">> & string))[];
|
|
279
|
-
hooks: string[];
|
|
280
|
-
}>>;
|
|
281
|
-
bindings: Record<string, string>;
|
|
282
|
-
}, "bindings" | "stages">>) | undefined, context: import("@nx/devkit").CreateDependenciesContext) => [];
|
|
6
|
+
export { createDependencies, createNodes } from './lifecycle-plugin.js';
|
|
283
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/plugin/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { lifecyclePluginContainer } from './container.js';
|
|
2
|
-
import { LifecyclePlugin } from './lifecycle-plugin.js';
|
|
3
1
|
export const name = 'nx-lifecycle';
|
|
4
|
-
export
|
|
2
|
+
export { createDependencies, createNodes } from './lifecycle-plugin.js';
|
|
5
3
|
|
|
6
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type { AssertLifecyclePluginOptions, LifecyclePluginOptions } from './schema.js';
|
|
1
|
+
import type { CreateDependenciesContext, CreateNodes } from '@nx/devkit';
|
|
2
|
+
import type { LifecyclePlan } from '../lifecycle/processor.js';
|
|
3
|
+
import type { LifecyclePluginOptions } from './schema.js';
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `createNodes` adds the anchor, hook and stage targets to every project with a `project.json`,
|
|
9
|
-
* and wires the bound targets declared there.
|
|
5
|
+
* Validates plugin options, with errors Nx prints, and plans the lifecycle from them.
|
|
10
6
|
*
|
|
7
|
+
* @param options - plugin options from `nx.json`
|
|
8
|
+
* @returns lifecycle targets and bindings
|
|
9
|
+
* @throws {Error} when options are invalid, or stages and bindings are inconsistent
|
|
10
|
+
*/
|
|
11
|
+
export declare const planPluginOptions: (options: LifecyclePluginOptions | undefined) => LifecyclePlan;
|
|
12
|
+
export declare const createNodes: CreateNodes<LifecyclePluginOptions>;
|
|
13
|
+
/**
|
|
11
14
|
* Nx applies `nx.json` `targetDefaults` and `project.json` on top of inferred targets,
|
|
12
15
|
* replacing `dependsOn` rather than merging it.
|
|
13
|
-
*
|
|
16
|
+
* This runs on the merged configuration, and fails if a bound target lost its wiring.
|
|
17
|
+
*
|
|
18
|
+
* @param options - plugin options from `nx.json`
|
|
19
|
+
* @param context - merged project configurations
|
|
20
|
+
* @returns no extra dependencies
|
|
21
|
+
* @throws {Error} when options are invalid, or a bound target lost its wiring
|
|
14
22
|
*/
|
|
15
|
-
export declare
|
|
16
|
-
#private;
|
|
17
|
-
readonly createNodes: CreateNodes<LifecyclePluginOptions>;
|
|
18
|
-
readonly createDependencies: (...args: Parameters<CreateDependencies<LifecyclePluginOptions>>) => [];
|
|
19
|
-
constructor(assertOptions: AssertLifecyclePluginOptions, readJsonFile: ReadJsonFile, assertProjectJson: AssertProjectJson, logger: PluginLogger);
|
|
20
|
-
}
|
|
23
|
+
export declare const createDependencies: (options: LifecyclePluginOptions | undefined, context: CreateDependenciesContext) => [];
|
|
21
24
|
//# sourceMappingURL=lifecycle-plugin.d.ts.map
|
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
import Path from 'node:path';
|
|
2
|
-
import { createNodesFromFiles } from '@nx/devkit';
|
|
2
|
+
import { createNodesFromFiles, logger, readJsonFile } from '@nx/devkit';
|
|
3
3
|
import { deepEqual } from 'fast-equals';
|
|
4
|
+
import { assertProjectJson } from '#schemas';
|
|
4
5
|
import { NOOP_EXECUTOR } from '../lifecycle/constants.js';
|
|
5
6
|
import { planLifecycle } from '../lifecycle/processor.js';
|
|
7
|
+
import { assertLifecyclePluginOptions } from './schema.js';
|
|
6
8
|
const describeTarget = ({ kind, name, stage })=>{
|
|
7
9
|
if (kind === 'anchor') {
|
|
8
10
|
return `Start of the ${stage} stage. Waits for the dependencies of the stage`;
|
|
9
11
|
}
|
|
10
|
-
|
|
11
|
-
return `Runs the targets bound to ${name}`;
|
|
12
|
-
}
|
|
13
|
-
return `Runs the ${stage} stage`;
|
|
12
|
+
return kind === 'hook' ? `Runs the targets bound to ${name}` : `Runs the ${stage} stage`;
|
|
14
13
|
};
|
|
15
14
|
const normalizeDependency = (dependency)=>{
|
|
16
15
|
if (typeof dependency !== 'string') {
|
|
17
16
|
return dependency;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
18
|
+
return dependency.startsWith('^') ? {
|
|
19
|
+
target: dependency.slice(1),
|
|
20
|
+
dependencies: true
|
|
21
|
+
} : {
|
|
26
22
|
target: dependency
|
|
27
23
|
};
|
|
28
24
|
};
|
|
29
|
-
const
|
|
25
|
+
const hasDependency = (dependsOn, expected)=>{
|
|
30
26
|
const normalizedExpected = normalizeDependency(expected);
|
|
31
27
|
return (dependsOn ?? []).some((dependency)=>deepEqual(normalizeDependency(dependency), normalizedExpected));
|
|
32
28
|
};
|
|
@@ -34,125 +30,113 @@ const validateProject = ({ targets = {} }, { lifecycleTargets, registeredTargets
|
|
|
34
30
|
const errors = [];
|
|
35
31
|
for (const [targetName, lifecycleTarget] of lifecycleTargets){
|
|
36
32
|
const target = targets[targetName];
|
|
37
|
-
if (target && (target.executor !== NOOP_EXECUTOR ||
|
|
33
|
+
if (target && (target.executor !== NOOP_EXECUTOR || lifecycleTarget.dependsOn.some((dependency)=>!hasDependency(target.dependsOn, dependency)))) {
|
|
38
34
|
errors.push(`${targetName} is inferred by nx-lifecycle, but project.json or nx.json targetDefaults override it. Remove it from there`);
|
|
39
35
|
}
|
|
40
36
|
}
|
|
41
37
|
for (const [targetName, lifecycleTarget] of registeredTargets){
|
|
42
38
|
const target = targets[targetName];
|
|
43
|
-
const hook = targets[lifecycleTarget.name];
|
|
44
39
|
if (!target) {
|
|
45
40
|
continue;
|
|
46
41
|
}
|
|
42
|
+
const hook = targets[lifecycleTarget.name];
|
|
47
43
|
if (!hook) {
|
|
48
44
|
errors.push(`${targetName} is bound to ${lifecycleTarget.name}, but nx-lifecycle only adds lifecycle targets to projects with a project.json. Add one`);
|
|
49
|
-
} else if (!
|
|
45
|
+
} else if (!hasDependency(hook.dependsOn, targetName)) {
|
|
50
46
|
errors.push(`${targetName} is bound to ${lifecycleTarget.name}, but is not declared in project.json. Declare it there so nx-lifecycle can wire it`);
|
|
51
|
-
} else if (!
|
|
47
|
+
} else if (!hasDependency(target.dependsOn, lifecycleTarget.previousHook)) {
|
|
52
48
|
errors.push(`${targetName} is bound to ${lifecycleTarget.name}, so it must depend on ${lifecycleTarget.previousHook}. A dependsOn in project.json or nx.json targetDefaults replaces the inferred one, so add "${lifecycleTarget.previousHook}" to it`);
|
|
53
49
|
}
|
|
54
50
|
}
|
|
55
51
|
return errors;
|
|
56
52
|
};
|
|
57
|
-
export
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.#logger = logger;
|
|
69
|
-
this.createNodes = [
|
|
70
|
-
'**/project.json',
|
|
71
|
-
this.#createNodes.bind(this)
|
|
72
|
-
];
|
|
73
|
-
this.createDependencies = this.#createDependencies.bind(this);
|
|
74
|
-
}
|
|
75
|
-
#plan(options) {
|
|
76
|
-
try {
|
|
77
|
-
this.#assertOptions(options);
|
|
78
|
-
} catch (err) {
|
|
79
|
-
const issues = err.cause;
|
|
80
|
-
throw new Error([
|
|
81
|
-
'Invalid nx-lifecycle plugin options in nx.json:',
|
|
82
|
-
...issues.map(({ instancePath, message })=>`- options${instancePath} ${message}`)
|
|
83
|
-
].join('\n'), {
|
|
84
|
-
cause: err
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
return planLifecycle(options);
|
|
88
|
-
}
|
|
89
|
-
async #createNodes(projectJsonPaths, options, context) {
|
|
90
|
-
const plan = this.#plan(options);
|
|
91
|
-
return createNodesFromFiles((projectJsonPath)=>this.#createProjectNode(projectJsonPath, plan, context), projectJsonPaths, options, context);
|
|
53
|
+
export const planPluginOptions = (options)=>{
|
|
54
|
+
try {
|
|
55
|
+
assertLifecyclePluginOptions(options);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
const issues = err.cause;
|
|
58
|
+
throw new Error([
|
|
59
|
+
'Invalid nx-lifecycle plugin options in nx.json:',
|
|
60
|
+
...issues.map(({ instancePath, message })=>`- options${instancePath} ${message}`)
|
|
61
|
+
].join('\n'), {
|
|
62
|
+
cause: err
|
|
63
|
+
});
|
|
92
64
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
for (const [targetName, lifecycleTarget] of registeredTargets){
|
|
110
|
-
if (targetName in declaredTargets) {
|
|
111
|
-
targets[lifecycleTarget.name].dependsOn.push(targetName);
|
|
112
|
-
targets[targetName] = {
|
|
113
|
-
dependsOn: [
|
|
114
|
-
lifecycleTarget.previousHook
|
|
115
|
-
]
|
|
116
|
-
};
|
|
65
|
+
return planLifecycle(options);
|
|
66
|
+
};
|
|
67
|
+
const createProjectNode = (projectJsonPath, { lifecycleTargets, registeredTargets }, context)=>{
|
|
68
|
+
const projectJson = readJsonFile(Path.join(context.workspaceRoot, projectJsonPath));
|
|
69
|
+
assertProjectJson(projectJson);
|
|
70
|
+
const declaredTargets = projectJson.targets ?? {};
|
|
71
|
+
const targets = {};
|
|
72
|
+
for (const [targetName, lifecycleTarget] of lifecycleTargets){
|
|
73
|
+
targets[targetName] = {
|
|
74
|
+
executor: NOOP_EXECUTOR,
|
|
75
|
+
dependsOn: [
|
|
76
|
+
...lifecycleTarget.dependsOn
|
|
77
|
+
],
|
|
78
|
+
metadata: {
|
|
79
|
+
description: describeTarget(lifecycleTarget)
|
|
117
80
|
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
for (const [targetName, lifecycleTarget] of registeredTargets){
|
|
84
|
+
if (!Object.hasOwn(declaredTargets, targetName)) {
|
|
85
|
+
continue;
|
|
118
86
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
87
|
+
targets[lifecycleTarget.name].dependsOn.push(targetName);
|
|
88
|
+
targets[targetName] = {
|
|
89
|
+
dependsOn: [
|
|
90
|
+
lifecycleTarget.previousHook
|
|
91
|
+
]
|
|
125
92
|
};
|
|
126
93
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
for (const [projectName, project] of Object.entries(context.projects)){
|
|
132
|
-
for (const error of validateProject(project, plan)){
|
|
133
|
-
const projectNames = errors.get(error) ?? [];
|
|
134
|
-
projectNames.push(projectName);
|
|
135
|
-
errors.set(error, projectNames);
|
|
136
|
-
}
|
|
137
|
-
for (const targetName of Object.keys(project.targets ?? {})){
|
|
138
|
-
definedTargets.add(targetName);
|
|
94
|
+
return {
|
|
95
|
+
projects: {
|
|
96
|
+
[Path.dirname(projectJsonPath)]: {
|
|
97
|
+
targets
|
|
139
98
|
}
|
|
140
99
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
const createLifecycleNodes = async (projectJsonPaths, options, context)=>{
|
|
103
|
+
const lifecyclePlan = planPluginOptions(options);
|
|
104
|
+
return createNodesFromFiles((projectJsonPath)=>createProjectNode(projectJsonPath, lifecyclePlan, context), projectJsonPaths, options, context);
|
|
105
|
+
};
|
|
106
|
+
export const createNodes = [
|
|
107
|
+
'**/project.json',
|
|
108
|
+
createLifecycleNodes
|
|
109
|
+
];
|
|
110
|
+
export const createDependencies = (options, context)=>{
|
|
111
|
+
const lifecyclePlan = planPluginOptions(options);
|
|
112
|
+
const errors = new Map();
|
|
113
|
+
const definedTargets = new Set();
|
|
114
|
+
for (const [projectName, project] of Object.entries(context.projects)){
|
|
115
|
+
for (const error of validateProject(project, lifecyclePlan)){
|
|
116
|
+
const projectNames = errors.get(error) ?? [];
|
|
117
|
+
projectNames.push(projectName);
|
|
118
|
+
errors.set(error, projectNames);
|
|
148
119
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
120
|
+
if (project.targets) {
|
|
121
|
+
for (const targetName of Object.keys(project.targets)){
|
|
122
|
+
definedTargets.add(targetName);
|
|
152
123
|
}
|
|
153
124
|
}
|
|
154
|
-
return [];
|
|
155
125
|
}
|
|
156
|
-
|
|
126
|
+
if (errors.size > 0) {
|
|
127
|
+
throw new Error([
|
|
128
|
+
'nx-lifecycle targets are not wired as configured:',
|
|
129
|
+
...[
|
|
130
|
+
...errors
|
|
131
|
+
].map(([error, projectNames])=>`- ${error}\n Projects: ${projectNames.join(', ')}`)
|
|
132
|
+
].join('\n'));
|
|
133
|
+
}
|
|
134
|
+
for (const targetName of lifecyclePlan.registeredTargets.keys()){
|
|
135
|
+
if (!definedTargets.has(targetName)) {
|
|
136
|
+
logger.warn(`Bound target ${targetName} is not defined in any project. Is it a typo?`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return [];
|
|
140
|
+
};
|
|
157
141
|
|
|
158
142
|
//# sourceMappingURL=lifecycle-plugin.js.map
|