@detergent-software/atk 8.9.0-dev.2 → 8.9.0-dev.21
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/CHANGELOG.md +145 -0
- package/README.md +13 -3
- package/build/cli.js +18 -6
- package/build/cli.js.map +1 -1
- package/build/command-manifest.json +1507 -0
- package/build/commands/_app.d.ts.map +1 -1
- package/build/commands/_app.js +8 -4
- package/build/commands/_app.js.map +1 -1
- package/build/commands/audit.d.ts.map +1 -1
- package/build/commands/audit.js +1 -1
- package/build/commands/audit.js.map +1 -1
- package/build/commands/browse.js +2 -2
- package/build/commands/browse.js.map +1 -1
- package/build/commands/cache.d.ts +1 -1
- package/build/commands/cache.d.ts.map +1 -1
- package/build/commands/cache.js +1 -16
- package/build/commands/cache.js.map +1 -1
- package/build/commands/config.d.ts.map +1 -1
- package/build/commands/config.js +1 -1
- package/build/commands/config.js.map +1 -1
- package/build/commands/diff.d.ts.map +1 -1
- package/build/commands/diff.js +4 -0
- package/build/commands/diff.js.map +1 -1
- package/build/commands/drift.d.ts.map +1 -1
- package/build/commands/drift.js +4 -0
- package/build/commands/drift.js.map +1 -1
- package/build/commands/index.js +1 -1
- package/build/commands/index.js.map +1 -1
- package/build/commands/info.d.ts.map +1 -1
- package/build/commands/info.js +50 -33
- package/build/commands/info.js.map +1 -1
- package/build/commands/init.d.ts.map +1 -1
- package/build/commands/init.js +4 -2
- package/build/commands/init.js.map +1 -1
- package/build/commands/install.d.ts.map +1 -1
- package/build/commands/install.js +28 -7
- package/build/commands/install.js.map +1 -1
- package/build/commands/list.js +2 -2
- package/build/commands/list.js.map +1 -1
- package/build/commands/login.d.ts.map +1 -1
- package/build/commands/login.js +12 -2
- package/build/commands/login.js.map +1 -1
- package/build/commands/logout.d.ts.map +1 -1
- package/build/commands/logout.js +9 -1
- package/build/commands/logout.js.map +1 -1
- package/build/commands/outdated.js +1 -1
- package/build/commands/outdated.js.map +1 -1
- package/build/commands/publish.d.ts +1 -1
- package/build/commands/publish.d.ts.map +1 -1
- package/build/commands/publish.js +32 -36
- package/build/commands/publish.js.map +1 -1
- package/build/commands/release-notes.d.ts.map +1 -1
- package/build/commands/release-notes.js +4 -0
- package/build/commands/release-notes.js.map +1 -1
- package/build/commands/schema.d.ts +3 -3
- package/build/commands/search.js +1 -1
- package/build/commands/search.js.map +1 -1
- package/build/commands/sync.d.ts +1 -1
- package/build/commands/sync.d.ts.map +1 -1
- package/build/commands/sync.js +27 -12
- package/build/commands/sync.js.map +1 -1
- package/build/commands/update.d.ts.map +1 -1
- package/build/commands/update.js +58 -9
- package/build/commands/update.js.map +1 -1
- package/build/commands/whoami.d.ts.map +1 -1
- package/build/commands/whoami.js +16 -4
- package/build/commands/whoami.js.map +1 -1
- package/build/commands/why.js +3 -4
- package/build/commands/why.js.map +1 -1
- package/build/components/Header.d.ts +2 -3
- package/build/components/Header.d.ts.map +1 -1
- package/build/components/Header.js +2 -9
- package/build/components/Header.js.map +1 -1
- package/build/components/LocalEditsHint.d.ts +16 -0
- package/build/components/LocalEditsHint.d.ts.map +1 -0
- package/build/components/LocalEditsHint.js +18 -0
- package/build/components/LocalEditsHint.js.map +1 -0
- package/build/components/SyncAllInSync.d.ts +5 -1
- package/build/components/SyncAllInSync.d.ts.map +1 -1
- package/build/components/SyncAllInSync.js +2 -2
- package/build/components/SyncAllInSync.js.map +1 -1
- package/build/components/header-art.d.ts +7 -0
- package/build/components/header-art.d.ts.map +1 -0
- package/build/components/header-art.js +14 -0
- package/build/components/header-art.js.map +1 -0
- package/build/components/index.d.ts +1 -0
- package/build/components/index.d.ts.map +1 -1
- package/build/components/index.js +1 -0
- package/build/components/index.js.map +1 -1
- package/build/hooks/useListActions.d.ts.map +1 -1
- package/build/hooks/useListActions.js +4 -0
- package/build/hooks/useListActions.js.map +1 -1
- package/build/hooks/usePublishState.d.ts +38 -207
- package/build/hooks/usePublishState.d.ts.map +1 -1
- package/build/hooks/usePublishState.js +83 -1501
- package/build/hooks/usePublishState.js.map +1 -1
- package/build/lib/adapter.js +23 -3
- package/build/lib/adapter.js.map +1 -1
- package/build/lib/api-client.d.ts +9 -5
- package/build/lib/api-client.d.ts.map +1 -1
- package/build/lib/api-client.js +35 -8
- package/build/lib/api-client.js.map +1 -1
- package/build/lib/atk-api/generated/types.gen.d.ts +4 -4
- package/build/lib/auth.d.ts +12 -2
- package/build/lib/auth.d.ts.map +1 -1
- package/build/lib/auth.js +38 -3
- package/build/lib/auth.js.map +1 -1
- package/build/lib/checksum.d.ts +40 -14
- package/build/lib/checksum.d.ts.map +1 -1
- package/build/lib/checksum.js +110 -57
- package/build/lib/checksum.js.map +1 -1
- package/build/lib/config.d.ts.map +1 -1
- package/build/lib/config.js +28 -5
- package/build/lib/config.js.map +1 -1
- package/build/lib/diagnostics.d.ts.map +1 -1
- package/build/lib/diagnostics.js +10 -7
- package/build/lib/diagnostics.js.map +1 -1
- package/build/lib/diff-command.js +1 -1
- package/build/lib/diff-command.js.map +1 -1
- package/build/lib/errors.d.ts +4 -1
- package/build/lib/errors.d.ts.map +1 -1
- package/build/lib/errors.js.map +1 -1
- package/build/lib/format-age.d.ts +3 -0
- package/build/lib/format-age.d.ts.map +1 -0
- package/build/lib/format-age.js +18 -0
- package/build/lib/format-age.js.map +1 -0
- package/build/lib/installer.d.ts +2 -7
- package/build/lib/installer.d.ts.map +1 -1
- package/build/lib/installer.js +30 -5
- package/build/lib/installer.js.map +1 -1
- package/build/lib/local-edits.d.ts +72 -0
- package/build/lib/local-edits.d.ts.map +1 -0
- package/build/lib/local-edits.js +145 -0
- package/build/lib/local-edits.js.map +1 -0
- package/build/lib/lockfile.d.ts +12 -8
- package/build/lib/lockfile.d.ts.map +1 -1
- package/build/lib/lockfile.js +193 -52
- package/build/lib/lockfile.js.map +1 -1
- package/build/lib/mover.d.ts.map +1 -1
- package/build/lib/mover.js +8 -12
- package/build/lib/mover.js.map +1 -1
- package/build/lib/offline.d.ts +19 -0
- package/build/lib/offline.d.ts.map +1 -0
- package/build/lib/offline.js +26 -0
- package/build/lib/offline.js.map +1 -0
- package/build/lib/owned-paths.d.ts +4 -2
- package/build/lib/owned-paths.d.ts.map +1 -1
- package/build/lib/owned-paths.js +19 -6
- package/build/lib/owned-paths.js.map +1 -1
- package/build/lib/pastel/commander-specs.d.ts +7 -0
- package/build/lib/pastel/commander-specs.d.ts.map +1 -0
- package/build/lib/pastel/commander-specs.js +50 -0
- package/build/lib/pastel/commander-specs.js.map +1 -0
- package/build/lib/pastel/generate-arguments.d.ts +3 -3
- package/build/lib/pastel/generate-arguments.d.ts.map +1 -1
- package/build/lib/pastel/generate-arguments.js +25 -22
- package/build/lib/pastel/generate-arguments.js.map +1 -1
- package/build/lib/pastel/generate-command.d.ts +7 -5
- package/build/lib/pastel/generate-command.d.ts.map +1 -1
- package/build/lib/pastel/generate-command.js +32 -67
- package/build/lib/pastel/generate-command.js.map +1 -1
- package/build/lib/pastel/generate-commands.d.ts +3 -5
- package/build/lib/pastel/generate-commands.d.ts.map +1 -1
- package/build/lib/pastel/generate-commands.js +6 -10
- package/build/lib/pastel/generate-commands.js.map +1 -1
- package/build/lib/pastel/generate-options.d.ts +3 -3
- package/build/lib/pastel/generate-options.d.ts.map +1 -1
- package/build/lib/pastel/generate-options.js +16 -13
- package/build/lib/pastel/generate-options.js.map +1 -1
- package/build/lib/pastel/index.d.ts +26 -4
- package/build/lib/pastel/index.d.ts.map +1 -1
- package/build/lib/pastel/index.js +104 -18
- package/build/lib/pastel/index.js.map +1 -1
- package/build/lib/pastel/internal-types.d.ts +39 -8
- package/build/lib/pastel/internal-types.d.ts.map +1 -1
- package/build/lib/pastel/manifest.d.ts +8 -0
- package/build/lib/pastel/manifest.d.ts.map +1 -0
- package/build/lib/pastel/manifest.js +7 -0
- package/build/lib/pastel/manifest.js.map +1 -0
- package/build/lib/pastel/read-commands.d.ts +7 -2
- package/build/lib/pastel/read-commands.d.ts.map +1 -1
- package/build/lib/pastel/read-commands.js +51 -30
- package/build/lib/pastel/read-commands.js.map +1 -1
- package/build/lib/pastel/render-command.d.ts +13 -0
- package/build/lib/pastel/render-command.d.ts.map +1 -0
- package/build/lib/pastel/render-command.js +56 -0
- package/build/lib/pastel/render-command.js.map +1 -0
- package/build/lib/publish-flow.d.ts +225 -0
- package/build/lib/publish-flow.d.ts.map +1 -0
- package/build/lib/publish-flow.js +1242 -0
- package/build/lib/publish-flow.js.map +1 -0
- package/build/lib/publish-run.d.ts +55 -0
- package/build/lib/publish-run.d.ts.map +1 -0
- package/build/lib/publish-run.js +164 -0
- package/build/lib/publish-run.js.map +1 -0
- package/build/lib/publisher.d.ts +11 -16
- package/build/lib/publisher.d.ts.map +1 -1
- package/build/lib/publisher.js +25 -42
- package/build/lib/publisher.js.map +1 -1
- package/build/lib/registry.d.ts +15 -1
- package/build/lib/registry.d.ts.map +1 -1
- package/build/lib/registry.js +108 -24
- package/build/lib/registry.js.map +1 -1
- package/build/lib/root-path.d.ts +11 -0
- package/build/lib/root-path.d.ts.map +1 -1
- package/build/lib/root-path.js +15 -1
- package/build/lib/root-path.js.map +1 -1
- package/build/lib/schemas/config.js +1 -1
- package/build/lib/schemas/config.js.map +1 -1
- package/build/lib/schemas/lockfile.d.ts +156 -23
- package/build/lib/schemas/lockfile.d.ts.map +1 -1
- package/build/lib/schemas/lockfile.js +100 -79
- package/build/lib/schemas/lockfile.js.map +1 -1
- package/build/lib/staging.d.ts +15 -0
- package/build/lib/staging.d.ts.map +1 -0
- package/build/lib/staging.js +33 -0
- package/build/lib/staging.js.map +1 -0
- package/build/lib/sync.d.ts +22 -6
- package/build/lib/sync.d.ts.map +1 -1
- package/build/lib/sync.js +59 -7
- package/build/lib/sync.js.map +1 -1
- package/build/lib/uninstaller.js +2 -2
- package/build/lib/uninstaller.js.map +1 -1
- package/build/lib/update-check.d.ts.map +1 -1
- package/build/lib/update-check.js +5 -1
- package/build/lib/update-check.js.map +1 -1
- package/build/lib/updater.d.ts +31 -1
- package/build/lib/updater.d.ts.map +1 -1
- package/build/lib/updater.js +143 -4
- package/build/lib/updater.js.map +1 -1
- package/build/lib/usage-error.d.ts +20 -0
- package/build/lib/usage-error.d.ts.map +1 -0
- package/build/lib/usage-error.js +41 -0
- package/build/lib/usage-error.js.map +1 -0
- package/build/lib/write-file.d.ts +5 -0
- package/build/lib/write-file.d.ts.map +1 -1
- package/build/lib/write-file.js +10 -7
- package/build/lib/write-file.js.map +1 -1
- package/package.json +81 -81
|
@@ -0,0 +1,1242 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { compare as semverCompare, valid as semverValid } from 'semver';
|
|
4
|
+
import { loadAllAdapters } from './adapter.js';
|
|
5
|
+
import { isApiError } from './api-client.js';
|
|
6
|
+
import { getCredential } from './auth.js';
|
|
7
|
+
import { errorGuidance, errorMessage } from './errors.js';
|
|
8
|
+
import { detectCompatibleTools, getSignedInUserName } from './init.js';
|
|
9
|
+
import { findInstalledAsset, readLockfile } from './lockfile.js';
|
|
10
|
+
import { diffManifests, fetchExistingManifest } from './manifest-diff.js';
|
|
11
|
+
import { parseOrgFromName } from './org.js';
|
|
12
|
+
import { findProjectRoot } from './paths.js';
|
|
13
|
+
import { buildPublishPlan, buildStagingArea, bumpVersion, checkRegistryVersion, detectAssetFromPath, detectPublishType, executePublish, findSiblingDependencies, isOrgScopedTarget, loadPublishBatch, loadPublishEntries, mapPublishError, missingDependencies, resolvePlanDependencies, unknownToolsError, updateManifestField, updateManifestVersion, validatePublishTarget, } from './publisher.js';
|
|
14
|
+
import { clearCache, fetchAssetFileBytes, fetchAssetReadme, fetchRegistry, findAsset } from './registry.js';
|
|
15
|
+
import { parseReviewersInput, validateGithubUsername } from './reviewers.js';
|
|
16
|
+
import { stageInstalledFiles } from './staging.js';
|
|
17
|
+
import { resolveTools } from './tool-resolver.js';
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// Helpers
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
export function createInitialState(flags) {
|
|
22
|
+
// Non-interactive when --yes, --dry-run, --json, or stdin is not a TTY (raw mode
|
|
23
|
+
// unsupported). Defaults isTTY to true when the flag is omitted (call site responsible
|
|
24
|
+
// for threading useStdin().isRawModeSupported in). --dry-run and --json force
|
|
25
|
+
// non-interactive regardless of TTY — JSON output cannot interleave with prompts.
|
|
26
|
+
const isTTY = flags.isTTY ?? true;
|
|
27
|
+
const nonInteractive = Boolean(flags.yes) || flags.dryRun || Boolean(flags.json) || !isTTY;
|
|
28
|
+
const flagError = batchFlagError(flags);
|
|
29
|
+
return {
|
|
30
|
+
authorValue: '',
|
|
31
|
+
bumpSelection: '',
|
|
32
|
+
confirmValue: '',
|
|
33
|
+
descriptionValue: '',
|
|
34
|
+
entries: [],
|
|
35
|
+
errorMessage: flagError ?? '',
|
|
36
|
+
flags,
|
|
37
|
+
isRawPublish: false,
|
|
38
|
+
isUpdate: false,
|
|
39
|
+
manifestDiff: undefined,
|
|
40
|
+
metadataSubPhase: 'description',
|
|
41
|
+
missingDependencies: [],
|
|
42
|
+
nonInteractive,
|
|
43
|
+
orgValue: '',
|
|
44
|
+
phase: flagError
|
|
45
|
+
? 'error'
|
|
46
|
+
: flags.update
|
|
47
|
+
? 'resolving-update'
|
|
48
|
+
: flags.fromInstalled
|
|
49
|
+
? 'resolving-installed'
|
|
50
|
+
: 'detecting',
|
|
51
|
+
plan: undefined,
|
|
52
|
+
progressMessage: '',
|
|
53
|
+
promptTagsValue: '',
|
|
54
|
+
publishConfirmValue: '',
|
|
55
|
+
publishResult: undefined,
|
|
56
|
+
rawDetection: null,
|
|
57
|
+
resolvedPath: flags.update ? '' : flags.fromInstalled ? '' : resolve(flags.rawPath),
|
|
58
|
+
resolvedVersion: '',
|
|
59
|
+
reviewerValue: '',
|
|
60
|
+
selectedPromptTools: [],
|
|
61
|
+
suggestedEntries: [],
|
|
62
|
+
tagsValue: '',
|
|
63
|
+
target: undefined,
|
|
64
|
+
token: undefined,
|
|
65
|
+
toolAdapters: [],
|
|
66
|
+
toolsDetected: [],
|
|
67
|
+
validation: undefined,
|
|
68
|
+
versionCheck: undefined,
|
|
69
|
+
withConfirmValue: '',
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Several folders published together (`atk publish a b c`) in one pull request; one folder named twice is one. */
|
|
73
|
+
export function isBatch(flags) {
|
|
74
|
+
return new Set(flags.paths?.map((path) => resolve(path))).size > 1;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Run the step for the state's phase, if it has one: the work the phase waits on,
|
|
78
|
+
* reported through `ctx.dispatch`, which reaches the runner only until the run is
|
|
79
|
+
* cancelled. An error the step throws is dispatched too, so this never rejects.
|
|
80
|
+
* Prompt and terminal phases have no step.
|
|
81
|
+
*/
|
|
82
|
+
export async function runPublishStep(state, ctx) {
|
|
83
|
+
const step = stepFor(state);
|
|
84
|
+
if (!step)
|
|
85
|
+
return;
|
|
86
|
+
const guarded = {
|
|
87
|
+
...ctx,
|
|
88
|
+
dispatch: (action) => {
|
|
89
|
+
if (!ctx.cancelled())
|
|
90
|
+
ctx.dispatch(action);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
try {
|
|
94
|
+
await step.run(state, guarded);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
if (ctx.cancelled())
|
|
98
|
+
return;
|
|
99
|
+
const action = step.fail
|
|
100
|
+
? await step.fail(err, state, guarded).catch(() => toErrorAction(err))
|
|
101
|
+
: toErrorAction(err);
|
|
102
|
+
if (action)
|
|
103
|
+
guarded.dispatch(action);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** The comma-separated values in a flag or prompt answer, trimmed, without empty ones. */
|
|
107
|
+
export function splitList(value) {
|
|
108
|
+
return (value ?? '')
|
|
109
|
+
.split(',')
|
|
110
|
+
.map((item) => item.trim())
|
|
111
|
+
.filter(Boolean);
|
|
112
|
+
}
|
|
113
|
+
/** Why the flags can't publish a batch: one installed asset, or one asset's metadata. Undefined otherwise. */
|
|
114
|
+
function batchFlagError(flags) {
|
|
115
|
+
if (!isBatch(flags))
|
|
116
|
+
return undefined;
|
|
117
|
+
if (flags.update || flags.fromInstalled) {
|
|
118
|
+
return `${flags.update ? '--update' : '--from-installed'} publishes one installed asset; leave it out to publish several folders.`;
|
|
119
|
+
}
|
|
120
|
+
const perAsset = [
|
|
121
|
+
['--description', flags.descriptionFlag],
|
|
122
|
+
['--tags', flags.tagsFlag],
|
|
123
|
+
['--tools', flags.toolsFlag],
|
|
124
|
+
].flatMap(([flag, value]) => (value === undefined ? [] : [flag]));
|
|
125
|
+
if (perAsset.length > 0) {
|
|
126
|
+
return `${perAsset.join(', ')} ${perAsset.length === 1 ? 'sets' : 'set'} one asset's metadata; put it in each folder's manifest.json to publish several folders.`;
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
/** In a batch, what the API calls `Root asset`, as the folder the user named. */
|
|
131
|
+
function batchRootLabel(state) {
|
|
132
|
+
return isBatch(state.flags) ? state.flags.rawPath : undefined;
|
|
133
|
+
}
|
|
134
|
+
/** What the API calls `dependencies[i]`, as the folder the user named. */
|
|
135
|
+
function entryLabels(state) {
|
|
136
|
+
return state.entries.map((entry) => entry.label);
|
|
137
|
+
}
|
|
138
|
+
/** The installed asset `--from-installed` or `--update` names, with the tool's adapter; an error when it isn't installed. */
|
|
139
|
+
async function findInstalledSource(state, ctx) {
|
|
140
|
+
const assetName = state.flags.rawPath;
|
|
141
|
+
const { name, org } = parseOrgFromName(assetName);
|
|
142
|
+
const projectRoot = findProjectRoot(state.flags.projectRoot);
|
|
143
|
+
const tools = await resolveTools(state.flags.tool);
|
|
144
|
+
const adapter = tools[0].adapter;
|
|
145
|
+
const lockfile = await readLockfile(projectRoot);
|
|
146
|
+
const installed = findInstalledAsset(lockfile, name, undefined, org);
|
|
147
|
+
if (!installed) {
|
|
148
|
+
ctx.dispatch({ message: `Asset '${assetName}' is not installed.`, type: 'ERROR' });
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
return { adapter, installed, org, projectRoot };
|
|
152
|
+
}
|
|
153
|
+
/** Run the writes in order until one throws: its index and error, or undefined when all succeed. */
|
|
154
|
+
async function firstFailure(edits) {
|
|
155
|
+
for (const [index, edit] of edits.entries()) {
|
|
156
|
+
try {
|
|
157
|
+
await edit.write();
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
return { error, index };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
function stepFor(state) {
|
|
166
|
+
switch (state.phase) {
|
|
167
|
+
case 'building-plan':
|
|
168
|
+
return buildingPlan;
|
|
169
|
+
case 'checking-entries':
|
|
170
|
+
return checkingEntries;
|
|
171
|
+
case 'checking-registry':
|
|
172
|
+
return checkingRegistry;
|
|
173
|
+
case 'detecting':
|
|
174
|
+
return detecting;
|
|
175
|
+
case 'gathering-metadata':
|
|
176
|
+
return state.metadataSubPhase === 'building-staging' ? buildingStaging : undefined;
|
|
177
|
+
case 'loading-tools':
|
|
178
|
+
return loadingTools;
|
|
179
|
+
case 'publishing':
|
|
180
|
+
return publishing;
|
|
181
|
+
case 'resolving-installed':
|
|
182
|
+
return resolvingInstalled;
|
|
183
|
+
case 'resolving-update':
|
|
184
|
+
return resolvingUpdate;
|
|
185
|
+
case 'validating':
|
|
186
|
+
return validating;
|
|
187
|
+
default:
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Folders next to the root asset that could fix the plan's error: an interactive
|
|
193
|
+
* run, a `422` naming root dependencies that aren't in the registry (or have no
|
|
194
|
+
* matching version), and a sibling folder whose manifest has the same type and
|
|
195
|
+
* name that isn't an entry yet. Undefined when there is nothing to offer.
|
|
196
|
+
* `--update` and `--from-installed` roots live in a temp folder, so they never get offers.
|
|
197
|
+
*/
|
|
198
|
+
async function suggestSiblingEntries(state, err) {
|
|
199
|
+
const { target } = state;
|
|
200
|
+
if (state.nonInteractive ||
|
|
201
|
+
state.flags.fromInstalled ||
|
|
202
|
+
state.flags.update ||
|
|
203
|
+
target?.type !== 'asset' ||
|
|
204
|
+
!(isApiError(err, 'dependency_not_found') || isApiError(err, 'dependency_version_unsatisfied'))) {
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
const included = (d) => state.entries.some((e) => e.target.assetType === d.type && e.target.data.name === d.name);
|
|
208
|
+
const missing = missingDependencies(target.data, err.issues).filter((d) => !included(d));
|
|
209
|
+
if (missing.length === 0)
|
|
210
|
+
return undefined;
|
|
211
|
+
const rootDir = state.rawDetection?.sourceDir ?? target.sourceDir;
|
|
212
|
+
const suggested = await findSiblingDependencies(rootDir, missing, state.entries.map((e) => e.target.sourceDir), target.data.org);
|
|
213
|
+
return suggested.length > 0 ? { missing, suggested } : undefined;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Build an ERROR dispatch action from a caught value, carrying the `code`,
|
|
217
|
+
* `hint` and `command` typed errors have so commands can render actionable
|
|
218
|
+
* recovery guidance.
|
|
219
|
+
*/
|
|
220
|
+
function toErrorAction(err, override) {
|
|
221
|
+
return {
|
|
222
|
+
...errorGuidance(err),
|
|
223
|
+
message: override ?? errorMessage(err),
|
|
224
|
+
type: 'ERROR',
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Write what the run changed in memory to the manifests on disk: the root's bump and each
|
|
229
|
+
* entry's, and the tags and tools the prompts asked for. Only once the publish has opened its
|
|
230
|
+
* PR, so a cancelled or failed one leaves every manifest as it was. A file whose write fails
|
|
231
|
+
* takes none of its later edits and comes back as one warning naming the fields it lacks; the
|
|
232
|
+
* other files are still written.
|
|
233
|
+
*/
|
|
234
|
+
async function writeManifestEdits(state) {
|
|
235
|
+
const target = state.target;
|
|
236
|
+
if (!target)
|
|
237
|
+
return [];
|
|
238
|
+
const files = new Map();
|
|
239
|
+
const edit = (dir, file, field, value, write) => {
|
|
240
|
+
const path = join(dir, file);
|
|
241
|
+
files.set(path, [...(files.get(path) ?? []), { field, value, write }]);
|
|
242
|
+
};
|
|
243
|
+
const version = (dir, file, value) => edit(dir, file, 'version', value, () => updateManifestVersion(dir, file, value));
|
|
244
|
+
const field = (name, value) => edit(target.sourceDir, 'manifest.json', name, value, () => updateManifestField(target.sourceDir, 'manifest.json', name, value));
|
|
245
|
+
if (state.versionCheck?.status === 'needs-bump' && state.resolvedVersion) {
|
|
246
|
+
version(target.sourceDir, target.type === 'asset' ? 'manifest.json' : 'bundle.json', state.resolvedVersion);
|
|
247
|
+
}
|
|
248
|
+
// Only an asset's manifest.json takes the prompted tags and tools, as the target (and so the plan) has them.
|
|
249
|
+
if (target.type === 'asset') {
|
|
250
|
+
const { tags, tools } = target.data;
|
|
251
|
+
if (state.promptTagsValue && tags && tags.length > 0) {
|
|
252
|
+
field('tags', tags);
|
|
253
|
+
}
|
|
254
|
+
if (state.selectedPromptTools.length > 0) {
|
|
255
|
+
field('tools', tools);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
for (const entry of state.entries) {
|
|
259
|
+
if (entry.versionCheck?.status === 'needs-bump' && entry.resolvedVersion) {
|
|
260
|
+
version(entry.target.sourceDir, 'manifest.json', entry.resolvedVersion);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const unwritten = [];
|
|
264
|
+
for (const [path, edits] of files) {
|
|
265
|
+
const failed = await firstFailure(edits);
|
|
266
|
+
if (!failed)
|
|
267
|
+
continue;
|
|
268
|
+
const missing = edits.slice(failed.index);
|
|
269
|
+
// Only the version matters to the next publish: it asks for missing tags and tools again.
|
|
270
|
+
const again = missing.some((e) => e.field === 'version') ? ' before you publish it again' : '';
|
|
271
|
+
unwritten.push(`The PR is open, but ${path} wasn't updated (${errorMessage(failed.error)}): set ${missing.map((e) => `"${e.field}" to ${JSON.stringify(e.value)}`).join(', ')}${again}.`);
|
|
272
|
+
}
|
|
273
|
+
return unwritten;
|
|
274
|
+
}
|
|
275
|
+
// ---------------------------------------------------------------------------
|
|
276
|
+
// Steps, one per phase that waits on work
|
|
277
|
+
// ---------------------------------------------------------------------------
|
|
278
|
+
const resolvingInstalled = {
|
|
279
|
+
async run(state, ctx) {
|
|
280
|
+
const source = await findInstalledSource(state, ctx);
|
|
281
|
+
if (!source)
|
|
282
|
+
return;
|
|
283
|
+
const { adapter, installed, projectRoot } = source;
|
|
284
|
+
// Copy the installed files into a temp directory, preserving their source paths
|
|
285
|
+
const tempDir = await stageInstalledFiles(installed, adapter, projectRoot);
|
|
286
|
+
ctx.stage(tempDir);
|
|
287
|
+
if (ctx.cancelled())
|
|
288
|
+
return;
|
|
289
|
+
// Generate manifest.json in the temp dir
|
|
290
|
+
const manifest = {
|
|
291
|
+
author: 'unknown',
|
|
292
|
+
description: `Published from installed asset ${installed.name}`,
|
|
293
|
+
entrypoint: installed.files[0]?.sourcePath ?? 'index.md',
|
|
294
|
+
name: installed.name,
|
|
295
|
+
...(installed.org ? { org: installed.org } : {}),
|
|
296
|
+
type: installed.type,
|
|
297
|
+
version: installed.version,
|
|
298
|
+
};
|
|
299
|
+
await writeFile(join(tempDir, 'manifest.json'), JSON.stringify(manifest, null, 2) + '\n', 'utf-8');
|
|
300
|
+
ctx.dispatch({ resolvedPath: tempDir, type: 'RESOLVED_INSTALLED' });
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
const resolvingUpdate = {
|
|
304
|
+
async run(state, ctx) {
|
|
305
|
+
const source = await findInstalledSource(state, ctx);
|
|
306
|
+
if (!source)
|
|
307
|
+
return;
|
|
308
|
+
const { adapter, installed, org, projectRoot } = source;
|
|
309
|
+
const assetName = state.flags.rawPath;
|
|
310
|
+
// Fetch the registry to find the latest version. An installed entry is always an asset.
|
|
311
|
+
const registry = await fetchRegistry({ force: state.flags.refresh });
|
|
312
|
+
if (ctx.cancelled())
|
|
313
|
+
return;
|
|
314
|
+
const resolvedAsset = findAsset(registry, installed.name, installed.type, undefined, installed.org ?? org);
|
|
315
|
+
if (!resolvedAsset) {
|
|
316
|
+
ctx.dispatch({ message: `Asset '${assetName}' not found in the registry.`, type: 'ERROR' });
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
// The installed files go out on top of the latest's manifest, so they must not be older
|
|
320
|
+
// than it: they would publish the next version without the changes made since.
|
|
321
|
+
const latestVersion = resolvedAsset.version;
|
|
322
|
+
if (!semverValid(installed.version) || semverCompare(installed.version, latestVersion) < 0) {
|
|
323
|
+
ctx.dispatch({
|
|
324
|
+
command: `atk diff ${assetName}`,
|
|
325
|
+
hint: `See what changed since v${installed.version} with \`atk diff ${assetName}\`, get the latest into a folder with \`atk checkout ${assetName}\`, carry your edits into it, and publish that folder.`,
|
|
326
|
+
message: `'${assetName}' is installed at v${installed.version}, but the registry's latest is v${latestVersion}. --update would publish your copy, built on v${installed.version}, as the next version and undo the changes made since.`,
|
|
327
|
+
type: 'ERROR',
|
|
328
|
+
});
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
// The latest's manifest as the registry has it, byte for byte, so a field this CLI's schema
|
|
332
|
+
// doesn't know (from a newer publisher) is published again; and its README, if any.
|
|
333
|
+
const { org: assetOrg, type } = resolvedAsset.asset;
|
|
334
|
+
const ref = { name: installed.name, ...(assetOrg ? { org: assetOrg } : {}), type };
|
|
335
|
+
const [manifest, readme] = await Promise.all([
|
|
336
|
+
fetchAssetFileBytes(ref, latestVersion, 'manifest.json'),
|
|
337
|
+
fetchAssetReadme(ref, latestVersion),
|
|
338
|
+
]);
|
|
339
|
+
if (ctx.cancelled())
|
|
340
|
+
return;
|
|
341
|
+
// Copy the user's locally modified files into a temp staging directory
|
|
342
|
+
const tempDir = await stageInstalledFiles(installed, adapter, projectRoot);
|
|
343
|
+
ctx.stage(tempDir);
|
|
344
|
+
if (ctx.cancelled())
|
|
345
|
+
return;
|
|
346
|
+
await writeFile(join(tempDir, 'manifest.json'), manifest);
|
|
347
|
+
if (readme) {
|
|
348
|
+
await writeFile(join(tempDir, 'README.md'), readme, 'utf-8');
|
|
349
|
+
}
|
|
350
|
+
ctx.dispatch({ resolvedPath: tempDir, type: 'RESOLVED_UPDATE' });
|
|
351
|
+
},
|
|
352
|
+
};
|
|
353
|
+
const detecting = {
|
|
354
|
+
async run(state, ctx) {
|
|
355
|
+
// A batch reads every folder now; any that is missing, a bundle or not an asset folder
|
|
356
|
+
// fails here, all of them together, before any prompt.
|
|
357
|
+
if (isBatch(state.flags)) {
|
|
358
|
+
const { entries, root } = await loadPublishBatch(state.flags.paths ?? [], state.flags.withPaths);
|
|
359
|
+
if (ctx.cancelled())
|
|
360
|
+
return;
|
|
361
|
+
ctx.dispatch({ entries, type: 'ENTRIES_LOADED' });
|
|
362
|
+
ctx.dispatch({ target: root.target, type: 'DETECT_DONE' });
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
// A --with folder that is missing, a bundle, the root or a repeat fails here, before any
|
|
366
|
+
// prompt; its validation and version check come in checking-entries.
|
|
367
|
+
if (state.flags.withPaths?.length) {
|
|
368
|
+
const entries = await loadPublishEntries(state.flags.withPaths, state.resolvedPath);
|
|
369
|
+
if (ctx.cancelled())
|
|
370
|
+
return;
|
|
371
|
+
ctx.dispatch({ entries, type: 'ENTRIES_LOADED' });
|
|
372
|
+
}
|
|
373
|
+
// First, try manifest-based detection (existing flow)
|
|
374
|
+
try {
|
|
375
|
+
const detected = await detectPublishType(state.resolvedPath);
|
|
376
|
+
if (ctx.cancelled())
|
|
377
|
+
return;
|
|
378
|
+
ctx.dispatch({ target: detected, type: 'DETECT_DONE' });
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
catch (manifestError) {
|
|
382
|
+
// Only attempt raw detection if the error is specifically about missing manifest/bundle
|
|
383
|
+
const manifestMsg = errorMessage(manifestError);
|
|
384
|
+
if (!manifestMsg.includes('No manifest.json or bundle.json found')) {
|
|
385
|
+
// This is a different error (e.g., invalid JSON in manifest) — surface it directly
|
|
386
|
+
ctx.dispatch({ message: manifestMsg, type: 'ERROR' });
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
// Manifest not found — attempt raw asset detection
|
|
391
|
+
const resolvedTools = await resolveTools(state.flags.tool);
|
|
392
|
+
const adapter = resolvedTools[0].adapter;
|
|
393
|
+
if (ctx.cancelled())
|
|
394
|
+
return;
|
|
395
|
+
const projectRoot = findProjectRoot(state.flags.projectRoot);
|
|
396
|
+
const detection = await detectAssetFromPath(state.resolvedPath, adapter, projectRoot);
|
|
397
|
+
if (ctx.cancelled())
|
|
398
|
+
return;
|
|
399
|
+
// Pre-fill metadata
|
|
400
|
+
const author = (await getSignedInUserName()) ?? '';
|
|
401
|
+
if (ctx.cancelled())
|
|
402
|
+
return;
|
|
403
|
+
const lockfile = await readLockfile(projectRoot);
|
|
404
|
+
if (ctx.cancelled())
|
|
405
|
+
return;
|
|
406
|
+
const tools = await detectCompatibleTools(detection.assetType);
|
|
407
|
+
if (ctx.cancelled())
|
|
408
|
+
return;
|
|
409
|
+
// Non-interactive mode (raw publish — no manifest exists yet, so the only
|
|
410
|
+
// sources for description are --description flag or exit-1; tags come from
|
|
411
|
+
// --tags or default to empty). Tool detection runs for both modes above.
|
|
412
|
+
if (!state.nonInteractive) {
|
|
413
|
+
// Interactive mode — gather metadata from the user
|
|
414
|
+
ctx.dispatch({
|
|
415
|
+
authorValue: author,
|
|
416
|
+
orgValue: lockfile.org ?? '',
|
|
417
|
+
rawDetection: detection,
|
|
418
|
+
toolsDetected: tools,
|
|
419
|
+
type: 'RAW_DETECT_DONE',
|
|
420
|
+
});
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (!state.flags.descriptionFlag) {
|
|
424
|
+
ctx.dispatch({
|
|
425
|
+
message: 'description required: provide --description or include in manifest.json',
|
|
426
|
+
type: 'ERROR',
|
|
427
|
+
});
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
// Tools resolution: --tools flag -> detected (already populated above)
|
|
431
|
+
let toolsList;
|
|
432
|
+
if (state.flags.toolsFlag) {
|
|
433
|
+
toolsList = splitList(state.flags.toolsFlag);
|
|
434
|
+
}
|
|
435
|
+
else if (tools.length > 0) {
|
|
436
|
+
toolsList = tools;
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
ctx.dispatch({
|
|
440
|
+
message: `--tools <comma-separated> required: no tools detected for type ${detection.assetType}`,
|
|
441
|
+
type: 'ERROR',
|
|
442
|
+
});
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const stagingDir = await buildStagingArea(detection, {
|
|
446
|
+
author,
|
|
447
|
+
description: state.flags.descriptionFlag,
|
|
448
|
+
...(lockfile.org ? { org: lockfile.org } : {}),
|
|
449
|
+
tags: splitList(state.flags.tagsFlag),
|
|
450
|
+
tools: toolsList,
|
|
451
|
+
});
|
|
452
|
+
ctx.stage(stagingDir);
|
|
453
|
+
if (ctx.cancelled())
|
|
454
|
+
return;
|
|
455
|
+
const detected = await detectPublishType(stagingDir);
|
|
456
|
+
if (ctx.cancelled())
|
|
457
|
+
return;
|
|
458
|
+
ctx.dispatch({ rawDetection: detection, target: detected, type: 'RAW_DETECT_DONE_NON_INTERACTIVE' });
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
/** The `building-staging` sub-phase of `gathering-metadata`: the manifest from the prompts' answers. */
|
|
462
|
+
const buildingStaging = {
|
|
463
|
+
async run(state, ctx) {
|
|
464
|
+
const stagingDir = await buildStagingArea(state.rawDetection, {
|
|
465
|
+
author: state.authorValue,
|
|
466
|
+
description: state.descriptionValue,
|
|
467
|
+
org: state.orgValue || undefined,
|
|
468
|
+
tags: splitList(state.tagsValue),
|
|
469
|
+
tools: state.toolsDetected,
|
|
470
|
+
});
|
|
471
|
+
ctx.stage(stagingDir);
|
|
472
|
+
if (ctx.cancelled())
|
|
473
|
+
return;
|
|
474
|
+
// Re-detect using the staging area (now has manifest.json)
|
|
475
|
+
const detectedTarget = await detectPublishType(stagingDir);
|
|
476
|
+
if (ctx.cancelled())
|
|
477
|
+
return;
|
|
478
|
+
ctx.dispatch({ target: detectedTarget, type: 'STAGING_DONE' });
|
|
479
|
+
},
|
|
480
|
+
};
|
|
481
|
+
const validating = {
|
|
482
|
+
async run(state, ctx) {
|
|
483
|
+
const target = state.target;
|
|
484
|
+
if (!target)
|
|
485
|
+
return;
|
|
486
|
+
let lockfileOrg;
|
|
487
|
+
let lockfileOrgReviewers;
|
|
488
|
+
try {
|
|
489
|
+
const projectRoot = findProjectRoot(state.flags.projectRoot);
|
|
490
|
+
const lockfile = await readLockfile(projectRoot);
|
|
491
|
+
lockfileOrg = lockfile.org;
|
|
492
|
+
lockfileOrgReviewers = lockfile.orgReviewers;
|
|
493
|
+
}
|
|
494
|
+
catch {
|
|
495
|
+
// No project root / lockfile — treat as no lockfile org / reviewers
|
|
496
|
+
}
|
|
497
|
+
if (ctx.cancelled())
|
|
498
|
+
return;
|
|
499
|
+
// Bundles need the registry so their asset refs can be resolved during
|
|
500
|
+
// validation — an unresolvable ref must fail here, not at install time.
|
|
501
|
+
let registry;
|
|
502
|
+
if (target.type === 'bundle') {
|
|
503
|
+
registry = await fetchRegistry({ force: state.flags.refresh });
|
|
504
|
+
if (ctx.cancelled())
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
const result = await validatePublishTarget(target, {
|
|
508
|
+
force: state.flags.force,
|
|
509
|
+
lockfileOrg,
|
|
510
|
+
registry,
|
|
511
|
+
});
|
|
512
|
+
if (ctx.cancelled())
|
|
513
|
+
return;
|
|
514
|
+
// A batch checks every asset before stopping, so one run lists every folder's problems.
|
|
515
|
+
if (isBatch(state.flags)) {
|
|
516
|
+
const entries = [];
|
|
517
|
+
for (const entry of state.entries) {
|
|
518
|
+
const validation = await validatePublishTarget(entry.target, { force: state.flags.force, lockfileOrg });
|
|
519
|
+
if (ctx.cancelled())
|
|
520
|
+
return;
|
|
521
|
+
entries.push({ ...entry, validation });
|
|
522
|
+
}
|
|
523
|
+
const failed = [{ label: state.flags.rawPath, validation: result }, ...entries].filter((f) => f.validation && !f.validation.valid);
|
|
524
|
+
if (failed.length > 0) {
|
|
525
|
+
const lines = failed.flatMap((f) => [
|
|
526
|
+
` ${f.label}:`,
|
|
527
|
+
...(f.validation?.errors ?? []).map((e) => ` - ${e}`),
|
|
528
|
+
]);
|
|
529
|
+
ctx.dispatch({ message: `Validation failed:\n${lines.join('\n')}`, type: 'ERROR' });
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
// checking-entries keeps these instead of validating each entry again.
|
|
533
|
+
ctx.dispatch({ entries, type: 'ENTRIES_LOADED' });
|
|
534
|
+
}
|
|
535
|
+
ctx.dispatch({ lockfileOrgReviewers, type: 'VALIDATE_DONE', validation: result });
|
|
536
|
+
},
|
|
537
|
+
};
|
|
538
|
+
/**
|
|
539
|
+
* In interactive mode, loads adapters for the multi-select prompt. In non-interactive
|
|
540
|
+
* mode, resolves tools via manifest -> --tools flag -> detectCompatibleTools(assetType)
|
|
541
|
+
* -> exit 1, then dispatches RESOLVE_TOOLS_NONINTERACTIVE to advance directly to
|
|
542
|
+
* checking-registry.
|
|
543
|
+
*/
|
|
544
|
+
const loadingTools = {
|
|
545
|
+
async run(state, ctx) {
|
|
546
|
+
if (!state.nonInteractive) {
|
|
547
|
+
const adapters = await loadAllAdapters();
|
|
548
|
+
if (ctx.cancelled())
|
|
549
|
+
return;
|
|
550
|
+
ctx.dispatch({ adapters, type: 'TOOLS_LOADED' });
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
// Manifest tools win when present (VALIDATE_DONE only routes here when
|
|
554
|
+
// manifest tools are missing for assets — bundles short-circuit hasTools).
|
|
555
|
+
if (state.target?.type !== 'asset') {
|
|
556
|
+
// Bundles don't carry tools — just advance.
|
|
557
|
+
ctx.dispatch({ tools: [], type: 'RESOLVE_TOOLS_NONINTERACTIVE' });
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
// Try --tools flag
|
|
561
|
+
let resolvedToolList = splitList(state.flags.toolsFlag);
|
|
562
|
+
if (state.flags.toolsFlag) {
|
|
563
|
+
// Validation ran before these tools were filled in, so check them here.
|
|
564
|
+
const toolsError = await unknownToolsError(resolvedToolList);
|
|
565
|
+
if (ctx.cancelled())
|
|
566
|
+
return;
|
|
567
|
+
if (toolsError) {
|
|
568
|
+
ctx.dispatch({ message: `--tools: ${toolsError}`, type: 'ERROR' });
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
// Fall back to detectCompatibleTools
|
|
573
|
+
if (resolvedToolList.length === 0) {
|
|
574
|
+
const assetType = state.target.assetType;
|
|
575
|
+
if (!assetType) {
|
|
576
|
+
ctx.dispatch({
|
|
577
|
+
message: '--tools <comma-separated> required: no tools detected for type unknown',
|
|
578
|
+
type: 'ERROR',
|
|
579
|
+
});
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
const detected = await detectCompatibleTools(assetType);
|
|
583
|
+
if (ctx.cancelled())
|
|
584
|
+
return;
|
|
585
|
+
if (detected.length === 0) {
|
|
586
|
+
ctx.dispatch({
|
|
587
|
+
message: `--tools <comma-separated> required: no tools detected for type ${assetType}`,
|
|
588
|
+
type: 'ERROR',
|
|
589
|
+
});
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
resolvedToolList = detected;
|
|
593
|
+
}
|
|
594
|
+
ctx.dispatch({ tools: resolvedToolList, type: 'RESOLVE_TOOLS_NONINTERACTIVE' });
|
|
595
|
+
},
|
|
596
|
+
};
|
|
597
|
+
const checkingRegistry = {
|
|
598
|
+
async fail(err) {
|
|
599
|
+
return toErrorAction(err, mapPublishError(err));
|
|
600
|
+
},
|
|
601
|
+
async run(state, ctx) {
|
|
602
|
+
const target = state.target;
|
|
603
|
+
if (!target)
|
|
604
|
+
return;
|
|
605
|
+
const authToken = (await getCredential()).token;
|
|
606
|
+
if (ctx.cancelled())
|
|
607
|
+
return;
|
|
608
|
+
const reg = await fetchRegistry({ force: state.flags.refresh });
|
|
609
|
+
if (ctx.cancelled())
|
|
610
|
+
return;
|
|
611
|
+
const versionResult = checkRegistryVersion(target, reg);
|
|
612
|
+
// A version the registry doesn't have yet is published as it is; needs-bump settles it later.
|
|
613
|
+
const isUpdate = versionResult.status !== 'new-asset';
|
|
614
|
+
const resolvedVersion = versionResult.status === 'needs-bump' ? '' : target.data.version;
|
|
615
|
+
ctx.dispatch({
|
|
616
|
+
isUpdate,
|
|
617
|
+
resolvedVersion,
|
|
618
|
+
token: authToken,
|
|
619
|
+
type: 'REGISTRY_CHECK_DONE',
|
|
620
|
+
versionCheck: versionResult,
|
|
621
|
+
});
|
|
622
|
+
},
|
|
623
|
+
};
|
|
624
|
+
/**
|
|
625
|
+
* Validate each entry not yet checked the same way as the root asset, and check its
|
|
626
|
+
* version against the registry; advanceToPlan then settles any bump it needs.
|
|
627
|
+
*/
|
|
628
|
+
const checkingEntries = {
|
|
629
|
+
async fail(err) {
|
|
630
|
+
return toErrorAction(err, mapPublishError(err));
|
|
631
|
+
},
|
|
632
|
+
async run(state, ctx) {
|
|
633
|
+
let lockfileOrg;
|
|
634
|
+
try {
|
|
635
|
+
lockfileOrg = (await readLockfile(findProjectRoot(state.flags.projectRoot))).org;
|
|
636
|
+
}
|
|
637
|
+
catch {
|
|
638
|
+
// No project root / lockfile — treat as no lockfile org
|
|
639
|
+
}
|
|
640
|
+
const registry = await fetchRegistry({ force: state.flags.refresh });
|
|
641
|
+
if (ctx.cancelled())
|
|
642
|
+
return;
|
|
643
|
+
const entries = [];
|
|
644
|
+
for (const entry of state.entries) {
|
|
645
|
+
if (entry.versionCheck) {
|
|
646
|
+
entries.push(entry);
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
const validation = entry.validation ?? (await validatePublishTarget(entry.target, { force: state.flags.force, lockfileOrg }));
|
|
650
|
+
if (ctx.cancelled())
|
|
651
|
+
return;
|
|
652
|
+
if (!validation.valid) {
|
|
653
|
+
ctx.dispatch({
|
|
654
|
+
message: `Validation failed for ${entry.label}:\n${validation.errors.map((e) => ` - ${e}`).join('\n')}`,
|
|
655
|
+
type: 'ERROR',
|
|
656
|
+
});
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
const versionCheck = checkRegistryVersion(entry.target, registry);
|
|
660
|
+
entries.push({
|
|
661
|
+
...entry,
|
|
662
|
+
...(versionCheck.status === 'needs-bump' ? {} : { resolvedVersion: entry.target.data.version }),
|
|
663
|
+
validation,
|
|
664
|
+
versionCheck,
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
ctx.dispatch({ entries, type: 'ENTRIES_CHECKED' });
|
|
668
|
+
},
|
|
669
|
+
};
|
|
670
|
+
/**
|
|
671
|
+
* Plans from the targets in memory, which carry every bump and prompted tag or tool:
|
|
672
|
+
* nothing is written to a manifest until the publish succeeds (writeManifestEdits).
|
|
673
|
+
*/
|
|
674
|
+
const buildingPlan = {
|
|
675
|
+
async fail(err, state, ctx) {
|
|
676
|
+
// Worded like the publishing phase: resolvePlanDependencies calls the same API.
|
|
677
|
+
const error = toErrorAction(err, mapPublishError(err, entryLabels(state), batchRootLabel(state)));
|
|
678
|
+
const suggestion = await suggestSiblingEntries(state, err).catch(() => undefined);
|
|
679
|
+
if (ctx.cancelled())
|
|
680
|
+
return undefined;
|
|
681
|
+
return suggestion ? { error, ...suggestion, type: 'SUGGEST_ENTRIES' } : error;
|
|
682
|
+
},
|
|
683
|
+
async run(state, ctx) {
|
|
684
|
+
const currentTarget = state.target;
|
|
685
|
+
if (!currentTarget)
|
|
686
|
+
return;
|
|
687
|
+
const currentVersion = state.resolvedVersion;
|
|
688
|
+
// Reject invalid reviewer usernames here, before any branch/commit/push work happens
|
|
689
|
+
const reviewers = parseReviewersInput(state.reviewerValue);
|
|
690
|
+
for (const reviewer of reviewers) {
|
|
691
|
+
const check = validateGithubUsername(reviewer);
|
|
692
|
+
if (!check.valid) {
|
|
693
|
+
throw new Error(check.error);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
const entries = state.entries.map((entry) => ({ label: entry.label, target: entry.target }));
|
|
697
|
+
const localPlan = await buildPublishPlan(currentTarget, currentVersion, state.isUpdate, state.flags.message, reviewers, entries, ...(isBatch(state.flags) ? [state.flags.rawPath] : []));
|
|
698
|
+
if (ctx.cancelled())
|
|
699
|
+
return;
|
|
700
|
+
// Ask the API for its plan now, so the preview and --dry-run show its dependencies
|
|
701
|
+
// and reviewers, and anything it rejects stops before the confirm prompt.
|
|
702
|
+
const publishPlan = await resolvePlanDependencies(localPlan);
|
|
703
|
+
if (ctx.cancelled())
|
|
704
|
+
return;
|
|
705
|
+
let manifestDiff;
|
|
706
|
+
if (state.isUpdate && state.versionCheck && state.versionCheck.status !== 'new-asset' && state.token) {
|
|
707
|
+
const existing = await fetchExistingManifest(currentTarget, state.versionCheck.latestVersion);
|
|
708
|
+
if (ctx.cancelled())
|
|
709
|
+
return;
|
|
710
|
+
if (existing) {
|
|
711
|
+
manifestDiff = diffManifests(existing, currentTarget.data);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
ctx.dispatch({ manifestDiff, plan: publishPlan, type: 'PLAN_DONE' });
|
|
715
|
+
},
|
|
716
|
+
};
|
|
717
|
+
const publishing = {
|
|
718
|
+
async fail(err, state) {
|
|
719
|
+
return toErrorAction(err, mapPublishError(err, entryLabels(state), batchRootLabel(state)));
|
|
720
|
+
},
|
|
721
|
+
async run(state, ctx) {
|
|
722
|
+
const plan = state.plan;
|
|
723
|
+
if (!plan || !state.token)
|
|
724
|
+
return;
|
|
725
|
+
const published = await executePublish(plan, (message) => ctx.dispatch({ message, type: 'PUBLISH_PROGRESS' }));
|
|
726
|
+
// The PR is open, so the folders take its versions, tags and tools even if the run was cancelled meanwhile.
|
|
727
|
+
const unwritten = await writeManifestEdits(state);
|
|
728
|
+
if (ctx.cancelled())
|
|
729
|
+
return;
|
|
730
|
+
const result = unwritten.length > 0 ? { ...published, warnings: [...(published.warnings ?? []), ...unwritten] } : published;
|
|
731
|
+
// Clear registry cache so subsequent commands see the new version
|
|
732
|
+
try {
|
|
733
|
+
await clearCache();
|
|
734
|
+
}
|
|
735
|
+
catch {
|
|
736
|
+
// Best-effort — don't fail publish over cache
|
|
737
|
+
}
|
|
738
|
+
// The lockfile is left as it was, even for an installed asset or a raw folder: the registry
|
|
739
|
+
// has the new version only once the PR merges, and a fresh clone installs the version the
|
|
740
|
+
// lockfile names (ATK-592). `atk update` (or `atk install`) records it after the merge.
|
|
741
|
+
if (ctx.cancelled())
|
|
742
|
+
return;
|
|
743
|
+
ctx.dispatch({ result, type: 'PUBLISH_DONE' });
|
|
744
|
+
},
|
|
745
|
+
};
|
|
746
|
+
// ---------------------------------------------------------------------------
|
|
747
|
+
// Reducer
|
|
748
|
+
// ---------------------------------------------------------------------------
|
|
749
|
+
export function publishReducer(state, action) {
|
|
750
|
+
switch (action.type) {
|
|
751
|
+
case 'BUMP_DONE': {
|
|
752
|
+
const bumped = {
|
|
753
|
+
...state,
|
|
754
|
+
errorMessage: action.message ? action.message : state.errorMessage,
|
|
755
|
+
resolvedVersion: action.version,
|
|
756
|
+
target: action.updatedTarget,
|
|
757
|
+
};
|
|
758
|
+
return action.message ? { ...bumped, phase: 'error' } : advanceToPlan(bumped);
|
|
759
|
+
}
|
|
760
|
+
case 'CONFIRM_PROMPT_TOOLS': {
|
|
761
|
+
if (action.tools.length === 0)
|
|
762
|
+
return state;
|
|
763
|
+
const updatedToolsTarget = state.target
|
|
764
|
+
? {
|
|
765
|
+
...state.target,
|
|
766
|
+
data: { ...state.target.data, tools: action.tools },
|
|
767
|
+
}
|
|
768
|
+
: undefined;
|
|
769
|
+
return {
|
|
770
|
+
...state,
|
|
771
|
+
phase: phaseAfterMetadata(updatedToolsTarget),
|
|
772
|
+
selectedPromptTools: action.tools,
|
|
773
|
+
target: updatedToolsTarget,
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
case 'DETECT_DONE':
|
|
777
|
+
if (action.target.type === 'bundle' && state.entries.length > 0) {
|
|
778
|
+
return {
|
|
779
|
+
...state,
|
|
780
|
+
errorMessage: 'A bundle is published on its own. Remove --with, and publish its new assets first.',
|
|
781
|
+
phase: 'error',
|
|
782
|
+
target: action.target,
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
return {
|
|
786
|
+
...state,
|
|
787
|
+
phase: 'validating',
|
|
788
|
+
target: action.target,
|
|
789
|
+
};
|
|
790
|
+
case 'ENTRIES_CHECKED':
|
|
791
|
+
return advanceToPlan({ ...state, entries: action.entries });
|
|
792
|
+
case 'ENTRIES_LOADED':
|
|
793
|
+
return { ...state, entries: action.entries };
|
|
794
|
+
case 'ERROR':
|
|
795
|
+
return {
|
|
796
|
+
...state,
|
|
797
|
+
errorCode: action.code,
|
|
798
|
+
errorCommand: action.command,
|
|
799
|
+
errorHint: action.hint,
|
|
800
|
+
errorMessage: action.message,
|
|
801
|
+
phase: 'error',
|
|
802
|
+
};
|
|
803
|
+
case 'PLAN_DONE': {
|
|
804
|
+
// dry-run always shows the dry-run result; --yes / non-TTY skip the confirm prompt
|
|
805
|
+
// and proceed directly to publishing.
|
|
806
|
+
let nextPhase;
|
|
807
|
+
if (state.flags.dryRun) {
|
|
808
|
+
nextPhase = 'dry-run-result';
|
|
809
|
+
}
|
|
810
|
+
else if (state.nonInteractive) {
|
|
811
|
+
nextPhase = 'publishing';
|
|
812
|
+
}
|
|
813
|
+
else {
|
|
814
|
+
nextPhase = 'confirm-publish';
|
|
815
|
+
}
|
|
816
|
+
return {
|
|
817
|
+
...state,
|
|
818
|
+
manifestDiff: action.manifestDiff,
|
|
819
|
+
phase: nextPhase,
|
|
820
|
+
plan: action.plan,
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
case 'PUBLISH_DONE':
|
|
824
|
+
return { ...state, phase: 'done', publishResult: action.result };
|
|
825
|
+
case 'PUBLISH_PROGRESS':
|
|
826
|
+
return { ...state, progressMessage: action.message };
|
|
827
|
+
case 'RAW_DETECT_DONE':
|
|
828
|
+
return {
|
|
829
|
+
...state,
|
|
830
|
+
authorValue: action.authorValue,
|
|
831
|
+
isRawPublish: true,
|
|
832
|
+
orgValue: action.orgValue,
|
|
833
|
+
phase: 'gathering-metadata',
|
|
834
|
+
rawDetection: action.rawDetection,
|
|
835
|
+
toolsDetected: action.toolsDetected,
|
|
836
|
+
};
|
|
837
|
+
case 'RAW_DETECT_DONE_NON_INTERACTIVE':
|
|
838
|
+
return {
|
|
839
|
+
...state,
|
|
840
|
+
isRawPublish: true,
|
|
841
|
+
phase: 'validating',
|
|
842
|
+
rawDetection: action.rawDetection,
|
|
843
|
+
target: action.target,
|
|
844
|
+
};
|
|
845
|
+
case 'REGISTRY_CHECK_DONE': {
|
|
846
|
+
const { isUpdate, resolvedVersion, token, versionCheck } = action;
|
|
847
|
+
let nextPhase;
|
|
848
|
+
let errorMessage = state.errorMessage;
|
|
849
|
+
let bumpedVersion = resolvedVersion;
|
|
850
|
+
let bumpedTarget = state.target;
|
|
851
|
+
if (versionCheck.status === 'new-asset') {
|
|
852
|
+
nextPhase = 'building-plan';
|
|
853
|
+
}
|
|
854
|
+
else if (versionCheck.status === 'version-already-bumped') {
|
|
855
|
+
// --yes / non-TTY implicitly confirm the update
|
|
856
|
+
nextPhase = state.nonInteractive ? 'building-plan' : 'confirm-update';
|
|
857
|
+
}
|
|
858
|
+
else {
|
|
859
|
+
// needs-bump
|
|
860
|
+
if (state.nonInteractive) {
|
|
861
|
+
if (state.flags.bump && state.target) {
|
|
862
|
+
// Auto-bump using the flag value; a successful publish writes it to the manifest
|
|
863
|
+
try {
|
|
864
|
+
bumpedVersion = bumpVersion(versionCheck.latestVersion, state.flags.bump);
|
|
865
|
+
bumpedTarget = {
|
|
866
|
+
...state.target,
|
|
867
|
+
data: { ...state.target.data, version: bumpedVersion },
|
|
868
|
+
};
|
|
869
|
+
nextPhase = 'building-plan';
|
|
870
|
+
}
|
|
871
|
+
catch {
|
|
872
|
+
errorMessage = 'Failed to compute bumped version.';
|
|
873
|
+
nextPhase = 'error';
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
else if (isBatch(state.flags)) {
|
|
877
|
+
// advanceToPlan lists every asset of the batch that needs --bump, once the entries are checked.
|
|
878
|
+
nextPhase = 'building-plan';
|
|
879
|
+
}
|
|
880
|
+
else {
|
|
881
|
+
errorMessage = `--bump <patch|minor|major> required: registry has v${versionCheck.latestVersion} but manifest is not newer`;
|
|
882
|
+
nextPhase = 'error';
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
else {
|
|
886
|
+
nextPhase = 'bump-prompt';
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
const checked = {
|
|
890
|
+
...state,
|
|
891
|
+
errorMessage,
|
|
892
|
+
isUpdate,
|
|
893
|
+
phase: nextPhase,
|
|
894
|
+
resolvedVersion: bumpedVersion,
|
|
895
|
+
target: bumpedTarget,
|
|
896
|
+
token,
|
|
897
|
+
versionCheck,
|
|
898
|
+
};
|
|
899
|
+
return nextPhase === 'building-plan' ? advanceToPlan(checked) : checked;
|
|
900
|
+
}
|
|
901
|
+
case 'RESOLVE_TOOLS_NONINTERACTIVE': {
|
|
902
|
+
const updatedTarget = state.target
|
|
903
|
+
? {
|
|
904
|
+
...state.target,
|
|
905
|
+
data: { ...state.target.data, tools: action.tools },
|
|
906
|
+
}
|
|
907
|
+
: undefined;
|
|
908
|
+
return {
|
|
909
|
+
...state,
|
|
910
|
+
phase: 'checking-registry',
|
|
911
|
+
target: updatedTarget,
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
case 'RESOLVED_INSTALLED':
|
|
915
|
+
return {
|
|
916
|
+
...state,
|
|
917
|
+
phase: 'detecting',
|
|
918
|
+
resolvedPath: action.resolvedPath,
|
|
919
|
+
};
|
|
920
|
+
case 'RESOLVED_UPDATE':
|
|
921
|
+
return {
|
|
922
|
+
...state,
|
|
923
|
+
phase: 'detecting',
|
|
924
|
+
resolvedPath: action.resolvedPath,
|
|
925
|
+
};
|
|
926
|
+
case 'SET_BUMP_SELECTION':
|
|
927
|
+
return { ...state, bumpSelection: action.value };
|
|
928
|
+
case 'SET_CONFIRM_VALUE':
|
|
929
|
+
return { ...state, confirmValue: action.value };
|
|
930
|
+
case 'SET_DESCRIPTION':
|
|
931
|
+
return { ...state, descriptionValue: action.value };
|
|
932
|
+
case 'SET_PROMPT_TAGS':
|
|
933
|
+
return { ...state, promptTagsValue: action.value };
|
|
934
|
+
case 'SET_PUBLISH_CONFIRM_VALUE':
|
|
935
|
+
return { ...state, publishConfirmValue: action.value };
|
|
936
|
+
case 'SET_REVIEWER':
|
|
937
|
+
return { ...state, reviewerValue: action.value };
|
|
938
|
+
case 'SET_TAGS':
|
|
939
|
+
return { ...state, tagsValue: action.value };
|
|
940
|
+
case 'SET_WITH_CONFIRM_VALUE':
|
|
941
|
+
return { ...state, withConfirmValue: action.value };
|
|
942
|
+
case 'STAGING_DONE':
|
|
943
|
+
return {
|
|
944
|
+
...state,
|
|
945
|
+
phase: 'validating',
|
|
946
|
+
target: action.target,
|
|
947
|
+
};
|
|
948
|
+
case 'SUBMIT_BUMP': {
|
|
949
|
+
const trimmed = state.bumpSelection.trim().toLowerCase();
|
|
950
|
+
if (trimmed !== 'patch' && trimmed !== 'minor' && trimmed !== 'major') {
|
|
951
|
+
return state; // Ignore invalid input
|
|
952
|
+
}
|
|
953
|
+
// The prompt is for an entry: bump it, then on to the next pending bump or the plan.
|
|
954
|
+
if (state.bumpEntry !== undefined) {
|
|
955
|
+
const entry = state.entries[state.bumpEntry];
|
|
956
|
+
if (entry?.versionCheck?.status !== 'needs-bump')
|
|
957
|
+
return state;
|
|
958
|
+
return bumpEntryAt({ ...state, bumpSelection: '' }, state.bumpEntry, trimmed);
|
|
959
|
+
}
|
|
960
|
+
if (!state.target || !state.versionCheck || state.versionCheck.status !== 'needs-bump') {
|
|
961
|
+
return state;
|
|
962
|
+
}
|
|
963
|
+
// Compute the bumped version in the reducer (pure, synchronous)
|
|
964
|
+
const bumpType = trimmed;
|
|
965
|
+
try {
|
|
966
|
+
const newVersion = bumpVersion(state.versionCheck.latestVersion, bumpType);
|
|
967
|
+
// The bump is only on the target until the publish succeeds, which writes it to
|
|
968
|
+
// the manifest; entries still to check or bump come first.
|
|
969
|
+
return advanceToPlan({
|
|
970
|
+
...state,
|
|
971
|
+
bumpSelection: '',
|
|
972
|
+
resolvedVersion: newVersion,
|
|
973
|
+
target: { ...state.target, data: { ...state.target.data, version: newVersion } },
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
catch {
|
|
977
|
+
return {
|
|
978
|
+
...state,
|
|
979
|
+
errorMessage: 'Failed to compute bumped version.',
|
|
980
|
+
phase: 'error',
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
case 'SUBMIT_CONFIRM': {
|
|
985
|
+
const trimmed = state.confirmValue.trim().toLowerCase();
|
|
986
|
+
if (trimmed === 'y' || trimmed === 'yes') {
|
|
987
|
+
return advanceToPlan(state);
|
|
988
|
+
}
|
|
989
|
+
else if (trimmed === 'n' || trimmed === 'no') {
|
|
990
|
+
return { ...state, errorMessage: 'Publish cancelled.', phase: 'error' };
|
|
991
|
+
}
|
|
992
|
+
// Otherwise ignore (wait for valid input)
|
|
993
|
+
return state;
|
|
994
|
+
}
|
|
995
|
+
case 'SUBMIT_DESCRIPTION': {
|
|
996
|
+
const trimmed = state.descriptionValue.trim();
|
|
997
|
+
if (!trimmed)
|
|
998
|
+
return state; // Don't allow empty description
|
|
999
|
+
return {
|
|
1000
|
+
...state,
|
|
1001
|
+
descriptionValue: trimmed,
|
|
1002
|
+
metadataSubPhase: 'tags',
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
case 'SUBMIT_PROMPT_TAGS': {
|
|
1006
|
+
const parsedTags = splitList(state.promptTagsValue);
|
|
1007
|
+
// Update the target's data with the new tags
|
|
1008
|
+
const updatedTagsTarget = state.target
|
|
1009
|
+
? {
|
|
1010
|
+
...state.target,
|
|
1011
|
+
data: { ...state.target.data, tags: parsedTags.length > 0 ? parsedTags : undefined },
|
|
1012
|
+
}
|
|
1013
|
+
: undefined;
|
|
1014
|
+
// Check if tools are also missing (only for assets)
|
|
1015
|
+
const needsToolsPrompt = updatedTagsTarget?.type === 'asset' &&
|
|
1016
|
+
(!('tools' in updatedTagsTarget.data) ||
|
|
1017
|
+
!Array.isArray(updatedTagsTarget.data.tools) ||
|
|
1018
|
+
(updatedTagsTarget.data.tools?.length ?? 0) === 0);
|
|
1019
|
+
const nextTagsPhase = needsToolsPrompt ? 'loading-tools' : phaseAfterMetadata(updatedTagsTarget);
|
|
1020
|
+
return {
|
|
1021
|
+
...state,
|
|
1022
|
+
phase: nextTagsPhase,
|
|
1023
|
+
target: updatedTagsTarget,
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
case 'SUBMIT_PUBLISH_CONFIRM': {
|
|
1027
|
+
const trimmed = state.publishConfirmValue.trim().toLowerCase();
|
|
1028
|
+
if (trimmed === 'y' || trimmed === 'yes') {
|
|
1029
|
+
return { ...state, phase: 'publishing' };
|
|
1030
|
+
}
|
|
1031
|
+
else if (trimmed === 'n' || trimmed === 'no') {
|
|
1032
|
+
return { ...state, errorMessage: 'Publish cancelled.', phase: 'error' };
|
|
1033
|
+
}
|
|
1034
|
+
// Otherwise ignore (wait for valid input)
|
|
1035
|
+
return state;
|
|
1036
|
+
}
|
|
1037
|
+
case 'SUBMIT_REVIEWER':
|
|
1038
|
+
return { ...state, phase: 'checking-registry' };
|
|
1039
|
+
case 'SUBMIT_TAGS':
|
|
1040
|
+
return {
|
|
1041
|
+
...state,
|
|
1042
|
+
metadataSubPhase: 'building-staging',
|
|
1043
|
+
};
|
|
1044
|
+
case 'SUBMIT_WITH_CONFIRM': {
|
|
1045
|
+
const trimmed = state.withConfirmValue.trim().toLowerCase();
|
|
1046
|
+
if (trimmed === 'y' || trimmed === 'yes') {
|
|
1047
|
+
return advanceToPlan({
|
|
1048
|
+
...state,
|
|
1049
|
+
entries: [...state.entries, ...state.suggestedEntries],
|
|
1050
|
+
missingDependencies: [],
|
|
1051
|
+
pendingError: undefined,
|
|
1052
|
+
suggestedEntries: [],
|
|
1053
|
+
withConfirmValue: '',
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
if ((trimmed === 'n' || trimmed === 'no') && state.pendingError) {
|
|
1057
|
+
return publishReducer({ ...state, suggestedEntries: [], withConfirmValue: '' }, state.pendingError);
|
|
1058
|
+
}
|
|
1059
|
+
return state;
|
|
1060
|
+
}
|
|
1061
|
+
case 'SUGGEST_ENTRIES':
|
|
1062
|
+
return {
|
|
1063
|
+
...state,
|
|
1064
|
+
missingDependencies: action.missing,
|
|
1065
|
+
pendingError: action.error,
|
|
1066
|
+
phase: 'confirm-with',
|
|
1067
|
+
suggestedEntries: action.suggested,
|
|
1068
|
+
withConfirmValue: '',
|
|
1069
|
+
};
|
|
1070
|
+
case 'TOOLS_LOADED':
|
|
1071
|
+
return {
|
|
1072
|
+
...state,
|
|
1073
|
+
phase: 'prompting-tools',
|
|
1074
|
+
toolAdapters: action.adapters,
|
|
1075
|
+
};
|
|
1076
|
+
case 'VALIDATE_DONE': {
|
|
1077
|
+
if (!action.validation.valid) {
|
|
1078
|
+
return {
|
|
1079
|
+
...state,
|
|
1080
|
+
errorMessage: `Validation failed:\n${action.validation.errors.map((e) => ` - ${e}`).join('\n')}`,
|
|
1081
|
+
phase: 'error',
|
|
1082
|
+
validation: action.validation,
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
// Seed the reviewers field: the --reviewer flag wins over the project's
|
|
1086
|
+
// lockfile-configured default (org.ts's CLI-flag > lockfile priority chain).
|
|
1087
|
+
const reviewerValue = state.flags.reviewerFlag ?? (action.lockfileOrgReviewers ?? []).join(', ');
|
|
1088
|
+
// Determine next phase based on missing tags/tools. A batch asks for neither: as for
|
|
1089
|
+
// a --with entry, a missing one is only a warning.
|
|
1090
|
+
const batch = isBatch(state.flags);
|
|
1091
|
+
const manifest = state.target?.data;
|
|
1092
|
+
const hasTags = batch || (manifest && 'tags' in manifest && Array.isArray(manifest.tags) && manifest.tags.length > 0);
|
|
1093
|
+
const hasTools = batch ||
|
|
1094
|
+
// Only assets have tools; bundles skip the tools prompt
|
|
1095
|
+
state.target?.type !== 'asset' ||
|
|
1096
|
+
(manifest && 'tools' in manifest && Array.isArray(manifest.tools) && manifest.tools.length > 0);
|
|
1097
|
+
const isOrgScoped = batch
|
|
1098
|
+
? [state.target, ...state.entries.map((entry) => entry.target)].some((t) => t && isOrgScopedTarget(t))
|
|
1099
|
+
: Boolean(state.target && isOrgScopedTarget(state.target));
|
|
1100
|
+
// Reviewers only apply to org-scoped assets (non-org PRs always go to the registry
|
|
1101
|
+
// maintainer) — fail fast rather than silently ignoring the flag.
|
|
1102
|
+
if (!isOrgScoped && state.flags.reviewerFlag && parseReviewersInput(state.flags.reviewerFlag).length > 0) {
|
|
1103
|
+
return {
|
|
1104
|
+
...state,
|
|
1105
|
+
errorMessage: 'The --reviewer flag only applies to org-scoped assets. Remove the flag to publish this asset.',
|
|
1106
|
+
phase: 'error',
|
|
1107
|
+
validation: action.validation,
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
// Non-interactive path: resolve tags from --tags flag (or empty) right here, then
|
|
1111
|
+
// either route to loading-tools (effect resolves tools async) or directly to
|
|
1112
|
+
// checking-registry. Manifest tags always win when present. The reviewer prompt
|
|
1113
|
+
// never applies here — non-interactive mode always skips it.
|
|
1114
|
+
if (state.nonInteractive) {
|
|
1115
|
+
let nextTarget = state.target;
|
|
1116
|
+
if (!hasTags && nextTarget) {
|
|
1117
|
+
const flagTags = splitList(state.flags.tagsFlag);
|
|
1118
|
+
nextTarget = {
|
|
1119
|
+
...nextTarget,
|
|
1120
|
+
data: { ...nextTarget.data, tags: flagTags.length > 0 ? flagTags : undefined },
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
let nextPhase;
|
|
1124
|
+
if (!hasTools) {
|
|
1125
|
+
// The loading-tools effect detects whether we're non-interactive and
|
|
1126
|
+
// either resolves tools from the manifest/flag/inference or errors out.
|
|
1127
|
+
nextPhase = 'loading-tools';
|
|
1128
|
+
}
|
|
1129
|
+
else {
|
|
1130
|
+
nextPhase = 'checking-registry';
|
|
1131
|
+
}
|
|
1132
|
+
return {
|
|
1133
|
+
...state,
|
|
1134
|
+
phase: nextPhase,
|
|
1135
|
+
reviewerValue,
|
|
1136
|
+
target: nextTarget,
|
|
1137
|
+
validation: action.validation,
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
let nextPhase;
|
|
1141
|
+
if (!hasTags) {
|
|
1142
|
+
nextPhase = 'prompting-tags';
|
|
1143
|
+
}
|
|
1144
|
+
else if (!hasTools) {
|
|
1145
|
+
nextPhase = 'loading-tools';
|
|
1146
|
+
}
|
|
1147
|
+
else {
|
|
1148
|
+
nextPhase = isOrgScoped ? 'prompting-reviewer' : 'checking-registry';
|
|
1149
|
+
}
|
|
1150
|
+
return {
|
|
1151
|
+
...state,
|
|
1152
|
+
phase: nextPhase,
|
|
1153
|
+
reviewerValue,
|
|
1154
|
+
validation: action.validation,
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
default:
|
|
1158
|
+
return state;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* The step before `building-plan`, once the root asset's own checks are done:
|
|
1163
|
+
* check the entries not yet checked, then settle each entry that needs a bump
|
|
1164
|
+
* (the bump prompt; `--bump` or an error when non-interactive), then plan.
|
|
1165
|
+
*/
|
|
1166
|
+
function advanceToPlan(state) {
|
|
1167
|
+
if (state.entries.some((entry) => !entry.versionCheck)) {
|
|
1168
|
+
return { ...state, bumpEntry: undefined, phase: 'checking-entries' };
|
|
1169
|
+
}
|
|
1170
|
+
// A batch without --bump names every asset that needs one, not just the first.
|
|
1171
|
+
if (isBatch(state.flags) && state.nonInteractive && !state.flags.bump) {
|
|
1172
|
+
const pending = [
|
|
1173
|
+
...(state.target && state.versionCheck?.status === 'needs-bump' && !state.resolvedVersion
|
|
1174
|
+
? [{ label: state.flags.rawPath, latestVersion: state.versionCheck.latestVersion, target: state.target }]
|
|
1175
|
+
: []),
|
|
1176
|
+
...state.entries.flatMap((entry) => entry.versionCheck?.status === 'needs-bump' && entry.resolvedVersion === undefined
|
|
1177
|
+
? [{ label: entry.label, latestVersion: entry.versionCheck.latestVersion, target: entry.target }]
|
|
1178
|
+
: []),
|
|
1179
|
+
];
|
|
1180
|
+
if (pending.length > 0) {
|
|
1181
|
+
const lines = pending.map((p) => ` ${p.label}: ${p.target.assetType}:${p.target.data.name} v${p.target.data.version}, registry has v${p.latestVersion}`);
|
|
1182
|
+
return {
|
|
1183
|
+
...state,
|
|
1184
|
+
errorMessage: `--bump <patch|minor|major> required: these manifests are not newer than the registry:\n${lines.join('\n')}`,
|
|
1185
|
+
phase: 'error',
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
const index = state.entries.findIndex((entry) => entry.versionCheck?.status === 'needs-bump' && entry.resolvedVersion === undefined);
|
|
1190
|
+
const entry = state.entries[index];
|
|
1191
|
+
if (entry?.versionCheck?.status !== 'needs-bump') {
|
|
1192
|
+
return { ...state, bumpEntry: undefined, phase: 'building-plan' };
|
|
1193
|
+
}
|
|
1194
|
+
if (!state.nonInteractive) {
|
|
1195
|
+
return { ...state, bumpEntry: index, bumpSelection: '', phase: 'bump-prompt' };
|
|
1196
|
+
}
|
|
1197
|
+
const { latestVersion } = entry.versionCheck;
|
|
1198
|
+
if (!state.flags.bump) {
|
|
1199
|
+
return {
|
|
1200
|
+
...state,
|
|
1201
|
+
errorMessage: `--bump <patch|minor|major> required: registry has v${latestVersion} of ${entry.target.assetType}:${entry.target.data.name} (from ${entry.label}) but its manifest is not newer`,
|
|
1202
|
+
phase: 'error',
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
return bumpEntryAt(state, index, state.flags.bump);
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Bump the entry at `index` from its registry version, then go on toward the
|
|
1209
|
+
* plan; an error state, as for the root, when the version can't be bumped.
|
|
1210
|
+
*/
|
|
1211
|
+
function bumpEntryAt(state, index, bump) {
|
|
1212
|
+
const entry = state.entries[index];
|
|
1213
|
+
if (entry?.versionCheck?.status !== 'needs-bump')
|
|
1214
|
+
return state;
|
|
1215
|
+
let version;
|
|
1216
|
+
try {
|
|
1217
|
+
version = bumpVersion(entry.versionCheck.latestVersion, bump);
|
|
1218
|
+
}
|
|
1219
|
+
catch {
|
|
1220
|
+
return { ...state, errorMessage: `Failed to compute bumped version for ${entry.label}.`, phase: 'error' };
|
|
1221
|
+
}
|
|
1222
|
+
return advanceToPlan({ ...state, entries: replaceEntry(state.entries, index, withVersion(entry, version)) });
|
|
1223
|
+
}
|
|
1224
|
+
/**
|
|
1225
|
+
* Phase to enter once the tags/tools metadata prompts are resolved: org-scoped
|
|
1226
|
+
* targets get the reviewer prompt, everything else proceeds to the registry check.
|
|
1227
|
+
*/
|
|
1228
|
+
function phaseAfterMetadata(target) {
|
|
1229
|
+
return target && isOrgScopedTarget(target) ? 'prompting-reviewer' : 'checking-registry';
|
|
1230
|
+
}
|
|
1231
|
+
function replaceEntry(entries, index, entry) {
|
|
1232
|
+
return entries.map((current, i) => (i === index ? entry : current));
|
|
1233
|
+
}
|
|
1234
|
+
/** The entry published at `version`; a successful publish writes it to the entry's manifest. */
|
|
1235
|
+
function withVersion(entry, version) {
|
|
1236
|
+
return {
|
|
1237
|
+
...entry,
|
|
1238
|
+
resolvedVersion: version,
|
|
1239
|
+
target: { ...entry.target, data: { ...entry.target.data, version } },
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
//# sourceMappingURL=publish-flow.js.map
|