@lariocpt/crust-site 0.0.0-stage → 0.4.2
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/LICENSE +21 -0
- package/README.md +99 -2
- package/docs/USAGE.md +1128 -0
- package/package.json +33 -4
- package/src/assets.ts +875 -0
- package/src/build-lock.ts +214 -0
- package/src/build.ts +755 -0
- package/src/cli.ts +269 -0
- package/src/config.ts +538 -0
- package/src/content.ts +267 -0
- package/src/dev.ts +821 -0
- package/src/diagnostics.ts +382 -0
- package/src/emit.ts +260 -0
- package/src/fence.ts +593 -0
- package/src/frontmatter.ts +240 -0
- package/src/fs-path.ts +54 -0
- package/src/html.ts +400 -0
- package/src/index.ts +128 -0
- package/src/markdown.ts +444 -0
- package/src/pages.ts +169 -0
- package/src/publication.ts +245 -0
- package/src/render.ts +940 -0
- package/src/routes.ts +363 -0
- package/src/types.ts +250 -0
- package/src/url.ts +273 -0
- package/src/validate.ts +367 -0
package/src/pages.ts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// Page parsing: file → frontmatter → markdown → Page (plan §2 content
|
|
2
|
+
// contract). This is the ONLY place the frontmatter rules that are not
|
|
3
|
+
// frontmatter-syntax (chunk 2) get applied: the derived description, the
|
|
4
|
+
// parseData hook, the draft flag. Route/canonicalUrl are filled later
|
|
5
|
+
// (buildRouteTable / chunk 6) — a Page from here carries only what the file
|
|
6
|
+
// itself said.
|
|
7
|
+
|
|
8
|
+
import type { Diagnostic } from "./diagnostics";
|
|
9
|
+
import { parseFrontmatter } from "./frontmatter";
|
|
10
|
+
import { renderMarkdown } from "./markdown";
|
|
11
|
+
import type { FrontmatterResult, Page, ResolvedSite, RouteResolver } from "./types";
|
|
12
|
+
|
|
13
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
14
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
15
|
+
const proto = Object.getPrototypeOf(value);
|
|
16
|
+
return proto === Object.prototype || proto === null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The description derivation (plan §2): first paragraph plain text,
|
|
21
|
+
* whitespace collapsed, truncated at 160 chars on a word boundary (the cut
|
|
22
|
+
* is the last space at or before 160; a single over-long word keeps the raw
|
|
23
|
+
* 160-char cut — a description is metadata, not a place to be clever).
|
|
24
|
+
*/
|
|
25
|
+
export function deriveDescription(firstParagraph: string): string {
|
|
26
|
+
const collapsed = firstParagraph.replace(/\s+/g, " ").trim();
|
|
27
|
+
if (collapsed.length <= 160) return collapsed;
|
|
28
|
+
const cut = collapsed.slice(0, 160);
|
|
29
|
+
const sp = cut.lastIndexOf(" ");
|
|
30
|
+
return (sp > 0 ? cut.slice(0, sp) : cut).trimEnd();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ParsePageInput {
|
|
34
|
+
/** The .md file on disk. */
|
|
35
|
+
absolutePath: string;
|
|
36
|
+
/** posix, relative to content.directory, extension stripped (plan §2). */
|
|
37
|
+
relativePath: string;
|
|
38
|
+
/** posix path used in diagnostics. */
|
|
39
|
+
sourcePath: string;
|
|
40
|
+
resolvedSite: ResolvedSite;
|
|
41
|
+
/**
|
|
42
|
+
* The page's route, when the caller already knows it (chunk 6 computes
|
|
43
|
+
* routes before rendering so relative .md links resolve against it).
|
|
44
|
+
* Without it, relative .md links cannot be route-resolved and are
|
|
45
|
+
* recorded exists:false — honest, never a silent pass.
|
|
46
|
+
*/
|
|
47
|
+
pageRoute?: string;
|
|
48
|
+
/** Route-table lookup handed to the markdown renderer (chunk 6 wires it). */
|
|
49
|
+
routeResolver?: RouteResolver;
|
|
50
|
+
/**
|
|
51
|
+
* Already-parsed frontmatter (chunk 8's pre-pass reads the file and parses
|
|
52
|
+
* the frontmatter ONCE, then hands it over so parsePage skips its own
|
|
53
|
+
* read+parse — a frontmatter problem is diagnosed exactly once, and the
|
|
54
|
+
* file is read exactly once). Without it, parsePage reads and parses as
|
|
55
|
+
* before.
|
|
56
|
+
*/
|
|
57
|
+
frontmatter?: FrontmatterResult;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Parse one .md file into a Page. Frontmatter problems propagate as the
|
|
62
|
+
* BuildError chunk 2 already raises (sorted, full-file coordinates);
|
|
63
|
+
* render-level problems (link.invalid, data-invalid) come back on the Page
|
|
64
|
+
* so a build can collect them across pages instead of dying on the first.
|
|
65
|
+
*/
|
|
66
|
+
export async function parsePage(input: ParsePageInput): Promise<Page> {
|
|
67
|
+
const { absolutePath, relativePath, sourcePath, resolvedSite } = input;
|
|
68
|
+
// Bun.file().text() hands back the raw bytes decoded; parseFrontmatter
|
|
69
|
+
// normalizes CRLF/CR and strips a BOM, and the body it returns is already
|
|
70
|
+
// LF-only — the markdown renderer never sees a CRLF. A caller that already
|
|
71
|
+
// parsed the frontmatter (chunk 8's pre-pass) passes the result, and the
|
|
72
|
+
// file is not re-read: the frontmatter — and its diagnostics — are
|
|
73
|
+
// produced exactly once.
|
|
74
|
+
const parsed =
|
|
75
|
+
input.frontmatter ?? parseFrontmatter(await Bun.file(absolutePath).text(), sourcePath);
|
|
76
|
+
// The URL policy's base is the FULL site URL — path prefix included — and
|
|
77
|
+
// markdown.ts combines it with `pageRoute`, so the base for a relative ref
|
|
78
|
+
// is exactly the page's canonical URL (url.ts: urlBase === canonicalUrl).
|
|
79
|
+
// Handing over `new URL(site).origin` here is the bug this line pins: for a
|
|
80
|
+
// prefixed site (https://x.dev/docs) an origin base silently drops the
|
|
81
|
+
// prefix from every relative-ref resolution.
|
|
82
|
+
const md = renderMarkdown(parsed.body, {
|
|
83
|
+
sourcePath,
|
|
84
|
+
bodyStartLine: parsed.bodyStartLine,
|
|
85
|
+
siteUrl: resolvedSite.site,
|
|
86
|
+
pageRoute: input.pageRoute,
|
|
87
|
+
resolveInternal: input.routeResolver,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const diagnostics: Diagnostic[] = [...md.diagnostics];
|
|
91
|
+
let description = parsed.frontmatter.description;
|
|
92
|
+
const warnings: Diagnostic[] = [];
|
|
93
|
+
if (description === undefined) {
|
|
94
|
+
if (md.firstParagraph === "") {
|
|
95
|
+
// Nothing to derive from (empty body, or a first paragraph with no
|
|
96
|
+
// text). The description stays "" and the page is still legal — but
|
|
97
|
+
// the warning must NOT claim a derivation happened (crust rule 1:
|
|
98
|
+
// the code must be true).
|
|
99
|
+
description = "";
|
|
100
|
+
warnings.push({
|
|
101
|
+
code: "frontmatter.missing-description",
|
|
102
|
+
severity: "warning",
|
|
103
|
+
sourcePath,
|
|
104
|
+
line: 1,
|
|
105
|
+
message:
|
|
106
|
+
"no description in frontmatter and no text to derive one from (the body has no first paragraph, or it has no text); the description stays empty",
|
|
107
|
+
});
|
|
108
|
+
} else {
|
|
109
|
+
description = deriveDescription(md.firstParagraph);
|
|
110
|
+
warnings.push({
|
|
111
|
+
code: "frontmatter.derived-description",
|
|
112
|
+
severity: "warning",
|
|
113
|
+
sourcePath,
|
|
114
|
+
line: 1,
|
|
115
|
+
message: `no description in frontmatter; derived from the first paragraph: ${JSON.stringify(description)}`,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// data: ONLY through content.parseData (plan §2 — raw frontmatter data is
|
|
121
|
+
// never passed through unvalidated). No parseData → data stays {} even
|
|
122
|
+
// when the frontmatter carried data.
|
|
123
|
+
let data: Record<string, unknown> = {};
|
|
124
|
+
const parseData = resolvedSite.content.parseData;
|
|
125
|
+
if (parseData) {
|
|
126
|
+
try {
|
|
127
|
+
let result: unknown = parseData(parsed.frontmatter.data ?? {}, { sourcePath });
|
|
128
|
+
// The contract says parseData returns `unknown` — an ASYNC hook returns
|
|
129
|
+
// a Promise, which must be awaited (pinned): a rejected Promise is a
|
|
130
|
+
// frontmatter.data-invalid like any other failure, never a raw
|
|
131
|
+
// unhandled rejection and never a silent pass.
|
|
132
|
+
if (result !== null && typeof result === "object") {
|
|
133
|
+
const then = (result as { then?: unknown }).then;
|
|
134
|
+
if (typeof then === "function") result = await result;
|
|
135
|
+
}
|
|
136
|
+
if (!isPlainObject(result)) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
`parseData must return a plain object, returned ${result === null ? "null" : typeof result}`,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
data = result;
|
|
142
|
+
} catch (e) {
|
|
143
|
+
diagnostics.push({
|
|
144
|
+
code: "frontmatter.data-invalid",
|
|
145
|
+
severity: "error",
|
|
146
|
+
sourcePath,
|
|
147
|
+
line: parsed.dataLine,
|
|
148
|
+
message: `content.parseData failed: ${e instanceof Error ? e.message : String(e)}`,
|
|
149
|
+
});
|
|
150
|
+
data = {};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
sourcePath,
|
|
156
|
+
relativePath,
|
|
157
|
+
...(parsed.frontmatter.route !== undefined ? { route: parsed.frontmatter.route } : {}),
|
|
158
|
+
...(parsed.frontmatter.layout !== undefined ? { layout: parsed.frontmatter.layout } : {}),
|
|
159
|
+
title: parsed.frontmatter.title,
|
|
160
|
+
description,
|
|
161
|
+
headings: md.headings,
|
|
162
|
+
data,
|
|
163
|
+
draft: parsed.frontmatter.draft === true,
|
|
164
|
+
body: md.html,
|
|
165
|
+
links: md.links,
|
|
166
|
+
warnings,
|
|
167
|
+
diagnostics: [...diagnostics, ...warnings],
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { copyFile, mkdir, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { compareStrings } from "./diagnostics";
|
|
4
|
+
import { filesystemPath as path } from "./fs-path";
|
|
5
|
+
|
|
6
|
+
/** Tests inject failures without intercepting transaction metadata operations. */
|
|
7
|
+
export interface PublishFs {
|
|
8
|
+
rename: (from: string, to: string) => Promise<void>;
|
|
9
|
+
copyTree: (from: string, to: string) => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const TRANSACTION_RE = /^\.crust-out-txn-([0-9a-f]{16})-(\d+)-([0-9a-f]+)$/;
|
|
13
|
+
|
|
14
|
+
interface Transaction {
|
|
15
|
+
readonly journal: string;
|
|
16
|
+
readonly old: string;
|
|
17
|
+
readonly output: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function messageOf(error: unknown): string {
|
|
21
|
+
return error instanceof Error ? error.message : String(error);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function exists(file: string): Promise<boolean> {
|
|
25
|
+
try {
|
|
26
|
+
await stat(file);
|
|
27
|
+
return true;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return false;
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function copyFallback(error: unknown): boolean {
|
|
35
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
36
|
+
return code === "EPERM" || code === "EXDEV";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Source trees contain only regular files and directories. */
|
|
40
|
+
async function copyTree(from: string, to: string): Promise<void> {
|
|
41
|
+
await mkdir(to, { recursive: true });
|
|
42
|
+
const entries = (await readdir(from, { withFileTypes: true })).sort((a, b) =>
|
|
43
|
+
compareStrings(a.name, b.name),
|
|
44
|
+
);
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
const source = path.join(from, entry.name);
|
|
47
|
+
const target = path.join(to, entry.name);
|
|
48
|
+
if (entry.isDirectory()) await copyTree(source, target);
|
|
49
|
+
else if (entry.isFile()) await copyFile(source, target);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function dependencies(overrides?: Partial<PublishFs>): PublishFs {
|
|
54
|
+
return { rename, copyTree, ...overrides };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function transaction(output: string, suffix: string): Transaction {
|
|
58
|
+
const parent = path.dirname(output);
|
|
59
|
+
return {
|
|
60
|
+
journal: path.join(parent, `.crust-out-txn-${suffix}`),
|
|
61
|
+
old: path.join(parent, `.crust-out-old-${suffix}`),
|
|
62
|
+
output,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function mark(tx: Transaction, state: string): Promise<void> {
|
|
67
|
+
// Empty, immutable markers: process death cannot leave half a JSON record.
|
|
68
|
+
await writeFile(path.join(tx.journal, state), "", { flag: "wx" });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function prune(tx: Transaction): Promise<void> {
|
|
72
|
+
// Keep the terminal marker until ALL backup removal has completed. If a
|
|
73
|
+
// recursive rm dies halfway, recovery must not restore the remaining half.
|
|
74
|
+
await rm(tx.old, { recursive: true, force: true });
|
|
75
|
+
// Remove "first"/"previous" BEFORE terminal markers. A kill during removal
|
|
76
|
+
// of a committed first-build journal must not turn it back into "first".
|
|
77
|
+
for (const name of await readdir(tx.journal)) {
|
|
78
|
+
if (name !== "committed" && name !== "restored") {
|
|
79
|
+
await rm(path.join(tx.journal, name), { recursive: true, force: true });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
await rm(tx.journal, { recursive: true, force: true });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function restore(tx: Transaction, fs: PublishFs): Promise<void> {
|
|
86
|
+
// Never merge a backup into an incomplete publish/recovery target.
|
|
87
|
+
await rm(tx.output, { recursive: true, force: true });
|
|
88
|
+
try {
|
|
89
|
+
await fs.rename(tx.old, tx.output);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (!copyFallback(error)) throw error;
|
|
92
|
+
await fs.copyTree(tx.old, tx.output);
|
|
93
|
+
}
|
|
94
|
+
await mark(tx, "restored");
|
|
95
|
+
await prune(tx).catch(() => {});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function recover(tx: Transaction, fs: PublishFs): Promise<void> {
|
|
99
|
+
const states = new Set(await readdir(tx.journal));
|
|
100
|
+
if (states.has("committed") || states.has("restored")) {
|
|
101
|
+
await prune(tx);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const oldExists = await exists(tx.old);
|
|
105
|
+
if (states.has("copying-backup") && !states.has("backup-ready")) {
|
|
106
|
+
// The original output has not been touched until backup-ready is written.
|
|
107
|
+
// This old tree is a PARTIAL backup, never a recovery source.
|
|
108
|
+
await prune(tx);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (states.has("first")) {
|
|
112
|
+
if (states.has("previous") || oldExists) {
|
|
113
|
+
throw new Error(`ambiguous publication transaction ${JSON.stringify(tx.journal)}`);
|
|
114
|
+
}
|
|
115
|
+
await rm(tx.output, { recursive: true, force: true });
|
|
116
|
+
await prune(tx);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (oldExists) {
|
|
120
|
+
// Also covers a legacy backup adopted just before a kill, before its
|
|
121
|
+
// "previous" marker was written. No backup copy starts before that marker.
|
|
122
|
+
await restore(tx, fs);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (states.has("previous") && !(await exists(tx.output))) {
|
|
126
|
+
throw new Error(`previous output and backup are missing for ${JSON.stringify(tx.journal)}`);
|
|
127
|
+
}
|
|
128
|
+
// No backup: either nothing moved yet, or a restore rename completed just
|
|
129
|
+
// before termination. In both cases the existing output must stay untouched.
|
|
130
|
+
await rm(tx.journal, { recursive: true, force: true });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Caller MUST hold the output lock. A transaction can belong to this same live
|
|
135
|
+
* PID after a failed publish; the lock, not the journal PID, proves exclusivity.
|
|
136
|
+
* Paired backups are excluded from legacy orphan cleanup even if pruning fails.
|
|
137
|
+
*/
|
|
138
|
+
export async function recoverTransactions(
|
|
139
|
+
output: string,
|
|
140
|
+
hash: string,
|
|
141
|
+
overrides?: Partial<PublishFs>,
|
|
142
|
+
): Promise<Set<string>> {
|
|
143
|
+
const paired = new Set<string>();
|
|
144
|
+
const transactions: Transaction[] = [];
|
|
145
|
+
for (const name of (await readdir(path.dirname(output))).sort(compareStrings)) {
|
|
146
|
+
const match = TRANSACTION_RE.exec(name);
|
|
147
|
+
if (match?.[1] !== hash) continue;
|
|
148
|
+
const tx = transaction(output, name.slice(".crust-out-txn-".length));
|
|
149
|
+
paired.add(path.basename(tx.old));
|
|
150
|
+
transactions.push(tx);
|
|
151
|
+
}
|
|
152
|
+
for (const tx of transactions) {
|
|
153
|
+
try {
|
|
154
|
+
await recover(tx, dependencies(overrides));
|
|
155
|
+
} catch (error) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`could not recover publication (${messageOf(error)}); retained backup at ${JSON.stringify(tx.old)}`,
|
|
158
|
+
{ cause: error },
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return paired;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Journal legacy recovery BEFORE its first possible partial copy. Lock required. */
|
|
166
|
+
export async function adoptLegacyBackup(
|
|
167
|
+
old: string,
|
|
168
|
+
output: string,
|
|
169
|
+
overrides?: Partial<PublishFs>,
|
|
170
|
+
): Promise<void> {
|
|
171
|
+
const name = path.basename(old);
|
|
172
|
+
const tx = transaction(output, name.slice(".crust-out-old-".length));
|
|
173
|
+
await mkdir(tx.journal);
|
|
174
|
+
await mark(tx, "previous");
|
|
175
|
+
try {
|
|
176
|
+
await restore(tx, dependencies(overrides));
|
|
177
|
+
} catch (error) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
`restoring the previous output failed (${messageOf(error)}); the previous output is at ${JSON.stringify(old)}`,
|
|
180
|
+
{ cause: error },
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Caller holds the output lock. Rename is preferred; EPERM/EXDEV copies are
|
|
187
|
+
* journaled. Commit precedes cleanup, so a kill during backup deletion preserves
|
|
188
|
+
* the new output. Failed recovery retains both its journal and intact backup.
|
|
189
|
+
*/
|
|
190
|
+
export async function publishOutput(
|
|
191
|
+
staging: string,
|
|
192
|
+
output: string,
|
|
193
|
+
hash: string,
|
|
194
|
+
overrides?: Partial<PublishFs>,
|
|
195
|
+
): Promise<void> {
|
|
196
|
+
const fs = dependencies(overrides);
|
|
197
|
+
const previous = await exists(output);
|
|
198
|
+
const tx = transaction(output, `${hash}-${process.pid}-${randomBytes(6).toString("hex")}`);
|
|
199
|
+
await mkdir(tx.journal);
|
|
200
|
+
await mark(tx, previous ? "previous" : "first");
|
|
201
|
+
let backupReady = false;
|
|
202
|
+
try {
|
|
203
|
+
if (previous) {
|
|
204
|
+
try {
|
|
205
|
+
await fs.rename(output, tx.old);
|
|
206
|
+
backupReady = true;
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if (!copyFallback(error)) throw error;
|
|
209
|
+
await mark(tx, "copying-backup");
|
|
210
|
+
await fs.copyTree(output, tx.old);
|
|
211
|
+
await mark(tx, "backup-ready");
|
|
212
|
+
backupReady = true;
|
|
213
|
+
await rm(output, { recursive: true, force: true });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
await fs.rename(staging, output);
|
|
218
|
+
} catch (error) {
|
|
219
|
+
if (!copyFallback(error)) throw error;
|
|
220
|
+
await fs.copyTree(staging, output);
|
|
221
|
+
}
|
|
222
|
+
await mark(tx, "committed");
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (backupReady) {
|
|
225
|
+
try {
|
|
226
|
+
await restore(tx, fs);
|
|
227
|
+
} catch (restoreError) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
`publish failed (${messageOf(error)}) AND restoring the previous output failed ` +
|
|
230
|
+
`(${messageOf(restoreError)}); the previous output is at ${JSON.stringify(tx.old)}`,
|
|
231
|
+
{ cause: error },
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
} else {
|
|
235
|
+
// No destructive operation on an existing output preceded backup-ready.
|
|
236
|
+
// A first publish can still have left an incomplete target, however.
|
|
237
|
+
if (!previous) await rm(output, { recursive: true, force: true });
|
|
238
|
+
await prune(tx).catch(() => {});
|
|
239
|
+
}
|
|
240
|
+
throw error;
|
|
241
|
+
}
|
|
242
|
+
// Nothing after commit can turn this into a rollback of the new output.
|
|
243
|
+
await prune(tx).catch(() => {});
|
|
244
|
+
await rm(staging, { recursive: true, force: true }).catch(() => {});
|
|
245
|
+
}
|