nx-lifecycle 0.0.10 → 0.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.
Files changed (51) hide show
  1. package/README.md +83 -31
  2. package/bin.mjs +3 -0
  3. package/dist/bin.d.ts +3 -0
  4. package/dist/bin.js +16 -0
  5. package/dist/cli.d.ts +22 -0
  6. package/dist/cli.js +45 -0
  7. package/dist/commands/index.d.ts +5 -0
  8. package/dist/commands/index.js +14 -0
  9. package/dist/commands/lib/dependencies.d.ts +10 -0
  10. package/dist/commands/lib/dependencies.js +12 -0
  11. package/dist/commands/lib/types.d.ts +9 -0
  12. package/dist/commands/lib/types.js +3 -0
  13. package/dist/commands/lifecycle-command.d.ts +22 -0
  14. package/dist/commands/lifecycle-command.js +54 -0
  15. package/dist/executors/lifecycle/index.cjs +4 -2
  16. package/dist/executors/lifecycle/index.d.cts +54 -4
  17. package/dist/executors/lifecycle/index.d.ts +3 -45
  18. package/dist/executors/lifecycle/index.js +9 -21
  19. package/dist/executors/lifecycle/lifecycle.d.ts +6 -10
  20. package/dist/executors/lifecycle/lifecycle.js +14 -94
  21. package/dist/{executors/lifecycle → lifecycle}/constants.js +2 -1
  22. package/dist/{executors/lifecycle → lifecycle}/depedencies.d.ts +3 -1
  23. package/dist/{executors/lifecycle → lifecycle}/depedencies.js +5 -2
  24. package/dist/lifecycle/index.d.ts +5 -0
  25. package/dist/lifecycle/index.js +25 -0
  26. package/dist/lifecycle/lifecycle-internal.d.ts +22 -0
  27. package/dist/lifecycle/lifecycle-internal.js +102 -0
  28. package/dist/lifecycle/normalizer.d.ts +25 -0
  29. package/dist/lifecycle/normalizer.js +44 -0
  30. package/dist/{executors/lifecycle → lifecycle}/processor.js +2 -1
  31. package/dist/lifecycle/schema.d.ts +337 -0
  32. package/dist/lifecycle/schema.js +54 -0
  33. package/dist/lifecycle/types.d.ts +9 -0
  34. package/dist/lifecycle/types.js +3 -0
  35. package/dist/schemas/configurations.js +2 -1
  36. package/dist/schemas/depend-on.js +2 -1
  37. package/dist/schemas/empty.js +2 -1
  38. package/dist/schemas/index.js +2 -1
  39. package/dist/schemas/lib/ajv.js +6 -2
  40. package/dist/schemas/nx-json.js +2 -1
  41. package/dist/schemas/project-json.js +2 -1
  42. package/dist/schemas/target.js +2 -1
  43. package/executors.json +1 -1
  44. package/package.json +31 -23
  45. package/dist/executors/lifecycle/normalizer.d.ts +0 -23
  46. package/dist/executors/lifecycle/normalizer.js +0 -21
  47. package/dist/executors/lifecycle/types.d.ts +0 -3
  48. package/dist/executors/lifecycle/types.js +0 -2
  49. package/src/executors/lifecycle/schema.json +0 -98
  50. /package/dist/{executors/lifecycle → lifecycle}/constants.d.ts +0 -0
  51. /package/dist/{executors/lifecycle → lifecycle}/processor.d.ts +0 -0
