@fuzdev/fuz_gitops 0.78.1 → 0.79.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 +78 -24
- package/dist/ModulesDetail.svelte +15 -22
- package/dist/ModulesDetail.svelte.d.ts.map +1 -1
- package/dist/ModulesNav.svelte +4 -1
- package/dist/ModulesPage.svelte +1 -3
- package/dist/ModulesPage.svelte.d.ts.map +1 -1
- package/dist/PageHeader.svelte +2 -2
- package/dist/PageHeader.svelte.d.ts +0 -3
- package/dist/PageHeader.svelte.d.ts.map +1 -1
- package/dist/PullRequestsDetail.svelte +10 -9
- package/dist/PullRequestsDetail.svelte.d.ts.map +1 -1
- package/dist/PullRequestsPage.svelte +1 -3
- package/dist/PullRequestsPage.svelte.d.ts.map +1 -1
- package/dist/ReposTable.svelte +27 -48
- package/dist/ReposTable.svelte.d.ts.map +1 -1
- package/dist/ReposTree.svelte +5 -19
- package/dist/ReposTree.svelte.d.ts.map +1 -1
- package/dist/ReposTreeNav.svelte +5 -7
- package/dist/ReposTreeNav.svelte.d.ts.map +1 -1
- package/dist/TablePage.svelte +1 -3
- package/dist/TablePage.svelte.d.ts.map +1 -1
- package/dist/TreeItemPage.svelte +1 -3
- package/dist/TreeItemPage.svelte.d.ts.map +1 -1
- package/dist/TreePage.svelte +1 -3
- package/dist/TreePage.svelte.d.ts.map +1 -1
- package/dist/ci_reconcile.d.ts +6 -10
- package/dist/ci_reconcile.d.ts.map +1 -1
- package/dist/ci_reconcile.js +6 -8
- package/dist/dependency_graph.d.ts +26 -49
- package/dist/dependency_graph.d.ts.map +1 -1
- package/dist/dependency_graph.js +37 -80
- package/dist/dependency_updater.d.ts +1 -1
- package/dist/dependency_updater.d.ts.map +1 -1
- package/dist/dependency_updater.js +6 -1
- package/dist/fetch_repo_data.d.ts +34 -8
- package/dist/fetch_repo_data.d.ts.map +1 -1
- package/dist/fetch_repo_data.js +44 -22
- package/dist/fs_fetch_value_cache.d.ts +1 -1
- package/dist/fs_fetch_value_cache.js +1 -1
- package/dist/git_operations.d.ts +6 -49
- package/dist/git_operations.d.ts.map +1 -1
- package/dist/git_operations.js +13 -126
- package/dist/github.d.ts +17 -2
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +15 -6
- package/dist/github_helpers.d.ts.map +1 -1
- package/dist/github_helpers.js +3 -11
- package/dist/gitops_analyze.task.d.ts +24 -2
- package/dist/gitops_analyze.task.d.ts.map +1 -1
- package/dist/gitops_analyze.task.js +43 -30
- package/dist/gitops_config.d.ts +34 -79
- package/dist/gitops_config.d.ts.map +1 -1
- package/dist/gitops_config.js +76 -53
- package/dist/gitops_constants.d.ts +6 -4
- package/dist/gitops_constants.d.ts.map +1 -1
- package/dist/gitops_constants.js +6 -4
- package/dist/gitops_plan.task.d.ts +29 -3
- package/dist/gitops_plan.task.d.ts.map +1 -1
- package/dist/gitops_plan.task.js +80 -58
- package/dist/gitops_publish.task.d.ts +62 -2
- package/dist/gitops_publish.task.d.ts.map +1 -1
- package/dist/gitops_publish.task.js +187 -102
- package/dist/gitops_run.task.d.ts +74 -0
- package/dist/gitops_run.task.d.ts.map +1 -1
- package/dist/gitops_run.task.js +174 -160
- package/dist/gitops_sync.task.d.ts +65 -3
- package/dist/gitops_sync.task.d.ts.map +1 -1
- package/dist/gitops_sync.task.js +154 -30
- package/dist/gitops_task_helpers.d.ts +86 -59
- package/dist/gitops_task_helpers.d.ts.map +1 -1
- package/dist/gitops_task_helpers.js +120 -79
- package/dist/gitops_validate.task.d.ts +1 -2
- package/dist/gitops_validate.task.d.ts.map +1 -1
- package/dist/gitops_validate.task.js +15 -22
- package/dist/graph_validation.d.ts +16 -27
- package/dist/graph_validation.d.ts.map +1 -1
- package/dist/graph_validation.js +23 -64
- package/dist/local_repo.d.ts +50 -62
- package/dist/local_repo.d.ts.map +1 -1
- package/dist/local_repo.js +80 -193
- package/dist/log_helpers.d.ts +8 -8
- package/dist/log_helpers.d.ts.map +1 -1
- package/dist/multi_repo_publisher.d.ts +10 -0
- package/dist/multi_repo_publisher.d.ts.map +1 -1
- package/dist/multi_repo_publisher.js +115 -51
- package/dist/npm_registry.d.ts +23 -19
- package/dist/npm_registry.d.ts.map +1 -1
- package/dist/npm_registry.js +20 -47
- package/dist/operations.d.ts +75 -180
- package/dist/operations.d.ts.map +1 -1
- package/dist/operations.js +15 -7
- package/dist/operations_defaults.d.ts +17 -2
- package/dist/operations_defaults.d.ts.map +1 -1
- package/dist/operations_defaults.js +104 -121
- package/dist/output_helpers.d.ts +36 -0
- package/dist/output_helpers.d.ts.map +1 -1
- package/dist/output_helpers.js +37 -3
- package/dist/preflight_checks.d.ts +20 -27
- package/dist/preflight_checks.d.ts.map +1 -1
- package/dist/preflight_checks.js +37 -126
- package/dist/publish_steps.d.ts +2 -4
- package/dist/publish_steps.d.ts.map +1 -1
- package/dist/publish_steps.js +2 -6
- package/dist/publishing_event.d.ts +2 -8
- package/dist/publishing_event.d.ts.map +1 -1
- package/dist/publishing_event.js +5 -4
- package/dist/publishing_event_handler.d.ts +10 -8
- package/dist/publishing_event_handler.d.ts.map +1 -1
- package/dist/publishing_event_handler.js +14 -12
- package/dist/publishing_plan.d.ts +16 -1
- package/dist/publishing_plan.d.ts.map +1 -1
- package/dist/publishing_plan.js +328 -250
- package/dist/publishing_plan_logging.d.ts +1 -1
- package/dist/publishing_plan_logging.d.ts.map +1 -1
- package/dist/publishing_plan_logging.js +21 -14
- package/dist/repo.svelte.d.ts +7 -0
- package/dist/repo.svelte.d.ts.map +1 -1
- package/dist/repo.svelte.js +3 -0
- package/dist/repo_readiness.d.ts +210 -0
- package/dist/repo_readiness.d.ts.map +1 -0
- package/dist/repo_readiness.js +516 -0
- package/dist/repos_status.d.ts +3340 -0
- package/dist/repos_status.d.ts.map +1 -0
- package/dist/repos_status.js +555 -0
- package/dist/repos_status_load.d.ts +65 -0
- package/dist/repos_status_load.d.ts.map +1 -0
- package/dist/repos_status_load.js +131 -0
- package/package.json +7 -27
- package/src/lib/ci_reconcile.ts +7 -11
- package/src/lib/dependency_graph.ts +45 -97
- package/src/lib/dependency_updater.ts +7 -1
- package/src/lib/fetch_repo_data.ts +66 -29
- package/src/lib/fs_fetch_value_cache.ts +1 -1
- package/src/lib/git_operations.ts +15 -187
- package/src/lib/github.ts +20 -8
- package/src/lib/github_helpers.ts +5 -12
- package/src/lib/gitops_analyze.task.ts +79 -41
- package/src/lib/gitops_config.ts +88 -137
- package/src/lib/gitops_constants.ts +6 -4
- package/src/lib/gitops_plan.task.ts +113 -61
- package/src/lib/gitops_publish.task.ts +255 -122
- package/src/lib/gitops_run.task.ts +250 -178
- package/src/lib/gitops_sync.task.ts +208 -33
- package/src/lib/gitops_task_helpers.ts +166 -110
- package/src/lib/gitops_validate.task.ts +17 -27
- package/src/lib/graph_validation.ts +25 -86
- package/src/lib/local_repo.ts +109 -316
- package/src/lib/log_helpers.ts +8 -18
- package/src/lib/multi_repo_publisher.ts +138 -53
- package/src/lib/npm_registry.ts +37 -62
- package/src/lib/operations.ts +78 -150
- package/src/lib/operations_defaults.ts +108 -154
- package/src/lib/output_helpers.ts +55 -3
- package/src/lib/preflight_checks.ts +47 -183
- package/src/lib/publish_steps.ts +15 -13
- package/src/lib/publishing_event.ts +5 -4
- package/src/lib/publishing_event_handler.ts +18 -16
- package/src/lib/publishing_plan.ts +451 -287
- package/src/lib/publishing_plan_logging.ts +32 -23
- package/src/lib/repo.svelte.ts +8 -0
- package/src/lib/repo_readiness.ts +647 -0
- package/src/lib/repos_status.ts +671 -0
- package/src/lib/repos_status_load.ts +173 -0
- package/dist/config_reconcile.d.ts +0 -46
- package/dist/config_reconcile.d.ts.map +0 -1
- package/dist/config_reconcile.js +0 -64
- package/dist/paths.d.ts +0 -7
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js +0 -6
- package/dist/repo_ops.d.ts +0 -59
- package/dist/repo_ops.d.ts.map +0 -1
- package/dist/repo_ops.js +0 -170
- package/dist/resolved_gitops_config.d.ts +0 -9
- package/dist/resolved_gitops_config.d.ts.map +0 -1
- package/dist/resolved_gitops_config.js +0 -12
- package/src/lib/config_reconcile.ts +0 -98
- package/src/lib/paths.ts +0 -6
- package/src/lib/repo_ops.ts +0 -216
- package/src/lib/resolved_gitops_config.ts +0 -27
|
@@ -4,17 +4,36 @@ import { z } from 'zod';
|
|
|
4
4
|
import { createInterface } from 'node:readline/promises';
|
|
5
5
|
import { styleText as st } from 'node:util';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
gate_publish_readiness,
|
|
9
|
+
get_gitops_ready,
|
|
10
|
+
log_readiness_block,
|
|
11
|
+
type ResolveGitopsReposOptions
|
|
12
|
+
} from './gitops_task_helpers.ts';
|
|
13
|
+
import type { LocalRepo } from './local_repo.ts';
|
|
14
|
+
import type { GitopsOperations, ReposOperations } from './operations.ts';
|
|
15
|
+
import { default_gitops_operations, default_repos_operations } from './operations_defaults.ts';
|
|
8
16
|
import {
|
|
9
17
|
execute_publishing_plan,
|
|
10
18
|
type PublishingOptions,
|
|
11
19
|
type PublishingResult
|
|
12
20
|
} from './multi_repo_publisher.ts';
|
|
13
|
-
import {
|
|
14
|
-
|
|
21
|
+
import {
|
|
22
|
+
mask_secrets,
|
|
23
|
+
masking_handler,
|
|
24
|
+
redact_secrets,
|
|
25
|
+
stdout_handler
|
|
26
|
+
} from './publishing_event_handler.ts';
|
|
27
|
+
import { generate_publishing_plan } from './publishing_plan.ts';
|
|
28
|
+
import { log_publishing_plan } from './publishing_plan_logging.ts';
|
|
15
29
|
import { derive_publish_steps, format_publish_steps, type PublishStep } from './publish_steps.ts';
|
|
16
30
|
import { decide_publish_gate, publish_run_failed } from './publish_gate.ts';
|
|
17
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
format_and_output,
|
|
33
|
+
output_is_machine,
|
|
34
|
+
route_human_output,
|
|
35
|
+
type OutputFormatters
|
|
36
|
+
} from './output_helpers.ts';
|
|
18
37
|
import { GITOPS_CONFIG_PATH_DEFAULT, GITOPS_NPM_WAIT_TIMEOUT_DEFAULT } from './gitops_constants.ts';
|
|
19
38
|
|
|
20
39
|
/** @nodocs */
|
|
@@ -23,20 +42,32 @@ export const Args = z.strictObject({
|
|
|
23
42
|
.string()
|
|
24
43
|
.meta({ description: 'path to the gitops config file, absolute or relative to the cwd' })
|
|
25
44
|
.default(GITOPS_CONFIG_PATH_DEFAULT),
|
|
26
|
-
|
|
45
|
+
registry: z
|
|
27
46
|
.string()
|
|
28
|
-
.meta({
|
|
47
|
+
.meta({
|
|
48
|
+
description:
|
|
49
|
+
'path to the repos.toml registry, when `repos` would not find it walking up from the cwd'
|
|
50
|
+
})
|
|
29
51
|
.optional(),
|
|
30
52
|
peer_strategy: z
|
|
31
|
-
.enum(['exact', 'caret', 'tilde'])
|
|
32
|
-
.meta({
|
|
53
|
+
.enum(['exact', 'caret', 'tilde', 'gte'])
|
|
54
|
+
.meta({
|
|
55
|
+
description:
|
|
56
|
+
'range prefix for a rewritten dependency of any type whose range has none (an existing prefix is kept; a wildcard becomes ^)'
|
|
57
|
+
})
|
|
33
58
|
.default('caret' as const),
|
|
34
59
|
wetrun: z.boolean().meta({ description: 'actually publish (default is dry run)' }).default(false),
|
|
35
60
|
format: z
|
|
36
61
|
.enum(['stdout', 'json', 'markdown'])
|
|
37
62
|
.meta({ description: 'output format' })
|
|
38
63
|
.default('stdout'),
|
|
39
|
-
deploy: z
|
|
64
|
+
deploy: z
|
|
65
|
+
.boolean()
|
|
66
|
+
.meta({
|
|
67
|
+
description:
|
|
68
|
+
'deploy each repo the run changed (published, or any dependency updated) after publishing'
|
|
69
|
+
})
|
|
70
|
+
.default(false),
|
|
40
71
|
plan: z
|
|
41
72
|
.boolean()
|
|
42
73
|
.meta({ description: 'show the plan and confirm before publishing; --no-plan to skip' })
|
|
@@ -54,13 +85,6 @@ export const Args = z.strictObject({
|
|
|
54
85
|
.boolean()
|
|
55
86
|
.meta({ description: 'show additional details in plan output' })
|
|
56
87
|
.default(false),
|
|
57
|
-
sync: z
|
|
58
|
-
.boolean()
|
|
59
|
-
.meta({
|
|
60
|
-
description:
|
|
61
|
-
'sync repos (switch branch, pull, install) before the dry run instead of reading the working tree as-is; always on for --wetrun'
|
|
62
|
-
})
|
|
63
|
-
.default(false),
|
|
64
88
|
preview: z
|
|
65
89
|
.boolean()
|
|
66
90
|
.meta({ description: 'show the ordered side-effects a --wetrun would perform' })
|
|
@@ -70,118 +94,224 @@ export type Args = z.infer<typeof Args>;
|
|
|
70
94
|
|
|
71
95
|
/** @nodocs */
|
|
72
96
|
export const task: Task<Args> = {
|
|
73
|
-
summary:
|
|
97
|
+
summary:
|
|
98
|
+
'publish the packages the plan publishes, in dependency order (a dry run unless --wetrun)',
|
|
74
99
|
Args,
|
|
75
100
|
run: async ({ args, log }): Promise<void> => {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
max_wait,
|
|
85
|
-
emit_json,
|
|
86
|
-
outfile,
|
|
87
|
-
verbose,
|
|
88
|
-
sync,
|
|
89
|
-
preview
|
|
90
|
-
} = args;
|
|
91
|
-
|
|
92
|
-
// Load repos. A dry run reads the working tree as-is unless `--sync`;
|
|
93
|
-
// a real publish (`--wetrun`) always syncs so preflight sees the canonical branches.
|
|
94
|
-
const { local_repos: repos } = await get_gitops_ready({
|
|
95
|
-
config,
|
|
96
|
-
dir,
|
|
97
|
-
download: false, // Don't download if missing
|
|
98
|
-
sync: sync || wetrun,
|
|
99
|
-
log
|
|
100
|
-
});
|
|
101
|
+
const outcome = await run_gitops_publish(args, log);
|
|
102
|
+
if (outcome === 'cancelled') {
|
|
103
|
+
process.exit(0);
|
|
104
|
+
} else if (outcome === 'failed') {
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
101
109
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
110
|
+
/**
|
|
111
|
+
* The side effects `run_gitops_publish` reaches through, injectable so the
|
|
112
|
+
* order of its steps is testable.
|
|
113
|
+
*
|
|
114
|
+
* @nodocs
|
|
115
|
+
*/
|
|
116
|
+
export interface GitopsPublishDeps {
|
|
117
|
+
/** Loads the configured repos as they sit (`get_gitops_ready`). */
|
|
118
|
+
load_repos: (options: ResolveGitopsReposOptions) => Promise<{ local_repos: Array<LocalRepo> }>;
|
|
119
|
+
/** Runs `repos status` for the readiness gate. */
|
|
120
|
+
repos_ops: ReposOperations;
|
|
121
|
+
/** The executor's operations. */
|
|
122
|
+
ops: GitopsOperations;
|
|
123
|
+
/**
|
|
124
|
+
* Asks the operator to confirm the plan, on stderr, so a machine-readable
|
|
125
|
+
* stdout carries nothing but its document or events.
|
|
126
|
+
*/
|
|
127
|
+
confirm: () => Promise<boolean>;
|
|
128
|
+
}
|
|
105
129
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
130
|
+
const default_gitops_publish_deps: GitopsPublishDeps = {
|
|
131
|
+
load_repos: get_gitops_ready,
|
|
132
|
+
repos_ops: default_repos_operations,
|
|
133
|
+
ops: default_gitops_operations,
|
|
134
|
+
confirm: async () => {
|
|
135
|
+
process.stderr.write('Continue with publishing? (y/n): ');
|
|
136
|
+
return prompt_for_confirmation();
|
|
137
|
+
}
|
|
138
|
+
};
|
|
109
139
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Runs `gro gitops_publish`, in order: load the repos as they sit,
|
|
142
|
+
* generate the plan, and — for `--wetrun` — run the readiness gate
|
|
143
|
+
* (`gate_publish_readiness`, read-only: `repos status --fetch`) before
|
|
144
|
+
* printing the plan and asking to confirm, so a refusal or a "no" changes
|
|
145
|
+
* nothing. Then preflight and the executor. A dry run skips the gate and
|
|
146
|
+
* prints the diagnostics' readiness block instead. Under `--emit_json`, or
|
|
147
|
+
* `--format json` or `markdown` without `--outfile`, the log goes to stderr
|
|
148
|
+
* and stdout carries the events or the report alone (`route_human_output`).
|
|
149
|
+
*
|
|
150
|
+
* @returns `cancelled` when the operator declines, `failed` when the run failed (its output already written), else `done`
|
|
151
|
+
* @throws {TaskError} when the readiness gate refuses or loading fails
|
|
152
|
+
* @nodocs
|
|
153
|
+
*/
|
|
154
|
+
export const run_gitops_publish = async (
|
|
155
|
+
args: Args,
|
|
156
|
+
log: Logger,
|
|
157
|
+
deps: Partial<GitopsPublishDeps> = {}
|
|
158
|
+
): Promise<'done' | 'cancelled' | 'failed'> => {
|
|
159
|
+
const { load_repos, repos_ops, ops, confirm } = { ...default_gitops_publish_deps, ...deps };
|
|
160
|
+
const {
|
|
161
|
+
config,
|
|
162
|
+
registry,
|
|
163
|
+
peer_strategy,
|
|
164
|
+
wetrun,
|
|
165
|
+
format,
|
|
166
|
+
deploy,
|
|
167
|
+
plan,
|
|
168
|
+
max_wait,
|
|
169
|
+
emit_json,
|
|
170
|
+
outfile,
|
|
171
|
+
verbose,
|
|
172
|
+
preview
|
|
173
|
+
} = args;
|
|
116
174
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (preview_steps) log_preview(preview_steps, log);
|
|
121
|
-
|
|
122
|
-
// Ask for confirmation
|
|
123
|
-
log.info(st('yellow', '⚠️ This will publish the packages shown above.'));
|
|
124
|
-
process.stdout.write('Continue with publishing? (y/n): ');
|
|
125
|
-
const confirmed = await prompt_for_confirmation();
|
|
126
|
-
if (!confirmed) {
|
|
127
|
-
log.info('Publishing cancelled');
|
|
128
|
-
process.exit(0);
|
|
129
|
-
}
|
|
130
|
-
} else if (preview_steps && format === 'stdout') {
|
|
131
|
-
// proceed (dry run or --no-plan): only render to stdout for the human format;
|
|
132
|
-
// json/markdown carry the preview in their structured output, so logging here too
|
|
133
|
-
// would corrupt that stream.
|
|
134
|
-
log_preview(preview_steps, log);
|
|
135
|
-
}
|
|
175
|
+
// With a machine-readable stdout, every human line goes to stderr: the log (the plan, the
|
|
176
|
+
// readiness block and gate, the executor's progress) and, in `confirm`, the prompt
|
|
177
|
+
const write_stdout = route_human_output(log, to_child_stdout(args) === 'stderr');
|
|
136
178
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
wetrun,
|
|
140
|
-
version_strategy: peer_strategy,
|
|
141
|
-
deploy,
|
|
142
|
-
max_wait,
|
|
143
|
-
log,
|
|
144
|
-
// Live JSON-lines stream when requested; events also surface on the result.
|
|
145
|
-
events: emit_json ? stdout_handler() : undefined
|
|
146
|
-
};
|
|
179
|
+
// Load repos as they sit; a real publish gates on their state below rather than moving them
|
|
180
|
+
const { local_repos: repos } = await load_repos({ config, registry, log });
|
|
147
181
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
try {
|
|
153
|
-
result = await execute_publishing_plan(repos, publishing_plan, options);
|
|
154
|
-
} catch (error) {
|
|
155
|
-
// Construct a failure result for fatal errors so output can still be generated
|
|
156
|
-
fatal_error = error instanceof Error ? error : new Error(String(error));
|
|
157
|
-
result = {
|
|
158
|
-
ok: false,
|
|
159
|
-
published: [],
|
|
160
|
-
// Note: FATAL_ERROR is a placeholder - only fatal_error.message is displayed in output
|
|
161
|
-
failed: [{ name: 'FATAL_ERROR', error: fatal_error }],
|
|
162
|
-
duration: 0,
|
|
163
|
-
events: [],
|
|
164
|
-
summary: { total: 0, published: 0, failed: 1, skipped: 0, duration: 0 },
|
|
165
|
-
plan_errors: publishing_plan.errors,
|
|
166
|
-
plan_warnings: publishing_plan.warnings
|
|
167
|
-
};
|
|
168
|
-
}
|
|
182
|
+
// Generate the plan once; the executor consumes this exact plan (no second pass).
|
|
183
|
+
const publishing_plan = await generate_publishing_plan(repos, { verbose, ops: ops.changeset });
|
|
184
|
+
const preview_steps = preview ? derive_publish_steps(publishing_plan, { deploy }) : null;
|
|
169
185
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
186
|
+
// Decide whether to show the plan + confirm, block, or proceed (the decision table lives
|
|
187
|
+
// in `decide_publish_gate`; readline + exit stay at the edge).
|
|
188
|
+
const gate = decide_publish_gate({ wetrun, show_plan: plan, plan: publishing_plan });
|
|
189
|
+
|
|
190
|
+
if (wetrun) {
|
|
191
|
+
// The readiness gate: fetch, then refuse unless every npm repo is ready. Read-only, and
|
|
192
|
+
// before the prompt and any side effect. A plan with errors is refused without fetching:
|
|
193
|
+
// below when the plan is shown, else by the executor before anything else it does.
|
|
194
|
+
if (publishing_plan.errors.length === 0) {
|
|
195
|
+
await gate_publish_readiness({
|
|
196
|
+
local_repos: repos,
|
|
197
|
+
registry,
|
|
198
|
+
publishing: new Set(publishing_plan.version_changes.map((vc) => vc.package_name)),
|
|
199
|
+
log,
|
|
200
|
+
repos_ops
|
|
177
201
|
});
|
|
178
202
|
}
|
|
203
|
+
} else {
|
|
204
|
+
log_readiness_block(repos, log);
|
|
205
|
+
}
|
|
179
206
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
207
|
+
// A real publish that shows its plan prints it first — including before a `blocked` throw,
|
|
208
|
+
// so the operator sees the errors that blocked it.
|
|
209
|
+
if (gate.action !== 'proceed') {
|
|
210
|
+
log.info(st('cyan', 'Publishing Plan'));
|
|
211
|
+
log_publishing_plan(publishing_plan, log, { verbose });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (gate.action === 'blocked') {
|
|
215
|
+
throw new Error(gate.message);
|
|
216
|
+
} else if (gate.action === 'confirm') {
|
|
217
|
+
if (preview_steps) log_preview(preview_steps, log);
|
|
218
|
+
|
|
219
|
+
// Ask for confirmation
|
|
220
|
+
log.info(st('yellow', '⚠️ This will publish the packages shown above.'));
|
|
221
|
+
const confirmed = await confirm();
|
|
222
|
+
if (!confirmed) {
|
|
223
|
+
log.info('Publishing cancelled');
|
|
224
|
+
return 'cancelled';
|
|
183
225
|
}
|
|
226
|
+
} else if (preview_steps && format === 'stdout') {
|
|
227
|
+
// proceed (dry run or --no-plan): only render to stdout for the human format;
|
|
228
|
+
// json/markdown carry the preview in their structured output, so logging here too
|
|
229
|
+
// would corrupt that stream.
|
|
230
|
+
log_preview(preview_steps, log);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Publishing options
|
|
234
|
+
const options: PublishingOptions = {
|
|
235
|
+
wetrun,
|
|
236
|
+
version_strategy: peer_strategy,
|
|
237
|
+
deploy,
|
|
238
|
+
max_wait,
|
|
239
|
+
log,
|
|
240
|
+
ops,
|
|
241
|
+
registry,
|
|
242
|
+
// Live JSON-lines stream when requested, secrets masked since failure messages carry
|
|
243
|
+
// npm's stderr; events also surface on the result.
|
|
244
|
+
events: emit_json ? masking_handler(stdout_handler(write_stdout)) : undefined,
|
|
245
|
+
child_stdout: to_child_stdout(args)
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// Execute publishing (may throw on fatal errors like circular dependencies)
|
|
249
|
+
let result: PublishingResult;
|
|
250
|
+
let fatal_error: Error | null = null;
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
result = await execute_publishing_plan(repos, publishing_plan, options);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
// Construct a failure result for fatal errors so output can still be generated
|
|
256
|
+
fatal_error = error instanceof Error ? error : new Error(String(error));
|
|
257
|
+
result = {
|
|
258
|
+
ok: false,
|
|
259
|
+
published: [],
|
|
260
|
+
// Note: FATAL_ERROR is a placeholder - only fatal_error.message is displayed in output
|
|
261
|
+
failed: [{ name: 'FATAL_ERROR', error: fatal_error }],
|
|
262
|
+
duration: 0,
|
|
263
|
+
events: [],
|
|
264
|
+
summary: { total: 0, published: 0, failed: 1, skipped: 0, duration: 0 },
|
|
265
|
+
plan_errors: publishing_plan.errors,
|
|
266
|
+
plan_warnings: publishing_plan.warnings
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Format and output result (always runs, even on fatal errors)
|
|
271
|
+
// Note: stdout format is handled by the executor's logging
|
|
272
|
+
if (format !== 'stdout') {
|
|
273
|
+
await format_and_output({ result, fatal_error, preview_steps }, create_publish_formatters(), {
|
|
274
|
+
format,
|
|
275
|
+
outfile,
|
|
276
|
+
log,
|
|
277
|
+
write_stdout
|
|
278
|
+
});
|
|
184
279
|
}
|
|
280
|
+
|
|
281
|
+
return publish_run_failed(result, fatal_error) ? 'failed' : 'done';
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Where `gro publish` and `gro deploy`, streaming live, show their stdout: on
|
|
286
|
+
* our stderr when our stdout carries a machine-readable stream — the
|
|
287
|
+
* `--emit_json` events, or a JSON or markdown report not sent to `--outfile` —
|
|
288
|
+
* so their output can't corrupt it, else on our stdout. The same test sends
|
|
289
|
+
* the task's own log and prompt to stderr.
|
|
290
|
+
*
|
|
291
|
+
* @nodocs
|
|
292
|
+
*/
|
|
293
|
+
export const to_child_stdout = (
|
|
294
|
+
args: Pick<Args, 'emit_json' | 'format' | 'outfile'>
|
|
295
|
+
): 'stdout' | 'stderr' =>
|
|
296
|
+
args.emit_json || output_is_machine(args.format, args.outfile) ? 'stderr' : 'stdout';
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* A failed package's markdown: the message's first line on the bullet, and the
|
|
300
|
+
* rest — the end of a command's stderr — in an indented fenced block, its fence
|
|
301
|
+
* longer than any backtick run inside so stderr can't close it.
|
|
302
|
+
*
|
|
303
|
+
* @param name - the package name
|
|
304
|
+
* @param message - the failure message
|
|
305
|
+
* @nodocs
|
|
306
|
+
*/
|
|
307
|
+
export const format_failure_markdown = (name: string, message: string): Array<string> => {
|
|
308
|
+
const [head, ...rest] = message.split('\n');
|
|
309
|
+
const lines = [`- \`${name}\`: ${head}`];
|
|
310
|
+
if (rest.length === 0) return lines;
|
|
311
|
+
const longest_run = Math.max(0, ...(rest.join('\n').match(/`+/g) ?? []).map((r) => r.length));
|
|
312
|
+
const fence = '`'.repeat(Math.max(3, longest_run + 1));
|
|
313
|
+
lines.push('', ` ${fence}`, ...rest.map((l) => ` ${l}`), ` ${fence}`);
|
|
314
|
+
return lines;
|
|
185
315
|
};
|
|
186
316
|
|
|
187
317
|
interface PublishResultData {
|
|
@@ -191,12 +321,15 @@ interface PublishResultData {
|
|
|
191
321
|
}
|
|
192
322
|
|
|
193
323
|
const create_publish_formatters = (): OutputFormatters<PublishResultData> => ({
|
|
194
|
-
json: (data) =>
|
|
195
|
-
|
|
196
|
-
|
|
324
|
+
json: (data) => {
|
|
325
|
+
// the result's events are the executor's unmasked capture; mask them as the live stream is
|
|
326
|
+
const result = { ...data.result, events: data.result.events.map(mask_secrets) };
|
|
327
|
+
return JSON.stringify(
|
|
328
|
+
data.preview_steps ? { ...result, preview: data.preview_steps } : result,
|
|
197
329
|
null,
|
|
198
330
|
2
|
|
199
|
-
)
|
|
331
|
+
);
|
|
332
|
+
},
|
|
200
333
|
markdown: (data) => format_result_markdown(data.result, data.fatal_error, data.preview_steps),
|
|
201
334
|
stdout: () => {
|
|
202
335
|
// stdout format is handled by the executor's logging
|
|
@@ -204,7 +337,7 @@ const create_publish_formatters = (): OutputFormatters<PublishResultData> => ({
|
|
|
204
337
|
}
|
|
205
338
|
});
|
|
206
339
|
|
|
207
|
-
/** Logs the ordered side-effect preview
|
|
340
|
+
/** Logs the ordered side-effect preview. */
|
|
208
341
|
const log_preview = (steps: Array<PublishStep>, log: Logger): void => {
|
|
209
342
|
log.info(st('cyan', '\nSide-effect preview (what a real publish would perform):'));
|
|
210
343
|
for (const line of format_publish_steps(steps)) {
|
|
@@ -227,7 +360,7 @@ const format_result_markdown = (
|
|
|
227
360
|
if (fatal_error) {
|
|
228
361
|
lines.push('## ❌ Fatal Error');
|
|
229
362
|
lines.push('');
|
|
230
|
-
lines.push(`**Error**: ${fatal_error.message}`);
|
|
363
|
+
lines.push(`**Error**: ${redact_secrets(fatal_error.message)}`);
|
|
231
364
|
lines.push('');
|
|
232
365
|
lines.push('Publishing could not proceed due to the error above.');
|
|
233
366
|
lines.push('');
|
|
@@ -256,7 +389,7 @@ const format_result_markdown = (
|
|
|
256
389
|
lines.push('## Failed Packages');
|
|
257
390
|
lines.push('');
|
|
258
391
|
for (const { name, error } of result.failed) {
|
|
259
|
-
lines.push(
|
|
392
|
+
lines.push(...format_failure_markdown(name, redact_secrets(error.message)));
|
|
260
393
|
}
|
|
261
394
|
}
|
|
262
395
|
|
|
@@ -293,7 +426,7 @@ const format_result_markdown = (
|
|
|
293
426
|
const prompt_for_confirmation = async (): Promise<boolean> => {
|
|
294
427
|
const rl = createInterface({
|
|
295
428
|
input: process.stdin,
|
|
296
|
-
output: process.
|
|
429
|
+
output: process.stderr
|
|
297
430
|
});
|
|
298
431
|
|
|
299
432
|
const answer = await rl.question('');
|