@bluestep-systems/b6p-core 0.8.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +310 -32
  2. package/dist/B6PCore.d.ts +7 -0
  3. package/dist/B6PCore.js +96 -1
  4. package/dist/B6PCore.js.map +1 -1
  5. package/dist/B6PUri.d.ts +6 -8
  6. package/dist/B6PUri.js +6 -8
  7. package/dist/B6PUri.js.map +1 -1
  8. package/dist/Err.d.ts +421 -0
  9. package/dist/Err.js +558 -0
  10. package/dist/Err.js.map +1 -1
  11. package/dist/auth/BearerAuthProvider.d.ts +32 -0
  12. package/dist/auth/BearerAuthProvider.js +49 -0
  13. package/dist/auth/BearerAuthProvider.js.map +1 -1
  14. package/dist/cache/OrgCache.js.map +1 -1
  15. package/dist/cache/ScriptMetaDataStore.js.map +1 -1
  16. package/dist/constants/ApiEndpoints.d.ts +1 -0
  17. package/dist/constants/ApiEndpoints.js +1 -0
  18. package/dist/constants/ApiEndpoints.js.map +1 -1
  19. package/dist/constants/AuthTypes.js.map +1 -1
  20. package/dist/constants/BlueHQ.js.map +1 -1
  21. package/dist/constants/CryptoAlgorithms.js.map +1 -1
  22. package/dist/constants/ExtensionConfig.js.map +1 -1
  23. package/dist/constants/FileExtensions.js.map +1 -1
  24. package/dist/constants/FolderNames.js.map +1 -1
  25. package/dist/constants/Gateway.d.ts +71 -0
  26. package/dist/constants/Gateway.js +79 -0
  27. package/dist/constants/Gateway.js.map +1 -0
  28. package/dist/constants/GitHubUrls.js.map +1 -1
  29. package/dist/constants/Http.js.map +1 -1
  30. package/dist/constants/MimeTypes.js.map +1 -1
  31. package/dist/constants/Numerical.js.map +1 -1
  32. package/dist/constants/OutputChannels.js.map +1 -1
  33. package/dist/constants/SettingsKeys.d.ts +5 -0
  34. package/dist/constants/SettingsKeys.js +5 -0
  35. package/dist/constants/SettingsKeys.js.map +1 -1
  36. package/dist/constants/SpecialFiles.js.map +1 -1
  37. package/dist/constants/WebDAVElements.js.map +1 -1
  38. package/dist/constants/index.d.ts +1 -0
  39. package/dist/constants/index.js +3 -1
  40. package/dist/constants/index.js.map +1 -1
  41. package/dist/data/DownstairsPathParser.js.map +1 -1
  42. package/dist/data/GlobMatcher.js.map +1 -1
  43. package/dist/data/IdUtility.js.map +1 -1
  44. package/dist/data/OrgWorker.js.map +1 -1
  45. package/dist/data/ScriptKey.d.ts +3 -27
  46. package/dist/data/ScriptKey.js +12 -24
  47. package/dist/data/ScriptKey.js.map +1 -1
  48. package/dist/data/ScriptUrlParser.js +3 -1
  49. package/dist/data/ScriptUrlParser.js.map +1 -1
  50. package/dist/data/ServerVersion.d.ts +76 -0
  51. package/dist/data/ServerVersion.js +111 -0
  52. package/dist/data/ServerVersion.js.map +1 -0
  53. package/dist/data/index.d.ts +2 -0
  54. package/dist/data/index.js +7 -1
  55. package/dist/data/index.js.map +1 -1
  56. package/dist/gateway/GatewayClient.d.ts +147 -0
  57. package/dist/gateway/GatewayClient.js +395 -0
  58. package/dist/gateway/GatewayClient.js.map +1 -0
  59. package/dist/gateway/GatewayContext.d.ts +43 -0
  60. package/dist/gateway/GatewayContext.js +3 -0
  61. package/dist/gateway/GatewayContext.js.map +1 -0
  62. package/dist/gateway/GatewayGit.d.ts +291 -0
  63. package/dist/gateway/GatewayGit.js +731 -0
  64. package/dist/gateway/GatewayGit.js.map +1 -0
  65. package/dist/gateway/GatewayKb.d.ts +173 -0
  66. package/dist/gateway/GatewayKb.js +354 -0
  67. package/dist/gateway/GatewayKb.js.map +1 -0
  68. package/dist/gateway/GatewayMarketplace.d.ts +116 -0
  69. package/dist/gateway/GatewayMarketplace.js +278 -0
  70. package/dist/gateway/GatewayMarketplace.js.map +1 -0
  71. package/dist/gateway/GatewayService.d.ts +47 -0
  72. package/dist/gateway/GatewayService.js +54 -0
  73. package/dist/gateway/GatewayService.js.map +1 -0
  74. package/dist/gateway/GatewayToken.d.ts +18 -0
  75. package/dist/gateway/GatewayToken.js +43 -0
  76. package/dist/gateway/GatewayToken.js.map +1 -0
  77. package/dist/gateway/GatewayTokenService.d.ts +101 -0
  78. package/dist/gateway/GatewayTokenService.js +465 -0
  79. package/dist/gateway/GatewayTokenService.js.map +1 -0
  80. package/dist/index.d.ts +29 -8
  81. package/dist/index.js +81 -9
  82. package/dist/index.js.map +1 -1
  83. package/dist/network/HttpClient.js.map +1 -1
  84. package/dist/network/HttpClientProvider.js.map +1 -1
  85. package/dist/network/StatusCodes.js.map +1 -1
  86. package/dist/persistence/PersistablePseudoMap.js.map +1 -1
  87. package/dist/persistence/PersistenceKeys.js.map +1 -1
  88. package/dist/persistence/PrivatePersistanceMap.js.map +1 -1
  89. package/dist/persistence/PseudoMap.js.map +1 -1
  90. package/dist/persistence/PublicPersistanceMap.js.map +1 -1
  91. package/dist/persistence/Serializable.js.map +1 -1
  92. package/dist/persistence/SharedFilePersistence.d.ts +22 -0
  93. package/dist/persistence/SharedFilePersistence.js +65 -14
  94. package/dist/persistence/SharedFilePersistence.js.map +1 -1
  95. package/dist/persistence/TypedMap.js.map +1 -1
  96. package/dist/persistence/TypedPersistable.js.map +1 -1
  97. package/dist/persistence/TypedPrivatePersistable.js.map +1 -1
  98. package/dist/persistence/dirLockdown.js.map +1 -1
  99. package/dist/providers.d.ts +46 -16
  100. package/dist/script/GitIdentity.d.ts +48 -0
  101. package/dist/script/GitIdentity.js +52 -0
  102. package/dist/script/GitIdentity.js.map +1 -0
  103. package/dist/script/GitSync.d.ts +388 -0
  104. package/dist/script/GitSync.js +1068 -0
  105. package/dist/script/GitSync.js.map +1 -0
  106. package/dist/script/ScriptContext.d.ts +20 -5
  107. package/dist/script/ScriptFactory.d.ts +1 -2
  108. package/dist/script/ScriptFactory.js +1 -2
  109. package/dist/script/ScriptFactory.js.map +1 -1
  110. package/dist/script/ScriptFile.d.ts +0 -94
  111. package/dist/script/ScriptFile.js +0 -245
  112. package/dist/script/ScriptFile.js.map +1 -1
  113. package/dist/script/ScriptFolder.d.ts +0 -9
  114. package/dist/script/ScriptFolder.js +4 -7
  115. package/dist/script/ScriptFolder.js.map +1 -1
  116. package/dist/script/ScriptNode.d.ts +0 -9
  117. package/dist/script/ScriptNode.js.map +1 -1
  118. package/dist/script/ScriptRoot.d.ts +0 -65
  119. package/dist/script/ScriptRoot.js +0 -199
  120. package/dist/script/ScriptRoot.js.map +1 -1
  121. package/dist/script/ScriptService.d.ts +113 -9
  122. package/dist/script/ScriptService.js +164 -52
  123. package/dist/script/ScriptService.js.map +1 -1
  124. package/dist/script/ServerCompile.d.ts +35 -0
  125. package/dist/script/ServerCompile.js +40 -0
  126. package/dist/script/ServerCompile.js.map +1 -0
  127. package/dist/script/TsConfig.d.ts +2 -2
  128. package/dist/script/TsConfig.js +3 -3
  129. package/dist/script/TsConfig.js.map +1 -1
  130. package/dist/script/push.d.ts +162 -188
  131. package/dist/script/push.js +216 -474
  132. package/dist/script/push.js.map +1 -1
  133. package/dist/session/SessionManager.js.map +1 -1
  134. package/dist/testing/FakeGateway.d.ts +280 -0
  135. package/dist/testing/FakeGateway.js +627 -0
  136. package/dist/testing/FakeGateway.js.map +1 -0
  137. package/dist/testing/MockFileSystem.js.map +1 -1
  138. package/dist/types.d.ts +332 -0
  139. package/dist/update/UpdateService.js.map +1 -1
  140. package/package.json +17 -12
  141. package/dist/script/ScriptTranspiler.d.ts +0 -121
  142. package/dist/script/ScriptTranspiler.js +0 -333
  143. package/dist/script/ScriptTranspiler.js.map +0 -1
  144. package/dist/script/SnapshotHistoryRecorder.d.ts +0 -47
  145. package/dist/script/SnapshotHistoryRecorder.js +0 -231
  146. package/dist/script/SnapshotHistoryRecorder.js.map +0 -1
  147. package/dist/script/TsLibResolver.d.ts +0 -60
  148. package/dist/script/TsLibResolver.js +0 -134
  149. package/dist/script/TsLibResolver.js.map +0 -1
