codiedev 0.9.5 → 0.9.6-beta.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/dist/backup/run.d.ts +2 -0
- package/dist/backup/run.js +42 -1
- package/package.json +1 -1
package/dist/backup/run.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export interface SelectDeps {
|
|
|
3
3
|
readFile: (rel: string) => string;
|
|
4
4
|
sha256: (content: string) => string;
|
|
5
5
|
}
|
|
6
|
+
export declare function unionPaths(a: string[], b: string[]): string[];
|
|
6
7
|
export declare function selectBackupFiles(input: {
|
|
7
8
|
repoKey: string;
|
|
8
9
|
statusPaths: string[];
|
|
@@ -14,6 +15,7 @@ export declare function selectBackupFiles(input: {
|
|
|
14
15
|
};
|
|
15
16
|
import { readConfig } from "../utils";
|
|
16
17
|
import { loadCache, saveCache } from "./cache";
|
|
18
|
+
export declare function gitCandidatePaths(root: string): string[];
|
|
17
19
|
export declare function runBackup(cwd: string, hookScriptPath: string): void;
|
|
18
20
|
export interface BackupUploadDeps {
|
|
19
21
|
readConfig: typeof readConfig;
|
package/dist/backup/run.js
CHANGED
|
@@ -33,11 +33,29 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.unionPaths = unionPaths;
|
|
36
37
|
exports.selectBackupFiles = selectBackupFiles;
|
|
38
|
+
exports.gitCandidatePaths = gitCandidatePaths;
|
|
37
39
|
exports.runBackup = runBackup;
|
|
38
40
|
exports.runBackupUpload = runBackupUpload;
|
|
39
41
|
const match_1 = require("./match");
|
|
40
42
|
const cache_1 = require("./cache");
|
|
43
|
+
// Pure: merge two path lists into one, deduped, preserving first-seen order.
|
|
44
|
+
function unionPaths(a, b) {
|
|
45
|
+
const seen = new Set();
|
|
46
|
+
const out = [];
|
|
47
|
+
for (const p of a)
|
|
48
|
+
if (!seen.has(p)) {
|
|
49
|
+
seen.add(p);
|
|
50
|
+
out.push(p);
|
|
51
|
+
}
|
|
52
|
+
for (const p of b)
|
|
53
|
+
if (!seen.has(p)) {
|
|
54
|
+
seen.add(p);
|
|
55
|
+
out.push(p);
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
41
59
|
// Pure: from this turn's git-status paths, keep artifact files whose content
|
|
42
60
|
// hash changed since the cache. Returns the changed candidates + next cache.
|
|
43
61
|
function selectBackupFiles(input) {
|
|
@@ -95,6 +113,27 @@ function gitStatusPaths(root) {
|
|
|
95
113
|
return [];
|
|
96
114
|
}
|
|
97
115
|
}
|
|
116
|
+
// All git-tracked files (committed, regardless of dirty state). `git ls-files`
|
|
117
|
+
// emits bare NUL-separated paths — no "XY " status prefix — so we don't slice.
|
|
118
|
+
function gitTrackedPaths(root) {
|
|
119
|
+
try {
|
|
120
|
+
const out = (0, child_process_1.execFileSync)("git", ["-C", root, "ls-files", "-z"], {
|
|
121
|
+
encoding: "utf8",
|
|
122
|
+
});
|
|
123
|
+
return out.split("\0").filter(Boolean);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// The hook's candidate set: dirty/untracked files ∪ all tracked files. Feeding
|
|
130
|
+
// tracked files in is what lets a COMMITTED artifact (clean status) still get
|
|
131
|
+
// backed up — the hash cache in selectBackupFiles dedups so already-backed-up
|
|
132
|
+
// files don't re-upload. selectBackupFiles rejects non-artifact paths cheaply
|
|
133
|
+
// (by regex, no content read), so the full tracked list is fine to pass.
|
|
134
|
+
function gitCandidatePaths(root) {
|
|
135
|
+
return unionPaths(gitStatusPaths(root), gitTrackedPaths(root));
|
|
136
|
+
}
|
|
98
137
|
const sha256 = (s) => crypto.createHash("sha256").update(s, "utf8").digest("hex");
|
|
99
138
|
// Stop/sessionEnd hook entry. Best-effort, never throws.
|
|
100
139
|
function runBackup(cwd, hookScriptPath) {
|
|
@@ -108,7 +147,9 @@ function runBackup(cwd, hookScriptPath) {
|
|
|
108
147
|
if (!root)
|
|
109
148
|
return;
|
|
110
149
|
const repoKey = (0, utils_1.getGitRemoteUrl)(root) ?? root;
|
|
111
|
-
|
|
150
|
+
// Dirty files ∪ tracked files — so committed-but-unbacked artifacts are
|
|
151
|
+
// caught too, not just unsaved drafts. Hash cache dedups the rest.
|
|
152
|
+
const statusPaths = gitCandidatePaths(root);
|
|
112
153
|
if (statusPaths.length === 0)
|
|
113
154
|
return;
|
|
114
155
|
const prevCache = (0, cache_2.loadCache)();
|
package/package.json
CHANGED