@bluestep-systems/b6p-core 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -19
- package/dist/B6PCore.js +42 -0
- package/dist/B6PCore.js.map +1 -1
- package/dist/Err.d.ts +6 -0
- package/dist/Err.js +6 -0
- package/dist/Err.js.map +1 -1
- package/dist/data/ScriptKey.d.ts +3 -27
- package/dist/data/ScriptKey.js +12 -24
- package/dist/data/ScriptKey.js.map +1 -1
- package/dist/data/ScriptUrlParser.js +3 -1
- package/dist/data/ScriptUrlParser.js.map +1 -1
- package/dist/index.d.ts +10 -4
- package/dist/index.js +52 -6
- package/dist/index.js.map +1 -1
- package/dist/providers.d.ts +13 -0
- package/dist/script/GitIdentity.d.ts +48 -0
- package/dist/script/GitIdentity.js +52 -0
- package/dist/script/GitIdentity.js.map +1 -0
- package/dist/script/GitSync.d.ts +321 -0
- package/dist/script/GitSync.js +1001 -0
- package/dist/script/GitSync.js.map +1 -0
- package/dist/script/ScriptContext.d.ts +22 -0
- package/dist/script/ScriptFile.d.ts +4 -96
- package/dist/script/ScriptFile.js +7 -248
- package/dist/script/ScriptFile.js.map +1 -1
- package/dist/script/ScriptFolder.d.ts +0 -9
- package/dist/script/ScriptFolder.js +4 -7
- package/dist/script/ScriptFolder.js.map +1 -1
- package/dist/script/ScriptNode.d.ts +0 -9
- package/dist/script/ScriptNode.js.map +1 -1
- package/dist/script/ScriptRoot.d.ts +0 -2
- package/dist/script/ScriptRoot.js +0 -21
- package/dist/script/ScriptRoot.js.map +1 -1
- package/dist/script/ScriptService.d.ts +78 -8
- package/dist/script/ScriptService.js +126 -52
- package/dist/script/ScriptService.js.map +1 -1
- package/dist/script/ScriptTranspiler.d.ts +62 -0
- package/dist/script/ScriptTranspiler.js +97 -5
- package/dist/script/ScriptTranspiler.js.map +1 -1
- package/dist/script/push.d.ts +82 -148
- package/dist/script/push.js +145 -384
- package/dist/script/push.js.map +1 -1
- package/package.json +12 -8
- package/dist/script/SnapshotHistoryRecorder.d.ts +0 -47
- package/dist/script/SnapshotHistoryRecorder.js +0 -231
- package/dist/script/SnapshotHistoryRecorder.js.map +0 -1
package/dist/script/push.js
CHANGED
|
@@ -36,31 +36,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.legacySyncRecords = legacySyncRecords;
|
|
39
40
|
exports.checkEmittedEntrypoint = checkEmittedEntrypoint;
|
|
40
|
-
exports.verifyLiveSnapshot = verifyLiveSnapshot;
|
|
41
|
-
exports.collectOverwriteCandidates = collectOverwriteCandidates;
|
|
42
|
-
exports.confirmOverwrites = confirmOverwrites;
|
|
43
41
|
exports.executePush = executePush;
|
|
44
|
-
exports.cleanupUnusedUpstairsPaths = cleanupUnusedUpstairsPaths;
|
|
45
42
|
const path = __importStar(require("path"));
|
|
46
|
-
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
47
43
|
const typescript_1 = __importDefault(require("typescript"));
|
|
44
|
+
const b6p_core_bsjs_git_1 = require("@bluestep-systems/b6p-core-bsjs-git");
|
|
48
45
|
const constants_1 = require("../constants");
|
|
49
46
|
const B6PUri_1 = require("../B6PUri");
|
|
50
|
-
const GlobMatcher_1 = require("../data/GlobMatcher");
|
|
51
47
|
const ScriptUrlParser_1 = require("../data/ScriptUrlParser");
|
|
52
48
|
const ScriptFactory_1 = require("./ScriptFactory");
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const ScriptFile_1 = require("./ScriptFile");
|
|
49
|
+
const GitIdentity_1 = require("./GitIdentity");
|
|
50
|
+
const GitSync_1 = require("./GitSync");
|
|
56
51
|
const TsConfig_1 = require("./TsConfig");
|
|
57
52
|
/**
|
|
58
|
-
* Recursively collect all files under a directory.
|
|
53
|
+
* Recursively collect all files under a directory, leaving out a git repository's own `.git` folder.
|
|
59
54
|
*/
|
|
60
55
|
async function flattenDirectory(dirPath, fs) {
|
|
61
56
|
const results = [];
|
|
62
57
|
const entries = await fs.readDirectory(B6PUri_1.B6PUri.fromFsPath(dirPath));
|
|
63
58
|
for (const [name, type] of entries) {
|
|
59
|
+
if (name === ".git") {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
64
62
|
const full = path.join(dirPath, name);
|
|
65
63
|
if (type === "directory") {
|
|
66
64
|
const nested = await flattenDirectory(full, fs);
|
|
@@ -73,25 +71,53 @@ async function flattenDirectory(dirPath, fs) {
|
|
|
73
71
|
return results;
|
|
74
72
|
}
|
|
75
73
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
74
|
+
* 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
|
|
75
|
+
* local edit from a platform change in a folder that has no repository yet.
|
|
76
|
+
* @param scriptRoot The script whose metadata holds the records
|
|
77
|
+
* @param draftPath The draft folder the records' paths are under
|
|
78
|
+
* @lastreviewed null
|
|
79
79
|
*/
|
|
80
|
-
async function
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
80
|
+
async function legacySyncRecords(scriptRoot, draftPath) {
|
|
81
|
+
const metadata = await scriptRoot.getMetaData();
|
|
82
|
+
const records = new Map((metadata?.pushPullRecords ?? []).map((r) => [r.downstairsPath, r.lastVerifiedHash]));
|
|
83
|
+
return async (relative) => records.get(B6PUri_1.B6PUri.fromFsPath(path.join(draftPath, ...relative.split("/"))).fsPath) ?? null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The build manifest as it is now in the draft folder, with where it goes back: a compile wipes the build folder, and a
|
|
87
|
+
* build that is not fully clean must leave an existing manifest as it was (spec §6), so it is put back afterwards.
|
|
88
|
+
* @lastreviewed null
|
|
89
|
+
*/
|
|
90
|
+
async function existingManifest(ctx, draftPath) {
|
|
91
|
+
const rootFile = async (name) => {
|
|
92
|
+
const uri = B6PUri_1.B6PUri.fromFsPath(path.join(draftPath, name));
|
|
93
|
+
return (await ctx.fs.exists(uri)) ? Buffer.from(await ctx.fs.readFile(uri)).toString("utf8") : undefined;
|
|
94
|
+
};
|
|
95
|
+
const config = (await rootFile("tsconfig.json")) ?? (await rootFile("jsconfig.json"));
|
|
96
|
+
const relative = (0, b6p_core_bsjs_git_1.buildManifestPath)((0, b6p_core_bsjs_git_1.buildOutputFolder)(config));
|
|
97
|
+
const uri = B6PUri_1.B6PUri.fromFsPath(path.join(draftPath, ...relative.split("/")));
|
|
98
|
+
return (await ctx.fs.exists(uri)) ? { uri, bytes: await ctx.fs.readFile(uri) } : undefined;
|
|
99
|
+
}
|
|
100
|
+
async function restoreManifest(ctx, kept) {
|
|
101
|
+
if (kept) {
|
|
102
|
+
await ctx.fs.createDirectory(kept.uri.dirname);
|
|
103
|
+
await ctx.fs.writeFile(kept.uri, kept.bytes);
|
|
93
104
|
}
|
|
94
105
|
}
|
|
106
|
+
function notPushed(typeCheckDiagnostics, typeCheckErrors = []) {
|
|
107
|
+
return {
|
|
108
|
+
pushed: false,
|
|
109
|
+
commitSha: null,
|
|
110
|
+
publishedSha: null,
|
|
111
|
+
publishError: null,
|
|
112
|
+
publishRefusal: null,
|
|
113
|
+
switchedToGit: false,
|
|
114
|
+
typeCheckDiagnostics,
|
|
115
|
+
typeCheckErrors,
|
|
116
|
+
liveVerified: null,
|
|
117
|
+
liveMismatches: [],
|
|
118
|
+
keptPlatformOnly: [],
|
|
119
|
+
};
|
|
120
|
+
}
|
|
95
121
|
/**
|
|
96
122
|
* Statements the compiler writes into a module with no code of its own: the ES module marker a
|
|
97
123
|
* types-only file compiles to, and the CommonJS preamble. Compared token by token, so spacing and
|
|
@@ -153,160 +179,39 @@ async function checkEmittedEntrypoint(opts) {
|
|
|
153
179
|
return { status: hasCode(text) ? "ok" : "empty", emittedPath };
|
|
154
180
|
}
|
|
155
181
|
/**
|
|
156
|
-
*
|
|
157
|
-
* @
|
|
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).
|
|
182
|
+
* Core push implementation, on git: the draft folder is the script's git working tree, a push commits it and pushes the
|
|
183
|
+
* draft branch, and a snapshot then publishes it (see {@link pushDraft}).
|
|
169
184
|
*
|
|
170
|
-
* A
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
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;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Core push implementation.
|
|
185
|
+
* A snapshot push compiles first and stops before pushing anything if the compiled entrypoint is missing or blank. It
|
|
186
|
+
* is published as pushed: the compiled output is part of the commit. If the platform refuses the publish the draft
|
|
187
|
+
* stays pushed and the result carries `publishError`. A snapshot that compiled with diagnostics is published anyway and
|
|
188
|
+
* warned about loudly.
|
|
274
189
|
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
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
|
|
281
|
-
*
|
|
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`.
|
|
190
|
+
* Before anything is pushed, one confirmation covers every platform file the push would overwrite; declining stops the
|
|
191
|
+
* push with nothing sent.
|
|
286
192
|
* @param opts.overwrite Draft-relative paths whose overwrite the caller confirms up front, so the
|
|
287
193
|
* push doesn't ask about them (e.g. a consumer's flag, after the user approved the files a
|
|
288
194
|
* declined push listed). Other at-risk files still ask.
|
|
195
|
+
* @param opts.author Who the commit is by. When absent: the folder's `git config`, then the environment.
|
|
196
|
+
* @param opts.adoptUnbound `false` for a deploy to a script the folder isn't the working copy of: the folder is then
|
|
197
|
+
* never bound to the target's repo. Default `true`.
|
|
289
198
|
* @throws an {@link Err.OverwriteDeclinedError} when an overwrite is not confirmed
|
|
199
|
+
* @throws {GitIdentityError} when no commit author can be found
|
|
290
200
|
* @lastreviewed null
|
|
291
201
|
*/
|
|
292
202
|
async function executePush(opts) {
|
|
293
203
|
const { ctx, targetUrl, rootPath, snapshot, message, overwrite } = opts;
|
|
294
|
-
const { fs, prompt, logger, sessionManager
|
|
204
|
+
const { fs, prompt, logger, sessionManager } = ctx;
|
|
295
205
|
const draftPath = path.join(rootPath, constants_1.FolderNames.DRAFT);
|
|
296
206
|
const draftUri = B6PUri_1.B6PUri.fromFsPath(draftPath);
|
|
297
207
|
if (!(await fs.exists(draftUri))) {
|
|
298
208
|
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
|
-
};
|
|
209
|
+
return notPushed(null);
|
|
307
210
|
}
|
|
308
|
-
//
|
|
309
|
-
//
|
|
211
|
+
// Fail before the compile and before the platform is touched: a commit made as nobody must not happen, and a script
|
|
212
|
+
// must not be switched to git by a push that then cannot commit.
|
|
213
|
+
const author = await (0, GitIdentity_1.resolveGitIdentity)({ explicit: opts.author, dir: draftPath, env: ctx.gitEnv });
|
|
214
|
+
// Build a parser from the target URL so the ScriptRoot can resolve the script's identity.
|
|
310
215
|
const parser = new ScriptUrlParser_1.ScriptUrlParser(targetUrl, sessionManager, logger, prompt);
|
|
311
216
|
const factory = new ScriptFactory_1.ScriptFactory(ctx);
|
|
312
217
|
// One ScriptRoot for the whole push; all files in this draft tree are
|
|
@@ -315,31 +220,45 @@ async function executePush(opts) {
|
|
|
315
220
|
const scriptRoot = factory.createScriptRoot(rootUri);
|
|
316
221
|
scriptRoot.withParser(parser);
|
|
317
222
|
// Snapshots transpile TS into the draft build folder so both the source
|
|
318
|
-
// and emitted JS
|
|
319
|
-
//
|
|
320
|
-
// A plain (non-snapshot) push does not compile, so its type-check status is
|
|
223
|
+
// and emitted JS are part of the commit that gets published. A plain
|
|
224
|
+
// (non-snapshot) push does not compile, so its type-check status is
|
|
321
225
|
// null rather than a count.
|
|
226
|
+
let buildSucceeded = false;
|
|
322
227
|
let typeCheckDiagnostics = null;
|
|
228
|
+
let typeCheckErrors = [];
|
|
323
229
|
let typeCheckDetail = "";
|
|
324
230
|
if (snapshot) {
|
|
325
|
-
const
|
|
231
|
+
const keptManifest = await existingManifest(ctx, draftPath);
|
|
232
|
+
let compileOutcome;
|
|
233
|
+
try {
|
|
234
|
+
compileOutcome = await scriptRoot.compileDraftFolder();
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
await restoreManifest(ctx, keptManifest);
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
if (!compileOutcome.fullyClean) {
|
|
241
|
+
await restoreManifest(ctx, keptManifest);
|
|
242
|
+
}
|
|
326
243
|
typeCheckDiagnostics = compileOutcome.diagnosticCount;
|
|
244
|
+
typeCheckErrors = compileOutcome.typeCheckErrors;
|
|
327
245
|
typeCheckDetail = compileOutcome.diagnosticText;
|
|
328
246
|
const buildFolderPath = (await scriptRoot.getDraftBuildFolder()).uri().fsPath;
|
|
329
247
|
const entrypoint = await checkEmittedEntrypoint({ draftPath, buildFolderPath, fs });
|
|
330
248
|
if (entrypoint.status === "missing" || entrypoint.status === "empty") {
|
|
249
|
+
await restoreManifest(ctx, keptManifest);
|
|
331
250
|
prompt.error(`Snapshot not published: the compiled entrypoint ${entrypoint.emittedPath} ` +
|
|
332
251
|
`${entrypoint.status === "missing" ? "is missing" : "has no code"} after compiling scripts/app.ts. ` +
|
|
333
252
|
`The platform runs that file, so publishing it would break the live version. Nothing was ` +
|
|
334
|
-
`
|
|
335
|
-
return
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
253
|
+
`pushed. Check scripts/app.ts, the compile output and the draft ${TsConfig_1.TsConfig.NAME}.`);
|
|
254
|
+
return notPushed(typeCheckDiagnostics, typeCheckErrors);
|
|
255
|
+
}
|
|
256
|
+
// A manifest vouches that every project's output was written from the sources as they are: a build that reported
|
|
257
|
+
// any error, or did not write every project's output, writes none (any existing one then goes stale).
|
|
258
|
+
buildSucceeded = compileOutcome.fullyClean;
|
|
259
|
+
if (!compileOutcome.fullyClean) {
|
|
260
|
+
prompt.warn(`No build manifest was written, because the build was not fully clean:\n\n${compileOutcome.uncleanReasons.join("\n")}\n\n` +
|
|
261
|
+
`A publish of this draft is refused until it is rebuilt cleanly and pushed.`);
|
|
343
262
|
}
|
|
344
263
|
}
|
|
345
264
|
// Push does NOT transpile client bundles (e.g. a MergeReport `static/script.ts`
|
|
@@ -357,102 +276,44 @@ async function executePush(opts) {
|
|
|
357
276
|
logger.info(`Found ${allFiles.length} files in draft folder`);
|
|
358
277
|
if (allFiles.length === 0) {
|
|
359
278
|
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
|
-
};
|
|
279
|
+
return notPushed(typeCheckDiagnostics, typeCheckErrors);
|
|
368
280
|
}
|
|
369
|
-
|
|
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),
|
|
281
|
+
const outcome = await (0, GitSync_1.pushDraft)({
|
|
377
282
|
ctx,
|
|
378
|
-
|
|
283
|
+
script: await parser.getScriptBaseKey(),
|
|
284
|
+
baseUrl: `${parser.url.origin}/`,
|
|
285
|
+
draftPath,
|
|
286
|
+
}, {
|
|
287
|
+
message: message && message.trim() ? message : snapshot ? "Snapshot from b6p" : "Push from b6p",
|
|
288
|
+
author,
|
|
289
|
+
snapshot,
|
|
290
|
+
adoptUnbound: opts.adoptUnbound ?? true,
|
|
291
|
+
// The build manifest goes in the same commit as the output it describes, and only after a good build.
|
|
292
|
+
...(buildSucceeded ? { buildManifest: { externallyBuilt: opts.externallyBuilt } } : {}),
|
|
293
|
+
enableGit: opts.enableGit,
|
|
379
294
|
preConfirmed: overwrite,
|
|
295
|
+
lastSynced: await legacySyncRecords(scriptRoot, draftPath),
|
|
380
296
|
});
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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;
|
|
297
|
+
if (outcome.switchedToGit) {
|
|
298
|
+
prompt.warn("This script now publishes through git. The switch cannot be undone: its draft and snapshot no longer " +
|
|
299
|
+
"accept WebDAV writes, and its history is the git history from here on.");
|
|
432
300
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
|
|
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
|
-
}
|
|
301
|
+
const publish = outcome.publish;
|
|
302
|
+
if (publish?.error) {
|
|
303
|
+
prompt.error(`The draft was pushed (commit ${outcome.commitSha}) but the platform did not publish it: ${publish.error}`);
|
|
304
|
+
}
|
|
305
|
+
if (publish && publish.liveVerified === false) {
|
|
306
|
+
prompt.error(`The platform reports publishing commit ${publish.publishedSha}, but its published branch is at another ` +
|
|
307
|
+
`commit${publish.liveMismatches.length > 0 ? `; the files that differ:\n\n${publish.liveMismatches.join("\n")}` : ""}.\n\n` +
|
|
308
|
+
`The live version may be out of date. Run the snapshot push again.`);
|
|
309
|
+
}
|
|
310
|
+
if (publish && publish.liveVerified === null && !publish.error) {
|
|
311
|
+
prompt.warn("Could not read the platform's published branch back to verify the publish.");
|
|
451
312
|
}
|
|
452
313
|
// A snapshot that compiled with diagnostics shipped un-type-checked JS. Say so
|
|
453
314
|
// loudly and do NOT let the run read as a clean success — the platform never
|
|
454
315
|
// type-checks, so this push was the only gate (ClickUp 86bbeb659).
|
|
455
|
-
const shippedWithDiagnostics = snapshot && typeCheckDiagnostics !== null && typeCheckDiagnostics > 0;
|
|
316
|
+
const shippedWithDiagnostics = snapshot && !publish?.error && typeCheckDiagnostics !== null && typeCheckDiagnostics > 0;
|
|
456
317
|
if (shippedWithDiagnostics) {
|
|
457
318
|
prompt.warn(`Published WITHOUT a passing type-check: the pre-publish transpile reported ` +
|
|
458
319
|
`${typeCheckDiagnostics} diagnostic(s). The JavaScript was emitted and is now live, but these ` +
|
|
@@ -460,125 +321,25 @@ async function executePush(opts) {
|
|
|
460
321
|
`the platform does not type-check on its side. Review them before relying on this build:\n\n` +
|
|
461
322
|
typeCheckDetail);
|
|
462
323
|
}
|
|
463
|
-
if (
|
|
464
|
-
prompt.
|
|
465
|
-
"
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
prompt.info("Snapshot uploaded — but see the type-check warning above.");
|
|
470
|
-
}
|
|
471
|
-
else {
|
|
472
|
-
prompt.info(snapshot ? "Snapshot complete!" : "Push complete!");
|
|
473
|
-
}
|
|
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
|
-
}
|
|
546
|
-
}
|
|
547
|
-
if (pathsToDelete.length === 0) {
|
|
548
|
-
logger.info("No unused upstairs paths to delete.");
|
|
549
|
-
return [];
|
|
550
|
-
}
|
|
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 });
|
|
558
|
-
}
|
|
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}`);
|
|
563
|
-
}
|
|
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;
|
|
572
|
-
}
|
|
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 });
|
|
576
|
-
}
|
|
577
|
-
return [];
|
|
578
|
-
}
|
|
579
|
-
catch (e) {
|
|
580
|
-
logger.warn(`Cleanup failed: ${e instanceof Error ? e.message : e}`);
|
|
581
|
-
return [];
|
|
324
|
+
if (!publish?.error && publish?.liveVerified !== false) {
|
|
325
|
+
prompt.info(shippedWithDiagnostics
|
|
326
|
+
? "Snapshot published — but see the type-check warning above."
|
|
327
|
+
: snapshot
|
|
328
|
+
? "Snapshot complete!"
|
|
329
|
+
: "Push complete!");
|
|
582
330
|
}
|
|
331
|
+
return {
|
|
332
|
+
pushed: true,
|
|
333
|
+
commitSha: outcome.commitSha,
|
|
334
|
+
publishedSha: publish?.publishedSha ?? null,
|
|
335
|
+
publishError: publish?.error ?? null,
|
|
336
|
+
publishRefusal: publish?.refusal ?? null,
|
|
337
|
+
typeCheckErrors,
|
|
338
|
+
switchedToGit: outcome.switchedToGit,
|
|
339
|
+
typeCheckDiagnostics,
|
|
340
|
+
liveVerified: publish?.liveVerified ?? null,
|
|
341
|
+
liveMismatches: publish?.liveMismatches ?? [],
|
|
342
|
+
keptPlatformOnly: outcome.keptPlatformOnly,
|
|
343
|
+
};
|
|
583
344
|
}
|
|
584
345
|
//# sourceMappingURL=push.js.map
|