@@ -32,35 +32,30 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
35
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.checkEmittedEntrypoint = checkEmittedEntrypoint;
40
- exports.verifyLiveSnapshot = verifyLiveSnapshot;
41
- exports.collectOverwriteCandidates = collectOverwriteCandidates;
42
- exports.confirmOverwrites = confirmOverwrites;
36
+ exports.legacySyncRecords = legacySyncRecords;
37
+ exports.describeBuildStatus = describeBuildStatus;
43
38
  exports.executePush = executePush;
44
- exports.cleanupUnusedUpstairsPaths = cleanupUnusedUpstairsPaths;
45
39
  const path = __importStar(require("path"));
46
- const fast_xml_parser_1 = require("fast-xml-parser");
47
- const typescript_1 = __importDefault(require("typescript"));
40
+ const b6p_core_bsjs_git_1 = require("@bluestep-systems/b6p-core-bsjs-git");
48
41
  const constants_1 = require("../constants");
49
42
  const B6PUri_1 = require("../B6PUri");
50
- const GlobMatcher_1 = require("../data/GlobMatcher");
51
43
  const ScriptUrlParser_1 = require("../data/ScriptUrlParser");
44
+ const ServerVersion_1 = require("../data/ServerVersion");
52
45
  const ScriptFactory_1 = require("./ScriptFactory");
53
- const SnapshotHistoryRecorder_1 = require("./SnapshotHistoryRecorder");
54
- const Err_1 = require("../Err");
55
- const ScriptFile_1 = require("./ScriptFile");
56
- const TsConfig_1 = require("./TsConfig");
46
+ const GitIdentity_1 = require("./GitIdentity");
47
+ const GitSync_1 = require("./GitSync");
48
+ const ServerCompile_1 = require("./ServerCompile");
57
49
  /**
58
- * Recursively collect all files under a directory.
50
+ * Recursively collect all files under a directory, leaving out a git repository's own `.git` folder.
59
51
  */
