shell-dsl 0.0.32 → 0.0.33
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 +109 -0
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/index.cjs +3 -1
- package/dist/cjs/src/index.cjs.map +3 -3
- package/dist/cjs/src/vcs/diff.cjs +102 -0
- package/dist/cjs/src/vcs/diff.cjs.map +10 -0
- package/dist/cjs/src/vcs/index.cjs +47 -0
- package/dist/cjs/src/vcs/index.cjs.map +10 -0
- package/dist/cjs/src/vcs/match.cjs +106 -0
- package/dist/cjs/src/vcs/match.cjs.map +10 -0
- package/dist/cjs/src/vcs/snapshot.cjs +112 -0
- package/dist/cjs/src/vcs/snapshot.cjs.map +10 -0
- package/dist/cjs/src/vcs/storage.cjs +120 -0
- package/dist/cjs/src/vcs/storage.cjs.map +10 -0
- package/dist/cjs/src/vcs/types.cjs +30 -0
- package/dist/cjs/src/vcs/types.cjs.map +9 -0
- package/dist/cjs/src/vcs/vcs.cjs +305 -0
- package/dist/cjs/src/vcs/vcs.cjs.map +10 -0
- package/dist/cjs/src/vcs/walk.cjs +83 -0
- package/dist/cjs/src/vcs/walk.cjs.map +10 -0
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/src/index.mjs +3 -1
- package/dist/mjs/src/index.mjs.map +3 -3
- package/dist/mjs/src/vcs/diff.mjs +62 -0
- package/dist/mjs/src/vcs/diff.mjs.map +10 -0
- package/dist/mjs/src/vcs/index.mjs +7 -0
- package/dist/mjs/src/vcs/index.mjs.map +10 -0
- package/dist/mjs/src/vcs/match.mjs +66 -0
- package/dist/mjs/src/vcs/match.mjs.map +10 -0
- package/dist/mjs/src/vcs/snapshot.mjs +72 -0
- package/dist/mjs/src/vcs/snapshot.mjs.map +10 -0
- package/dist/mjs/src/vcs/storage.mjs +79 -0
- package/dist/mjs/src/vcs/storage.mjs.map +10 -0
- package/dist/mjs/src/vcs/types.mjs +2 -0
- package/dist/mjs/src/vcs/types.mjs.map +9 -0
- package/dist/mjs/src/vcs/vcs.mjs +265 -0
- package/dist/mjs/src/vcs/vcs.mjs.map +10 -0
- package/dist/mjs/src/vcs/walk.mjs +43 -0
- package/dist/mjs/src/vcs/walk.mjs.map +10 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/vcs/diff.d.ts +10 -0
- package/dist/types/src/vcs/index.d.ts +2 -0
- package/dist/types/src/vcs/match.d.ts +5 -0
- package/dist/types/src/vcs/snapshot.d.ts +20 -0
- package/dist/types/src/vcs/storage.d.ts +22 -0
- package/dist/types/src/vcs/types.d.ts +74 -0
- package/dist/types/src/vcs/vcs.d.ts +35 -0
- package/dist/types/src/vcs/walk.d.ts +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@ bun add shell-dsl memfs
|
|
|
36
36
|
- **Automatic escaping** — Interpolated values are escaped by default for safety
|
|
37
37
|
- **POSIX-inspired syntax** — Pipes, redirects, control flow operators, and more
|
|
38
38
|
- **Streaming pipelines** — Commands communicate via async iteration
|
|
39
|
+
- **Version control** — Built-in VCS with commits, branches, checkout, and diffs on any virtual filesystem
|
|
39
40
|
- **TypeScript-first** — Full type definitions included
|
|
40
41
|
|
|
41
42
|
## Getting Started
|
|
@@ -745,6 +746,109 @@ const fs = new FileSystem("/", {}, createWebUnderlyingFS(root));
|
|
|
745
746
|
```
|
|
746
747
|
|
|
747
748
|
|
|
749
|
+
## Version Control
|
|
750
|
+
|
|
751
|
+
`VersionControlSystem` adds git-like version control to any `VirtualFS`. It tracks changes as diffs, supports branching, and stores metadata in a `.vcs` directory.
|
|
752
|
+
|
|
753
|
+
```ts
|
|
754
|
+
import { VersionControlSystem, createVirtualFS } from "shell-dsl";
|
|
755
|
+
import { createFsFromVolume, Volume } from "memfs";
|
|
756
|
+
|
|
757
|
+
const vol = new Volume();
|
|
758
|
+
vol.fromJSON({
|
|
759
|
+
"/project/src/index.ts": 'console.log("hello")',
|
|
760
|
+
"/project/README.md": "# My Project",
|
|
761
|
+
});
|
|
762
|
+
const fs = createVirtualFS(createFsFromVolume(vol));
|
|
763
|
+
|
|
764
|
+
const vcs = new VersionControlSystem({
|
|
765
|
+
fs,
|
|
766
|
+
path: "/project",
|
|
767
|
+
});
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
### Committing Changes
|
|
771
|
+
|
|
772
|
+
```ts
|
|
773
|
+
// Commit all pending changes
|
|
774
|
+
const rev = await vcs.commit("initial commit");
|
|
775
|
+
|
|
776
|
+
// Selective commit with glob patterns (relative to root path)
|
|
777
|
+
await vcs.commit("update src only", { paths: ["/src/**"] });
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
### Checking Status
|
|
781
|
+
|
|
782
|
+
`status()` returns a `DiffEntry[]` describing uncommitted changes:
|
|
783
|
+
|
|
784
|
+
```ts
|
|
785
|
+
const changes = await vcs.status();
|
|
786
|
+
for (const entry of changes) {
|
|
787
|
+
console.log(entry.type, entry.path); // "add" | "modify" | "delete"
|
|
788
|
+
}
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
### Checkout
|
|
792
|
+
|
|
793
|
+
```ts
|
|
794
|
+
// Checkout a specific revision (errors if working tree is dirty)
|
|
795
|
+
await vcs.checkout(1);
|
|
796
|
+
|
|
797
|
+
// Force checkout, discarding uncommitted changes
|
|
798
|
+
await vcs.checkout(1, { force: true });
|
|
799
|
+
|
|
800
|
+
// Partial checkout — restore specific files without changing HEAD
|
|
801
|
+
await vcs.checkout(1, { paths: ["/src/index.ts", "/**/*.txt"] });
|
|
802
|
+
```
|
|
803
|
+
|
|
804
|
+
### Branching
|
|
805
|
+
|
|
806
|
+
```ts
|
|
807
|
+
// Create a branch at HEAD
|
|
808
|
+
await vcs.branch("feature");
|
|
809
|
+
|
|
810
|
+
// Switch to a branch
|
|
811
|
+
await vcs.checkout("feature");
|
|
812
|
+
|
|
813
|
+
// List all branches
|
|
814
|
+
const branches = await vcs.branches();
|
|
815
|
+
// [{ name: "main", revision: 1, current: false },
|
|
816
|
+
// { name: "feature", revision: 1, current: true }]
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
### History and Diffs
|
|
820
|
+
|
|
821
|
+
```ts
|
|
822
|
+
// Revision history
|
|
823
|
+
const entries = await vcs.log();
|
|
824
|
+
const filtered = await vcs.log({ path: "src/index.ts", limit: 10 });
|
|
825
|
+
|
|
826
|
+
// Diff between two revisions
|
|
827
|
+
const diff = await vcs.diff(1, 2);
|
|
828
|
+
for (const entry of diff) {
|
|
829
|
+
console.log(entry.type, entry.path); // "add" | "modify" | "delete"
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// Current HEAD info
|
|
833
|
+
const head = await vcs.head();
|
|
834
|
+
// { branch: "main", revision: 2 }
|
|
835
|
+
```
|
|
836
|
+
|
|
837
|
+
### Separate VCS Storage
|
|
838
|
+
|
|
839
|
+
By default, metadata lives in `{path}/.vcs`. You can store it on a different filesystem:
|
|
840
|
+
|
|
841
|
+
```ts
|
|
842
|
+
const vcs = new VersionControlSystem({
|
|
843
|
+
fs: workingTreeFs,
|
|
844
|
+
path: "/project",
|
|
845
|
+
vcsPath: {
|
|
846
|
+
fs: metadataFs, // different VirtualFS instance
|
|
847
|
+
path: "/meta/.vcs", // custom location
|
|
848
|
+
},
|
|
849
|
+
});
|
|
850
|
+
```
|
|
851
|
+
|
|
748
852
|
## Low-Level API
|
|
749
853
|
|
|
750
854
|
For advanced use cases (custom tooling, AST inspection):
|
|
@@ -809,6 +913,11 @@ import type {
|
|
|
809
913
|
Permission,
|
|
810
914
|
PermissionRules,
|
|
811
915
|
UnderlyingFS,
|
|
916
|
+
VCSConfig,
|
|
917
|
+
Revision,
|
|
918
|
+
DiffEntry,
|
|
919
|
+
LogEntry,
|
|
920
|
+
BranchInfo,
|
|
812
921
|
} from "shell-dsl";
|
|
813
922
|
```
|
|
814
923
|
|
package/dist/cjs/package.json
CHANGED
package/dist/cjs/src/index.cjs
CHANGED
|
@@ -70,6 +70,7 @@ __export(exports_src, {
|
|
|
70
70
|
createShellDSL: () => import_shell_dsl.createShellDSL,
|
|
71
71
|
createPipe: () => import_io2.createPipe,
|
|
72
72
|
WebFileSystem: () => import_fs2.WebFileSystem,
|
|
73
|
+
VersionControlSystem: () => import_vcs.VersionControlSystem,
|
|
73
74
|
StdinImpl: () => import_io.StdinImpl,
|
|
74
75
|
ShellPromise: () => import_shell_promise.ShellPromise,
|
|
75
76
|
ShellError: () => import_errors.ShellError,
|
|
@@ -100,5 +101,6 @@ var import_fs2 = require("./fs/index.cjs");
|
|
|
100
101
|
var import_io = require("./io/index.cjs");
|
|
101
102
|
var import_io2 = require("./io/index.cjs");
|
|
102
103
|
var import_utils = require("./utils/index.cjs");
|
|
104
|
+
var import_vcs = require("./vcs/index.cjs");
|
|
103
105
|
|
|
104
|
-
//# debugId=
|
|
106
|
+
//# debugId=27F0973A44539CA064756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"// Main class exports\nexport { ShellDSL, createShellDSL, type Program } from \"./shell-dsl.cjs\";\nexport { ShellPromise, type ShellPromiseOptions } from \"./shell-promise.cjs\";\n\n// Types\nexport type {\n VirtualFS,\n FileStat,\n Command,\n CommandContext,\n Stdin,\n Stdout,\n Stderr,\n OutputCollector,\n ExecResult,\n ShellConfig,\n RawValue,\n} from \"./types.cjs\";\nexport { isRawValue } from \"./types.cjs\";\n\n// Errors\nexport { ShellError, LexError, ParseError } from \"./errors.cjs\";\n\n// Lexer\nexport { Lexer, lex, tokenToString } from \"./lexer/index.cjs\";\nexport type { Token, RedirectMode } from \"./lexer/index.cjs\";\n\n// Parser\nexport { Parser, parse } from \"./parser/index.cjs\";\nexport type {\n ASTNode,\n Redirect,\n CommandNode,\n PipelineNode,\n AndNode,\n OrNode,\n SequenceNode,\n LiteralNode,\n VariableNode,\n SubstitutionNode,\n GlobNode,\n ConcatNode,\n IfNode,\n ForNode,\n WhileNode,\n UntilNode,\n CaseNode,\n CaseClause,\n ArithmeticNode,\n} from \"./parser/index.cjs\";\nexport {\n isCommandNode,\n isPipelineNode,\n isAndNode,\n isOrNode,\n isSequenceNode,\n isLiteralNode,\n isVariableNode,\n isSubstitutionNode,\n isGlobNode,\n isConcatNode,\n isIfNode,\n isForNode,\n isWhileNode,\n isUntilNode,\n isCaseNode,\n isArithmeticNode,\n} from \"./parser/index.cjs\";\n\n// Interpreter\nexport { Interpreter, type InterpreterOptions, BreakException, ContinueException } from \"./interpreter/index.cjs\";\n\n// Filesystem\nexport { createVirtualFS } from \"./fs/index.cjs\";\nexport {\n FileSystem,\n ReadOnlyFileSystem,\n WebFileSystem,\n createWebUnderlyingFS,\n type PathOps,\n type Permission,\n type PermissionRules,\n type UnderlyingFS,\n} from \"./fs/index.cjs\";\n\n// I/O\nexport { createStdin, StdinImpl } from \"./io/index.cjs\";\nexport { createStdout, createStderr, createPipe, OutputCollectorImpl, PipeBuffer } from \"./io/index.cjs\";\n\n// Utilities\nexport { escape, escapeForInterpolation, globVirtualFS } from \"./utils/index.cjs\";\nexport type { GlobVirtualFS, GlobOptions } from \"./utils/index.cjs\";\n"
|
|
5
|
+
"// Main class exports\nexport { ShellDSL, createShellDSL, type Program } from \"./shell-dsl.cjs\";\nexport { ShellPromise, type ShellPromiseOptions } from \"./shell-promise.cjs\";\n\n// Types\nexport type {\n VirtualFS,\n FileStat,\n Command,\n CommandContext,\n Stdin,\n Stdout,\n Stderr,\n OutputCollector,\n ExecResult,\n ShellConfig,\n RawValue,\n} from \"./types.cjs\";\nexport { isRawValue } from \"./types.cjs\";\n\n// Errors\nexport { ShellError, LexError, ParseError } from \"./errors.cjs\";\n\n// Lexer\nexport { Lexer, lex, tokenToString } from \"./lexer/index.cjs\";\nexport type { Token, RedirectMode } from \"./lexer/index.cjs\";\n\n// Parser\nexport { Parser, parse } from \"./parser/index.cjs\";\nexport type {\n ASTNode,\n Redirect,\n CommandNode,\n PipelineNode,\n AndNode,\n OrNode,\n SequenceNode,\n LiteralNode,\n VariableNode,\n SubstitutionNode,\n GlobNode,\n ConcatNode,\n IfNode,\n ForNode,\n WhileNode,\n UntilNode,\n CaseNode,\n CaseClause,\n ArithmeticNode,\n} from \"./parser/index.cjs\";\nexport {\n isCommandNode,\n isPipelineNode,\n isAndNode,\n isOrNode,\n isSequenceNode,\n isLiteralNode,\n isVariableNode,\n isSubstitutionNode,\n isGlobNode,\n isConcatNode,\n isIfNode,\n isForNode,\n isWhileNode,\n isUntilNode,\n isCaseNode,\n isArithmeticNode,\n} from \"./parser/index.cjs\";\n\n// Interpreter\nexport { Interpreter, type InterpreterOptions, BreakException, ContinueException } from \"./interpreter/index.cjs\";\n\n// Filesystem\nexport { createVirtualFS } from \"./fs/index.cjs\";\nexport {\n FileSystem,\n ReadOnlyFileSystem,\n WebFileSystem,\n createWebUnderlyingFS,\n type PathOps,\n type Permission,\n type PermissionRules,\n type UnderlyingFS,\n} from \"./fs/index.cjs\";\n\n// I/O\nexport { createStdin, StdinImpl } from \"./io/index.cjs\";\nexport { createStdout, createStderr, createPipe, OutputCollectorImpl, PipeBuffer } from \"./io/index.cjs\";\n\n// Utilities\nexport { escape, escapeForInterpolation, globVirtualFS } from \"./utils/index.cjs\";\nexport type { GlobVirtualFS, GlobOptions } from \"./utils/index.cjs\";\n\n// Version Control\nexport { VersionControlSystem } from \"./vcs/index.cjs\";\nexport type {\n VCSConfig,\n Revision,\n DiffEntry,\n TreeManifest,\n FileEntry,\n CommitOptions,\n CheckoutOptions,\n LogOptions,\n LogEntry,\n BranchInfo,\n} from \"./vcs/index.cjs\";\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACuD,IAAvD;AACuD,IAAvD;AAgB2B,IAA3B;AAGiD,IAAjD;AAG0C,IAA1C;AAI8B,IAA9B;AAuCO,IAjBP;AAoBwF,IAAxF;AAGgC,IAAhC;AAUO,IATP;AAYuC,IAAvC;AACwF,IAAxF;AAG8D,IAA9D;AAIqC,IAArC;",
|
|
8
|
+
"debugId": "27F0973A44539CA064756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
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/diff.ts
|
|
40
|
+
var exports_diff = {};
|
|
41
|
+
__export(exports_diff, {
|
|
42
|
+
diffWorkingTree: () => diffWorkingTree,
|
|
43
|
+
diffManifests: () => diffManifests
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(exports_diff);
|
|
46
|
+
var import_walk = require("./walk.cjs");
|
|
47
|
+
function diffManifests(before, after) {
|
|
48
|
+
const entries = [];
|
|
49
|
+
const allPaths = new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
50
|
+
for (const path of allPaths) {
|
|
51
|
+
const prev = before[path];
|
|
52
|
+
const curr = after[path];
|
|
53
|
+
if (!prev && curr) {
|
|
54
|
+
entries.push({ type: "add", path, content: curr.content });
|
|
55
|
+
} else if (prev && !curr) {
|
|
56
|
+
entries.push({ type: "delete", path, previousContent: prev.content });
|
|
57
|
+
} else if (prev && curr && prev.content !== curr.content) {
|
|
58
|
+
entries.push({
|
|
59
|
+
type: "modify",
|
|
60
|
+
path,
|
|
61
|
+
content: curr.content,
|
|
62
|
+
previousContent: prev.content
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return entries.sort((a, b) => a.path.localeCompare(b.path));
|
|
67
|
+
}
|
|
68
|
+
async function diffWorkingTree(fs, rootPath, manifest, exclude = []) {
|
|
69
|
+
const entries = [];
|
|
70
|
+
const workingFiles = await import_walk.walkTree(fs, rootPath, exclude);
|
|
71
|
+
const manifestPaths = new Set(Object.keys(manifest));
|
|
72
|
+
const seenPaths = new Set;
|
|
73
|
+
for (const relPath of workingFiles) {
|
|
74
|
+
seenPaths.add(relPath);
|
|
75
|
+
const fullPath = fs.resolve(rootPath, relPath);
|
|
76
|
+
const content = await fs.readFile(fullPath);
|
|
77
|
+
const b64 = Buffer.from(content).toString("base64");
|
|
78
|
+
const prev = manifest[relPath];
|
|
79
|
+
if (!prev) {
|
|
80
|
+
entries.push({ type: "add", path: relPath, content: b64 });
|
|
81
|
+
} else if (prev.content !== b64) {
|
|
82
|
+
entries.push({
|
|
83
|
+
type: "modify",
|
|
84
|
+
path: relPath,
|
|
85
|
+
content: b64,
|
|
86
|
+
previousContent: prev.content
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const manifestPath of manifestPaths) {
|
|
91
|
+
if (!seenPaths.has(manifestPath)) {
|
|
92
|
+
entries.push({
|
|
93
|
+
type: "delete",
|
|
94
|
+
path: manifestPath,
|
|
95
|
+
previousContent: manifest[manifestPath].content
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return entries.sort((a, b) => a.path.localeCompare(b.path));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//# debugId=C182915799ABD69764756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/vcs/diff.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { VirtualFS } from \"../types.cjs\";\nimport type { TreeManifest, DiffEntry } from \"./types.cjs\";\nimport { walkTree } from \"./walk.cjs\";\n\n/**\n * Compute diff entries between two tree manifests.\n */\nexport function diffManifests(\n before: TreeManifest,\n after: TreeManifest,\n): DiffEntry[] {\n const entries: DiffEntry[] = [];\n const allPaths = new Set([...Object.keys(before), ...Object.keys(after)]);\n\n for (const path of allPaths) {\n const prev = before[path];\n const curr = after[path];\n\n if (!prev && curr) {\n entries.push({ type: \"add\", path, content: curr.content });\n } else if (prev && !curr) {\n entries.push({ type: \"delete\", path, previousContent: prev.content });\n } else if (prev && curr && prev.content !== curr.content) {\n entries.push({\n type: \"modify\",\n path,\n content: curr.content,\n previousContent: prev.content,\n });\n }\n }\n\n return entries.sort((a, b) => a.path.localeCompare(b.path));\n}\n\n/**\n * Compute diff between a tree manifest and the current working tree.\n */\nexport async function diffWorkingTree(\n fs: VirtualFS,\n rootPath: string,\n manifest: TreeManifest,\n exclude: string[] = [],\n): Promise<DiffEntry[]> {\n const entries: DiffEntry[] = [];\n const workingFiles = await walkTree(fs, rootPath, exclude);\n const manifestPaths = new Set(Object.keys(manifest));\n const seenPaths = new Set<string>();\n\n for (const relPath of workingFiles) {\n seenPaths.add(relPath);\n const fullPath = fs.resolve(rootPath, relPath);\n const content = await fs.readFile(fullPath);\n const b64 = Buffer.from(content).toString(\"base64\");\n\n const prev = manifest[relPath];\n if (!prev) {\n entries.push({ type: \"add\", path: relPath, content: b64 });\n } else if (prev.content !== b64) {\n entries.push({\n type: \"modify\",\n path: relPath,\n content: b64,\n previousContent: prev.content,\n });\n }\n }\n\n for (const manifestPath of manifestPaths) {\n if (!seenPaths.has(manifestPath)) {\n entries.push({\n type: \"delete\",\n path: manifestPath,\n previousContent: manifest[manifestPath]!.content,\n });\n }\n }\n\n return entries.sort((a, b) => a.path.localeCompare(b.path));\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEyB,IAAzB;AAKO,SAAS,aAAa,CAC3B,QACA,OACa;AAAA,EACb,MAAM,UAAuB,CAAC;AAAA,EAC9B,MAAM,WAAW,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,MAAM,GAAG,GAAG,OAAO,KAAK,KAAK,CAAC,CAAC;AAAA,EAExE,WAAW,QAAQ,UAAU;AAAA,IAC3B,MAAM,OAAO,OAAO;AAAA,IACpB,MAAM,OAAO,MAAM;AAAA,IAEnB,IAAI,CAAC,QAAQ,MAAM;AAAA,MACjB,QAAQ,KAAK,EAAE,MAAM,OAAO,MAAM,SAAS,KAAK,QAAQ,CAAC;AAAA,IAC3D,EAAO,SAAI,QAAQ,CAAC,MAAM;AAAA,MACxB,QAAQ,KAAK,EAAE,MAAM,UAAU,MAAM,iBAAiB,KAA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AAAA,QACN,iBAAiB,SAAS,cAAe;AAAA,MAC3C,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,OAAO,QAAQ,KAAK,CAAC,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC;AAAA;",
|
|
8
|
+
"debugId": "C182915799ABD69764756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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/index.ts
|
|
40
|
+
var exports_vcs = {};
|
|
41
|
+
__export(exports_vcs, {
|
|
42
|
+
VersionControlSystem: () => import_vcs.VersionControlSystem
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(exports_vcs);
|
|
45
|
+
var import_vcs = require("./vcs.cjs");
|
|
46
|
+
|
|
47
|
+
//# debugId=882B2013CEEDB5D864756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/vcs/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"export { VersionControlSystem } from \"./vcs.cjs\";\nexport type {\n VCSConfig,\n Revision,\n DiffEntry,\n TreeManifest,\n FileEntry,\n CommitOptions,\n CheckoutOptions,\n LogOptions,\n LogEntry,\n BranchInfo,\n} from \"./types.cjs\";\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAqC,IAArC;",
|
|
8
|
+
"debugId": "882B2013CEEDB5D864756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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/match.ts
|
|
40
|
+
var exports_match = {};
|
|
41
|
+
__export(exports_match, {
|
|
42
|
+
matchGlobPath: () => matchGlobPath
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(exports_match);
|
|
45
|
+
function matchGlobPath(pattern, filePath) {
|
|
46
|
+
const p = pattern.startsWith("/") ? pattern.slice(1) : pattern;
|
|
47
|
+
const f = filePath.startsWith("/") ? filePath.slice(1) : filePath;
|
|
48
|
+
const patternParts = p.split("/");
|
|
49
|
+
const pathParts = f.split("/");
|
|
50
|
+
return matchParts(patternParts, pathParts, 0, 0);
|
|
51
|
+
}
|
|
52
|
+
function matchParts(pattern, path, pi, fi) {
|
|
53
|
+
while (pi < pattern.length && fi < path.length) {
|
|
54
|
+
const seg = pattern[pi];
|
|
55
|
+
if (seg === "**") {
|
|
56
|
+
for (let i = fi;i <= path.length; i++) {
|
|
57
|
+
if (matchParts(pattern, path, pi + 1, i))
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (!matchSegment(seg, path[fi]))
|
|
63
|
+
return false;
|
|
64
|
+
pi++;
|
|
65
|
+
fi++;
|
|
66
|
+
}
|
|
67
|
+
while (pi < pattern.length && pattern[pi] === "**")
|
|
68
|
+
pi++;
|
|
69
|
+
return pi === pattern.length && fi === path.length;
|
|
70
|
+
}
|
|
71
|
+
function matchSegment(pattern, segment) {
|
|
72
|
+
let regex = "^";
|
|
73
|
+
for (let i = 0;i < pattern.length; i++) {
|
|
74
|
+
const c = pattern[i];
|
|
75
|
+
switch (c) {
|
|
76
|
+
case "*":
|
|
77
|
+
regex += "[^/]*";
|
|
78
|
+
break;
|
|
79
|
+
case "?":
|
|
80
|
+
regex += "[^/]";
|
|
81
|
+
break;
|
|
82
|
+
case ".":
|
|
83
|
+
case "^":
|
|
84
|
+
case "$":
|
|
85
|
+
case "+":
|
|
86
|
+
case "{":
|
|
87
|
+
case "}":
|
|
88
|
+
case "(":
|
|
89
|
+
case ")":
|
|
90
|
+
case "|":
|
|
91
|
+
case "\\":
|
|
92
|
+
regex += "\\" + c;
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
regex += c;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
regex += "$";
|
|
99
|
+
try {
|
|
100
|
+
return new RegExp(regex).test(segment);
|
|
101
|
+
} catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//# debugId=9C038AE3F1837D4764756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/vcs/match.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Match a file path against a glob pattern.\n * Supports `**` for recursive directory matching, `*` for single segment wildcard.\n */\nexport function matchGlobPath(pattern: string, filePath: string): boolean {\n // Normalize: strip leading slashes\n const p = pattern.startsWith(\"/\") ? pattern.slice(1) : pattern;\n const f = filePath.startsWith(\"/\") ? filePath.slice(1) : filePath;\n\n const patternParts = p.split(\"/\");\n const pathParts = f.split(\"/\");\n\n return matchParts(patternParts, pathParts, 0, 0);\n}\n\nfunction matchParts(\n pattern: string[],\n path: string[],\n pi: number,\n fi: number,\n): boolean {\n while (pi < pattern.length && fi < path.length) {\n const seg = pattern[pi]!;\n\n if (seg === \"**\") {\n // ** matches zero or more path segments\n // Try matching rest of pattern against current position and all subsequent positions\n for (let i = fi; i <= path.length; i++) {\n if (matchParts(pattern, path, pi + 1, i)) return true;\n }\n return false;\n }\n\n if (!matchSegment(seg, path[fi]!)) return false;\n pi++;\n fi++;\n }\n\n // Skip trailing ** patterns\n while (pi < pattern.length && pattern[pi] === \"**\") pi++;\n\n return pi === pattern.length && fi === path.length;\n}\n\nfunction matchSegment(pattern: string, segment: string): boolean {\n // Convert glob segment to regex\n let regex = \"^\";\n for (let i = 0; i < pattern.length; i++) {\n const c = pattern[i]!;\n switch (c) {\n case \"*\":\n regex += \"[^/]*\";\n break;\n case \"?\":\n regex += \"[^/]\";\n break;\n case \".\":\n case \"^\":\n case \"$\":\n case \"+\":\n case \"{\":\n case \"}\":\n case \"(\":\n case \")\":\n case \"|\":\n case \"\\\\\":\n regex += \"\\\\\" + c;\n break;\n default:\n regex += c;\n }\n }\n regex += \"$\";\n\n try {\n return new RegExp(regex).test(segment);\n } catch {\n return false;\n }\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,SAAS,aAAa,CAAC,SAAiB,UAA2B;AAAA,EAExE,MAAM,IAAI,QAAQ,WAAW,GAAG,IAAI,QAAQ,MAAM,CAAC,IAAI;AAAA,EACvD,MAAM,IAAI,SAAS,WAAW,GAAG,IAAI,SAAS,MAAM,CAAC,IAAI;AAAA,EAEzD,MAAM,e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AAAA;AAAA;",
|
|
8
|
+
"debugId": "9C038AE3F1837D4764756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
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_walk = require("./walk.cjs");
|
|
48
|
+
async function buildTreeManifest(fs, rootPath, exclude = []) {
|
|
49
|
+
const manifest = {};
|
|
50
|
+
const files = await import_walk.walkTree(fs, rootPath, exclude);
|
|
51
|
+
for (const relPath of files) {
|
|
52
|
+
const fullPath = fs.resolve(rootPath, relPath);
|
|
53
|
+
const content = await fs.readFile(fullPath);
|
|
54
|
+
const buf = Buffer.from(content);
|
|
55
|
+
manifest[relPath] = {
|
|
56
|
+
content: buf.toString("base64"),
|
|
57
|
+
size: buf.length
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return manifest;
|
|
61
|
+
}
|
|
62
|
+
async function buildPartialManifest(fs, rootPath, paths) {
|
|
63
|
+
const manifest = {};
|
|
64
|
+
for (const relPath of paths) {
|
|
65
|
+
const fullPath = fs.resolve(rootPath, relPath);
|
|
66
|
+
if (!await fs.exists(fullPath))
|
|
67
|
+
continue;
|
|
68
|
+
const stat = await fs.stat(fullPath);
|
|
69
|
+
if (!stat.isFile())
|
|
70
|
+
continue;
|
|
71
|
+
const content = await fs.readFile(fullPath);
|
|
72
|
+
const buf = Buffer.from(content);
|
|
73
|
+
manifest[relPath] = {
|
|
74
|
+
content: buf.toString("base64"),
|
|
75
|
+
size: buf.length
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return manifest;
|
|
79
|
+
}
|
|
80
|
+
async function restoreTree(fs, rootPath, manifest, options) {
|
|
81
|
+
const fullRestore = options?.fullRestore ?? false;
|
|
82
|
+
const filterPaths = options?.paths ? new Set(options.paths) : null;
|
|
83
|
+
for (const [relPath, entry] of Object.entries(manifest)) {
|
|
84
|
+
if (filterPaths && !filterPaths.has(relPath))
|
|
85
|
+
continue;
|
|
86
|
+
await writeFileFromEntry(fs, rootPath, relPath, entry);
|
|
87
|
+
}
|
|
88
|
+
if (fullRestore) {
|
|
89
|
+
const exclude = getVcsDirName(rootPath);
|
|
90
|
+
const currentFiles = await import_walk.walkTree(fs, rootPath, exclude ? [exclude] : []);
|
|
91
|
+
for (const relPath of currentFiles) {
|
|
92
|
+
if (!manifest[relPath]) {
|
|
93
|
+
const fullPath = fs.resolve(rootPath, relPath);
|
|
94
|
+
await fs.rm(fullPath);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function writeFileFromEntry(fs, rootPath, relPath, entry) {
|
|
100
|
+
const fullPath = fs.resolve(rootPath, relPath);
|
|
101
|
+
const dir = fs.dirname(fullPath);
|
|
102
|
+
if (!await fs.exists(dir)) {
|
|
103
|
+
await fs.mkdir(dir, { recursive: true });
|
|
104
|
+
}
|
|
105
|
+
const buf = Buffer.from(entry.content, "base64");
|
|
106
|
+
await fs.writeFile(fullPath, buf);
|
|
107
|
+
}
|
|
108
|
+
function getVcsDirName(_rootPath) {
|
|
109
|
+
return ".vcs";
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//# debugId=E0FC26F624360D1C64756E2164756E21
|
|
@@ -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 } from \"./types.cjs\";\nimport { walkTree } 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 exclude: string[] = [],\n): Promise<TreeManifest> {\n const manifest: TreeManifest = {};\n const files = await walkTree(fs, rootPath, exclude);\n\n for (const relPath of files) {\n const fullPath = fs.resolve(rootPath, relPath);\n const content = await fs.readFile(fullPath);\n const buf = Buffer.from(content);\n manifest[relPath] = {\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.isFile()) continue;\n\n const content = await fs.readFile(fullPath);\n const buf = Buffer.from(content);\n manifest[relPath] = {\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?: { fullRestore?: boolean; paths?: string[] },\n): Promise<void> {\n const fullRestore = options?.fullRestore ?? false;\n const filterPaths = options?.paths ? new Set(options.paths) : null;\n\n // Write files from manifest\n for (const [relPath, entry] of Object.entries(manifest)) {\n if (filterPaths && !filterPaths.has(relPath)) continue;\n await writeFileFromEntry(fs, rootPath, relPath, entry);\n }\n\n // Delete files not in manifest (full restore only)\n if (fullRestore) {\n const exclude = getVcsDirName(rootPath);\n const currentFiles = await walkTree(fs, rootPath, exclude ? [exclude] : []);\n\n for (const relPath of currentFiles) {\n if (!manifest[relPath]) {\n const fullPath = fs.resolve(rootPath, relPath);\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 const dir = fs.dirname(fullPath);\n\n // Ensure parent directory exists\n if (!(await fs.exists(dir))) {\n await fs.mkdir(dir, { recursive: true });\n }\n\n const buf = Buffer.from(entry.content, \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