shell-dsl 0.0.32 → 0.0.34

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 (54) hide show
  1. package/README.md +130 -0
  2. package/dist/cjs/package.json +1 -1
  3. package/dist/cjs/src/index.cjs +3 -1
  4. package/dist/cjs/src/index.cjs.map +3 -3
  5. package/dist/cjs/src/vcs/diff.cjs +107 -0
  6. package/dist/cjs/src/vcs/diff.cjs.map +10 -0
  7. package/dist/cjs/src/vcs/index.cjs +47 -0
  8. package/dist/cjs/src/vcs/index.cjs.map +10 -0
  9. package/dist/cjs/src/vcs/match.cjs +106 -0
  10. package/dist/cjs/src/vcs/match.cjs.map +10 -0
  11. package/dist/cjs/src/vcs/rules.cjs +180 -0
  12. package/dist/cjs/src/vcs/rules.cjs.map +10 -0
  13. package/dist/cjs/src/vcs/snapshot.cjs +228 -0
  14. package/dist/cjs/src/vcs/snapshot.cjs.map +10 -0
  15. package/dist/cjs/src/vcs/storage.cjs +120 -0
  16. package/dist/cjs/src/vcs/storage.cjs.map +10 -0
  17. package/dist/cjs/src/vcs/types.cjs +30 -0
  18. package/dist/cjs/src/vcs/types.cjs.map +9 -0
  19. package/dist/cjs/src/vcs/vcs.cjs +322 -0
  20. package/dist/cjs/src/vcs/vcs.cjs.map +10 -0
  21. package/dist/cjs/src/vcs/walk.cjs +89 -0
  22. package/dist/cjs/src/vcs/walk.cjs.map +10 -0
  23. package/dist/mjs/package.json +1 -1
  24. package/dist/mjs/src/index.mjs +3 -1
  25. package/dist/mjs/src/index.mjs.map +3 -3
  26. package/dist/mjs/src/vcs/diff.mjs +67 -0
  27. package/dist/mjs/src/vcs/diff.mjs.map +10 -0
  28. package/dist/mjs/src/vcs/index.mjs +7 -0
  29. package/dist/mjs/src/vcs/index.mjs.map +10 -0
  30. package/dist/mjs/src/vcs/match.mjs +66 -0
  31. package/dist/mjs/src/vcs/match.mjs.map +10 -0
  32. package/dist/mjs/src/vcs/rules.mjs +140 -0
  33. package/dist/mjs/src/vcs/rules.mjs.map +10 -0
  34. package/dist/mjs/src/vcs/snapshot.mjs +188 -0
  35. package/dist/mjs/src/vcs/snapshot.mjs.map +10 -0
  36. package/dist/mjs/src/vcs/storage.mjs +79 -0
  37. package/dist/mjs/src/vcs/storage.mjs.map +10 -0
  38. package/dist/mjs/src/vcs/types.mjs +2 -0
  39. package/dist/mjs/src/vcs/types.mjs.map +9 -0
  40. package/dist/mjs/src/vcs/vcs.mjs +282 -0
  41. package/dist/mjs/src/vcs/vcs.mjs.map +10 -0
  42. package/dist/mjs/src/vcs/walk.mjs +49 -0
  43. package/dist/mjs/src/vcs/walk.mjs.map +10 -0
  44. package/dist/types/src/index.d.ts +2 -0
  45. package/dist/types/src/vcs/diff.d.ts +11 -0
  46. package/dist/types/src/vcs/index.d.ts +2 -0
  47. package/dist/types/src/vcs/match.d.ts +5 -0
  48. package/dist/types/src/vcs/rules.d.ts +23 -0
  49. package/dist/types/src/vcs/snapshot.d.ts +26 -0
  50. package/dist/types/src/vcs/storage.d.ts +22 -0
  51. package/dist/types/src/vcs/types.d.ts +99 -0
  52. package/dist/types/src/vcs/vcs.d.ts +35 -0
  53. package/dist/types/src/vcs/walk.d.ts +19 -0
  54. package/package.json +1 -1
