shfs 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{fs-DSmBon4m.d.mts → fs-rz7EnuDE.d.mts} +2 -1
- package/dist/fs.d.mts +2 -1
- package/dist/fs.mjs +50 -18
- package/dist/fs.mjs.map +1 -1
- package/dist/index.d.mts +17 -16
- package/dist/index.mjs +1057 -321
- package/dist/index.mjs.map +1 -1
- package/dist/path-BR0nl4aX.mjs +12 -0
- package/dist/path-BR0nl4aX.mjs.map +1 -0
- package/dist/util/path.d.mts +5 -0
- package/dist/util/path.mjs +3 -0
- package/package.json +12 -6
|
@@ -7,6 +7,7 @@ interface FS {
|
|
|
7
7
|
readLines(path: string): Stream<string>;
|
|
8
8
|
writeFile(path: string, content: Uint8Array): Promise<void>;
|
|
9
9
|
deleteFile(path: string): Promise<void>;
|
|
10
|
+
deleteDirectory(path: string, recursive?: boolean): Promise<void>;
|
|
10
11
|
readdir(path: string): Stream<string>;
|
|
11
12
|
mkdir(path: string, recursive?: boolean): Promise<void>;
|
|
12
13
|
stat(path: string): Promise<{
|
|
@@ -18,4 +19,4 @@ interface FS {
|
|
|
18
19
|
}
|
|
19
20
|
//#endregion
|
|
20
21
|
export { Stream as n, FS as t };
|
|
21
|
-
//# sourceMappingURL=fs-
|
|
22
|
+
//# sourceMappingURL=fs-rz7EnuDE.d.mts.map
|
package/dist/fs.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as Stream, t as FS } from "./fs-
|
|
1
|
+
import { n as Stream, t as FS } from "./fs-rz7EnuDE.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/fs/memory.d.ts
|
|
4
4
|
declare class MemoryFS implements FS {
|
|
@@ -11,6 +11,7 @@ declare class MemoryFS implements FS {
|
|
|
11
11
|
readLines(path: string): Stream<string>;
|
|
12
12
|
writeFile(path: string, content: Uint8Array): Promise<void>;
|
|
13
13
|
deleteFile(path: string): Promise<void>;
|
|
14
|
+
deleteDirectory(path: string, recursive?: boolean): Promise<void>;
|
|
14
15
|
readdir(glob: string): Stream<string>;
|
|
15
16
|
mkdir(path: string, recursive?: boolean): Promise<void>;
|
|
16
17
|
stat(path: string): Promise<{
|
package/dist/fs.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { t as normalizePath } from "./path-BR0nl4aX.mjs";
|
|
2
|
+
import picomatch from "picomatch";
|
|
3
|
+
|
|
1
4
|
//#region src/fs/memory.ts
|
|
2
|
-
const TRAILING_SLASH_REGEX = /\/$/;
|
|
3
5
|
var MemoryFS = class {
|
|
4
6
|
files = /* @__PURE__ */ new Map();
|
|
5
7
|
directories = /* @__PURE__ */ new Set();
|
|
@@ -12,40 +14,69 @@ var MemoryFS = class {
|
|
|
12
14
|
});
|
|
13
15
|
}
|
|
14
16
|
setFile(path, content) {
|
|
17
|
+
const normalizedPath = normalizePath(path);
|
|
15
18
|
const encoded = typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
16
|
-
this.files.set(
|
|
17
|
-
this.fileMetadata.set(
|
|
19
|
+
this.files.set(normalizedPath, encoded);
|
|
20
|
+
this.fileMetadata.set(normalizedPath, {
|
|
18
21
|
mtime: /* @__PURE__ */ new Date(),
|
|
19
22
|
isDirectory: false
|
|
20
23
|
});
|
|
21
24
|
}
|
|
22
25
|
async readFile(path) {
|
|
23
|
-
const
|
|
26
|
+
const normalizedPath = normalizePath(path);
|
|
27
|
+
const content = this.files.get(normalizedPath);
|
|
24
28
|
if (!content) throw new Error(`File not found: ${path}`);
|
|
25
29
|
return content;
|
|
26
30
|
}
|
|
27
31
|
async *readLines(path) {
|
|
28
|
-
const
|
|
32
|
+
const normalizedPath = normalizePath(path);
|
|
33
|
+
const content = this.files.get(normalizedPath);
|
|
29
34
|
if (!content) throw new Error(`File not found: ${path}`);
|
|
30
35
|
yield* new TextDecoder().decode(content).split("\n").filter((_, i, arr) => !(i === arr.length - 1 && arr[i] === ""));
|
|
31
36
|
}
|
|
32
37
|
async writeFile(path, content) {
|
|
33
|
-
|
|
38
|
+
const normalizedPath = normalizePath(path);
|
|
39
|
+
this.files.set(normalizedPath, content);
|
|
40
|
+
this.fileMetadata.set(normalizedPath, {
|
|
41
|
+
mtime: /* @__PURE__ */ new Date(),
|
|
42
|
+
isDirectory: false
|
|
43
|
+
});
|
|
34
44
|
}
|
|
35
45
|
async deleteFile(path) {
|
|
36
|
-
|
|
37
|
-
this.files.
|
|
46
|
+
const normalizedPath = normalizePath(path);
|
|
47
|
+
if (!this.files.has(normalizedPath)) throw new Error(`File not found: ${path}`);
|
|
48
|
+
this.files.delete(normalizedPath);
|
|
49
|
+
this.fileMetadata.delete(normalizedPath);
|
|
50
|
+
}
|
|
51
|
+
async deleteDirectory(path, recursive = false) {
|
|
52
|
+
const normalizedPath = normalizePath(path);
|
|
53
|
+
if (normalizedPath === "/") throw new Error("rm: cannot remove '/'");
|
|
54
|
+
if (!this.directories.has(normalizedPath)) throw new Error(`No such file or directory: ${path}`);
|
|
55
|
+
const childPrefix = `${normalizedPath}/`;
|
|
56
|
+
const hasChildDirectories = Array.from(this.directories).some((directory) => directory !== normalizedPath && directory.startsWith(childPrefix));
|
|
57
|
+
const hasChildFiles = Array.from(this.files.keys()).some((filePath) => filePath.startsWith(childPrefix));
|
|
58
|
+
if (!recursive && (hasChildDirectories || hasChildFiles)) throw new Error(`Directory not empty: ${path}`);
|
|
59
|
+
for (const filePath of Array.from(this.files.keys())) if (filePath.startsWith(childPrefix)) {
|
|
60
|
+
this.files.delete(filePath);
|
|
61
|
+
this.fileMetadata.delete(filePath);
|
|
62
|
+
}
|
|
63
|
+
const directoriesToDelete = Array.from(this.directories).filter((directory) => directory === normalizedPath || directory.startsWith(childPrefix)).sort((a, b) => b.length - a.length);
|
|
64
|
+
for (const directory of directoriesToDelete) {
|
|
65
|
+
if (directory === "/") continue;
|
|
66
|
+
this.directories.delete(directory);
|
|
67
|
+
this.fileMetadata.delete(directory);
|
|
68
|
+
}
|
|
38
69
|
}
|
|
39
70
|
async *readdir(glob) {
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const paths = Array.from(this.files.keys()).filter((path) => regex.test(path)).sort();
|
|
71
|
+
const isMatch = picomatch(glob, { dot: true });
|
|
72
|
+
const paths = [...Array.from(this.directories.keys()), ...Array.from(this.files.keys())].filter((path) => isMatch(path)).sort();
|
|
43
73
|
for (const path of paths) yield path;
|
|
44
74
|
}
|
|
45
75
|
async mkdir(path, recursive = false) {
|
|
46
|
-
|
|
76
|
+
const normalizedPath = normalizePath(path);
|
|
77
|
+
if (this.directories.has(normalizedPath) || this.files.has(normalizedPath)) throw new Error(`Directory already exists: ${path}`);
|
|
47
78
|
if (recursive) {
|
|
48
|
-
const parts =
|
|
79
|
+
const parts = normalizedPath.split("/").filter(Boolean);
|
|
49
80
|
let current = "";
|
|
50
81
|
for (const part of parts) {
|
|
51
82
|
current += `/${part}`;
|
|
@@ -58,17 +89,17 @@ var MemoryFS = class {
|
|
|
58
89
|
}
|
|
59
90
|
}
|
|
60
91
|
} else {
|
|
61
|
-
const parentPath =
|
|
92
|
+
const parentPath = normalizedPath.substring(0, normalizedPath.lastIndexOf("/")) || "/";
|
|
62
93
|
if (parentPath !== "/" && !this.directories.has(parentPath) && !this.files.has(parentPath)) throw new Error(`No such file or directory: ${parentPath}`);
|
|
63
|
-
this.directories.add(
|
|
64
|
-
this.fileMetadata.set(
|
|
94
|
+
this.directories.add(normalizedPath);
|
|
95
|
+
this.fileMetadata.set(normalizedPath, {
|
|
65
96
|
mtime: /* @__PURE__ */ new Date(),
|
|
66
97
|
isDirectory: true
|
|
67
98
|
});
|
|
68
99
|
}
|
|
69
100
|
}
|
|
70
101
|
async stat(path) {
|
|
71
|
-
const normalizedPath = path
|
|
102
|
+
const normalizedPath = normalizePath(path);
|
|
72
103
|
if (this.directories.has(normalizedPath)) return {
|
|
73
104
|
isDirectory: true,
|
|
74
105
|
size: 0,
|
|
@@ -86,7 +117,8 @@ var MemoryFS = class {
|
|
|
86
117
|
throw new Error(`No such file or directory: ${path}`);
|
|
87
118
|
}
|
|
88
119
|
async exists(path) {
|
|
89
|
-
|
|
120
|
+
const normalizedPath = normalizePath(path);
|
|
121
|
+
return this.files.has(normalizedPath) || this.directories.has(normalizedPath);
|
|
90
122
|
}
|
|
91
123
|
};
|
|
92
124
|
|
package/dist/fs.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.mjs","names":[],"sources":["../src/fs/memory.ts"],"sourcesContent":["import type { Stream } from '../stream';\nimport type { FS } from './fs';\n\nexport type { FS } from './fs';\n\nconst TRAILING_SLASH_REGEX = /\\/$/;\n\nexport class MemoryFS implements FS {\n\tprivate readonly files = new Map<string, Uint8Array>();\n\tprivate readonly directories = new Set<string>();\n\tprivate readonly fileMetadata = new Map<\n\t\tstring,\n\t\t{ mtime: Date; isDirectory: boolean }\n\t>();\n\n\tconstructor() {\n\t\t// Initialize root directory\n\t\tthis.directories.add('/');\n\t\tthis.fileMetadata.set('/', { mtime: new Date(), isDirectory: true });\n\t}\n\n\tsetFile(path: string, content: string | Uint8Array): void {\n\t\tconst encoded =\n\t\t\ttypeof content === 'string'\n\t\t\t\t? new TextEncoder().encode(content)\n\t\t\t\t: content;\n\t\tthis.files.set(path, encoded);\n\t\tthis.fileMetadata.set(path, { mtime: new Date(), isDirectory: false });\n\t}\n\n\tasync readFile(path: string): Promise<Uint8Array> {\n\t\tconst content = this.files.get(path);\n\t\tif (!content) {\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\t\treturn content;\n\t}\n\n\tasync *readLines(path: string): Stream<string> {\n\t\tconst content = this.files.get(path);\n\t\tif (!content) {\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\t\tconst text = new TextDecoder().decode(content);\n\t\tconst lines = text\n\t\t\t.split('\\n')\n\t\t\t.filter((_, i, arr) => !(i === arr.length - 1 && arr[i] === ''));\n\t\tyield* lines;\n\t}\n\n\tasync writeFile(path: string, content: Uint8Array): Promise<void> {\n\t\tthis.files.set(path, content);\n\t}\n\n\tasync deleteFile(path: string): Promise<void> {\n\t\tif (!this.files.has(path)) {\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\t\tthis.files.delete(path);\n\t}\n\n\tasync *readdir(glob: string): Stream<string> {\n\t\tconst pattern = glob\n\t\t\t.replace(/\\*\\*/g, '.*')\n\t\t\t.replace(/\\*/g, '[^/]*')\n\t\t\t.replace(/\\?/g, '[^/]')\n\t\t\t.replace(/\\./g, '\\\\.');\n\n\t\tconst regex = new RegExp(`^${pattern}$`);\n\n\t\tconst paths = Array.from(this.files.keys())\n\t\t\t.filter((path) => regex.test(path))\n\t\t\t.sort();\n\n\t\tfor (const path of paths) {\n\t\t\tyield path;\n\t\t}\n\t}\n\n\tasync mkdir(path: string, recursive = false): Promise<void> {\n\t\tif (this.directories.has(path) || this.files.has(path)) {\n\t\t\tthrow new Error(`Directory already exists: ${path}`);\n\t\t}\n\n\t\tif (recursive) {\n\t\t\t// Create all parent directories\n\t\t\tconst parts = path.split('/').filter(Boolean);\n\t\t\tlet current = '';\n\t\t\tfor (const part of parts) {\n\t\t\t\tcurrent += `/${part}`;\n\t\t\t\tif (\n\t\t\t\t\t!(this.directories.has(current) || this.files.has(current))\n\t\t\t\t) {\n\t\t\t\t\tthis.directories.add(current);\n\t\t\t\t\tthis.fileMetadata.set(current, {\n\t\t\t\t\t\tmtime: new Date(),\n\t\t\t\t\t\tisDirectory: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Check if parent directory exists\n\t\t\tconst parentPath = path.substring(0, path.lastIndexOf('/')) || '/';\n\t\t\tif (\n\t\t\t\tparentPath !== '/' &&\n\t\t\t\t!this.directories.has(parentPath) &&\n\t\t\t\t!this.files.has(parentPath)\n\t\t\t) {\n\t\t\t\tthrow new Error(`No such file or directory: ${parentPath}`);\n\t\t\t}\n\t\t\tthis.directories.add(path);\n\t\t\tthis.fileMetadata.set(path, {\n\t\t\t\tmtime: new Date(),\n\t\t\t\tisDirectory: true,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync stat(\n\t\tpath: string\n\t): Promise<{ isDirectory: boolean; size: number; mtime: Date }> {\n\t\t// Normalize path by removing trailing slash\n\t\tconst normalizedPath = path.replace(TRAILING_SLASH_REGEX, '') || '/';\n\n\t\tif (this.directories.has(normalizedPath)) {\n\t\t\treturn {\n\t\t\t\tisDirectory: true,\n\t\t\t\tsize: 0,\n\t\t\t\tmtime:\n\t\t\t\t\tthis.fileMetadata.get(normalizedPath)?.mtime || new Date(),\n\t\t\t};\n\t\t}\n\n\t\tif (this.files.has(normalizedPath)) {\n\t\t\tconst content = this.files.get(normalizedPath);\n\t\t\tif (content === undefined) {\n\t\t\t\tthrow new Error(`No such file or directory: ${path}`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tisDirectory: false,\n\t\t\t\tsize: content.byteLength,\n\t\t\t\tmtime:\n\t\t\t\t\tthis.fileMetadata.get(normalizedPath)?.mtime || new Date(),\n\t\t\t};\n\t\t}\n\n\t\tthrow new Error(`No such file or directory: ${path}`);\n\t}\n\n\tasync exists(path: string): Promise<boolean> {\n\t\treturn this.files.has(path) || this.directories.has(path);\n\t}\n}\n"],"mappings":";AAKA,MAAM,uBAAuB;AAE7B,IAAa,WAAb,MAAoC;CACnC,AAAiB,wBAAQ,IAAI,KAAyB;CACtD,AAAiB,8BAAc,IAAI,KAAa;CAChD,AAAiB,+BAAe,IAAI,KAGjC;CAEH,cAAc;AAEb,OAAK,YAAY,IAAI,IAAI;AACzB,OAAK,aAAa,IAAI,KAAK;GAAE,uBAAO,IAAI,MAAM;GAAE,aAAa;GAAM,CAAC;;CAGrE,QAAQ,MAAc,SAAoC;EACzD,MAAM,UACL,OAAO,YAAY,WAChB,IAAI,aAAa,CAAC,OAAO,QAAQ,GACjC;AACJ,OAAK,MAAM,IAAI,MAAM,QAAQ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version":3,"file":"fs.mjs","names":[],"sources":["../src/fs/memory.ts"],"sourcesContent":["import picomatch from 'picomatch';\nimport type { Stream } from '../stream';\nimport { normalizePath } from '../util/path';\nimport type { FS } from './fs';\n\nexport type { FS } from './fs';\n\nexport class MemoryFS implements FS {\n\tprivate readonly files = new Map<string, Uint8Array>();\n\tprivate readonly directories = new Set<string>();\n\tprivate readonly fileMetadata = new Map<\n\t\tstring,\n\t\t{ mtime: Date; isDirectory: boolean }\n\t>();\n\n\tconstructor() {\n\t\t// Initialize root directory\n\t\tthis.directories.add('/');\n\t\tthis.fileMetadata.set('/', { mtime: new Date(), isDirectory: true });\n\t}\n\n\tsetFile(path: string, content: string | Uint8Array): void {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tconst encoded =\n\t\t\ttypeof content === 'string'\n\t\t\t\t? new TextEncoder().encode(content)\n\t\t\t\t: content;\n\t\tthis.files.set(normalizedPath, encoded);\n\t\tthis.fileMetadata.set(normalizedPath, {\n\t\t\tmtime: new Date(),\n\t\t\tisDirectory: false,\n\t\t});\n\t}\n\n\tasync readFile(path: string): Promise<Uint8Array> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tconst content = this.files.get(normalizedPath);\n\t\tif (!content) {\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\t\treturn content;\n\t}\n\n\tasync *readLines(path: string): Stream<string> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tconst content = this.files.get(normalizedPath);\n\t\tif (!content) {\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\t\tconst text = new TextDecoder().decode(content);\n\t\tconst lines = text\n\t\t\t.split('\\n')\n\t\t\t.filter((_, i, arr) => !(i === arr.length - 1 && arr[i] === ''));\n\t\tyield* lines;\n\t}\n\n\tasync writeFile(path: string, content: Uint8Array): Promise<void> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tthis.files.set(normalizedPath, content);\n\t\tthis.fileMetadata.set(normalizedPath, {\n\t\t\tmtime: new Date(),\n\t\t\tisDirectory: false,\n\t\t});\n\t}\n\n\tasync deleteFile(path: string): Promise<void> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tif (!this.files.has(normalizedPath)) {\n\t\t\tthrow new Error(`File not found: ${path}`);\n\t\t}\n\t\tthis.files.delete(normalizedPath);\n\t\tthis.fileMetadata.delete(normalizedPath);\n\t}\n\n\tasync deleteDirectory(path: string, recursive = false): Promise<void> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tif (normalizedPath === '/') {\n\t\t\tthrow new Error(\"rm: cannot remove '/'\");\n\t\t}\n\t\tif (!this.directories.has(normalizedPath)) {\n\t\t\tthrow new Error(`No such file or directory: ${path}`);\n\t\t}\n\n\t\tconst childPrefix = `${normalizedPath}/`;\n\t\tconst hasChildDirectories = Array.from(this.directories).some(\n\t\t\t(directory) =>\n\t\t\t\tdirectory !== normalizedPath &&\n\t\t\t\tdirectory.startsWith(childPrefix)\n\t\t);\n\t\tconst hasChildFiles = Array.from(this.files.keys()).some((filePath) =>\n\t\t\tfilePath.startsWith(childPrefix)\n\t\t);\n\n\t\tif (!recursive && (hasChildDirectories || hasChildFiles)) {\n\t\t\tthrow new Error(`Directory not empty: ${path}`);\n\t\t}\n\n\t\tfor (const filePath of Array.from(this.files.keys())) {\n\t\t\tif (filePath.startsWith(childPrefix)) {\n\t\t\t\tthis.files.delete(filePath);\n\t\t\t\tthis.fileMetadata.delete(filePath);\n\t\t\t}\n\t\t}\n\n\t\tconst directoriesToDelete = Array.from(this.directories)\n\t\t\t.filter(\n\t\t\t\t(directory) =>\n\t\t\t\t\tdirectory === normalizedPath ||\n\t\t\t\t\tdirectory.startsWith(childPrefix)\n\t\t\t)\n\t\t\t.sort((a, b) => b.length - a.length);\n\t\tfor (const directory of directoriesToDelete) {\n\t\t\tif (directory === '/') {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.directories.delete(directory);\n\t\t\tthis.fileMetadata.delete(directory);\n\t\t}\n\t}\n\n\tasync *readdir(glob: string): Stream<string> {\n\t\tconst isMatch = picomatch(glob, { dot: true });\n\n\t\tconst allPaths = [\n\t\t\t...Array.from(this.directories.keys()),\n\t\t\t...Array.from(this.files.keys()),\n\t\t];\n\t\tconst paths = allPaths.filter((path) => isMatch(path)).sort();\n\n\t\tfor (const path of paths) {\n\t\t\tyield path;\n\t\t}\n\t}\n\n\tasync mkdir(path: string, recursive = false): Promise<void> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\tif (\n\t\t\tthis.directories.has(normalizedPath) ||\n\t\t\tthis.files.has(normalizedPath)\n\t\t) {\n\t\t\tthrow new Error(`Directory already exists: ${path}`);\n\t\t}\n\n\t\tif (recursive) {\n\t\t\t// Create all parent directories\n\t\t\tconst parts = normalizedPath.split('/').filter(Boolean);\n\t\t\tlet current = '';\n\t\t\tfor (const part of parts) {\n\t\t\t\tcurrent += `/${part}`;\n\t\t\t\tif (\n\t\t\t\t\t!(this.directories.has(current) || this.files.has(current))\n\t\t\t\t) {\n\t\t\t\t\tthis.directories.add(current);\n\t\t\t\t\tthis.fileMetadata.set(current, {\n\t\t\t\t\t\tmtime: new Date(),\n\t\t\t\t\t\tisDirectory: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Check if parent directory exists\n\t\t\tconst parentPath =\n\t\t\t\tnormalizedPath.substring(0, normalizedPath.lastIndexOf('/')) ||\n\t\t\t\t'/';\n\t\t\tif (\n\t\t\t\tparentPath !== '/' &&\n\t\t\t\t!this.directories.has(parentPath) &&\n\t\t\t\t!this.files.has(parentPath)\n\t\t\t) {\n\t\t\t\tthrow new Error(`No such file or directory: ${parentPath}`);\n\t\t\t}\n\t\t\tthis.directories.add(normalizedPath);\n\t\t\tthis.fileMetadata.set(normalizedPath, {\n\t\t\t\tmtime: new Date(),\n\t\t\t\tisDirectory: true,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync stat(\n\t\tpath: string\n\t): Promise<{ isDirectory: boolean; size: number; mtime: Date }> {\n\t\t// Normalize path by removing trailing slash\n\t\tconst normalizedPath = normalizePath(path);\n\n\t\tif (this.directories.has(normalizedPath)) {\n\t\t\treturn {\n\t\t\t\tisDirectory: true,\n\t\t\t\tsize: 0,\n\t\t\t\tmtime:\n\t\t\t\t\tthis.fileMetadata.get(normalizedPath)?.mtime || new Date(),\n\t\t\t};\n\t\t}\n\n\t\tif (this.files.has(normalizedPath)) {\n\t\t\tconst content = this.files.get(normalizedPath);\n\t\t\tif (content === undefined) {\n\t\t\t\tthrow new Error(`No such file or directory: ${path}`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tisDirectory: false,\n\t\t\t\tsize: content.byteLength,\n\t\t\t\tmtime:\n\t\t\t\t\tthis.fileMetadata.get(normalizedPath)?.mtime || new Date(),\n\t\t\t};\n\t\t}\n\n\t\tthrow new Error(`No such file or directory: ${path}`);\n\t}\n\n\tasync exists(path: string): Promise<boolean> {\n\t\tconst normalizedPath = normalizePath(path);\n\t\treturn (\n\t\t\tthis.files.has(normalizedPath) ||\n\t\t\tthis.directories.has(normalizedPath)\n\t\t);\n\t}\n}\n"],"mappings":";;;;AAOA,IAAa,WAAb,MAAoC;CACnC,AAAiB,wBAAQ,IAAI,KAAyB;CACtD,AAAiB,8BAAc,IAAI,KAAa;CAChD,AAAiB,+BAAe,IAAI,KAGjC;CAEH,cAAc;AAEb,OAAK,YAAY,IAAI,IAAI;AACzB,OAAK,aAAa,IAAI,KAAK;GAAE,uBAAO,IAAI,MAAM;GAAE,aAAa;GAAM,CAAC;;CAGrE,QAAQ,MAAc,SAAoC;EACzD,MAAM,iBAAiB,cAAc,KAAK;EAC1C,MAAM,UACL,OAAO,YAAY,WAChB,IAAI,aAAa,CAAC,OAAO,QAAQ,GACjC;AACJ,OAAK,MAAM,IAAI,gBAAgB,QAAQ;AACvC,OAAK,aAAa,IAAI,gBAAgB;GACrC,uBAAO,IAAI,MAAM;GACjB,aAAa;GACb,CAAC;;CAGH,MAAM,SAAS,MAAmC;E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-22,23 +22,24 @@ interface JsonRecord {
|
|
|
22
22
|
type Record = FileRecord | LineRecord | JsonRecord;
|
|
23
23
|
//#endregion
|
|
24
24
|
//#region src/shell/shell.d.ts
|
|
25
|
+
interface ShellOptions {
|
|
26
|
+
cwd?: string;
|
|
27
|
+
}
|
|
28
|
+
interface ShellCommand {
|
|
29
|
+
cwd(path: string): ShellCommand;
|
|
30
|
+
json(): Promise<unknown[]>;
|
|
31
|
+
lines(): Promise<string[]>;
|
|
32
|
+
raw(): Promise<Record[]>;
|
|
33
|
+
stdout(): Promise<void>;
|
|
34
|
+
text(): Promise<string>;
|
|
35
|
+
}
|
|
25
36
|
declare class Shell {
|
|
26
37
|
private readonly fs;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
stdout(): Promise<void>;
|
|
33
|
-
text(): Promise<string>;
|
|
34
|
-
};
|
|
35
|
-
exec(strings: TemplateStringsArray, ...exprs: unknown[]): {
|
|
36
|
-
json(): Promise<unknown[]>;
|
|
37
|
-
lines(): Promise<string[]>;
|
|
38
|
-
raw(): Promise<Record[]>;
|
|
39
|
-
stdout(): Promise<void>;
|
|
40
|
-
text(): Promise<string>;
|
|
41
|
-
};
|
|
38
|
+
private currentCwd;
|
|
39
|
+
constructor(fs: FS, options?: ShellOptions);
|
|
40
|
+
$: (strings: TemplateStringsArray, ...exprs: unknown[]) => ShellCommand;
|
|
41
|
+
exec(strings: TemplateStringsArray, ...exprs: unknown[]): ShellCommand;
|
|
42
|
+
cwd(newCwd: string): void;
|
|
42
43
|
private _exec;
|
|
43
44
|
}
|
|
44
45
|
//#endregion
|