gutterpress 0.11.23-alpha.4 → 0.11.23-alpha.6
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 +1 -1
- package/dist/api/index.d.ts +5 -3
- package/dist/api/index.js +17 -7
- package/dist/{build-c48eer6f.js → build-py643c5a.js} +8 -8
- package/dist/{cli-93mkaw6v.js → cli-09jj8w5g.js} +63 -31
- package/dist/{cli-a35w7wzg.js → cli-31anr0r9.js} +107 -56
- package/dist/{cli-y6d1arem.js → cli-55br530w.js} +4 -4
- package/dist/{cli-54xt7pjg.js → cli-58fsk6d7.js} +2 -2
- package/dist/{cli-d9mm3vvh.js → cli-bnf7eb38.js} +1 -1
- package/dist/{cli-gnpea9dx.js → cli-qzkq9em8.js} +1 -1
- package/dist/{cli-pspjxnc8.js → cli-tf9tw6at.js} +1 -1
- package/dist/{cli-rqh295j9.js → cli-x777v272.js} +3 -3
- package/dist/cli.js +12 -12
- package/dist/{doctor-ptb346k8.js → doctor-tyrzqphh.js} +3 -3
- package/dist/{engine-4rzdx6af.js → engine-4rabsgwq.js} +1 -1
- package/dist/{engine-6txhxmmv.js → engine-wm4fggac.js} +2 -2
- package/dist/{ext-gy8szg3x.js → ext-70kt3eft.js} +8 -8
- package/dist/{extension-restore-m8tj43e7.js → extension-restore-fjfn1hrk.js} +4 -4
- package/dist/{extension-restore-dymzcasz.js → extension-restore-whag4sm0.js} +2 -2
- package/dist/{index-8ywkd2sv.js → index-1zqkfzcd.js} +3 -3
- package/dist/{index-5kh4c78h.js → index-2vxzxyyj.js} +2 -2
- package/dist/{index-kaks3mm2.js → index-cmakyf43.js} +3 -3
- package/dist/{index-h6yk5tjx.js → index-cw03e9p4.js} +107 -56
- package/dist/{index-ea94zbq4.js → index-ejbfetdn.js} +327 -86
- package/dist/{index-yc3xj266.js → index-wm4x7xbf.js} +1 -1
- package/dist/index.js +18 -8
- package/dist/lib/publish/connect.d.ts +8 -1
- package/dist/lib/publish/manifest-publish.d.ts +26 -2
- package/dist/lib/publish/selections.d.ts +12 -1
- package/dist/lib/publish/types.d.ts +15 -5
- package/dist/lib/remote-auth/repair.d.ts +2 -2
- package/dist/lib/remote-auth/revisions.d.ts +60 -0
- package/dist/lib/remote-auth/scorched-earth.d.ts +2 -2
- package/dist/lib/remote-auth/sync-messages.d.ts +28 -27
- package/dist/lib/remote-auth/sync-types.d.ts +3 -0
- package/dist/lib/remote-auth/sync.d.ts +7 -8
- package/dist/lib/remote-auth/transport.d.ts +8 -1
- package/dist/lib/source-provider.d.ts +80 -35
- package/dist/{manifest.schema-w86c1xw1.json → manifest.schema-93sd7zje.json} +13 -6
- package/dist/{new-t2t28ccb.js → new-b27kyr02.js} +11 -11
- package/dist/{plugins-fec8t2bh.js → plugins-racab3cj.js} +1 -1
- package/dist/{plugins-sqa4msdk.js → plugins-vpx7c53c.js} +3 -3
- package/dist/{preflight-srq8fktp.js → preflight-akdqz9v8.js} +8 -8
- package/dist/{preview-zsp9hstd.js → preview-bck9f88w.js} +8 -8
- package/dist/{preview-interface-nnmrxyqm.js → preview-interface-0xdh0r5b.js} +3 -66
- package/dist/{publish-hhy31gr9.js → publish-keyp8rh4.js} +8 -8
- package/dist/render.js +2 -2
- package/dist/schema/manifest.types.d.ts +18 -3
- package/dist/{source-provider-knmcam50.js → source-provider-n7vehh6t.js} +15 -3
- package/dist/{source-provider-98k5deda.js → source-provider-tgzet3j5.js} +15 -3
- package/dist/{validate-r9jdz85h.js → validate-z28cvr5x.js} +8 -8
- package/package.json +1 -1
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
capabilitiesFor,
|
|
8
8
|
detectProjectSource,
|
|
9
|
-
findEnclosingRepoDir
|
|
9
|
+
findEnclosingRepoDir,
|
|
10
|
+
syncRemoteFor
|
|
10
11
|
} from "./index-v5mp7a6q.js";
|
|
11
12
|
|
|
12
13
|
// src/lib/git-fs.ts
|
|
@@ -214,6 +215,7 @@ function gitScopeFor(source) {
|
|
|
214
215
|
return source.repoRoot || source.path;
|
|
215
216
|
}
|
|
216
217
|
var HISTORY_PAGE_LIMIT = 100;
|
|
218
|
+
var NO_VERSION_HISTORY = "This book isn't keeping version history yet. Turn on version history first.";
|
|
217
219
|
var DEFAULT_AUTHOR = "gutterpress";
|
|
218
220
|
var DEFAULT_EMAIL = "noreply@gutterpress.local";
|
|
219
221
|
var DEFAULT_BRANCH = "main";
|
|
@@ -385,7 +387,7 @@ class LocalFolderSourceProvider {
|
|
|
385
387
|
async initVersionHistory(options) {
|
|
386
388
|
const dir = options.projectDir;
|
|
387
389
|
if (await findEnclosingRepoDir(dir) !== undefined) {
|
|
388
|
-
throw new Error("This folder is already inside a
|
|
390
|
+
throw new Error("This folder is already inside a book that keeps version history, so " + "Gutterpress won't start a separate one here.");
|
|
389
391
|
}
|
|
390
392
|
return withRepoLock(dir, async () => {
|
|
391
393
|
const cache = {};
|
|
@@ -409,7 +411,7 @@ class LocalFolderSourceProvider {
|
|
|
409
411
|
});
|
|
410
412
|
}
|
|
411
413
|
snapshot() {
|
|
412
|
-
return Promise.reject(new Error(
|
|
414
|
+
return Promise.reject(new Error(NO_VERSION_HISTORY));
|
|
413
415
|
}
|
|
414
416
|
listHistory() {
|
|
415
417
|
return Promise.resolve([]);
|
|
@@ -418,7 +420,7 @@ class LocalFolderSourceProvider {
|
|
|
418
420
|
return Promise.resolve({ entries: [], hasMore: false });
|
|
419
421
|
}
|
|
420
422
|
restore() {
|
|
421
|
-
return Promise.reject(new Error(
|
|
423
|
+
return Promise.reject(new Error(NO_VERSION_HISTORY));
|
|
422
424
|
}
|
|
423
425
|
}
|
|
424
426
|
|
|
@@ -517,7 +519,7 @@ async function snapshotWorkingTreeUnlocked(options) {
|
|
|
517
519
|
const workdirClean = changes.adds.length === 0 && changes.removes.length === 0;
|
|
518
520
|
if (workdirClean && !staleStaging) {
|
|
519
521
|
logger.debug("snapshot", "no changes — skipping");
|
|
520
|
-
throw new Error("
|
|
522
|
+
throw new Error("Nothing new to save — your last version already has everything.");
|
|
521
523
|
}
|
|
522
524
|
if (workdirClean && staleStaging && await stageMatchesHead(dir, cache)) {
|
|
523
525
|
logger.debug("snapshot", "stale marker outlived a completed commit — clearing, not recommitting");
|
|
@@ -555,7 +557,7 @@ async function snapshotWorkingTreeUnlocked(options) {
|
|
|
555
557
|
};
|
|
556
558
|
}
|
|
557
559
|
function isNoChangesError(e) {
|
|
558
|
-
return e instanceof Error && /
|
|
560
|
+
return e instanceof Error && /nothing new to save/i.test(e.message);
|
|
559
561
|
}
|
|
560
562
|
async function countUnversionedChanges(projectDir) {
|
|
561
563
|
const source = await detectProjectSource(projectDir);
|
|
@@ -586,14 +588,13 @@ function gitDirFor(projectDir) {
|
|
|
586
588
|
function snapshotStagingMarkerPath(projectDir) {
|
|
587
589
|
return path2.join(gitDirFor(projectDir), SNAPSHOT_STAGING_MARKER);
|
|
588
590
|
}
|
|
589
|
-
var RESTORE_BACKUP_MESSAGE = "Automatic
|
|
590
|
-
var AUTO_SNAPSHOT_MESSAGE = "Automatic
|
|
591
|
+
var RESTORE_BACKUP_MESSAGE = "Automatic version before restoring";
|
|
592
|
+
var AUTO_SNAPSHOT_MESSAGE = "Automatic version";
|
|
591
593
|
async function restoreVersionWithBackup(options) {
|
|
592
594
|
const { projectDir, id, authorName, authorEmail } = options;
|
|
593
595
|
const source = await detectProjectSource(projectDir);
|
|
594
|
-
if (source.type !== "local-git-folder")
|
|
595
|
-
throw new Error(
|
|
596
|
-
}
|
|
596
|
+
if (source.type !== "local-git-folder")
|
|
597
|
+
throw new Error(NO_VERSION_HISTORY);
|
|
597
598
|
const provider = new LocalGitSourceProvider(source);
|
|
598
599
|
const repoDir = gitScopeFor(source);
|
|
599
600
|
return withRepoLock(repoDir, async () => {
|
|
@@ -610,42 +611,105 @@ async function restoreVersionWithBackup(options) {
|
|
|
610
611
|
try {
|
|
611
612
|
await provider.restoreUnlocked({ projectDir, id });
|
|
612
613
|
} catch (cause) {
|
|
613
|
-
throw new Error(backupId ? "
|
|
614
|
+
throw new Error(backupId ? "Going back to that version didn't finish, but your work is safe — it was " + "saved as an automatic version and appears in your version history." : "Going back to that version didn't finish. Your book files were not changed.", { cause });
|
|
614
615
|
}
|
|
615
616
|
return { restoredId: id, backupId };
|
|
616
617
|
});
|
|
617
618
|
}
|
|
618
|
-
var SWITCH_BRANCH_SNAPSHOT_MESSAGE = "Saved before switching
|
|
619
|
-
async function
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
const repoDir = gitScopeFor(source);
|
|
624
|
-
const [local, current, remotes] = await Promise.all([
|
|
625
|
-
git.listBranches({ fs: gitFs, dir: repoDir }),
|
|
626
|
-
git.currentBranch({ fs: gitFs, dir: repoDir, fullname: false }).catch(() => {
|
|
619
|
+
var SWITCH_BRANCH_SNAPSHOT_MESSAGE = "Saved before switching revision";
|
|
620
|
+
async function readRevisionRefs(dir) {
|
|
621
|
+
const [names, current, remote] = await Promise.all([
|
|
622
|
+
git.listBranches({ fs: gitFs, dir }),
|
|
623
|
+
git.currentBranch({ fs: gitFs, dir, fullname: false }).catch(() => {
|
|
627
624
|
return;
|
|
628
625
|
}),
|
|
629
|
-
|
|
626
|
+
syncRemoteFor(dir)
|
|
630
627
|
]);
|
|
631
|
-
const
|
|
632
|
-
const
|
|
633
|
-
for (const { remote } of remotes) {
|
|
634
|
-
const names = await git.listBranches({ fs: gitFs, dir: repoDir, remote }).catch(() => []);
|
|
635
|
-
for (const name of names) {
|
|
636
|
-
if (name === "HEAD")
|
|
637
|
-
continue;
|
|
638
|
-
if (!localNames.has(name))
|
|
639
|
-
remoteOnly.add(name);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
628
|
+
const tips = async (branches, prefix) => new Map(await Promise.all(branches.map(async (name) => [name, await git.resolveRef({ fs: gitFs, dir, ref: `${prefix}${name}` })])));
|
|
629
|
+
const onlineNames = remote ? (await git.listBranches({ fs: gitFs, dir, remote: remote.remote }).catch(() => [])).filter((name) => name !== "HEAD") : [];
|
|
642
630
|
return {
|
|
643
631
|
current: current ?? null,
|
|
644
|
-
|
|
645
|
-
|
|
632
|
+
local: await tips(names, "refs/heads/"),
|
|
633
|
+
online: await tips(onlineNames, `refs/remotes/${remote?.remote}/`)
|
|
646
634
|
};
|
|
647
635
|
}
|
|
648
|
-
|
|
636
|
+
var ANCESTRY_DEPTH = 1000;
|
|
637
|
+
async function isContained(dir, tip, inTip, cache) {
|
|
638
|
+
if (tip === inTip)
|
|
639
|
+
return true;
|
|
640
|
+
return git.isDescendent({ fs: gitFs, dir, cache, oid: inTip, ancestor: tip, depth: ANCESTRY_DEPTH }).catch(() => false);
|
|
641
|
+
}
|
|
642
|
+
async function listRevisions(dir) {
|
|
643
|
+
const source = await detectProjectSource(dir);
|
|
644
|
+
if (source.type !== "local-git-folder")
|
|
645
|
+
return null;
|
|
646
|
+
const repoDir = gitScopeFor(source);
|
|
647
|
+
const { current, local, online } = await readRevisionRefs(repoDir);
|
|
648
|
+
const cache = {};
|
|
649
|
+
const names = [...new Set([...local.keys(), ...online.keys()])].sort((a, b) => a.localeCompare(b));
|
|
650
|
+
const revisions = await Promise.all(names.map(async (name) => {
|
|
651
|
+
const here = local.get(name);
|
|
652
|
+
const there = online.get(name);
|
|
653
|
+
return {
|
|
654
|
+
name,
|
|
655
|
+
current: name === current,
|
|
656
|
+
where: here && there ? "online" : here ? "this-computer" : "online-only",
|
|
657
|
+
notBackedUp: Boolean(here && there && !await isContained(repoDir, here, there, cache))
|
|
658
|
+
};
|
|
659
|
+
}));
|
|
660
|
+
return { current, revisions };
|
|
661
|
+
}
|
|
662
|
+
function revisionNameFrom(input) {
|
|
663
|
+
return input.trim().replace(/\s+/g, "-");
|
|
664
|
+
}
|
|
665
|
+
var UNUSABLE_REVISION_NAME = /[\u0000- \u007f~^:?*[\\/<>"|]|\.\.|@\{|^[-.]|\.$|\.lock$|^@$/;
|
|
666
|
+
var REVISION_NAME_MAX = 100;
|
|
667
|
+
async function assertFreeRevisionName(repoDir, name) {
|
|
668
|
+
if (!name)
|
|
669
|
+
throw new Error("Give the revision a name.");
|
|
670
|
+
if (name.length > REVISION_NAME_MAX || UNUSABLE_REVISION_NAME.test(name)) {
|
|
671
|
+
throw new Error(`"${name}" can't be a revision name. Use plain words, numbers and dashes, up to ${REVISION_NAME_MAX} characters.`);
|
|
672
|
+
}
|
|
673
|
+
const { local, online } = await readRevisionRefs(repoDir);
|
|
674
|
+
const taken = (names) => [...names].find((n) => n.toLowerCase() === name.toLowerCase());
|
|
675
|
+
const here = taken(local.keys());
|
|
676
|
+
if (here)
|
|
677
|
+
throw new Error(`There's already a revision called "${here}". Pick a different name.`);
|
|
678
|
+
const there = taken(online.keys());
|
|
679
|
+
if (there) {
|
|
680
|
+
throw new Error(`"${there}" is already a revision in the online copy. Switch to it, or pick a different name.`);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
async function saveUnsavedWork(options, cache) {
|
|
684
|
+
try {
|
|
685
|
+
await snapshotWorkingTreeUnlocked({
|
|
686
|
+
projectDir: options.projectDir,
|
|
687
|
+
repoRoot: options.repoDir,
|
|
688
|
+
message: SWITCH_BRANCH_SNAPSHOT_MESSAGE,
|
|
689
|
+
authorName: options.authorName,
|
|
690
|
+
authorEmail: options.authorEmail,
|
|
691
|
+
cache
|
|
692
|
+
});
|
|
693
|
+
} catch (e) {
|
|
694
|
+
if (!isNoChangesError(e))
|
|
695
|
+
throw e;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
async function createRevision(options) {
|
|
699
|
+
const { projectDir, authorName, authorEmail } = options;
|
|
700
|
+
const source = await detectProjectSource(projectDir);
|
|
701
|
+
if (source.type !== "local-git-folder")
|
|
702
|
+
throw new Error(NO_VERSION_HISTORY);
|
|
703
|
+
const repoDir = gitScopeFor(source);
|
|
704
|
+
const name = revisionNameFrom(options.name);
|
|
705
|
+
return withRepoLock(repoDir, async () => {
|
|
706
|
+
await assertFreeRevisionName(repoDir, name);
|
|
707
|
+
await saveUnsavedWork({ projectDir, repoDir, authorName, authorEmail }, {});
|
|
708
|
+
await git.branch({ fs: gitFs, dir: repoDir, ref: name, checkout: true });
|
|
709
|
+
return { current: name };
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
async function resolveRevision(repoDir, branch) {
|
|
649
713
|
const local = await git.resolveRef({ fs: gitFs, dir: repoDir, ref: `refs/heads/${branch}` }).catch(() => {
|
|
650
714
|
return;
|
|
651
715
|
});
|
|
@@ -659,7 +723,7 @@ async function resolveCopy(repoDir, branch) {
|
|
|
659
723
|
if (oid)
|
|
660
724
|
return { oid, remote };
|
|
661
725
|
}
|
|
662
|
-
throw new Error(`Couldn't find a
|
|
726
|
+
throw new Error(`Couldn't find a revision named "${branch}" — it may have been renamed or deleted.`);
|
|
663
727
|
}
|
|
664
728
|
function isCheckoutConflictError(e) {
|
|
665
729
|
return e?.code === "CheckoutConflictError";
|
|
@@ -696,29 +760,16 @@ async function diffCommitPaths(dir, fromOid, toOid, cache) {
|
|
|
696
760
|
async function switchBranch(options) {
|
|
697
761
|
const { projectDir, branch, authorName, authorEmail } = options;
|
|
698
762
|
const source = await detectProjectSource(projectDir);
|
|
699
|
-
if (source.type !== "local-git-folder")
|
|
700
|
-
throw new Error(
|
|
701
|
-
}
|
|
763
|
+
if (source.type !== "local-git-folder")
|
|
764
|
+
throw new Error(NO_VERSION_HISTORY);
|
|
702
765
|
const repoDir = gitScopeFor(source);
|
|
703
766
|
return withRepoLock(repoDir, async () => {
|
|
704
767
|
const cache = {};
|
|
705
|
-
|
|
706
|
-
await snapshotWorkingTreeUnlocked({
|
|
707
|
-
projectDir,
|
|
708
|
-
repoRoot: repoDir,
|
|
709
|
-
message: SWITCH_BRANCH_SNAPSHOT_MESSAGE,
|
|
710
|
-
authorName,
|
|
711
|
-
authorEmail,
|
|
712
|
-
cache
|
|
713
|
-
});
|
|
714
|
-
} catch (e) {
|
|
715
|
-
if (!isNoChangesError(e))
|
|
716
|
-
throw e;
|
|
717
|
-
}
|
|
768
|
+
await saveUnsavedWork({ projectDir, repoDir, authorName, authorEmail }, cache);
|
|
718
769
|
const fromOid = await git.resolveRef({ fs: gitFs, dir: repoDir, ref: "HEAD" }).catch(() => {
|
|
719
770
|
return;
|
|
720
771
|
});
|
|
721
|
-
const { oid: toOid, remote } = await
|
|
772
|
+
const { oid: toOid, remote } = await resolveRevision(repoDir, branch);
|
|
722
773
|
try {
|
|
723
774
|
await git.checkout({
|
|
724
775
|
fs: gitFs,
|
|
@@ -730,7 +781,7 @@ async function switchBranch(options) {
|
|
|
730
781
|
});
|
|
731
782
|
} catch (e) {
|
|
732
783
|
if (isCheckoutConflictError(e)) {
|
|
733
|
-
throw new Error("Couldn't switch
|
|
784
|
+
throw new Error("Couldn't switch revisions — some files changed on disk right as the switch " + "started. Try again.", { cause: e });
|
|
734
785
|
}
|
|
735
786
|
throw e;
|
|
736
787
|
}
|
|
@@ -742,4 +793,4 @@ async function switchBranch(options) {
|
|
|
742
793
|
});
|
|
743
794
|
}
|
|
744
795
|
|
|
745
|
-
export { gitFs, errorLogData, resolveLogger, gitScopeFor, HISTORY_PAGE_LIMIT, withRepoLock, whenGitIdle, __repoLockQueueSizeForTests, resolveGitAuthor, listWorkdirChanges, stageChanges, hasPendingChanges, hasUncommittedChanges, snapshotWorkingTreeUnlocked, isNoChangesError, countUnversionedChanges, providerFor, gitDirFor, snapshotStagingMarkerPath, RESTORE_BACKUP_MESSAGE, AUTO_SNAPSHOT_MESSAGE, restoreVersionWithBackup, SWITCH_BRANCH_SNAPSHOT_MESSAGE,
|
|
796
|
+
export { gitFs, errorLogData, resolveLogger, gitScopeFor, HISTORY_PAGE_LIMIT, NO_VERSION_HISTORY, withRepoLock, whenGitIdle, __repoLockQueueSizeForTests, resolveGitAuthor, listWorkdirChanges, stageChanges, hasPendingChanges, hasUncommittedChanges, snapshotWorkingTreeUnlocked, isNoChangesError, countUnversionedChanges, providerFor, gitDirFor, snapshotStagingMarkerPath, RESTORE_BACKUP_MESSAGE, AUTO_SNAPSHOT_MESSAGE, restoreVersionWithBackup, SWITCH_BRANCH_SNAPSHOT_MESSAGE, readRevisionRefs, isContained, listRevisions, revisionNameFrom, assertFreeRevisionName, createRevision, switchBranch };
|