@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.
- package/README.md +338 -88
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +136 -22
- package/dist/devenv/index.d.ts +10 -0
- package/dist/devenv/index.d.ts.map +1 -0
- package/dist/devenv/index.js +27 -0
- package/dist/lib/cli-package.d.ts +4 -0
- package/dist/lib/cli-package.d.ts.map +1 -0
- package/dist/lib/cli-package.js +15 -0
- package/dist/lib/devenv.d.ts +6 -0
- package/dist/lib/devenv.d.ts.map +1 -0
- package/dist/lib/devenv.js +82 -0
- package/dist/lib/run.d.ts +5 -0
- package/dist/lib/run.d.ts.map +1 -1
- package/dist/lib/run.js +13 -0
- package/dist/lib/workspace.d.ts +20 -1
- package/dist/lib/workspace.d.ts.map +1 -1
- package/dist/lib/workspace.js +87 -7
- package/dist/monorepo/commit-msg.d.ts +8 -1
- package/dist/monorepo/commit-msg.d.ts.map +1 -1
- package/dist/monorepo/commit-msg.js +85 -7
- package/dist/monorepo/index.d.ts +24 -2
- package/dist/monorepo/index.d.ts.map +1 -1
- package/dist/monorepo/index.js +136 -15
- package/dist/monorepo/lockfile.d.ts +5 -1
- package/dist/monorepo/lockfile.d.ts.map +1 -1
- package/dist/monorepo/lockfile.js +45 -5
- package/dist/monorepo/managed-files.d.ts +1 -1
- package/dist/monorepo/managed-files.d.ts.map +1 -1
- package/dist/monorepo/managed-files.js +28 -11
- package/dist/monorepo/nx-sync.d.ts +2 -1
- package/dist/monorepo/nx-sync.d.ts.map +1 -1
- package/dist/monorepo/nx-sync.js +8 -2
- package/dist/monorepo/package-hygiene.d.ts +6 -2
- package/dist/monorepo/package-hygiene.d.ts.map +1 -1
- package/dist/monorepo/package-hygiene.js +12 -4
- package/dist/monorepo/package-policy.d.ts +25 -2
- package/dist/monorepo/package-policy.d.ts.map +1 -1
- package/dist/monorepo/package-policy.js +1289 -27
- package/dist/monorepo/packed-manifest.d.ts +4 -0
- package/dist/monorepo/packed-manifest.d.ts.map +1 -0
- package/dist/monorepo/packed-manifest.js +51 -0
- package/dist/monorepo/packed-package.d.ts +3 -0
- package/dist/monorepo/packed-package.d.ts.map +1 -1
- package/dist/monorepo/packed-package.js +69 -31
- package/dist/monorepo/packs/index.d.ts +20 -1
- package/dist/monorepo/packs/index.d.ts.map +1 -1
- package/dist/monorepo/packs/index.js +240 -18
- package/dist/monorepo/publish-workflow.d.ts +82 -0
- package/dist/monorepo/publish-workflow.d.ts.map +1 -0
- package/dist/monorepo/publish-workflow.js +336 -0
- package/dist/monorepo/tool-validation.d.ts +22 -0
- package/dist/monorepo/tool-validation.d.ts.map +1 -0
- package/dist/monorepo/tool-validation.js +399 -0
- package/dist/nx/index.d.ts +24 -0
- package/dist/nx/index.d.ts.map +1 -0
- package/dist/nx/index.js +94 -0
- package/dist/nx-version-actions.cjs +25 -0
- package/dist/nx-version-actions.d.cts +6 -0
- package/dist/nx-version-actions.d.cts.map +1 -0
- package/dist/release/bootstrap-npm-packages.d.ts +19 -0
- package/dist/release/bootstrap-npm-packages.d.ts.map +1 -0
- package/dist/release/bootstrap-npm-packages.js +58 -0
- package/dist/release/candidates.d.ts +11 -0
- package/dist/release/candidates.d.ts.map +1 -0
- package/dist/release/candidates.js +181 -0
- package/dist/release/core.d.ts +51 -0
- package/dist/release/core.d.ts.map +1 -0
- package/dist/release/core.js +97 -0
- package/dist/release/github-release.d.ts +46 -0
- package/dist/release/github-release.d.ts.map +1 -0
- package/dist/release/github-release.js +97 -0
- package/dist/release/index.d.ts +39 -5
- package/dist/release/index.d.ts.map +1 -1
- package/dist/release/index.js +763 -130
- package/dist/release/npm-auth.d.ts +16 -0
- package/dist/release/npm-auth.d.ts.map +1 -0
- package/dist/release/npm-auth.js +39 -0
- package/dist/release/orchestration.d.ts +49 -0
- package/dist/release/orchestration.d.ts.map +1 -0
- package/dist/release/orchestration.js +113 -0
- package/dist/release/publish-plan.d.ts +17 -0
- package/dist/release/publish-plan.d.ts.map +1 -0
- package/dist/release/publish-plan.js +15 -0
- package/dist/release/retag-unpublished.d.ts +34 -0
- package/dist/release/retag-unpublished.d.ts.map +1 -0
- package/dist/release/retag-unpublished.js +77 -0
- package/managed/raw/git-format-staged.yml +54 -0
- package/managed/raw/tooling/git-hooks/commit-msg.sh +1 -1
- package/managed/raw/tooling/git-hooks/pre-commit.sh +2 -7
- package/managed/templates/github/actions/setup-devenv/action.yml +1 -7
- package/managed/templates/github/workflows/ci.yml +3 -0
- package/package.json +37 -4
- package/src/cli.ts +193 -40
- package/src/devenv/index.test.ts +49 -0
- package/src/devenv/index.ts +38 -0
- package/src/lib/cli-package.ts +18 -0
- package/src/lib/devenv.test.ts +28 -0
- package/src/lib/devenv.ts +89 -0
- package/src/lib/run.ts +19 -0
- package/src/lib/workspace.ts +117 -7
- package/src/monorepo/__tests__/nx-version-actions.test.ts +75 -0
- package/src/monorepo/__tests__/publish-workflow.test.ts +322 -0
- package/src/monorepo/commit-msg.test.ts +45 -0
- package/src/monorepo/commit-msg.ts +107 -7
- package/src/monorepo/index.ts +181 -15
- package/src/monorepo/lockfile.ts +52 -7
- package/src/monorepo/managed-files.ts +43 -13
- package/src/monorepo/nx-sync.ts +9 -2
- package/src/monorepo/package-hygiene.test.ts +34 -0
- package/src/monorepo/package-hygiene.ts +26 -4
- package/src/monorepo/package-policy.test.ts +902 -0
- package/src/monorepo/package-policy.ts +1527 -25
- package/src/monorepo/packed-manifest.ts +67 -0
- package/src/monorepo/packed-package.ts +90 -31
- package/src/monorepo/packs/index.test.ts +189 -0
- package/src/monorepo/packs/index.ts +314 -19
- package/src/monorepo/publish-workflow.ts +422 -0
- package/src/monorepo/setup-test-tracing.test.ts +120 -0
- package/src/monorepo/tool-validation.test.ts +261 -0
- package/src/monorepo/tool-validation.ts +462 -0
- package/src/nx/index.test.ts +64 -0
- package/src/nx/index.ts +119 -0
- package/src/nx-version-actions.cts +36 -0
- package/src/release/__tests__/bootstrap-npm-packages.test.ts +127 -0
- package/src/release/__tests__/candidates.test.ts +217 -0
- package/src/release/__tests__/core-properties.test.ts +149 -0
- package/src/release/__tests__/core-scenarios.test.ts +187 -0
- package/src/release/__tests__/core.test.ts +73 -0
- package/src/release/__tests__/fixture-repo.test.ts +314 -0
- package/src/release/__tests__/github-release.test.ts +149 -0
- package/src/release/__tests__/helpers/fixture-repo.ts +114 -0
- package/src/release/__tests__/npm-auth.test.ts +120 -0
- package/src/release/__tests__/orchestration.test.ts +246 -0
- package/src/release/__tests__/publish-plan.test.ts +67 -0
- package/src/release/__tests__/retag-unpublished.test.ts +160 -0
- package/src/release/__tests__/trust-publisher.test.ts +133 -0
- package/src/release/bootstrap-npm-packages.ts +88 -0
- package/src/release/candidates.ts +225 -0
- package/src/release/core.ts +171 -0
- package/src/release/github-release.ts +134 -0
- package/src/release/index.ts +974 -138
- package/src/release/npm-auth.ts +93 -0
- package/src/release/orchestration.ts +196 -0
- package/src/release/publish-plan.ts +37 -0
- package/src/release/retag-unpublished.ts +122 -0
- package/managed/raw/.git-format-staged.yml +0 -47
- 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 {
|
|
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
|
-
|
|
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
|
|
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
|
-
(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
69
|
-
return
|
|
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-
|
|
74
|
-
|
|
75
|
-
return
|
|
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(
|
|
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
|
-
|
|
90
|
-
|
|
227
|
+
let hasPrinted = printedBefore;
|
|
228
|
+
for (const pack of selectedPacks) {
|
|
229
|
+
const validate = pack[method];
|
|
230
|
+
if (!validate) {
|
|
91
231
|
continue;
|
|
92
232
|
}
|
|
93
|
-
|
|
233
|
+
const label = `${pack.name} (${phase})`;
|
|
234
|
+
if (options.verbose) {
|
|
235
|
+
printCheckHeading(label, hasPrinted || checkedPacks > 0);
|
|
236
|
+
}
|
|
237
|
+
hasPrinted = true;
|
|
94
238
|
checkedPacks++;
|
|
95
|
-
|
|
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 {
|