@smoothbricks/cli 0.1.0 → 0.2.0

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 (148) hide show
  1. package/README.md +338 -88
  2. package/dist/cli.d.ts.map +1 -1
  3. package/dist/cli.js +136 -22
  4. package/dist/devenv/index.d.ts +10 -0
  5. package/dist/devenv/index.d.ts.map +1 -0
  6. package/dist/devenv/index.js +27 -0
  7. package/dist/lib/cli-package.d.ts +4 -0
  8. package/dist/lib/cli-package.d.ts.map +1 -0
  9. package/dist/lib/cli-package.js +15 -0
  10. package/dist/lib/devenv.d.ts +6 -0
  11. package/dist/lib/devenv.d.ts.map +1 -0
  12. package/dist/lib/devenv.js +82 -0
  13. package/dist/lib/run.d.ts +5 -0
  14. package/dist/lib/run.d.ts.map +1 -1
  15. package/dist/lib/run.js +13 -0
  16. package/dist/lib/workspace.d.ts +20 -1
  17. package/dist/lib/workspace.d.ts.map +1 -1
  18. package/dist/lib/workspace.js +87 -7
  19. package/dist/monorepo/commit-msg.d.ts +8 -1
  20. package/dist/monorepo/commit-msg.d.ts.map +1 -1
  21. package/dist/monorepo/commit-msg.js +85 -7
  22. package/dist/monorepo/index.d.ts +24 -2
  23. package/dist/monorepo/index.d.ts.map +1 -1
  24. package/dist/monorepo/index.js +136 -15
  25. package/dist/monorepo/lockfile.d.ts +5 -1
  26. package/dist/monorepo/lockfile.d.ts.map +1 -1
  27. package/dist/monorepo/lockfile.js +45 -5
  28. package/dist/monorepo/managed-files.d.ts +1 -1
  29. package/dist/monorepo/managed-files.d.ts.map +1 -1
  30. package/dist/monorepo/managed-files.js +28 -11
  31. package/dist/monorepo/nx-sync.d.ts +2 -1
  32. package/dist/monorepo/nx-sync.d.ts.map +1 -1
  33. package/dist/monorepo/nx-sync.js +8 -2
  34. package/dist/monorepo/package-hygiene.d.ts +6 -2
  35. package/dist/monorepo/package-hygiene.d.ts.map +1 -1
  36. package/dist/monorepo/package-hygiene.js +12 -4
  37. package/dist/monorepo/package-policy.d.ts +25 -2
  38. package/dist/monorepo/package-policy.d.ts.map +1 -1
  39. package/dist/monorepo/package-policy.js +1289 -27
  40. package/dist/monorepo/packed-manifest.d.ts +4 -0
  41. package/dist/monorepo/packed-manifest.d.ts.map +1 -0
  42. package/dist/monorepo/packed-manifest.js +51 -0
  43. package/dist/monorepo/packed-package.d.ts +3 -0
  44. package/dist/monorepo/packed-package.d.ts.map +1 -1
  45. package/dist/monorepo/packed-package.js +69 -31
  46. package/dist/monorepo/packs/index.d.ts +20 -1
  47. package/dist/monorepo/packs/index.d.ts.map +1 -1
  48. package/dist/monorepo/packs/index.js +240 -18
  49. package/dist/monorepo/publish-workflow.d.ts +82 -0
  50. package/dist/monorepo/publish-workflow.d.ts.map +1 -0
  51. package/dist/monorepo/publish-workflow.js +336 -0
  52. package/dist/monorepo/tool-validation.d.ts +22 -0
  53. package/dist/monorepo/tool-validation.d.ts.map +1 -0
  54. package/dist/monorepo/tool-validation.js +399 -0
  55. package/dist/nx/index.d.ts +24 -0
  56. package/dist/nx/index.d.ts.map +1 -0
  57. package/dist/nx/index.js +94 -0
  58. package/dist/nx-version-actions.cjs +25 -0
  59. package/dist/nx-version-actions.d.cts +6 -0
  60. package/dist/nx-version-actions.d.cts.map +1 -0
  61. package/dist/release/bootstrap-npm-packages.d.ts +19 -0
  62. package/dist/release/bootstrap-npm-packages.d.ts.map +1 -0
  63. package/dist/release/bootstrap-npm-packages.js +58 -0
  64. package/dist/release/candidates.d.ts +11 -0
  65. package/dist/release/candidates.d.ts.map +1 -0
  66. package/dist/release/candidates.js +181 -0
  67. package/dist/release/core.d.ts +51 -0
  68. package/dist/release/core.d.ts.map +1 -0
  69. package/dist/release/core.js +97 -0
  70. package/dist/release/github-release.d.ts +46 -0
  71. package/dist/release/github-release.d.ts.map +1 -0
  72. package/dist/release/github-release.js +97 -0
  73. package/dist/release/index.d.ts +39 -5
  74. package/dist/release/index.d.ts.map +1 -1
  75. package/dist/release/index.js +763 -130
  76. package/dist/release/npm-auth.d.ts +16 -0
  77. package/dist/release/npm-auth.d.ts.map +1 -0
  78. package/dist/release/npm-auth.js +39 -0
  79. package/dist/release/orchestration.d.ts +49 -0
  80. package/dist/release/orchestration.d.ts.map +1 -0
  81. package/dist/release/orchestration.js +113 -0
  82. package/dist/release/publish-plan.d.ts +17 -0
  83. package/dist/release/publish-plan.d.ts.map +1 -0
  84. package/dist/release/publish-plan.js +15 -0
  85. package/dist/release/retag-unpublished.d.ts +34 -0
  86. package/dist/release/retag-unpublished.d.ts.map +1 -0
  87. package/dist/release/retag-unpublished.js +77 -0
  88. package/managed/raw/git-format-staged.yml +54 -0
  89. package/managed/raw/tooling/git-hooks/commit-msg.sh +1 -1
  90. package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -7
  91. package/managed/templates/github/actions/setup-devenv/action.yml +1 -7
  92. package/managed/templates/github/workflows/ci.yml +3 -0
  93. package/package.json +37 -4
  94. package/src/cli.ts +193 -40
  95. package/src/devenv/index.test.ts +49 -0
  96. package/src/devenv/index.ts +38 -0
  97. package/src/lib/cli-package.ts +18 -0
  98. package/src/lib/devenv.test.ts +28 -0
  99. package/src/lib/devenv.ts +89 -0
  100. package/src/lib/run.ts +19 -0
  101. package/src/lib/workspace.ts +117 -7
  102. package/src/monorepo/__tests__/nx-version-actions.test.ts +75 -0
  103. package/src/monorepo/__tests__/publish-workflow.test.ts +322 -0
  104. package/src/monorepo/commit-msg.test.ts +45 -0
  105. package/src/monorepo/commit-msg.ts +107 -7
  106. package/src/monorepo/index.ts +181 -15
  107. package/src/monorepo/lockfile.ts +52 -7
  108. package/src/monorepo/managed-files.ts +43 -13
  109. package/src/monorepo/nx-sync.ts +9 -2
  110. package/src/monorepo/package-hygiene.test.ts +34 -0
  111. package/src/monorepo/package-hygiene.ts +26 -4
  112. package/src/monorepo/package-policy.test.ts +902 -0
  113. package/src/monorepo/package-policy.ts +1527 -25
  114. package/src/monorepo/packed-manifest.ts +67 -0
  115. package/src/monorepo/packed-package.ts +90 -31
  116. package/src/monorepo/packs/index.test.ts +189 -0
  117. package/src/monorepo/packs/index.ts +314 -19
  118. package/src/monorepo/publish-workflow.ts +422 -0
  119. package/src/monorepo/setup-test-tracing.test.ts +120 -0
  120. package/src/monorepo/tool-validation.test.ts +261 -0
  121. package/src/monorepo/tool-validation.ts +462 -0
  122. package/src/nx/index.test.ts +64 -0
  123. package/src/nx/index.ts +119 -0
  124. package/src/nx-version-actions.cts +36 -0
  125. package/src/release/__tests__/bootstrap-npm-packages.test.ts +127 -0
  126. package/src/release/__tests__/candidates.test.ts +217 -0
  127. package/src/release/__tests__/core-properties.test.ts +149 -0
  128. package/src/release/__tests__/core-scenarios.test.ts +187 -0
  129. package/src/release/__tests__/core.test.ts +73 -0
  130. package/src/release/__tests__/fixture-repo.test.ts +314 -0
  131. package/src/release/__tests__/github-release.test.ts +149 -0
  132. package/src/release/__tests__/helpers/fixture-repo.ts +114 -0
  133. package/src/release/__tests__/npm-auth.test.ts +120 -0
  134. package/src/release/__tests__/orchestration.test.ts +246 -0
  135. package/src/release/__tests__/publish-plan.test.ts +67 -0
  136. package/src/release/__tests__/retag-unpublished.test.ts +160 -0
  137. package/src/release/__tests__/trust-publisher.test.ts +133 -0
  138. package/src/release/bootstrap-npm-packages.ts +88 -0
  139. package/src/release/candidates.ts +225 -0
  140. package/src/release/core.ts +171 -0
  141. package/src/release/github-release.ts +134 -0
  142. package/src/release/index.ts +974 -138
  143. package/src/release/npm-auth.ts +93 -0
  144. package/src/release/orchestration.ts +196 -0
  145. package/src/release/publish-plan.ts +37 -0
  146. package/src/release/retag-unpublished.ts +122 -0
  147. package/managed/raw/.git-format-staged.yml +0 -47
  148. package/managed/templates/github/workflows/publish.yml +0 -136