@@ -1,102 +1,22 @@
1
- import { deepEqual } from 'fast-equals';
2
1
  export class Lifecycle {
3
- #normalizer;
4
- #readFile;
5
- #writeFile;
6
- #formatFiles;
7
- #processNxAndProjectJsons;
8
- #isNxJson;
9
- #isProjectJson;
10
- #logger;
11
- constructor(normalizer, readFile, writeFile, formatFiles, processNxAndProjectJsons, isNxJson, isProjectJson, logger){
12
- this.#normalizer = normalizer;
13
- this.#readFile = readFile;
14
- this.#writeFile = writeFile;
15
- this.#formatFiles = formatFiles;
16
- this.#processNxAndProjectJsons = processNxAndProjectJsons;
17
- this.#isNxJson = isNxJson;
18
- this.#isProjectJson = isProjectJson;
19
- this.#logger = logger;
2
+ #lifecycleInternal;
3
+ lifecycle;
4
+ constructor(lifecycleInternal){
5
+ this.#lifecycleInternal = lifecycleInternal;
6
+ this.lifecycle = this.#lifecycle.bind(this);
20
7
  }
21
- async lifecycle(options, context) {
22
- const normalized = this.#normalizer.normalizeOptions(options, context);
23
- const { nxJson, projectJsons } = await this.#loadJsonConfigs(normalized);
24
- const { processedNxJson, processedProjectJsons } = this.#processNxAndProjectJsons({
25
- nxJson: nxJson.data,
26
- projectJsons: projectJsons.map(({ data })=>data),
27
- options: normalized
28
- });
29
- await this.#saveJsonConfigs({
30
- jsons: [
31
- {
32
- ...nxJson,
33
- processed: processedNxJson
34
- },
35
- ...projectJsons.map((projectJson, i)=>({
36
- ...projectJson,
37
- processed: processedProjectJsons[i]
38
- }))
39
- ],
40
- options: normalized
8
+ async #lifecycle(options, context) {
9
+ await this.#lifecycleInternal(options, {
10
+ root: context.root,
11
+ projects: Object.values(context.projectsConfigurations.projects).map((projectConfig)=>({
12
+ name: projectConfig.name,
13
+ root: projectConfig.root
14
+ }))
41
15
  });
42
16
  return {
43
17
  success: true
44
18
  };
45
19
  }
46
- async #loadJsonConfigs({ nxJsonPath, packageJsonPaths }) {
47
- const [rawNxJson, ...rawProjectJsons] = await Promise.all([
48
- this.#readFile(nxJsonPath, 'utf8'),
49
- ...packageJsonPaths.map(async ({ name, path })=>({
50
- name,
51
- path,
52
- rawData: await this.#readFile(path, 'utf8')
53
- }))
54
- ]);
55
- const parsedNxJson = JSON.parse(rawNxJson);
56
- if (!this.#isNxJson(parsedNxJson)) {
57
- throw new Error(`Failed to parse nx.json: ${JSON.stringify(this.#isNxJson.errors, null, 2)}`);
58
- }
59
- return {
60
- nxJson: {
61
- name: 'nx.json',
62
- path: nxJsonPath,
63
- data: parsedNxJson
64
- },
65
- projectJsons: rawProjectJsons.map(({ name, path, rawData })=>{
66
- const data = JSON.parse(rawData);
67
- if (!this.#isProjectJson(data)) {
68
- throw new Error(`Failed to parse ${path}: ${JSON.stringify(this.#isProjectJson.errors, null, 2)}`);
69
- }
70
- return {
71
- name,
72
- path,
73
- data
74
- };
75
- })
76
- };
77
- }
78
- async #saveJsonConfigs({ jsons, options }) {
79
- const filesToUpdate = [];
80
- for (const { path, data, processed } of jsons){
81
- if (deepEqual(data, processed)) {
82
- continue;
83
- }
84
- if (options.check) {
85
- throw new Error(`File ${path} is not up to date`);
86
- }
87
- filesToUpdate.push({
88
- path,
89
- processed
90
- });
91
- }
92
- await Promise.all(filesToUpdate.map(async ({ path, processed })=>{
93
- this.#logger.info(`Updating ${path}`);
94
- if (options.dryRun) {
95
- return;
96
- }
97
- return this.#writeFile(path, JSON.stringify(processed), 'utf8');
98
- }));
99
- await this.#formatFiles(filesToUpdate.map((file)=>file.path));
100
- }
101
20
  }
