sandbox-fs 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/FSModule.d.ts.map +1 -1
- package/dist/FSModule.js +81 -18
- package/dist/FSModule.js.map +1 -1
- package/dist/PathMapper.d.ts.map +1 -1
- package/dist/PathMapper.js +147 -41
- package/dist/PathMapper.js.map +1 -1
- package/dist/VirtualFileSystem.d.ts.map +1 -1
- package/dist/VirtualFileSystem.js +27 -1
- package/dist/VirtualFileSystem.js.map +1 -1
- package/dist/operations/newer.d.ts.map +1 -1
- package/dist/operations/newer.js +32 -3
- package/dist/operations/newer.js.map +1 -1
- package/dist/operations/read.d.ts.map +1 -1
- package/dist/operations/read.js +100 -14
- package/dist/operations/read.js.map +1 -1
- package/dist/utils/ErrorFilter.d.ts.map +1 -1
- package/dist/utils/ErrorFilter.js +21 -24
- package/dist/utils/ErrorFilter.js.map +1 -1
- package/dist/wrappers/VirtualDir.d.ts.map +1 -1
- package/dist/wrappers/VirtualDir.js +36 -35
- package/dist/wrappers/VirtualDir.js.map +1 -1
- package/dist/wrappers/VirtualDirent.d.ts.map +1 -1
- package/dist/wrappers/VirtualDirent.js +28 -9
- package/dist/wrappers/VirtualDirent.js.map +1 -1
- package/package.json +8 -4
- package/dist/FSModule.d.ts +0 -153
- package/dist/PathMapper.d.ts +0 -30
- package/dist/PathModule.d.ts +0 -69
- package/dist/ResourceTracker.d.ts +0 -74
- package/dist/VirtualFileSystem.d.ts +0 -145
- package/dist/index.d.ts +0 -9
- package/dist/operations/newer.d.ts +0 -36
- package/dist/operations/read.d.ts +0 -24
- package/dist/operations/symlink.d.ts +0 -8
- package/dist/operations/write.d.ts +0 -29
- package/dist/utils/ErrorFilter.d.ts +0 -6
- package/dist/utils/callbackify.d.ts +0 -9
- package/dist/wrappers/VirtualDir.d.ts +0 -34
- package/dist/wrappers/VirtualDirent.d.ts +0 -21
- package/example.js +0 -95
- package/example.ts +0 -32
- package/src/FSModule.ts +0 -546
- package/src/PathMapper.ts +0 -102
- package/src/PathModule.ts +0 -142
- package/src/ResourceTracker.ts +0 -162
- package/src/VirtualFileSystem.ts +0 -172
- package/src/index.ts +0 -9
- package/src/operations/newer.ts +0 -223
- package/src/operations/read.ts +0 -319
- package/src/operations/symlink.ts +0 -31
- package/src/operations/write.ts +0 -189
- package/src/utils/ErrorFilter.ts +0 -57
- package/src/utils/callbackify.ts +0 -54
- package/src/wrappers/VirtualDir.ts +0 -84
- package/src/wrappers/VirtualDirent.ts +0 -60
- package/test-data/example.txt +0 -1
- package/test-data/subdir/nested.txt +0 -1
- package/tsconfig.example.json +0 -8
- package/tsconfig.json +0 -21
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import { VirtualDirent } from './VirtualDirent';
|
|
3
|
-
import type { PathMapper } from '../PathMapper';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Virtual Dir that wraps a real fs.Dir and returns VirtualDirent instances
|
|
7
|
-
*/
|
|
8
|
-
export class VirtualDir implements AsyncIterable<VirtualDirent> {
|
|
9
|
-
private realDir: fs.Dir;
|
|
10
|
-
private _virtualPath: string;
|
|
11
|
-
private pathMapper: PathMapper;
|
|
12
|
-
|
|
13
|
-
constructor(realDir: fs.Dir, virtualPath: string, pathMapper: PathMapper) {
|
|
14
|
-
this.realDir = realDir;
|
|
15
|
-
this._virtualPath = virtualPath;
|
|
16
|
-
this.pathMapper = pathMapper;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get path(): string {
|
|
20
|
-
return this._virtualPath;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Read the next directory entry
|
|
25
|
-
*/
|
|
26
|
-
async read(): Promise<VirtualDirent | null> {
|
|
27
|
-
const realDirent = await this.realDir.read();
|
|
28
|
-
if (realDirent === null) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Construct virtual path for this entry
|
|
33
|
-
const virtualEntryPath = this._virtualPath === '/'
|
|
34
|
-
? `/${realDirent.name}`
|
|
35
|
-
: `${this._virtualPath}/${realDirent.name}`;
|
|
36
|
-
|
|
37
|
-
return new VirtualDirent(realDirent, virtualEntryPath, realDirent.name);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Synchronously read the next directory entry
|
|
42
|
-
*/
|
|
43
|
-
readSync(): VirtualDirent | null {
|
|
44
|
-
const realDirent = this.realDir.readSync();
|
|
45
|
-
if (realDirent === null) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const virtualEntryPath = this._virtualPath === '/'
|
|
50
|
-
? `/${realDirent.name}`
|
|
51
|
-
: `${this._virtualPath}/${realDirent.name}`;
|
|
52
|
-
|
|
53
|
-
return new VirtualDirent(realDirent, virtualEntryPath, realDirent.name);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Close the directory
|
|
58
|
-
*/
|
|
59
|
-
async close(): Promise<void> {
|
|
60
|
-
await this.realDir.close();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Synchronously close the directory
|
|
65
|
-
*/
|
|
66
|
-
closeSync(): void {
|
|
67
|
-
this.realDir.closeSync();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Async iterator support
|
|
72
|
-
*/
|
|
73
|
-
[Symbol.asyncIterator](): AsyncIterator<VirtualDirent> {
|
|
74
|
-
return {
|
|
75
|
-
next: async (): Promise<IteratorResult<VirtualDirent>> => {
|
|
76
|
-
const dirent = await this.read();
|
|
77
|
-
if (dirent === null) {
|
|
78
|
-
return { done: true, value: undefined };
|
|
79
|
-
}
|
|
80
|
-
return { done: false, value: dirent };
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Virtual Dirent that wraps a real fs.Dirent and exposes virtual paths
|
|
5
|
-
*/
|
|
6
|
-
export class VirtualDirent implements fs.Dirent {
|
|
7
|
-
private realDirent: fs.Dirent;
|
|
8
|
-
private _virtualPath: string;
|
|
9
|
-
private _name: string;
|
|
10
|
-
|
|
11
|
-
constructor(realDirent: fs.Dirent, virtualPath: string, name?: string) {
|
|
12
|
-
this.realDirent = realDirent;
|
|
13
|
-
this._virtualPath = virtualPath;
|
|
14
|
-
this._name = name || realDirent.name;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get name(): string {
|
|
18
|
-
return this._name;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get path(): string {
|
|
22
|
-
return this._virtualPath;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get parentPath(): string {
|
|
26
|
-
// Return the parent directory path
|
|
27
|
-
const parts = this._virtualPath.split('/').filter(Boolean);
|
|
28
|
-
if (parts.length === 0) return '/';
|
|
29
|
-
parts.pop();
|
|
30
|
-
return '/' + parts.join('/');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
isFile(): boolean {
|
|
34
|
-
return this.realDirent.isFile();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
isDirectory(): boolean {
|
|
38
|
-
return this.realDirent.isDirectory();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
isBlockDevice(): boolean {
|
|
42
|
-
return this.realDirent.isBlockDevice();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
isCharacterDevice(): boolean {
|
|
46
|
-
return this.realDirent.isCharacterDevice();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
isSymbolicLink(): boolean {
|
|
50
|
-
return this.realDirent.isSymbolicLink();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
isFIFO(): boolean {
|
|
54
|
-
return this.realDirent.isFIFO();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
isSocket(): boolean {
|
|
58
|
-
return this.realDirent.isSocket();
|
|
59
|
-
}
|
|
60
|
-
}
|
package/test-data/example.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Hello from VFS!
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Nested file content
|
package/tsconfig.example.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2021",
|
|
4
|
-
"module": "CommonJS",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"lib": ["ES2021"],
|
|
7
|
-
"outDir": "./dist",
|
|
8
|
-
"rootDir": "./src",
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"declarationMap": true,
|
|
11
|
-
"sourceMap": true,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"skipLibCheck": true,
|
|
15
|
-
"forceConsistentCasingInFileNames": true,
|
|
16
|
-
"resolveJsonModule": true,
|
|
17
|
-
"types": ["node"]
|
|
18
|
-
},
|
|
19
|
-
"include": ["src/**/*"],
|
|
20
|
-
"exclude": ["node_modules", "dist"]
|
|
21
|
-
}
|