shell-dsl 0.0.34 → 0.0.35
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 +16 -3
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/fs/memfs-adapter.cjs +56 -2
- package/dist/cjs/src/fs/memfs-adapter.cjs.map +3 -3
- package/dist/cjs/src/fs/real-fs.cjs +134 -3
- package/dist/cjs/src/fs/real-fs.cjs.map +3 -3
- package/dist/cjs/src/fs/special-files.cjs +3 -2
- package/dist/cjs/src/fs/special-files.cjs.map +3 -3
- package/dist/cjs/src/fs/web-fs.cjs +72 -3
- package/dist/cjs/src/fs/web-fs.cjs.map +3 -3
- package/dist/cjs/src/index.cjs.map +2 -2
- package/dist/cjs/src/types.cjs.map +2 -2
- package/dist/cjs/src/vcs/content.cjs +106 -0
- package/dist/cjs/src/vcs/content.cjs.map +10 -0
- package/dist/cjs/src/vcs/diff.cjs +72 -28
- package/dist/cjs/src/vcs/diff.cjs.map +3 -3
- package/dist/cjs/src/vcs/index.cjs.map +1 -1
- package/dist/cjs/src/vcs/objects.cjs +141 -0
- package/dist/cjs/src/vcs/objects.cjs.map +10 -0
- package/dist/cjs/src/vcs/rules.cjs +6 -3
- package/dist/cjs/src/vcs/rules.cjs.map +3 -3
- package/dist/cjs/src/vcs/snapshot.cjs +89 -39
- package/dist/cjs/src/vcs/snapshot.cjs.map +3 -3
- package/dist/cjs/src/vcs/storage.cjs +44 -3
- package/dist/cjs/src/vcs/storage.cjs.map +3 -3
- package/dist/cjs/src/vcs/text-diff.cjs +219 -0
- package/dist/cjs/src/vcs/text-diff.cjs.map +10 -0
- package/dist/cjs/src/vcs/vcs.cjs +108 -61
- package/dist/cjs/src/vcs/vcs.cjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/src/fs/memfs-adapter.mjs +57 -2
- package/dist/mjs/src/fs/memfs-adapter.mjs.map +3 -3
- package/dist/mjs/src/fs/real-fs.mjs +135 -3
- package/dist/mjs/src/fs/real-fs.mjs.map +3 -3
- package/dist/mjs/src/fs/special-files.mjs +3 -2
- package/dist/mjs/src/fs/special-files.mjs.map +3 -3
- package/dist/mjs/src/fs/web-fs.mjs +72 -3
- package/dist/mjs/src/fs/web-fs.mjs.map +3 -3
- package/dist/mjs/src/index.mjs.map +2 -2
- package/dist/mjs/src/types.mjs.map +2 -2
- package/dist/mjs/src/vcs/content.mjs +66 -0
- package/dist/mjs/src/vcs/content.mjs.map +10 -0
- package/dist/mjs/src/vcs/diff.mjs +72 -28
- package/dist/mjs/src/vcs/diff.mjs.map +3 -3
- package/dist/mjs/src/vcs/index.mjs.map +1 -1
- package/dist/mjs/src/vcs/objects.mjs +106 -0
- package/dist/mjs/src/vcs/objects.mjs.map +10 -0
- package/dist/mjs/src/vcs/rules.mjs +6 -3
- package/dist/mjs/src/vcs/rules.mjs.map +3 -3
- package/dist/mjs/src/vcs/snapshot.mjs +89 -39
- package/dist/mjs/src/vcs/snapshot.mjs.map +3 -3
- package/dist/mjs/src/vcs/storage.mjs +45 -3
- package/dist/mjs/src/vcs/storage.mjs.map +3 -3
- package/dist/mjs/src/vcs/text-diff.mjs +179 -0
- package/dist/mjs/src/vcs/text-diff.mjs.map +10 -0
- package/dist/mjs/src/vcs/vcs.mjs +115 -63
- package/dist/mjs/src/vcs/vcs.mjs.map +3 -3
- package/dist/types/src/fs/real-fs.d.ts +12 -1
- package/dist/types/src/index.d.ts +2 -2
- package/dist/types/src/types.d.ts +10 -0
- package/dist/types/src/vcs/content.d.ts +6 -0
- package/dist/types/src/vcs/diff.d.ts +10 -7
- package/dist/types/src/vcs/index.d.ts +1 -1
- package/dist/types/src/vcs/objects.d.ts +22 -0
- package/dist/types/src/vcs/snapshot.d.ts +13 -8
- package/dist/types/src/vcs/storage.d.ts +7 -1
- package/dist/types/src/vcs/text-diff.d.ts +1 -0
- package/dist/types/src/vcs/types.d.ts +20 -5
- package/dist/types/src/vcs/vcs.d.ts +6 -0
- package/package.json +7 -2
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
discardsSpecialFileWrites,
|
|
6
6
|
existsSpecialFile,
|
|
7
7
|
getSpecialPathError,
|
|
8
|
+
isDevNullPath,
|
|
8
9
|
readSpecialFile,
|
|
9
10
|
statSpecialFile
|
|
10
11
|
} from "./special-files.mjs";
|
|
@@ -19,6 +20,17 @@ function createVirtualFS(memfs) {
|
|
|
19
20
|
const buf = Buffer.from(content);
|
|
20
21
|
return encoding ? buf.toString(encoding) : buf;
|
|
21
22
|
},
|
|
23
|
+
readStream(path) {
|
|
24
|
+
if (isDevNullPath(path)) {
|
|
25
|
+
return emptyIterable();
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
async* [Symbol.asyncIterator]() {
|
|
29
|
+
const content = await fs.readFile(path);
|
|
30
|
+
yield Buffer.from(content);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
},
|
|
22
34
|
async readdir(path) {
|
|
23
35
|
const specialError = getSpecialPathError(path, "readdir");
|
|
24
36
|
if (specialError)
|
|
@@ -35,7 +47,8 @@ function createVirtualFS(memfs) {
|
|
|
35
47
|
isFile: () => stats.isFile(),
|
|
36
48
|
isDirectory: () => stats.isDirectory(),
|
|
37
49
|
size: Number(stats.size),
|
|
38
|
-
mtime: new Date(stats.mtime)
|
|
50
|
+
mtime: new Date(stats.mtime),
|
|
51
|
+
mtimeMs: Number(stats.mtimeMs ?? stats.mtime)
|
|
39
52
|
};
|
|
40
53
|
},
|
|
41
54
|
async exists(path) {
|
|
@@ -61,6 +74,36 @@ function createVirtualFS(memfs) {
|
|
|
61
74
|
}
|
|
62
75
|
await fs.appendFile(path, data);
|
|
63
76
|
},
|
|
77
|
+
async writeStream(path, opts) {
|
|
78
|
+
if (discardsSpecialFileWrites(path)) {
|
|
79
|
+
return createDiscardingWritable();
|
|
80
|
+
}
|
|
81
|
+
const chunks = [];
|
|
82
|
+
let closed = false;
|
|
83
|
+
return {
|
|
84
|
+
async write(chunk) {
|
|
85
|
+
if (closed) {
|
|
86
|
+
throw new Error("stream is closed");
|
|
87
|
+
}
|
|
88
|
+
chunks.push(Buffer.from(chunk));
|
|
89
|
+
},
|
|
90
|
+
async close() {
|
|
91
|
+
if (closed)
|
|
92
|
+
return;
|
|
93
|
+
closed = true;
|
|
94
|
+
const data = Buffer.concat(chunks.map((chunk) => Buffer.from(chunk)));
|
|
95
|
+
if (opts?.append) {
|
|
96
|
+
await fs.appendFile(path, data);
|
|
97
|
+
} else {
|
|
98
|
+
await fs.writeFile(path, data);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
async abort(_reason) {
|
|
102
|
+
closed = true;
|
|
103
|
+
chunks.length = 0;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
},
|
|
64
107
|
async mkdir(path, opts) {
|
|
65
108
|
const specialError = getSpecialPathError(path, "mkdir");
|
|
66
109
|
if (specialError)
|
|
@@ -102,8 +145,20 @@ function createVirtualFS(memfs) {
|
|
|
102
145
|
}
|
|
103
146
|
};
|
|
104
147
|
}
|
|
148
|
+
function emptyIterable() {
|
|
149
|
+
return {
|
|
150
|
+
async* [Symbol.asyncIterator]() {}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function createDiscardingWritable() {
|
|
154
|
+
return {
|
|
155
|
+
async write(_chunk) {},
|
|
156
|
+
async close() {},
|
|
157
|
+
async abort(_reason) {}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
105
160
|
export {
|
|
106
161
|
createVirtualFS
|
|
107
162
|
};
|
|
108
163
|
|
|
109
|
-
//# debugId=
|
|
164
|
+
//# debugId=D1AA4DE00C9BA29964756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/fs/memfs-adapter.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { IFs } from \"memfs\";\nimport type { VirtualFS, FileStat } from \"../types.mjs\";\nimport * as pathModule from \"path\";\nimport { globVirtualFS } from \"../utils/glob.mjs\";\nimport {\n discardsSpecialFileWrites,\n existsSpecialFile,\n getSpecialPathError,\n readSpecialFile,\n statSpecialFile,\n} from \"./special-files.mjs\";\n\nexport function createVirtualFS(memfs: IFs): VirtualFS {\n const { promises: fs } = memfs;\n\n return {\n readFile: (async (path: string, encoding?: BufferEncoding): Promise<Buffer | string> => {\n const specialContent = readSpecialFile(path, encoding);\n if (specialContent !== undefined) return specialContent;\n const content = await fs.readFile(path);\n const buf = Buffer.from(content);\n return encoding ? buf.toString(encoding) : buf;\n }) as VirtualFS[\"readFile\"],\n\n async readdir(path: string): Promise<string[]> {\n const specialError = getSpecialPathError(path, \"readdir\");\n if (specialError) throw specialError;\n const entries = await fs.readdir(path);\n return entries.map(String);\n },\n\n async stat(path: string): Promise<FileStat> {\n const specialStat = statSpecialFile(path);\n if (specialStat) return specialStat;\n const stats = await fs.stat(path);\n return {\n isFile: () => stats.isFile(),\n isDirectory: () => stats.isDirectory(),\n size: Number(stats.size),\n mtime: new Date(stats.mtime),\n };\n },\n\n async exists(path: string): Promise<boolean> {\n const specialExists = existsSpecialFile(path);\n if (specialExists !== undefined) return specialExists;\n try {\n await fs.stat(path);\n return true;\n } catch {\n return false;\n }\n },\n\n async writeFile(path: string, data: Buffer | string): Promise<void> {\n if (discardsSpecialFileWrites(path)) {\n return;\n }\n await fs.writeFile(path, data);\n },\n\n async appendFile(path: string, data: Buffer | string): Promise<void> {\n if (discardsSpecialFileWrites(path)) {\n return;\n }\n await fs.appendFile(path, data);\n },\n\n async mkdir(path: string, opts?: { recursive?: boolean }): Promise<void> {\n const specialError = getSpecialPathError(path, \"mkdir\");\n if (specialError) throw specialError;\n await fs.mkdir(path, opts);\n },\n\n async rm(path: string, opts?: { recursive?: boolean; force?: boolean }): Promise<void> {\n const specialError = getSpecialPathError(path, \"rm\");\n if (specialError) throw specialError;\n try {\n const stats = await fs.stat(path);\n if (stats.isDirectory()) {\n await fs.rmdir(path, { recursive: opts?.recursive });\n } else {\n await fs.unlink(path);\n }\n } catch (err) {\n if (!opts?.force) throw err;\n }\n },\n\n resolve(...paths: string[]): string {\n return pathModule.resolve(...paths);\n },\n\n dirname(path: string): string {\n return pathModule.dirname(path);\n },\n\n basename(path: string): string {\n return pathModule.basename(path);\n },\n\n async glob(pattern: string, opts?: { cwd?: string }): Promise<string[]> {\n const cwd = opts?.cwd ?? \"/\";\n return globVirtualFS(\n {\n readdir: (filePath: string) => this.readdir(filePath),\n stat: (filePath: string) => this.stat(filePath),\n resolve: (...paths: string[]) => this.resolve(...paths),\n },\n pattern,\n { cwd }\n );\n },\n };\n}\n"
|
|
5
|
+
"import type { IFs } from \"memfs\";\nimport type { VirtualFS, VirtualFSWritable, FileStat } from \"../types.mjs\";\nimport * as pathModule from \"path\";\nimport { globVirtualFS } from \"../utils/glob.mjs\";\nimport {\n discardsSpecialFileWrites,\n existsSpecialFile,\n getSpecialPathError,\n isDevNullPath,\n readSpecialFile,\n statSpecialFile,\n} from \"./special-files.mjs\";\n\nexport function createVirtualFS(memfs: IFs): VirtualFS {\n const { promises: fs } = memfs;\n\n return {\n readFile: (async (path: string, encoding?: BufferEncoding): Promise<Buffer | string> => {\n const specialContent = readSpecialFile(path, encoding);\n if (specialContent !== undefined) return specialContent;\n const content = await fs.readFile(path);\n const buf = Buffer.from(content);\n return encoding ? buf.toString(encoding) : buf;\n }) as VirtualFS[\"readFile\"],\n\n readStream(path: string): AsyncIterable<Uint8Array> {\n if (isDevNullPath(path)) {\n return emptyIterable();\n }\n return {\n async *[Symbol.asyncIterator]() {\n const content = await fs.readFile(path);\n yield Buffer.from(content);\n },\n };\n },\n\n async readdir(path: string): Promise<string[]> {\n const specialError = getSpecialPathError(path, \"readdir\");\n if (specialError) throw specialError;\n const entries = await fs.readdir(path);\n return entries.map(String);\n },\n\n async stat(path: string): Promise<FileStat> {\n const specialStat = statSpecialFile(path);\n if (specialStat) return specialStat;\n const stats = await fs.stat(path);\n return {\n isFile: () => stats.isFile(),\n isDirectory: () => stats.isDirectory(),\n size: Number(stats.size),\n mtime: new Date(stats.mtime),\n mtimeMs: Number((stats as { mtimeMs?: number }).mtimeMs ?? stats.mtime),\n };\n },\n\n async exists(path: string): Promise<boolean> {\n const specialExists = existsSpecialFile(path);\n if (specialExists !== undefined) return specialExists;\n try {\n await fs.stat(path);\n return true;\n } catch {\n return false;\n }\n },\n\n async writeFile(path: string, data: Buffer | string): Promise<void> {\n if (discardsSpecialFileWrites(path)) {\n return;\n }\n await fs.writeFile(path, data);\n },\n\n async appendFile(path: string, data: Buffer | string): Promise<void> {\n if (discardsSpecialFileWrites(path)) {\n return;\n }\n await fs.appendFile(path, data);\n },\n\n async writeStream(path: string, opts?: { append?: boolean }): Promise<VirtualFSWritable> {\n if (discardsSpecialFileWrites(path)) {\n return createDiscardingWritable();\n }\n\n const chunks: Uint8Array[] = [];\n let closed = false;\n\n return {\n async write(chunk: Uint8Array): Promise<void> {\n if (closed) {\n throw new Error(\"stream is closed\");\n }\n chunks.push(Buffer.from(chunk));\n },\n async close(): Promise<void> {\n if (closed) return;\n closed = true;\n const data = Buffer.concat(chunks.map((chunk) => Buffer.from(chunk)));\n if (opts?.append) {\n await fs.appendFile(path, data);\n } else {\n await fs.writeFile(path, data);\n }\n },\n async abort(_reason?: unknown): Promise<void> {\n closed = true;\n chunks.length = 0;\n },\n };\n },\n\n async mkdir(path: string, opts?: { recursive?: boolean }): Promise<void> {\n const specialError = getSpecialPathError(path, \"mkdir\");\n if (specialError) throw specialError;\n await fs.mkdir(path, opts);\n },\n\n async rm(path: string, opts?: { recursive?: boolean; force?: boolean }): Promise<void> {\n const specialError = getSpecialPathError(path, \"rm\");\n if (specialError) throw specialError;\n try {\n const stats = await fs.stat(path);\n if (stats.isDirectory()) {\n await fs.rmdir(path, { recursive: opts?.recursive });\n } else {\n await fs.unlink(path);\n }\n } catch (err) {\n if (!opts?.force) throw err;\n }\n },\n\n resolve(...paths: string[]): string {\n return pathModule.resolve(...paths);\n },\n\n dirname(path: string): string {\n return pathModule.dirname(path);\n },\n\n basename(path: string): string {\n return pathModule.basename(path);\n },\n\n async glob(pattern: string, opts?: { cwd?: string }): Promise<string[]> {\n const cwd = opts?.cwd ?? \"/\";\n return globVirtualFS(\n {\n readdir: (filePath: string) => this.readdir(filePath),\n stat: (filePath: string) => this.stat(filePath),\n resolve: (...paths: string[]) => this.resolve(...paths),\n },\n pattern,\n { cwd }\n );\n },\n };\n}\n\nfunction emptyIterable(): AsyncIterable<Uint8Array> {\n return {\n async *[Symbol.asyncIterator]() {},\n };\n}\n\nfunction createDiscardingWritable(): VirtualFSWritable {\n return {\n async write(_chunk: Uint8Array): Promise<void> {},\n async close(): Promise<void> {},\n async abort(_reason?: unknown): Promise<void> {},\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAEA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAEA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,SAAS,eAAe,CAAC,OAAuB;AAAA,EACrD,QAAQ,UAAU,OAAO;AAAA,EAEzB,OAAO;AAAA,IACL,UAAW,OAAO,MAAc,aAAwD;AAAA,MACtF,MAAM,iBAAiB,gBAAgB,MAAM,QAAQ;AAAA,MACrD,IAAI,mBAAmB;AAAA,QAAW,OAAO;AAAA,MACzC,MAAM,UAAU,MAAM,GAAG,SAAS,IAAI;AAAA,MACtC,MAAM,MAAM,OAAO,KAAK,OAAO;AAAA,MAC/B,OAAO,WAAW,IAAI,SAAS,QAAQ,IAAI;AAAA;AAAA,IAG7C,UAAU,CAAC,MAAyC;AAAA,MAClD,IAAI,cAAc,IAAI,GAAG;AAAA,QACvB,OAAO,cAAc;AAAA,MACvB;AAAA,MACA,OAAO;AAAA,gBACG,OAAO,cAAc,GAAG;AAAA,UAC9B,MAAM,UAAU,MAAM,GAAG,SAAS,IAAI;AAAA,UACt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tB,OAAO,KAAK;AAAA,QACZ,IAAI,CAAC,MAAM;AAAA,UAAO,MAAM;AAAA;AAAA;AAAA,IAI5B,OAAO,IAAI,OAAyB;AAAA,MAClC,OAAkB,mBAAQ,GAAG,KAAK;AAAA;AAAA,IAGpC,OAAO,CAAC,MAAsB;AAAA,MAC5B,OAAkB,mBAAQ,IAAI;AAAA;AAAA,IAGhC,QAAQ,CAAC,MAAsB;AAAA,MAC7B,OAAkB,oBAAS,IAAI;AAAA;AAAA,SAG3B,KAAI,CAAC,SAAiB,MAA4C;AAAA,MACtE,MAAM,MAAM,MAAM,OAAO;AAAA,MACzB,OAAO,cACL;AAAA,QACE,SAAS,CAAC,aAAqB,KAAK,QAAQ,QAAQ;AAAA,QACpD,MAAM,CAAC,aAAqB,KAAK,KAAK,QAAQ;AAAA,QAC9C,SAAS,IAAI,UAAoB,KAAK,QAAQ,GAAG,KAAK;AAAA,MACxD,GACA,SACA,EAAE,IAAI,CACR;AAAA;AAAA,EAEJ;AAAA;AAGF,SAAS,aAAa,GAA8B;AAAA,EAClD,OAAO;AAAA,YACG,OAAO,cAAc,GAAG;AAAA,EAClC;AAAA;AAGF,SAAS,wBAAwB,GAAsB;AAAA,EACrD,OAAO;AAAA,SACC,MAAK,CAAC,QAAmC;AAAA,SACzC,MAAK,GAAkB;AAAA,SACvB,MAAK,CAAC,SAAkC;AAAA,EAChD;AAAA;",
|
|
8
|
+
"debugId": "D1AA4DE00C9BA29964756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
// src/fs/real-fs.ts
|
|
2
2
|
import * as path from "path";
|
|
3
|
+
import * as nodeStreamFs from "node:fs";
|
|
3
4
|
import * as nodeFs from "node:fs/promises";
|
|
4
5
|
import { globVirtualFS } from "../utils/glob.mjs";
|
|
5
6
|
import {
|
|
6
7
|
discardsSpecialFileWrites,
|
|
7
8
|
existsSpecialFile,
|
|
8
9
|
getSpecialPathError,
|
|
10
|
+
isDevNullPath,
|
|
9
11
|
readSpecialFile,
|
|
10
12
|
statSpecialFile
|
|
11
13
|
} from "./special-files.mjs";
|
|
12
|
-
var defaultFS = {
|
|
14
|
+
var defaultFS = {
|
|
15
|
+
promises: nodeFs,
|
|
16
|
+
streams: {
|
|
17
|
+
createReadStream(realPath) {
|
|
18
|
+
return createNodeReadIterable(realPath);
|
|
19
|
+
},
|
|
20
|
+
createWriteStream(realPath, opts) {
|
|
21
|
+
return createNodeWritable(realPath, opts);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
13
25
|
var nodePathOps = {
|
|
14
26
|
separator: path.sep,
|
|
15
27
|
resolve: (...paths) => path.resolve(...paths),
|
|
@@ -117,6 +129,18 @@ class FileSystem {
|
|
|
117
129
|
const buf = Buffer.from(content);
|
|
118
130
|
return encoding ? buf.toString(encoding) : buf;
|
|
119
131
|
}
|
|
132
|
+
readStream(filePath) {
|
|
133
|
+
if (isDevNullPath(filePath)) {
|
|
134
|
+
return emptyIterable();
|
|
135
|
+
}
|
|
136
|
+
this.checkPermission(filePath, "read");
|
|
137
|
+
const realPath = this.resolveSafePath(filePath);
|
|
138
|
+
const nativeStream = this.underlyingFs.streams?.createReadStream?.(realPath);
|
|
139
|
+
if (nativeStream) {
|
|
140
|
+
return normalizeChunks(nativeStream);
|
|
141
|
+
}
|
|
142
|
+
return bufferToIterable(this.readFile(filePath));
|
|
143
|
+
}
|
|
120
144
|
async readdir(dirPath) {
|
|
121
145
|
const specialError = getSpecialPathError(dirPath, "readdir");
|
|
122
146
|
if (specialError) {
|
|
@@ -139,7 +163,8 @@ class FileSystem {
|
|
|
139
163
|
isFile: () => stats.isFile(),
|
|
140
164
|
isDirectory: () => stats.isDirectory(),
|
|
141
165
|
size: stats.size,
|
|
142
|
-
mtime: stats.mtime
|
|
166
|
+
mtime: stats.mtime,
|
|
167
|
+
mtimeMs: stats.mtimeMs ?? stats.mtime.getTime()
|
|
143
168
|
};
|
|
144
169
|
}
|
|
145
170
|
async exists(filePath) {
|
|
@@ -172,6 +197,24 @@ class FileSystem {
|
|
|
172
197
|
const realPath = this.resolveSafePath(filePath);
|
|
173
198
|
await this.underlyingFs.promises.appendFile(realPath, data);
|
|
174
199
|
}
|
|
200
|
+
async writeStream(filePath, opts) {
|
|
201
|
+
if (discardsSpecialFileWrites(filePath)) {
|
|
202
|
+
return createDiscardingWritable();
|
|
203
|
+
}
|
|
204
|
+
this.checkPermission(filePath, "write");
|
|
205
|
+
const realPath = this.resolveSafePath(filePath);
|
|
206
|
+
const nativeWriter = this.underlyingFs.streams?.createWriteStream?.(realPath, opts);
|
|
207
|
+
if (nativeWriter) {
|
|
208
|
+
return nativeWriter;
|
|
209
|
+
}
|
|
210
|
+
return createBufferedWritable(async (buffer) => {
|
|
211
|
+
if (opts?.append) {
|
|
212
|
+
await this.underlyingFs.promises.appendFile(realPath, buffer);
|
|
213
|
+
} else {
|
|
214
|
+
await this.underlyingFs.promises.writeFile(realPath, buffer);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
175
218
|
async mkdir(dirPath, opts) {
|
|
176
219
|
const specialError = getSpecialPathError(dirPath, "mkdir");
|
|
177
220
|
if (specialError) {
|
|
@@ -205,8 +248,97 @@ class FileSystem {
|
|
|
205
248
|
return globVirtualFS(this, pattern, { cwd });
|
|
206
249
|
}
|
|
207
250
|
}
|
|
251
|
+
function emptyIterable() {
|
|
252
|
+
return {
|
|
253
|
+
async* [Symbol.asyncIterator]() {}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function bufferToIterable(bufferPromise) {
|
|
257
|
+
return {
|
|
258
|
+
async* [Symbol.asyncIterator]() {
|
|
259
|
+
const buffer = await bufferPromise;
|
|
260
|
+
yield buffer;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
async function* normalizeChunks(source) {
|
|
265
|
+
for await (const chunk of source) {
|
|
266
|
+
yield chunk instanceof Uint8Array ? chunk : new Uint8Array(chunk);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function createDiscardingWritable() {
|
|
270
|
+
return {
|
|
271
|
+
async write(_chunk) {},
|
|
272
|
+
async close() {},
|
|
273
|
+
async abort(_reason) {}
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function createBufferedWritable(onClose) {
|
|
277
|
+
const chunks = [];
|
|
278
|
+
let closed = false;
|
|
279
|
+
return {
|
|
280
|
+
async write(chunk) {
|
|
281
|
+
if (closed) {
|
|
282
|
+
throw new Error("stream is closed");
|
|
283
|
+
}
|
|
284
|
+
chunks.push(Buffer.from(chunk));
|
|
285
|
+
},
|
|
286
|
+
async close() {
|
|
287
|
+
if (closed)
|
|
288
|
+
return;
|
|
289
|
+
closed = true;
|
|
290
|
+
await onClose(Buffer.concat(chunks.map((chunk) => Buffer.from(chunk))));
|
|
291
|
+
},
|
|
292
|
+
async abort(_reason) {
|
|
293
|
+
closed = true;
|
|
294
|
+
chunks.length = 0;
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
async function* createNodeReadIterable(realPath) {
|
|
299
|
+
const stream = nodeStreamFs.createReadStream(realPath);
|
|
300
|
+
for await (const chunk of stream) {
|
|
301
|
+
yield Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function createNodeWritable(realPath, opts) {
|
|
305
|
+
const stream = nodeStreamFs.createWriteStream(realPath, {
|
|
306
|
+
flags: opts?.append ? "a" : "w"
|
|
307
|
+
});
|
|
308
|
+
const ready = new Promise((resolve2, reject) => {
|
|
309
|
+
stream.once("open", () => resolve2());
|
|
310
|
+
stream.once("error", reject);
|
|
311
|
+
});
|
|
312
|
+
return {
|
|
313
|
+
async write(chunk) {
|
|
314
|
+
await ready;
|
|
315
|
+
await new Promise((resolve2, reject) => {
|
|
316
|
+
stream.write(chunk, (error) => {
|
|
317
|
+
if (error)
|
|
318
|
+
reject(error);
|
|
319
|
+
else
|
|
320
|
+
resolve2();
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
async close() {
|
|
325
|
+
await ready;
|
|
326
|
+
await new Promise((resolve2, reject) => {
|
|
327
|
+
stream.end((error) => {
|
|
328
|
+
if (error)
|
|
329
|
+
reject(error);
|
|
330
|
+
else
|
|
331
|
+
resolve2();
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
},
|
|
335
|
+
async abort(reason) {
|
|
336
|
+
stream.destroy(reason instanceof Error ? reason : undefined);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
}
|
|
208
340
|
export {
|
|
209
341
|
FileSystem
|
|
210
342
|
};
|
|
211
343
|
|
|
212
|
-
//# debugId=
|
|
344
|
+
//# debugId=4D82D1C6073DF96D64756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/fs/real-fs.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import * as path from \"path\";\nimport * as nodeFs from \"node:fs/promises\";\nimport type { VirtualFS, FileStat } from \"../types.mjs\";\nimport { globVirtualFS } from \"../utils/glob.mjs\";\nimport {\n discardsSpecialFileWrites,\n existsSpecialFile,\n getSpecialPathError,\n readSpecialFile,\n statSpecialFile,\n} from \"./special-files.mjs\";\n\nexport type Permission = \"read-write\" | \"read-only\" | \"excluded\";\nexport type PermissionRules = Record<string, Permission>;\nexport interface PathOps {\n readonly separator: string;\n resolve(...paths: string[]): string;\n normalize(path: string): string;\n join(...paths: string[]): string;\n relative(from: string, to: string): string;\n isAbsolute(path: string): boolean;\n dirname(path: string): string;\n basename(path: string): string;\n}\n\n// Minimal interface for the underlying fs (compatible with node:fs and memfs)\nexport interface UnderlyingFS {\n pathOps?: PathOps;\n promises: {\n readFile(path: string): Promise<Buffer | Uint8Array | string>;\n readdir(path: string): Promise<string[]>;\n stat(path: string): Promise<{\n isFile(): boolean;\n isDirectory(): boolean;\n size: number;\n mtime: Date;\n }>;\n writeFile(path: string, data: Buffer | string): Promise<void>;\n appendFile(path: string, data: Buffer | string): Promise<void>;\n mkdir(path: string, opts?: { recursive?: boolean }): Promise<string | undefined | void>;\n rm(path: string, opts?: { recursive?: boolean; force?: boolean }): Promise<void>;\n };\n}\n\n// Default: use real node:fs\nconst defaultFS: UnderlyingFS = { promises: nodeFs };\nconst nodePathOps: PathOps = {\n separator: path.sep,\n resolve: (...paths) => path.resolve(...paths),\n normalize: (filePath) => path.normalize(filePath),\n join: (...paths) => path.join(...paths),\n relative: (from, to) => path.relative(from, to),\n isAbsolute: (filePath) => path.isAbsolute(filePath),\n dirname: (filePath) => path.dirname(filePath),\n basename: (filePath) => path.basename(filePath),\n};\n\ninterface CompiledRule {\n pattern: string;\n permission: Permission;\n specificity: number;\n}\n\nexport class FileSystem implements VirtualFS {\n private readonly mountBase: string | null;\n private readonly rules: CompiledRule[];\n private readonly pathOps: PathOps;\n protected readonly underlyingFs: UnderlyingFS;\n\n constructor(mountPath?: string, permissions?: PermissionRules, fs?: UnderlyingFS) {\n const underlyingFs = fs ?? defaultFS;\n this.pathOps = underlyingFs.pathOps ?? nodePathOps;\n this.mountBase = mountPath ? this.pathOps.resolve(mountPath) : null;\n this.rules = this.compileRules(permissions ?? {});\n this.underlyingFs = underlyingFs;\n }\n\n private compileRules(permissions: PermissionRules): CompiledRule[] {\n return Object.entries(permissions)\n .map(([pattern, permission]) => ({\n pattern,\n permission,\n specificity: this.calculateSpecificity(pattern),\n }))\n .sort((a, b) => b.specificity - a.specificity); // highest first\n }\n\n private calculateSpecificity(pattern: string): number {\n const segments = pattern.split(\"/\").filter(Boolean);\n let score = segments.length * 1000; // segment count is primary\n\n for (const seg of segments) {\n if (seg === \"**\") score += 0;\n else if (seg.includes(\"*\")) score += 1;\n else score += 10; // literal segment\n }\n return score;\n }\n\n public getPermission(virtualPath: string): Permission {\n const normalized = virtualPath.replace(/^\\/+/, \"\"); // strip leading slashes\n\n for (const rule of this.rules) {\n if (this.matchGlob(rule.pattern, normalized)) {\n return rule.permission;\n }\n }\n return \"read-write\"; // default\n }\n\n private matchGlob(pattern: string, filePath: string): boolean {\n // Convert glob to regex\n // ** matches any path segments, * matches within segment\n const regex = pattern\n .split(\"/\")\n .map((seg) => {\n if (seg === \"**\") return \".*\";\n return seg.replace(/\\*/g, \"[^/]*\").replace(/\\?/g, \"[^/]\");\n })\n .join(\"/\");\n return new RegExp(`^${regex}$`).test(filePath);\n }\n\n public checkPermission(virtualPath: string, operation: \"read\" | \"write\"): void {\n const perm = this.getPermission(virtualPath);\n\n if (perm === \"excluded\") {\n throw new Error(`Access denied: \"${virtualPath}\" is excluded`);\n }\n if (operation === \"write\" && perm === \"read-only\") {\n throw new Error(`Access denied: \"${virtualPath}\" is read-only`);\n }\n }\n\n private resolveSafePath(virtualPath: string): string {\n if (this.mountBase === null) {\n return this.pathOps.resolve(virtualPath);\n }\n\n // Check for path traversal by tracking depth\n const segments = virtualPath.split(\"/\").filter(Boolean);\n let depth = 0;\n for (const seg of segments) {\n if (seg === \"..\") {\n depth--;\n if (depth < 0) {\n throw new Error(`Path traversal blocked: \"${virtualPath}\" escapes mount point`);\n }\n } else if (seg !== \".\") {\n depth++;\n }\n }\n\n const normalized = this.pathOps.normalize(virtualPath);\n const relativePath = normalized.startsWith(\"/\") ? normalized.slice(1) : normalized;\n const realPath = this.pathOps.join(this.mountBase, relativePath);\n const resolved = this.pathOps.resolve(realPath);\n\n // Double-check containment (defense in depth), including root mounts.\n const relativeFromMount = this.pathOps.relative(this.mountBase, resolved);\n const escapesMount =\n relativeFromMount === \"..\" ||\n relativeFromMount.startsWith(`..${this.pathOps.separator}`) ||\n this.pathOps.isAbsolute(relativeFromMount);\n if (escapesMount) {\n throw new Error(`Path traversal blocked: \"${virtualPath}\" escapes mount point`);\n }\n\n return resolved;\n }\n\n // Read operations\n async readFile(filePath: string): Promise<Buffer>;\n async readFile(filePath: string, encoding: BufferEncoding): Promise<string>;\n async readFile(filePath: string, encoding?: BufferEncoding): Promise<Buffer | string> {\n const specialContent = readSpecialFile(filePath, encoding);\n if (specialContent !== undefined) {\n return specialContent;\n }\n this.checkPermission(filePath, \"read\");\n const realPath = this.resolveSafePath(filePath);\n const content = await this.underlyingFs.promises.readFile(realPath);\n const buf = Buffer.from(content);\n return encoding ? buf.toString(encoding) : buf;\n }\n\n async readdir(dirPath: string): Promise<string[]> {\n const specialError = getSpecialPathError(dirPath, \"readdir\");\n if (specialError) {\n throw specialError;\n }\n this.checkPermission(dirPath, \"read\");\n const realPath = this.resolveSafePath(dirPath);\n const entries = await this.underlyingFs.promises.readdir(realPath);\n return entries.map(String);\n }\n\n async stat(filePath: string): Promise<FileStat> {\n const specialStat = statSpecialFile(filePath);\n if (specialStat) {\n return specialStat;\n }\n this.checkPermission(filePath, \"read\");\n const realPath = this.resolveSafePath(filePath);\n const stats = await this.underlyingFs.promises.stat(realPath);\n return {\n isFile: () => stats.isFile(),\n isDirectory: () => stats.isDirectory(),\n size: stats.size,\n mtime: stats.mtime,\n };\n }\n\n async exists(filePath: string): Promise<boolean> {\n const specialExists = existsSpecialFile(filePath);\n if (specialExists !== undefined) {\n return specialExists;\n }\n try {\n this.checkPermission(filePath, \"read\");\n const realPath = this.resolveSafePath(filePath);\n await this.underlyingFs.promises.stat(realPath);\n return true;\n } catch {\n return false;\n }\n }\n\n // Write operations\n async writeFile(filePath: string, data: Buffer | string): Promise<void> {\n if (discardsSpecialFileWrites(filePath)) {\n return;\n }\n this.checkPermission(filePath, \"write\");\n const realPath = this.resolveSafePath(filePath);\n await this.underlyingFs.promises.writeFile(realPath, data);\n }\n\n async appendFile(filePath: string, data: Buffer | string): Promise<void> {\n if (discardsSpecialFileWrites(filePath)) {\n return;\n }\n this.checkPermission(filePath, \"write\");\n const realPath = this.resolveSafePath(filePath);\n await this.underlyingFs.promises.appendFile(realPath, data);\n }\n\n async mkdir(dirPath: string, opts?: { recursive?: boolean }): Promise<void> {\n const specialError = getSpecialPathError(dirPath, \"mkdir\");\n if (specialError) {\n throw specialError;\n }\n this.checkPermission(dirPath, \"write\");\n const realPath = this.resolveSafePath(dirPath);\n await this.underlyingFs.promises.mkdir(realPath, opts);\n }\n\n async rm(filePath: string, opts?: { recursive?: boolean; force?: boolean }): Promise<void> {\n const specialError = getSpecialPathError(filePath, \"rm\");\n if (specialError) {\n throw specialError;\n }\n this.checkPermission(filePath, \"write\");\n const realPath = this.resolveSafePath(filePath);\n await this.underlyingFs.promises.rm(realPath, opts);\n }\n\n // Path utilities (no permission check needed)\n resolve(...paths: string[]): string {\n return this.pathOps.resolve(\"/\", ...paths);\n }\n\n dirname(filePath: string): string {\n return this.pathOps.dirname(filePath);\n }\n\n basename(filePath: string): string {\n return this.pathOps.basename(filePath);\n }\n\n // Glob expansion\n async glob(pattern: string, opts?: { cwd?: string }): Promise<string[]> {\n const cwd = opts?.cwd ?? \"/\";\n this.checkPermission(cwd, \"read\");\n return globVirtualFS(this, pattern, { cwd });\n }\n}\n"
|
|
5
|
+
"import * as path from \"path\";\nimport * as nodeStreamFs from \"node:fs\";\nimport * as nodeFs from \"node:fs/promises\";\nimport type { VirtualFS, VirtualFSWritable, FileStat } from \"../types.mjs\";\nimport { globVirtualFS } from \"../utils/glob.mjs\";\nimport {\n discardsSpecialFileWrites,\n existsSpecialFile,\n getSpecialPathError,\n isDevNullPath,\n readSpecialFile,\n statSpecialFile,\n} from \"./special-files.mjs\";\n\nexport type Permission = \"read-write\" | \"read-only\" | \"excluded\";\nexport type PermissionRules = Record<string, Permission>;\nexport interface PathOps {\n readonly separator: string;\n resolve(...paths: string[]): string;\n normalize(path: string): string;\n join(...paths: string[]): string;\n relative(from: string, to: string): string;\n isAbsolute(path: string): boolean;\n dirname(path: string): string;\n basename(path: string): string;\n}\n\n// Minimal interface for the underlying fs (compatible with node:fs and memfs)\nexport interface UnderlyingFS {\n pathOps?: PathOps;\n promises: {\n readFile(path: string): Promise<Buffer | Uint8Array | string>;\n readdir(path: string): Promise<string[]>;\n stat(path: string): Promise<{\n isFile(): boolean;\n isDirectory(): boolean;\n size: number;\n mtime: Date;\n mtimeMs?: number;\n }>;\n writeFile(path: string, data: Buffer | string): Promise<void>;\n appendFile(path: string, data: Buffer | string): Promise<void>;\n mkdir(path: string, opts?: { recursive?: boolean }): Promise<string | undefined | void>;\n rm(path: string, opts?: { recursive?: boolean; force?: boolean }): Promise<void>;\n };\n streams?: {\n createReadStream?(path: string): AsyncIterable<Uint8Array>;\n createWriteStream?(\n path: string,\n opts?: { append?: boolean },\n ): Promise<VirtualFSWritable> | VirtualFSWritable;\n };\n}\n\n// Default: use real node:fs\nconst defaultFS: UnderlyingFS = {\n promises: nodeFs,\n streams: {\n createReadStream(realPath: string): AsyncIterable<Uint8Array> {\n return createNodeReadIterable(realPath);\n },\n createWriteStream(realPath: string, opts?: { append?: boolean }): VirtualFSWritable {\n return createNodeWritable(realPath, opts);\n },\n },\n};\nconst nodePathOps: PathOps = {\n separator: path.sep,\n resolve: (...paths) => path.resolve(...paths),\n normalize: (filePath) => path.normalize(filePath),\n join: (...paths) => path.join(...paths),\n relative: (from, to) => path.relative(from, to),\n isAbsolute: (filePath) => path.isAbsolute(filePath),\n dirname: (filePath) => path.dirname(filePath),\n basename: (filePath) => path.basename(filePath),\n};\n\ninterface CompiledRule {\n pattern: string;\n permission: Permission;\n specificity: number;\n}\n\nexport class FileSystem implements VirtualFS {\n private readonly mountBase: string | null;\n private readonly rules: CompiledRule[];\n private readonly pathOps: PathOps;\n protected readonly underlyingFs: UnderlyingFS;\n\n constructor(mountPath?: string, permissions?: PermissionRules, fs?: UnderlyingFS) {\n const underlyingFs = fs ?? defaultFS;\n this.pathOps = underlyingFs.pathOps ?? nodePathOps;\n this.mountBase = mountPath ? this.pathOps.resolve(mountPath) : null;\n this.rules = this.compileRules(permissions ?? {});\n this.underlyingFs = underlyingFs;\n }\n\n private compileRules(permissions: PermissionRules): CompiledRule[] {\n return Object.entries(permissions)\n .map(([pattern, permission]) => ({\n pattern,\n permission,\n specificity: this.calculateSpecificity(pattern),\n }))\n .sort((a, b) => b.specificity - a.specificity); // highest first\n }\n\n private calculateSpecificity(pattern: string): number {\n const segments = pattern.split(\"/\").filter(Boolean);\n let score = segments.length * 1000; // segment count is primary\n\n for (const seg of segments) {\n if (seg === \"**\") score += 0;\n else if (seg.includes(\"*\")) score += 1;\n else score += 10; // literal segment\n }\n return score;\n }\n\n public getPermission(virtualPath: string): Permission {\n const normalized = virtualPath.replace(/^\\/+/, \"\"); // strip leading slashes\n\n for (const rule of this.rules) {\n if (this.matchGlob(rule.pattern, normalized)) {\n return rule.permission;\n }\n }\n return \"read-write\"; // default\n }\n\n private matchGlob(pattern: string, filePath: string): boolean {\n // Convert glob to regex\n // ** matches any path segments, * matches within segment\n const regex = pattern\n .split(\"/\")\n .map((seg) => {\n if (seg === \"**\") return \".*\";\n return seg.replace(/\\*/g, \"[^/]*\").replace(/\\?/g, \"[^/]\");\n })\n .join(\"/\");\n return new RegExp(`^${regex}$`).test(filePath);\n }\n\n public checkPermission(virtualPath: string, operation: \"read\" | \"write\"): void {\n const perm = this.getPermission(virtualPath);\n\n if (perm === \"excluded\") {\n throw new Error(`Access denied: \"${virtualPath}\" is excluded`);\n }\n if (operation === \"write\" && perm === \"read-only\") {\n throw new Error(`Access denied: \"${virtualPath}\" is read-only`);\n }\n }\n\n private resolveSafePath(virtualPath: string): string {\n if (this.mountBase === null) {\n return this.pathOps.resolve(virtualPath);\n }\n\n // Check for path traversal by tracking depth\n const segments = virtualPath.split(\"/\").filter(Boolean);\n let depth = 0;\n for (const seg of segments) {\n if (seg === \"..\") {\n depth--;\n if (depth < 0) {\n throw new Error(`Path traversal blocked: \"${virtualPath}\" escapes mount point`);\n }\n } else if (seg !== \".\") {\n depth++;\n }\n }\n\n const normalized = this.pathOps.normalize(virtualPath);\n const relativePath = normalized.startsWith(\"/\") ? normalized.slice(1) : normalized;\n const realPath = this.pathOps.join(this.mountBase, relativePath);\n const resolved = this.pathOps.resolve(realPath);\n\n // Double-check containment (defense in depth), including root mounts.\n const relativeFromMount = this.pathOps.relative(this.mountBase, resolved);\n const escapesMount =\n relativeFromMount === \"..\" ||\n relativeFromMount.startsWith(`..${this.pathOps.separator}`) ||\n this.pathOps.isAbsolute(relativeFromMount);\n if (escapesMount) {\n throw new Error(`Path traversal blocked: \"${virtualPath}\" escapes mount point`);\n }\n\n return resolved;\n }\n\n // Read operations\n async readFile(filePath: string): Promise<Buffer>;\n async readFile(filePath: string, encoding: BufferEncoding): Promise<string>;\n async readFile(filePath: string, encoding?: BufferEncoding): Promise<Buffer | string> {\n const specialContent = readSpecialFile(filePath, encoding);\n if (specialContent !== undefined) {\n return specialContent;\n }\n this.checkPermission(filePath, \"read\");\n const realPath = this.resolveSafePath(filePath);\n const content = await this.underlyingFs.promises.readFile(realPath);\n const buf = Buffer.from(content);\n return encoding ? buf.toString(encoding) : buf;\n }\n\n readStream(filePath: string): AsyncIterable<Uint8Array> {\n if (isDevNullPath(filePath)) {\n return emptyIterable();\n }\n this.checkPermission(filePath, \"read\");\n const realPath = this.resolveSafePath(filePath);\n const nativeStream = this.underlyingFs.streams?.createReadStream?.(realPath);\n if (nativeStream) {\n return normalizeChunks(nativeStream);\n }\n return bufferToIterable(this.readFile(filePath) as Promise<Buffer>);\n }\n\n async readdir(dirPath: string): Promise<string[]> {\n const specialError = getSpecialPathError(dirPath, \"readdir\");\n if (specialError) {\n throw specialError;\n }\n this.checkPermission(dirPath, \"read\");\n const realPath = this.resolveSafePath(dirPath);\n const entries = await this.underlyingFs.promises.readdir(realPath);\n return entries.map(String);\n }\n\n async stat(filePath: string): Promise<FileStat> {\n const specialStat = statSpecialFile(filePath);\n if (specialStat) {\n return specialStat;\n }\n this.checkPermission(filePath, \"read\");\n const realPath = this.resolveSafePath(filePath);\n const stats = await this.underlyingFs.promises.stat(realPath);\n return {\n isFile: () => stats.isFile(),\n isDirectory: () => stats.isDirectory(),\n size: stats.size,\n mtime: stats.mtime,\n mtimeMs: stats.mtimeMs ?? stats.mtime.getTime(),\n };\n }\n\n async exists(filePath: string): Promise<boolean> {\n const specialExists = existsSpecialFile(filePath);\n if (specialExists !== undefined) {\n return specialExists;\n }\n try {\n this.checkPermission(filePath, \"read\");\n const realPath = this.resolveSafePath(filePath);\n await this.underlyingFs.promises.stat(realPath);\n return true;\n } catch {\n return false;\n }\n }\n\n // Write operations\n async writeFile(filePath: string, data: Buffer | string): Promise<void> {\n if (discardsSpecialFileWrites(filePath)) {\n return;\n }\n this.checkPermission(filePath, \"write\");\n const realPath = this.resolveSafePath(filePath);\n await this.underlyingFs.promises.writeFile(realPath, data);\n }\n\n async appendFile(filePath: string, data: Buffer | string): Promise<void> {\n if (discardsSpecialFileWrites(filePath)) {\n return;\n }\n this.checkPermission(filePath, \"write\");\n const realPath = this.resolveSafePath(filePath);\n await this.underlyingFs.promises.appendFile(realPath, data);\n }\n\n async writeStream(filePath: string, opts?: { append?: boolean }): Promise<VirtualFSWritable> {\n if (discardsSpecialFileWrites(filePath)) {\n return createDiscardingWritable();\n }\n this.checkPermission(filePath, \"write\");\n const realPath = this.resolveSafePath(filePath);\n const nativeWriter = this.underlyingFs.streams?.createWriteStream?.(realPath, opts);\n if (nativeWriter) {\n return nativeWriter;\n }\n return createBufferedWritable(async (buffer) => {\n if (opts?.append) {\n await this.underlyingFs.promises.appendFile(realPath, buffer);\n } else {\n await this.underlyingFs.promises.writeFile(realPath, buffer);\n }\n });\n }\n\n async mkdir(dirPath: string, opts?: { recursive?: boolean }): Promise<void> {\n const specialError = getSpecialPathError(dirPath, \"mkdir\");\n if (specialError) {\n throw specialError;\n }\n this.checkPermission(dirPath, \"write\");\n const realPath = this.resolveSafePath(dirPath);\n await this.underlyingFs.promises.mkdir(realPath, opts);\n }\n\n async rm(filePath: string, opts?: { recursive?: boolean; force?: boolean }): Promise<void> {\n const specialError = getSpecialPathError(filePath, \"rm\");\n if (specialError) {\n throw specialError;\n }\n this.checkPermission(filePath, \"write\");\n const realPath = this.resolveSafePath(filePath);\n await this.underlyingFs.promises.rm(realPath, opts);\n }\n\n // Path utilities (no permission check needed)\n resolve(...paths: string[]): string {\n return this.pathOps.resolve(\"/\", ...paths);\n }\n\n dirname(filePath: string): string {\n return this.pathOps.dirname(filePath);\n }\n\n basename(filePath: string): string {\n return this.pathOps.basename(filePath);\n }\n\n // Glob expansion\n async glob(pattern: string, opts?: { cwd?: string }): Promise<string[]> {\n const cwd = opts?.cwd ?? \"/\";\n this.checkPermission(cwd, \"read\");\n return globVirtualFS(this, pattern, { cwd });\n }\n}\n\nfunction emptyIterable(): AsyncIterable<Uint8Array> {\n return {\n async *[Symbol.asyncIterator]() {},\n };\n}\n\nfunction bufferToIterable(bufferPromise: Promise<Buffer>): AsyncIterable<Uint8Array> {\n return {\n async *[Symbol.asyncIterator]() {\n const buffer = await bufferPromise;\n yield buffer;\n },\n };\n}\n\nasync function* normalizeChunks(source: AsyncIterable<Uint8Array>): AsyncIterable<Uint8Array> {\n for await (const chunk of source) {\n yield chunk instanceof Uint8Array ? chunk : new Uint8Array(chunk);\n }\n}\n\nfunction createDiscardingWritable(): VirtualFSWritable {\n return {\n async write(_chunk: Uint8Array): Promise<void> {},\n async close(): Promise<void> {},\n async abort(_reason?: unknown): Promise<void> {},\n };\n}\n\nfunction createBufferedWritable(\n onClose: (buffer: Buffer) => Promise<void>,\n): VirtualFSWritable {\n const chunks: Uint8Array[] = [];\n let closed = false;\n\n return {\n async write(chunk: Uint8Array): Promise<void> {\n if (closed) {\n throw new Error(\"stream is closed\");\n }\n chunks.push(Buffer.from(chunk));\n },\n async close(): Promise<void> {\n if (closed) return;\n closed = true;\n await onClose(Buffer.concat(chunks.map((chunk) => Buffer.from(chunk))));\n },\n async abort(_reason?: unknown): Promise<void> {\n closed = true;\n chunks.length = 0;\n },\n };\n}\n\nasync function* createNodeReadIterable(realPath: string): AsyncIterable<Uint8Array> {\n const stream = nodeStreamFs.createReadStream(realPath);\n for await (const chunk of stream) {\n yield Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);\n }\n}\n\nfunction createNodeWritable(\n realPath: string,\n opts?: { append?: boolean },\n): VirtualFSWritable {\n const stream = nodeStreamFs.createWriteStream(realPath, {\n flags: opts?.append ? \"a\" : \"w\",\n });\n const ready = new Promise<void>((resolve, reject) => {\n stream.once(\"open\", () => resolve());\n stream.once(\"error\", reject);\n });\n\n return {\n async write(chunk: Uint8Array): Promise<void> {\n await ready;\n await new Promise<void>((resolve, reject) => {\n stream.write(chunk, (error) => {\n if (error) reject(error);\n else resolve();\n });\n });\n },\n async close(): Promise<void> {\n await ready;\n await new Promise<void>((resolve, reject) => {\n stream.end((error?: Error | null) => {\n if (error) reject(error);\n else resolve();\n });\n });\n },\n async abort(reason?: unknown): Promise<void> {\n stream.destroy(reason instanceof Error ? reason : undefined);\n },\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAAA;AACA;AAEA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAAA;AACA;AACA;AAEA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkDA,IAAM,YAA0B;AAAA,EAC9B,UAAU;AAAA,EACV,SAAS;AAAA,IACP,gBAAgB,CAAC,UAA6C;AAAA,MAC5D,OAAO,uBAAuB,QAAQ;AAAA;AAAA,IAExC,iBAAiB,CAAC,UAAkB,MAAgD;AAAA,MAClF,OAAO,mBAAmB,UAAU,IAAI;AAAA;AAAA,EAE5C;AACF;AACA,IAAM,cAAuB;AAAA,EAC3B,WAAgB;AAAA,EAChB,SAAS,IAAI,UAAe,aAAQ,GAAG,KAAK;AAAA,EAC5C,WAAW,CAAC,aAAkB,eAAU,QAAQ;AAAA,EAChD,MAAM,IAAI,UAAe,UAAK,GAAG,KAAK;AAAA,EACtC,UAAU,CAAC,MAAM,OAAY,cAAS,MAAM,EAAE;AAAA,EAC9C,YAAY,CAAC,aAAkB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B;AAAA,MAC3B,MAAM;AAAA,MACN,MAAM,IAAI,QAAc,CAAC,UAAS,WAAW;AAAA,QAC3C,OAAO,IAAI,CAAC,UAAyB;AAAA,UACnC,IAAI;AAAA,YAAO,OAAO,KAAK;AAAA,UAClB;AAAA,qBAAQ;AAAA,SACd;AAAA,OACF;AAAA;AAAA,SAEG,MAAK,CAAC,QAAiC;AAAA,MAC3C,OAAO,QAAQ,kBAAkB,QAAQ,SAAS,SAAS;AAAA;AAAA,EAE/D;AAAA;",
|
|
8
|
+
"debugId": "4D82D1C6073DF96D64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -20,7 +20,8 @@ function statSpecialFile(path) {
|
|
|
20
20
|
isFile: () => true,
|
|
21
21
|
isDirectory: () => false,
|
|
22
22
|
size: 0,
|
|
23
|
-
mtime: new Date(0)
|
|
23
|
+
mtime: new Date(0),
|
|
24
|
+
mtimeMs: 0
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
27
|
function existsSpecialFile(path) {
|
|
@@ -55,4 +56,4 @@ export {
|
|
|
55
56
|
DEV_NULL_PATH
|
|
56
57
|
};
|
|
57
58
|
|
|
58
|
-
//# debugId=
|
|
59
|
+
//# debugId=B26D9A26BDC0990864756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/fs/special-files.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { FileStat } from \"../types.mjs\";\n\nexport const DEV_NULL_PATH = \"/dev/null\";\n\nfunction normalizeSpecialPath(path: string): string {\n return path.replace(/\\\\/g, \"/\");\n}\n\nexport function isDevNullPath(path: string): boolean {\n return normalizeSpecialPath(path) === DEV_NULL_PATH;\n}\n\nexport function readSpecialFile(\n path: string,\n encoding?: BufferEncoding\n): Buffer | string | undefined {\n if (!isDevNullPath(path)) {\n return undefined;\n }\n\n return encoding ? \"\" : Buffer.alloc(0);\n}\n\nexport function statSpecialFile(path: string): FileStat | undefined {\n if (!isDevNullPath(path)) {\n return undefined;\n }\n\n return {\n isFile: () => true,\n isDirectory: () => false,\n size: 0,\n mtime: new Date(0),\n };\n}\n\nexport function existsSpecialFile(path: string): boolean | undefined {\n if (!isDevNullPath(path)) {\n return undefined;\n }\n\n return true;\n}\n\nexport function discardsSpecialFileWrites(path: string): boolean {\n return isDevNullPath(path);\n}\n\nexport function getSpecialPathError(\n path: string,\n operation: \"mkdir\" | \"readdir\" | \"rm\"\n): Error | undefined {\n if (!isDevNullPath(path)) {\n return undefined;\n }\n\n switch (operation) {\n case \"mkdir\":\n return new Error(`EEXIST: file already exists, mkdir '${DEV_NULL_PATH}'`);\n case \"readdir\":\n return new Error(`ENOTDIR: not a directory, scandir '${DEV_NULL_PATH}'`);\n case \"rm\":\n return new Error(`EPERM: operation not permitted, rm '${DEV_NULL_PATH}'`);\n }\n}\n"
|
|
5
|
+
"import type { FileStat } from \"../types.mjs\";\n\nexport const DEV_NULL_PATH = \"/dev/null\";\n\nfunction normalizeSpecialPath(path: string): string {\n return path.replace(/\\\\/g, \"/\");\n}\n\nexport function isDevNullPath(path: string): boolean {\n return normalizeSpecialPath(path) === DEV_NULL_PATH;\n}\n\nexport function readSpecialFile(\n path: string,\n encoding?: BufferEncoding\n): Buffer | string | undefined {\n if (!isDevNullPath(path)) {\n return undefined;\n }\n\n return encoding ? \"\" : Buffer.alloc(0);\n}\n\nexport function statSpecialFile(path: string): FileStat | undefined {\n if (!isDevNullPath(path)) {\n return undefined;\n }\n\n return {\n isFile: () => true,\n isDirectory: () => false,\n size: 0,\n mtime: new Date(0),\n mtimeMs: 0,\n };\n}\n\nexport function existsSpecialFile(path: string): boolean | undefined {\n if (!isDevNullPath(path)) {\n return undefined;\n }\n\n return true;\n}\n\nexport function discardsSpecialFileWrites(path: string): boolean {\n return isDevNullPath(path);\n}\n\nexport function getSpecialPathError(\n path: string,\n operation: \"mkdir\" | \"readdir\" | \"rm\"\n): Error | undefined {\n if (!isDevNullPath(path)) {\n return undefined;\n }\n\n switch (operation) {\n case \"mkdir\":\n return new Error(`EEXIST: file already exists, mkdir '${DEV_NULL_PATH}'`);\n case \"readdir\":\n return new Error(`ENOTDIR: not a directory, scandir '${DEV_NULL_PATH}'`);\n case \"rm\":\n return new Error(`EPERM: operation not permitted, rm '${DEV_NULL_PATH}'`);\n }\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAEO,IAAM,gBAAgB;AAE7B,SAAS,oBAAoB,CAAC,MAAsB;AAAA,EAClD,OAAO,KAAK,QAAQ,OAAO,GAAG;AAAA;AAGzB,SAAS,aAAa,CAAC,MAAuB;AAAA,EACnD,OAAO,qBAAqB,IAAI,MAAM;AAAA;AAGjC,SAAS,eAAe,CAC7B,MACA,UAC6B;AAAA,EAC7B,IAAI,CAAC,cAAc,IAAI,GAAG;AAAA,IACxB;AAAA,EACF;AAAA,EAEA,OAAO,WAAW,KAAK,OAAO,MAAM,CAAC;AAAA;AAGhC,SAAS,eAAe,CAAC,MAAoC;AAAA,EAClE,IAAI,CAAC,cAAc,IAAI,GAAG;AAAA,IACxB;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,aAAa,MAAM;AAAA,IACnB,MAAM;AAAA,IACN,OAAO,IAAI,KAAK,CAAC;AAAA,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAEO,IAAM,gBAAgB;AAE7B,SAAS,oBAAoB,CAAC,MAAsB;AAAA,EAClD,OAAO,KAAK,QAAQ,OAAO,GAAG;AAAA;AAGzB,SAAS,aAAa,CAAC,MAAuB;AAAA,EACnD,OAAO,qBAAqB,IAAI,MAAM;AAAA;AAGjC,SAAS,eAAe,CAC7B,MACA,UAC6B;AAAA,EAC7B,IAAI,CAAC,cAAc,IAAI,GAAG;AAAA,IACxB;AAAA,EACF;AAAA,EAEA,OAAO,WAAW,KAAK,OAAO,MAAM,CAAC;AAAA;AAGhC,SAAS,eAAe,CAAC,MAAoC;AAAA,EAClE,IAAI,CAAC,cAAc,IAAI,GAAG;AAAA,IACxB;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,aAAa,MAAM;AAAA,IACnB,MAAM;AAAA,IACN,OAAO,IAAI,KAAK,CAAC;AAAA,IACjB,SAAS;AAAA,EACX;AAAA;AAGK,SAAS,iBAAiB,CAAC,MAAmC;AAAA,EACnE,IAAI,CAAC,cAAc,IAAI,GAAG;AAAA,IACxB;AAAA,EACF;AAAA,EAEA,OAAO;AAAA;AAGF,SAAS,yBAAyB,CAAC,MAAuB;AAAA,EAC/D,OAAO,cAAc,IAAI;AAAA;AAGpB,SAAS,mBAAmB,CACjC,MACA,WACmB;AAAA,EACnB,IAAI,CAAC,cAAc,IAAI,GAAG;AAAA,IACxB;AAAA,EACF;AAAA,EAEA,QAAQ;AAAA,SACD;AAAA,MACH,OAAO,IAAI,MAAM,uCAAuC,gBAAgB;AAAA,SACrE;AAAA,MACH,OAAO,IAAI,MAAM,sCAAsC,gBAAgB;AAAA,SACpE;AAAA,MACH,OAAO,IAAI,MAAM,uCAAuC,gBAAgB;AAAA;AAAA;",
|
|
8
|
+
"debugId": "B26D9A26BDC0990864756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -81,7 +81,8 @@ function createWebUnderlyingFS(root) {
|
|
|
81
81
|
isFile: () => true,
|
|
82
82
|
isDirectory: () => false,
|
|
83
83
|
size: file.size,
|
|
84
|
-
mtime: new Date(file.lastModified ?? 0)
|
|
84
|
+
mtime: new Date(file.lastModified ?? 0),
|
|
85
|
+
mtimeMs: file.lastModified ?? 0
|
|
85
86
|
};
|
|
86
87
|
} catch (error) {
|
|
87
88
|
if (!isNotFoundOrTypeMismatch(error))
|
|
@@ -150,6 +151,57 @@ function createWebUnderlyingFS(root) {
|
|
|
150
151
|
throw error;
|
|
151
152
|
}
|
|
152
153
|
}
|
|
154
|
+
},
|
|
155
|
+
streams: {
|
|
156
|
+
createReadStream(path) {
|
|
157
|
+
return {
|
|
158
|
+
async* [Symbol.asyncIterator]() {
|
|
159
|
+
const { parentSegments, name } = splitParent(path);
|
|
160
|
+
const parent = await walkDirectory(root, parentSegments, false);
|
|
161
|
+
const fileHandle = await parent.getFileHandle(name, { create: false });
|
|
162
|
+
const file = await fileHandle.getFile();
|
|
163
|
+
for await (const chunk of streamToAsyncIterable(file.stream())) {
|
|
164
|
+
yield chunk;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
},
|
|
169
|
+
async createWriteStream(path, opts) {
|
|
170
|
+
const { parentSegments, name } = splitParent(path);
|
|
171
|
+
const parent = await walkDirectory(root, parentSegments, false);
|
|
172
|
+
const fileHandle = await parent.getFileHandle(name, { create: true });
|
|
173
|
+
const existingFile = opts?.append ? await fileHandle.getFile() : null;
|
|
174
|
+
const writable = await fileHandle.createWritable({ keepExistingData: !!opts?.append });
|
|
175
|
+
let position = opts?.append ? existingFile?.size ?? 0 : 0;
|
|
176
|
+
let closed = false;
|
|
177
|
+
return {
|
|
178
|
+
async write(chunk) {
|
|
179
|
+
if (closed) {
|
|
180
|
+
throw new Error("stream is closed");
|
|
181
|
+
}
|
|
182
|
+
const bytes = new Uint8Array(chunk.byteLength);
|
|
183
|
+
bytes.set(chunk, 0);
|
|
184
|
+
await writable.write({
|
|
185
|
+
type: "write",
|
|
186
|
+
position,
|
|
187
|
+
data: bytes
|
|
188
|
+
});
|
|
189
|
+
position += bytes.byteLength;
|
|
190
|
+
},
|
|
191
|
+
async close() {
|
|
192
|
+
if (closed)
|
|
193
|
+
return;
|
|
194
|
+
closed = true;
|
|
195
|
+
await writable.close();
|
|
196
|
+
},
|
|
197
|
+
async abort(_reason) {
|
|
198
|
+
if (closed)
|
|
199
|
+
return;
|
|
200
|
+
closed = true;
|
|
201
|
+
await writable.abort?.();
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
153
205
|
}
|
|
154
206
|
};
|
|
155
207
|
}
|
|
@@ -164,7 +216,8 @@ function createDirectoryStat() {
|
|
|
164
216
|
isFile: () => false,
|
|
165
217
|
isDirectory: () => true,
|
|
166
218
|
size: 0,
|
|
167
|
-
mtime: DIRECTORY_MTIME
|
|
219
|
+
mtime: DIRECTORY_MTIME,
|
|
220
|
+
mtimeMs: DIRECTORY_MTIME.getTime()
|
|
168
221
|
};
|
|
169
222
|
}
|
|
170
223
|
function normalizeWebPath(path) {
|
|
@@ -224,6 +277,22 @@ async function entryExists(dir, name) {
|
|
|
224
277
|
return false;
|
|
225
278
|
}
|
|
226
279
|
}
|
|
280
|
+
async function* streamToAsyncIterable(stream) {
|
|
281
|
+
const reader = stream.getReader();
|
|
282
|
+
try {
|
|
283
|
+
while (true) {
|
|
284
|
+
const { done, value } = await reader.read();
|
|
285
|
+
if (done) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (value) {
|
|
289
|
+
yield value;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
} finally {
|
|
293
|
+
reader.releaseLock();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
227
296
|
function isNotFoundOrTypeMismatch(error) {
|
|
228
297
|
return isNotFoundError(error) || isTypeMismatchError(error);
|
|
229
298
|
}
|
|
@@ -252,4 +321,4 @@ export {
|
|
|
252
321
|
WebFileSystem
|
|
253
322
|
};
|
|
254
323
|
|
|
255
|
-
//# debugId=
|
|
324
|
+
//# debugId=D6530F8F37F8735C64756E2164756E21
|