102
- //# sourceMappingURL=lifecycle.js.map
21
+
22
+ //# sourceMappingURL=lifecycle.js.map
@@ -1,2 +1,3 @@
1
1
  export const NOOP_EXECUTOR = 'nx:noop';
2
- //# sourceMappingURL=constants.js.map
2
+
3
+ //# sourceMappingURL=constants.js.map
@@ -1,5 +1,6 @@
1
1
  import { readFile, writeFile } from 'node:fs/promises';
2
2
  import { type FilesFormatter } from 'format-file';
3
+ import { type ParseCwd } from 'parse-cwd';
3
4
  export interface Logger {
4
5
  info: (...args: unknown[]) => void;
5
6
  error: (...args: unknown[]) => void;
@@ -9,5 +10,6 @@ export declare const writeFileIdentifier: import("haywire").HaywireId<typeof wri
9
10
  export declare const formatFileIdentifier: import("haywire").HaywireId<FilesFormatter, null, null, false, false, false, false>;
10
11
  export declare const isCiIdentifier: import("haywire").HaywireId<boolean, null, "isCI", false, false, false, false>;
11
12
  export declare const loggerIdentifier: import("haywire").HaywireId<Logger, null, null, false, false, false, false>;
12
- export declare const dependenciesModule: import("haywire").Module<[import("haywire").NonExtendable<typeof readFile | null | undefined, null, null>] | [import("haywire").NonExtendable<typeof readFile | null, null, null>] | [import("haywire").NonExtendable<typeof readFile | undefined, null, null>] | [import("haywire").NonExtendable<typeof readFile, null, null>] | [import("haywire").NonExtendable<typeof writeFile | null | undefined, null, null>] | [import("haywire").NonExtendable<typeof writeFile | null, null, null>] | [import("haywire").NonExtendable<typeof writeFile | undefined, null, null>] | [import("haywire").NonExtendable<typeof writeFile, null, null>] | [import("haywire").NonExtendable<FilesFormatter | null | undefined, null, null>] | [import("haywire").NonExtendable<FilesFormatter | null, null, null>] | [import("haywire").NonExtendable<FilesFormatter | undefined, null, null>] | [import("haywire").NonExtendable<FilesFormatter, null, null>] | [import("haywire").NonExtendable<boolean | null | undefined, null, "isCI">] | [import("haywire").NonExtendable<boolean | null, null, "isCI">] | [import("haywire").NonExtendable<boolean | undefined, null, "isCI">] | [import("haywire").NonExtendable<boolean, null, "isCI">] | [import("haywire").NonExtendable<Logger | null | undefined, null, null>] | [import("haywire").NonExtendable<Logger | null, null, null>] | [import("haywire").NonExtendable<Logger | undefined, null, null>] | [import("haywire").NonExtendable<Logger, null, null>], never, false>;
13
+ export declare const parseCwdId: import("haywire").HaywireId<ParseCwd, null, null, false, false, false, false>;
14
+ export declare const dependenciesModule: import("haywire").Module<[import("haywire").NonExtendable<typeof readFile | null | undefined, null, null>] | [import("haywire").NonExtendable<typeof readFile | null, null, null>] | [import("haywire").NonExtendable<typeof readFile | undefined, null, null>] | [import("haywire").NonExtendable<typeof readFile, null, null>] | [import("haywire").NonExtendable<typeof writeFile | null | undefined, null, null>] | [import("haywire").NonExtendable<typeof writeFile | null, null, null>] | [import("haywire").NonExtendable<typeof writeFile | undefined, null, null>] | [import("haywire").NonExtendable<typeof writeFile, null, null>] | [import("haywire").NonExtendable<FilesFormatter | null | undefined, null, null>] | [import("haywire").NonExtendable<FilesFormatter | null, null, null>] | [import("haywire").NonExtendable<FilesFormatter | undefined, null, null>] | [import("haywire").NonExtendable<FilesFormatter, null, null>] | [import("haywire").NonExtendable<boolean | null | undefined, null, "isCI">] | [import("haywire").NonExtendable<boolean | null, null, "isCI">] | [import("haywire").NonExtendable<boolean | undefined, null, "isCI">] | [import("haywire").NonExtendable<boolean, null, "isCI">] | [import("haywire").NonExtendable<Logger | null | undefined, null, null>] | [import("haywire").NonExtendable<Logger | null, null, null>] | [import("haywire").NonExtendable<Logger | undefined, null, null>] | [import("haywire").NonExtendable<Logger, null, null>] | [import("haywire").NonExtendable<ParseCwd | null | undefined, null, null>] | [import("haywire").NonExtendable<ParseCwd | null, null, null>] | [import("haywire").NonExtendable<ParseCwd | undefined, null, null>] | [import("haywire").NonExtendable<ParseCwd, null, null>], never, false>;
13
15
  //# sourceMappingURL=depedencies.d.ts.map
@@ -2,10 +2,13 @@ import { readFile, writeFile } from 'node:fs/promises';
2
2
  import { isCI } from 'ci-info';
3
3
  import { formatFiles } from 'format-file';
4
4
  import { bind, createModule, identifier } from 'haywire';
5
+ import { parseCwd } from 'parse-cwd';
5
6
  export const readFileIdentifier = identifier();
6
7
  export const writeFileIdentifier = identifier();
7
8
  export const formatFileIdentifier = identifier();
8
9
  export const isCiIdentifier = identifier().named('isCI');
9
10
  export const loggerIdentifier = identifier();
10
- export const dependenciesModule = createModule(bind(readFileIdentifier).withInstance(readFile)).addBinding(bind(writeFileIdentifier).withInstance(writeFile)).addBinding(bind(formatFileIdentifier).withInstance(formatFiles)).addBinding(bind(isCiIdentifier).withInstance(isCI)).addBinding(bind(loggerIdentifier).withInstance(console));
11
- //# sourceMappingURL=depedencies.js.map
11
+ export const parseCwdId = identifier();
12
+ export const dependenciesModule = createModule(bind(readFileIdentifier).withInstance(readFile)).addBinding(bind(writeFileIdentifier).withInstance(writeFile)).addBinding(bind(formatFileIdentifier).withInstance(formatFiles)).addBinding(bind(isCiIdentifier).withInstance(isCI)).addBinding(bind(loggerIdentifier).withInstance(console)).addBinding(bind(parseCwdId).withInstance(parseCwd));
13
+
14
+ //# sourceMappingURL=depedencies.js.map
@@ -0,0 +1,5 @@
1
+ import { type ILifecycleInternal, LifecycleInternal } from './lifecycle-internal.js';
2
+ import { Normalizer } from './normalizer.js';
3
+ export declare const lifecycleInternalId: import("haywire").HaywireId<ILifecycleInternal, null, null, false, false, false, false>;
4
+ export declare const lifecycleInternalModule: import("haywire").Module<[import("haywire").NonExtendable<typeof import("fs/promises").readFile | null | undefined, null, null>] | [import("haywire").NonExtendable<typeof import("fs/promises").readFile | null, null, null>] | [import("haywire").NonExtendable<typeof import("fs/promises").readFile | undefined, null, null>] | [import("haywire").NonExtendable<typeof import("fs/promises").readFile, null, null>] | [import("haywire").NonExtendable<typeof import("fs/promises").writeFile | null | undefined, null, null>] | [import("haywire").NonExtendable<typeof import("fs/promises").writeFile | null, null, null>] | [import("haywire").NonExtendable<typeof import("fs/promises").writeFile | undefined, null, null>] | [import("haywire").NonExtendable<typeof import("fs/promises").writeFile, null, null>] | [import("haywire").NonExtendable<import("format-file").FilesFormatter | null | undefined, null, null>] | [import("haywire").NonExtendable<import("format-file").FilesFormatter | null, null, null>] | [import("haywire").NonExtendable<import("format-file").FilesFormatter | undefined, null, null>] | [import("haywire").NonExtendable<import("format-file").FilesFormatter, null, null>] | [import("haywire").NonExtendable<boolean | null | undefined, null, "isCI">] | [import("haywire").NonExtendable<boolean | null, null, "isCI">] | [import("haywire").NonExtendable<boolean | undefined, null, "isCI">] | [import("haywire").NonExtendable<boolean, null, "isCI">] | [import("haywire").NonExtendable<import("./depedencies.js").Logger | null | undefined, null, null>] | [import("haywire").NonExtendable<import("./depedencies.js").Logger | null, null, null>] | [import("haywire").NonExtendable<import("./depedencies.js").Logger | undefined, null, null>] | [import("haywire").NonExtendable<import("./depedencies.js").Logger, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd | null | undefined, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd | null, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd | undefined, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd, null, null>] | [import("haywire").NonExtendable<ILifecycleInternal | null | undefined, null, null>] | [import("haywire").NonExtendable<ILifecycleInternal | null, null, null>] | [import("haywire").NonExtendable<ILifecycleInternal | undefined, null, null>] | [import("haywire").NonExtendable<ILifecycleInternal, null, null>] | [import("haywire").NonExtendable<LifecycleInternal, typeof LifecycleInternal, null>] | [import("haywire").NonExtendable<LifecycleInternal | null | undefined, typeof LifecycleInternal, null>] | [import("haywire").NonExtendable<LifecycleInternal | null, typeof LifecycleInternal, null>] | [import("haywire").NonExtendable<LifecycleInternal | undefined, typeof LifecycleInternal, null>] | [import("haywire").NonExtendable<Normalizer, typeof Normalizer, null>] | [import("haywire").NonExtendable<import("./processor.js").NxAndProjectJsonProcessor, null, null>] | [import("haywire").NonExtendable<import("#schemas").IsNxJson, null, "nxJson">] | [import("haywire").NonExtendable<import("#schemas").IsProjectJson, null, "projectJson">] | [import("haywire").NonExtendable<Normalizer | null | undefined, typeof Normalizer, null>] | [import("haywire").NonExtendable<Normalizer | null, typeof Normalizer, null>] | [import("haywire").NonExtendable<Normalizer | undefined, typeof Normalizer, null>] | [import("haywire").NonExtendable<import("./processor.js").NxAndProjectJsonProcessor | null | undefined, null, null>] | [import("haywire").NonExtendable<import("./processor.js").NxAndProjectJsonProcessor | null, null, null>] | [import("haywire").NonExtendable<import("./processor.js").NxAndProjectJsonProcessor | undefined, null, null>] | [import("haywire").NonExtendable<import("#schemas").IsNxJson | null | undefined, null, "nxJson">] | [import("haywire").NonExtendable<import("#schemas").IsNxJson | null, null, "nxJson">] | [import("haywire").NonExtendable<import("#schemas").IsNxJson | undefined, null, "nxJson">] | [import("haywire").NonExtendable<import("#schemas").IsProjectJson | null | undefined, null, "projectJson">] | [import("haywire").NonExtendable<import("#schemas").IsProjectJson | null, null, "projectJson">] | [import("haywire").NonExtendable<import("#schemas").IsProjectJson | undefined, null, "projectJson">], [import("haywire").NonExtendable<typeof import("fs/promises").readFile, null, null>] | [import("haywire").NonExtendable<typeof import("fs/promises").writeFile, null, null>] | [import("haywire").NonExtendable<import("format-file").FilesFormatter, null, null>] | [import("haywire").NonExtendable<boolean, null, "isCI">] | [import("haywire").NonExtendable<import("./depedencies.js").Logger, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd, null, null>] | [import("haywire").NonExtendable<LifecycleInternal, typeof LifecycleInternal, null>] | [import("haywire").NonExtendable<Normalizer, typeof Normalizer, null>] | [import("haywire").NonExtendable<import("./processor.js").NxAndProjectJsonProcessor, null, null>] | [import("haywire").NonExtendable<import("#schemas").IsNxJson, null, "nxJson">] | [import("haywire").NonExtendable<import("#schemas").IsProjectJson, null, "projectJson">], false>;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { bind, identifier } from 'haywire';
2
+ import { isNxJson, isNxJsonIdentifier, isProjectJson, isProjectJsonIdentifier } from '#schemas';
3
+ import { dependenciesModule, formatFileIdentifier, isCiIdentifier, loggerIdentifier, parseCwdId, readFileIdentifier, writeFileIdentifier } from './depedencies.js';
4
+ import { LifecycleInternal } from './lifecycle-internal.js';
5
+ import { Normalizer } from './normalizer.js';
6
+ import { nxAndProjectJsonProcessorIdentifier, processNxAndProjectJsons } from './processor.js';
7
+ export const lifecycleInternalId = identifier();
8
+ export const lifecycleInternalModule = dependenciesModule.addBinding(bind(lifecycleInternalId).withDependencies([
9
+ LifecycleInternal
10
+ ]).withProvider((l)=>l.lifecycleInternal)).addBinding(bind(LifecycleInternal).withConstructorProvider().withDependencies([
11
+ Normalizer,
12
+ readFileIdentifier,
13
+ writeFileIdentifier,
14
+ formatFileIdentifier,
15
+ nxAndProjectJsonProcessorIdentifier,
16
+ isNxJsonIdentifier,
17
+ isProjectJsonIdentifier,
18
+ loggerIdentifier
19
+ ])).addBinding(bind(Normalizer).withDependencies([
20
+ isCiIdentifier.supplier(),
21
+ parseCwdId,
22
+ readFileIdentifier
23
+ ]).withConstructorProvider()).addBinding(bind(nxAndProjectJsonProcessorIdentifier).withInstance(processNxAndProjectJsons)).addBinding(bind(isNxJsonIdentifier).withInstance(isNxJson)).addBinding(bind(isProjectJsonIdentifier).withInstance(isProjectJson));
24
+
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,22 @@
1
+ import type { readFile as ReadFile, writeFile as WriteFile } from 'node:fs/promises';
2
+ import type { FilesFormatter } from 'format-file';
3
+ import type { IsNxJson, IsProjectJson } from '#schemas';
4
+ import type { Logger } from './depedencies.js';
5
+ import type { Normalizer } from './normalizer.js';
6
+ import type { NxAndProjectJsonProcessor } from './processor.js';
7
+ import type { LifecycleOptionsOrConfig } from './schema.js';
8
+ import type { NxContext } from './types.js';
9
+ export type ILifecycleInternal = (options: LifecycleOptionsOrConfig, context: NxContext) => Promise<void>;
10
+ /**
11
+ * Main logic for lifecycle file management.
12
+ *
13
+ * Loads the `nx.json` + `project.json`s for all projects,
14
+ * calculates the new targets and dependencies,
15
+ * and re-writes files as appropriate.
16
+ */
17
+ export declare class LifecycleInternal {
18
+ #private;
19
+ readonly lifecycleInternal: ILifecycleInternal;
20
+ constructor(normalizer: Normalizer, readFile: typeof ReadFile, writeFile: typeof WriteFile, formatFiles: FilesFormatter, processNxAndProjectJsons: NxAndProjectJsonProcessor, isNxJson: IsNxJson, isProjectJson: IsProjectJson, logger: Logger);
21
+ }
22
+ //# sourceMappingURL=lifecycle-internal.d.ts.map
@@ -0,0 +1,102 @@
1
+ import { deepEqual } from 'fast-equals';
2
+ export class LifecycleInternal {
3
+ #normalizer;
4
+ #readFile;
5
+ #writeFile;
6
+ #formatFiles;
7
+ #processNxAndProjectJsons;
8
+ #isNxJson;
9
+ #isProjectJson;
10
+ #logger;
11
+ lifecycleInternal;
12
+ constructor(normalizer, readFile, writeFile, formatFiles, processNxAndProjectJsons, isNxJson, isProjectJson, logger){
13
+ this.#normalizer = normalizer;
14
+ this.#readFile = readFile;
15
+ this.#writeFile = writeFile;
16
+ this.#formatFiles = formatFiles;
17
+ this.#processNxAndProjectJsons = processNxAndProjectJsons;
18
+ this.#isNxJson = isNxJson;
19
+ this.#isProjectJson = isProjectJson;
20
+ this.#logger = logger;
21
+ this.lifecycleInternal = this.#lifecycleInternal.bind(this);
22
+ }
23
+ async #lifecycleInternal(options, context) {
24
+ const normalized = await this.#normalizer.normalizeOptions(options, context);
25
+ const { nxJson, projectJsons } = await this.#loadJsonConfigs(normalized);
26
+ const { processedNxJson, processedProjectJsons } = this.#processNxAndProjectJsons({
27
+ nxJson: nxJson.data,
28
+ projectJsons: projectJsons.map(({ data })=>data),
29
+ options: normalized
30
+ });
31
+ await this.#saveJsonConfigs({
32
+ jsons: [
33
+ {
34
+ ...nxJson,
35
+ processed: processedNxJson
36
+ },
37
+ ...projectJsons.map((projectJson, i)=>({
38
+ ...projectJson,
39
+ processed: processedProjectJsons[i]
40
+ }))
41
+ ],
42
+ options: normalized
43
+ });
44
+ }
45
+ async #loadJsonConfigs({ nxJsonPath, packageJsonPaths }) {
46
+ const [rawNxJson, ...rawProjectJsons] = await Promise.all([
47
+ this.#readFile(nxJsonPath, 'utf8'),
48
+ ...packageJsonPaths.map(async ({ name, path })=>({
49
+ name,
50
+ path,
51
+ rawData: await this.#readFile(path, 'utf8')
52
+ }))
53
+ ]);
54
+ const parsedNxJson = JSON.parse(rawNxJson);
55
+ if (!this.#isNxJson(parsedNxJson)) {
56
+ throw new Error(`Failed to parse nx.json: ${JSON.stringify(this.#isNxJson.errors, null, 2)}`);
57
+ }
58
+ return {
59
+ nxJson: {
60
+ name: 'nx.json',
61
+ path: nxJsonPath,
62
+ data: parsedNxJson
63
+ },
64
+ projectJsons: rawProjectJsons.map(({ name, path, rawData })=>{
65
+ const data = JSON.parse(rawData);
66
+ if (!this.#isProjectJson(data)) {
67
+ throw new Error(`Failed to parse ${path}: ${JSON.stringify(this.#isProjectJson.errors, null, 2)}`);
68
+ }
69
+ return {
70
+ name,
71
+ path,
72
+ data
73
+ };
74
+ })
75
+ };
76
+ }
77
+ async #saveJsonConfigs({ jsons, options }) {
78
+ const filesToUpdate = [];
79
+ for (const { path, data, processed } of jsons){
80
+ if (deepEqual(data, processed)) {
81
+ continue;
82
+ }
83
+ if (options.check) {
84
+ throw new Error(`File ${path} is not up to date`);
85
+ }
86
+ filesToUpdate.push({
87
+ path,
88
+ processed
89
+ });
90
+ }
91
+ await Promise.all(filesToUpdate.map(async ({ path, processed })=>{
92
+ this.#logger.info(`Updating ${path}`);
93
+ if (options.dryRun) {
94
+ return;
95
+ }
96
+ return this.#writeFile(path, JSON.stringify(processed), 'utf8');
97
+ }));
98
+ await this.#formatFiles(filesToUpdate.map((file)=>file.path));
99
+ }
100
+ }
101
+
102
+ //# sourceMappingURL=lifecycle-internal.js.map
@@ -0,0 +1,25 @@
1
+ import type { readFile as ReadFile } from 'node:fs/promises';
2
+ import type { ParseCwd } from 'parse-cwd';
3
+ import { type LifecycleOptions, type LifecycleOptionsOrConfig } from './schema.js';
4
+ import type { NxContext } from './types.js';
5
+ export interface NormalizedOptions {
6
+ check: boolean;
7
+ dryRun: boolean;
8
+ nxJsonPath: string;
9
+ packageJsonPaths: {
10
+ name: string;
11
+ path: string;
12
+ }[];
13
+ stages: LifecycleOptions['stages'];
14
+ bindings: LifecycleOptions['bindings'];
15
+ }
16
+ /**
17
+ * Standardizes the options passed to this executor,
18
+ * based on input, reasonable defaults, and project state.
19
+ */
20
+ export declare class Normalizer {
21
+ #private;
22
+ constructor(isCI: () => boolean, parseCwd: ParseCwd, readFile: typeof ReadFile);
23
+ normalizeOptions(options: LifecycleOptionsOrConfig, context: NxContext): Promise<NormalizedOptions>;
24
+ }
25
+ //# sourceMappingURL=normalizer.d.ts.map
@@ -0,0 +1,44 @@
1
+ import Path from 'node:path';
2
+ import { isLifecycleOptions } from './schema.js';
3
+ export class Normalizer {
4
+ #isCI;
5
+ #parseCwd;
6
+ #readFile;
7
+ constructor(isCI, parseCwd, readFile){
8
+ this.#isCI = isCI;
9
+ this.#parseCwd = parseCwd;
10
+ this.#readFile = readFile;
11
+ }
12
+ async normalizeOptions(options, context) {
13
+ const loadedOptions = await this.#loadOptions(options);
14
+ return {
15
+ check: loadedOptions.check ?? this.#isCI(),
16
+ dryRun: loadedOptions.dryRun ?? false,
17
+ nxJsonPath: Path.join(context.root, 'nx.json'),
18
+ packageJsonPaths: context.projects.map((project)=>({
19
+ name: project.name,
20
+ path: Path.join(context.root, project.root, 'project.json')
21
+ })),
22
+ stages: loadedOptions.stages,
23
+ bindings: loadedOptions.bindings
24
+ };
25
+ }
26
+ async #loadOptions(options) {
27
+ if ('stages' in options) {
28
+ return options;
29
+ }
30
+ const cwd = await this.#parseCwd(options.cwd);
31
+ const configFile = Path.join(cwd, options.configFile ?? './lifecycle.json');
32
+ const loadedConfig = await this.#readFile(configFile, 'utf8');
33
+ const parsedConfig = JSON.parse(loadedConfig);
34
+ if (isLifecycleOptions(parsedConfig)) {
35
+ return {
36
+ ...parsedConfig,
37
+ ...options
38
+ };
39
+ }
40
+ throw new Error(`Invalid config loaded from ${configFile}`);
41
+ }
42
+ }
43
+
44
+ //# sourceMappingURL=normalizer.js.map
@@ -236,4 +236,5 @@ export const processNxAndProjectJsons = ({ nxJson, projectJsons, options })=>{
236
236
  }
237
237
  return response;
238
238
  };
239
- //# sourceMappingURL=processor.js.map
239
+
240
+ //# sourceMappingURL=processor.js.map