@@ -0,0 +1,180 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ function __accessProp(key) {
6
+ return this[key];
7
+ }
8
+ var __toCommonJS = (from) => {
9
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
+ if (entry)
11
+ return entry;
12
+ entry = __defProp({}, "__esModule", { value: true });
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (var key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(entry, key))
16
+ __defProp(entry, key, {
17
+ get: __accessProp.bind(from, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ __moduleCache.set(from, entry);
22
+ return entry;
23
+ };
24
+ var __moduleCache;
25
+ var __returnValue = (v) => v;
26
+ function __exportSetter(name, newValue) {
27
+ this[name] = __returnValue.bind(null, newValue);
28
+ }
29
+ var __export = (target, all) => {
30
+ for (var name in all)
31
+ __defProp(target, name, {
32
+ get: all[name],
33
+ enumerable: true,
34
+ configurable: true,
35
+ set: __exportSetter.bind(all, name)
36
+ });
37
+ };
38
+
39
+ // src/vcs/rules.ts
40
+ var exports_rules = {};
41
+ __export(exports_rules, {
42
+ matchVCSPath: () => matchVCSPath,
43
+ VCSRules: () => VCSRules
44
+ });
45
+ module.exports = __toCommonJS(exports_rules);
46
+ var import_match = require("./match.cjs");
47
+
48
+ class VCSRules {
49
+ internalPath;
50
+ ignorePatterns;
51
+ attributeRules;
52
+ constructor(config = {}) {
53
+ this.internalPath = normalizePath(config.internalPath ?? config.internalDirName ?? "");
54
+ this.ignorePatterns = [...config.ignore ?? []];
55
+ this.attributeRules = [...config.attributes ?? []];
56
+ }
57
+ isInternalPath(relPath) {
58
+ if (!this.internalPath)
59
+ return false;
60
+ const normalizedPath = normalizePath(relPath);
61
+ if (!normalizedPath)
62
+ return false;
63
+ return normalizedPath === this.internalPath || normalizedPath.startsWith(`${this.internalPath}/`);
64
+ }
65
+ isIgnored(relPath) {
66
+ if (this.isInternalPath(relPath))
67
+ return true;
68
+ return this.ignorePatterns.some((pattern) => matchVCSPath(pattern, relPath));
69
+ }
70
+ shouldEnterDirectory(relPath, trackedPaths) {
71
+ if (this.isInternalPath(relPath))
72
+ return false;
73
+ if (!this.isIgnored(relPath))
74
+ return true;
75
+ return hasTrackedPathAtOrBelow(relPath, trackedPaths);
76
+ }
77
+ shouldIncludeWorkingFile(relPath, trackedPaths) {
78
+ if (this.isInternalPath(relPath))
79
+ return false;
80
+ if (trackedPaths.has(relPath))
81
+ return true;
82
+ return !this.isIgnored(relPath);
83
+ }
84
+ shouldIncludeEmptyDirectory(relPath, trackedPaths) {
85
+ if (this.isInternalPath(relPath))
86
+ return false;
87
+ if (trackedPaths.has(relPath))
88
+ return true;
89
+ return !this.isIgnored(relPath);
90
+ }
91
+ shouldIncludeRestoreScanFile(relPath) {
92
+ return !this.isInternalPath(relPath);
93
+ }
94
+ shouldPreserveUntrackedIgnored(relPath, trackedPaths) {
95
+ if (trackedPaths.has(relPath))
96
+ return false;
97
+ return this.isIgnored(relPath);
98
+ }
99
+ resolveAttributes(relPath) {
100
+ let binary = false;
101
+ let diff = "text";
102
+ for (const rule of this.attributeRules) {
103
+ if (!matchVCSPath(rule.pattern, relPath))
104
+ continue;
105
+ if (rule.binary !== undefined) {
106
+ binary = rule.binary;
107
+ }
108
+ if (rule.diff !== undefined) {
109
+ diff = rule.diff;
110
+ }
111
+ }
112
+ if (diff === "binary") {
113
+ binary = true;
114
+ }
115
+ return { binary, diff };
116
+ }
117
+ }
118
+ function matchVCSPath(pattern, relPath) {
119
+ const normalizedPattern = normalizePattern(pattern);
120
+ const normalizedPath = normalizePath(relPath);
121
+ if (!normalizedPattern || !normalizedPath)
122
+ return false;
123
+ if (normalizedPattern.mode === "root-path") {
124
+ return import_match.matchGlobPath(normalizedPattern.pattern, normalizedPath);
125
+ }
126
+ if (normalizedPattern.mode === "root-segment") {
127
+ const [firstSegment] = normalizedPath.split("/");
128
+ return firstSegment ? import_match.matchGlobPath(normalizedPattern.pattern, firstSegment) : false;
129
+ }
130
+ if (normalizedPattern.mode === "root-prefix") {
131
+ return import_match.matchGlobPath(normalizedPattern.pattern, normalizedPath) || import_match.matchGlobPath(`${normalizedPattern.pattern}/**`, normalizedPath);
132
+ }
133
+ const segments = normalizedPath.split("/");
134
+ return segments.some((segment) => import_match.matchGlobPath(normalizedPattern.pattern, segment));
135
+ }
136
+ function normalizePath(relPath) {
137
+ return relPath.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
138
+ }
139
+ function normalizePattern(pattern) {
140
+ let normalized = pattern.trim();
141
+ if (!normalized)
142
+ return null;
143
+ normalized = normalized.replace(/\\/g, "/");
144
+ const anchored = normalized.startsWith("/");
145
+ const directoryOnly = normalized.endsWith("/");
146
+ normalized = normalized.replace(/^\/+/, "").replace(/\/+$/, "");
147
+ if (!normalized)
148
+ return null;
149
+ if (normalized.includes("/")) {
150
+ return {
151
+ pattern: normalized,
152
+ mode: directoryOnly ? "root-prefix" : "root-path"
153
+ };
154
+ }
155
+ if (anchored) {
156
+ return {
157
+ pattern: normalized,
158
+ mode: "root-segment"
159
+ };
160
+ }
161
+ return {
162
+ pattern: normalized,
163
+ mode: "segment"
164
+ };
165
+ }
166
+ function hasTrackedPathAtOrBelow(relPath, trackedPaths) {
167
+ const normalizedPath = normalizePath(relPath);
168
+ if (!normalizedPath)
169
+ return false;
170
+ const prefix = normalizedPath + "/";
171
+ for (const trackedPath of trackedPaths) {
172
+ const normalizedTrackedPath = normalizePath(trackedPath);
173
+ if (normalizedTrackedPath === normalizedPath || normalizedTrackedPath.startsWith(prefix)) {
174
+ return true;
175
+ }
176
+ }
177
+ return false;
178
+ }
179
+
180
+ //# debugId=FD722B600498944364756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/vcs/rules.ts"],
4
+ "sourcesContent": [
5
+ "import { matchGlobPath } from \"./match.cjs\";\nimport type { VCSAttributeRule, VCSResolvedAttributes } from \"./types.cjs\";\n\ninterface VCSRulesConfig {\n internalPath?: string;\n internalDirName?: string;\n ignore?: string[];\n attributes?: VCSAttributeRule[];\n}\n\nexport class VCSRules {\n private readonly internalPath: string;\n private readonly ignorePatterns: string[];\n private readonly attributeRules: VCSAttributeRule[];\n\n constructor(config: VCSRulesConfig = {}) {\n this.internalPath = normalizePath(config.internalPath ?? config.internalDirName ?? \"\");\n this.ignorePatterns = [...(config.ignore ?? [])];\n this.attributeRules = [...(config.attributes ?? [])];\n }\n\n isInternalPath(relPath: string): boolean {\n if (!this.internalPath) return false;\n const normalizedPath = normalizePath(relPath);\n if (!normalizedPath) return false;\n return normalizedPath === this.internalPath || normalizedPath.startsWith(`${this.internalPath}/`);\n }\n\n isIgnored(relPath: string): boolean {\n if (this.isInternalPath(relPath)) return true;\n return this.ignorePatterns.some((pattern) => matchVCSPath(pattern, relPath));\n }\n\n shouldEnterDirectory(relPath: string, trackedPaths: Iterable<string>): boolean {\n if (this.isInternalPath(relPath)) return false;\n if (!this.isIgnored(relPath)) return true;\n return hasTrackedPathAtOrBelow(relPath, trackedPaths);\n }\n\n shouldIncludeWorkingFile(relPath: string, trackedPaths: ReadonlySet<string>): boolean {\n if (this.isInternalPath(relPath)) return false;\n if (trackedPaths.has(relPath)) return true;\n return !this.isIgnored(relPath);\n }\n\n shouldIncludeEmptyDirectory(relPath: string, trackedPaths: ReadonlySet<string>): boolean {\n if (this.isInternalPath(relPath)) return false;\n if (trackedPaths.has(relPath)) return true;\n return !this.isIgnored(relPath);\n }\n\n shouldIncludeRestoreScanFile(relPath: string): boolean {\n return !this.isInternalPath(relPath);\n }\n\n shouldPreserveUntrackedIgnored(relPath: string, trackedPaths: ReadonlySet<string>): boolean {\n if (trackedPaths.has(relPath)) return false;\n return this.isIgnored(relPath);\n }\n\n resolveAttributes(relPath: string): VCSResolvedAttributes {\n let binary = false;\n let diff: VCSResolvedAttributes[\"diff\"] = \"text\";\n\n for (const rule of this.attributeRules) {\n if (!matchVCSPath(rule.pattern, relPath)) continue;\n if (rule.binary !== undefined) {\n binary = rule.binary;\n }\n if (rule.diff !== undefined) {\n diff = rule.diff;\n }\n }\n\n if (diff === \"binary\") {\n binary = true;\n }\n\n return { binary, diff };\n }\n}\n\nexport function matchVCSPath(pattern: string, relPath: string): boolean {\n const normalizedPattern = normalizePattern(pattern);\n const normalizedPath = normalizePath(relPath);\n\n if (!normalizedPattern || !normalizedPath) return false;\n\n if (normalizedPattern.mode === \"root-path\") {\n return matchGlobPath(normalizedPattern.pattern, normalizedPath);\n }\n\n if (normalizedPattern.mode === \"root-segment\") {\n const [firstSegment] = normalizedPath.split(\"/\");\n return firstSegment ? matchGlobPath(normalizedPattern.pattern, firstSegment) : false;\n }\n\n if (normalizedPattern.mode === \"root-prefix\") {\n return (\n matchGlobPath(normalizedPattern.pattern, normalizedPath) ||\n matchGlobPath(`${normalizedPattern.pattern}/**`, normalizedPath)\n );\n }\n\n const segments = normalizedPath.split(\"/\");\n return segments.some((segment) => matchGlobPath(normalizedPattern.pattern, segment));\n}\n\nfunction normalizePath(relPath: string): string {\n return relPath.replace(/\\\\/g, \"/\").replace(/^\\/+/, \"\").replace(/\\/+$/, \"\");\n}\n\nfunction normalizePattern(pattern: string): {\n pattern: string;\n mode: \"root-path\" | \"root-prefix\" | \"root-segment\" | \"segment\";\n} | null {\n let normalized = pattern.trim();\n if (!normalized) return null;\n\n normalized = normalized.replace(/\\\\/g, \"/\");\n const anchored = normalized.startsWith(\"/\");\n const directoryOnly = normalized.endsWith(\"/\");\n normalized = normalized.replace(/^\\/+/, \"\").replace(/\\/+$/, \"\");\n if (!normalized) return null;\n\n if (normalized.includes(\"/\")) {\n return {\n pattern: normalized,\n mode: directoryOnly ? \"root-prefix\" : \"root-path\",\n };\n }\n\n if (anchored) {\n return {\n pattern: normalized,\n mode: \"root-segment\",\n };\n }\n\n return {\n pattern: normalized,\n mode: \"segment\",\n };\n}\n\nfunction hasTrackedPathAtOrBelow(relPath: string, trackedPaths: Iterable<string>): boolean {\n const normalizedPath = normalizePath(relPath);\n if (!normalizedPath) return false;\n\n const prefix = normalizedPath + \"/\";\n for (const trackedPath of trackedPaths) {\n const normalizedTrackedPath = normalizePath(trackedPath);\n if (\n normalizedTrackedPath === normalizedPath ||\n normalizedTrackedPath.startsWith(prefix)\n ) {\n return true;\n }\n }\n return false;\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA8B,IAA9B;AAAA;AAUO,MAAM,SAAS;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B,kBAC1B,sBAAsB,WAAW,MAAM,GACvC;AAAA,MACA,OAAO;AAAA,IACT;AAAA,EACF;AAAA,EACA,OAAO;AAAA;",
8
+ "debugId": "FD722B600498944364756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,228 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ function __accessProp(key) {
6
+ return this[key];
7
+ }
8
+ var __toCommonJS = (from) => {
9
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
+ if (entry)
11
+ return entry;
12
+ entry = __defProp({}, "__esModule", { value: true });
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (var key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(entry, key))
16
+ __defProp(entry, key, {
17
+ get: __accessProp.bind(from, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ __moduleCache.set(from, entry);
22
+ return entry;
23
+ };
24
+ var __moduleCache;
25
+ var __returnValue = (v) => v;
26
+ function __exportSetter(name, newValue) {
27
+ this[name] = __returnValue.bind(null, newValue);
28
+ }
29
+ var __export = (target, all) => {
30
+ for (var name in all)
31
+ __defProp(target, name, {
32
+ get: all[name],
33
+ enumerable: true,
34
+ configurable: true,
35
+ set: __exportSetter.bind(all, name)
36
+ });
37
+ };
38
+
39
+ // src/vcs/snapshot.ts
40
+ var exports_snapshot = {};
41
+ __export(exports_snapshot, {
42
+ restoreTree: () => restoreTree,
43
+ buildTreeManifest: () => buildTreeManifest,
44
+ buildPartialManifest: () => buildPartialManifest
45
+ });
46
+ module.exports = __toCommonJS(exports_snapshot);
47
+ var import_rules = require("./rules.cjs");
48
+ var import_walk = require("./walk.cjs");
49
+ async function buildTreeManifest(fs, rootPath, options) {
50
+ const manifest = {};
51
+ const rules = options?.rules ?? new import_rules.VCSRules({ internalDirName: ".vcs" });
52
+ const trackedPaths = new Set(options?.trackedPaths ?? []);
53
+ const entries = await import_walk.walkTreeEntries(fs, rootPath, {
54
+ enterDirectory: (relPath) => rules.shouldEnterDirectory(relPath, trackedPaths),
55
+ includeFile: (relPath) => rules.shouldIncludeWorkingFile(relPath, trackedPaths),
56
+ includeDirectory: (relPath, info) => info.empty && rules.shouldIncludeEmptyDirectory(relPath, trackedPaths)
57
+ });
58
+ for (const entry of entries) {
59
+ if (entry.kind === "directory") {
60
+ manifest[entry.path] = { kind: "directory", size: 0 };
61
+ continue;
62
+ }
63
+ const fullPath = fs.resolve(rootPath, entry.path);
64
+ const content = await fs.readFile(fullPath);
65
+ const buf = Buffer.from(content);
66
+ manifest[entry.path] = {
67
+ kind: "file",
68
+ content: buf.toString("base64"),
69
+ size: buf.length
70
+ };
71
+ }
72
+ return manifest;
73
+ }
74
+ async function buildPartialManifest(fs, rootPath, paths) {
75
+ const manifest = {};
76
+ for (const relPath of paths) {
77
+ const fullPath = fs.resolve(rootPath, relPath);
78
+ if (!await fs.exists(fullPath))
79
+ continue;
80
+ const stat = await fs.stat(fullPath);
81
+ if (stat.isDirectory()) {
82
+ const entries = await fs.readdir(fullPath);
83
+ if (entries.length === 0) {
84
+ manifest[relPath] = { kind: "directory", size: 0 };
85
+ }
86
+ continue;
87
+ }
88
+ if (!stat.isFile())
89
+ continue;
90
+ const content = await fs.readFile(fullPath);
91
+ const buf = Buffer.from(content);
92
+ manifest[relPath] = {
93
+ kind: "file",
94
+ content: buf.toString("base64"),
95
+ size: buf.length
96
+ };
97
+ }
98
+ return manifest;
99
+ }
100
+ async function restoreTree(fs, rootPath, manifest, options) {
101
+ const fullRestore = options?.fullRestore ?? false;
102
+ const rules = options?.rules ?? new import_rules.VCSRules({ internalDirName: ".vcs" });
103
+ const trackedPaths = new Set(options?.trackedPaths ?? []);
104
+ const scopePatterns = options?.paths ?? null;
105
+ const scopedEntries = Object.entries(manifest).filter(([relPath]) => isPathInScope(relPath, scopePatterns)).sort(([a], [b]) => a.localeCompare(b));
106
+ const targetPaths = new Set(scopedEntries.map(([relPath]) => relPath));
107
+ const requiredDirectories = collectRequiredDirectories(scopedEntries);
108
+ const shouldDeleteExtras = fullRestore || scopePatterns !== null;
109
+ if (shouldDeleteExtras) {
110
+ const currentEntries = await import_walk.walkTreeEntries(fs, rootPath, {
111
+ enterDirectory: (relPath) => !rules.isInternalPath(relPath),
112
+ includeFile: (relPath) => rules.shouldIncludeRestoreScanFile(relPath),
113
+ includeDirectory: () => true
114
+ });
115
+ for (const current of currentEntries) {
116
+ if (current.kind !== "file")
117
+ continue;
118
+ if (!isPathInScope(current.path, scopePatterns))
119
+ continue;
120
+ if (targetPaths.has(current.path))
121
+ continue;
122
+ if (rules.shouldPreserveUntrackedIgnored(current.path, trackedPaths))
123
+ continue;
124
+ await fs.rm(fs.resolve(rootPath, current.path));
125
+ }
126
+ }
127
+ for (const directory of [...requiredDirectories].sort(comparePathDepth)) {
128
+ await ensureDirectoryExists(fs, fs.resolve(rootPath, directory));
129
+ }
130
+ for (const [relPath, entry] of scopedEntries) {
131
+ if (isDirectoryEntry(entry)) {
132
+ await ensureDirectoryExists(fs, fs.resolve(rootPath, relPath));
133
+ continue;
134
+ }
135
+ await writeFileFromEntry(fs, rootPath, relPath, entry);
136
+ }
137
+ if (shouldDeleteExtras) {
138
+ const currentEntries = await import_walk.walkTreeEntries(fs, rootPath, {
139
+ enterDirectory: (relPath) => !rules.isInternalPath(relPath),
140
+ includeFile: () => true,
141
+ includeDirectory: () => true
142
+ });
143
+ const directories = currentEntries.filter((entry) => entry.kind === "directory").map((entry) => entry.path).filter((relPath) => isPathInScope(relPath, scopePatterns)).sort((a, b) => comparePathDepth(b, a));
144
+ for (const relPath of directories) {
145
+ if (requiredDirectories.has(relPath))
146
+ continue;
147
+ if (rules.shouldPreserveUntrackedIgnored(relPath, trackedPaths))
148
+ continue;
149
+ const fullPath = fs.resolve(rootPath, relPath);
150
+ if (await isEmptyDirectory(fs, fullPath)) {
151
+ await fs.rm(fullPath);
152
+ }
153
+ }
154
+ }
155
+ }
156
+ async function writeFileFromEntry(fs, rootPath, relPath, entry) {
157
+ const fullPath = fs.resolve(rootPath, relPath);
158
+ await ensureDirectoryExists(fs, fs.dirname(fullPath));
159
+ await removeDirectoryAtPath(fs, fullPath);
160
+ const buf = Buffer.from(entry.content, "base64");
161
+ await fs.writeFile(fullPath, buf);
162
+ }
163
+ function isDirectoryEntry(entry) {
164
+ return entry.kind === "directory";
165
+ }
166
+ function isPathInScope(relPath, patterns) {
167
+ if (!patterns || patterns.length === 0)
168
+ return true;
169
+ return patterns.some((pattern) => import_rules.matchVCSPath(pattern, relPath));
170
+ }
171
+ function collectRequiredDirectories(entries) {
172
+ const directories = new Set;
173
+ for (const [relPath, entry] of entries) {
174
+ if (isDirectoryEntry(entry)) {
175
+ directories.add(relPath);
176
+ }
177
+ for (const parent of parentDirectories(relPath)) {
178
+ directories.add(parent);
179
+ }
180
+ }
181
+ return directories;
182
+ }
183
+ function parentDirectories(relPath) {
184
+ const parts = relPath.split("/").filter(Boolean);
185
+ const parents = [];
186
+ for (let i = 1;i < parts.length; i++) {
187
+ parents.push(parts.slice(0, i).join("/"));
188
+ }
189
+ return parents;
190
+ }
191
+ function comparePathDepth(a, b) {
192
+ const depthA = a.split("/").filter(Boolean).length;
193
+ const depthB = b.split("/").filter(Boolean).length;
194
+ if (depthA !== depthB)
195
+ return depthA - depthB;
196
+ return a.localeCompare(b);
197
+ }
198
+ async function ensureDirectoryExists(fs, dirPath) {
199
+ const parent = fs.dirname(dirPath);
200
+ if (parent !== dirPath) {
201
+ await ensureDirectoryExists(fs, parent);
202
+ }
203
+ if (await fs.exists(dirPath)) {
204
+ const stat = await fs.stat(dirPath);
205
+ if (stat.isDirectory())
206
+ return;
207
+ await fs.rm(dirPath, { recursive: true, force: true });
208
+ }
209
+ await fs.mkdir(dirPath, { recursive: true });
210
+ }
211
+ async function removeDirectoryAtPath(fs, path) {
212
+ if (!await fs.exists(path))
213
+ return;
214
+ const stat = await fs.stat(path);
215
+ if (stat.isDirectory()) {
216
+ await fs.rm(path, { recursive: true, force: true });
217
+ }
218
+ }
219
+ async function isEmptyDirectory(fs, dirPath) {
220
+ try {
221
+ const entries = await fs.readdir(dirPath);
222
+ return entries.length === 0;
223
+ } catch {
224
+ return false;
225
+ }
226
+ }
227
+
228
+ //# debugId=7E15F1F035E56CC164756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/vcs/snapshot.ts"],
4
+ "sourcesContent": [
5
+ "import type { VirtualFS } from \"../types.cjs\";\nimport type { TreeManifest, FileEntry, TreeEntry } from \"./types.cjs\";\nimport { matchVCSPath, VCSRules } from \"./rules.cjs\";\nimport { walkTreeEntries } from \"./walk.cjs\";\n\n/**\n * Build a TreeManifest from the current working tree.\n */\nexport async function buildTreeManifest(\n fs: VirtualFS,\n rootPath: string,\n options?: {\n rules?: VCSRules;\n trackedPaths?: Iterable<string>;\n },\n): Promise<TreeManifest> {\n const manifest: TreeManifest = {};\n const rules = options?.rules ?? new VCSRules({ internalDirName: \".vcs\" });\n const trackedPaths = new Set(options?.trackedPaths ?? []);\n const entries = await walkTreeEntries(fs, rootPath, {\n enterDirectory: (relPath) => rules.shouldEnterDirectory(relPath, trackedPaths),\n includeFile: (relPath) => rules.shouldIncludeWorkingFile(relPath, trackedPaths),\n includeDirectory: (relPath, info) =>\n info.empty && rules.shouldIncludeEmptyDirectory(relPath, trackedPaths),\n });\n\n for (const entry of entries) {\n if (entry.kind === \"directory\") {\n manifest[entry.path] = { kind: \"directory\", size: 0 };\n continue;\n }\n\n const fullPath = fs.resolve(rootPath, entry.path);\n const content = await fs.readFile(fullPath);\n const buf = Buffer.from(content);\n manifest[entry.path] = {\n kind: \"file\",\n content: buf.toString(\"base64\"),\n size: buf.length,\n };\n }\n\n return manifest;\n}\n\n/**\n * Build a TreeManifest for only the specified relative paths.\n */\nexport async function buildPartialManifest(\n fs: VirtualFS,\n rootPath: string,\n paths: string[],\n): Promise<TreeManifest> {\n const manifest: TreeManifest = {};\n\n for (const relPath of paths) {\n const fullPath = fs.resolve(rootPath, relPath);\n if (!(await fs.exists(fullPath))) continue;\n const stat = await fs.stat(fullPath);\n if (stat.isDirectory()) {\n const entries = await fs.readdir(fullPath);\n if (entries.length === 0) {\n manifest[relPath] = { kind: \"directory\", size: 0 };\n }\n continue;\n }\n if (!stat.isFile()) continue;\n\n const content = await fs.readFile(fullPath);\n const buf = Buffer.from(content);\n manifest[relPath] = {\n kind: \"file\",\n content: buf.toString(\"base64\"),\n size: buf.length,\n };\n }\n\n return manifest;\n}\n\n/**\n * Restore a working tree from a TreeManifest.\n *\n * If `fullRestore` is true, deletes working tree files not in the manifest.\n * If `paths` is provided, only restores matching files.\n */\nexport async function restoreTree(\n fs: VirtualFS,\n rootPath: string,\n manifest: TreeManifest,\n options?: {\n fullRestore?: boolean;\n paths?: string[];\n rules?: VCSRules;\n trackedPaths?: Iterable<string>;\n },\n): Promise<void> {\n const fullRestore = options?.fullRestore ?? false;\n const rules = options?.rules ?? new VCSRules({ internalDirName: \".vcs\" });\n const trackedPaths = new Set(options?.trackedPaths ?? []);\n const scopePatterns = options?.paths ?? null;\n const scopedEntries = Object.entries(manifest)\n .filter(([relPath]) => isPathInScope(relPath, scopePatterns))\n .sort(([a], [b]) => a.localeCompare(b));\n const targetPaths = new Set(scopedEntries.map(([relPath]) => relPath));\n const requiredDirectories = collectRequiredDirectories(scopedEntries);\n const shouldDeleteExtras = fullRestore || scopePatterns !== null;\n\n if (shouldDeleteExtras) {\n const currentEntries = await walkTreeEntries(fs, rootPath, {\n enterDirectory: (relPath) => !rules.isInternalPath(relPath),\n includeFile: (relPath) => rules.shouldIncludeRestoreScanFile(relPath),\n includeDirectory: () => true,\n });\n\n for (const current of currentEntries) {\n if (current.kind !== \"file\") continue;\n if (!isPathInScope(current.path, scopePatterns)) continue;\n if (targetPaths.has(current.path)) continue;\n if (rules.shouldPreserveUntrackedIgnored(current.path, trackedPaths)) continue;\n await fs.rm(fs.resolve(rootPath, current.path));\n }\n }\n\n for (const directory of [...requiredDirectories].sort(comparePathDepth)) {\n await ensureDirectoryExists(fs, fs.resolve(rootPath, directory));\n }\n\n for (const [relPath, entry] of scopedEntries) {\n if (isDirectoryEntry(entry)) {\n await ensureDirectoryExists(fs, fs.resolve(rootPath, relPath));\n continue;\n }\n await writeFileFromEntry(fs, rootPath, relPath, entry);\n }\n\n if (shouldDeleteExtras) {\n const currentEntries = await walkTreeEntries(fs, rootPath, {\n enterDirectory: (relPath) => !rules.isInternalPath(relPath),\n includeFile: () => true,\n includeDirectory: () => true,\n });\n\n const directories = currentEntries\n .filter((entry) => entry.kind === \"directory\")\n .map((entry) => entry.path)\n .filter((relPath) => isPathInScope(relPath, scopePatterns))\n .sort((a, b) => comparePathDepth(b, a));\n\n for (const relPath of directories) {\n if (requiredDirectories.has(relPath)) continue;\n if (rules.shouldPreserveUntrackedIgnored(relPath, trackedPaths)) continue;\n const fullPath = fs.resolve(rootPath, relPath);\n if (await isEmptyDirectory(fs, fullPath)) {\n await fs.rm(fullPath);\n }\n }\n }\n}\n\nasync function writeFileFromEntry(\n fs: VirtualFS,\n rootPath: string,\n relPath: string,\n entry: FileEntry,\n): Promise<void> {\n const fullPath = fs.resolve(rootPath, relPath);\n await ensureDirectoryExists(fs, fs.dirname(fullPath));\n await removeDirectoryAtPath(fs, fullPath);\n\n const buf = Buffer.from(entry.content, \"base64\");\n await fs.writeFile(fullPath, buf);\n}\n\nfunction isDirectoryEntry(entry: TreeEntry): entry is Extract<TreeEntry, { kind: \"directory\" }> {\n return entry.kind === \"directory\";\n}\n\nfunction isPathInScope(relPath: string, patterns: string[] | null): boolean {\n if (!patterns || patterns.length === 0) return true;\n return patterns.some((pattern) => matchVCSPath(pattern, relPath));\n}\n\nfunction collectRequiredDirectories(entries: Array<[string, TreeEntry]>): Set<string> {\n const directories = new Set<string>();\n\n for (const [relPath, entry] of entries) {\n if (isDirectoryEntry(entry)) {\n directories.add(relPath);\n }\n for (const parent of parentDirectories(relPath)) {\n directories.add(parent);\n }\n }\n\n return directories;\n}\n\nfunction parentDirectories(relPath: string): string[] {\n const parts = relPath.split(\"/\").filter(Boolean);\n const parents: string[] = [];\n\n for (let i = 1; i < parts.length; i++) {\n parents.push(parts.slice(0, i).join(\"/\"));\n }\n\n return parents;\n}\n\nfunction comparePathDepth(a: string, b: string): number {\n const depthA = a.split(\"/\").filter(Boolean).length;\n const depthB = b.split(\"/\").filter(Boolean).length;\n if (depthA !== depthB) return depthA - depthB;\n return a.localeCompare(b);\n}\n\nasync function ensureDirectoryExists(fs: VirtualFS, dirPath: string): Promise<void> {\n const parent = fs.dirname(dirPath);\n if (parent !== dirPath) {\n await ensureDirectoryExists(fs, parent);\n }\n\n if (await fs.exists(dirPath)) {\n const stat = await fs.stat(dirPath);\n if (stat.isDirectory()) return;\n await fs.rm(dirPath, { recursive: true, force: true });\n }\n\n await fs.mkdir(dirPath, { recursive: true });\n}\n\nasync function removeDirectoryAtPath(fs: VirtualFS, path: string): Promise<void> {\n if (!(await fs.exists(path))) return;\n const stat = await fs.stat(path);\n if (stat.isDirectory()) {\n await fs.rm(path, { recursive: true, force: true });\n }\n}\n\nasync function isEmptyDirectory(fs: VirtualFS, dirPath: string): Promise<boolean> {\n try {\n const entries = await fs.readdir(dirPath);\n return entries.length === 0;\n } catch {\n return false;\n }\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEuC,IAAvC;AACgC,IAAhC;AAKA,eAAsB,iBAAiB,CACrC,IACA,UACA,SAIuB;AAAA,EACvB,MAAM,WAAyB,CAAC;AAAA,EAChC,MAAM,QAAQ,SAAS,SAAS,IAAI,sBAAS,EAAE,iBAAiB,OAAO,CAAC;AAAA,EACxE,MAAM,eAAe,IAAI,IAAI,SAAS,gBAAgB,CAAC,CAAC;AAA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__defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ function __accessProp(key) {
6
+ return this[key];
7
+ }
8
+ var __toCommonJS = (from) => {
9
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
+ if (entry)
11
+ return entry;
12
+ entry = __defProp({}, "__esModule", { value: true });
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (var key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(entry, key))
16
+ __defProp(entry, key, {
17
+ get: __accessProp.bind(from, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ __moduleCache.set(from, entry);
22
+ return entry;
23
+ };
24
+ var __moduleCache;
25
+ var __returnValue = (v) => v;
26
+ function __exportSetter(name, newValue) {
27
+ this[name] = __returnValue.bind(null, newValue);
28
+ }
29
+ var __export = (target, all) => {
30
+ for (var name in all)
31
+ __defProp(target, name, {
32
+ get: all[name],
33
+ enumerable: true,
34
+ configurable: true,
35
+ set: __exportSetter.bind(all, name)
36
+ });
37
+ };
38
+
39
+ // src/vcs/storage.ts
40
+ var exports_storage = {};
41
+ __export(exports_storage, {
42
+ VCSStorage: () => VCSStorage
43
+ });
44
+ module.exports = __toCommonJS(exports_storage);
45
+
46
+ class VCSStorage {
47
+ fs;
48
+ basePath;
49
+ constructor(fs, basePath) {
50
+ this.fs = fs;
51
+ this.basePath = basePath;
52
+ }
53
+ path(...segments) {
54
+ return this.fs.resolve(this.basePath, ...segments);
55
+ }
56
+ async isInitialized() {
57
+ return this.fs.exists(this.path("HEAD"));
58
+ }
59
+ async initialize(defaultBranch = "main") {
60
+ await this.fs.mkdir(this.basePath, { recursive: true });
61
+ await this.fs.mkdir(this.path("refs", "heads"), { recursive: true });
62
+ await this.fs.mkdir(this.path("revisions"), { recursive: true });
63
+ await this.writeHead({ ref: `refs/heads/${defaultBranch}` });
64
+ await this.writeJSON(["counter.json"], { next: 1 });
65
+ await this.writeJSON(["config.json"], { defaultBranch });
66
+ }
67
+ async readHead() {
68
+ return this.readJSON("HEAD");
69
+ }
70
+ async writeHead(head) {
71
+ await this.writeJSON(["HEAD"], head);
72
+ }
73
+ async readBranch(name) {
74
+ const branchPath = this.path("refs", "heads", name);
75
+ if (!await this.fs.exists(branchPath))
76
+ return null;
77
+ return this.readJSON("refs", "heads", name);
78
+ }
79
+ async writeBranch(name, ref) {
80
+ await this.writeJSON(["refs", "heads", name], ref);
81
+ }
82
+ async deleteBranch(name) {
83
+ const branchPath = this.path("refs", "heads", name);
84
+ await this.fs.rm(branchPath);
85
+ }
86
+ async listBranches() {
87
+ const headsPath = this.path("refs", "heads");
88
+ try {
89
+ return await this.fs.readdir(headsPath);
90
+ } catch {
91
+ return [];
92
+ }
93
+ }
94
+ async readRevision(id) {
95
+ return this.readJSON("revisions", `${id}.json`);
96
+ }
97
+ async writeRevision(rev) {
98
+ await this.writeJSON(["revisions", `${rev.id}.json`], rev);
99
+ }
100
+ async nextRevisionId() {
101
+ const counter = await this.readJSON("counter.json");
102
+ const id = counter.next;
103
+ await this.writeJSON(["counter.json"], { next: id + 1 });
104
+ return id;
105
+ }
106
+ async readConfig() {
107
+ return this.readJSON("config.json");
108
+ }
109
+ async readJSON(...segments) {
110
+ const filePath = this.path(...segments);
111
+ const content = await this.fs.readFile(filePath, "utf8");
112
+ return JSON.parse(content);
113
+ }
114
+ async writeJSON(segments, data) {
115
+ const filePath = this.path(...segments);
116
+ await this.fs.writeFile(filePath, JSON.stringify(data, null, 2));
117
+ }
118
+ }
119
+
120
+ //# debugId=E27DBCC23E16A74564756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/vcs/storage.ts"],
4
+ "sourcesContent": [
5
+ "import type { VirtualFS } from \"../types.cjs\";\nimport type {\n HeadRef,\n BranchRef,\n RevisionCounter,\n VCSConfigFile,\n Revision,\n} from \"./types.cjs\";\n\nexport class VCSStorage {\n constructor(\n private readonly fs: VirtualFS,\n private readonly basePath: string,\n ) {}\n\n private path(...segments: string[]): string {\n return this.fs.resolve(this.basePath, ...segments);\n }\n\n // --- Init ---\n\n async isInitialized(): Promise<boolean> {\n return this.fs.exists(this.path(\"HEAD\"));\n }\n\n async initialize(defaultBranch: string = \"main\"): Promise<void> {\n await this.fs.mkdir(this.basePath, { recursive: true });\n await this.fs.mkdir(this.path(\"refs\", \"heads\"), { recursive: true });\n await this.fs.mkdir(this.path(\"revisions\"), { recursive: true });\n\n await this.writeHead({ ref: `refs/heads/${defaultBranch}` });\n await this.writeJSON([\"counter.json\"], { next: 1 } satisfies RevisionCounter);\n await this.writeJSON([\"config.json\"], { defaultBranch } satisfies VCSConfigFile);\n }\n\n // --- HEAD ---\n\n async readHead(): Promise<HeadRef> {\n return this.readJSON<HeadRef>(\"HEAD\");\n }\n\n async writeHead(head: HeadRef): Promise<void> {\n await this.writeJSON([\"HEAD\"], head);\n }\n\n // --- Branches ---\n\n async readBranch(name: string): Promise<BranchRef | null> {\n const branchPath = this.path(\"refs\", \"heads\", name);\n if (!(await this.fs.exists(branchPath))) return null;\n return this.readJSON<BranchRef>(\"refs\", \"heads\", name);\n }\n\n async writeBranch(name: string, ref: BranchRef): Promise<void> {\n await this.writeJSON([\"refs\", \"heads\", name], ref);\n }\n\n async deleteBranch(name: string): Promise<void> {\n const branchPath = this.path(\"refs\", \"heads\", name);\n await this.fs.rm(branchPath);\n }\n\n async listBranches(): Promise<string[]> {\n const headsPath = this.path(\"refs\", \"heads\");\n try {\n return await this.fs.readdir(headsPath);\n } catch {\n return [];\n }\n }\n\n // --- Revisions ---\n\n async readRevision(id: number): Promise<Revision> {\n return this.readJSON<Revision>(\"revisions\", `${id}.json`);\n }\n\n async writeRevision(rev: Revision): Promise<void> {\n await this.writeJSON([\"revisions\", `${rev.id}.json`], rev);\n }\n\n // --- Counter ---\n\n async nextRevisionId(): Promise<number> {\n const counter = await this.readJSON<RevisionCounter>(\"counter.json\");\n const id = counter.next;\n await this.writeJSON([\"counter.json\"], { next: id + 1 } satisfies RevisionCounter);\n return id;\n }\n\n // --- Config ---\n\n async readConfig(): Promise<VCSConfigFile> {\n return this.readJSON<VCSConfigFile>(\"config.json\");\n }\n\n // --- Helpers ---\n\n private async readJSON<T>(...segments: string[]): Promise<T> {\n const filePath = this.path(...segments);\n const content = await this.fs.readFile(filePath, \"utf8\");\n return JSON.parse(content) as T;\n }\n\n private async writeJSON(segments: string[], data: unknown): Promise<void> {\n const filePath = this.path(...segments);\n await this.fs.writeFile(filePath, JSON.stringify(data, null, 2));\n }\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASO,MAAM,WAAW;AAAA,EAEH;AAAA,EACA;AAAA,EAFnB,WAAW,CACQ,IACA,UACjB;AAAA,IAFiB;AAAA,IACA;AAAA;AAAA,EAGX,IAAI,IAAI,UAA4B;AAAA,IAC1C,OAAO,KAAK,GAAG,QAAQ,KAAK,UAAU,GAAG,QAAQ;AAAA;AAAA,OAK7C,cAAa,GAAqB;AAAA,IACtC,OAAO,KAAK,GAAG,OAAO,KAAK,KAAK,MAAM,CAAC;AAAA;AAAA,OAGnC,WAAU,CAAC,gBAAwB,QAAuB;AAAA,IAC9D,MAAM,KAAK,GAAG,MAAM,KAAK,UAAU,EAAE,WAAW,KAAK,CAAC;AAAA,IACtD,MAAM,KAAK,GAAG,MAAM,KAAK,KAAK,QAAQ,OAAO,GAAG,EAAE,WAAW,KAAK,CAAC;AAAA,IACnE,MAAM,KAAK,GAAG,MAAM,KAAK,KAAK,WAAW,GAAG,EAAE,WAAW,KAAK,CAAC;AAAA,IAE/D,MAAM,KAAK,UAAU,EAAE,KAAK,cAAc,gBAAgB,CAAC;AAAA,IAC3D,MAAM,KAAK,UAAU,CAAC,cAAc,GAAG,EAAE,MAAM,EAAE,C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AAK,UAAU,CAAC,cAAc,GAAG,EAAE,MAAM,KAAK,EAAE,CAA2B;AAAA,IACjF,OAAO;AAAA;AAAA,OAKH,WAAU,GAA2B;AAAA,IACzC,OAAO,KAAK,SAAwB,aAAa;AAAA;AAAA,OAKrC,SAAW,IAAI,UAAgC;AAAA,IAC3D,MAAM,WAAW,KAAK,KAAK,GAAG,QAAQ;AAAA,IACtC,MAAM,UAAU,MAAM,KAAK,GAAG,SAAS,UAAU,MAAM;AAAA,IACvD,OAAO,KAAK,MAAM,OAAO;AAAA;AAAA,OAGb,UAAS,CAAC,UAAoB,MAA8B;AAAA,IACxE,MAAM,WAAW,KAAK,KAAK,GAAG,QAAQ;AAAA,IACtC,MAAM,KAAK,GAAG,UAAU,UAAU,KAAK,UAAU,MAAM,MAAM,CAAC,CAAC;AAAA;AAEnE;",
8
+ "debugId": "E27DBCC23E16A74564756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ function __accessProp(key) {
6
+ return this[key];
7
+ }
8
+ var __toCommonJS = (from) => {
9
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
+ if (entry)
11
+ return entry;
12
+ entry = __defProp({}, "__esModule", { value: true });
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (var key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(entry, key))
16
+ __defProp(entry, key, {
17
+ get: __accessProp.bind(from, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ __moduleCache.set(from, entry);
22
+ return entry;
23
+ };
24
+ var __moduleCache;
25
+
26
+ // src/vcs/types.ts
27
+ var exports_types = {};
28
+ module.exports = __toCommonJS(exports_types);
29
+
30
+ //# debugId=0D69226887DD202F64756E2164756E21
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "0D69226887DD202F64756E2164756E21",
8
+ "names": []
9
+ }