@@ -1,33 +1,66 @@
1
1
  import { chmodSync, existsSync, statSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import { runStatus } from '../../lib/run.js';
4
+ import { readProjectTargets } from '../../nx/index.js';
5
+ import { syncBunLockfileVersions, validateBunLockfileVersions } from '../lockfile.js';
3
6
  import { validateManagedFiles } from '../managed-files.js';
4
- import { validateNxSync } from '../nx-sync.js';
7
+ import { fixNxSync, validateNxSync } from '../nx-sync.js';
5
8
  import { fixPackageHygiene, validatePackageHygiene } from '../package-hygiene.js';
6
9
  import {
10
+ applyFixableMonorepoDefaults,
11
+ applyNxReleaseDefaults,
7
12
  applyPublicPackageDefaults,
8
13
  applyWorkspaceDependencyDefaults,
14
+ type ResolvedProjectTargets,
15
+ validateNxProjectNames,
9
16
  validateNxReleaseConfig,
10
17
  validatePublicPackageMetadata,
11
18
  validatePublicTags,
12
19
  validateRootPackagePolicy,
13
20
  validateWorkspaceDependencies,
14
21
  } from '../package-policy.js';
15
- import { validatePackedPublicPackages } from '../packed-package.js';
22
+ import {
23
+ validatePackedPublicPackageManifest,
24
+ validatePackedPublicPackagePublint,
25
+ validatePackedPublicPackageTypes,
26
+ } from '../packed-package.js';
16
27
  import { syncRootRuntimeVersions } from '../runtime.js';
28
+ import { applyToolConfigDefaults, validateToolConfig } from '../tool-validation.js';
17
29
 
18
30
  export interface MonorepoContext {
19
31
  root: string;
20
32
  syncRuntime: boolean;
33
+ verbose?: boolean;
21
34
  }
22
35
 
23
36
  export interface ValidatePackOptions {
24
37
  failFast?: boolean;
38
+ fix?: boolean;
39
+ verbose?: boolean;
25
40
  }
26
41
 
27
- interface MonorepoPack {
42
+ export interface MonorepoPack {
28
43
  name: string;
29
44
  init?(ctx: MonorepoContext): Promise<void> | void;
30
- validate?(ctx: MonorepoContext): Promise<number> | number;
45
+ fixPreBuild?(ctx: MonorepoContext): Promise<void> | void;
46
+ fixPostBuild?(ctx: MonorepoContext): Promise<void> | void;
47
+ validatePreBuild?(ctx: MonorepoContext): Promise<number> | number;
48
+ validatePostBuild?(ctx: MonorepoContext): Promise<number> | number;
49
+ }
50
+
51
+ export interface ValidatePackRunHooks {
52
+ packs?: readonly MonorepoPack[];
53
+ runBuild?: (ctx: MonorepoContext, options?: ValidatePackOptions) => Promise<number> | number;
54
+ }
55
+
56
+ export interface ValidatePackResult {
57
+ failures: number;
58
+ failedChecks: number;
59
+ }
60
+
61
+ interface CapturedOutput {
62
+ logs: string[];
63
+ errors: string[];
31
64
  }
32
65
 
33
66
  const packs: MonorepoPack[] = [
@@ -35,18 +68,29 @@ const packs: MonorepoPack[] = [
35
68
  name: 'core',
36
69
  async init(ctx) {
37
70
  ensureLocalSmooShim(ctx.root);
71
+ applyNxReleaseDefaults(ctx.root);
38
72
  if (ctx.syncRuntime) {
39
73
  await syncRootRuntimeVersions(ctx.root);
40
74
  } else {
41
75
  console.log('skip root runtime versions (outside devenv; pass --sync-runtime to force)');
42
76
  }
43
77
  },
44
- async validate(ctx) {
78
+ async fixPreBuild(ctx) {
79
+ applyFixableMonorepoDefaults(ctx.root);
80
+ await applyToolConfigDefaults(ctx.root);
81
+ syncBunLockfileVersions(ctx.root);
82
+ await fixNxSync(ctx.root, ctx.verbose === true);
83
+ applyWorkspaceDependencyDefaults(ctx.root, { resolvedTargetsByProject: await readResolvedTargetsByProject(ctx) });
84
+ },
85
+ async validatePreBuild(ctx) {
45
86
  return (
46
87
  validateManagedFiles(ctx.root) +
47
88
  validateRootPackagePolicy(ctx.root) +
89
+ validateToolConfig(ctx.root) +
90
+ validateNxProjectNames(ctx.root) +
48
91
  validateNxReleaseConfig(ctx.root) +
49
- (await validateNxSync(ctx.root))
92
+ validateBunLockfileVersions(ctx.root) +
93
+ (await validateNxSync(ctx.root, ctx.verbose === true))
50
94
  );
51
95
  },
52
96
  },
@@ -55,24 +99,55 @@ const packs: MonorepoPack[] = [
55
99
  init(ctx) {
56
100
  applyPublicPackageDefaults(ctx.root);
57
101
  },
58
- validate(ctx) {
102
+ fixPreBuild(ctx) {
103
+ applyPublicPackageDefaults(ctx.root);
104
+ },
105
+ validatePreBuild(ctx) {
59
106
  return validatePublicTags(ctx.root) + validatePublicPackageMetadata(ctx.root);
60
107
  },
61
108
  },
62
109
  {
63
110
  name: 'workspace-dependencies',
64
- async init(ctx) {
111
+ init(ctx) {
65
112
  applyWorkspaceDependencyDefaults(ctx.root);
113
+ },
114
+ async fixPostBuild(ctx) {
115
+ applyWorkspaceDependencyDefaults(ctx.root, { resolvedTargetsByProject: await readResolvedTargetsByProject(ctx) });
116
+ },
117
+ async validatePostBuild(ctx) {
118
+ return validateWorkspaceDependencies(ctx.root, {
119
+ resolvedTargetsByProject: await readResolvedTargetsByProject(ctx),
120
+ });
121
+ },
122
+ },
123
+ {
124
+ name: 'package-hygiene',
125
+ async init(ctx) {
126
+ await fixPackageHygiene(ctx.root, ctx.verbose === true);
127
+ },
128
+ async fixPostBuild(ctx) {
66
129
  await fixPackageHygiene(ctx.root);
67
130
  },
68
- async validate(ctx) {
69
- return validateWorkspaceDependencies(ctx.root) + (await validatePackageHygiene(ctx.root));
131
+ async validatePostBuild(ctx) {
132
+ return validatePackageHygiene(ctx.root, ctx.verbose === true);
133
+ },
134
+ },
135
+ {
136
+ name: 'packed-package-publint',
137
+ validatePostBuild(ctx) {
138
+ return validatePackedPublicPackagePublint(ctx.root);
139
+ },
140
+ },
141
+ {
142
+ name: 'packed-package-manifest',
143
+ validatePostBuild(ctx) {
144
+ return validatePackedPublicPackageManifest(ctx.root);
70
145
  },
71
146
  },
72
147
  {
73
- name: 'packed-packages',
74
- validate(ctx) {
75
- return validatePackedPublicPackages(ctx.root);
148
+ name: 'packed-package-types',
149
+ validatePostBuild(ctx) {
150
+ return validatePackedPublicPackageTypes(ctx.root);
76
151
  },
77
152
  },
78
153
  ];
@@ -83,22 +158,242 @@ export async function runInitPacks(ctx: MonorepoContext): Promise<void> {
83
158
  }
84
159
  }
85
160
 
86
- export async function runValidatePacks(ctx: MonorepoContext, options: ValidatePackOptions = {}): Promise<number> {
161
+ export async function runValidatePacks(
162
+ ctx: MonorepoContext,
163
+ options: ValidatePackOptions = {},
164
+ hooks: ValidatePackRunHooks = {},
165
+ ): Promise<ValidatePackResult> {
166
+ const selectedPacks = hooks.packs ?? packs;
167
+ const build = hooks.runBuild ?? runBuild;
168
+
169
+ if (options.fix) {
170
+ await runFixPhase(ctx, selectedPacks, 'pre-build', 'fixPreBuild');
171
+ const buildFailures = await build(ctx, options);
172
+ if (buildFailures > 0) {
173
+ return { failures: buildFailures, failedChecks: 1 };
174
+ }
175
+ await runFixPhase(ctx, selectedPacks, 'post-build', 'fixPostBuild');
176
+ return runValidationPhases(ctx, selectedPacks, options, false);
177
+ }
178
+
179
+ const preBuild = await runValidationPhase(ctx, selectedPacks, options, 'pre-build', 'validatePreBuild', false);
180
+ if (preBuild.failures > 0 && options.failFast) {
181
+ return preBuild;
182
+ }
183
+ const buildFailures = await build(ctx, options);
184
+ if (buildFailures > 0) {
185
+ return { failures: preBuild.failures + buildFailures, failedChecks: preBuild.failedChecks + 1 };
186
+ }
187
+ return sumResults(
188
+ preBuild,
189
+ await runValidationPhase(ctx, selectedPacks, options, 'post-build', 'validatePostBuild', true),
190
+ );
191
+ }
192
+
193
+ async function runValidationPhases(
194
+ ctx: MonorepoContext,
195
+ selectedPacks: readonly MonorepoPack[],
196
+ options: ValidatePackOptions,
197
+ printedBefore: boolean,
198
+ ): Promise<ValidatePackResult> {
199
+ const preBuild = await runValidationPhase(
200
+ ctx,
201
+ selectedPacks,
202
+ options,
203
+ 'pre-build',
204
+ 'validatePreBuild',
205
+ printedBefore,
206
+ );
207
+ if (preBuild.failures > 0 && options.failFast) {
208
+ return preBuild;
209
+ }
210
+ return sumResults(
211
+ preBuild,
212
+ await runValidationPhase(ctx, selectedPacks, options, 'post-build', 'validatePostBuild', true),
213
+ );
214
+ }
215
+
216
+ async function runValidationPhase(
217
+ ctx: MonorepoContext,
218
+ selectedPacks: readonly MonorepoPack[],
219
+ options: ValidatePackOptions,
220
+ phase: 'pre-build' | 'post-build',
221
+ method: 'validatePreBuild' | 'validatePostBuild',
222
+ printedBefore: boolean,
223
+ ): Promise<ValidatePackResult> {
87
224
  let failures = 0;
225
+ let failedChecks = 0;
88
226
  let checkedPacks = 0;
89
- for (const pack of packs) {
90
- if (!pack.validate) {
227
+ let hasPrinted = printedBefore;
228
+ for (const pack of selectedPacks) {
229
+ const validate = pack[method];
230
+ if (!validate) {
91
231
  continue;
92
232
  }
93
- console.log(`${checkedPacks === 0 ? '' : '\n'}== ${pack.name} ==`);
233
+ const label = `${pack.name} (${phase})`;
234
+ if (options.verbose) {
235
+ printCheckHeading(label, hasPrinted || checkedPacks > 0);
236
+ }
237
+ hasPrinted = true;
94
238
  checkedPacks++;
95
- const packFailures = await pack.validate(ctx);
239
+ let packFailures: number;
240
+ let output = emptyCapturedOutput();
241
+ try {
242
+ if (options.verbose) {
243
+ packFailures = await validate(ctx);
244
+ } else {
245
+ const captured = await captureConsoleOutput(() => validate(ctx));
246
+ packFailures = captured.result;
247
+ output = captured.output;
248
+ }
249
+ } catch (error) {
250
+ if (!options.verbose) {
251
+ printCheckHeading(label, true);
252
+ if (error instanceof CapturedConsoleError) {
253
+ output = error.output;
254
+ }
255
+ printCapturedOutput(output);
256
+ }
257
+ throw error instanceof CapturedConsoleError ? error.cause : error;
258
+ }
96
259
  failures += packFailures;
260
+ if (packFailures > 0) {
261
+ failedChecks++;
262
+ }
263
+ if (!options.verbose && packFailures > 0) {
264
+ printCheckHeading(label, true);
265
+ printCapturedOutput(output);
266
+ }
267
+ printCheckStatus(label, packFailures);
97
268
  if (packFailures > 0 && options.failFast) {
98
269
  break;
99
270
  }
100
271
  }
101
- return failures;
272
+ return { failures, failedChecks };
273
+ }
274
+
275
+ function sumResults(left: ValidatePackResult, right: ValidatePackResult): ValidatePackResult {
276
+ return { failures: left.failures + right.failures, failedChecks: left.failedChecks + right.failedChecks };
277
+ }
278
+
279
+ async function runFixPhase(
280
+ ctx: MonorepoContext,
281
+ selectedPacks: readonly MonorepoPack[],
282
+ phase: 'pre-build' | 'post-build',
283
+ method: 'fixPreBuild' | 'fixPostBuild',
284
+ ): Promise<void> {
285
+ let checkedPacks = 0;
286
+ for (const pack of selectedPacks) {
287
+ const fix = pack[method];
288
+ if (!fix) {
289
+ continue;
290
+ }
291
+ const label = `${pack.name} (${phase} fix)`;
292
+ if (ctx.verbose) {
293
+ printCheckHeading(label, checkedPacks > 0);
294
+ }
295
+ checkedPacks++;
296
+ if (ctx.verbose) {
297
+ await fix(ctx);
298
+ continue;
299
+ }
300
+ let output = emptyCapturedOutput();
301
+ try {
302
+ output = (await captureConsoleOutput(() => fix(ctx))).output;
303
+ } catch (error) {
304
+ if (error instanceof CapturedConsoleError) {
305
+ output = error.output;
306
+ }
307
+ printCheckHeading(label, true);
308
+ printCapturedOutput(output);
309
+ throw error instanceof CapturedConsoleError ? error.cause : error;
310
+ }
311
+ }
312
+ }
313
+
314
+ async function runBuild(ctx: MonorepoContext, options: ValidatePackOptions = {}): Promise<number> {
315
+ if (options.verbose) {
316
+ printCheckHeading('build', true);
317
+ }
318
+ const status = await runStatus('nx', ['run-many', '-t', 'build'], ctx.root, options.verbose !== true);
319
+ if (status !== 0) {
320
+ if (!options.verbose) {
321
+ printCheckHeading('build', true);
322
+ }
323
+ console.error('nx run-many -t build failed');
324
+ printCheckStatus('build', 1);
325
+ return 1;
326
+ }
327
+ printCheckStatus('build', 0);
328
+ return 0;
329
+ }
330
+
331
+ function printCheckStatus(label: string, failures: number): void {
332
+ if (failures === 0) {
333
+ console.log(`🆗 ${label}`);
334
+ return;
335
+ }
336
+ const noun = failures === 1 ? 'problem' : 'problems';
337
+ console.log(`👎 ${label} (${failures} ${noun})\n`);
338
+ }
339
+
340
+ function printCheckHeading(label: string, separate: boolean): void {
341
+ console.log(`${separate ? '\n' : ''}== ${label} ==`);
342
+ }
343
+
344
+ function emptyCapturedOutput(): CapturedOutput {
345
+ return { logs: [], errors: [] };
346
+ }
347
+
348
+ async function captureConsoleOutput<T>(fn: () => Promise<T> | T): Promise<{ result: T; output: CapturedOutput }> {
349
+ const output = emptyCapturedOutput();
350
+ const originalLog = console.log;
351
+ const originalError = console.error;
352
+ console.log = (...args: unknown[]) => {
353
+ output.logs.push(args.join(' '));
354
+ };
355
+ console.error = (...args: unknown[]) => {
356
+ output.errors.push(args.join(' '));
357
+ };
358
+ try {
359
+ return { result: await fn(), output };
360
+ } catch (error) {
361
+ throw new CapturedConsoleError(error, output);
362
+ } finally {
363
+ console.log = originalLog;
364
+ console.error = originalError;
365
+ }
366
+ }
367
+
368
+ class CapturedConsoleError extends Error {
369
+ constructor(
370
+ public override readonly cause: unknown,
371
+ public readonly output: CapturedOutput,
372
+ ) {
373
+ super(cause instanceof Error ? cause.message : String(cause));
374
+ }
375
+ }
376
+
377
+ function printCapturedOutput(output: CapturedOutput): void {
378
+ for (const line of output.logs) {
379
+ console.log(line);
380
+ }
381
+ for (const line of output.errors) {
382
+ console.log(line);
383
+ }
384
+ }
385
+
386
+ async function readResolvedTargetsByProject(ctx: MonorepoContext): Promise<Map<string, ResolvedProjectTargets>> {
387
+ const projects = await readProjectTargets(ctx.root);
388
+ return new Map(
389
+ projects.map((project) => [
390
+ project.project,
391
+ {
392
+ targets: new Set(project.targets),
393
+ ...(project.buildDependsOn ? { buildDependsOn: project.buildDependsOn } : {}),
394
+ },
395
+ ]),
396
+ );
102
397
  }
103
398
 
104
399
  function ensureLocalSmooShim(root: string): void {