60
52
  async function flattenDirectory(dirPath, fs) {
61
53
  const results = [];
62
54
  const entries = await fs.readDirectory(B6PUri_1.B6PUri.fromFsPath(dirPath));
63
55
  for (const [name, type] of entries) {
56
+ if (name === ".git") {
57
+ continue;
58
+ }
64
59
  const full = path.join(dirPath, name);
65
60
  if (type === "directory") {
66
61
  const nested = await flattenDirectory(full, fs);
@@ -73,512 +68,259 @@ async function flattenDirectory(dirPath, fs) {
73
68
  return results;
74
69
  }
75
70
  /**
76
- * Read .gitignore patterns from the script root. Used only for the cleanup
77
- * pass; per-file gitignore filtering during upload is handled inside
78
- * ScriptFile.upload() / getReasonToNotPush().
79
- */
80
- async function readGitIgnorePatterns(rootPath, fs) {
81
- const gitignorePath = path.join(rootPath, constants_1.SpecialFiles.GITIGNORE);
82
- const uri = B6PUri_1.B6PUri.fromFsPath(gitignorePath);
83
- try {
84
- const raw = await fs.readFile(uri);
85
- const text = Buffer.from(raw).toString("utf-8");
86
- return text
87
- .split(/\r?\n/)
88
- .map((l) => l.trim())
89
- .filter((l) => l.length > 0 && !l.startsWith("#"));
90
- }
91
- catch {
92
- return ["**/.DS_Store"];
93
- }
94
- }
95
- /**
96
- * Statements the compiler writes into a module with no code of its own: the ES module marker a
97
- * types-only file compiles to, and the CommonJS preamble. Compared token by token, so spacing and
98
- * comments don't matter.
99
- * @lastreviewed null
100
- */
101
- const EMPTY_MODULE_STATEMENTS = [
102
- "export{};",
103
- '"use strict";',
104
- "'use strict';",
105
- 'Object.defineProperty(exports,"__esModule",{value:true});',
106
- ];
107
- /**
108
- * Whether compiled JavaScript has code beyond comments and {@link EMPTY_MODULE_STATEMENTS}. The
109
- * compiler always appends an inline source map comment, so a blank `app.ts` never compiles to a
110
- * blank file; the TypeScript scanner drops comments and whitespace as trivia.
111
- * @param js The compiled file's text
71
+ * The hashes a pre-git push or pull recorded for the files of a draft folder, as the lookup the git side uses to tell a
72
+ * local edit from a platform change in a folder that has no repository yet.
73
+ * @param scriptRoot The script whose metadata holds the records
74
+ * @param draftPath The draft folder the records' paths are under
112
75
  * @lastreviewed null
113
76
  */
114
- function hasCode(js) {
115
- const scanner = typescript_1.default.createScanner(typescript_1.default.ScriptTarget.Latest, true, typescript_1.default.LanguageVariant.Standard, js);
116
- let tokens = "";
117
- for (let kind = scanner.scan(); kind !== typescript_1.default.SyntaxKind.EndOfFileToken; kind = scanner.scan()) {
118
- tokens += scanner.getTokenText();
119
- }
120
- for (const statement of EMPTY_MODULE_STATEMENTS) {
121
- tokens = tokens.split(statement).join("");
122
- }
123
- return tokens.length > 0;
77
+ async function legacySyncRecords(scriptRoot, draftPath) {
78
+ const metadata = await scriptRoot.getMetaData();
79
+ const records = new Map((metadata?.pushPullRecords ?? []).map((r) => [r.downstairsPath, r.lastVerifiedHash]));
80
+ return async (relative) => records.get(B6PUri_1.B6PUri.fromFsPath(path.join(draftPath, ...relative.split("/"))).fsPath) ?? null;
124
81
  }
125
82
  /**
126
- * Pre-publish check for a snapshot push: after the compile, the entrypoint the platform runtime
127
- * loads must be there. The runtime resolves `scripts/app` to `<build folder>/scripts/app.js`; if
128
- * that file is missing or has no code, publishing it breaks the live version (a missing one fails
129
- * with `NoSuchFileException .../scripts/app`, one with no code answers an empty `200`), so the push
130
- * must stop before any upload (ClickUp 86bbqnrtp).
131
- *
132
- * Only the entrypoint is checked. A helper module may legitimately compile to almost nothing, so
133
- * checking every emitted file would stop good pushes. The transpiler sets `rootDir` to the
134
- * tsconfig's folder, which is why `scripts/app.ts` always maps to `<build folder>/scripts/app.js`.
135
- * @param opts.draftPath The draft folder
136
- * @param opts.buildFolderPath The draft-root tsconfig's build folder ({@link ScriptRoot.getDraftBuildFolder})
137
- * @param opts.fs The file system to read
138
- * @returns What was found, and the path it looked at
83
+ * What a build status that does not publish means, for {@link BuildIncomplete.description}.
139
84
  * @lastreviewed null
140
85
  */
141
- async function checkEmittedEntrypoint(opts) {
142
- const { draftPath, buildFolderPath, fs } = opts;
143
- const emittedPath = path.join(buildFolderPath, constants_1.FolderNames.SCRIPTS, "app" + constants_1.FileExtensions.JAVASCRIPT);
144
- const sourceUri = B6PUri_1.B6PUri.fromFsPath(path.join(draftPath, constants_1.FolderNames.SCRIPTS, "app" + constants_1.FileExtensions.TYPESCRIPT));
145
- if (!(await fs.exists(sourceUri))) {
146
- return { status: "no-source", emittedPath };
86
+ function describeBuildStatus(status, rawStatus) {
87
+ switch (status) {
88
+ case "BUSY":
89
+ return "the platform was busy and did not build the draft";
90
+ case "INPUT_INCOMPLETE":
91
+ return "the platform's copy of the draft was incomplete, so it did not build it";
92
+ case "COMPILER_UNAVAILABLE":
93
+ return "the platform's compiler was unavailable";
94
+ case "NOT_PERMITTED":
95
+ return "the platform did not permit building this script";
96
+ case "WRITE_FAILED":
97
+ return "the platform could not write the build output";
98
+ case "OUTPUT_UPLOAD":
99
+ return "the platform took the output as uploaded and did not build it";
100
+ case "SKIPPED_GIT_MANAGED":
101
+ return "this server does not build git drafts";
102
+ case "GATE_TRIPPED":
103
+ return "the platform's save gate held back the new output";
104
+ case "EMIT_WITHHELD":
105
+ return "the platform withheld the new output";
106
+ case "UNKNOWN":
107
+ return `the platform reported a build status this version does not know (${rawStatus || "none"})`;
108
+ default:
109
+ return `the platform reported ${rawStatus}`;
147
110
  }
148
- const emittedUri = B6PUri_1.B6PUri.fromFsPath(emittedPath);
149
- if (!(await fs.exists(emittedUri))) {
150
- return { status: "missing", emittedPath };
151
- }
152
- const text = Buffer.from(await fs.readFile(emittedUri)).toString("utf-8");
153
- return { status: hasCode(text) ? "ok" : "empty", emittedPath };
154
111
  }
155
- /**
156
- * How the read-back retry warning describes each failed status.
157
- * @lastreviewed null
158
- */
159
- const READ_BACK_PROBLEMS = {
160
- mismatch: "doesn't match what was pushed",
161
- missing: "is missing (404)",
162
- unreadable: "could not be read back",
163
- };
164
- /**
165
- * Post-publish read-back for a snapshot push: `HEAD`s the `snapshot/` copy of each file the push
166
- * wrote and compares its ETag with the local SHA-512. The platform can accept a write (2xx) and
167
- * still serve different bytes, e.g. an empty or cut-off file, so a clean upload alone doesn't prove
168
- * the live version is right (ClickUp 86bbqnrtp).
169
- *
170
- * A copy that differs, is missing (`404`) or can't be read (another non-2xx) is re-sent once and
171
- * checked again; a re-send the platform refuses leaves it a mismatch. Only a 2xx without a content
172
- * hash is indeterminate. Files are checked one at a time, in the order given.
173
- * @param files The files this push wrote to `snapshot/`
174
- * @param ctx Where the retries are logged
175
- * @returns The files still mismatched, and the ones that could not be compared
176
- * @lastreviewed null
177
- */
178
- async function verifyLiveSnapshot(files, ctx) {
179
- const check = { mismatches: [], indeterminate: [] };
180
- for (const file of files) {
181
- const snapshotUrl = ScriptFile_1.ScriptFile.snapshotUrl(await file.upstairsUrl());
182
- const relative = file.pathWithRespectToDraftRoot().split(path.sep).join("/");
183
- let status = await file.readBackStatus(snapshotUrl);
184
- if (status === "mismatch" || status === "missing" || status === "unreadable") {
185
- ctx.logger.warn(`Live copy of ${relative} ${READ_BACK_PROBLEMS[status]}; sending it again: ${snapshotUrl}`);
186
- try {
187
- await file.putTo(snapshotUrl);
188
- status = await file.readBackStatus(snapshotUrl);
189
- }
190
- catch (e) {
191
- ctx.logger.warn(`Re-sending ${relative} failed: ${e instanceof Error ? e.message : e}`);
192
- }
193
- }
194
- if (status === "indeterminate") {
195
- check.indeterminate.push(relative);
196
- }
197
- else if (status !== "match") {
198
- check.mismatches.push(relative);
199
- }
200
- }
201
- return check;
202
- }
203
- /**
204
- * Finds the files of a push whose upload would overwrite a platform version nobody here has seen,
205
- * by the rule in {@link ScriptFile.platformChangeAtRisk}. Files the push won't upload anyway
206
- * (ignored, declarations, already in sync) are left out, so they are never asked about.
207
- *
208
- * Reads the platform one file at a time. The skip check it runs is cached on each file, so the
209
- * upload that follows doesn't repeat it.
210
- * @param files The push's files, the same instances the upload will use
211
- * @param opts.isSnapshot Whether the push also publishes to `snapshot/`
212
- * @returns The files at risk, in the order given
213
- * @lastreviewed null
214
- */
215
- async function collectOverwriteCandidates(files, opts) {
216
- const candidates = [];
217
- for (const file of files) {
218
- if (await file.getReasonToNotPush({ isSnapshot: opts.isSnapshot })) {
219
- continue;
220
- }
221
- const risk = await file.platformChangeAtRisk();
222
- if (risk) {
223
- candidates.push({ file, path: file.pathWithRespectToDraftRoot().split(path.sep).join("/"), risk });
224
- }
225
- }
226
- return candidates;
227
- }
228
- /**
229
- * The push's one overwrite confirmation (ClickUp 86bbjennm). Before anything is uploaded, it finds
230
- * every file at risk ({@link collectOverwriteCandidates}) and asks once for all of them, so an
231
- * answer, or the lack of one, can no longer leave a push half done. Files the caller already
232
- * confirmed in `preConfirmed` are not asked about: that is how a consumer confirms without a
233
- * prompt, e.g. from a flag.
234
- * @param opts.files The push's files, the same instances the upload will use
235
- * @param opts.ctx Where the prompt goes
236
- * @param opts.isSnapshot Whether the push also publishes to `snapshot/`
237
- * @param opts.preConfirmed Draft-relative paths (`/`- or `\`-separated) the caller confirms up front
238
- * @returns The files whose overwrite is confirmed; `upload()` skips its own prompt for them
239
- * @throws an {@link Err.OverwriteDeclinedError} listing the files, when the answer is anything but
240
- * "Overwrite all". Nothing has been uploaded at that point.
241
- * @lastreviewed null
242
- */
243
- async function confirmOverwrites(opts) {
244
- const { prompt } = opts.ctx;
245
- const preConfirmed = new Set((opts.preConfirmed ?? []).map((p) => p.replace(/\\/g, "/").replace(/^\.\//, "")));
246
- const candidates = await collectOverwriteCandidates(opts.files, { isSnapshot: opts.isSnapshot });
247
- const confirmed = new Set(candidates.filter((c) => preConfirmed.has(c.path)).map((c) => c.file));
248
- const toAsk = candidates.filter((c) => !preConfirmed.has(c.path));
249
- if (toAsk.length === 0) {
250
- return confirmed;
251
- }
252
- const why = (c) => c.risk === "changed"
253
- ? "changed on the platform since the last push or pull from here"
254
- : "the platform has a different copy, never pulled or pushed from this machine";
255
- const list = toAsk.map((c) => `${c.path} (${why(c)})`).join("\n");
256
- // "Cancel" is FIRST: an empty answer and the CLI's --yes both take options[0] (ClickUp 86bc2h3ef).
257
- const CANCEL = "Cancel";
258
- const OVERWRITE_ALL = "Overwrite all";
259
- const answer = await prompt.confirm(`${toAsk.length} file(s) would overwrite a platform version nobody here has seen:\n\n${list}\n\n` +
260
- `Nothing has been uploaded yet. Overwrite all of them with your local files?`, [CANCEL, OVERWRITE_ALL], { destructive: true, safeOption: CANCEL });
261
- if (answer !== OVERWRITE_ALL) {
262
- const kind = opts.isSnapshot ? "Snapshot push" : "Push";
263
- await prompt.popup(`${kind} cancelled: nothing was uploaded.`);
264
- // What was kept and why; how to confirm is the consumer's to say (it gets `paths`).
265
- throw new Err_1.Err.OverwriteDeclinedError(`${kind} stopped before uploading anything: ${toAsk.length} file(s) were not overwritten, because ` +
266
- `each would overwrite a platform version nobody here has seen:\n\n${list}\n\n` +
267
- `Pull or audit them to see the platform versions before overwriting them.`, toAsk.map((c) => c.path));
268
- }
269
- toAsk.forEach((c) => confirmed.add(c.file));
270
- return confirmed;
112
+ function notPushed(route) {
113
+ return {
114
+ pushed: false,
115
+ commitSha: null,
116
+ publishedSha: null,
117
+ publishError: null,
118
+ publishRefusal: null,
119
+ switchedToGit: false,
120
+ route,
121
+ snapshotRefused: null,
122
+ build: null,
123
+ buildCommitSha: null,
124
+ buildVouched: null,
125
+ buildError: null,
126
+ buildErrorKind: null,
127
+ buildErrorReason: null,
128
+ buildIncomplete: null,
129
+ buildFastForward: null,
130
+ typeCheckDiagnostics: null,
131
+ typeCheckErrors: [],
132
+ liveVerified: null,
133
+ liveMismatches: [],
134
+ keptPlatformOnly: [],
135
+ };
271
136
  }
272
137
  /**
273
- * Core push implementation.
138
+ * Core push implementation, on git: the draft folder is the script's git working tree, a push commits it and pushes the
139
+ * draft branch (see {@link pushDraft}), the platform then builds the pushed commit, and a snapshot publishes the build.
274
140
  *
275
- * Delegates the per-file work to {@link ScriptFile.upload}, which handles:
276
- * - exclusion logic (declarations / .git / .gitignore / integrity match)
277
- * - collision detection against last-verified hash with user prompt
278
- * - snapshot dual-write (draft + snapshot)
279
- * - metadata `lastVerifiedHash` updates via touch()
280
- * - rich error wrapping
141
+ * Nothing compiles here. The server's version picks the route once per push ({@link resolvePushRoute}): a `dev` server
142
+ * or one at or above `MIN_SERVER_VERSION` builds every push (GraphQL `compileDraft` pinned to the pushed commit), which
143
+ * commits the output, and the build manifest when it vouches for the build, as one build commit; the draft folder is
144
+ * fast-forwarded to it. A snapshot push then publishes that commit, unless the build failed or ended in a status that
145
+ * does not publish (a tripped gate, a withheld emit). An unclean build is published-or-refused by the platform's
146
+ * manifest check, never by core. On any other server the push is a git push alone, and a snapshot push takes no
147
+ * snapshot (`snapshotRefused`). If the platform refuses the publish the draft stays pushed and the result carries
148
+ * `publishError`.
281
149
  *
282
- * Before any upload, one confirmation covers every file that would overwrite a platform version
283
- * nobody here has seen ({@link confirmOverwrites}); declining stops the push with nothing written.
284
- * A snapshot push then reads the live copies back ({@link verifyLiveSnapshot}). If any is still
285
- * wrong, the push stops before cleanup and history and returns `liveVerified: false`.
150
+ * Before anything is pushed, one confirmation covers every platform file the push would overwrite; declining stops the
151
+ * push with nothing sent.
286
152
  * @param opts.overwrite Draft-relative paths whose overwrite the caller confirms up front, so the
287
153
  * push doesn't ask about them (e.g. a consumer's flag, after the user approved the files a
288
154
  * declined push listed). Other at-risk files still ask.
155
+ * @param opts.author Who the commit is by. When absent: the folder's `git config`, then the environment.
156
+ * @param opts.adoptUnbound `false` for a deploy to a script the folder isn't the working copy of: the folder is then
157
+ * never bound to the target's repo. Default `true`.
158
+ * @param opts.floor Overrides `MIN_SERVER_VERSION` (`null` means unset); for tests
159
+ * @param opts.sleep Waits between the build's retries; for tests
289
160
  * @throws an {@link Err.OverwriteDeclinedError} when an overwrite is not confirmed
161
+ * @throws {GitIdentityError} when no commit author can be found
290
162
  * @lastreviewed null
291
163
  */
292
164
  async function executePush(opts) {
293
165
  const { ctx, targetUrl, rootPath, snapshot, message, overwrite } = opts;
294
- const { fs, prompt, logger, sessionManager, progress } = ctx;
166
+ const { fs, prompt, logger, sessionManager } = ctx;
295
167
  const draftPath = path.join(rootPath, constants_1.FolderNames.DRAFT);
296
168
  const draftUri = B6PUri_1.B6PUri.fromFsPath(draftPath);
297
169
  if (!(await fs.exists(draftUri))) {
298
170
  prompt.error(`Draft folder not found: ${draftPath}`);
299
- return {
300
- pushed: false,
301
- historyRecorded: false,
302
- typeCheckDiagnostics: null,
303
- liveVerified: null,
304
- liveMismatches: [],
305
- keptPlatformOnly: [],
306
- };
171
+ return notPushed(null);
307
172
  }
308
- // Build a parser from the target URL so the ScriptRoot can resolve
309
- // upstairs URLs (mirrors what executePull does on the pull side).
173
+ // Fail before the platform is touched: a commit made as nobody must not happen, and a script must not be switched
174
+ // to git by a push that then cannot commit.
175
+ const author = await (0, GitIdentity_1.resolveGitIdentity)({ explicit: opts.author, dir: draftPath, env: ctx.gitEnv });
176
+ // Build a parser from the target URL so the ScriptRoot can resolve the script's identity.
310
177
  const parser = new ScriptUrlParser_1.ScriptUrlParser(targetUrl, sessionManager, logger, prompt);
311
178
  const factory = new ScriptFactory_1.ScriptFactory(ctx);
312
- // One ScriptRoot for the whole push; all files in this draft tree are
313
- // siblings under the same root.
314
179
  const rootUri = B6PUri_1.B6PUri.fromFsPath(rootPath).asDirectory();
315
180
  const scriptRoot = factory.createScriptRoot(rootUri);
316
181
  scriptRoot.withParser(parser);
317
- // Snapshots transpile TS into the draft build folder so both the source
318
- // and emitted JS get uploaded and captured in history. Must run before
319
- // flattenDirectory so the emitted files are included in the upload set.
320
- // A plain (non-snapshot) push does not compile, so its type-check status is
321
- // null rather than a count.
322
- let typeCheckDiagnostics = null;
323
- let typeCheckDetail = "";
324
- if (snapshot) {
325
- const compileOutcome = await scriptRoot.compileDraftFolder();
326
- typeCheckDiagnostics = compileOutcome.diagnosticCount;
327
- typeCheckDetail = compileOutcome.diagnosticText;
328
- const buildFolderPath = (await scriptRoot.getDraftBuildFolder()).uri().fsPath;
329
- const entrypoint = await checkEmittedEntrypoint({ draftPath, buildFolderPath, fs });
330
- if (entrypoint.status === "missing" || entrypoint.status === "empty") {
331
- prompt.error(`Snapshot not published: the compiled entrypoint ${entrypoint.emittedPath} ` +
332
- `${entrypoint.status === "missing" ? "is missing" : "has no code"} after compiling scripts/app.ts. ` +
333
- `The platform runs that file, so publishing it would break the live version. Nothing was ` +
334
- `uploaded. Check scripts/app.ts, the compile output and the draft ${TsConfig_1.TsConfig.NAME}.`);
335
- return {
336
- pushed: false,
337
- historyRecorded: false,
338
- typeCheckDiagnostics,
339
- liveVerified: null,
340
- liveMismatches: [],
341
- keptPlatformOnly: [],
342
- };
343
- }
344
- }
345
- // Push does NOT transpile client bundles (e.g. a MergeReport `static/script.ts`
346
- // → `static/.build/script.js`); the platform serves that emitted JS verbatim
347
- // rather than recompiling it. Warn loudly if a bundle's source is newer than
348
- // its compiled output so a push can't silently ship stale client JS
349
- // (b6p-cli#9). Runs for both plain and snapshot pushes; reflects on-disk state
350
- // after any snapshot compile.
351
- for (const { bundle, buildFolder } of await scriptRoot.findStaleClientBundles()) {
352
- prompt.warn(`Stale client bundle: source(s) under ${bundle} are newer than the compiled output in ${buildFolder}. ` +
353
- `b6p push does not transpile client TypeScript — recompile the bundle before pushing, ` +
354
- `or you will ship stale client JS.`);
355
- }
356
182
  const allFiles = await flattenDirectory(draftPath, fs);
357
183
  logger.info(`Found ${allFiles.length} files in draft folder`);
358
184
  if (allFiles.length === 0) {
359
185
  prompt.info("No files to push — draft folder is empty.");
360
- return {
361
- pushed: false,
362
- historyRecorded: false,
363
- typeCheckDiagnostics,
364
- liveVerified: null,
365
- liveMismatches: [],
366
- keptPlatformOnly: [],
367
- };
186
+ return notPushed(null);
368
187
  }
369
- // One ScriptFile per file for the whole push: the confirmation pass and the upload share them,
370
- // and with them each file's cached skip check.
371
- const entries = allFiles.map((filePath) => ({
372
- filePath,
373
- file: factory.createFile(B6PUri_1.B6PUri.fromFsPath(filePath), scriptRoot),
374
- }));
375
- const confirmed = await confirmOverwrites({
376
- files: entries.map((e) => e.file),
377
- ctx,
378
- isSnapshot: snapshot,
379
- preConfirmed: overwrite,
188
+ const route = await (0, ServerVersion_1.resolvePushRoute)({
189
+ origin: parser.url.origin,
190
+ fetchFn: (url, init) => sessionManager.fetch(url, init),
191
+ ...(opts.floor !== undefined ? { floor: opts.floor } : {}),
380
192
  });
381
- // Files upload() actually wrote (a resolved Response); skipped files resolve with undefined.
382
- const written = [];
383
- const uploadTasks = entries.map(({ filePath, file }) => ({
384
- execute: async () => {
385
- try {
386
- if (await file.upload({ isSnapshot: snapshot, overwriteConfirmed: confirmed.has(file) })) {
387
- written.push(file);
388
- }
389
- }
390
- catch (e) {
391
- if (e instanceof Err_1.Err.UserCancelledError) {
392
- // Surface cancellation to the progress runner so it can stop the batch.
393
- throw e;
394
- }
395
- logger.error(`Failed to push ${filePath}: ${e instanceof Error ? e.message : e}`);
396
- throw e;
397
- }
398
- },
399
- description: path.basename(filePath),
400
- }));
401
- await progress.withProgress(uploadTasks, {
402
- title: snapshot ? "Pushing Snapshot..." : "Pushing Script...",
403
- showItemCount: true,
404
- cleanupMessage: "Cleaning up...",
405
- });
406
- // A snapshot push is only done when the runtime serves what was pushed. If a live copy is still
407
- // wrong, stop: deleting platform files or recording a restore point would build on a broken publish.
408
- let liveVerified = null;
409
- if (snapshot) {
410
- const live = await verifyLiveSnapshot(written, ctx);
411
- if (live.indeterminate.length > 0) {
412
- prompt.warn(`Could not verify the live copy of ${live.indeterminate.length} file(s): the platform served them ` +
413
- `without a content hash (ETag).\n\n${live.indeterminate.join("\n")}`);
414
- }
415
- if (live.mismatches.length > 0) {
416
- prompt.error(`The live (snapshot/) copy of ${live.mismatches.length} file(s) is missing, unreadable or does not ` +
417
- `match what was pushed, ` +
418
- `even after sending it again. The live version may be broken or out of date:\n\n` +
419
- `${live.mismatches.join("\n")}\n\n` +
420
- `No cleanup ran and no snapshot history was recorded. Run the snapshot push again.`);
421
- return {
422
- pushed: true,
423
- historyRecorded: false,
424
- typeCheckDiagnostics,
425
- liveVerified: false,
426
- liveMismatches: live.mismatches,
427
- keptPlatformOnly: [],
428
- };
429
- }
430
- // Nothing was wrong, but a copy served without a content hash was never compared.
431
- liveVerified = live.indeterminate.length > 0 ? null : true;
432
- }
433
- // Cleanup: delete unused upstairs paths.
434
- const gitignorePatterns = await readGitIgnorePatterns(rootPath, fs);
435
- const gitignoreMatcher = new GlobMatcher_1.GlobMatcher(rootPath, gitignorePatterns);
436
- const keptPlatformOnly = await cleanupUnusedUpstairsPaths({
193
+ const build = route.mode === "server-build";
194
+ const snapshotRefused = snapshot ? (0, ServerVersion_1.snapshotRefusalFor)(route) : null;
195
+ const outcome = await (0, GitSync_1.pushDraft)({
437
196
  ctx,
438
- targetUrl,
197
+ script: await parser.getScriptBaseKey(),
198
+ baseUrl: `${parser.url.origin}/`,
439
199
  draftPath,
440
- gitignoreMatcher,
200
+ }, {
201
+ message: message && message.trim() ? message : snapshot ? "Snapshot from b6p" : "Push from b6p",
202
+ author,
203
+ snapshot: snapshot && build,
204
+ build,
205
+ adoptUnbound: opts.adoptUnbound ?? true,
206
+ enableGit: opts.enableGit,
207
+ preConfirmed: overwrite,
208
+ lastSynced: await legacySyncRecords(scriptRoot, draftPath),
209
+ ...(opts.sleep ? { sleep: opts.sleep } : {}),
441
210
  });
442
- let historyRecorded = true;
443
- if (snapshot) {
444
- try {
445
- await SnapshotHistoryRecorder_1.SnapshotHistoryRecorder.record(scriptRoot, message ?? "");
446
- }
447
- catch (e) {
448
- historyRecorded = false;
449
- logger.warn(`Failed to record snapshot history: ${e instanceof Error ? e.message : e}`);
450
- }
451
- }
452
- // A snapshot that compiled with diagnostics shipped un-type-checked JS. Say so
453
- // loudly and do NOT let the run read as a clean success — the platform never
454
- // type-checks, so this push was the only gate (ClickUp 86bbeb659).
455
- const shippedWithDiagnostics = snapshot && typeCheckDiagnostics !== null && typeCheckDiagnostics > 0;
456
- if (shippedWithDiagnostics) {
457
- prompt.warn(`Published WITHOUT a passing type-check: the pre-publish transpile reported ` +
458
- `${typeCheckDiagnostics} diagnostic(s). The JavaScript was emitted and is now live, but these ` +
459
- `were NOT verified — each is either a real type error or a missing platform declaration, and ` +
460
- `the platform does not type-check on its side. Review them before relying on this build:\n\n` +
461
- typeCheckDetail);
462
- }
463
- if (snapshot && !historyRecorded) {
464
- prompt.warn("Snapshot files uploaded and compiled, but the snapshot history entry could NOT be recorded — " +
465
- "the browser IDE's Project History has no restore point for this snapshot. " +
466
- "Run the snapshot push again to retry recording it.");
211
+ if (outcome.switchedToGit) {
212
+ prompt.warn("This script now publishes through git. The switch cannot be undone: its draft and snapshot no longer " +
213
+ "accept WebDAV writes, and its history is the git history from here on.");
467
214
  }
468
- else if (shippedWithDiagnostics) {
469
- prompt.info("Snapshot uploaded — but see the type-check warning above.");
470
- }
471
- else {
472
- prompt.info(snapshot ? "Snapshot complete!" : "Push complete!");
215
+ if (snapshotRefused) {
216
+ prompt.error(`The draft was pushed (commit ${outcome.commitSha}), but no snapshot was taken: ` +
217
+ (snapshotRefused.reason === "too-old"
218
+ ? `the server runs ${snapshotRefused.serverVersion}, and building a git draft needs ${snapshotRefused.required} or later.`
219
+ : snapshotRefused.reason === "floor-unset"
220
+ ? "the first server release that builds git drafts is not known yet."
221
+ : "the server's version could not be read, so it is not known to build git drafts."));
473
222
  }
474
- return { pushed: true, historyRecorded, typeCheckDiagnostics, liveVerified, liveMismatches: [], keptPlatformOnly };
475
- }
476
- /**
477
- * Delete remote files that no longer have a local counterpart, after one confirmation listing
478
- * them. Anything but an explicit "Yes" keeps them all, including a prompt that throws because it
479
- * got no answer. Files matched by `.gitignore` are never deleted. Failures are logged, never
480
- * thrown: a push that uploaded fine is not failed by cleanup.
481
- * @param opts.ctx Where requests, prompts and logs go
482
- * @param opts.targetUrl The script's WebDAV base URL, listed with `PROPFIND`
483
- * @param opts.draftPath The local draft folder to compare against
484
- * @param opts.gitignoreMatcher The script's `.gitignore` patterns
485
- * @returns Draft-relative paths of the platform-only files it kept because deleting them was not
486
- * confirmed; empty when there were none, when they were deleted, or when cleanup failed
487
- * @lastreviewed null
488
- */
489
- async function cleanupUnusedUpstairsPaths(opts) {
490
- const { ctx, targetUrl, draftPath, gitignoreMatcher } = opts;
491
- const { fs, prompt, logger, sessionManager } = ctx;
492
- try {
493
- const parser = new fast_xml_parser_1.XMLParser();
494
- const response = await sessionManager.fetch(targetUrl, {
495
- headers: {
496
- [constants_1.Http.Headers.ACCEPT]: constants_1.Http.Headers.ACCEPT_ALL,
497
- [constants_1.Http.Headers.CACHE_CONTROL]: constants_1.Http.Headers.NO_CACHE,
498
- },
499
- method: constants_1.Http.Methods.PROPFIND,
500
- });
501
- if (!response.ok) {
502
- logger.warn(`PROPFIND failed during cleanup: ${response.status}`);
503
- return [];
504
- }
505
- const xml = await response.text();
506
- const parsed = parser.parse(xml);
507
- const responses = parsed?.["D:multistatus"]?.["D:response"];
508
- if (!responses?.filter) {
509
- return [];
510
- }
511
- const localFiles = await flattenDirectory(draftPath, fs);
512
- const localRelatives = new Set(localFiles.map((f) => path.relative(draftPath, f).split(path.sep).join("/")));
513
- const pathsToDelete = [];
514
- const relativesToDelete = [];
515
- for (const entry of responses) {
516
- const href = entry["D:href"];
517
- if (!href) {
518
- continue;
519
- }
520
- const entryUrl = new URL(href, targetUrl);
521
- const basePath = new URL(targetUrl).pathname;
522
- const relative = entryUrl.pathname.slice(basePath.length);
523
- if (!relative || relative === "/") {
524
- continue;
525
- }
526
- const draftPrefix = constants_1.FolderNames.DRAFT + "/";
527
- if (!relative.startsWith(draftPrefix)) {
528
- continue;
529
- }
530
- const draftRelative = relative.slice(draftPrefix.length);
531
- if (!draftRelative) {
532
- continue;
533
- }
534
- if (draftRelative.endsWith("/")) {
535
- continue;
536
- }
537
- const localEquivalent = path.join(draftPath, ...draftRelative.split("/"));
538
- if (gitignoreMatcher.matches(localEquivalent)) {
539
- logger.info(`File is in .gitignore; skipping deletion: ${href}`);
540
- continue;
541
- }
542
- if (!localRelatives.has(draftRelative)) {
543
- pathsToDelete.push(entryUrl.href);
544
- relativesToDelete.push(draftRelative);
545
- }
223
+ const built = outcome.build;
224
+ const typeCheckErrors = (0, ServerCompile_1.typeCheckErrorsOf)(built?.compile ?? null);
225
+ const nothingPublished = snapshot ? " Nothing was published." : "";
226
+ const status = built?.compile?.status;
227
+ const buildIncomplete = built?.compile && status && !(0, b6p_core_bsjs_git_1.compileAllowsPublish)(status)
228
+ ? {
229
+ status,
230
+ rawStatus: built.compile.rawStatus,
231
+ description: built.outcomeUnknown
232
+ ? built.outcomeUnknown.buildFound
233
+ ? "the platform could not tell whether its build landed; the draft it holds is a build of this push, " +
234
+ "taken in here, but how that build went is not known"
235
+ : "the platform could not tell whether its build landed, and no build of this push is on its draft"
236
+ : describeBuildStatus(status, built.compile.rawStatus),
546
237
  }
547
- if (pathsToDelete.length === 0) {
548
- logger.info("No unused upstairs paths to delete.");
549
- return [];
238
+ : null;
239
+ const fastForward = built?.fastForward ?? null;
240
+ if (built?.error) {
241
+ prompt.error(built.errorKind === "not-requested"
242
+ ? `The draft was pushed (commit ${outcome.commitSha}), but no build was asked for: ${built.error}${nothingPublished}`
243
+ : built.errorKind === "refused"
244
+ ? `The draft was pushed (commit ${outcome.commitSha}), but the platform refused to build it ` +
245
+ `(${built.errorReason}): ${built.error}${nothingPublished}`
246
+ : `The draft was pushed (commit ${outcome.commitSha}), but the platform's build request failed: ${built.error}${nothingPublished}`);
247
+ }
248
+ else if (built?.compile) {
249
+ if (buildIncomplete) {
250
+ const gate = built.compile.gate;
251
+ prompt.error(`The draft was pushed (commit ${outcome.commitSha}), but ${buildIncomplete.description} ` +
252
+ `(${buildIncomplete.rawStatus || buildIncomplete.status}).${nothingPublished}` +
253
+ (gate && gate.problems.length > 0
254
+ ? `\n\n${gate.problems.map((p) => `${p.tsconfig}: ${p.message}`).join("\n")}`
255
+ : ""));
550
256
  }
551
- // "No" is FIRST: an empty answer and the CLI's --yes both take options[0], and a yes deletes
552
- // platform files that may exist nowhere else (ClickUp 86bc2h3ef).
553
- const NO = "No";
554
- const YES = "Yes";
555
- let answer;
556
- try {
557
- answer = await prompt.confirm(`The following ${pathsToDelete.length} upstairs path(s) no longer have local counterparts:\n\n${pathsToDelete.join("\n")}\n\nDelete them?`, [NO, YES], { destructive: true, safeOption: NO });
257
+ else if (!built.vouched && status === "COMPILED") {
258
+ prompt.warn("The build was not clean, so the platform committed its output without a build manifest: a publish of this " +
259
+ "draft is refused until it builds cleanly.");
558
260
  }
559
- catch (e) {
560
- // No answer at all (end of input, a dismissed dialog) is not a yes. The files stay, so they
561
- // must be reported as kept, not lost in the catch below as a failed cleanup.
562
- logger.warn(`Cleanup prompt got no answer: ${e instanceof Error ? e.message : e}`);
261
+ if (fastForward?.state === "blocked") {
262
+ prompt.error(`The platform built the draft (build commit ${built.buildCommitSha}), but the draft folder was left at ` +
263
+ `${outcome.commitSha}: ${fastForward.blockedPaths.length} local file(s) the build changes differ from both ` +
264
+ `the pushed commit and the build.${nothingPublished}\n\n${fastForward.blockedPaths.join("\n")}`);
563
265
  }
564
- if (answer !== YES) {
565
- // A warning, not info: consumers that quiet info (e.g. for machine-readable output) still
566
- // show warnings, and an auto-answered prompt was never shown to anyone. It says what was
567
- // kept; how to confirm a delete is the consumer's to explain.
568
- prompt.warn(`Kept ${pathsToDelete.length} platform-only file(s): they are on the platform but not in your local ` +
569
- `draft folder, and deleting them was not confirmed.\n\n${pathsToDelete.join("\n")}\n\n` +
570
- `Pull them to get them locally.`);
571
- return relativesToDelete;
266
+ else if (fastForward?.state === "failed") {
267
+ prompt.error(`The platform built the draft (build commit ${built.buildCommitSha}), but the draft folder could not be ` +
268
+ `moved to it: ${fastForward.error}${nothingPublished}`);
572
269
  }
573
- for (const url of pathsToDelete) {
574
- logger.info("Deleting unused upstairs path: " + url);
575
- await sessionManager.fetch(url, { method: constants_1.Http.Methods.DELETE });
270
+ if (typeCheckErrors.length > 0) {
271
+ const total = built.compile.errors + built.compile.warnings;
272
+ prompt.warn(`The platform's build reported ${total} diagnostic(s)` +
273
+ (total > typeCheckErrors.length
274
+ ? `; ${typeCheckErrors.length} of them in the script's sources are listed`
275
+ : " in the script's sources") +
276
+ `:\n\n` +
277
+ typeCheckErrors
278
+ .map((e) => `${e.file}:${e.line}:${e.column} ${e.severity} TS${e.code}: ${e.message}`)
279
+ .join("\n"));
576
280
  }
577
- return [];
578
281
  }
579
- catch (e) {
580
- logger.warn(`Cleanup failed: ${e instanceof Error ? e.message : e}`);
581
- return [];
282
+ const publish = outcome.publish;
283
+ if (publish?.error) {
284
+ prompt.error(`The draft was pushed (commit ${outcome.commitSha}) but the platform did not publish it: ${publish.error}`);
285
+ }
286
+ if (publish && publish.liveVerified === false) {
287
+ prompt.error(`The platform reports publishing commit ${publish.publishedSha}, but its published branch is at another ` +
288
+ `commit${publish.liveMismatches.length > 0 ? `; the files that differ:\n\n${publish.liveMismatches.join("\n")}` : ""}.\n\n` +
289
+ `The live version may be out of date. Run the snapshot push again.`);
582
290
  }
291
+ if (publish && publish.liveVerified === null && !publish.error) {
292
+ prompt.warn("Could not read the platform's published branch back to verify the publish.");
293
+ }
294
+ const builtCleanly = !built ||
295
+ (!built.error &&
296
+ !buildIncomplete &&
297
+ (fastForward === null || fastForward.state === "fast-forwarded" || fastForward.state === "unchanged"));
298
+ const succeeded = snapshot ? !!publish && !publish.error && publish.liveVerified !== false : builtCleanly;
299
+ if (succeeded) {
300
+ prompt.info(snapshot ? "Snapshot complete!" : "Push complete!");
301
+ }
302
+ return {
303
+ pushed: true,
304
+ commitSha: outcome.commitSha,
305
+ publishedSha: publish?.publishedSha ?? null,
306
+ publishError: publish?.error ?? null,
307
+ publishRefusal: publish?.refusal ?? null,
308
+ switchedToGit: outcome.switchedToGit,
309
+ route,
310
+ snapshotRefused,
311
+ build: built?.compile ?? null,
312
+ buildCommitSha: built?.buildCommitSha ?? null,
313
+ buildVouched: built && !built.error ? built.vouched : null,
314
+ buildError: built?.error ?? null,
315
+ buildErrorKind: built?.errorKind ?? null,
316
+ buildErrorReason: built?.errorReason ?? null,
317
+ buildIncomplete,
318
+ buildFastForward: fastForward,
319
+ typeCheckDiagnostics: built?.compile ? built.compile.errors + built.compile.warnings : null,
320
+ typeCheckErrors,
321
+ liveVerified: publish?.liveVerified ?? null,
322
+ liveMismatches: publish?.liveMismatches ?? [],
323
+ keptPlatformOnly: outcome.keptPlatformOnly,
324
+ };
583
325
  }
584
326
  //# sourceMappingURL=push.js.map